Add `--no-project` alias for `uv python pin --no-workspace` (#6514)

This matches the other interfaces and seems like an oversight.
This commit is contained in:
Zanie Blue 2024-08-23 11:08:27 -05:00 committed by GitHub
parent 57f833c302
commit 4cdca06db2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 38 additions and 17 deletions

View File

@ -3061,13 +3061,13 @@ pub struct PythonPinArgs {
#[arg(long, overrides_with("no_resolved"), hide = true)] #[arg(long, overrides_with("no_resolved"), hide = true)]
pub no_resolved: bool, pub no_resolved: bool,
/// Avoid validating the Python pin is compatible with the workspace. /// Avoid validating the Python pin is compatible with the project or workspace.
/// ///
/// By default, a workspace is discovered in the current directory or any parent /// By default, a project or workspace is discovered in the current directory or any parent
/// directory. If a workspace is found, the Python pin is validated against /// directory. If a workspace is found, the Python pin is validated against the workspace's
/// the workspace's `requires-python` constraint. /// `requires-python` constraint.
#[arg(long)] #[arg(long, alias = "no-workspace")]
pub no_workspace: bool, pub no_project: bool,
} }
#[derive(Args)] #[derive(Args)]

View File

@ -22,11 +22,11 @@ pub(crate) async fn pin(
request: Option<String>, request: Option<String>,
resolved: bool, resolved: bool,
python_preference: PythonPreference, python_preference: PythonPreference,
no_workspace: bool, no_project: bool,
cache: &Cache, cache: &Cache,
printer: Printer, printer: Printer,
) -> Result<ExitStatus> { ) -> Result<ExitStatus> {
let virtual_project = if no_workspace { let virtual_project = if no_project {
None None
} else { } else {
match VirtualProject::discover(&CWD, &DiscoveryOptions::default()).await { match VirtualProject::discover(&CWD, &DiscoveryOptions::default()).await {

View File

@ -961,7 +961,7 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
args.request, args.request,
args.resolved, args.resolved,
globals.python_preference, globals.python_preference,
args.no_workspace, args.no_project,
&cache, &cache,
printer, printer,
) )

View File

@ -588,7 +588,7 @@ impl PythonFindSettings {
pub(crate) struct PythonPinSettings { pub(crate) struct PythonPinSettings {
pub(crate) request: Option<String>, pub(crate) request: Option<String>,
pub(crate) resolved: bool, pub(crate) resolved: bool,
pub(crate) no_workspace: bool, pub(crate) no_project: bool,
} }
impl PythonPinSettings { impl PythonPinSettings {
@ -599,13 +599,13 @@ impl PythonPinSettings {
request, request,
no_resolved, no_resolved,
resolved, resolved,
no_workspace, no_project,
} = args; } = args;
Self { Self {
request, request,
resolved: flag(resolved, no_resolved).unwrap_or(false), resolved: flag(resolved, no_resolved).unwrap_or(false),
no_workspace, no_project,
} }
} }
} }

View File

@ -264,17 +264,38 @@ fn python_pin_compatible_with_requires_python() -> anyhow::Result<()> {
error: The requested Python version `cpython@3.10` is incompatible with the project `requires-python` value of `>=3.11`. error: The requested Python version `cpython@3.10` is incompatible with the project `requires-python` value of `>=3.11`.
"###); "###);
// Request an incompatible version with project discovery turned off
uv_snapshot!(context.filters(), context.python_pin().arg("cpython@3.10").arg("--no-project"), @r###"
success: true
exit_code: 0
----- stdout -----
Pinned `.python-version` to `cpython@3.10`
----- stderr -----
"###);
// And, as an alias, workspace discovery
uv_snapshot!(context.filters(), context.python_pin().arg("cpython@3.10").arg("--no-workspace"), @r###"
success: true
exit_code: 0
----- stdout -----
Pinned `.python-version` to `cpython@3.10`
----- stderr -----
"###);
// Request a complex version range that resolves to an incompatible version // Request a complex version range that resolves to an incompatible version
uv_snapshot!(context.filters(), context.python_pin().arg(">3.8,<3.11"), @r###" uv_snapshot!(context.filters(), context.python_pin().arg(">3.8,<3.11"), @r###"
success: true success: true
exit_code: 0 exit_code: 0
----- stdout ----- ----- stdout -----
Pinned `.python-version` to `>3.8, <3.11` Updated `.python-version` from `cpython@3.10` -> `>3.8, <3.11`
----- stderr ----- ----- stderr -----
warning: The requested Python version `>3.8, <3.11` resolves to `3.10.[X]` which is incompatible with the project `requires-python` value of `>=3.11`. warning: The requested Python version `>3.8, <3.11` resolves to `3.10.[X]` which is incompatible with the project `requires-python` value of `>=3.11`.
"###); "###);
// Request a version that is compatible
uv_snapshot!(context.filters(), context.python_pin().arg("3.11"), @r###" uv_snapshot!(context.filters(), context.python_pin().arg("3.11"), @r###"
success: true success: true
exit_code: 0 exit_code: 0

View File

@ -3293,12 +3293,12 @@ uv python pin [OPTIONS] [REQUEST]
<p>For example, spinners or progress bars.</p> <p>For example, spinners or progress bars.</p>
</dd><dt><code>--no-project</code></dt><dd><p>Avoid validating the Python pin is compatible with the project or workspace.</p>
<p>By default, a project or workspace is discovered in the current directory or any parent directory. If a workspace is found, the Python pin is validated against the workspace&#8217;s <code>requires-python</code> constraint.</p>
</dd><dt><code>--no-python-downloads</code></dt><dd><p>Disable automatic downloads of Python.</p> </dd><dt><code>--no-python-downloads</code></dt><dd><p>Disable automatic downloads of Python.</p>
</dd><dt><code>--no-workspace</code></dt><dd><p>Avoid validating the Python pin is compatible with the workspace.</p>
<p>By default, a workspace is discovered in the current directory or any parent directory. If a workspace is found, the Python pin is validated against the workspace&#8217;s <code>requires-python</code> constraint.</p>
</dd><dt><code>--offline</code></dt><dd><p>Disable network access.</p> </dd><dt><code>--offline</code></dt><dd><p>Disable network access.</p>
<p>When disabled, uv will only use locally cached data and locally available files.</p> <p>When disabled, uv will only use locally cached data and locally available files.</p>