Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coerce empty string values to None for UV_PYTHON env var #7878

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 75 additions & 44 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,16 @@ fn parse_maybe_file_path(input: &str) -> Result<Maybe<PathBuf>, String> {
}
}

// Parse a string, mapping the empty string to `None`.
#[allow(clippy::unnecessary_wraps)]
fn parse_maybe_string(input: &str) -> Result<Maybe<String>, String> {
if input.is_empty() {
Ok(Maybe::None)
} else {
Ok(Maybe::Some(input.to_string()))
}
}

#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
pub struct PipCompileArgs {
Expand Down Expand Up @@ -955,8 +965,8 @@ pub struct PipCompileArgs {
///
/// See `uv help python` for details on Python discovery and supported
/// request formats.
#[arg(long, verbatim_doc_comment, help_heading = "Python options")]
pub python: Option<String>,
#[arg(long, verbatim_doc_comment, help_heading = "Python options", value_parser = parse_maybe_string)]
pub python: Option<Maybe<String>>,

/// Install packages into the system Python environment.
///
Expand Down Expand Up @@ -1209,9 +1219,10 @@ pub struct PipSyncArgs {
short,
env = "UV_PYTHON",
verbatim_doc_comment,
help_heading = "Python options"
help_heading = "Python options",
value_parser = parse_maybe_string,
)]
pub python: Option<String>,
pub python: Option<Maybe<String>>,

/// Install packages into the system Python environment.
///
Expand Down Expand Up @@ -1491,9 +1502,10 @@ pub struct PipInstallArgs {
short,
env = "UV_PYTHON",
verbatim_doc_comment,
help_heading = "Python options"
help_heading = "Python options",
value_parser = parse_maybe_string,
)]
pub python: Option<String>,
pub python: Option<Maybe<String>>,

/// Install packages into the system Python environment.
///
Expand Down Expand Up @@ -1656,9 +1668,10 @@ pub struct PipUninstallArgs {
short,
env = "UV_PYTHON",
verbatim_doc_comment,
help_heading = "Python options"
help_heading = "Python options",
value_parser = parse_maybe_string,
)]
pub python: Option<String>,
pub python: Option<Maybe<String>>,

/// Attempt to use `keyring` for authentication for remote requirements files.
///
Expand Down Expand Up @@ -1764,9 +1777,10 @@ pub struct PipFreezeArgs {
short,
env = "UV_PYTHON",
verbatim_doc_comment,
help_heading = "Python options"
help_heading = "Python options",
value_parser = parse_maybe_string,
)]
pub python: Option<String>,
pub python: Option<Maybe<String>>,

/// List packages in the system Python environment.
///
Expand Down Expand Up @@ -1828,9 +1842,10 @@ pub struct PipListArgs {
short,
env = "UV_PYTHON",
verbatim_doc_comment,
help_heading = "Python options"
help_heading = "Python options",
value_parser = parse_maybe_string,
)]
pub python: Option<String>,
pub python: Option<Maybe<String>>,

/// List packages in the system Python environment.
///
Expand Down Expand Up @@ -1868,9 +1883,10 @@ pub struct PipCheckArgs {
short,
env = "UV_PYTHON",
verbatim_doc_comment,
help_heading = "Python options"
help_heading = "Python options",
value_parser = parse_maybe_string,
)]
pub python: Option<String>,
pub python: Option<Maybe<String>>,

/// Check packages in the system Python environment.
///
Expand Down Expand Up @@ -1916,9 +1932,10 @@ pub struct PipShowArgs {
short,
env = "UV_PYTHON",
verbatim_doc_comment,
help_heading = "Python options"
help_heading = "Python options",
value_parser = parse_maybe_string,
)]
pub python: Option<String>,
pub python: Option<Maybe<String>>,

/// Show a package in the system Python environment.
///
Expand Down Expand Up @@ -1971,9 +1988,10 @@ pub struct PipTreeArgs {
short,
env = "UV_PYTHON",
verbatim_doc_comment,
help_heading = "Python options"
help_heading = "Python options",
value_parser = parse_maybe_string,
)]
pub python: Option<String>,
pub python: Option<Maybe<String>>,

/// List packages in the system Python environment.
///
Expand Down Expand Up @@ -2106,9 +2124,10 @@ pub struct BuildArgs {
short,
env = "UV_PYTHON",
verbatim_doc_comment,
help_heading = "Python options"
help_heading = "Python options",
value_parser = parse_maybe_string,
)]
pub python: Option<String>,
pub python: Option<Maybe<String>>,

#[command(flatten)]
pub resolver: ResolverArgs,
Expand All @@ -2135,9 +2154,10 @@ pub struct VenvArgs {
short,
env = "UV_PYTHON",
verbatim_doc_comment,
help_heading = "Python options"
help_heading = "Python options",
value_parser = parse_maybe_string,
)]
pub python: Option<String>,
pub python: Option<Maybe<String>>,

/// Ignore virtual environments when searching for the Python interpreter.
///
Expand Down Expand Up @@ -2423,9 +2443,10 @@ pub struct InitArgs {
short,
env = "UV_PYTHON",
verbatim_doc_comment,
help_heading = "Python options"
help_heading = "Python options",
value_parser = parse_maybe_string,
)]
pub python: Option<String>,
pub python: Option<Maybe<String>>,
}

#[derive(Args)]
Expand Down Expand Up @@ -2591,9 +2612,10 @@ pub struct RunArgs {
short,
env = "UV_PYTHON",
verbatim_doc_comment,
help_heading = "Python options"
help_heading = "Python options",
value_parser = parse_maybe_string,
)]
pub python: Option<String>,
pub python: Option<Maybe<String>>,

/// Whether to show resolver and installer output from any environment modifications.
///
Expand Down Expand Up @@ -2733,9 +2755,10 @@ pub struct SyncArgs {
short,
env = "UV_PYTHON",
verbatim_doc_comment,
help_heading = "Python options"
help_heading = "Python options",
value_parser = parse_maybe_string,
)]
pub python: Option<String>,
pub python: Option<Maybe<String>>,
}

#[derive(Args)]
Expand Down Expand Up @@ -2776,9 +2799,10 @@ pub struct LockArgs {
short,
env = "UV_PYTHON",
verbatim_doc_comment,
help_heading = "Python options"
help_heading = "Python options",
value_parser = parse_maybe_string,
)]
pub python: Option<String>,
pub python: Option<Maybe<String>>,
}

#[derive(Args)]
Expand Down Expand Up @@ -2898,9 +2922,10 @@ pub struct AddArgs {
short,
env = "UV_PYTHON",
verbatim_doc_comment,
help_heading = "Python options"
help_heading = "Python options",
value_parser = parse_maybe_string,
)]
pub python: Option<String>,
pub python: Option<Maybe<String>>,
}

#[derive(Args)]
Expand Down Expand Up @@ -2964,9 +2989,10 @@ pub struct RemoveArgs {
short,
env = "UV_PYTHON",
verbatim_doc_comment,
help_heading = "Python options"
help_heading = "Python options",
value_parser = parse_maybe_string,
)]
pub python: Option<String>,
pub python: Option<Maybe<String>>,
}

#[derive(Args)]
Expand Down Expand Up @@ -3038,9 +3064,10 @@ pub struct TreeArgs {
short,
env = "UV_PYTHON",
verbatim_doc_comment,
help_heading = "Python options"
help_heading = "Python options",
value_parser = parse_maybe_string,
)]
pub python: Option<String>,
pub python: Option<Maybe<String>>,
}

#[derive(Args)]
Expand Down Expand Up @@ -3162,9 +3189,10 @@ pub struct ExportArgs {
short,
env = "UV_PYTHON",
verbatim_doc_comment,
help_heading = "Python options"
help_heading = "Python options",
value_parser = parse_maybe_string,
)]
pub python: Option<String>,
pub python: Option<Maybe<String>>,
}

#[derive(Args)]
Expand Down Expand Up @@ -3311,9 +3339,10 @@ pub struct ToolRunArgs {
short,
env = "UV_PYTHON",
verbatim_doc_comment,
help_heading = "Python options"
help_heading = "Python options",
value_parser = parse_maybe_string,
)]
pub python: Option<String>,
pub python: Option<Maybe<String>>,

/// Whether to show resolver and installer output from any environment modifications.
///
Expand Down Expand Up @@ -3372,9 +3401,10 @@ pub struct ToolInstallArgs {
short,
env = "UV_PYTHON",
verbatim_doc_comment,
help_heading = "Python options"
help_heading = "Python options",
value_parser = parse_maybe_string,
)]
pub python: Option<String>,
pub python: Option<Maybe<String>>,
}

#[derive(Args)]
Expand Down Expand Up @@ -3448,9 +3478,10 @@ pub struct ToolUpgradeArgs {
short,
env = "UV_PYTHON",
verbatim_doc_comment,
help_heading = "Python options"
help_heading = "Python options",
value_parser = parse_maybe_string,
)]
pub python: Option<String>,
pub python: Option<Maybe<String>>,

#[command(flatten)]
pub installer: ResolverInstallerArgs,
Expand Down
Loading
Loading