Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support references between requirements files #58

Closed
jab opened this issue Jun 3, 2024 · 5 comments · Fixed by #63
Closed

Support references between requirements files #58

jab opened this issue Jun 3, 2024 · 5 comments · Fixed by #63

Comments

@jab
Copy link

jab commented Jun 3, 2024

requirements files support referring to other requirements (or constraints) files (by beginning a line with -r or -c). Composing requirements files thus is required to support correct, DRY, layered requirements (e.g. test dependencies should be constrained by runtime dependencies).

I tried using a requirements.in file that uses -c with rules_uv's pip_compile rule, but didn't see any way to specify the other requirements files that it references e.g. as data dependencies, so unsurprisingly it failed when I ran the pip_compile target. Would it make sense to add support for this?

Thanks for maintaining rules_uv! <3

@jab
Copy link
Author

jab commented Jun 3, 2024

Just realized that accepting data dependencies might also be necessary to support requirements files that use -e/--editable.

@mark-thm
Copy link
Collaborator

mark-thm commented Jun 4, 2024

This ruleset aims to be a drop-in replacement for https://rules-python.readthedocs.io/en/stable/api/pip.html#compile-pip-requirements — is that what you’re presently using/could you share an example of your configuration?

@jab
Copy link
Author

jab commented Jun 6, 2024

rules_python's compile_pip_requirements does support this.

An example that should be fairly quick to reproduce would be to clone https://github.com/jab/shorty and make the following 1-line change:

diff --git a/requirements.test.in b/requirements.test.in
index b998a06..a5eb409 100644
--- a/requirements.test.in
+++ b/requirements.test.in
@@ -1 +1,2 @@
+-c ./requirements.base.txt
 absl-py

This allows the dependency resolution for the test environment to take into account the already-resolved dependencies of the base environment (so the test deps can be smoothly layered on top).

If you try to compile this with rules_uv, it currently fails:

❯ bazel run :compile_test_requirements
INFO: Analyzed target //:compile_test_requirements (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //:compile_test_requirements up-to-date:
  bazel-bin/compile_test_requirements
INFO: Elapsed time: 0.087s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/compile_test_requirements
error: Error parsing included file in `requirements.test.in` at position 0
  Caused by: failed to read from file `./requirements.base.txt`
  Caused by: No such file or directory (os error 2)

Of course, if you directly invoke uv outside the sandbox to compile this, it works just fine, since it can access the referenced requirements file:

❯ uv pip compile --python bazel-bin/app.runfiles/.app.venv/bin/python requirements.test.in
Resolved 1 package in 2ms
# This file was autogenerated by uv via the following command:
#    uv pip compile --python bazel-bin/app.runfiles/.app.venv/bin/python requirements.test.in
absl-py==2.1.0
    # via -r requirements.test.in

@mark-thm
Copy link
Collaborator

Fixed in #63

@jab
Copy link
Author

jab commented Jun 21, 2024

Thanks for fixing this! Looking forward to picking it up in the next release.

(Also, just corrected the first sentence in my previous comment - rules_python's compile_pip_requirements does support this already.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants