Skip to content

Implement a --group flag for dependency-group parsing for pip-compile #2175

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

sirosen
Copy link
Member

@sirosen sirosen commented Apr 23, 2025

Resolves #2062 1

This is an initial proposed implementation, but even after finishing it, I have two major outstanding questions.

Q1: Should --group be considered a source file?

I didn't merge parsed --group inputs into src_files, but I did count len(src_files) + len(groups) in a couple of contexts to make it behave similarly.
I'm not sure if this was the right approach, or if I missed or misunderstood the goals of the src_files checking in any way.

Extra attention in this area during review would be appreciated -- as a new contributor, I did my best to follow the existing code and keep the changes small, but may have made mistakes.

Q2: What tests are missing?

The iniital tests are pretty simple and limited. Probably, more tests would be worthwhile, but it's hard to tell what cases would be useful vs redundant with existing tests.
What additional checks seem important?

Note: Accepts pyproject.toml:X and pyproject.toml::X

Both : and :: syntax are accepted, noted in helptext with double-: as [pyproject-path::]groupname.

I decided on this after weighing the options from #2062 and would be willing to adjust if there's a strong objection, but think this is the best approach.
pip-compile can have its own syntax, but accepting the pip install syntax is an easy gain for compatibility.

Because the filename part is already optional, the behavior which handles output of options also naturally handles the : vs :: variation.

Commits

  • Add --group to pip-compile options
  • Implement dependency-groups parsing, based on pip
  • Preserve input arg for --group when writing output
  • Add tests for [dependency-groups]

Checklists

Contributor checklist
  • Included tests for the changes.
  • PR title is short, clear, and ready to be included in the user-facing changelog.
Maintainer checklist
  • Verified one of these labels is present: backwards incompatible, feature, enhancement, deprecation, bug, dependency, docs or skip-changelog as they determine changelog listing.
  • Assign the PR to an existing or new milestone for the target version (following Semantic Versioning).

Footnotes

  1. Aside: sorry it took so long to submit a PR! This has been on my to-do list for a while.

sirosen added 6 commits April 21, 2025 21:57
Define the option, but don't implement any behavior other than parsing
yet.

This is defined very similarly to `--group` for `pip` commands, but
allows for a double-colon as a delimiter, rather than requiring
only one.
Import and adapt the dependency-groups support code from within pip,
for use in the pip-compile CLI context.
When parsing `--group` inputs, use a custom type to record the input
argument value. This allows the writer to more accurately reproduce
the input command as part of the output.
And apply fixes and changes as required.
Tests include a simple positive test case and a number of error
checking cases for different scenarios.

Minor fixes to output are needed and `--group` is treated as an
alternative to having a source file when determining whether or not
sufficient input options were given.
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.

Eventually implement support for the PEP 735 "dependency groups"
1 participant