Skip to content

Commit 6324e15

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 6324e15

14 files changed

Lines changed: 517 additions & 64 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: 18 additions & 4 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.
@@ -15,13 +17,15 @@ genrule(
1517
outs = ["requirements.clean.bzl"],
1618
cmd = " | ".join([
1719
"cat $<",
18-
# Insert our load statement after the existing one so we don't produce a file with buildifier warnings
19-
"""sed -e '/^load.*/i\\'$$'\\n''load("@python39//:defs.bzl", "interpreter")'""",
20+
# Insert our load statement for the interpreter
21+
"""sed -e '7 i \\\nload("@python39//:defs.bzl", "interpreter")\n'""",
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
@@ -22,6 +22,12 @@ load("@rules_python//python:pip.bzl", "pip_parse")
2222
pip_parse(
2323
name = "pip",
2424
python_interpreter_target = interpreter,
25+
requirement_clusters = {
26+
"vbap": [
27+
"oletools",
28+
"pcodedmp",
29+
],
30+
},
2531
requirements_lock = "//:requirements.txt",
2632
)
2733

0 commit comments

Comments
 (0)