mirror of
https://github.com/astral-sh/uv.git
synced 2025-09-11 04:56:24 +00:00
Add support for --system-site-packages
in uv venv
(#2101)
## Summary Adds support for `--system-site-packages`. Unlike `pip`, we won't take the system site packages into account in subsequent commands. I think this is ok. Closes https://github.com/astral-sh/uv/issues/1483.
This commit is contained in:
parent
d0ffabd1f2
commit
c579e6f6bf
6 changed files with 33 additions and 3 deletions
|
@ -66,6 +66,7 @@ pub fn create_bare_venv(
|
||||||
location: &Utf8Path,
|
location: &Utf8Path,
|
||||||
interpreter: &Interpreter,
|
interpreter: &Interpreter,
|
||||||
prompt: Prompt,
|
prompt: Prompt,
|
||||||
|
system_site_packages: bool,
|
||||||
extra_cfg: Vec<(String, String)>,
|
extra_cfg: Vec<(String, String)>,
|
||||||
) -> Result<VenvPaths, Error> {
|
) -> Result<VenvPaths, Error> {
|
||||||
// We have to canonicalize the interpreter path, otherwise the home is set to the venv dir instead of the real root.
|
// We have to canonicalize the interpreter path, otherwise the home is set to the venv dir instead of the real root.
|
||||||
|
@ -251,7 +252,11 @@ pub fn create_bare_venv(
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"include-system-site-packages".to_string(),
|
"include-system-site-packages".to_string(),
|
||||||
"false".to_string(),
|
if system_site_packages {
|
||||||
|
"true".to_string()
|
||||||
|
} else {
|
||||||
|
"false".to_string()
|
||||||
|
},
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"base-prefix".to_string(),
|
"base-prefix".to_string(),
|
||||||
|
|
|
@ -51,12 +51,19 @@ pub fn create_venv(
|
||||||
location: &Path,
|
location: &Path,
|
||||||
interpreter: Interpreter,
|
interpreter: Interpreter,
|
||||||
prompt: Prompt,
|
prompt: Prompt,
|
||||||
|
system_site_packages: bool,
|
||||||
extra_cfg: Vec<(String, String)>,
|
extra_cfg: Vec<(String, String)>,
|
||||||
) -> Result<PythonEnvironment, Error> {
|
) -> Result<PythonEnvironment, Error> {
|
||||||
let location: &Utf8Path = location
|
let location: &Utf8Path = location
|
||||||
.try_into()
|
.try_into()
|
||||||
.map_err(|err: FromPathError| err.into_io_error())?;
|
.map_err(|err: FromPathError| err.into_io_error())?;
|
||||||
let paths = create_bare_venv(location, &interpreter, prompt, extra_cfg)?;
|
let paths = create_bare_venv(
|
||||||
|
location,
|
||||||
|
&interpreter,
|
||||||
|
prompt,
|
||||||
|
system_site_packages,
|
||||||
|
extra_cfg,
|
||||||
|
)?;
|
||||||
Ok(PythonEnvironment::from_interpreter(
|
Ok(PythonEnvironment::from_interpreter(
|
||||||
interpreter,
|
interpreter,
|
||||||
paths.root.as_std_path(),
|
paths.root.as_std_path(),
|
||||||
|
|
|
@ -23,6 +23,8 @@ struct Cli {
|
||||||
python: Option<String>,
|
python: Option<String>,
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
prompt: Option<String>,
|
prompt: Option<String>,
|
||||||
|
#[clap(long)]
|
||||||
|
system_site_packages: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run() -> Result<(), gourgeist::Error> {
|
fn run() -> Result<(), gourgeist::Error> {
|
||||||
|
@ -45,6 +47,7 @@ fn run() -> Result<(), gourgeist::Error> {
|
||||||
&location,
|
&location,
|
||||||
&interpreter,
|
&interpreter,
|
||||||
Prompt::from_args(cli.prompt),
|
Prompt::from_args(cli.prompt),
|
||||||
|
cli.system_site_packages,
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
)?;
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -402,6 +402,7 @@ impl SourceBuild {
|
||||||
&temp_dir.path().join(".venv"),
|
&temp_dir.path().join(".venv"),
|
||||||
interpreter.clone(),
|
interpreter.clone(),
|
||||||
gourgeist::Prompt::None,
|
gourgeist::Prompt::None,
|
||||||
|
false,
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ pub(crate) async fn venv(
|
||||||
python_request: Option<&str>,
|
python_request: Option<&str>,
|
||||||
index_locations: &IndexLocations,
|
index_locations: &IndexLocations,
|
||||||
prompt: Prompt,
|
prompt: Prompt,
|
||||||
|
system_site_packages: bool,
|
||||||
connectivity: Connectivity,
|
connectivity: Connectivity,
|
||||||
seed: bool,
|
seed: bool,
|
||||||
exclude_newer: Option<DateTime<Utc>>,
|
exclude_newer: Option<DateTime<Utc>>,
|
||||||
|
@ -45,6 +46,7 @@ pub(crate) async fn venv(
|
||||||
python_request,
|
python_request,
|
||||||
index_locations,
|
index_locations,
|
||||||
prompt,
|
prompt,
|
||||||
|
system_site_packages,
|
||||||
connectivity,
|
connectivity,
|
||||||
seed,
|
seed,
|
||||||
exclude_newer,
|
exclude_newer,
|
||||||
|
@ -87,6 +89,7 @@ async fn venv_impl(
|
||||||
python_request: Option<&str>,
|
python_request: Option<&str>,
|
||||||
index_locations: &IndexLocations,
|
index_locations: &IndexLocations,
|
||||||
prompt: Prompt,
|
prompt: Prompt,
|
||||||
|
system_site_packages: bool,
|
||||||
connectivity: Connectivity,
|
connectivity: Connectivity,
|
||||||
seed: bool,
|
seed: bool,
|
||||||
exclude_newer: Option<DateTime<Utc>>,
|
exclude_newer: Option<DateTime<Utc>>,
|
||||||
|
@ -123,7 +126,7 @@ async fn venv_impl(
|
||||||
let extra_cfg = vec![("uv".to_string(), env!("CARGO_PKG_VERSION").to_string())];
|
let extra_cfg = vec![("uv".to_string(), env!("CARGO_PKG_VERSION").to_string())];
|
||||||
|
|
||||||
// Create the virtual environment.
|
// Create the virtual environment.
|
||||||
let venv = gourgeist::create_venv(path, interpreter, prompt, extra_cfg)
|
let venv = gourgeist::create_venv(path, interpreter, prompt, system_site_packages, extra_cfg)
|
||||||
.map_err(VenvError::Creation)?;
|
.map_err(VenvError::Creation)?;
|
||||||
|
|
||||||
// Install seed packages.
|
// Install seed packages.
|
||||||
|
|
|
@ -936,6 +936,16 @@ struct VenvArgs {
|
||||||
#[clap(long, verbatim_doc_comment)]
|
#[clap(long, verbatim_doc_comment)]
|
||||||
prompt: Option<String>,
|
prompt: Option<String>,
|
||||||
|
|
||||||
|
/// Give the virtual environment access to the system site packages directory.
|
||||||
|
///
|
||||||
|
/// Unlike `pip`, when a virtual environment is created with `--system-site-packages`, `uv` will
|
||||||
|
/// _not_ take system site packages into account when running commands like `uv pip list` or
|
||||||
|
/// `uv pip install`. The `--system-site-packages` flag will provide the virtual environment
|
||||||
|
/// with access to the system site packages directory at runtime, but it will not affect the
|
||||||
|
/// behavior of `uv` commands.
|
||||||
|
#[clap(long)]
|
||||||
|
system_site_packages: bool,
|
||||||
|
|
||||||
/// The URL of the Python package index (by default: <https://pypi.org/simple>).
|
/// The URL of the Python package index (by default: <https://pypi.org/simple>).
|
||||||
///
|
///
|
||||||
/// The index given by this flag is given lower priority than all other
|
/// The index given by this flag is given lower priority than all other
|
||||||
|
@ -1388,6 +1398,7 @@ async fn run() -> Result<ExitStatus> {
|
||||||
args.python.as_deref(),
|
args.python.as_deref(),
|
||||||
&index_locations,
|
&index_locations,
|
||||||
gourgeist::Prompt::from_args(prompt),
|
gourgeist::Prompt::from_args(prompt),
|
||||||
|
args.system_site_packages,
|
||||||
if args.offline {
|
if args.offline {
|
||||||
Connectivity::Offline
|
Connectivity::Offline
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue