From 0734b0317e15b85c75a73884d2715b65395c2fba Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sun, 12 Jan 2025 21:58:19 -0500 Subject: [PATCH] Provide pyproject.toml path for parse errors in uv venv --- crates/uv/src/commands/venv.rs | 12 ++++++++++-- crates/uv/tests/it/venv.rs | 8 +++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/crates/uv/src/commands/venv.rs b/crates/uv/src/commands/venv.rs index f6a731ebbfcb..0fe661223775 100644 --- a/crates/uv/src/commands/venv.rs +++ b/crates/uv/src/commands/venv.rs @@ -27,7 +27,7 @@ use uv_resolver::{ExcludeNewer, FlatIndex}; use uv_settings::PythonInstallMirrors; use uv_shell::{shlex_posix, shlex_windows, Shell}; use uv_types::{AnyErrorBuild, BuildContext, BuildIsolation, BuildStack, HashStrategy}; -use uv_warnings::{warn_user, warn_user_once}; +use uv_warnings::warn_user; use uv_workspace::{DiscoveryOptions, VirtualProject, WorkspaceError}; use crate::commands::pip::loggers::{DefaultInstallLogger, InstallLogger}; @@ -162,8 +162,16 @@ async fn venv_impl( Err(WorkspaceError::MissingProject(_)) => None, Err(WorkspaceError::MissingPyprojectToml) => None, Err(WorkspaceError::NonWorkspace(_)) => None, + Err(WorkspaceError::Toml(path, err)) => { + warn_user!( + "Failed to parse `{}` during environment creation:\n{}", + path.user_display().cyan(), + textwrap::indent(&err.to_string(), " ") + ); + None + } Err(err) => { - warn_user_once!("{err}"); + warn_user!("{err}"); None } } diff --git a/crates/uv/tests/it/venv.rs b/crates/uv/tests/it/venv.rs index 127b52907b8d..2b1542d73a3a 100644 --- a/crates/uv/tests/it/venv.rs +++ b/crates/uv/tests/it/venv.rs @@ -535,7 +535,13 @@ fn create_venv_warns_user_on_requires_python_discovery_error() -> Result<()> { | ^ expected `.`, `=` - warning: Failed to parse: `pyproject.toml` + warning: Failed to parse `pyproject.toml` during environment creation: + TOML parse error at line 1, column 9 + | + 1 | invalid toml + | ^ + expected `.`, `=` + Using CPython 3.12.[X] interpreter at: [PYTHON-3.12] Creating virtual environment at: .venv Activate with: source .venv/[BIN]/activate