Skip to content

Commit

Permalink
Provide pyproject.toml path for parse errors in uv venv (#10553)
Browse files Browse the repository at this point in the history
## Summary

Closes #10522.

## Test Plan

```
❯ cargo run venv
warning: Failed to parse `pyproject.toml` during environment creation:
  TOML parse error at line 1, column 1
    |
  1 | [project]
    | ^^^^^^^^^
  `pyproject.toml` is using the `[project]` table, but the required `project.version` field is neither set nor present in the `project.dynamic` list

Using CPython 3.13.0
Creating virtual environment at: .venv
Activate with: source .venv/bin/activate
```
  • Loading branch information
charliermarsh authored Jan 13, 2025
1 parent 2401878 commit 53d3d5e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
12 changes: 10 additions & 2 deletions crates/uv/src/commands/venv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
}
}
Expand Down
8 changes: 7 additions & 1 deletion crates/uv/tests/it/venv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 53d3d5e

Please sign in to comment.