-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add support for --upgrade-group
#18266
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5717,8 +5717,9 @@ pub struct ToolUpgradeArgs { | |
| #[arg(long)] | ||
| pub python_platform: Option<TargetTriple>, | ||
|
|
||
| // The following is equivalent to flattening `ResolverInstallerArgs`, with the `--upgrade`, and | ||
| // `--upgrade-package` options hidden, and the `--no-upgrade` option removed. | ||
| // The following is equivalent to flattening `ResolverInstallerArgs`, with the `--upgrade`, | ||
| // `--upgrade-package`, and `--upgrade-group` options hidden, and the `--no-upgrade` option | ||
| // removed. | ||
| /// Allow package upgrades, ignoring pinned versions in any existing output file. Implies | ||
| /// `--refresh`. | ||
| #[arg(hide = true, long, short = 'U', help_heading = "Resolver options")] | ||
|
|
@@ -5729,6 +5730,11 @@ pub struct ToolUpgradeArgs { | |
| #[arg(hide = true, long, short = 'P', help_heading = "Resolver options")] | ||
| pub upgrade_package: Vec<Requirement<VerbatimParsedUrl>>, | ||
|
|
||
| /// Allow upgrades for all packages in a dependency group, ignoring pinned versions in any | ||
| /// existing output file. | ||
| #[arg(hide = true, long, help_heading = "Resolver options")] | ||
| pub upgrade_group: Vec<GroupName>, | ||
|
|
||
| #[command(flatten)] | ||
| pub index_args: IndexArgs, | ||
|
|
||
|
|
@@ -7048,6 +7054,11 @@ pub struct ResolverArgs { | |
| #[arg(long, short = 'P', help_heading = "Resolver options")] | ||
| pub upgrade_package: Vec<Requirement<VerbatimParsedUrl>>, | ||
|
|
||
| /// Allow upgrades for all packages in a dependency group, ignoring pinned versions in any | ||
| /// existing output file. | ||
| #[arg(long, help_heading = "Resolver options")] | ||
| pub upgrade_group: Vec<GroupName>, | ||
|
|
||
| /// The strategy to use when resolving against multiple index URLs. | ||
| /// | ||
| /// By default, uv will stop at the first index on which a given package is available, and limit | ||
|
|
@@ -7259,6 +7270,11 @@ pub struct ResolverInstallerArgs { | |
| #[arg(long, short = 'P', help_heading = "Resolver options", value_hint = ValueHint::Other)] | ||
| pub upgrade_package: Vec<Requirement<VerbatimParsedUrl>>, | ||
|
|
||
| /// Allow upgrades for all packages in a dependency group, ignoring pinned versions in any | ||
| /// existing output file. | ||
| #[arg(long, help_heading = "Resolver options")] | ||
| pub upgrade_group: Vec<GroupName>, | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we support
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not supported in the project interface right now, deferring. |
||
|
|
||
| /// Reinstall all packages, regardless of whether they're already installed. Implies | ||
| /// `--refresh`. | ||
| #[arg( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| use std::path::Path; | ||
|
|
||
| use anyhow::Result; | ||
| use rustc_hash::FxHashSet; | ||
|
|
||
| use uv_configuration::Upgrade; | ||
| use uv_fs::CWD; | ||
| use uv_git::ResolvedRepositoryReference; | ||
| use uv_normalize::PackageName; | ||
| use uv_requirements_txt::RequirementsTxt; | ||
| use uv_resolver::{Lock, LockError, Preference, PreferenceError, PylockToml, PylockTomlErrorKind}; | ||
|
|
||
|
|
@@ -71,12 +73,17 @@ pub fn read_lock_requirements( | |
| return Ok(LockedRequirements::default()); | ||
| } | ||
|
|
||
| // Resolve `--upgrade-group` to a set of package names by collecting all dependencies from | ||
| // the specified groups across all workspace member packages in the lock. | ||
| let group_packages = resolve_group_packages(lock, upgrade); | ||
|
|
||
| let mut preferences = Vec::new(); | ||
| let mut git = Vec::new(); | ||
|
|
||
| for package in lock.packages() { | ||
| // Skip the distribution if it's not included in the upgrade strategy. | ||
| if upgrade.contains(package.name()) { | ||
| // Skip the distribution if it's included in the upgrade strategy or belongs to an | ||
| // upgraded group. | ||
| if upgrade.contains(package.name()) || group_packages.contains(package.name()) { | ||
| continue; | ||
| } | ||
|
|
||
|
|
@@ -94,6 +101,41 @@ pub fn read_lock_requirements( | |
| Ok(LockedRequirements { preferences, git }) | ||
| } | ||
|
|
||
| /// Resolve the `--upgrade-group` group names to a set of package names by looking at the | ||
| /// dependency groups defined on packages in the lockfile. | ||
| fn resolve_group_packages(lock: &Lock, upgrade: &Upgrade) -> FxHashSet<PackageName> { | ||
|
||
| let groups = upgrade.groups(); | ||
| if groups.is_empty() { | ||
| return FxHashSet::default(); | ||
| } | ||
|
|
||
| let mut packages = FxHashSet::default(); | ||
|
|
||
| // Check package-level dependency groups (the standard case for projects with a `[project]` | ||
| // table). | ||
| for package in lock.packages() { | ||
| for (group_name, dependencies) in package.resolved_dependency_groups() { | ||
| if groups.contains(group_name) { | ||
| for dependency in dependencies { | ||
| packages.insert(dependency.package_name().clone()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Check manifest-level dependency groups, which cover projects without a `[project]` table | ||
| // (e.g., virtual workspace roots or PEP 723 scripts). | ||
| for (group_name, requirements) in lock.dependency_groups() { | ||
| if groups.contains(group_name) { | ||
| for requirement in requirements { | ||
| packages.insert(requirement.name.clone()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| packages | ||
| } | ||
|
|
||
| /// Load the preferred requirements from an existing `pylock.toml` file, applying the upgrade strategy. | ||
| pub async fn read_pylock_toml_requirements( | ||
| output_file: &Path, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.