Refactoring for parameter extensions (#44)
diff --git a/defs.bzl b/defs.bzl index 45bb84b..c956339 100644 --- a/defs.bzl +++ b/defs.bzl
@@ -2,7 +2,6 @@ DEFAULT_REPOSITORY_NAME = "pip" - def _pip_repository_impl(rctx): python_interpreter = rctx.attr.python_interpreter if rctx.attr.python_interpreter_target != None: @@ -25,33 +24,34 @@ ] pypath = ":".join([str(p) for p in [rules_root] + thirdparty_roots]) + args = [ + python_interpreter, + "-m", + "extract_wheels", + "--requirements", + rctx.path(rctx.attr.requirements), + "--repo", + "@%s" % rctx.attr.name, + ] + result = rctx.execute( - [ - python_interpreter, - "-m", - "extract_wheels", - "--requirements", - rctx.path(rctx.attr.requirements), - "--repo", - "@%s" % rctx.attr.name, - ], - environment={ + args, + environment = { # Manually construct the PYTHONPATH since we cannot use the toolchain here - "PYTHONPATH": pypath + "PYTHONPATH": pypath, }, - timeout=rctx.attr.timeout, + timeout = rctx.attr.timeout, ) if result.return_code: fail("rules_python_external failed: %s (%s)" % (result.stdout, result.stderr)) return - pip_repository = repository_rule( - attrs={ - "requirements": attr.label(allow_single_file=True, mandatory=True,), + attrs = { + "requirements": attr.label(allow_single_file = True, mandatory = True), "wheel_env": attr.string_dict(), - "python_interpreter": attr.string(default="python3"), + "python_interpreter": attr.string(default = "python3"), "python_interpreter_target": attr.label(allow_single_file = True, doc = """ If you are using a custom python interpreter built by another repository rule, use this attribute to specify its BUILD target. This allows pip_repository to invoke @@ -61,11 +61,12 @@ # 600 is documented as default here: https://docs.bazel.build/versions/master/skylark/lib/repository_ctx.html#execute "timeout": attr.int(default = 600), }, - implementation=_pip_repository_impl, + implementation = _pip_repository_impl, ) - -def pip_install(requirements, name=DEFAULT_REPOSITORY_NAME, **kwargs): +def pip_install(requirements, name = DEFAULT_REPOSITORY_NAME, **kwargs): pip_repository( - name=name, requirements=requirements, **kwargs + name = name, + requirements = requirements, + **kwargs )
diff --git a/extract_wheels/__init__.py b/extract_wheels/__init__.py index 390dcd0..89c7c59 100644 --- a/extract_wheels/__init__.py +++ b/extract_wheels/__init__.py
@@ -65,9 +65,10 @@ ) args = parser.parse_args() + pip_args = [sys.executable, "-m", "pip", "wheel", "-r", args.requirements] # Assumes any errors are logged by pip so do nothing. This command will fail if pip fails subprocess.check_output( - [sys.executable, "-m", "pip", "wheel", "-r", args.requirements] + pip_args ) extras = requirements.parse_extras(args.requirements)