rules_python icon indicating copy to clipboard operation
rules_python copied to clipboard

Skip comments in the files that `requirements_test` compares

Open iphan opened this issue 1 year ago • 2 comments

🚀 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.

iphan avatar Jun 14 '24 19:06 iphan

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.

aignas avatar Jun 17 '24 01:06 aignas

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

Thank you

iphan avatar Jun 19 '24 00:06 iphan

I am going to close the PR since rules_python has functionality to specify different lock files for different platforms and rules_uv exists. Please look at the docs for rules_uv here: https://github.com/theoremlp/rules_uv/tree/main until we have support for uv ourselves.

aignas avatar Nov 13 '24 08:11 aignas