mirror of https://github.com/astral-sh/uv
feature: shorthand for --with (-w) in uvx and uv tool run (#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? -->
This commit is contained in:
parent
b0348ee2a9
commit
43dbdba578
|
|
@ -3045,7 +3045,7 @@ pub struct RunArgs {
|
||||||
/// When used in a project, these dependencies will be layered on top of the project environment
|
/// 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
|
/// in a separate, ephemeral environment. These dependencies are allowed to conflict with those
|
||||||
/// specified by the project.
|
/// specified by the project.
|
||||||
#[arg(long)]
|
#[arg(short = 'w', long)]
|
||||||
pub with: Vec<comma::CommaSeparatedRequirements>,
|
pub with: Vec<comma::CommaSeparatedRequirements>,
|
||||||
|
|
||||||
/// Run with the given packages installed in editable mode.
|
/// Run with the given packages installed in editable mode.
|
||||||
|
|
@ -4256,7 +4256,7 @@ pub struct ToolRunArgs {
|
||||||
pub from: Option<String>,
|
pub from: Option<String>,
|
||||||
|
|
||||||
/// Run with the given packages installed.
|
/// Run with the given packages installed.
|
||||||
#[arg(long)]
|
#[arg(short = 'w', long)]
|
||||||
pub with: Vec<comma::CommaSeparatedRequirements>,
|
pub with: Vec<comma::CommaSeparatedRequirements>,
|
||||||
|
|
||||||
/// Run with the given packages installed in editable mode
|
/// Run with the given packages installed in editable mode
|
||||||
|
|
@ -4371,7 +4371,7 @@ pub struct ToolInstallArgs {
|
||||||
pub from: Option<String>,
|
pub from: Option<String>,
|
||||||
|
|
||||||
/// Include the following additional requirements.
|
/// Include the following additional requirements.
|
||||||
#[arg(long)]
|
#[arg(short = 'w', long)]
|
||||||
pub with: Vec<comma::CommaSeparatedRequirements>,
|
pub with: Vec<comma::CommaSeparatedRequirements>,
|
||||||
|
|
||||||
/// Include all requirements listed in the given `requirements.txt` files.
|
/// Include all requirements listed in the given `requirements.txt` files.
|
||||||
|
|
|
||||||
|
|
@ -1125,6 +1125,70 @@ fn tool_run_without_output() {
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
fn tool_run_csv_with_shorthand() -> anyhow::Result<()> {
|
||||||
|
let context = TestContext::new("3.12").with_filtered_counts();
|
||||||
|
let tool_dir = context.temp_dir.child("tools");
|
||||||
|
let bin_dir = context.temp_dir.child("bin");
|
||||||
|
|
||||||
|
let anyio_local = context.temp_dir.child("src").child("anyio_local");
|
||||||
|
copy_dir_all(
|
||||||
|
context.workspace_root.join("scripts/packages/anyio_local"),
|
||||||
|
&anyio_local,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let black_editable = context.temp_dir.child("src").child("black_editable");
|
||||||
|
copy_dir_all(
|
||||||
|
context
|
||||||
|
.workspace_root
|
||||||
|
.join("scripts/packages/black_editable"),
|
||||||
|
&black_editable,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let pyproject_toml = context.temp_dir.child("pyproject.toml");
|
||||||
|
pyproject_toml.write_str(indoc! { r#"
|
||||||
|
[project]
|
||||||
|
name = "foo"
|
||||||
|
version = "1.0.0"
|
||||||
|
requires-python = ">=3.8"
|
||||||
|
dependencies = ["anyio", "sniffio==1.3.1"]
|
||||||
|
"#
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let test_script = context.temp_dir.child("main.py");
|
||||||
|
test_script.write_str(indoc! { r"
|
||||||
|
import sniffio
|
||||||
|
"
|
||||||
|
})?;
|
||||||
|
|
||||||
|
// Performs a tool run with a comma-separated `--with` flag.
|
||||||
|
uv_snapshot!(context.filters(), context.tool_run()
|
||||||
|
.arg("-w")
|
||||||
|
.arg("iniconfig,typing-extensions")
|
||||||
|
.arg("pytest")
|
||||||
|
.arg("--version")
|
||||||
|
.env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str())
|
||||||
|
.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
|
||||||
|
+ typing-extensions==4.10.0
|
||||||
|
"###);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
fn tool_run_csv_with() -> anyhow::Result<()> {
|
fn tool_run_csv_with() -> anyhow::Result<()> {
|
||||||
|
|
|
||||||
|
|
@ -200,6 +200,12 @@ The `--with` option supports package specifications, so a specific version can b
|
||||||
$ uvx --with <extra-package>==<version> <tool-package>
|
$ uvx --with <extra-package>==<version> <tool-package>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The `-w` shorthand can be used in place of the `--with` option:
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ uvx -w <extra-package> <tool-package>
|
||||||
|
```
|
||||||
|
|
||||||
If the requested version conflicts with the requirements of the tool package, package resolution
|
If the requested version conflicts with the requirements of the tool package, package resolution
|
||||||
will fail and the command will error.
|
will fail and the command will error.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -246,7 +246,7 @@ used.</p>
|
||||||
</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>
|
</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>
|
||||||
</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>
|
</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>
|
||||||
<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>
|
<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>
|
||||||
</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>
|
</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>
|
||||||
<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>
|
<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>
|
||||||
</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>
|
</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>
|
||||||
<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>
|
<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]
|
||||||
</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>
|
</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>
|
||||||
</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>
|
</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>
|
||||||
<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>
|
<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>
|
||||||
</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>
|
</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>
|
||||||
</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>
|
</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>
|
||||||
<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>
|
<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>
|
||||||
</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>
|
</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>
|
||||||
</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>
|
</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>
|
||||||
</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>
|
</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>
|
||||||
<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>
|
<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>
|
||||||
</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>
|
</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>
|
||||||
</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>
|
</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>
|
||||||
</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>
|
</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>
|
||||||
</dd></dl>
|
</dd></dl>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue