bazelbuild / rules_python

Bazel Python Rules
https://rules-python.readthedocs.io
Apache License 2.0
517 stars 530 forks source link

Skip comments in the files that `requirements_test` compares #1970

Open iphan opened 2 months ago

iphan commented 2 months ago

🚀 feature request

Relevant Rules

compile_pip_requirements rule

Description

compile_pip_requirements rule adds a requirements_test, which we use in our CI to validate the generated files: it runs the requirements.update bazel command and compares its output to the requirements.txt file stored in our repo. We hit a strange issue with pip-compile where the files generated on our local vs. CI differs only in the comments, causing the test to fail only on CI. For example, file generated on local only has

    # via -r requirements.in

whereas file generated on CI includes

    # via
    #   -r requirements.in
    #   keyring

Describe the solution you'd like

Would it be possible to skip the comments when requirements_test is comparing the generated requirements.txt files?

Describe alternatives you've considered

add --no-annotate as an extra-arg, so pip-compile does not to write comments. But ideally we'd like to keep this information as it is still useful to understand where each dependency comes from.

aignas commented 2 months ago

Since the comparison is happening in Python, that could be doable, however, this would deviate from rules_uv because it is not dropping comments.

However, the fact that your requirements.txt has different comments suggests that you are trying to reuse a requirements.txt generated on a different OS/Arch. For proper handling of such cases, consider using rules_uv that has support for this.

iphan commented 2 months ago

Can you say more about how to use rules_uv for this case?

Thank you