Skip to content

Commit bad3c20

Browse files
committed
feat(pip_repository): Enable PyPi dep cycles
This patch adjusts the pip_repository interface to accept a new parameter: `composite_libs`, being a list of PyPi package names which form a cycle and must be installed together. The intuition behind this design is that a dependency cycle {a <-> b} is implemented simply as emplacing both a and b at once. Hence a dependency graph {c -> a, c -> b} has the same effect. If we modify the installation of a and b to remove their mutual dependency, and generate a c which dominates a and b, we can then modify the `requirement()` and `whl_requirement()` helper functions to recognize the requirements a and b and provide a reference to c instead.
1 parent 693a158 commit bad3c20

17 files changed

Lines changed: 446 additions & 62 deletions

docs/pip_repository.md

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

examples/pip_parse_vendored/BUILD.bazel

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
22
load("@bazel_skylib//rules:write_file.bzl", "write_file")
3+
load("@rules_python//python:defs.bzl", "py_test")
34
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
5+
load("//:requirements.bzl", "requirement")
46

57
# This rule adds a convenient way to update the requirements.txt
68
# lockfile based on the requirements.in.
@@ -20,8 +22,10 @@ genrule(
2022
# Replace the bazel 6.0.0 specific comment with something that bazel 5.4.0 would produce.
2123
# This enables this example to be run as a test under bazel 5.4.0.
2224
"""sed -e 's#@//#//#'""",
23-
"""sed 's#"@python39_.*//:bin/python3"#interpreter#' >$@""",
24-
]),
25+
"""sed 's#"@python39_.*//:bin/python3"#interpreter#'""",
26+
# Stick some buildifiler disables in as needed
27+
"""sed 's/^def /# buildifier: disable=function-docstring\\\ndef /g'""",
28+
]) + " >$@",
2529
)
2630

2731
write_file(
@@ -50,3 +54,13 @@ diff_test(
5054
file1 = "requirements.bzl",
5155
file2 = ":make_platform_agnostic",
5256
)
57+
58+
py_test(
59+
name = "test",
60+
srcs = ["test.py"],
61+
deps = [
62+
requirement("oletools"),
63+
requirement("pcodedmp"),
64+
requirement("requests"),
65+
],
66+
)

examples/pip_parse_vendored/WORKSPACE

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ load("@rules_python//python:pip.bzl", "pip_parse")
2121
# It also wouldn't be needed by users of this ruleset.
2222
pip_parse(
2323
name = "pip",
24+
composite_libs = {
25+
"vbap": [
26+
"oletools",
27+
"pcodedmp",
28+
],
29+
},
2430
python_interpreter_target = interpreter,
2531
requirements_lock = "//:requirements.txt",
2632
)

0 commit comments

Comments
 (0)