mirror of https://github.com/astral-sh/uv
chore: use uv-version in uv-virtualenv (#3221)
## Summary This is mainly a cleanup PR to leverage uv-version in uv-virtualenv instead of passing it via `uv`. In #1852 I introduced the ability to pass extra cfg to `gourgeist` for the primary purpose of passing the uv version, but since the dawn of the uv-version crate dynamically passing more values to pyvenv.cfg is no longer needed. ## Test Plan Existing `uv` tests should still verify `uv = <version>` exists in the venv and make sure no regressions were introduced.
This commit is contained in:
parent
f0c0f874ce
commit
308f95fce1
|
|
@ -5035,6 +5035,7 @@ dependencies = [
|
||||||
"uv-cache",
|
"uv-cache",
|
||||||
"uv-fs",
|
"uv-fs",
|
||||||
"uv-interpreter",
|
"uv-interpreter",
|
||||||
|
"uv-version",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
||||||
|
|
@ -414,7 +414,6 @@ impl SourceBuild {
|
||||||
interpreter.clone(),
|
interpreter.clone(),
|
||||||
uv_virtualenv::Prompt::None,
|
uv_virtualenv::Prompt::None,
|
||||||
false,
|
false,
|
||||||
Vec::new(),
|
|
||||||
)?,
|
)?,
|
||||||
BuildIsolation::Shared(venv) => venv.clone(),
|
BuildIsolation::Shared(venv) => venv.clone(),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ pypi-types = { workspace = true }
|
||||||
uv-cache = { workspace = true }
|
uv-cache = { workspace = true }
|
||||||
uv-fs = { workspace = true }
|
uv-fs = { workspace = true }
|
||||||
uv-interpreter = { workspace = true }
|
uv-interpreter = { workspace = true }
|
||||||
|
uv-version = { workspace = true }
|
||||||
|
|
||||||
anstream = { workspace = true }
|
anstream = { workspace = true }
|
||||||
cachedir = { workspace = true }
|
cachedir = { workspace = true }
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,10 @@ use fs_err::File;
|
||||||
use pypi_types::Scheme;
|
use pypi_types::Scheme;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
|
use crate::{Error, Prompt};
|
||||||
use uv_fs::Simplified;
|
use uv_fs::Simplified;
|
||||||
use uv_interpreter::{Interpreter, Virtualenv};
|
use uv_interpreter::{Interpreter, Virtualenv};
|
||||||
|
use uv_version::version;
|
||||||
use crate::{Error, Prompt};
|
|
||||||
|
|
||||||
/// The bash activate scripts with the venv dependent paths patches out
|
/// The bash activate scripts with the venv dependent paths patches out
|
||||||
const ACTIVATE_TEMPLATES: &[(&str, &str)] = &[
|
const ACTIVATE_TEMPLATES: &[(&str, &str)] = &[
|
||||||
|
|
@ -47,7 +47,6 @@ pub fn create_bare_venv(
|
||||||
interpreter: &Interpreter,
|
interpreter: &Interpreter,
|
||||||
prompt: Prompt,
|
prompt: Prompt,
|
||||||
system_site_packages: bool,
|
system_site_packages: bool,
|
||||||
extra_cfg: Vec<(String, String)>,
|
|
||||||
) -> Result<Virtualenv, Error> {
|
) -> Result<Virtualenv, Error> {
|
||||||
// Determine the base Python executable; that is, the Python executable that should be
|
// Determine the base Python executable; that is, the Python executable that should be
|
||||||
// considered the "base" for the virtual environment. This is typically the Python executable
|
// considered the "base" for the virtual environment. This is typically the Python executable
|
||||||
|
|
@ -218,23 +217,6 @@ pub fn create_bare_venv(
|
||||||
fs::write(scripts.join(name), activator)?;
|
fs::write(scripts.join(name), activator)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate extra_cfg
|
|
||||||
let reserved_keys = [
|
|
||||||
"home",
|
|
||||||
"implementation",
|
|
||||||
"version_info",
|
|
||||||
"include-system-site-packages",
|
|
||||||
"base-prefix",
|
|
||||||
"base-exec-prefix",
|
|
||||||
"base-executable",
|
|
||||||
"prompt",
|
|
||||||
];
|
|
||||||
for (key, _) in &extra_cfg {
|
|
||||||
if reserved_keys.contains(&key.as_str()) {
|
|
||||||
return Err(Error::ReservedConfigKey(key.to_string()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut pyvenv_cfg_data: Vec<(String, String)> = vec![
|
let mut pyvenv_cfg_data: Vec<(String, String)> = vec![
|
||||||
(
|
(
|
||||||
"home".to_string(),
|
"home".to_string(),
|
||||||
|
|
@ -244,6 +226,7 @@ pub fn create_bare_venv(
|
||||||
"implementation".to_string(),
|
"implementation".to_string(),
|
||||||
interpreter.markers().platform_python_implementation.clone(),
|
interpreter.markers().platform_python_implementation.clone(),
|
||||||
),
|
),
|
||||||
|
("uv".to_string(), version().to_string()),
|
||||||
(
|
(
|
||||||
"version_info".to_string(),
|
"version_info".to_string(),
|
||||||
interpreter.markers().python_full_version.string.clone(),
|
interpreter.markers().python_full_version.string.clone(),
|
||||||
|
|
@ -256,10 +239,7 @@ pub fn create_bare_venv(
|
||||||
"false".to_string()
|
"false".to_string()
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
]
|
];
|
||||||
.into_iter()
|
|
||||||
.chain(extra_cfg)
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
if let Some(prompt) = prompt {
|
if let Some(prompt) = prompt {
|
||||||
pyvenv_cfg_data.push(("prompt".to_string(), prompt));
|
pyvenv_cfg_data.push(("prompt".to_string(), prompt));
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,6 @@ pub enum Error {
|
||||||
InterpreterError(#[from] uv_interpreter::Error),
|
InterpreterError(#[from] uv_interpreter::Error),
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Platform(#[from] PlatformError),
|
Platform(#[from] PlatformError),
|
||||||
#[error("Reserved key used for pyvenv.cfg: {0}")]
|
|
||||||
ReservedConfigKey(String),
|
|
||||||
#[error("Could not find a suitable Python executable for the virtual environment based on the interpreter: {0}")]
|
#[error("Could not find a suitable Python executable for the virtual environment based on the interpreter: {0}")]
|
||||||
NotFound(String),
|
NotFound(String),
|
||||||
}
|
}
|
||||||
|
|
@ -53,16 +51,9 @@ pub fn create_venv(
|
||||||
interpreter: Interpreter,
|
interpreter: Interpreter,
|
||||||
prompt: Prompt,
|
prompt: Prompt,
|
||||||
system_site_packages: bool,
|
system_site_packages: bool,
|
||||||
extra_cfg: Vec<(String, String)>,
|
|
||||||
) -> Result<PythonEnvironment, Error> {
|
) -> Result<PythonEnvironment, Error> {
|
||||||
// Create the virtualenv at the given location.
|
// Create the virtualenv at the given location.
|
||||||
let virtualenv = create_bare_venv(
|
let virtualenv = create_bare_venv(location, &interpreter, prompt, system_site_packages)?;
|
||||||
location,
|
|
||||||
&interpreter,
|
|
||||||
prompt,
|
|
||||||
system_site_packages,
|
|
||||||
extra_cfg,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// Create the corresponding `PythonEnvironment`.
|
// Create the corresponding `PythonEnvironment`.
|
||||||
let interpreter = interpreter.with_virtualenv(virtualenv);
|
let interpreter = interpreter.with_virtualenv(virtualenv);
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,6 @@ fn run() -> Result<(), uv_virtualenv::Error> {
|
||||||
&interpreter,
|
&interpreter,
|
||||||
Prompt::from_args(cli.prompt),
|
Prompt::from_args(cli.prompt),
|
||||||
cli.system_site_packages,
|
cli.system_site_packages,
|
||||||
Vec::new(),
|
|
||||||
)?;
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -233,7 +233,6 @@ async fn environment_for_run(
|
||||||
python_env.into_interpreter(),
|
python_env.into_interpreter(),
|
||||||
uv_virtualenv::Prompt::None,
|
uv_virtualenv::Prompt::None,
|
||||||
false,
|
false,
|
||||||
Vec::new(),
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Determine the tags, markers, and interpreter to use for resolution.
|
// Determine the tags, markers, and interpreter to use for resolution.
|
||||||
|
|
|
||||||
|
|
@ -140,12 +140,8 @@ async fn venv_impl(
|
||||||
)
|
)
|
||||||
.into_diagnostic()?;
|
.into_diagnostic()?;
|
||||||
|
|
||||||
// Extra cfg for pyvenv.cfg to specify uv version
|
|
||||||
let extra_cfg = vec![("uv".to_string(), env!("CARGO_PKG_VERSION").to_string())];
|
|
||||||
|
|
||||||
// Create the virtual environment.
|
// Create the virtual environment.
|
||||||
let venv =
|
let venv = uv_virtualenv::create_venv(path, interpreter, prompt, system_site_packages)
|
||||||
uv_virtualenv::create_venv(path, interpreter, prompt, system_site_packages, extra_cfg)
|
|
||||||
.map_err(VenvError::Creation)?;
|
.map_err(VenvError::Creation)?;
|
||||||
|
|
||||||
// Install seed packages.
|
// Install seed packages.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue