Skip to content

Commit

Permalink
Respect empty
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Oct 4, 2024
1 parent 4d9610d commit 9f59c8e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
15 changes: 14 additions & 1 deletion crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,18 @@ fn parse_index_url(input: &str) -> Result<Maybe<IndexUrl>, String> {
}
}

/// Parse a string into an [`FlatIndexLocation`], mapping the empty string to `None`.
fn parse_flat_index(input: &str) -> Result<Maybe<FlatIndexLocation>, String> {
if input.is_empty() {
Ok(Maybe::None)
} else {
match FlatIndexLocation::from_str(input) {
Ok(url) => Ok(Maybe::Some(url)),
Err(err) => Err(err.to_string()),
}
}
}

/// Parse a string into an [`Url`], mapping the empty string to `None`.
fn parse_insecure_host(input: &str) -> Result<Maybe<TrustedHost>, String> {
if input.is_empty() {
Expand Down Expand Up @@ -3735,9 +3747,10 @@ pub struct IndexArgs {
short,
env = "UV_FIND_LINKS",
value_delimiter = ' ',
value_parser = parse_flat_index,
help_heading = "Index options"
)]
pub find_links: Option<Vec<FlatIndexLocation>>,
pub find_links: Option<Vec<Maybe<FlatIndexLocation>>>,

/// Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those
/// provided via `--find-links`.
Expand Down
33 changes: 24 additions & 9 deletions crates/uv-cli/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,19 @@ impl From<IndexArgs> for PipOptions {

Self {
index_url: index_url.and_then(Maybe::into_option),
extra_index_url: extra_index_url.map(|extra_index_urls| {
extra_index_urls
extra_index_url: extra_index_url.map(|extra_index_url| {
extra_index_url
.into_iter()
.filter_map(Maybe::into_option)
.collect()
}),
no_index: if no_index { Some(true) } else { None },
find_links,
find_links: find_links.map(|find_links| {
find_links
.into_iter()
.filter_map(Maybe::into_option)
.collect()
}),
..PipOptions::default()
}
}
Expand Down Expand Up @@ -243,8 +248,8 @@ pub fn resolver_options(

ResolverOptions {
index_url: index_args.index_url.and_then(Maybe::into_option),
extra_index_url: index_args.extra_index_url.map(|extra_index_urls| {
extra_index_urls
extra_index_url: index_args.extra_index_url.map(|extra_index_url| {
extra_index_url
.into_iter()
.filter_map(Maybe::into_option)
.collect()
Expand All @@ -254,7 +259,12 @@ pub fn resolver_options(
} else {
None
},
find_links: index_args.find_links,
find_links: index_args.find_links.map(|find_links| {
find_links
.into_iter()
.filter_map(Maybe::into_option)
.collect()
}),
upgrade: flag(upgrade, no_upgrade),
upgrade_package: Some(upgrade_package),
index_strategy,
Expand Down Expand Up @@ -327,8 +337,8 @@ pub fn resolver_installer_options(

ResolverInstallerOptions {
index_url: index_args.index_url.and_then(Maybe::into_option),
extra_index_url: index_args.extra_index_url.map(|extra_index_urls| {
extra_index_urls
extra_index_url: index_args.extra_index_url.map(|extra_index_url| {
extra_index_url
.into_iter()
.filter_map(Maybe::into_option)
.collect()
Expand All @@ -338,7 +348,12 @@ pub fn resolver_installer_options(
} else {
None
},
find_links: index_args.find_links,
find_links: index_args.find_links.map(|find_links| {
find_links
.into_iter()
.filter_map(Maybe::into_option)
.collect()
}),
upgrade: flag(upgrade, no_upgrade),
upgrade_package: if upgrade_package.is_empty() {
None
Expand Down

0 comments on commit 9f59c8e

Please sign in to comment.