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 7dfb804
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 90 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
14 changes: 5 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 @@ -300,18 +300,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 +324,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 +421,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
24 changes: 12 additions & 12 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 @@ -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
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
14 changes: 7 additions & 7 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 @@ -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 @@ -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
4 changes: 2 additions & 2 deletions crates/uv-workspace/src/pyproject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//!
//! Then lowers them into a dependency specification.

use distribution_types::IndexSource;
use distribution_types::Index;
use glob::Pattern;
use pep440_rs::{Version, VersionSpecifiers};
use pypi_types::{RequirementSource, SupportedEnvironments, VerbatimParsedUrl};
Expand Down Expand Up @@ -189,7 +189,7 @@ pub struct ToolUv {
url = "https://download.pytorch.org/whl/cu121"
"#
)]
pub index: Option<Vec<IndexSource>>,
pub index: Option<Vec<Index>>,

/// The workspace definition for the project, if any.
#[option_group]
Expand Down
6 changes: 3 additions & 3 deletions crates/uv-workspace/src/workspace.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Resolve the current [`ProjectWorkspace`] or [`Workspace`].

use distribution_types::IndexSource;
use distribution_types::Index;
use either::Either;
use glob::{glob, GlobError, PatternError};
use pep508_rs::{MarkerTree, RequirementOrigin, VerbatimUrl};
Expand Down Expand Up @@ -82,7 +82,7 @@ pub struct Workspace {
/// The index table from the workspace `pyproject.toml`.
///
/// This table is overridden by the project indexes.
indexes: Vec<IndexSource>,
indexes: Vec<Index>,
/// The `pyproject.toml` of the workspace root.
pyproject_toml: PyProjectToml,
}
Expand Down Expand Up @@ -536,7 +536,7 @@ impl Workspace {
}

/// The index table from the workspace `pyproject.toml`.
pub fn indexes(&self) -> &[IndexSource] {
pub fn indexes(&self) -> &[Index] {
&self.indexes
}

Expand Down
8 changes: 4 additions & 4 deletions crates/uv/src/commands/pip/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use owo_colors::OwoColorize;
use tracing::debug;

use distribution_types::{
DependencyMetadata, IndexCapabilities, IndexLocations, IndexSource,
NameRequirementSpecification, UnresolvedRequirementSpecification, Verbatim,
DependencyMetadata, Index, IndexCapabilities, IndexLocations, NameRequirementSpecification,
UnresolvedRequirementSpecification, Verbatim,
};
use install_wheel_rs::linker::LinkMode;
use pypi_types::{Requirement, SupportedEnvironments};
Expand Down Expand Up @@ -277,8 +277,8 @@ pub(crate) async fn pip_compile(
let index_locations = index_locations.combine(
extra_index_urls
.into_iter()
.map(IndexSource::from_extra_index_url)
.chain(index_url.map(IndexSource::from_index_url))
.map(Index::from_extra_index_url)
.chain(index_url.map(Index::from_index_url))
.collect(),
find_links,
no_index,
Expand Down
Loading

0 comments on commit 7dfb804

Please sign in to comment.