mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00
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
8 changed files with 9 additions and 43 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -5035,6 +5035,7 @@ dependencies = [
|
|||
"uv-cache",
|
||||
"uv-fs",
|
||||
"uv-interpreter",
|
||||
"uv-version",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -414,7 +414,6 @@ impl SourceBuild {
|
|||
interpreter.clone(),
|
||||
uv_virtualenv::Prompt::None,
|
||||
false,
|
||||
Vec::new(),
|
||||
)?,
|
||||
BuildIsolation::Shared(venv) => venv.clone(),
|
||||
};
|
||||
|
|
|
@ -26,6 +26,7 @@ pypi-types = { workspace = true }
|
|||
uv-cache = { workspace = true }
|
||||
uv-fs = { workspace = true }
|
||||
uv-interpreter = { workspace = true }
|
||||
uv-version = { workspace = true }
|
||||
|
||||
anstream = { workspace = true }
|
||||
cachedir = { workspace = true }
|
||||
|
|
|
@ -11,10 +11,10 @@ use fs_err::File;
|
|||
use pypi_types::Scheme;
|
||||
use tracing::info;
|
||||
|
||||
use crate::{Error, Prompt};
|
||||
use uv_fs::Simplified;
|
||||
use uv_interpreter::{Interpreter, Virtualenv};
|
||||
|
||||
use crate::{Error, Prompt};
|
||||
use uv_version::version;
|
||||
|
||||
/// The bash activate scripts with the venv dependent paths patches out
|
||||
const ACTIVATE_TEMPLATES: &[(&str, &str)] = &[
|
||||
|
@ -47,7 +47,6 @@ pub fn create_bare_venv(
|
|||
interpreter: &Interpreter,
|
||||
prompt: Prompt,
|
||||
system_site_packages: bool,
|
||||
extra_cfg: Vec<(String, String)>,
|
||||
) -> Result<Virtualenv, Error> {
|
||||
// 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
|
||||
|
@ -218,23 +217,6 @@ pub fn create_bare_venv(
|
|||
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![
|
||||
(
|
||||
"home".to_string(),
|
||||
|
@ -244,6 +226,7 @@ pub fn create_bare_venv(
|
|||
"implementation".to_string(),
|
||||
interpreter.markers().platform_python_implementation.clone(),
|
||||
),
|
||||
("uv".to_string(), version().to_string()),
|
||||
(
|
||||
"version_info".to_string(),
|
||||
interpreter.markers().python_full_version.string.clone(),
|
||||
|
@ -256,10 +239,7 @@ pub fn create_bare_venv(
|
|||
"false".to_string()
|
||||
},
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.chain(extra_cfg)
|
||||
.collect();
|
||||
];
|
||||
|
||||
if let Some(prompt) = prompt {
|
||||
pyvenv_cfg_data.push(("prompt".to_string(), prompt));
|
||||
|
|
|
@ -18,8 +18,6 @@ pub enum Error {
|
|||
InterpreterError(#[from] uv_interpreter::Error),
|
||||
#[error(transparent)]
|
||||
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}")]
|
||||
NotFound(String),
|
||||
}
|
||||
|
@ -53,16 +51,9 @@ pub fn create_venv(
|
|||
interpreter: Interpreter,
|
||||
prompt: Prompt,
|
||||
system_site_packages: bool,
|
||||
extra_cfg: Vec<(String, String)>,
|
||||
) -> Result<PythonEnvironment, Error> {
|
||||
// Create the virtualenv at the given location.
|
||||
let virtualenv = create_bare_venv(
|
||||
location,
|
||||
&interpreter,
|
||||
prompt,
|
||||
system_site_packages,
|
||||
extra_cfg,
|
||||
)?;
|
||||
let virtualenv = create_bare_venv(location, &interpreter, prompt, system_site_packages)?;
|
||||
|
||||
// Create the corresponding `PythonEnvironment`.
|
||||
let interpreter = interpreter.with_virtualenv(virtualenv);
|
||||
|
|
|
@ -46,7 +46,6 @@ fn run() -> Result<(), uv_virtualenv::Error> {
|
|||
&interpreter,
|
||||
Prompt::from_args(cli.prompt),
|
||||
cli.system_site_packages,
|
||||
Vec::new(),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -233,7 +233,6 @@ async fn environment_for_run(
|
|||
python_env.into_interpreter(),
|
||||
uv_virtualenv::Prompt::None,
|
||||
false,
|
||||
Vec::new(),
|
||||
)?;
|
||||
|
||||
// Determine the tags, markers, and interpreter to use for resolution.
|
||||
|
|
|
@ -140,13 +140,9 @@ async fn venv_impl(
|
|||
)
|
||||
.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.
|
||||
let venv =
|
||||
uv_virtualenv::create_venv(path, interpreter, prompt, system_site_packages, extra_cfg)
|
||||
.map_err(VenvError::Creation)?;
|
||||
let venv = uv_virtualenv::create_venv(path, interpreter, prompt, system_site_packages)
|
||||
.map_err(VenvError::Creation)?;
|
||||
|
||||
// Install seed packages.
|
||||
if seed {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue