mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-16 01:35:00 +00:00
Add support for upgrading Python in tool environments (#7605)
This PR adds support for upgrading the build environment of tools with the addition of a ```--python``` argument to ```uv upgrade```, as specified in #7471. Some things to note: - I added support for individual packages — I didn't think there was a good reason for ```--python``` to only apply to all packages - Upgrading with ```--python``` also upgrades the package itself — I think this is fair as if a user wants to _strictly_ switch the version of Python being used to build a tool's environment they can use ```uv install```. This behavior can of course be modified if others don't agree! Closes https://github.com/astral-sh/uv/issues/6297. Closes https://github.com/astral-sh/uv/issues/7471.
This commit is contained in:
parent
f5601e2610
commit
106633a5e5
10 changed files with 394 additions and 53 deletions
|
@ -300,4 +300,26 @@ impl PythonEnvironment {
|
|||
pub fn into_interpreter(self) -> Interpreter {
|
||||
Arc::unwrap_or_clone(self.0).interpreter
|
||||
}
|
||||
|
||||
/// Returns `true` if the [`PythonEnvironment`] uses the same underlying [`Interpreter`].
|
||||
pub fn uses(&self, interpreter: &Interpreter) -> bool {
|
||||
// TODO(zanieb): Consider using `sysconfig.get_path("stdlib")` instead, which
|
||||
// should be generally robust.
|
||||
if cfg!(windows) {
|
||||
// On Windows, we can't canonicalize an interpreter based on its executable path
|
||||
// because the executables are separate shim files (not links). Instead, we
|
||||
// compare the `sys.base_prefix`.
|
||||
let old_base_prefix = self.interpreter().sys_base_prefix();
|
||||
let selected_base_prefix = interpreter.sys_base_prefix();
|
||||
old_base_prefix == selected_base_prefix
|
||||
} else {
|
||||
// On Unix, we can see if the canonicalized executable is the same file.
|
||||
self.interpreter().sys_executable() == interpreter.sys_executable()
|
||||
|| same_file::is_same_file(
|
||||
self.interpreter().sys_executable(),
|
||||
interpreter.sys_executable(),
|
||||
)
|
||||
.unwrap_or(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue