Skip to content

Refactor the --color option implementation and add unit tests - #2458

Merged
webknjaz merged 2 commits into
pypa:mainfrom
sirosen:testing/coverage/color-opt
Oct 15, 2026
Merged

webknjaz merged 2 commits into
pypa:mainfrom
sirosen:testing/coverage/color-opt

Conversation

@sirosen

@sirosen sirosen commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor
  1. Set expose_value=False so that pip-compile is not responsible for handling the logic which more naturally belongs inside of the flag implementation itself.

  2. Implement that logic using a callback.

  3. Add unit tests for the flag, in isolation from pip-compile.


No changelog needed. Yet another step towards complete test coverage. (See #2347 and #2264 for context.)

This is open as a draft because it modifies the same test file as #2457, and is therefore blocked on that PR.
It's also a good checkpoint for this body of work and will be the last one I open for today. I did as many as I could, implementing a series of isolated changes, and this was the first naturally occurring collision between two of these improvements (they both need a unit test module for the CLI options).

Update: this should now be ready. 😄

Contributor checklist
  • Included tests for the changes.
  • A change note is created in changelog.d/ (see changelog.d/README.md
    for instructions) or the PR text says "no changelog needed".
Maintainer checklist
  • If no changelog is needed, apply the bot:chronographer:skip label.
  • Assign the PR to an existing or new milestone for the target version
    (following Semantic Versioning).

@sirosen sirosen added this to the 7.6.2 milestone Aug 13, 2026
@sirosen
sirosen requested a review from a team August 13, 2026 01:17
@sirosen sirosen added the bot:chronographer:skip A mark meaning no public change log needed for the patch. label Aug 13, 2026
@sirosen
sirosen marked this pull request as draft August 13, 2026 01:17
@sirosen
sirosen force-pushed the testing/coverage/color-opt branch from 5dc4e0d to d1ce0e1 Compare August 15, 2026 01:40
@sirosen
sirosen marked this pull request as ready for review August 15, 2026 01:40
@sirosen sirosen mentioned this pull request Aug 22, 2026
4 tasks done
@sirosen
sirosen force-pushed the testing/coverage/color-opt branch from d1ce0e1 to 1a86e82 Compare September 22, 2026 20:33
@sirosen sirosen modified the milestones: 7.6.2, 7.7.0 Oct 5, 2026
@sirosen
sirosen force-pushed the testing/coverage/color-opt branch from 1a86e82 to 80db760 Compare October 12, 2026 20:37
Comment thread tests/unit/scripts/test_options.py
1.  Set `expose_value=False` so that `pip-compile` is not responsible for
    handling the logic which more naturally belongs inside of the flag
    implementation itself.

2.  Implement that logic using a callback.

3.  Add unit tests for the flag, in isolation from `pip-compile`.
@sirosen
sirosen force-pushed the testing/coverage/color-opt branch from f9f4538 to cb6d2fb Compare October 15, 2026 00:07
pytest.param(["--color"], True, id="enable"),
pytest.param(["--no-color"], False, id="disable"),
# last one wins semantics
pytest.param(["--color", "--no-color"], False, id="disable_overrides_enable"),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should we use kebab-case for IDs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🤷 Maybe?

I haven't thought very hard about it. I was using snake case so that it doesn't look like multiple parameters.

Do you want me to change it? I have no preference here, but want to be clear before I make an update. 😄

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I figured you didn't want said confusion but it surprised me because I always use kebab-case for any non-python identifiers for distinction.

I can see that it can cause weirdness with multiple layers of parametrize, though.

I prefer dashes but won't insist. Your call.

@webknjaz webknjaz closed this Oct 15, 2026
@webknjaz webknjaz reopened this Oct 15, 2026
@webknjaz

Copy link
Copy Markdown
Member

Noticed a few integrations not reporting stuff. Attempted to fix some: #2498. Reopening the PR will hopefully report a few more checks, probably not all.

@webknjaz webknjaz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The only reason I didn't approve earlier was that the missing coverage checks distracted me and I went on the side quest to fix them.. Feel free to make changes or merge as is.

@webknjaz webknjaz closed this Oct 15, 2026
@webknjaz webknjaz reopened this Oct 15, 2026
@webknjaz webknjaz mentioned this pull request Oct 15, 2026
5 tasks done
@webknjaz
webknjaz added this pull request to the merge queue Oct 15, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 15, 2026
@webknjaz
webknjaz added this pull request to the merge queue Oct 15, 2026
@webknjaz

Copy link
Copy Markdown
Member

Flaky failure in the merge queue: https://github.com/pypa/pip-tools/actions/runs/38812543452/job/116689071786#step:8:54. Scheduled again.

Merged via the queue into pypa:main with commit ab9b075 Oct 15, 2026
190 checks passed
@sirosen
sirosen deleted the testing/coverage/color-opt branch October 16, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:skip A mark meaning no public change log needed for the patch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants