diff --git a/docs/pip.md b/docs/pip.md index 037bdfa90b..73035fdfef 100755 --- a/docs/pip.md +++ b/docs/pip.md @@ -5,7 +5,7 @@ ## pip_import
-pip_import(name, python_interpreter, requirements)
+pip_import(name, extra_pip_args, python_interpreter, requirements)
 
A rule for importing `requirements.txt` dependencies into Bazel. @@ -67,6 +67,15 @@ py_binary(

+ + extra_pip_args + + List of strings; optional +

+ Extra arguments to pass on to pip. Must not contain spaces. +

+ + python_interpreter diff --git a/packaging/piptool.py b/packaging/piptool.py index 766a6742fd..ffae941064 100644 --- a/packaging/piptool.py +++ b/packaging/piptool.py @@ -102,6 +102,9 @@ def pip_main(argv): parser.add_argument('--directory', action='store', help=('The directory into which to put .whl files.')) +parser.add_argument('--extra_pip_args', action='store', + help=('Extra arguments to pass down to pip.')) + def determine_possible_extras(whls): """Determines the list of possible "extras" for each .whl @@ -160,7 +163,10 @@ def main(): args = parser.parse_args() # https://github.com/pypa/pip/blob/9.0.1/pip/__init__.py#L209 - if pip_main(["wheel", "-w", args.directory, "-r", args.input]): + pip_args = ["wheel", "-w", args.directory, "-r", args.input] + if args.extra_pip_args: + pip_args += args.extra_pip_args.strip("\"").split() + if pip_main(pip_args): sys.exit(1) # Enumerate the .whl files we downloaded. diff --git a/python/pip.bzl b/python/pip.bzl index 37da2a2cac..cae023f646 100644 --- a/python/pip.bzl +++ b/python/pip.bzl @@ -22,8 +22,7 @@ def _pip_import_impl(repository_ctx): # requirements.bzl without it. repository_ctx.file("BUILD", "") - # To see the output, pass: quiet=False - result = repository_ctx.execute([ + args = [ repository_ctx.attr.python_interpreter, repository_ctx.path(repository_ctx.attr._script), "--python_interpreter", @@ -36,13 +35,24 @@ def _pip_import_impl(repository_ctx): repository_ctx.path("requirements.bzl"), "--directory", repository_ctx.path(""), - ]) + ] + if repository_ctx.attr.extra_pip_args: + args += [ + "--extra_pip_args", + "\"" + " ".join(repository_ctx.attr.extra_pip_args) + "\"", + ] + + # To see the output, pass: quiet=False + result = repository_ctx.execute(args) if result.return_code: fail("pip_import failed: %s (%s)" % (result.stdout, result.stderr)) pip_import = repository_rule( attrs = { + "extra_pip_args": attr.string_list( + doc = "Extra arguments to pass on to pip. Must not contain spaces.", + ), "python_interpreter": attr.string(default = "python", doc = """ The command to run the Python interpreter used to invoke pip and unpack the wheels. diff --git a/tools/piptool.par b/tools/piptool.par index 57ef98d14e..2fa8909d0a 100755 Binary files a/tools/piptool.par and b/tools/piptool.par differ