-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update
compile_pip_requirements
to support multiple input fil…
…es (#1067) `pip-compile` can compile multiple input files into a single output file, but `rules_python`'s `compile_pip_requirements` doesn't currently support this. With this change, the `requirements_in` argument to `compile_pip_requirements` can now accept a list of strings (in addition to the previously accepted argument types). In order to support a variable number of input files, my coworker (@lpulley) and I updated `dependency_resolver.py` to use the `click` CLI library. We felt this was acceptable since `pip-compile` already requires `click` to run, so we're not adding a new dependency. We also made changes to the script to avoid mutating `sys.argv`, instead opting to build a new list (`argv`) from scratch that'll be passed to the `pip-compile` CLI. While subjective, I feel this improves readability, since it's not immediately obvious what's in `sys.argv`, but it's clear that `argv` begins empty, and is added to over the course of the program's execution. --------- Co-authored-by: Logan Pulley <[email protected]> Co-authored-by: Ignas Anikevicius <[email protected]> Co-authored-by: Richard Levasseur <[email protected]>
- Loading branch information
1 parent
0d6d8f3
commit e923f9e
Showing
12 changed files
with
130 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
load("@rules_python//python:pip.bzl", "compile_pip_requirements") | ||
|
||
compile_pip_requirements( | ||
name = "multiple_requirements_in", | ||
srcs = [ | ||
"requirements_1.in", | ||
"requirements_2.in", | ||
], | ||
requirements_txt = "multiple_requirements_in.txt", | ||
) | ||
|
||
compile_pip_requirements( | ||
name = "multiple_pyproject_toml", | ||
srcs = [ | ||
"a/pyproject.toml", | ||
"b/pyproject.toml", | ||
], | ||
requirements_txt = "multiple_pyproject_toml.txt", | ||
) | ||
|
||
compile_pip_requirements( | ||
name = "multiple_inputs", | ||
srcs = [ | ||
"a/pyproject.toml", | ||
"b/pyproject.toml", | ||
"requirements_1.in", | ||
"requirements_2.in", | ||
], | ||
requirements_txt = "multiple_inputs.txt", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# multiple_inputs | ||
|
||
Test that `compile_pip_requirements` works as intended when using more than one input file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[project] | ||
name = "multiple_inputs_1" | ||
version = "0.0.0" | ||
|
||
dependencies = ["urllib3"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[project] | ||
name = "multiple_inputs_2" | ||
version = "0.0.0" | ||
|
||
dependencies = ["attrs"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# | ||
# This file is autogenerated by pip-compile with Python 3.11 | ||
# by the following command: | ||
# | ||
# bazel run //tests/multiple_inputs:multiple_inputs.update | ||
# | ||
attrs==23.1.0 \ | ||
--hash=sha256:1f28b4522cdc2fb4256ac1a020c78acf9cba2c6b461ccd2c126f3aa8e8335d04 \ | ||
--hash=sha256:6279836d581513a26f1bf235f9acd333bc9115683f14f7e8fae46c98fc50e015 | ||
# via | ||
# -r tests/multiple_inputs/requirements_2.in | ||
# multiple_inputs_2 (tests/multiple_inputs/b/pyproject.toml) | ||
urllib3==2.0.7 \ | ||
--hash=sha256:c97dfde1f7bd43a71c8d2a58e369e9b2bf692d1334ea9f9cae55add7d0dd0f84 \ | ||
--hash=sha256:fdb6d215c776278489906c2f8916e6e7d4f5a9b602ccbcfdf7f016fc8da0596e | ||
# via | ||
# -r tests/multiple_inputs/requirements_1.in | ||
# multiple_inputs_1 (tests/multiple_inputs/a/pyproject.toml) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# | ||
# This file is autogenerated by pip-compile with Python 3.11 | ||
# by the following command: | ||
# | ||
# bazel run //tests/multiple_inputs:multiple_pyproject_toml.update | ||
# | ||
attrs==23.1.0 \ | ||
--hash=sha256:1f28b4522cdc2fb4256ac1a020c78acf9cba2c6b461ccd2c126f3aa8e8335d04 \ | ||
--hash=sha256:6279836d581513a26f1bf235f9acd333bc9115683f14f7e8fae46c98fc50e015 | ||
# via multiple_inputs_2 (tests/multiple_inputs/b/pyproject.toml) | ||
urllib3==2.0.7 \ | ||
--hash=sha256:c97dfde1f7bd43a71c8d2a58e369e9b2bf692d1334ea9f9cae55add7d0dd0f84 \ | ||
--hash=sha256:fdb6d215c776278489906c2f8916e6e7d4f5a9b602ccbcfdf7f016fc8da0596e | ||
# via multiple_inputs_1 (tests/multiple_inputs/a/pyproject.toml) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# | ||
# This file is autogenerated by pip-compile with Python 3.11 | ||
# by the following command: | ||
# | ||
# bazel run //tests/multiple_inputs:multiple_requirements_in.update | ||
# | ||
attrs==23.1.0 \ | ||
--hash=sha256:1f28b4522cdc2fb4256ac1a020c78acf9cba2c6b461ccd2c126f3aa8e8335d04 \ | ||
--hash=sha256:6279836d581513a26f1bf235f9acd333bc9115683f14f7e8fae46c98fc50e015 | ||
# via -r tests/multiple_inputs/requirements_2.in | ||
urllib3==2.0.7 \ | ||
--hash=sha256:c97dfde1f7bd43a71c8d2a58e369e9b2bf692d1334ea9f9cae55add7d0dd0f84 \ | ||
--hash=sha256:fdb6d215c776278489906c2f8916e6e7d4f5a9b602ccbcfdf7f016fc8da0596e | ||
# via -r tests/multiple_inputs/requirements_1.in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
urllib3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
attrs |