Skip to content

Commit 43dbdba

Browse files
authored
feature: shorthand for --with (-w) in uvx and uv tool run (astral-sh#14530)
<!-- Thank you for contributing to uv! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary This is a small quality of life feature that adds a shorthand (`-w`) to the `--with` flag for minimizing keystrokes. Pretty minor, but I didn't see any conflicts with `-w` and thought this could be a nice place for it. ```bash # proposed addition (short) uvx -w numpy ipython # original (long) uvx --with numpy ipython ``` ## Test Plan Added testing already in the P.R. - just copied over tests from the `--with` flag <!-- How was it tested? -->
1 parent b0348ee commit 43dbdba

File tree

4 files changed

+76
-6
lines changed

4 files changed

+76
-6
lines changed

crates/uv-cli/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3045,7 +3045,7 @@ pub struct RunArgs {
30453045
/// When used in a project, these dependencies will be layered on top of the project environment
30463046
/// in a separate, ephemeral environment. These dependencies are allowed to conflict with those
30473047
/// specified by the project.
3048-
#[arg(long)]
3048+
#[arg(short = 'w', long)]
30493049
pub with: Vec<comma::CommaSeparatedRequirements>,
30503050

30513051
/// Run with the given packages installed in editable mode.
@@ -4256,7 +4256,7 @@ pub struct ToolRunArgs {
42564256
pub from: Option<String>,
42574257

42584258
/// Run with the given packages installed.
4259-
#[arg(long)]
4259+
#[arg(short = 'w', long)]
42604260
pub with: Vec<comma::CommaSeparatedRequirements>,
42614261

42624262
/// Run with the given packages installed in editable mode
@@ -4371,7 +4371,7 @@ pub struct ToolInstallArgs {
43714371
pub from: Option<String>,
43724372

43734373
/// Include the following additional requirements.
4374-
#[arg(long)]
4374+
#[arg(short = 'w', long)]
43754375
pub with: Vec<comma::CommaSeparatedRequirements>,
43764376

43774377
/// Include all requirements listed in the given `requirements.txt` files.

crates/uv/tests/it/tool_run.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,70 @@ fn tool_run_without_output() {
11251125
"###);
11261126
}
11271127

1128+
#[test]
1129+
#[cfg(not(windows))]
1130+
fn tool_run_csv_with_shorthand() -> anyhow::Result<()> {
1131+
let context = TestContext::new("3.12").with_filtered_counts();
1132+
let tool_dir = context.temp_dir.child("tools");
1133+
let bin_dir = context.temp_dir.child("bin");
1134+
1135+
let anyio_local = context.temp_dir.child("src").child("anyio_local");
1136+
copy_dir_all(
1137+
context.workspace_root.join("scripts/packages/anyio_local"),
1138+
&anyio_local,
1139+
)?;
1140+
1141+
let black_editable = context.temp_dir.child("src").child("black_editable");
1142+
copy_dir_all(
1143+
context
1144+
.workspace_root
1145+
.join("scripts/packages/black_editable"),
1146+
&black_editable,
1147+
)?;
1148+
1149+
let pyproject_toml = context.temp_dir.child("pyproject.toml");
1150+
pyproject_toml.write_str(indoc! { r#"
1151+
[project]
1152+
name = "foo"
1153+
version = "1.0.0"
1154+
requires-python = ">=3.8"
1155+
dependencies = ["anyio", "sniffio==1.3.1"]
1156+
"#
1157+
})?;
1158+
1159+
let test_script = context.temp_dir.child("main.py");
1160+
test_script.write_str(indoc! { r"
1161+
import sniffio
1162+
"
1163+
})?;
1164+
1165+
// Performs a tool run with a comma-separated `--with` flag.
1166+
uv_snapshot!(context.filters(), context.tool_run()
1167+
.arg("-w")
1168+
.arg("iniconfig,typing-extensions")
1169+
.arg("pytest")
1170+
.arg("--version")
1171+
.env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str())
1172+
.env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str()), @r###"
1173+
success: true
1174+
exit_code: 0
1175+
----- stdout -----
1176+
pytest 8.1.1
1177+
1178+
----- stderr -----
1179+
Resolved [N] packages in [TIME]
1180+
Prepared [N] packages in [TIME]
1181+
Installed [N] packages in [TIME]
1182+
+ iniconfig==2.0.0
1183+
+ packaging==24.0
1184+
+ pluggy==1.4.0
1185+
+ pytest==8.1.1
1186+
+ typing-extensions==4.10.0
1187+
"###);
1188+
1189+
Ok(())
1190+
}
1191+
11281192
#[test]
11291193
#[cfg(not(windows))]
11301194
fn tool_run_csv_with() -> anyhow::Result<()> {

docs/concepts/tools.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ The `--with` option supports package specifications, so a specific version can b
200200
$ uvx --with <extra-package>==<version> <tool-package>
201201
```
202202

203+
The `-w` shorthand can be used in place of the `--with` option:
204+
205+
```console
206+
$ uvx -w <extra-package> <tool-package>
207+
```
208+
203209
If the requested version conflicts with the requirements of the tool package, package resolution
204210
will fail and the command will error.
205211

docs/reference/cli.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ used.</p>
246246
</dd><dt id="uv-run--upgrade-package"><a href="#uv-run--upgrade-package"><code>--upgrade-package</code></a>, <code>-P</code> <i>upgrade-package</i></dt><dd><p>Allow upgrades for a specific package, ignoring pinned versions in any existing output file. Implies <code>--refresh-package</code></p>
247247
</dd><dt id="uv-run--verbose"><a href="#uv-run--verbose"><code>--verbose</code></a>, <code>-v</code></dt><dd><p>Use verbose output.</p>
248248
<p>You can configure fine-grained logging using the <code>RUST_LOG</code> environment variable. (<a href="https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives">https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives</a>)</p>
249-
</dd><dt id="uv-run--with"><a href="#uv-run--with"><code>--with</code></a> <i>with</i></dt><dd><p>Run with the given packages installed.</p>
249+
</dd><dt id="uv-run--with"><a href="#uv-run--with"><code>--with</code></a>, <code>-w</code> <i>with</i></dt><dd><p>Run with the given packages installed.</p>
250250
<p>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.</p>
251251
</dd><dt id="uv-run--with-editable"><a href="#uv-run--with-editable"><code>--with-editable</code></a> <i>with-editable</i></dt><dd><p>Run with the given packages installed in editable mode.</p>
252252
<p>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.</p>
@@ -1935,7 +1935,7 @@ uv tool run [OPTIONS] [COMMAND]
19351935
</dd><dt id="uv-tool-run--upgrade-package"><a href="#uv-tool-run--upgrade-package"><code>--upgrade-package</code></a>, <code>-P</code> <i>upgrade-package</i></dt><dd><p>Allow upgrades for a specific package, ignoring pinned versions in any existing output file. Implies <code>--refresh-package</code></p>
19361936
</dd><dt id="uv-tool-run--verbose"><a href="#uv-tool-run--verbose"><code>--verbose</code></a>, <code>-v</code></dt><dd><p>Use verbose output.</p>
19371937
<p>You can configure fine-grained logging using the <code>RUST_LOG</code> environment variable. (<a href="https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives">https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives</a>)</p>
1938-
</dd><dt id="uv-tool-run--with"><a href="#uv-tool-run--with"><code>--with</code></a> <i>with</i></dt><dd><p>Run with the given packages installed</p>
1938+
</dd><dt id="uv-tool-run--with"><a href="#uv-tool-run--with"><code>--with</code></a>, <code>-w</code> <i>with</i></dt><dd><p>Run with the given packages installed</p>
19391939
</dd><dt id="uv-tool-run--with-editable"><a href="#uv-tool-run--with-editable"><code>--with-editable</code></a> <i>with-editable</i></dt><dd><p>Run with the given packages installed in editable mode</p>
19401940
<p>When used in a project, these dependencies will be layered on top of the uv tool's environment in a separate, ephemeral environment. These dependencies are allowed to conflict with those specified.</p>
19411941
</dd><dt id="uv-tool-run--with-requirements"><a href="#uv-tool-run--with-requirements"><code>--with-requirements</code></a> <i>with-requirements</i></dt><dd><p>Run with all packages listed in the given <code>requirements.txt</code> files</p>
@@ -2104,7 +2104,7 @@ uv tool install [OPTIONS] <PACKAGE>
21042104
</dd><dt id="uv-tool-install--upgrade-package"><a href="#uv-tool-install--upgrade-package"><code>--upgrade-package</code></a>, <code>-P</code> <i>upgrade-package</i></dt><dd><p>Allow upgrades for a specific package, ignoring pinned versions in any existing output file. Implies <code>--refresh-package</code></p>
21052105
</dd><dt id="uv-tool-install--verbose"><a href="#uv-tool-install--verbose"><code>--verbose</code></a>, <code>-v</code></dt><dd><p>Use verbose output.</p>
21062106
<p>You can configure fine-grained logging using the <code>RUST_LOG</code> environment variable. (<a href="https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives">https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives</a>)</p>
2107-
</dd><dt id="uv-tool-install--with"><a href="#uv-tool-install--with"><code>--with</code></a> <i>with</i></dt><dd><p>Include the following additional requirements</p>
2107+
</dd><dt id="uv-tool-install--with"><a href="#uv-tool-install--with"><code>--with</code></a>, <code>-w</code> <i>with</i></dt><dd><p>Include the following additional requirements</p>
21082108
</dd><dt id="uv-tool-install--with-editable"><a href="#uv-tool-install--with-editable"><code>--with-editable</code></a> <i>with-editable</i></dt><dd><p>Include the given packages in editable mode</p>
21092109
</dd><dt id="uv-tool-install--with-requirements"><a href="#uv-tool-install--with-requirements"><code>--with-requirements</code></a> <i>with-requirements</i></dt><dd><p>Include all requirements listed in the given <code>requirements.txt</code> files</p>
21102110
</dd></dl>

0 commit comments

Comments
 (0)