diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index 5b03c55e5666d..558ec43c5f15c 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -76,7 +76,6 @@ const STYLES: Styles = Styles::styled() #[derive(Parser)] #[command(name = "uv", author, long_version = crate::version::uv_self_version())] #[command(about = "An extremely fast Python package manager.")] -#[command(propagate_version = true)] #[command( after_help = "Use `uv help` for more details.", after_long_help = "", @@ -127,7 +126,7 @@ pub struct TopLevelArgs { help: Option, /// Display the uv version. - #[arg(global = true, short = 'V', long, action = clap::ArgAction::Version, help_heading = "Global options")] + #[arg(short = 'V', long, action = clap::ArgAction::Version)] version: Option, } @@ -4062,9 +4061,10 @@ pub enum ToolCommand { override_usage = "uvx [OPTIONS] [COMMAND]", about = "Run a command provided by a Python package.", after_help = "Use `uv help tool run` for more details.", - after_long_help = "" + after_long_help = "", + long_version = crate::version::uv_self_version() )] - Uvx(ToolRunArgs), + Uvx(UvxArgs), /// Install commands provided by a Python package. /// /// Packages are installed into an isolated virtual environment in the uv tools directory. The @@ -4222,6 +4222,16 @@ pub struct ToolRunArgs { pub generate_shell_completion: Option, } +#[derive(Args)] +pub struct UvxArgs { + #[command(flatten)] + pub tool_run: ToolRunArgs, + + /// Display the uvx version. + #[arg(short = 'V', long, action = clap::ArgAction::Version)] + pub version: Option, +} + #[derive(Args)] #[allow(clippy::struct_excessive_bools)] pub struct ToolInstallArgs { diff --git a/crates/uv/src/lib.rs b/crates/uv/src/lib.rs index bdef0be80afb5..1dd8b24647e7d 100644 --- a/crates/uv/src/lib.rs +++ b/crates/uv/src/lib.rs @@ -1067,7 +1067,7 @@ async fn run(mut cli: Cli) -> Result { command: run_variant @ (ToolCommand::Uvx(_) | ToolCommand::Run(_)), }) => { let (args, invocation_source) = match run_variant { - ToolCommand::Uvx(args) => (args, ToolRunCommand::Uvx), + ToolCommand::Uvx(args) => (args.tool_run, ToolRunCommand::Uvx), ToolCommand::Run(args) => (args, ToolRunCommand::ToolRun), // OK guarded by the outer match statement _ => unreachable!(), @@ -1081,15 +1081,15 @@ async fn run(mut cli: Cli) -> Result { .find_subcommand("uvx") .unwrap() .clone() - // Avoid duplicating the `--help` and `--version` flags from the top-level arguments. + // Avoid duplicating the `--help` and `--version` flags from the top-level + // arguments. .disable_help_flag(true) - .disable_version_flag(true) - .version(env!("CARGO_PKG_VERSION")); + .disable_version_flag(true); - // Copy the top-level arguments into the `uvx` command. (Like `Args::augment_args`, but - // expanded to skip collisions.) + // Copy the top-level arguments into the `uvx` command, as in `Args::augment_args`, + // but expanded to skip collisions. for arg in TopLevelArgs::command().get_arguments() { - if arg.get_id() != "isolated" { + if arg.get_id() != "isolated" && arg.get_id() != "version" { uvx = uvx.arg(arg); } } diff --git a/crates/uv/tests/it/help.rs b/crates/uv/tests/it/help.rs index b1f883f4984e8..c3d9f853acd12 100644 --- a/crates/uv/tests/it/help.rs +++ b/crates/uv/tests/it/help.rs @@ -438,9 +438,6 @@ fn help_subcommand() { -h, --help Display the concise help for this command - -V, --version - Display the uv version - Use `uv help python ` for more information on a specific command. @@ -691,9 +688,6 @@ fn help_subsubcommand() { -h, --help Display the concise help for this command - -V, --version - Display the uv version - ----- stderr ----- "#); @@ -755,8 +749,6 @@ fn help_flag_subcommand() { Avoid discovering configuration files (`pyproject.toml`, `uv.toml`) [env: UV_NO_CONFIG=] -h, --help Display the concise help for this command - -V, --version - Display the uv version Use `uv help python` for more details. @@ -826,8 +818,6 @@ fn help_flag_subsubcommand() { Avoid discovering configuration files (`pyproject.toml`, `uv.toml`) [env: UV_NO_CONFIG=] -h, --help Display the concise help for this command - -V, --version - Display the uv version ----- stderr ----- "#); @@ -896,7 +886,7 @@ fn help_unknown_subcommand() { fn help_unknown_subsubcommand() { let context = TestContext::new_with_versions(&[]); - uv_snapshot!(context.filters(), context.help().arg("python").arg("foobar"), @r###" + uv_snapshot!(context.filters(), context.help().arg("python").arg("foobar"), @r" success: false exit_code: 2 ----- stdout ----- @@ -909,7 +899,7 @@ fn help_unknown_subsubcommand() { pin dir uninstall - "###); + "); } #[test] @@ -1014,14 +1004,20 @@ fn help_with_help() { fn help_with_version() { let context = TestContext::new_with_versions(&[]); - uv_snapshot!(context.filters(), context.help().arg("--version"), @r###" - success: true - exit_code: 0 + uv_snapshot!(context.filters(), context.help().arg("--version"), @r" + success: false + exit_code: 2 ----- stdout ----- - uv [VERSION] ([COMMIT] DATE) ----- stderr ----- - "###); + error: unexpected argument '--version' found + + tip: a similar argument exists: '--verbose' + + Usage: uv help --verbose... [COMMAND]... + + For more information, try '--help'. + "); } #[test] diff --git a/crates/uv/tests/it/run.rs b/crates/uv/tests/it/run.rs index 00e2d6115b76d..610f5e2f9d0d7 100644 --- a/crates/uv/tests/it/run.rs +++ b/crates/uv/tests/it/run.rs @@ -143,6 +143,10 @@ fn run_with_python_version() -> Result<()> { fn run_args() -> Result<()> { let context = TestContext::new("3.12"); + let mut filters = context.filters(); + filters.push((r"Usage: (uv|\.exe) run \[OPTIONS\] (?s).*", "[UV RUN HELP]")); + filters.push((r"usage: (\[VENV\]|\[PYTHON-3.12\])(?s).*", "[PYTHON HELP]")); + let pyproject_toml = context.temp_dir.child("pyproject.toml"); pyproject_toml.write_str(indoc! { r#" [project] @@ -158,31 +162,25 @@ fn run_args() -> Result<()> { })?; // We treat arguments before the command as uv arguments - uv_snapshot!(context.filters(), context.run().arg("--version").arg("python"), @r###" + uv_snapshot!(filters, context.run().arg("--help").arg("python"), @r" success: true exit_code: 0 ----- stdout ----- - uv [VERSION] ([COMMIT] DATE) + Run a command or script - ----- stderr ----- - "###); + [UV RUN HELP] + "); // We don't treat arguments after the command as uv arguments - uv_snapshot!(context.filters(), context.run().arg("python").arg("--version"), @r###" + uv_snapshot!(filters, context.run().arg("python").arg("--help"), @r" success: true exit_code: 0 ----- stdout ----- - Python 3.12.[X] - - ----- stderr ----- - Resolved 1 package in [TIME] - Prepared 1 package in [TIME] - Installed 1 package in [TIME] - + foo==1.0.0 (from file://[TEMP_DIR]/) - "###); + [PYTHON HELP] + "); // Can use `--` to separate uv arguments from the command arguments. - uv_snapshot!(context.filters(), context.run().arg("--").arg("python").arg("--version"), @r###" + uv_snapshot!(filters, context.run().arg("--").arg("python").arg("--version"), @r###" success: true exit_code: 0 ----- stdout ----- diff --git a/crates/uv/tests/it/tool_run.rs b/crates/uv/tests/it/tool_run.rs index 037cd41affd64..fb5e2f182f09d 100644 --- a/crates/uv/tests/it/tool_run.rs +++ b/crates/uv/tests/it/tool_run.rs @@ -9,46 +9,43 @@ use uv_static::EnvVars; #[test] fn tool_run_args() { let context = TestContext::new("3.12").with_filtered_counts(); + let mut filters = context.filters(); + filters.push(( + r"Usage: uv tool run \[OPTIONS\] (?s).*", + "[UV TOOL RUN HELP]", + )); + filters.push((r"usage: pytest \[options\] (?s).*", "[PYTEST HELP]")); let tool_dir = context.temp_dir.child("tools"); let bin_dir = context.temp_dir.child("bin"); - // We treat arguments before the command as uv arguments - uv_snapshot!(context.filters(), context.tool_run() - .arg("--version") + // We treat arguments before the command as uv tool run arguments + uv_snapshot!(filters, context.tool_run() + .arg("--help") .arg("pytest") .env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str()) - .env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str()), @r###" + .env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str()), @r" success: true exit_code: 0 ----- stdout ----- - uv [VERSION] ([COMMIT] DATE) + Run a command provided by a Python package - ----- stderr ----- - "###); + [UV TOOL RUN HELP] + "); - // We don't treat arguments after the command as uv arguments - uv_snapshot!(context.filters(), context.tool_run() + // We don't treat arguments after the command as uv tool run arguments + uv_snapshot!(filters, context.tool_run() .arg("pytest") - .arg("--version") + .arg("--help") .env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str()) - .env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str()), @r###" + .env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str()), @r" success: true exit_code: 0 ----- stdout ----- - pytest 8.1.1 - - ----- stderr ----- - Resolved [N] packages in [TIME] - Prepared [N] packages in [TIME] - Installed [N] packages in [TIME] - + iniconfig==2.0.0 - + packaging==24.0 - + pluggy==1.4.0 - + pytest==8.1.1 - "###); + [PYTEST HELP] + "); // Can use `--` to separate uv arguments from the command arguments. - uv_snapshot!(context.filters(), context.tool_run() + uv_snapshot!(filters, context.tool_run() .arg("--") .arg("pytest") .arg("--version") diff --git a/docs/reference/cli.md b/docs/reference/cli.md index 816d14558a517..90aa2d4c5f3fc 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -481,8 +481,6 @@ uv run [OPTIONS] [COMMAND]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
--with with

Run with the given packages installed.

When used in a project, these dependencies will be layered on top of the project environment in a separate, ephemeral environment. These dependencies are allowed to conflict with those specified by the project.

@@ -731,8 +729,6 @@ uv init [OPTIONS] [PATH]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
## uv add @@ -1114,8 +1110,6 @@ uv add [OPTIONS] >

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
## uv remove @@ -1462,8 +1456,6 @@ uv remove [OPTIONS] ...

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
## uv sync @@ -1888,8 +1880,6 @@ uv sync [OPTIONS]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
## uv lock @@ -2206,8 +2196,6 @@ uv lock [OPTIONS]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
## uv export @@ -2615,8 +2603,6 @@ uv export [OPTIONS]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
## uv tree @@ -3059,8 +3045,6 @@ uv tree [OPTIONS]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
## uv tool @@ -3433,8 +3417,6 @@ uv tool run [OPTIONS] [COMMAND]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
--with with

Run with the given packages installed

--with-editable with-editable

Run with the given packages installed in editable mode

@@ -3775,8 +3757,6 @@ uv tool install [OPTIONS]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
--with with

Include the following extra requirements

--with-editable with-editable

Include the given packages in editable mode

@@ -4084,8 +4064,6 @@ uv tool upgrade [OPTIONS] ...

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
### uv tool list @@ -4200,8 +4178,6 @@ uv tool list [OPTIONS]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
### uv tool uninstall @@ -4322,8 +4298,6 @@ uv tool uninstall [OPTIONS] ...

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
### uv tool update-shell @@ -4442,8 +4416,6 @@ uv tool update-shell [OPTIONS]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
### uv tool dir @@ -4580,8 +4552,6 @@ uv tool dir [OPTIONS]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
## uv python @@ -4810,8 +4780,6 @@ uv python list [OPTIONS] [REQUEST]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
### uv python install @@ -4983,8 +4951,6 @@ uv python install [OPTIONS] [TARGETS]...

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
### uv python find @@ -5124,8 +5090,6 @@ uv python find [OPTIONS] [REQUEST]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
### uv python pin @@ -5274,8 +5238,6 @@ uv python pin [OPTIONS] [REQUEST]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
### uv python dir @@ -5410,8 +5372,6 @@ uv python dir [OPTIONS]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
### uv python uninstall @@ -5537,8 +5497,6 @@ uv python uninstall [OPTIONS] ...

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
## uv pip @@ -6135,8 +6093,6 @@ uv pip compile [OPTIONS] >

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
### uv pip sync @@ -6602,8 +6558,6 @@ uv pip sync [OPTIONS] ...

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
### uv pip install @@ -7155,8 +7109,6 @@ uv pip install [OPTIONS] |--editable You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
### uv pip uninstall @@ -7316,8 +7268,6 @@ uv pip uninstall [OPTIONS] >

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
### uv pip freeze @@ -7450,8 +7400,6 @@ uv pip freeze [OPTIONS]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
### uv pip list @@ -7672,8 +7620,6 @@ uv pip list [OPTIONS]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
### uv pip show @@ -7810,8 +7756,6 @@ uv pip show [OPTIONS] [PACKAGE]...

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
### uv pip tree @@ -8025,8 +7969,6 @@ uv pip tree [OPTIONS]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
### uv pip check @@ -8153,8 +8095,6 @@ uv pip check [OPTIONS]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
## uv venv @@ -8417,8 +8357,6 @@ uv venv [OPTIONS] [PATH]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
## uv build @@ -8772,8 +8710,6 @@ uv build [OPTIONS] [SRC]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
--wheel

Build a binary distribution ("wheel") from the given directory

@@ -8969,8 +8905,6 @@ uv publish --publish-url https://upload.pypi.org/legacy/ --check-url https://pyp

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
## uv cache @@ -9109,8 +9043,6 @@ uv cache clean [OPTIONS] [PACKAGE]...

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
### uv cache prune @@ -9229,8 +9161,6 @@ uv cache prune [OPTIONS]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
### uv cache dir @@ -9351,8 +9281,6 @@ uv cache dir [OPTIONS]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
## uv self @@ -9492,8 +9420,6 @@ uv self update [OPTIONS] [TARGET_VERSION]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
### uv self version @@ -9608,8 +9534,6 @@ uv self version [OPTIONS]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
## uv version @@ -9749,8 +9673,6 @@ uv version [OPTIONS] [VALUE]

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-
## uv generate-shell-completion @@ -9925,7 +9847,5 @@ uv help [OPTIONS] [COMMAND]...

You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)

-
--version, -V

Display the uv version

-