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 annotations on pip packages with extras. #865

Merged

Conversation

william-smith-skydio
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

  • 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:

What is the current behavior?

When using pip_parse with packages with extras, e.g. requests[security]>=2.8.1, it is not possible to add annotations. The requests package will otherwise work correctly, but trying to add an annotation to requests will not result in the annotation actually being applied. This is because annotations have separate logic for parsing requirements in the generated .bzl file. It would previously turn the requirement into requests[security] rather than just requests and fail to match, as just requests is expected.

What is the new behavior?

The custom parsing logic has been changed to support extras, e.g. requests[security]>=2.8.1.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

E.g., the following requirement:

```
requests[security]>=2.8.1
```

This is handled correctly by all of the other plumbing, but trying
to add an annotation to `requests` will fail. This is because
annotations have separate logic for parsing requirements in the
generated .bzl file. It would previously turn the requirement into
`requests[security]` rather than just `requests`.
Copy link
Collaborator

@f0rmiga f0rmiga left a comment

Choose a reason for hiding this comment

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

LGTM. @hrfuller could you take a second pass, please?

Copy link
Contributor

@hrfuller hrfuller left a comment

Choose a reason for hiding this comment

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

LGTM as well. IIRC the requirement strings come from the requirements lock file. Ideal the lock file should have "simple" requirement strings and then extras should just be on their own lines in the lock file. Given that pip_compile doesn't work like that this seems like the best solution.

@hrfuller hrfuller merged commit bd42ad2 into bazelbuild:main Nov 4, 2022
ianpegg-bc pushed a commit to ianpegg-bc/rules_python that referenced this pull request May 12, 2023
* Support annotations on pip packages with extras.

E.g., the following requirement:

```
requests[security]>=2.8.1
```

This is handled correctly by all of the other plumbing, but trying
to add an annotation to `requests` will fail. This is because
annotations have separate logic for parsing requirements in the
generated .bzl file. It would previously turn the requirement into
`requests[security]` rather than just `requests`.

* Add test verifying that annotations work for packages with extras.
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 this pull request may close these issues.

None yet

3 participants