Skip to content

Commit 6a43ebd

Browse files
Add option to use "pip download" instead of "pip wheel" to download wheels for other platforms (bazel-contrib#773)
1 parent e0a7829 commit 6a43ebd

File tree

6 files changed

+28
-10
lines changed

6 files changed

+28
-10
lines changed

docs/pip_repository.md

Lines changed: 9 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/pip_parse_vendored/requirements.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ all_requirements = ["@pip_certifi//:pkg", "@pip_charset_normalizer//:pkg", "@pip
1212
all_whl_requirements = ["@pip_certifi//:whl", "@pip_charset_normalizer//:whl", "@pip_idna//:whl", "@pip_requests//:whl", "@pip_urllib3//:whl"]
1313

1414
_packages = [("pip_certifi", "certifi==2021.10.8 --hash=sha256:78884e7c1d4b00ce3cea67b44566851c4343c120abd683433ce934a68ea58872 --hash=sha256:d62a0163eb4c2344ac042ab2bdf75399a71a2d8c7d47eac2e2ee91b9d6339569"), ("pip_charset_normalizer", "charset-normalizer==2.0.12 --hash=sha256:2857e29ff0d34db842cd7ca3230549d1a697f96ee6d3fb071cfa6c7393832597 --hash=sha256:6881edbebdb17b39b4eaaa821b438bf6eddffb4468cf344f09f89def34a8b1df"), ("pip_idna", "idna==3.3 --hash=sha256:84d9dd047ffa80596e0f246e2eab0b391788b0503584e8945f2368256d2735ff --hash=sha256:9d643ff0a55b762d5cdb124b8eaa99c66322e2157b69160bc32796e824360e6d"), ("pip_requests", "requests==2.27.1 --hash=sha256:68d7c56fd5a8999887728ef304a6d12edc7be74f1cfa47714fc8b414525c9a61 --hash=sha256:f22fa1e554c9ddfd16e6e41ac79759e17be9e492b3587efa038054674760e72d"), ("pip_urllib3", "urllib3==1.26.9 --hash=sha256:44ece4d53fb1706f667c9bd1c648f5469a2ec925fcf3a776667042d645472c14 --hash=sha256:aabaf16477806a5e1dd19aa41f8c2b7950dd3c746362d7e3223dbe6de6ac448e")]
15-
_config = {"enable_implicit_namespace_pkgs": False, "environment": {}, "extra_pip_args": [], "isolated": True, "pip_data_exclude": [], "python_interpreter": "python3", "python_interpreter_target": interpreter, "quiet": True, "repo": "pip", "repo_prefix": "pip_", "timeout": 600}
15+
_config = {"download_only": False, "enable_implicit_namespace_pkgs": False, "environment": {}, "extra_pip_args": [], "isolated": True, "pip_data_exclude": [], "python_interpreter": "python3", "python_interpreter_target": interpreter, "quiet": True, "repo": "pip", "repo_prefix": "pip_", "timeout": 600}
1616
_annotations = {}
1717

1818
def _clean_name(name):

python/pip_install/extract_wheels/arguments.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ def parse_common_args(parser: ArgumentParser) -> ArgumentParser:
3939
required=True,
4040
help="Prefix to prepend to packages",
4141
)
42+
parser.add_argument(
43+
"--download_only",
44+
action="store_true",
45+
help="Use 'pip download' instead of 'pip wheel'. Disables building wheels from source, but allows use of "
46+
"--platform, --python-version, --implementation, and --abi in --extra_pip_args.",
47+
)
4248
return parser
4349

4450

python/pip_install/extract_wheels/extract_single_wheel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def main() -> None:
3838
pip_args = (
3939
[sys.executable, "-m", "pip"]
4040
+ (["--isolated"] if args.isolated else [])
41-
+ ["wheel", "--no-deps"]
41+
+ ["download" if args.download_only else "wheel", "--no-deps"]
4242
+ deserialized_args["extra_pip_args"]
4343
)
4444

python/pip_install/extract_wheels/extract_wheels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def main() -> None:
8080
pip_args = (
8181
[sys.executable, "-m", "pip"]
8282
+ (["--isolated"] if args.isolated else [])
83-
+ ["wheel", "-r", args.requirements]
83+
+ ["download" if args.download_only else "wheel", "-r", args.requirements]
8484
+ ["--wheel-dir", os.getcwd()]
8585
+ deserialized_args["extra_pip_args"]
8686
)

python/pip_install/pip_repository.bzl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ def _parse_optional_attrs(rctx, args):
130130
struct(arg = rctx.attr.extra_pip_args).to_json(),
131131
]
132132

133+
if rctx.attr.download_only:
134+
args.append("--download_only")
135+
133136
if rctx.attr.pip_data_exclude != None:
134137
args += [
135138
"--pip_data_exclude",
@@ -250,6 +253,13 @@ common_env = [
250253
]
251254

252255
common_attrs = {
256+
"download_only": attr.bool(
257+
doc = """
258+
Whether to use "pip download" instead of "pip wheel". Disables building wheels from source, but allows use of
259+
--platform, --python-version, --implementation, and --abi in --extra_pip_args to download wheels for a different
260+
platform from the host platform.
261+
""",
262+
),
253263
"enable_implicit_namespace_pkgs": attr.bool(
254264
default = False,
255265
doc = """

0 commit comments

Comments
 (0)