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,10 @@ use uv_types::{
|
||||
};
|
||||
use uv_virtualenv::OnExisting;
|
||||
use uv_warnings::warn_user;
|
||||
use uv_workspace::{DiscoveryOptions, VirtualProject, WorkspaceCache, WorkspaceErrorKind};
|
||||
use uv_workspace::{
|
||||
DiscoveryOptions, ProjectEnvironmentSelection, VirtualProject, WorkspaceCache,
|
||||
WorkspaceErrorKind,
|
||||
};
|
||||
|
||||
use crate::commands::ExitStatus;
|
||||
use crate::commands::pip::loggers::{DefaultInstallLogger, InstallLogger};
|
||||
@@ -133,6 +136,16 @@ pub(crate) async fn venv(
|
||||
let project_environment_selection =
|
||||
project_environment.map(|workspace| workspace.environment_selection(Some(false)));
|
||||
|
||||
if project_environment_selection
|
||||
.as_ref()
|
||||
.is_some_and(ProjectEnvironmentSelection::is_default)
|
||||
&& preview.is_enabled(PreviewFeature::CentralizedProjectEnvs)
|
||||
{
|
||||
warn_user!(
|
||||
"The `centralized-project-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_selection.map_or_else(
|
||||
|
||||
@@ -74,6 +74,74 @@ fn create_venv() {
|
||||
context.venv.assert(predicates::path::is_dir());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_venv_centralized_project_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-project-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-project-envs")
|
||||
.arg("--python")
|
||||
.arg("3.12"), @"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
warning: The `centralized-project-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-project-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