8000 compile_pip_requirements: Fix defaulted macro args behaviour by thundergolfer · Pull Request #467 · bazel-contrib/rules_python · GitHub
[go: up one dir, main page]

Skip to content

Conversation

thundergolfer
Copy link

What is the current behavior?

  • The requirements_in arg cannot be popped from **kwargs because it is a named argument. So the arg value is always: name + ".in"
  • The requirements_txt arg is actually set by passing requirements_locked to the macro. If you pass the latter, you can set the former. If you just pass the former, the arg value is always name + ".txt", similar to the above.

The result is that the .in file must always be ${name}.in and you have to set the lock file name via an undocumented kwarg.

What is the new behavior?

Both args are given None defaults which the macro body will immediately detect and replace with the name + ".in" and name + ".txt" value if needed.

With this change the following macro instantiation now works as expected:

compile_pip_requirements(
    name = "requirements_annotated",
    requirements_in = "requirements.in",
    requirements_locked = "requirements.annotated.txt",
)

I could have done requirements_in = requirements_in or name + ".in, but I wanted to explictly check fo None and not catch anything falsey.

Another alternative is keeping the = "requirements.in" defaulting and abandoning the defaulting to the name + <ext> setup.

PR Checklist

Please check if your PR fulfills the following requirements:

  • Does not include precompiled binaries, eg. .par files. See CONTRIBUTING.md for info
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature (please, look at the "Scope of the project" section in the README.md file)
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Does this PR introduce a breaking change?

  • Yes
  • No

Copy link
Contributor
@alexeagle alexeagle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!!

@alexeagle alexeagle merged commit ef4d735 into master May 8, 2021
@thundergolfer thundergolfer deleted the jonathon--compile_pip_requirements-fix-may2021 branch May 9, 2021 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0