Allow overriding config attrs in pip_parse-generated install_deps (#751)
diff --git a/examples/pip_parse_vendored/README.md b/examples/pip_parse_vendored/README.md
index 616e291..f53260a 100644
--- a/examples/pip_parse_vendored/README.md
+++ b/examples/pip_parse_vendored/README.md
@@ -9,3 +9,23 @@
- 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 58c6e7b..33199b0 100644
--- a/examples/pip_parse_vendored/requirements.bzl
+++ b/examples/pip_parse_vendored/requirements.bzl
@@ -41,11 +41,13 @@
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 5762cf5..d0abcac 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 @@
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,