mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-29 15:04:07 +00:00
Use base executable to set virtualenv Python path (#8481)
See extensive discussion in https://github.com/astral-sh/uv/pull/8433#issuecomment-2430472849. This PR brings us into alignment with the standard library by using `sys._base_executable` rather than canonicalizing the executable path. The benefits are primarily for Homebrew, where we'll now resolve to paths like `/opt/homebrew/opt/python@3.12/bin` instead of the undesirable `/opt/homebrew/Cellar/python@3.9/3.9.19_1/Frameworks/Python.framework/Versions/3.9/bin`. Most other users should see no change, though in some cases, nested virtual environments now have slightly different behavior -- namely, they _sometimes_ resolve to the virtual environment Python (at least for Homebrew; not for rtx or uv Pythons though). See [here](https://docs.google.com/spreadsheets/d/1Vw5ClYEjgrBJJhQiwa3cCenIA1GbcRyudYN9NwQaEcM/edit?gid=0#gid=0) for a breakdown. Closes https://github.com/astral-sh/uv/issues/1640. Closes https://github.com/astral-sh/uv/issues/1795.
This commit is contained in:
parent
b6c531f4dd
commit
633467576b
3 changed files with 34 additions and 23 deletions
|
@ -45,6 +45,7 @@ pub struct Interpreter {
|
|||
sys_executable: PathBuf,
|
||||
sys_path: Vec<PathBuf>,
|
||||
stdlib: PathBuf,
|
||||
sysconfig_prefix: Option<PathBuf>,
|
||||
tags: OnceLock<Tags>,
|
||||
target: Option<Target>,
|
||||
prefix: Option<Prefix>,
|
||||
|
@ -78,6 +79,7 @@ impl Interpreter {
|
|||
sys_executable: info.sys_executable,
|
||||
sys_path: info.sys_path,
|
||||
stdlib: info.stdlib,
|
||||
sysconfig_prefix: info.sysconfig_prefix,
|
||||
tags: OnceLock::new(),
|
||||
target: None,
|
||||
prefix: None,
|
||||
|
@ -365,6 +367,11 @@ impl Interpreter {
|
|||
&self.stdlib
|
||||
}
|
||||
|
||||
/// Return the `prefix` path for this Python interpreter, as returned by `sysconfig.get_config_var("prefix")`.
|
||||
pub fn sysconfig_prefix(&self) -> Option<&Path> {
|
||||
self.sysconfig_prefix.as_deref()
|
||||
}
|
||||
|
||||
/// Return the `purelib` path for this Python interpreter, as returned by `sysconfig.get_paths()`.
|
||||
pub fn purelib(&self) -> &Path {
|
||||
&self.scheme.purelib
|
||||
|
@ -424,6 +431,19 @@ impl Interpreter {
|
|||
self.prefix.as_ref()
|
||||
}
|
||||
|
||||
/// Returns `true` if an [`Interpreter`] may be a `python-build-standalone` interpreter.
|
||||
///
|
||||
/// This method may return false positives, but it should not return false negatives. In other
|
||||
/// words, if this method returns `true`, the interpreter _may_ be from
|
||||
/// `python-build-standalone`; if it returns `false`, the interpreter is definitely _not_ from
|
||||
/// `python-build-standalone`.
|
||||
///
|
||||
/// See: <https://github.com/indygreg/python-build-standalone/issues/382>
|
||||
pub fn is_standalone(&self) -> bool {
|
||||
self.sysconfig_prefix()
|
||||
.is_some_and(|prefix| prefix == Path::new("/install"))
|
||||
}
|
||||
|
||||
/// Return the [`Layout`] environment used to install wheels into this interpreter.
|
||||
pub fn layout(&self) -> Layout {
|
||||
Layout {
|
||||
|
@ -605,6 +625,7 @@ struct InterpreterInfo {
|
|||
sys_executable: PathBuf,
|
||||
sys_path: Vec<PathBuf>,
|
||||
stdlib: PathBuf,
|
||||
sysconfig_prefix: Option<PathBuf>,
|
||||
pointer_size: PointerSize,
|
||||
gil_disabled: bool,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue