mirror of
https://github.com/astral-sh/uv
synced 2026-06-21 13:47:25 +00:00
Warn about lack of uv venv support
This commit is contained in:
@@ -22,7 +22,7 @@ use uv_distribution_types::{
|
||||
use uv_fs::Simplified;
|
||||
use uv_install_wheel::LinkMode;
|
||||
use uv_normalize::DefaultGroups;
|
||||
use uv_preview::Preview;
|
||||
use uv_preview::{Preview, PreviewFeature};
|
||||
use uv_python::{
|
||||
EnvironmentPreference, PythonDownloads, PythonInstallation, PythonPreference, PythonRequest,
|
||||
};
|
||||
@@ -34,7 +34,9 @@ use uv_types::{
|
||||
};
|
||||
use uv_virtualenv::OnExisting;
|
||||
use uv_warnings::warn_user;
|
||||
use uv_workspace::{DiscoveryOptions, VirtualProject, WorkspaceCache, WorkspaceErrorKind};
|
||||
use uv_workspace::{
|
||||
DiscoveryOptions, ProjectEnvironmentTarget, VirtualProject, WorkspaceCache, WorkspaceErrorKind,
|
||||
};
|
||||
|
||||
use crate::commands::ExitStatus;
|
||||
use crate::commands::pip::loggers::{DefaultInstallLogger, InstallLogger};
|
||||
@@ -129,17 +131,22 @@ pub(crate) async fn venv(
|
||||
.as_ref()
|
||||
.map(VirtualProject::workspace)
|
||||
.filter(|workspace| path.is_none() && workspace.install_path() == project_dir);
|
||||
let project_environment_target =
|
||||
project_environment.map(|workspace| workspace.venv(Some(false)));
|
||||
|
||||
if project_environment_target
|
||||
.as_ref()
|
||||
.is_some_and(ProjectEnvironmentTarget::is_default)
|
||||
&& preview.is_enabled(PreviewFeature::CentralizedEnvs)
|
||||
{
|
||||
warn_user!("The `centralized-envs` preview feature currently has no effect on `uv venv`");
|
||||
}
|
||||
|
||||
// Determine the default path; either the virtual environment for the project or `.venv`.
|
||||
let path = path.unwrap_or_else(|| {
|
||||
project_environment.map_or_else(
|
||||
project_environment_target.map_or_else(
|
||||
|| PathBuf::from(".venv"),
|
||||
|workspace| {
|
||||
workspace
|
||||
.venv(Some(false))
|
||||
.project_path(workspace.install_path())
|
||||
.into_owned()
|
||||
},
|
||||
|target| target.project_path(project_dir).into_owned(),
|
||||
)
|
||||
});
|
||||
|
||||
|
||||
@@ -74,6 +74,74 @@ fn create_venv() {
|
||||
context.venv.assert(predicates::path::is_dir());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_venv_centralized_envs_warning() -> Result<()> {
|
||||
let context = uv_test::test_context_with_versions!(&["3.12"]);
|
||||
|
||||
// The feature is project-scoped, so it does not warn outside a project.
|
||||
uv_snapshot!(context.filters(), context.venv()
|
||||
.arg("--preview-features")
|
||||
.arg("centralized-envs")
|
||||
.arg("--python")
|
||||
.arg("3.12"), @"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
Using CPython 3.12.[X] interpreter at: [PYTHON-3.12]
|
||||
Creating virtual environment at: .venv
|
||||
Activate with: source .venv/[BIN]/activate
|
||||
"
|
||||
);
|
||||
|
||||
fs_err::remove_dir_all(&context.venv)?;
|
||||
context
|
||||
.temp_dir
|
||||
.child("pyproject.toml")
|
||||
.write_str(indoc! {r#"
|
||||
[project]
|
||||
name = "project"
|
||||
version = "0.1.0"
|
||||
"#})?;
|
||||
|
||||
uv_snapshot!(context.filters(), context.venv()
|
||||
.arg("--preview-features")
|
||||
.arg("centralized-envs")
|
||||
.arg("--python")
|
||||
.arg("3.12"), @"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
warning: The `centralized-envs` preview feature currently has no effect on `uv venv`
|
||||
Using CPython 3.12.[X] interpreter at: [PYTHON-3.12]
|
||||
Creating virtual environment at: .venv
|
||||
Activate with: source .venv/[BIN]/activate
|
||||
"
|
||||
);
|
||||
|
||||
uv_snapshot!(context.filters(), context.venv()
|
||||
.env(EnvVars::UV_PROJECT_ENVIRONMENT, "explicit")
|
||||
.arg("--preview-features")
|
||||
.arg("centralized-envs")
|
||||
.arg("--python")
|
||||
.arg("3.12"), @"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
Using CPython 3.12.[X] interpreter at: [PYTHON-3.12]
|
||||
Creating virtual environment at: explicit
|
||||
Activate with: source explicit/[BIN]/activate
|
||||
"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_venv_313() {
|
||||
let context = uv_test::test_context_with_versions!(&["3.13"]);
|
||||
|
||||
Reference in New Issue
Block a user