-
Notifications
You must be signed in to change notification settings - Fork 3k
Surface pinned-version hint when uv tool upgrade can’t move the tool
#16081
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
Changes from all commits
fa2b0f8
fae19a5
842e1ed
3486bfd
adcfbbd
50345c2
5eaaa64
43cbde2
2caecb8
3164f92
74d1efd
315faa9
58c33ce
e7e32a7
5d8133e
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 |
|---|---|---|
|
|
@@ -9,17 +9,18 @@ use tracing::{debug, trace}; | |
| use uv_cache::Cache; | ||
| use uv_client::BaseClientBuilder; | ||
| use uv_configuration::{Concurrency, Constraints, DryRun, TargetTriple}; | ||
| use uv_distribution_types::{ExtraBuildRequires, Requirement}; | ||
| use uv_distribution_types::{ExtraBuildRequires, Requirement, RequirementSource}; | ||
| use uv_fs::CWD; | ||
| use uv_normalize::PackageName; | ||
| use uv_pep440::{Operator, Version}; | ||
| use uv_preview::Preview; | ||
| use uv_python::{ | ||
| EnvironmentPreference, Interpreter, PythonDownloads, PythonInstallation, PythonPreference, | ||
| PythonRequest, | ||
| }; | ||
| use uv_requirements::RequirementsSpecification; | ||
| use uv_settings::{Combine, PythonInstallMirrors, ResolverInstallerOptions, ToolOptions}; | ||
| use uv_tool::InstalledTools; | ||
| use uv_tool::{InstalledTools, Tool}; | ||
| use uv_warnings::write_error_chain; | ||
| use uv_workspace::WorkspaceCache; | ||
|
|
||
|
|
@@ -114,6 +115,9 @@ pub(crate) async fn upgrade( | |
| // Determine whether we applied any upgrades. | ||
| let mut did_upgrade_environment = vec![]; | ||
|
|
||
| // Constraints that caused upgrades to be skipped or altered. | ||
| let mut collected_constraints: Vec<(PackageName, UpgradeConstraint)> = Vec::new(); | ||
|
|
||
| let mut errors = Vec::new(); | ||
| for (name, constraints) in &names { | ||
| debug!("Upgrading tool: `{name}`"); | ||
|
|
@@ -135,14 +139,22 @@ pub(crate) async fn upgrade( | |
| .await; | ||
|
|
||
| match result { | ||
| Ok(UpgradeOutcome::UpgradeEnvironment) => { | ||
| did_upgrade_environment.push(name); | ||
| } | ||
| Ok(UpgradeOutcome::UpgradeDependencies | UpgradeOutcome::UpgradeTool) => { | ||
| did_upgrade_tool.push(name); | ||
| } | ||
| Ok(UpgradeOutcome::NoOp) => { | ||
| debug!("Upgrading `{name}` was a no-op"); | ||
| Ok(report) => { | ||
| match report.outcome { | ||
| UpgradeOutcome::UpgradeEnvironment => { | ||
| did_upgrade_environment.push(name); | ||
| } | ||
| UpgradeOutcome::UpgradeTool | UpgradeOutcome::UpgradeDependencies => { | ||
| did_upgrade_tool.push(name); | ||
| } | ||
| UpgradeOutcome::NoOp => { | ||
| debug!("Upgrading `{name}` was a no-op"); | ||
| } | ||
| } | ||
|
|
||
| if let Some(constraint) = report.constraint.clone() { | ||
| collected_constraints.push((name.clone(), constraint)); | ||
| } | ||
| } | ||
| Err(err) => { | ||
| errors.push((name, err)); | ||
|
|
@@ -187,6 +199,14 @@ pub(crate) async fn upgrade( | |
| } | ||
| } | ||
|
|
||
| if !collected_constraints.is_empty() { | ||
| writeln!(printer.stderr())?; | ||
| } | ||
|
|
||
| for (name, constraint) in collected_constraints { | ||
| constraint.print(&name, printer)?; | ||
| } | ||
|
|
||
| Ok(ExitStatus::Success) | ||
| } | ||
|
|
||
|
|
@@ -202,6 +222,39 @@ enum UpgradeOutcome { | |
| NoOp, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| enum UpgradeConstraint { | ||
| /// The tool remains pinned to an exact version, so an upgrade was skipped. | ||
| PinnedVersion { version: Version }, | ||
| } | ||
|
|
||
| impl UpgradeConstraint { | ||
| fn print(&self, name: &PackageName, printer: Printer) -> Result<()> { | ||
| match self { | ||
| Self::PinnedVersion { version } => { | ||
| let name = name.to_string(); | ||
| let reinstall_command = format!("uv tool install {name}@latest"); | ||
|
|
||
| writeln!( | ||
| printer.stderr(), | ||
| "hint: `{}` is pinned to `{}` (installed with an exact version pin); reinstall with `{}` to upgrade to a new version.", | ||
| name.cyan(), | ||
| version.to_string().magenta(), | ||
| reinstall_command.green(), | ||
| )?; | ||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| struct UpgradeReport { | ||
| outcome: UpgradeOutcome, | ||
| constraint: Option<UpgradeConstraint>, | ||
| } | ||
|
Comment on lines
+252
to
+256
Member
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. There's still something awkward about this abstraction, but 🤷♀️ I'm not having any great ideas so we can leave it until we have another use-case that helps us refactor. @konstin might have an idea.
Member
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. Previous conversation at #16081 (comment)
Member
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. I don't have a better idea either. |
||
|
|
||
| /// Upgrade a specific tool. | ||
| async fn upgrade_tool( | ||
| name: &PackageName, | ||
|
|
@@ -217,7 +270,7 @@ async fn upgrade_tool( | |
| installer_metadata: bool, | ||
| concurrency: Concurrency, | ||
| preview: Preview, | ||
| ) -> Result<UpgradeOutcome> { | ||
| ) -> Result<UpgradeReport> { | ||
| // Ensure the tool is installed. | ||
| let existing_tool_receipt = match installed_tools.get_tool_receipt(name) { | ||
| Ok(Some(receipt)) => receipt, | ||
|
|
@@ -398,5 +451,38 @@ async fn upgrade_tool( | |
| )?; | ||
| } | ||
|
|
||
| Ok(outcome) | ||
| let constraint = match &outcome { | ||
| UpgradeOutcome::UpgradeDependencies | UpgradeOutcome::NoOp => { | ||
| pinned_requirement_version(&existing_tool_receipt, name) | ||
| .map(|version| UpgradeConstraint::PinnedVersion { version }) | ||
| } | ||
| UpgradeOutcome::UpgradeTool | UpgradeOutcome::UpgradeEnvironment => None, | ||
| }; | ||
|
|
||
| Ok(UpgradeReport { | ||
| outcome, | ||
| constraint, | ||
| }) | ||
| } | ||
|
|
||
| fn pinned_requirement_version(tool: &Tool, name: &PackageName) -> Option<Version> { | ||
| pinned_version_from(tool.requirements(), name) | ||
| .or_else(|| pinned_version_from(tool.constraints(), name)) | ||
| } | ||
|
|
||
| fn pinned_version_from(requirements: &[Requirement], name: &PackageName) -> Option<Version> { | ||
| requirements | ||
| .iter() | ||
| .filter(|requirement| requirement.name == *name) | ||
| .find_map(|requirement| match &requirement.source { | ||
| RequirementSource::Registry { specifier, .. } => { | ||
| specifier | ||
| .iter() | ||
| .find_map(|specifier| match specifier.operator() { | ||
| Operator::Equal | Operator::ExactEqual => Some(specifier.version().clone()), | ||
| _ => None, | ||
| }) | ||
| } | ||
| _ => None, | ||
| }) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.