Respect --index-url in uv pip list (#8942)
## Summary As an oversight, these arguments weren't being respected from the CLI or elsewhere -- we always hit PyPI, ignored `--exclude-newer`, etc. It has to do with the way that the `PipOptions` are setup -- there's a global struct that we pass around everywhere and fill in with defaults, so there's no type safety to guarantee that we provide whatever it is we need to use in the command. The newer APIs are much better about this. Closes #8927.
This commit is contained in:
@@ -1926,6 +1926,9 @@ pub struct PipListArgs {
|
||||
#[arg(long, overrides_with("strict"), hide = true)]
|
||||
pub no_strict: bool,
|
||||
|
||||
#[command(flatten)]
|
||||
pub fetch: FetchArgs,
|
||||
|
||||
/// The Python interpreter for which packages should be listed.
|
||||
///
|
||||
/// By default, uv lists packages in a virtual environment but will show
|
||||
@@ -4698,6 +4701,49 @@ pub struct ResolverInstallerArgs {
|
||||
pub no_sources: bool,
|
||||
}
|
||||
|
||||
/// Arguments that are used by commands that need to fetch from the Simple API.
|
||||
#[derive(Args)]
|
||||
#[allow(clippy::struct_excessive_bools)]
|
||||
pub struct FetchArgs {
|
||||
#[command(flatten)]
|
||||
pub index_args: IndexArgs,
|
||||
|
||||
/// The strategy to use when resolving against multiple index URLs.
|
||||
///
|
||||
/// By default, uv will stop at the first index on which a given package is available, and
|
||||
/// limit resolutions to those present on that first index (`first-match`). This prevents
|
||||
/// "dependency confusion" attacks, whereby an attacker can upload a malicious package under the
|
||||
/// same name to an alternate index.
|
||||
#[arg(
|
||||
long,
|
||||
value_enum,
|
||||
env = EnvVars::UV_INDEX_STRATEGY,
|
||||
help_heading = "Index options"
|
||||
)]
|
||||
pub index_strategy: Option<IndexStrategy>,
|
||||
|
||||
/// Attempt to use `keyring` for authentication for index URLs.
|
||||
///
|
||||
/// At present, only `--keyring-provider subprocess` is supported, which configures uv to
|
||||
/// use the `keyring` CLI to handle authentication.
|
||||
///
|
||||
/// Defaults to `disabled`.
|
||||
#[arg(
|
||||
long,
|
||||
value_enum,
|
||||
env = EnvVars::UV_KEYRING_PROVIDER,
|
||||
help_heading = "Index options"
|
||||
)]
|
||||
pub keyring_provider: Option<KeyringProviderType>,
|
||||
|
||||
/// 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
|
||||
/// format (e.g., `2006-12-02`) in your system's configured time zone.
|
||||
#[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
|
||||
pub exclude_newer: Option<ExcludeNewer>,
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
pub struct DisplayTreeArgs {
|
||||
/// Maximum display depth of the dependency tree
|
||||
|
||||
@@ -5,7 +5,7 @@ use uv_resolver::PrereleaseMode;
|
||||
use uv_settings::{Combine, PipOptions, ResolverInstallerOptions, ResolverOptions};
|
||||
|
||||
use crate::{
|
||||
BuildOptionsArgs, IndexArgs, InstallerArgs, Maybe, RefreshArgs, ResolverArgs,
|
||||
BuildOptionsArgs, FetchArgs, IndexArgs, InstallerArgs, Maybe, RefreshArgs, ResolverArgs,
|
||||
ResolverInstallerArgs,
|
||||
};
|
||||
|
||||
@@ -163,6 +163,24 @@ impl From<ResolverInstallerArgs> for PipOptions {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FetchArgs> for PipOptions {
|
||||
fn from(args: FetchArgs) -> Self {
|
||||
let FetchArgs {
|
||||
index_args,
|
||||
index_strategy,
|
||||
keyring_provider,
|
||||
exclude_newer,
|
||||
} = args;
|
||||
|
||||
Self {
|
||||
index_strategy,
|
||||
keyring_provider,
|
||||
exclude_newer,
|
||||
..PipOptions::from(index_args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IndexArgs> for PipOptions {
|
||||
fn from(args: IndexArgs) -> Self {
|
||||
let IndexArgs {
|
||||
|
||||
Reference in New Issue
Block a user