Skip to content

Commit

Permalink
Use home
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Mar 1, 2024
1 parent 50dda6b commit 7856ed2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/uv-interpreter/src/get_interpreter_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def format_full_version(info):
"base_prefix": sys.base_prefix,
"base_exec_prefix": sys.base_exec_prefix,
"prefix": sys.prefix,
"base_executable": getattr(sys, "_base_executable", None),
"sys_executable": sys.executable,
"sysconfig_paths": sysconfig.get_paths(),
}
Expand Down
10 changes: 10 additions & 0 deletions crates/uv-interpreter/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct Interpreter {
prefix: PathBuf,
base_exec_prefix: PathBuf,
base_prefix: PathBuf,
base_executable: Option<PathBuf>,
sys_executable: PathBuf,
tags: OnceCell<Tags>,
}
Expand All @@ -54,6 +55,7 @@ impl Interpreter {
prefix: info.prefix,
base_exec_prefix: info.base_exec_prefix,
base_prefix: info.base_prefix,
base_executable: info.base_executable,
sys_executable: info.sys_executable,
tags: OnceCell::new(),
})
Expand All @@ -77,6 +79,7 @@ impl Interpreter {
prefix: PathBuf::from("/dev/null"),
base_exec_prefix: PathBuf::from("/dev/null"),
base_prefix: PathBuf::from("/dev/null"),
base_executable: None,
sys_executable: PathBuf::from("/dev/null"),
tags: OnceCell::new(),
}
Expand Down Expand Up @@ -355,6 +358,12 @@ impl Interpreter {
&self.prefix
}

/// Return the `sys._base_executable` path for this Python interpreter. Some platforms do not
/// have this attribute, so it may be `None`.
pub fn base_executable(&self) -> Option<&Path> {
self.base_executable.as_deref()
}

/// Return the `sys.executable` path for this Python interpreter.
pub fn sys_executable(&self) -> &Path {
&self.sys_executable
Expand Down Expand Up @@ -455,6 +464,7 @@ struct InterpreterInfo {
prefix: PathBuf,
base_exec_prefix: PathBuf,
base_prefix: PathBuf,
base_executable: Option<PathBuf>,
sys_executable: PathBuf,
}

Expand Down
14 changes: 11 additions & 3 deletions crates/uv-virtualenv/src/bare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,17 @@ pub fn create_bare_venv(
system_site_packages: bool,
extra_cfg: Vec<(String, String)>,
) -> Result<Virtualenv, Error> {
// We have to canonicalize the interpreter path, otherwise the home is set to the venv dir instead of the real root.
// This would make python-build-standalone fail with the encodings module not being found because its home is wrong.
let base_python = fs_err::canonicalize(interpreter.sys_executable())?;
let base_python = if cfg!(unix) {
fs_err::canonicalize(interpreter.sys_executable())?
} else if cfg!(windows) {
if let Some(base_executable) = interpreter.base_executable() {
base_executable.to_path_buf()
} else {
fs_err::canonicalize(interpreter.sys_executable())?
}
} else {
unimplemented!("Only Windows and Unix are supported")
};

// Validate the existing location.
match location.metadata() {
Expand Down

0 comments on commit 7856ed2

Please sign in to comment.