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

fix handling of --all-groups and --no-default-groups flags #11224

Merged
merged 13 commits into from
Feb 5, 2025

Conversation

Gankra
Copy link
Contributor

@Gankra Gankra commented Feb 4, 2025

This is a rewrite of the groups subsystem to have more clear semantics, and some adjustments to the CLI flag constraints. In doing so, the following bugs are fixed:

  • --no-default-groups --no-group foo is no longer needlessly rejected
  • --all-groups --no-default-groups now correctly evaluates to --all-groups where previously it was erroneously being interpretted as just --no-default-groups
  • --all-groups --only-dev is now illegal, where previously it was accepted and mishandled, as if it was a mythical --only-all-groups flag

Fixes #10890
Closes #10891

unambiguous semantics and a clearer implementation.
@Gankra Gankra added the internal A refactor or improvement that is not user-facing label Feb 4, 2025
Comment on lines 2734 to 2735
#[arg(long, conflicts_with_all = ["group", "dev", "all_groups"])]
pub only_dev: bool,
Copy link
Member

Choose a reason for hiding this comment

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

--only-dev and --dev do not conflict, --no-dev?

Suggested change
#[arg(long, conflicts_with_all = ["group", "dev", "all_groups"])]
pub only_dev: bool,
#[arg(long, conflicts_with_all = ["group", "no_dev", "all_groups"])]
pub only_dev: bool,

Copy link
Contributor Author

@Gankra Gankra Feb 4, 2025

Choose a reason for hiding this comment

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

The idea I'm trying to express here is essentially that --dev --only-dev is "what are you even doing".

This is more clear with --group A --only-group B, which is clearly "what no", but rejecting that and not rejecting --group A --only-group A is a pain for very little benefit. Since --dev --only-dev essentially desugars to that, I figured it's best to reject it for uniformity (and the followup code essentially assumes only one of these flags is ever true, although in a trivial way where we could fix it to "saturate" to --only-dev).

Copy link
Member

Choose a reason for hiding this comment

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

That makes sense. I'd prefer to just allow redundant options, but understand it can get complicated and if it's not worth it it's not a big deal. Is it a breaking change though?

--only-dev --no-dev should still error though, no? Or does it not because we say that "exclusions override" and that's fine?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I wasn't sure how exclusions and overrides interact. It should probably be tightened up but I didn't want to break something (I'll test it out / read the docs properly to figure out how this should be handled).

In terms of breaking... hmm... seems like the old impl tried harder to rationalize both inputs being provided... but in a bit of an adhoc way...

if matches!(dev, Some(DevMode::Only)) {
unreachable!("cannot specify both `--only-dev` and `--group`")
};
// Ensure that `--no-group` and `--group` are mutually exclusive.
group.retain(|group| !no_group.contains(group));
Some(GroupsSpecification::Include {
include: IncludeGroups::Some(group),
exclude: no_group,
})
} else if !only_group.is_empty() {
if matches!(dev, Some(DevMode::Include)) {
unreachable!("cannot specify both `--dev` and `--only-group`")
};
// Ensure that `--no-group` and `--only-group` are mutually exclusive.
only_group.retain(|group| !no_group.contains(group));
Some(GroupsSpecification::Only {
include: only_group,
exclude: no_group,
})

Copy link
Member

Choose a reason for hiding this comment

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

In general, I'd say a breaking change here would not be ideal. I'd suggest PR'ing some tests for edge-cases to main first so we can see if they change here? If it seems hard to avoid a regression, then I guess we should wait for 0.6?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok cool so this is the Final Potential Breakage to hash out (collapsed a few others that I regard as Equivalent).

Looking closer, the current code:

  • Hard panics(!) on --group --only-dev and --dev --only-group
  • CLI conflicts --group --only-group
  • CLI conflicts --dev --only-dev
  • Saturates --only-dev --dev to --only-dev
  • CLI conflicts --only-dev --no-dev
  • Positionally Overrides --dev --no-dev --dev ...

So overall the current code hard rejects trying to mix --only-* with --group/--dev, except in the exact case of --only-dev --dev, which it turns into --only-dev. Which is fair enough, if a bit inconsistent. It's interesting that there's no overriding between --only-dev and --no-dev but I don't want to poke that bear in this PR.

I've adjusted things to preserve this behaviour, although the hard panics are now CLI conflicts.

crates/uv-cli/src/lib.rs Outdated Show resolved Hide resolved
crates/uv-cli/src/lib.rs Outdated Show resolved Hide resolved
@@ -251,7 +251,7 @@ pub(crate) async fn run(
lock: &lock,
},
&ExtrasSpecification::default(),
&DevGroupsManifest::default(),
&DevGroupsSpecification::default().with_defaults(Vec::new()),
Copy link
Member

@zanieb zanieb Feb 4, 2025

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree it's a bit weird, but on the other hand I do kind of like that it's really hammering in "there were two different things I was theoretically supposed to be inputting and I'm doing Neither of them".

Comment on lines +1980 to +1981
// --dev --only-dev should saturate as --only-dev
uv_snapshot!(context.filters(), context.sync()
Copy link
Member

Choose a reason for hiding this comment

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

Weird to allow this but not // --group and --only-group should error if they name same things but... eh.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Preserving previous behaviour :)

@Gankra Gankra added bug Something isn't working and removed internal A refactor or improvement that is not user-facing labels Feb 5, 2025
@Gankra Gankra changed the title Rewrite DevGroupSpecification and DevGroupManifest fix handling of --all-group and --no-default-groups flags Feb 5, 2025
@Gankra Gankra changed the title fix handling of --all-group and --no-default-groups flags fix handling of --all-groups and --no-default-groups flags Feb 5, 2025
@Gankra Gankra merged commit 72d9361 into main Feb 5, 2025
73 checks passed
@Gankra Gankra deleted the gankra/group-cleanup branch February 5, 2025 20:31
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Feb 6, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [astral-sh/uv](https://github.com/astral-sh/uv) | patch | `0.5.27` -> `0.5.29` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>astral-sh/uv (astral-sh/uv)</summary>

### [`v0.5.29`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#0529)

[Compare Source](astral-sh/uv@0.5.28...0.5.29)

##### Enhancements

-   Add `--bare` option to `uv init` ([#&#8203;11192](astral-sh/uv#11192))
-   Add support for respecting `VIRTUAL_ENV` in project commands via `--active` ([#&#8203;11189](astral-sh/uv#11189))
-   Allow the project `VIRTUAL_ENV` warning to be silenced with `--no-active` ([#&#8203;11251](astral-sh/uv#11251))

##### Python

The managed Python distributions have been updated, including:

-   CPython 3.12.9
-   CPython 3.13.2
-   pkg-config files are now relocatable

See the [`python-build-standalone` release notes](https://github.com/astral-sh/python-build-standalone/releases/tag/20250205) for more details.

##### Bug fixes

-   Always use base Python discovery logic for cached environments ([#&#8203;11254](astral-sh/uv#11254))
-   Use a flock to avoid concurrent initialization of project environments ([#&#8203;11259](astral-sh/uv#11259))
-   Fix handling of `--all-groups` and `--no-default-groups` flags ([#&#8203;11224](astral-sh/uv#11224))

##### Documentation

-   Minor touchups to the Docker provenance docs ([#&#8203;11252](astral-sh/uv#11252))
-   Move content from the `mkdocs.public.yml` into the template ([#&#8203;11246](astral-sh/uv#11246))

### [`v0.5.28`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#0528)

[Compare Source](astral-sh/uv@0.5.27...0.5.28)

##### Bug fixes

-   Allow discovering virtual environments from the first interpreter found on the `PATH` ([#&#8203;11218](astral-sh/uv#11218))
-   Clear ephemeral overlays when running tools ([#&#8203;11141](astral-sh/uv#11141))
-   Disable SSL in Git commands for `--allow-insecure-host` ([#&#8203;11210](astral-sh/uv#11210))
-   Fix hardlinks in tar unpacking ([#&#8203;11221](astral-sh/uv#11221))
-   Set base executable when returning virtual environment ([#&#8203;11209](astral-sh/uv#11209))
-   Use base Python for cached environments ([#&#8203;11208](astral-sh/uv#11208))

##### Documentation

-   Add documentation on verifying Docker image attestations ([#&#8203;11140](astral-sh/uv#11140))
-   Add `last updated` to documentation ([#&#8203;11164](astral-sh/uv#11164))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xNTguMSIsInVwZGF0ZWRJblZlciI6IjM5LjE1OC4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--no-default-groups should be able to use with --no-group and --all-groups
2 participants