Skip to content

Commit

Permalink
Add settings
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Aug 24, 2024
1 parent b2db1d7 commit 2e5b71e
Show file tree
Hide file tree
Showing 23 changed files with 474 additions and 103 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 1 addition & 19 deletions crates/uv-cli/src/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ pub struct PipCompileCompatArgs {
#[clap(long, hide = true)]
client_cert: Option<String>,

#[clap(long, hide = true)]
trusted_host: Option<String>,

#[clap(long, hide = true)]
emit_trusted_host: bool,

Expand Down Expand Up @@ -118,15 +115,9 @@ impl CompatArgs for PipCompileCompatArgs {
));
}

if self.trusted_host.is_some() {
return Err(anyhow!(
"pip-compile's `--trusted-host` is unsupported (uv always requires HTTPS)"
));
}

if self.emit_trusted_host {
return Err(anyhow!(
"pip-compile's `--emit-trusted-host` is unsupported (uv always requires HTTPS)"
"pip-compile's `--emit-trusted-host` is unsupported"
));
}

Expand Down Expand Up @@ -209,9 +200,6 @@ pub struct PipSyncCompatArgs {
#[clap(short, long, hide = true)]
ask: bool,

#[clap(long, hide = true)]
trusted_host: Option<String>,

#[clap(long, hide = true)]
python_executable: Option<String>,

Expand Down Expand Up @@ -265,12 +253,6 @@ impl CompatArgs for PipSyncCompatArgs {
));
}

if self.trusted_host.is_some() {
return Err(anyhow!(
"pip-sync's `--trusted-host` is unsupported (uv always requires HTTPS)"
));
}

if self.config.is_some() {
return Err(anyhow!(
"pip-sync's `--config` is unsupported (uv does not use a configuration file)"
Expand Down
77 changes: 76 additions & 1 deletion crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use std::str::FromStr;
use anyhow::{anyhow, Result};
use clap::builder::styling::Style;
use clap::{Args, Parser, Subcommand};

use distribution_types::{FlatIndexLocation, IndexUrl};
use pep508_rs::Requirement;
use pypi_types::VerbatimParsedUrl;
use url::Url;
use uv_cache::CacheArgs;
use uv_configuration::{
ConfigSettingEntry, IndexStrategy, KeyringProviderType, PackageNameSpecifier, TargetTriple,
Expand Down Expand Up @@ -678,6 +678,18 @@ fn parse_index_url(input: &str) -> Result<Maybe<IndexUrl>, String> {
}
}

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

/// Parse a string into a [`PathBuf`]. The string can represent a file, either as a path or a
/// `file://` URL.
fn parse_file_path(input: &str) -> Result<PathBuf, String> {
Expand Down Expand Up @@ -1559,6 +1571,18 @@ pub struct PipUninstallArgs {
#[arg(long, value_enum, env = "UV_KEYRING_PROVIDER")]
pub keyring_provider: Option<KeyringProviderType>,

/// A list of trusted hostnames for SSL connections.
///
/// WARNING: Hosts included in this list will not be verified against the system's certificate
/// store.
#[arg(
long,
env = "UV_TRUSTED_HOST",
value_delimiter = ' ',
value_parser = parse_maybe_url,
)]
pub trusted_host: Option<Vec<Maybe<Url>>>,

/// Use the system Python to uninstall packages.
///
/// By default, uv uninstalls from the virtual environment in the current working directory or
Expand Down Expand Up @@ -1985,6 +2009,18 @@ pub struct VenvArgs {
#[arg(long, value_enum, env = "UV_KEYRING_PROVIDER")]
pub keyring_provider: Option<KeyringProviderType>,

/// A list of trusted hostnames for SSL connections.
///
/// WARNING: Hosts included in this list will not be verified against the system's certificate
/// store.
#[arg(
long,
env = "UV_TRUSTED_HOST",
value_delimiter = ' ',
value_parser = parse_maybe_url,
)]
pub trusted_host: Option<Vec<Maybe<Url>>>,

/// Limit candidate packages to those that were uploaded prior to the given date.
///
/// Accepts both RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`) and local dates in the same
Expand Down Expand Up @@ -3324,6 +3360,19 @@ pub struct InstallerArgs {
)]
pub keyring_provider: Option<KeyringProviderType>,

/// A list of trusted hostnames for SSL connections.
///
/// WARNING: Hosts included in this list will not be verified against the system's certificate
/// store.
#[arg(
long,
env = "UV_TRUSTED_HOST",
value_delimiter = ' ',
value_parser = parse_maybe_url,
help_heading = "Index options"
)]
pub trusted_host: Option<Vec<Maybe<Url>>>,

/// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
#[arg(
long,
Expand Down Expand Up @@ -3466,6 +3515,19 @@ pub struct ResolverArgs {
)]
pub keyring_provider: Option<KeyringProviderType>,

/// A list of trusted hostnames for SSL connections.
///
/// WARNING: Hosts included in this list will not be verified against the system's certificate
/// store.
#[arg(
long,
env = "UV_TRUSTED_HOST",
value_delimiter = ' ',
value_parser = parse_maybe_url,
help_heading = "Index options"
)]
pub trusted_host: Option<Vec<Maybe<Url>>>,

/// The strategy to use when selecting between the different compatible versions for a given
/// package requirement.
///
Expand Down Expand Up @@ -3638,6 +3700,19 @@ pub struct ResolverInstallerArgs {
)]
pub keyring_provider: Option<KeyringProviderType>,

/// A list of trusted hostnames for SSL connections.
///
/// WARNING: Hosts included in this list will not be verified against the system's certificate
/// store.
#[arg(
long,
env = "UV_TRUSTED_HOST",
value_delimiter = ' ',
value_parser = parse_maybe_url,
help_heading = "Index options"
)]
pub trusted_host: Option<Vec<Maybe<Url>>>,

/// The strategy to use when selecting between the different compatible versions for a given
/// package requirement.
///
Expand Down
35 changes: 35 additions & 0 deletions crates/uv-cli/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl From<ResolverArgs> for PipOptions {
upgrade_package,
index_strategy,
keyring_provider,
trusted_host,
resolution,
prerelease,
pre,
Expand All @@ -55,6 +56,12 @@ impl From<ResolverArgs> for PipOptions {
upgrade_package: Some(upgrade_package),
index_strategy,
keyring_provider,
trusted_host: trusted_host.map(|trusted_host| {
trusted_host
.into_iter()
.filter_map(Maybe::into_option)
.collect()
}),
resolution,
prerelease: if pre {
Some(PrereleaseMode::Allow)
Expand Down Expand Up @@ -82,6 +89,7 @@ impl From<InstallerArgs> for PipOptions {
reinstall_package,
index_strategy,
keyring_provider,
trusted_host,
config_setting,
no_build_isolation,
build_isolation,
Expand All @@ -97,6 +105,12 @@ impl From<InstallerArgs> for PipOptions {
reinstall_package: Some(reinstall_package),
index_strategy,
keyring_provider,
trusted_host: trusted_host.map(|trusted_host| {
trusted_host
.into_iter()
.filter_map(Maybe::into_option)
.collect()
}),
config_settings: config_setting
.map(|config_settings| config_settings.into_iter().collect::<ConfigSettings>()),
no_build_isolation: flag(no_build_isolation, build_isolation),
Expand All @@ -121,6 +135,7 @@ impl From<ResolverInstallerArgs> for PipOptions {
reinstall_package,
index_strategy,
keyring_provider,
trusted_host,
resolution,
prerelease,
pre,
Expand All @@ -142,6 +157,12 @@ impl From<ResolverInstallerArgs> for PipOptions {
reinstall_package: Some(reinstall_package),
index_strategy,
keyring_provider,
trusted_host: trusted_host.map(|trusted_host| {
trusted_host
.into_iter()
.filter_map(Maybe::into_option)
.collect()
}),
resolution,
prerelease: if pre {
Some(PrereleaseMode::Allow)
Expand Down Expand Up @@ -194,6 +215,7 @@ pub fn resolver_options(resolver_args: ResolverArgs, build_args: BuildArgs) -> R
upgrade_package,
index_strategy,
keyring_provider,
trusted_host,
resolution,
prerelease,
pre,
Expand Down Expand Up @@ -233,6 +255,12 @@ pub fn resolver_options(resolver_args: ResolverArgs, build_args: BuildArgs) -> R
upgrade_package: Some(upgrade_package),
index_strategy,
keyring_provider,
trusted_host: trusted_host.map(|trusted_host| {
trusted_host
.into_iter()
.filter_map(Maybe::into_option)
.collect()
}),
resolution,
prerelease: if pre {
Some(PrereleaseMode::Allow)
Expand Down Expand Up @@ -268,6 +296,7 @@ pub fn resolver_installer_options(
reinstall_package,
index_strategy,
keyring_provider,
trusted_host,
resolution,
prerelease,
pre,
Expand Down Expand Up @@ -319,6 +348,12 @@ pub fn resolver_installer_options(
},
index_strategy,
keyring_provider,
trusted_host: trusted_host.map(|trusted_host| {
trusted_host
.into_iter()
.filter_map(Maybe::into_option)
.collect()
}),
resolution,
prerelease: if pre {
Some(PrereleaseMode::Allow)
Expand Down
Loading

0 comments on commit 2e5b71e

Please sign in to comment.