Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Sep 27, 2024
1 parent 65a88bf commit 518f3b3
Show file tree
Hide file tree
Showing 22 changed files with 294 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{IndexUrl, IndexUrlError};

#[derive(Debug, Clone, Hash, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct IndexSource {
pub struct Index {
/// The name of the index.
///
/// Index names can be used to reference indexes elsewhere in the configuration. For example,
Expand Down Expand Up @@ -72,8 +72,8 @@ pub struct IndexSource {
// Flat,
// }

impl IndexSource {
/// Initialize an [`IndexSource`] from a pip-style `--index-url`.
impl Index {
/// Initialize an [`Index`] from a pip-style `--index-url`.
pub fn from_index_url(url: IndexUrl) -> Self {
Self {
url,
Expand All @@ -83,7 +83,7 @@ impl IndexSource {
}
}

/// Initialize an [`IndexSource`] from a pip-style `--extra-index-url`.
/// Initialize an [`Index`] from a pip-style `--extra-index-url`.
pub fn from_extra_index_url(url: IndexUrl) -> Self {
Self {
url,
Expand All @@ -94,7 +94,7 @@ impl IndexSource {
}
}

impl FromStr for IndexSource {
impl FromStr for Index {
type Err = IndexSourceError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Expand Down Expand Up @@ -126,7 +126,7 @@ impl FromStr for IndexSource {
}
}

/// An error that can occur when parsing an [`IndexSource`].
/// An error that can occur when parsing an [`Index`].
#[derive(Error, Debug)]
pub enum IndexSourceError {
#[error(transparent)]
Expand Down
15 changes: 6 additions & 9 deletions crates/distribution-types/src/index_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use url::{ParseError, Url};

use pep508_rs::{VerbatimUrl, VerbatimUrlError};

use crate::{IndexSource, Verbatim};
use crate::{Index, Verbatim};

static PYPI_URL: LazyLock<Url> = LazyLock::new(|| Url::parse("https://pypi.org/simple").unwrap());

Expand Down Expand Up @@ -55,6 +55,7 @@ impl IndexUrl {
}
}

/// Convert the index URL into a [`Url`].
pub fn into_url(self) -> Url {
match self {
Self::Pypi(url) => url.into_url(),
Expand Down Expand Up @@ -300,18 +301,14 @@ impl From<VerbatimUrl> for FlatIndexLocation {
#[derive(Default, Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
pub struct IndexLocations {
indexes: Vec<IndexSource>,
indexes: Vec<Index>,
flat_index: Vec<FlatIndexLocation>,
no_index: bool,
}

impl IndexLocations {
/// Determine the index URLs to use for fetching packages.
pub fn new(
indexes: Vec<IndexSource>,
flat_index: Vec<FlatIndexLocation>,
no_index: bool,
) -> Self {
pub fn new(indexes: Vec<Index>, flat_index: Vec<FlatIndexLocation>, no_index: bool) -> Self {
Self {
indexes,
flat_index,
Expand All @@ -328,7 +325,7 @@ impl IndexLocations {
#[must_use]
pub fn combine(
self,
indexes: Vec<IndexSource>,
indexes: Vec<Index>,
flat_index: Vec<FlatIndexLocation>,
no_index: bool,
) -> Self {
Expand Down Expand Up @@ -425,7 +422,7 @@ impl<'a> IndexLocations {
/// From a pip perspective, this type merges `--index-url` and `--extra-index-url`.
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct IndexUrls {
indexes: Vec<IndexSource>,
indexes: Vec<Index>,
no_index: bool,
}

Expand Down
4 changes: 2 additions & 2 deletions crates/distribution-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub use crate::error::*;
pub use crate::file::*;
pub use crate::hash::*;
pub use crate::id::*;
pub use crate::index_source::*;
pub use crate::index::*;
pub use crate::index_url::*;
pub use crate::installed::*;
pub use crate::prioritized_distribution::*;
Expand All @@ -76,7 +76,7 @@ mod error;
mod file;
mod hash;
mod id;
mod index_source;
mod index;
mod index_url;
mod installed;
mod prioritized_distribution;
Expand Down
40 changes: 20 additions & 20 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use anyhow::{anyhow, Result};
use clap::builder::styling::{AnsiColor, Effects, Style};
use clap::builder::Styles;
use clap::{Args, Parser, Subcommand};
use distribution_types::{FlatIndexLocation, IndexSource, IndexUrl};
use distribution_types::{FlatIndexLocation, Index, IndexUrl};
use pep508_rs::Requirement;
use pypi_types::VerbatimParsedUrl;
use url::Url;
Expand Down Expand Up @@ -779,13 +779,13 @@ fn parse_index_url(input: &str) -> Result<Maybe<IndexUrl>, String> {
}
}

/// Parse a string into an [`IndexSource`], mapping the empty string to `None`.
fn parse_index_source(input: &str) -> Result<Maybe<IndexSource>, String> {
/// Parse a string into an [`Index`], mapping the empty string to `None`.
fn parse_index_source(input: &str) -> Result<Maybe<Index>, String> {
if input.is_empty() {
Ok(Maybe::None)
} else {
match IndexSource::from_str(input) {
Ok(index) => Ok(Maybe::Some(IndexSource {
match Index::from_str(input) {
Ok(index) => Ok(Maybe::Some(Index {
default: false,
..index
})),
Expand All @@ -794,13 +794,13 @@ fn parse_index_source(input: &str) -> Result<Maybe<IndexSource>, String> {
}
}

/// Parse a string into an [`IndexSource`], mapping the empty string to `None`.
fn parse_default_index_source(input: &str) -> Result<Maybe<IndexSource>, String> {
/// Parse a string into an [`Index`], mapping the empty string to `None`.
fn parse_default_index_source(input: &str) -> Result<Maybe<Index>, String> {
if input.is_empty() {
Ok(Maybe::None)
} else {
match IndexSource::from_str(input) {
Ok(index) => Ok(Maybe::Some(IndexSource {
match Index::from_str(input) {
Ok(index) => Ok(Maybe::Some(Index {
default: true,
..index
})),
Expand Down Expand Up @@ -2250,8 +2250,8 @@ pub struct VenvArgs {
///
/// 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 attack can upload a malicious package under the
/// same name to a secondary.
/// "dependency confusion" attacks, whereby an attacker can upload a malicious package under the
/// same name to an alternate index.
#[arg(long, value_enum, env = "UV_INDEX_STRATEGY")]
pub index_strategy: Option<IndexStrategy>,

Expand Down Expand Up @@ -3702,7 +3702,7 @@ pub struct GenerateShellCompletionArgs {
#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
pub struct IndexArgs {
/// The URLs of packages indexes to use when resolving dependencies.
/// The URLs to use when resolving dependencies, in addition to the default index.
///
/// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
/// directory laid out in the same format.
Expand All @@ -3711,7 +3711,7 @@ pub struct IndexArgs {
/// `--default-index` (which defaults to PyPI). When multiple `--index` flags are
/// provided, earlier values take priority.
#[arg(long, env = "UV_INDEX", value_delimiter = ' ', value_parser = parse_index_source, help_heading = "Index options")]
pub index: Option<Vec<Maybe<IndexSource>>>,
pub index: Option<Vec<Maybe<Index>>>,

/// The URL of the default package index (by default: <https://pypi.org/simple>).
///
Expand All @@ -3721,7 +3721,7 @@ pub struct IndexArgs {
/// The index given by this flag is given lower priority than all other indexes specified via
/// the `--index` flag.
#[arg(long, env = "UV_DEFAULT_INDEX", value_parser = parse_default_index_source, help_heading = "Index options")]
pub default_index: Option<Maybe<IndexSource>>,
pub default_index: Option<Maybe<Index>>,

/// The URL of the Python package index (by default: <https://pypi.org/simple>).
///
Expand Down Expand Up @@ -3868,8 +3868,8 @@ pub struct InstallerArgs {
///
/// 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 attack can upload a malicious package under the
/// same name to a secondary.
/// "dependency confusion" attacks, whereby an attacker can upload a malicious package under the
/// same name to an alternate index.
#[arg(
long,
value_enum,
Expand Down Expand Up @@ -4030,8 +4030,8 @@ pub struct ResolverArgs {
///
/// 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 attack can upload a malicious package under the
/// same name to a secondary.
/// "dependency confusion" attacks, whereby an attacker can upload a malicious package under the
/// same name to an alternate index.
#[arg(
long,
value_enum,
Expand Down Expand Up @@ -4222,8 +4222,8 @@ pub struct ResolverInstallerArgs {
///
/// 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 attack can upload a malicious package under the
/// same name to a secondary.
/// "dependency confusion" attacks, whereby an attacker can upload a malicious package under the
/// same name to an alternate index.
#[arg(
long,
value_enum,
Expand Down
20 changes: 8 additions & 12 deletions crates/uv-distribution/src/metadata/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use thiserror::Error;
use url::Url;

use distribution_filename::DistExtension;
use distribution_types::IndexSource;
use distribution_types::Index;
use pep440_rs::VersionSpecifiers;
use pep508_rs::{VerbatimUrl, VersionOrUrl};
use pypi_types::{ParsedUrlError, Requirement, RequirementSource, VerbatimParsedUrl};
Expand Down Expand Up @@ -34,7 +34,7 @@ impl LoweredRequirement {
project_name: &PackageName,
project_dir: &Path,
project_sources: &BTreeMap<PackageName, Source>,
project_indexes: &[IndexSource],
project_indexes: &[Index],
workspace: &Workspace,
) -> Result<Self, LoweringError> {
let (source, origin) = if let Some(source) = project_sources.get(&requirement.name) {
Expand Down Expand Up @@ -115,15 +115,13 @@ impl LoweredRequirement {
// in that order.
let Some(index) = project_indexes
.iter()
.find(|IndexSource { name, .. }| {
name.as_ref().is_some_and(|name| *name == index)
})
.find(|Index { name, .. }| name.as_ref().is_some_and(|name| *name == index))
.or_else(|| {
workspace.indexes().iter().find(|IndexSource { name, .. }| {
workspace.indexes().iter().find(|Index { name, .. }| {
name.as_ref().is_some_and(|name| *name == index)
})
})
.map(|IndexSource { url: index, .. }| index.clone())
.map(|Index { url: index, .. }| index.clone())
else {
return Err(LoweringError::MissingIndex(requirement.name, index));
};
Expand Down Expand Up @@ -205,7 +203,7 @@ impl LoweredRequirement {
requirement: pep508_rs::Requirement<VerbatimParsedUrl>,
dir: &Path,
sources: &BTreeMap<PackageName, Source>,
indexes: &[IndexSource],
indexes: &[Index],
) -> Result<Self, LoweringError> {
let source = sources.get(&requirement.name).cloned();

Expand Down Expand Up @@ -247,10 +245,8 @@ impl LoweredRequirement {
Source::Registry { index } => {
let Some(index) = indexes
.iter()
.find(|IndexSource { name, .. }| {
name.as_ref().is_some_and(|name| *name == index)
})
.map(|IndexSource { url: index, .. }| index.clone())
.find(|Index { name, .. }| name.as_ref().is_some_and(|name| *name == index))
.map(|Index { url: index, .. }| index.clone())
else {
return Err(LoweringError::MissingIndex(requirement.name, index));
};
Expand Down
4 changes: 2 additions & 2 deletions crates/uv-scripts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::sync::LazyLock;

use distribution_types::IndexSource;
use distribution_types::Index;
use memchr::memmem::Finder;
use pep440_rs::VersionSpecifiers;
use pep508_rs::PackageName;
Expand Down Expand Up @@ -194,7 +194,7 @@ pub struct ToolUv {
#[serde(flatten)]
pub top_level: ResolverInstallerOptions,
pub sources: Option<BTreeMap<PackageName, Source>>,
pub indexes: Option<Vec<IndexSource>>,
pub indexes: Option<Vec<Index>>,
}

#[derive(Debug, Error)]
Expand Down
22 changes: 11 additions & 11 deletions crates/uv-settings/src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{fmt::Debug, num::NonZeroUsize, path::PathBuf};

use distribution_types::{FlatIndexLocation, IndexSource, IndexUrl, StaticMetadata};
use distribution_types::{FlatIndexLocation, Index, IndexUrl, StaticMetadata};
use install_wheel_rs::linker::LinkMode;
use pep508_rs::Requirement;
use pypi_types::{SupportedEnvironments, VerbatimParsedUrl};
Expand Down Expand Up @@ -234,7 +234,7 @@ pub struct GlobalOptions {
#[serde(rename_all = "kebab-case")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct InstallerOptions {
pub index: Option<Vec<IndexSource>>,
pub index: Option<Vec<Index>>,
pub index_url: Option<IndexUrl>,
pub extra_index_url: Option<Vec<IndexUrl>>,
pub no_index: Option<bool>,
Expand Down Expand Up @@ -262,7 +262,7 @@ pub struct InstallerOptions {
#[serde(rename_all = "kebab-case")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct ResolverOptions {
pub index: Option<Vec<IndexSource>>,
pub index: Option<Vec<Index>>,
pub index_url: Option<IndexUrl>,
pub extra_index_url: Option<Vec<IndexUrl>>,
pub no_index: Option<bool>,
Expand Down Expand Up @@ -329,7 +329,7 @@ pub struct ResolverInstallerOptions {
url = "https://download.pytorch.org/whl/cu121"
"#
)]
pub index: Option<Vec<IndexSource>>,
pub index: Option<Vec<Index>>,
/// The URL of the Python package index (by default: <https://pypi.org/simple>).
///
/// Accepts either a repository compliant with [PEP 503](https://peps.python.org/pep-0503/)
Expand Down Expand Up @@ -398,8 +398,8 @@ pub struct ResolverInstallerOptions {
///
/// 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 attack can upload a malicious package under the
/// same name to a secondary.
/// "dependency confusion" attacks, whereby an attacker can upload a malicious package under the
/// same name to an alternate index.
#[option(
default = "\"first-index\"",
value_type = "str",
Expand Down Expand Up @@ -773,7 +773,7 @@ pub struct PipOptions {
/// Additionally, marking an index as default will disable the PyPI default index.
#[serde(skip)]
#[cfg_attr(feature = "schemars", schemars(skip))]
pub index: Option<Vec<IndexSource>>,
pub index: Option<Vec<Index>>,
/// The URL of the Python package index (by default: <https://pypi.org/simple>).
///
/// Accepts either a repository compliant with [PEP 503](https://peps.python.org/pep-0503/)
Expand Down Expand Up @@ -837,8 +837,8 @@ pub struct PipOptions {
///
/// 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 attack can upload a malicious package under the
/// same name to a secondary.
/// "dependency confusion" attacks, whereby an attacker can upload a malicious package under the
/// same name to an alternate index.
#[option(
default = "\"first-index\"",
value_type = "str",
Expand Down Expand Up @@ -1444,7 +1444,7 @@ impl From<ResolverInstallerOptions> for InstallerOptions {
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct ToolOptions {
pub index: Option<Vec<IndexSource>>,
pub index: Option<Vec<Index>>,
pub index_url: Option<IndexUrl>,
pub extra_index_url: Option<Vec<IndexUrl>>,
pub no_index: Option<bool>,
Expand Down Expand Up @@ -1550,7 +1550,7 @@ pub struct OptionsWire {

// #[serde(flatten)]
// top_level: ResolverInstallerOptions,
index: Option<Vec<IndexSource>>,
index: Option<Vec<Index>>,
index_url: Option<IndexUrl>,
extra_index_url: Option<Vec<IndexUrl>>,
no_index: Option<bool>,
Expand Down
Loading

0 comments on commit 518f3b3

Please sign in to comment.