8000 Add extra_pip_args option to pip_import by scarito1 · Pull Request #274 · bazel-contrib/rules_python · GitHub
[go: up one dir, main page]

Skip to content

Add extra_pip_args option to pip_import #274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packaging/piptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
16 changes: 13 additions & 3 deletions python/pip.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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.",
),
"python_interpreter": attr.string(default = "python", doc = """
The command to run the Python interpreter used to invoke pip and unpack the
wheels.
Expand Down
Binary file modified tools/piptool.par
Binary file not shown.
0