mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-17 10:53:37 +00:00
Prefix sys fields with sys_ consistently on Interpreter (#4084)
## Summary This is more consistent across the struct _and_ opens up space for `--prefix`.
This commit is contained in:
parent
120148f0a1
commit
fa2b6a28bc
6 changed files with 48 additions and 48 deletions
|
|
@ -636,7 +636,7 @@ impl CacheBucket {
|
||||||
Self::BuiltWheels => "built-wheels-v3",
|
Self::BuiltWheels => "built-wheels-v3",
|
||||||
Self::FlatIndex => "flat-index-v0",
|
Self::FlatIndex => "flat-index-v0",
|
||||||
Self::Git => "git-v0",
|
Self::Git => "git-v0",
|
||||||
Self::Interpreter => "interpreter-v1",
|
Self::Interpreter => "interpreter-v2",
|
||||||
Self::Simple => "simple-v8",
|
Self::Simple => "simple-v8",
|
||||||
Self::Wheels => "wheels-v1",
|
Self::Wheels => "wheels-v1",
|
||||||
Self::Archive => "archive-v0",
|
Self::Archive => "archive-v0",
|
||||||
|
|
|
||||||
|
|
@ -545,10 +545,10 @@ def main() -> None:
|
||||||
interpreter_info = {
|
interpreter_info = {
|
||||||
"result": "success",
|
"result": "success",
|
||||||
"markers": markers,
|
"markers": markers,
|
||||||
"base_prefix": sys.base_prefix,
|
"sys_base_prefix": sys.base_prefix,
|
||||||
"base_exec_prefix": sys.base_exec_prefix,
|
"sys_base_exec_prefix": sys.base_exec_prefix,
|
||||||
"prefix": sys.prefix,
|
"sys_prefix": sys.prefix,
|
||||||
"base_executable": getattr(sys, "_base_executable", None),
|
"sys_base_executable": getattr(sys, "_base_executable", None),
|
||||||
"sys_executable": sys.executable,
|
"sys_executable": sys.executable,
|
||||||
"sys_path": sys.path,
|
"sys_path": sys.path,
|
||||||
"stdlib": sysconfig.get_path("stdlib"),
|
"stdlib": sysconfig.get_path("stdlib"),
|
||||||
|
|
|
||||||
|
|
@ -75,11 +75,11 @@ impl PythonEnvironment {
|
||||||
|| matches!(found.source(), InterpreterSource::CondaPrefix),
|
|| matches!(found.source(), InterpreterSource::CondaPrefix),
|
||||||
"Not a virtualenv (source: {}, prefix: {})",
|
"Not a virtualenv (source: {}, prefix: {})",
|
||||||
found.source(),
|
found.source(),
|
||||||
found.interpreter().base_prefix().display()
|
found.interpreter().sys_base_prefix().display()
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(Self(Arc::new(PythonEnvironmentShared {
|
Ok(Self(Arc::new(PythonEnvironmentShared {
|
||||||
root: found.interpreter().prefix().to_path_buf(),
|
root: found.interpreter().sys_prefix().to_path_buf(),
|
||||||
interpreter: found.into_interpreter(),
|
interpreter: found.into_interpreter(),
|
||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
|
|
@ -91,7 +91,7 @@ impl PythonEnvironment {
|
||||||
let found = find_interpreter(&request, system, &sources, cache)??;
|
let found = find_interpreter(&request, system, &sources, cache)??;
|
||||||
|
|
||||||
Ok(Self(Arc::new(PythonEnvironmentShared {
|
Ok(Self(Arc::new(PythonEnvironmentShared {
|
||||||
root: found.interpreter().prefix().to_path_buf(),
|
root: found.interpreter().sys_prefix().to_path_buf(),
|
||||||
interpreter: found.into_interpreter(),
|
interpreter: found.into_interpreter(),
|
||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
|
|
@ -111,7 +111,7 @@ impl PythonEnvironment {
|
||||||
let interpreter = Interpreter::query(executable, cache)?;
|
let interpreter = Interpreter::query(executable, cache)?;
|
||||||
|
|
||||||
Ok(Self(Arc::new(PythonEnvironmentShared {
|
Ok(Self(Arc::new(PythonEnvironmentShared {
|
||||||
root: interpreter.prefix().to_path_buf(),
|
root: interpreter.sys_prefix().to_path_buf(),
|
||||||
interpreter,
|
interpreter,
|
||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
|
|
@ -127,7 +127,7 @@ impl PythonEnvironment {
|
||||||
let request = InterpreterRequest::parse(request);
|
let request = InterpreterRequest::parse(request);
|
||||||
let interpreter = find_interpreter(&request, system, &sources, cache)??.into_interpreter();
|
let interpreter = find_interpreter(&request, system, &sources, cache)??.into_interpreter();
|
||||||
Ok(Self(Arc::new(PythonEnvironmentShared {
|
Ok(Self(Arc::new(PythonEnvironmentShared {
|
||||||
root: interpreter.prefix().to_path_buf(),
|
root: interpreter.sys_prefix().to_path_buf(),
|
||||||
interpreter,
|
interpreter,
|
||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
|
|
@ -136,7 +136,7 @@ impl PythonEnvironment {
|
||||||
pub fn from_default_python(preview: PreviewMode, cache: &Cache) -> Result<Self, Error> {
|
pub fn from_default_python(preview: PreviewMode, cache: &Cache) -> Result<Self, Error> {
|
||||||
let interpreter = find_default_interpreter(preview, cache)??.into_interpreter();
|
let interpreter = find_default_interpreter(preview, cache)??.into_interpreter();
|
||||||
Ok(Self(Arc::new(PythonEnvironmentShared {
|
Ok(Self(Arc::new(PythonEnvironmentShared {
|
||||||
root: interpreter.prefix().to_path_buf(),
|
root: interpreter.sys_prefix().to_path_buf(),
|
||||||
interpreter,
|
interpreter,
|
||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
|
|
@ -144,7 +144,7 @@ impl PythonEnvironment {
|
||||||
/// Create a [`PythonEnvironment`] from an existing [`Interpreter`].
|
/// Create a [`PythonEnvironment`] from an existing [`Interpreter`].
|
||||||
pub fn from_interpreter(interpreter: Interpreter) -> Self {
|
pub fn from_interpreter(interpreter: Interpreter) -> Self {
|
||||||
Self(Arc::new(PythonEnvironmentShared {
|
Self(Arc::new(PythonEnvironmentShared {
|
||||||
root: interpreter.prefix().to_path_buf(),
|
root: interpreter.sys_prefix().to_path_buf(),
|
||||||
interpreter,
|
interpreter,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,10 +29,10 @@ pub struct Interpreter {
|
||||||
markers: Box<MarkerEnvironment>,
|
markers: Box<MarkerEnvironment>,
|
||||||
scheme: Scheme,
|
scheme: Scheme,
|
||||||
virtualenv: Scheme,
|
virtualenv: Scheme,
|
||||||
prefix: PathBuf,
|
sys_prefix: PathBuf,
|
||||||
base_exec_prefix: PathBuf,
|
sys_base_exec_prefix: PathBuf,
|
||||||
base_prefix: PathBuf,
|
sys_base_prefix: PathBuf,
|
||||||
base_executable: Option<PathBuf>,
|
sys_base_executable: Option<PathBuf>,
|
||||||
sys_executable: PathBuf,
|
sys_executable: PathBuf,
|
||||||
sys_path: Vec<PathBuf>,
|
sys_path: Vec<PathBuf>,
|
||||||
stdlib: PathBuf,
|
stdlib: PathBuf,
|
||||||
|
|
@ -58,12 +58,12 @@ impl Interpreter {
|
||||||
markers: Box::new(info.markers),
|
markers: Box::new(info.markers),
|
||||||
scheme: info.scheme,
|
scheme: info.scheme,
|
||||||
virtualenv: info.virtualenv,
|
virtualenv: info.virtualenv,
|
||||||
prefix: info.prefix,
|
sys_prefix: info.sys_prefix,
|
||||||
base_exec_prefix: info.base_exec_prefix,
|
sys_base_exec_prefix: info.sys_base_exec_prefix,
|
||||||
pointer_size: info.pointer_size,
|
pointer_size: info.pointer_size,
|
||||||
gil_disabled: info.gil_disabled,
|
gil_disabled: info.gil_disabled,
|
||||||
base_prefix: info.base_prefix,
|
sys_base_prefix: info.sys_base_prefix,
|
||||||
base_executable: info.base_executable,
|
sys_base_executable: info.sys_base_executable,
|
||||||
sys_executable: info.sys_executable,
|
sys_executable: info.sys_executable,
|
||||||
sys_path: info.sys_path,
|
sys_path: info.sys_path,
|
||||||
stdlib: info.stdlib,
|
stdlib: info.stdlib,
|
||||||
|
|
@ -91,10 +91,10 @@ impl Interpreter {
|
||||||
scripts: PathBuf::from("/dev/null"),
|
scripts: PathBuf::from("/dev/null"),
|
||||||
data: PathBuf::from("/dev/null"),
|
data: PathBuf::from("/dev/null"),
|
||||||
},
|
},
|
||||||
prefix: PathBuf::from("/dev/null"),
|
sys_prefix: PathBuf::from("/dev/null"),
|
||||||
base_exec_prefix: PathBuf::from("/dev/null"),
|
sys_base_exec_prefix: PathBuf::from("/dev/null"),
|
||||||
base_prefix: PathBuf::from("/dev/null"),
|
sys_base_prefix: PathBuf::from("/dev/null"),
|
||||||
base_executable: None,
|
sys_base_executable: None,
|
||||||
sys_executable: PathBuf::from("/dev/null"),
|
sys_executable: PathBuf::from("/dev/null"),
|
||||||
sys_path: vec![],
|
sys_path: vec![],
|
||||||
stdlib: PathBuf::from("/dev/null"),
|
stdlib: PathBuf::from("/dev/null"),
|
||||||
|
|
@ -111,7 +111,7 @@ impl Interpreter {
|
||||||
Self {
|
Self {
|
||||||
scheme: virtualenv.scheme,
|
scheme: virtualenv.scheme,
|
||||||
sys_executable: virtualenv.executable,
|
sys_executable: virtualenv.executable,
|
||||||
prefix: virtualenv.root,
|
sys_prefix: virtualenv.root,
|
||||||
target: None,
|
target: None,
|
||||||
..self
|
..self
|
||||||
}
|
}
|
||||||
|
|
@ -158,7 +158,7 @@ impl Interpreter {
|
||||||
/// See: <https://github.com/pypa/pip/blob/0ad4c94be74cc24874c6feb5bb3c2152c398a18e/src/pip/_internal/utils/virtualenv.py#L14>
|
/// See: <https://github.com/pypa/pip/blob/0ad4c94be74cc24874c6feb5bb3c2152c398a18e/src/pip/_internal/utils/virtualenv.py#L14>
|
||||||
pub fn is_virtualenv(&self) -> bool {
|
pub fn is_virtualenv(&self) -> bool {
|
||||||
// Maybe this should return `false` if it's a target?
|
// Maybe this should return `false` if it's a target?
|
||||||
self.prefix != self.base_prefix
|
self.sys_prefix != self.sys_base_prefix
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if the environment is a `--target` environment.
|
/// Returns `true` if the environment is a `--target` environment.
|
||||||
|
|
@ -273,24 +273,24 @@ impl Interpreter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the `sys.base_exec_prefix` path for this Python interpreter.
|
/// Return the `sys.base_exec_prefix` path for this Python interpreter.
|
||||||
pub fn base_exec_prefix(&self) -> &Path {
|
pub fn sys_base_exec_prefix(&self) -> &Path {
|
||||||
&self.base_exec_prefix
|
&self.sys_base_exec_prefix
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the `sys.base_prefix` path for this Python interpreter.
|
/// Return the `sys.base_prefix` path for this Python interpreter.
|
||||||
pub fn base_prefix(&self) -> &Path {
|
pub fn sys_base_prefix(&self) -> &Path {
|
||||||
&self.base_prefix
|
&self.sys_base_prefix
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the `sys.prefix` path for this Python interpreter.
|
/// Return the `sys.prefix` path for this Python interpreter.
|
||||||
pub fn prefix(&self) -> &Path {
|
pub fn sys_prefix(&self) -> &Path {
|
||||||
&self.prefix
|
&self.sys_prefix
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the `sys._base_executable` path for this Python interpreter. Some platforms do not
|
/// Return the `sys._base_executable` path for this Python interpreter. Some platforms do not
|
||||||
/// have this attribute, so it may be `None`.
|
/// have this attribute, so it may be `None`.
|
||||||
pub fn base_executable(&self) -> Option<&Path> {
|
pub fn sys_base_executable(&self) -> Option<&Path> {
|
||||||
self.base_executable.as_deref()
|
self.sys_base_executable.as_deref()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the `sys.executable` path for this Python interpreter.
|
/// Return the `sys.executable` path for this Python interpreter.
|
||||||
|
|
@ -374,7 +374,7 @@ impl Interpreter {
|
||||||
include: if self.is_virtualenv() {
|
include: if self.is_virtualenv() {
|
||||||
// If the interpreter is a venv, then the `include` directory has a different structure.
|
// If the interpreter is a venv, then the `include` directory has a different structure.
|
||||||
// See: https://github.com/pypa/pip/blob/0ad4c94be74cc24874c6feb5bb3c2152c398a18e/src/pip/_internal/locations/_sysconfig.py#L172
|
// See: https://github.com/pypa/pip/blob/0ad4c94be74cc24874c6feb5bb3c2152c398a18e/src/pip/_internal/locations/_sysconfig.py#L172
|
||||||
self.prefix.join("include").join("site").join(format!(
|
self.sys_prefix.join("include").join("site").join(format!(
|
||||||
"python{}.{}",
|
"python{}.{}",
|
||||||
self.python_major(),
|
self.python_major(),
|
||||||
self.python_minor()
|
self.python_minor()
|
||||||
|
|
@ -476,10 +476,10 @@ struct InterpreterInfo {
|
||||||
markers: MarkerEnvironment,
|
markers: MarkerEnvironment,
|
||||||
scheme: Scheme,
|
scheme: Scheme,
|
||||||
virtualenv: Scheme,
|
virtualenv: Scheme,
|
||||||
prefix: PathBuf,
|
sys_prefix: PathBuf,
|
||||||
base_exec_prefix: PathBuf,
|
sys_base_exec_prefix: PathBuf,
|
||||||
base_prefix: PathBuf,
|
sys_base_prefix: PathBuf,
|
||||||
base_executable: Option<PathBuf>,
|
sys_base_executable: Option<PathBuf>,
|
||||||
sys_executable: PathBuf,
|
sys_executable: PathBuf,
|
||||||
sys_path: Vec<PathBuf>,
|
sys_path: Vec<PathBuf>,
|
||||||
stdlib: PathBuf,
|
stdlib: PathBuf,
|
||||||
|
|
@ -709,9 +709,9 @@ mod tests {
|
||||||
"python_version": "3.12",
|
"python_version": "3.12",
|
||||||
"sys_platform": "linux"
|
"sys_platform": "linux"
|
||||||
},
|
},
|
||||||
"base_exec_prefix": "/home/ferris/.pyenv/versions/3.12.0",
|
"sys_base_exec_prefix": "/home/ferris/.pyenv/versions/3.12.0",
|
||||||
"base_prefix": "/home/ferris/.pyenv/versions/3.12.0",
|
"sys_base_prefix": "/home/ferris/.pyenv/versions/3.12.0",
|
||||||
"prefix": "/home/ferris/projects/uv/.venv",
|
"sys_prefix": "/home/ferris/projects/uv/.venv",
|
||||||
"sys_executable": "/home/ferris/projects/uv/.venv/bin/python",
|
"sys_executable": "/home/ferris/projects/uv/.venv/bin/python",
|
||||||
"sys_path": [
|
"sys_path": [
|
||||||
"/home/ferris/.pyenv/versions/3.12.0/lib/python3.12/lib/python3.12",
|
"/home/ferris/.pyenv/versions/3.12.0/lib/python3.12/lib/python3.12",
|
||||||
|
|
|
||||||
|
|
@ -192,9 +192,9 @@ mod tests {
|
||||||
"python_version": "{VERSION}",
|
"python_version": "{VERSION}",
|
||||||
"sys_platform": "linux"
|
"sys_platform": "linux"
|
||||||
},
|
},
|
||||||
"base_exec_prefix": "/home/ferris/.pyenv/versions/{FULL_VERSION}",
|
"sys_base_exec_prefix": "/home/ferris/.pyenv/versions/{FULL_VERSION}",
|
||||||
"base_prefix": "/home/ferris/.pyenv/versions/{FULL_VERSION}",
|
"sys_base_prefix": "/home/ferris/.pyenv/versions/{FULL_VERSION}",
|
||||||
"prefix": "{PREFIX}",
|
"sys_prefix": "{PREFIX}",
|
||||||
"sys_executable": "{PATH}",
|
"sys_executable": "{PATH}",
|
||||||
"sys_path": [
|
"sys_path": [
|
||||||
"/home/ferris/.pyenv/versions/{FULL_VERSION}/lib/python{VERSION}/lib/python{VERSION}",
|
"/home/ferris/.pyenv/versions/{FULL_VERSION}/lib/python{VERSION}/lib/python{VERSION}",
|
||||||
|
|
|
||||||
|
|
@ -68,12 +68,12 @@ pub fn create_bare_venv(
|
||||||
// already a "system Python". We canonicalize the path to ensure that it's real and
|
// already a "system Python". We canonicalize the path to ensure that it's real and
|
||||||
// consistent, though we don't expect any symlinks on Windows.
|
// consistent, though we don't expect any symlinks on Windows.
|
||||||
if interpreter.is_virtualenv() {
|
if interpreter.is_virtualenv() {
|
||||||
if let Some(base_executable) = interpreter.base_executable() {
|
if let Some(base_executable) = interpreter.sys_base_executable() {
|
||||||
base_executable.to_path_buf()
|
base_executable.to_path_buf()
|
||||||
} else {
|
} else {
|
||||||
// Assume `python.exe`, though the exact executable name is never used (below) on
|
// Assume `python.exe`, though the exact executable name is never used (below) on
|
||||||
// Windows, only its parent directory.
|
// Windows, only its parent directory.
|
||||||
interpreter.base_prefix().join("python.exe")
|
interpreter.sys_base_prefix().join("python.exe")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
uv_fs::canonicalize_executable(interpreter.sys_executable())?
|
uv_fs::canonicalize_executable(interpreter.sys_executable())?
|
||||||
|
|
@ -395,7 +395,7 @@ fn copy_launcher_windows(
|
||||||
// `DLLs` subdirectory (if it exists).
|
// `DLLs` subdirectory (if it exists).
|
||||||
for directory in [
|
for directory in [
|
||||||
python_home,
|
python_home,
|
||||||
interpreter.base_prefix().join("DLLs").as_path(),
|
interpreter.sys_base_prefix().join("DLLs").as_path(),
|
||||||
] {
|
] {
|
||||||
let entries = match fs_err::read_dir(directory) {
|
let entries = match fs_err::read_dir(directory) {
|
||||||
Ok(read_dir) => read_dir,
|
Ok(read_dir) => read_dir,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue