From 07c3f8547abbd5b97839a48af226a0fbcfaa5e7c Mon Sep 17 00:00:00 2001 From: Timothy Trippel Date: Tue, 12 Apr 2022 16:25:05 -0700 Subject: [PATCH 1/2] support pip "--find-links" argument for airgapped `pip_install()` Signed-off-by: Timothy Trippel --- python/pip_install/extract_wheels/__init__.py | 7 +++++++ python/pip_install/pip_repository.bzl | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/python/pip_install/extract_wheels/__init__.py b/python/pip_install/extract_wheels/__init__.py index cda6d541b0..334a6f8912 100644 --- a/python/pip_install/extract_wheels/__init__.py +++ b/python/pip_install/extract_wheels/__init__.py @@ -58,6 +58,12 @@ def main() -> None: parser = argparse.ArgumentParser( description="Resolve and fetch artifacts transitively from PyPI" ) + parser.add_argument( + "--find-links", + type=str, + default=None, + help="Directory to look for archives such as sdist or wheel files.", + ) parser.add_argument( "--requirements", action="store", @@ -82,6 +88,7 @@ def main() -> None: + (["--isolated"] if args.isolated else []) + ["wheel", "-r", args.requirements] + ["--wheel-dir", os.getcwd()] + + (["--find-links", "{}/../{}".format(os.getcwd(), args.find_links)] if args.find_links else []) + deserialized_args["extra_pip_args"] ) diff --git a/python/pip_install/pip_repository.bzl b/python/pip_install/pip_repository.bzl index e587f34c73..9e955f99a5 100644 --- a/python/pip_install/pip_repository.bzl +++ b/python/pip_install/pip_repository.bzl @@ -160,6 +160,10 @@ def _pip_repository_impl(rctx): "--annotations", annotations_file, ] + + # TODO: move this in to _parse_optional_attrs() + if rctx.attr.find_links: + args += ["--find-links", rctx.attr.find_links.workspace_name] progress_message = "Extracting wheels" args += ["--repo", rctx.attr.name, "--repo-prefix", rctx.attr.repo_prefix] @@ -211,6 +215,12 @@ can be passed. "extra_pip_args": attr.string_list( doc = "Extra arguments to pass on to pip. Must not contain spaces.", ), + "find_links": attr.label( + doc = """\ +The [--find-links](https://pip.pypa.io/en/stable/cli/pip_wheel/#cmdoption-f) to +pass to the underlying pip command. +""", + ), "isolated": attr.bool( doc = """\ Whether or not to pass the [--isolated](https://pip.pypa.io/en/stable/cli/pip/#cmdoption-isolated) flag to From 67923e883055451b39b44fd09b00aeb2fc08e604 Mon Sep 17 00:00:00 2001 From: Noah Moroze Date: Thu, 27 Mar 2025 11:00:19 -0400 Subject: [PATCH 2/2] Update pkginfo This fixes a regression where an exception is raised when setting up OpenTitan's Python dependencies: .../.cache/bazel/.../.../external/rules_python/python/pip_install/extract_wheels/lib/wheel.py", line 57, in entry_points name = "{}-{}".format(metadata.name.replace("-", "_"), metadata.version) AttributeError: 'NoneType' object has no attribute 'replace' The issue seems related to the previous version of pkginfo not being able to parse newer versions of Python package metadata, although the reason why this started failing all of a sudden has not been root caused. Signed-off-by: Noah Moroze --- python/pip_install/repositories.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/pip_install/repositories.bzl b/python/pip_install/repositories.bzl index 352f66341c..86921f313e 100644 --- a/python/pip_install/repositories.bzl +++ b/python/pip_install/repositories.bzl @@ -29,8 +29,8 @@ _RULE_DEPS = [ ), ( "pypi__pkginfo", - "https://files.pythonhosted.org/packages/cd/00/49f59cdd2c6a52e6665fda4de671dac5614366dc827e050c55428241b929/pkginfo-1.8.2-py2.py3-none-any.whl", - "c24c487c6a7f72c66e816ab1796b96ac6c3d14d49338293d2141664330b55ffc", + "https://files.pythonhosted.org/packages/fa/3d/f4f2ba829efb54b6cd2d91349c7463316a9cc55a43fc980447416c88540f/pkginfo-1.12.1.2-py3-none-any.whl", + "c783ac885519cab2c34927ccfa6bf64b5a704d7c69afaea583dd9b7afe969343", ), ( "pypi__setuptools",