diff --git a/BUILD b/BUILD new file mode 100644 index 0000000..a0854ba --- /dev/null +++ b/BUILD @@ -0,0 +1,3 @@ +package(default_visibility = ["//visibility:public"]) + +exports_files(["setup.cfg"]) diff --git a/setup.cfg b/setup.cfg index 66b0f32..bf2609e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -18,7 +18,7 @@ index-servers = pypi shitlist = pip,pkg_resources,setuptools [flake8] -extend-ignore = E203,E501,F405,F403,E731 +extend-ignore = E203,E501,F405,F403,E731,E306 [pypi] repository = https://pypi.python.org/pypi diff --git a/tools/autoflake/BUILD b/tools/autoflake/BUILD index 34fd3ed..9088820 100644 --- a/tools/autoflake/BUILD +++ b/tools/autoflake/BUILD @@ -3,5 +3,8 @@ py_binary( main = "__main__.py", deps = [ py_requirement("autoflake"), - ] + ], + visibility = [ + "//visibility:public" + ], ) diff --git a/tools/flake8/BUILD b/tools/flake8/BUILD index f522a80..86dee31 100644 --- a/tools/flake8/BUILD +++ b/tools/flake8/BUILD @@ -1,7 +1,12 @@ +exports_files(["flake8.cfg"], visibility=["//visibility:public"]) + py_binary( name = "flake8", main = "__main__.py", deps = [ py_requirement("flake8"), ], + visibility = [ + "//visibility:public" + ], ) diff --git a/tools/flake8/flake8.bzl b/tools/flake8/flake8.bzl new file mode 100644 index 0000000..b9990af --- /dev/null +++ b/tools/flake8/flake8.bzl @@ -0,0 +1,65 @@ +"""Linting for Python using Aspects.""" + + +def _flake8_aspect_impl(target, ctx): + if hasattr(ctx.rule.attr, 'srcs'): + flake8 = ctx.attr._flake8.files_to_run + config = ctx.attr._config.files.to_list()[0] + + files = [] + for src in ctx.rule.attr.srcs: + for f in src.files.to_list(): + if f.extension == "py": + files.append(f) + + if files: + report = ctx.actions.declare_file(ctx.label.name + ".report") + else: + return [] + + args = ["--config", config.path, "--tee", "--output-file", report.path] + for f in files: + args.append(f.path) + + ctx.actions.run( + executable = flake8, + inputs = files, + tools = ctx.attr._config.files.to_list() + ctx.attr._flake8.files.to_list(), + arguments = args, + outputs = [report], + mnemonic = "Flake8", + ) + + return [ + OutputGroupInfo(flake8_checks = depset([report])) + ] + + return [] + + +flake8_aspect = aspect( + implementation = _flake8_aspect_impl, + attr_aspects = ['deps'], + attrs = { + '_flake8': attr.label(default="//tools/flake8"), + '_config': attr.label( + default="//:setup.cfg", + executable=False, + allow_single_file=True + ), + } +) + + +def _flake8_rule_impl(ctx): + ready_targets = [dep for dep in ctx.attr.deps if "flake8_checks" in dir(dep[OutputGroupInfo])] + files = depset([], transitive = [dep[OutputGroupInfo].flake8_checks for dep in ready_targets]) + return [DefaultInfo(files = files)] + + +flake8 = rule( + implementation = _flake8_rule_impl, + attrs = { + 'deps' : attr.label_list(aspects = [flake8_aspect]), + }, +) diff --git a/tools/isort/BUILD b/tools/isort/BUILD index 76881ad..d501e4c 100644 --- a/tools/isort/BUILD +++ b/tools/isort/BUILD @@ -3,5 +3,9 @@ py_binary( main = "__main__.py", deps = [ py_requirement("isort"), - ] + ], + visibility = [ + "//visibility:public" + ], + ) diff --git a/tools/openapi/BUILD b/tools/openapi/BUILD index a163d91..b7ced9e 100644 --- a/tools/openapi/BUILD +++ b/tools/openapi/BUILD @@ -3,5 +3,8 @@ py_binary( main = "__main__.py", deps = [ py_requirement("openapi-spec-validator"), - ] + ], + visibility = [ + "//visibility:public" + ], ) diff --git a/tools/python/defs.bzl b/tools/python/defs.bzl index e492eed..1dc3f09 100644 --- a/tools/python/defs.bzl +++ b/tools/python/defs.bzl @@ -14,6 +14,9 @@ load("@rules_zapp//zapp:zapp.bzl", "zapp_binary", ) +load("//tools/flake8:flake8.bzl", + "flake8", +) def py_requirement(*args, **kwargs): """A re-export of requirement()""" @@ -208,6 +211,12 @@ def py_project(name=None, ], ) + # if lib_srcs: + # flake8( + # name = "flake8", + # deps = [lib_name], + # ) + if main: py_binary( name=name, diff --git a/tools/sphinx/BUILD b/tools/sphinx/BUILD index 8fbf928..665c612 100644 --- a/tools/sphinx/BUILD +++ b/tools/sphinx/BUILD @@ -8,5 +8,8 @@ py_binary( py_requirement("sphinxcontrib-openapi"), py_requirement("sphinxcontrib-programoutput"), py_requirement("livereload"), - ] + ], + visibility = [ + "//visibility:public" + ], ) diff --git a/tools/unify/BUILD b/tools/unify/BUILD index ef86bd2..4945bbf 100644 --- a/tools/unify/BUILD +++ b/tools/unify/BUILD @@ -3,5 +3,8 @@ py_binary( main = "__main__.py", deps = [ py_requirement("unify"), - ] + ], + visibility = [ + "//visibility:public" + ], ) diff --git a/tools/xfmt/BUILD b/tools/xfmt/BUILD index f859712..5d2e4fc 100644 --- a/tools/xfmt/BUILD +++ b/tools/xfmt/BUILD @@ -5,5 +5,8 @@ py_binary( py_requirement("beautifulsoup4"), py_requirement("click"), py_requirement("lxml"), - ] + ], + visibility = [ + "//visibility:public" + ], ) diff --git a/tools/yamllint/BUILD b/tools/yamllint/BUILD index 6e5e23b..8ad05cf 100644 --- a/tools/yamllint/BUILD +++ b/tools/yamllint/BUILD @@ -4,5 +4,8 @@ py_binary( main = "__main__.py", deps = [ py_requirement("yamllint"), - ] + ], + visibility = [ + "//visibility:public" + ], )