Skip to content

Commit dd7f9c5

Browse files
brandjonscarito1
andauthored
Add extra_pip_args option to pip_import (bazel-contrib#274)
Adds the attr extra_pip_args to pip_import. These args will be passed along to the pip invocation inside piptool. Closes bazel-contrib#274 and closes bazel-contrib#278. Co-authored-by: scarito1 <scarito@google.com>
1 parent 7c0abe5 commit dd7f9c5

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

docs/pip.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
## pip_import
66

77
<pre>
8-
pip_import(<a href="#pip_import-name">name</a>, <a href="#pip_import-python_interpreter">python_interpreter</a>, <a href="#pip_import-requirements">requirements</a>)
8+
pip_import(<a href="#pip_import-name">name</a>, <a href="#pip_import-extra_pip_args">extra_pip_args</a>, <a href="#pip_import-python_interpreter">python_interpreter</a>, <a href="#pip_import-requirements">requirements</a>)
99
</pre>
1010

1111
A rule for importing `requirements.txt` dependencies into Bazel.
@@ -67,6 +67,15 @@ py_binary(
6767
</p>
6868
</td>
6969
</tr>
70+
<tr id="pip_import-extra_pip_args">
71+
<td><code>extra_pip_args</code></td>
72+
<td>
73+
List of strings; optional
74+
<p>
75+
Extra arguments to pass on to pip. Must not contain spaces.
76+
</p>
77+
</td>
78+
</tr>
7079
<tr id="pip_import-python_interpreter">
7180
<td><code>python_interpreter</code></td>
7281
<td>

packaging/piptool.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ def pip_main(argv):
102102
parser.add_argument('--directory', action='store',
103103
help=('The directory into which to put .whl files.'))
104104

105+
parser.add_argument('--extra_pip_args', action='store',
106+
help=('Extra arguments to pass down to pip.'))
107+
105108
def determine_possible_extras(whls):
106109
"""Determines the list of possible "extras" for each .whl
107110
@@ -160,7 +163,10 @@ def main():
160163
args = parser.parse_args()
161164

162165
# https://github.com/pypa/pip/blob/9.0.1/pip/__init__.py#L209
163-
if pip_main(["wheel", "-w", args.directory, "-r", args.input]):
166+
pip_args = ["wheel", "-w", args.directory, "-r", args.input]
167+
if args.extra_pip_args:
168+
pip_args += args.extra_pip_args.strip("\"").split()
169+
if pip_main(pip_args):
164170
sys.exit(1)
165171

166172
# Enumerate the .whl files we downloaded.

python/pip.bzl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ def _pip_import_impl(repository_ctx):
2222
# requirements.bzl without it.
2323
repository_ctx.file("BUILD", "")
2424

25-
# To see the output, pass: quiet=False
26-
result = repository_ctx.execute([
25+
args = [
2726
repository_ctx.attr.python_interpreter,
2827
repository_ctx.path(repository_ctx.attr._script),
2928
"--python_interpreter",
@@ -36,13 +35,24 @@ def _pip_import_impl(repository_ctx):
3635
repository_ctx.path("requirements.bzl"),
3736
"--directory",
3837
repository_ctx.path(""),
39-
])
38+
]
39+
if repository_ctx.attr.extra_pip_args:
40+
args += [
41+
"--extra_pip_args",
42+
"\"" + " ".join(repository_ctx.attr.extra_pip_args) + "\"",
43+
]
44+
45+
# To see the output, pass: quiet=False
46+
result = repository_ctx.execute(args)
4047

4148
if result.return_code:
4249
fail("pip_import failed: %s (%s)" % (result.stdout, result.stderr))
4350

4451
pip_import = repository_rule(
4552
attrs = {
53+
"extra_pip_args": attr.string_list(
54+
doc = "Extra arguments to pass on to pip. Must not contain spaces.",
55+
),
4656
"python_interpreter": attr.string(default = "python", doc = """
4757
The command to run the Python interpreter used to invoke pip and unpack the
4858
wheels.

tools/piptool.par

460 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy