Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug where no warning is output when parsing of workspace settings fails. #4014

Merged
merged 3 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions crates/uv-warnings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ pub fn enable() {
ENABLED.store(true, std::sync::atomic::Ordering::SeqCst);
}

/// Disable user-facing warnings.
pub fn disable() {
ENABLED.store(false, std::sync::atomic::Ordering::SeqCst);
}

/// Warn a user, if warnings are enabled.
#[macro_export]
macro_rules! warn_user {
Expand Down
9 changes: 8 additions & 1 deletion crates/uv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ async fn run() -> Result<ExitStatus> {
}
};

// enable flag to pick up warnings generated by workspace loading.
if !cli.global_args.quiet {
uv_warnings::enable();
}

// Load the workspace settings, prioritizing (in order):
// 1. The configuration file specified on the command-line.
// 2. The configuration file in the current directory.
Expand Down Expand Up @@ -148,7 +153,9 @@ async fn run() -> Result<ExitStatus> {
};

// Configure the `warn!` macros, which control user-facing warnings in the CLI.
if !globals.quiet {
if globals.quiet {
uv_warnings::disable();
} else {
uv_warnings::enable();
}

Expand Down
9 changes: 8 additions & 1 deletion crates/uv/tests/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3048,7 +3048,6 @@ fn override_multi_dependency() -> Result<()> {
}

/// Check how invalid `tool.uv.override-dependencies` is handled in `pyproject.toml`.
// TODO(konsti): We should show a warnings here or better fail parsing.
#[test]
fn override_dependency_from_workspace_invalid_syntax() -> Result<()> {
let context = TestContext::new("3.12");
Expand Down Expand Up @@ -3095,6 +3094,14 @@ fn override_dependency_from_workspace_invalid_syntax() -> Result<()> {
# via flask

----- stderr -----
warning: Failed to parse `pyproject.toml`: TOML parse error at line 9, column 29
|
9 | override-dependencies = [
| ^
no such comparison operator "=", must be one of ~= == != <= >= < > ===
werkzeug=2.3.0
^^^^^^

Resolved 7 packages in [TIME]
"###
);
Expand Down
6 changes: 6 additions & 0 deletions crates/uv/tests/pip_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ fn invalid_pyproject_toml_syntax() -> Result<()> {
----- stdout -----

----- stderr -----
warning: Failed to parse `pyproject.toml`: TOML parse error at line 1, column 5
|
1 | 123 - 456
| ^
expected `.`, `=`

error: Failed to parse: `pyproject.toml`
Caused by: TOML parse error at line 1, column 5
|
Expand Down
Loading