Skip to content

Commit

Permalink
feat(pip_repository): Enable PyPi dep cycles
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
arrdem committed May 18, 2023
1 parent 693a158 commit 6324e15
Show file tree
Hide file tree
Showing 14 changed files with 517 additions and 64 deletions.
8 changes: 5 additions & 3 deletions docs/pip_repository.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 18 additions & 4 deletions examples/pip_parse_vendored/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@rules_python//python:defs.bzl", "py_test")
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
load("//:requirements.bzl", "requirement")

# This rule adds a convenient way to update the requirements.txt
# lockfile based on the requirements.in.
Expand All @@ -15,13 +17,15 @@ genrule(
outs = ["requirements.clean.bzl"],
cmd = " | ".join([
"cat $<",
# Insert our load statement after the existing one so we don't produce a file with buildifier warnings
"""sed -e '/^load.*/i\\'$$'\\n''load("@python39//:defs.bzl", "interpreter")'""",
# Insert our load statement for the interpreter
"""sed -e '7 i \\\nload("@python39//:defs.bzl", "interpreter")\n'""",
# Replace the bazel 6.0.0 specific comment with something that bazel 5.4.0 would produce.
# This enables this example to be run as a test under bazel 5.4.0.
"""sed -e 's#@//#//#'""",
"""sed 's#"@python39_.*//:bin/python3"#interpreter#' >$@""",
]),
"""sed 's#"@python39_.*//:bin/python3"#interpreter#'""",
# Stick some buildifiler disables in as needed
"""sed 's/^def /# buildifier: disable=function-docstring\\\ndef /g'""",
]) + " >$@",
)

write_file(
Expand Down Expand Up @@ -50,3 +54,13 @@ diff_test(
file1 = "requirements.bzl",
file2 = ":make_platform_agnostic",
)

py_test(
name = "test",
srcs = ["test.py"],
deps = [
requirement("oletools"),
requirement("pcodedmp"),
requirement("requests"),
],
)
6 changes: 6 additions & 0 deletions examples/pip_parse_vendored/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ load("@rules_python//python:pip.bzl", "pip_parse")
pip_parse(
name = "pip",
python_interpreter_target = interpreter,
requirement_clusters = {
"vbap": [
"oletools",
"pcodedmp",
],
},
requirements_lock = "//:requirements.txt",
)

Expand Down
Loading

0 comments on commit 6324e15

Please sign in to comment.