Skip to content

Consolidate tilde requires-python warnings - #1385

Draft
zaniebot wants to merge 3 commits into
mainfrom
zb/consolidate-requires-python-warnings
Draft

zaniebot wants to merge 3 commits into
mainfrom
zb/consolidate-requires-python-warnings

Conversation

@zaniebot

Copy link
Copy Markdown
Collaborator

Workspaces with several requires-python = "~=3.12" declarations repeat the full ambiguity warning for each package or dependency group. Consolidate the affected sources into one warning while retaining the existing text for a single source. Warning eligibility and the computed Python range are unchanged. This implements the consolidation suggested in astral-sh#14422.

@astral-automations-bot astral-automations-bot Bot added area:error-messages Messaging when something goes wrong enhancement New feature or request labels Sep 11, 2026
@zaniebot zaniebot added risk:1 Negligible risk of localized mistakes that are obvious and easy to correct. priority:3 Normal: useful features, documentation, usability, or routine efficiency improvements. size:1 Small: one localized behavior with straightforward tests or documentation checks. labels Sep 11, 2026
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/consolidate-requires-python-warnings branch from 64a8e16 to 0c1b97a Compare September 30, 2026 19:03
@codspeed

codspeed Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 54 untouched benchmarks
⏩ 35 skipped benchmarks1


Comparing zb/consolidate-requires-python-warnings (9f2f4a8) with main (f3e56e1)

Open in CodSpeed

Footnotes

  1. 35 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/consolidate-requires-python-warnings branch 3 times, most recently from b01dd36 to db1da3a Compare October 7, 2026 22:01
Comment on lines +254 to +255
if let Some(warning) = format_tilde_requires_python_warning(&requires_python) {
warn_user_once!("{warning}");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P2] Preserve per-source deduplication when aggregating warnings

When a project and its selected dev group both declare requires-python = "~=3.12", normal uv sync calls this function with groups during environment discovery, then without groups through LockTarget::requires_python during locking. The first call emits the aggregate warning; the second emits the single-project warning. Because warn_user_once! deduplicates complete messages, the project declaration is now reported twice. Previously its individual warning was suppressed on the second call. Deduplicate declarations before formatting the aggregate, and cover this two-stage path with a sync integration snapshot.

Comment thread crates/uv-python-context/src/lib.rs Outdated
CompatibleProjectPython, ProjectPythonRequest, ProjectPythonRequirement, PythonRequestSource,
PythonRequirementConflicts, PythonRequirementSource, find_requires_python,
format_requires_python_sources,
format_requires_python_sources, format_tilde_requires_python_warning,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P3] Keep the warning formatter private to its owning crate

The only consumer of this export outside project.rs is the new test module in uv-project-commands. This exposes an implementation detail solely for testing and places its regression tests in a different crate from the implementation. The existing lock_requires_python_compatible_specifier integration snapshot already covers the single-project warning and two excluded forms. Extend the command snapshot coverage for consolidation and selected groups, then keep this helper private; that also verifies warning emission rather than only the returned string.

@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/consolidate-requires-python-warnings branch from db1da3a to a4b27db Compare October 8, 2026 02:32
@zaniebot
zaniebot deployed to automations October 9, 2026 01:41 — with GitHub Actions Active
@zaniebot
zaniebot deployed to automations October 9, 2026 01:44 — with GitHub Actions Active
Comment on lines +296 to +298
Some((source.clone(), specifiers.clone()))
})
.collect();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P3] Pass filtered tilde specifiers directly to the formatter

The caller has already checked the specifier count, converted to TildeVersionSpecifier, and excluded patch versions. Rebuilding RequiresPythonSources here clones the declarations and specifiers solely for the formatter to repeat those same checks and build another collection. This creates two places to maintain warning eligibility. Collect borrowed (source, specifier) entries and pass that slice to the formatter so it only handles rendering.

Comment on lines +31 to +32
- `example`: `~=3.12` is interpreted as `>=3.12, <4`; use `~=3.12.[X]` to constrain the version as `>=3.12.[X], <3.13`
- `example:dev`: `~=3.12` is interpreted as `>=3.12, <4`; use `~=3.12.[X]` to constrain the version as `>=3.12.[X], <3.13`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P3] Keep suggested patch versions visible in the snapshot

With test_context!("3.12"), the context filters replace every 3.12.<digits> with 3.12.[X], hiding the deterministic .0 that this diagnostic recommends. The new multi-source rendering could incorrectly suggest ~=3.12.1 and this snapshot would still pass. Use declarations such as ~=3.11 with the existing Python 3.12 context so the suggested patch and bounds remain visible without requiring another interpreter.

@zaniebot
zaniebot deployed to automations October 9, 2026 02:36 — with GitHub Actions Active
@zaniebot zaniebot added the project:maintainer-followups Maintainer follow-up work label Oct 9, 2026

This branch was successfully deployed

1 active deployment
automations — 9f2f4a81 Deployed Oct 9, 2026 by zaniebot via review-code-quality / code quality review #8754
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:error-messages Messaging when something goes wrong enhancement New feature or request priority:3 Normal: useful features, documentation, usability, or routine efficiency improvements. project:maintainer-followups Maintainer follow-up work risk:1 Negligible risk of localized mistakes that are obvious and easy to correct. size:1 Small: one localized behavior with straightforward tests or documentation checks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants