diff --git a/examples/pip_parse_vendored/README.md b/examples/pip_parse_vendored/README.md index 616e291409..f53260a175 100644 --- a/examples/pip_parse_vendored/README.md +++ b/examples/pip_parse_vendored/README.md @@ -9,3 +9,23 @@ The requirements now form a triple: - requirements.in - human editable, expresses only direct dependencies and load-bearing version constraints - requirements.txt - lockfile produced by pip-compile or other means - requirements.bzl - the "parsed" version of the lockfile readable by Bazel downloader + +The `requirements.bzl` file contains baked-in attributes such as `python_interpreter_target` as they were specified in the original `pip_parse` rule. These can be overridden at install time by passing arguments to `install_deps`. For example: + +```python +# Register a hermetic toolchain +load("@rules_python//python:repositories.bzl", "python_register_toolchains") + +python_register_toolchains( + name = "python39", + python_version = "3.9", +) +load("@python39//:defs.bzl", "interpreter") + +# Load dependencies vendored by some other ruleset. +load("@some_rules//:py_deps.bzl", "install_deps") + +install_deps( + python_interpreter_target = interpreter, +) +``` diff --git a/examples/pip_parse_vendored/requirements.bzl b/examples/pip_parse_vendored/requirements.bzl index 58c6e7bad1..33199b07aa 100644 --- a/examples/pip_parse_vendored/requirements.bzl +++ b/examples/pip_parse_vendored/requirements.bzl @@ -41,11 +41,13 @@ def _get_annotation(requirement): name = requirement.split(" ")[0].split("=")[0] return _annotations.get(name) -def install_deps(): +def install_deps(**whl_library_kwargs): + whl_config = dict(_config) + whl_config.update(whl_library_kwargs) for name, requirement in _packages: whl_library( name = name, requirement = requirement, annotation = _get_annotation(requirement), - **_config + **whl_config ) diff --git a/python/pip_install/extract_wheels/parse_requirements_to_bzl.py b/python/pip_install/extract_wheels/parse_requirements_to_bzl.py index 5762cf542c..d0abcac891 100644 --- a/python/pip_install/extract_wheels/parse_requirements_to_bzl.py +++ b/python/pip_install/extract_wheels/parse_requirements_to_bzl.py @@ -158,13 +158,15 @@ def _get_annotation(requirement): name = requirement.split(" ")[0].split("=")[0] return _annotations.get(name) - def install_deps(): + def install_deps(**whl_library_kwargs): + whl_config = dict(_config) + whl_config.update(whl_library_kwargs) for name, requirement in _packages: whl_library( name = name, requirement = requirement, annotation = _get_annotation(requirement), - **_config + **whl_config ) """.format( all_requirements=all_requirements,