Skip to content

Commit

Permalink
Add --no-project alias for uv python pin --no-workspace (#6514)
Browse files Browse the repository at this point in the history
This matches the other interfaces and seems like an oversight.
  • Loading branch information
zanieb authored Aug 23, 2024
1 parent 57f833c commit 4cdca06
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 16 deletions.
12 changes: 6 additions & 6 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3061,13 +3061,13 @@ pub struct PythonPinArgs {
#[arg(long, overrides_with("no_resolved"), hide = true)]
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
/// directory. If a workspace is found, the Python pin is validated against
/// the workspace's `requires-python` constraint.
#[arg(long)]
pub no_workspace: bool,
/// 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's
/// `requires-python` constraint.
#[arg(long, alias = "no-workspace")]
pub no_project: bool,
}

#[derive(Args)]
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/src/commands/python/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ pub(crate) async fn pin(
request: Option<String>,
resolved: bool,
python_preference: PythonPreference,
no_workspace: bool,
no_project: bool,
cache: &Cache,
printer: Printer,
) -> Result<ExitStatus> {
let virtual_project = if no_workspace {
let virtual_project = if no_project {
None
} else {
match VirtualProject::discover(&CWD, &DiscoveryOptions::default()).await {
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
args.request,
args.resolved,
globals.python_preference,
args.no_workspace,
args.no_project,
&cache,
printer,
)
Expand Down
6 changes: 3 additions & 3 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ impl PythonFindSettings {
pub(crate) struct PythonPinSettings {
pub(crate) request: Option<String>,
pub(crate) resolved: bool,
pub(crate) no_workspace: bool,
pub(crate) no_project: bool,
}

impl PythonPinSettings {
Expand All @@ -599,13 +599,13 @@ impl PythonPinSettings {
request,
no_resolved,
resolved,
no_workspace,
no_project,
} = args;

Self {
request,
resolved: flag(resolved, no_resolved).unwrap_or(false),
no_workspace,
no_project,
}
}
}
Expand Down
23 changes: 22 additions & 1 deletion crates/uv/tests/python_pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
"###);

// 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