Skip to content

Commit 3208ab0

Browse files
committed
Rename
1 parent 65a88bf commit 3208ab0

File tree

22 files changed

+290
-158
lines changed

22 files changed

+290
-158
lines changed

crates/distribution-types/src/index_source.rs renamed to crates/distribution-types/src/index.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{IndexUrl, IndexUrlError};
55

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

75-
impl IndexSource {
76-
/// Initialize an [`IndexSource`] from a pip-style `--index-url`.
75+
impl Index {
76+
/// Initialize an [`Index`] from a pip-style `--index-url`.
7777
pub fn from_index_url(url: IndexUrl) -> Self {
7878
Self {
7979
url,
@@ -83,7 +83,7 @@ impl IndexSource {
8383
}
8484
}
8585

86-
/// Initialize an [`IndexSource`] from a pip-style `--extra-index-url`.
86+
/// Initialize an [`Index`] from a pip-style `--extra-index-url`.
8787
pub fn from_extra_index_url(url: IndexUrl) -> Self {
8888
Self {
8989
url,
@@ -94,7 +94,7 @@ impl IndexSource {
9494
}
9595
}
9696

97-
impl FromStr for IndexSource {
97+
impl FromStr for Index {
9898
type Err = IndexSourceError;
9999

100100
fn from_str(s: &str) -> Result<Self, Self::Err> {
@@ -126,7 +126,7 @@ impl FromStr for IndexSource {
126126
}
127127
}
128128

129-
/// An error that can occur when parsing an [`IndexSource`].
129+
/// An error that can occur when parsing an [`Index`].
130130
#[derive(Error, Debug)]
131131
pub enum IndexSourceError {
132132
#[error(transparent)]

crates/distribution-types/src/index_url.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use url::{ParseError, Url};
1111

1212
use pep508_rs::{VerbatimUrl, VerbatimUrlError};
1313

14-
use crate::{IndexSource, Verbatim};
14+
use crate::{Index, Verbatim};
1515

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

@@ -55,6 +55,7 @@ impl IndexUrl {
5555
}
5656
}
5757

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

308309
impl IndexLocations {
309310
/// Determine the index URLs to use for fetching packages.
310-
pub fn new(
311-
indexes: Vec<IndexSource>,
312-
flat_index: Vec<FlatIndexLocation>,
313-
no_index: bool,
314-
) -> Self {
311+
pub fn new(indexes: Vec<Index>, flat_index: Vec<FlatIndexLocation>, no_index: bool) -> Self {
315312
Self {
316313
indexes,
317314
flat_index,
@@ -328,7 +325,7 @@ impl IndexLocations {
328325
#[must_use]
329326
pub fn combine(
330327
self,
331-
indexes: Vec<IndexSource>,
328+
indexes: Vec<Index>,
332329
flat_index: Vec<FlatIndexLocation>,
333330
no_index: bool,
334331
) -> Self {
@@ -425,7 +422,7 @@ impl<'a> IndexLocations {
425422
/// From a pip perspective, this type merges `--index-url` and `--extra-index-url`.
426423
#[derive(Default, Debug, Clone, PartialEq, Eq)]
427424
pub struct IndexUrls {
428-
indexes: Vec<IndexSource>,
425+
indexes: Vec<Index>,
429426
no_index: bool,
430427
}
431428

crates/distribution-types/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub use crate::error::*;
5757
pub use crate::file::*;
5858
pub use crate::hash::*;
5959
pub use crate::id::*;
60-
pub use crate::index_source::*;
60+
pub use crate::index::*;
6161
pub use crate::index_url::*;
6262
pub use crate::installed::*;
6363
pub use crate::prioritized_distribution::*;
@@ -76,7 +76,7 @@ mod error;
7676
mod file;
7777
mod hash;
7878
mod id;
79-
mod index_source;
79+
mod index;
8080
mod index_url;
8181
mod installed;
8282
mod prioritized_distribution;

crates/uv-cli/src/lib.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use anyhow::{anyhow, Result};
77
use clap::builder::styling::{AnsiColor, Effects, Style};
88
use clap::builder::Styles;
99
use clap::{Args, Parser, Subcommand};
10-
use distribution_types::{FlatIndexLocation, IndexSource, IndexUrl};
10+
use distribution_types::{FlatIndexLocation, Index, IndexUrl};
1111
use pep508_rs::Requirement;
1212
use pypi_types::VerbatimParsedUrl;
1313
use url::Url;
@@ -779,13 +779,13 @@ fn parse_index_url(input: &str) -> Result<Maybe<IndexUrl>, String> {
779779
}
780780
}
781781

782-
/// Parse a string into an [`IndexSource`], mapping the empty string to `None`.
783-
fn parse_index_source(input: &str) -> Result<Maybe<IndexSource>, String> {
782+
/// Parse a string into an [`Index`], mapping the empty string to `None`.
783+
fn parse_index_source(input: &str) -> Result<Maybe<Index>, String> {
784784
if input.is_empty() {
785785
Ok(Maybe::None)
786786
} else {
787-
match IndexSource::from_str(input) {
788-
Ok(index) => Ok(Maybe::Some(IndexSource {
787+
match Index::from_str(input) {
788+
Ok(index) => Ok(Maybe::Some(Index {
789789
default: false,
790790
..index
791791
})),
@@ -794,13 +794,13 @@ fn parse_index_source(input: &str) -> Result<Maybe<IndexSource>, String> {
794794
}
795795
}
796796

797-
/// Parse a string into an [`IndexSource`], mapping the empty string to `None`.
798-
fn parse_default_index_source(input: &str) -> Result<Maybe<IndexSource>, String> {
797+
/// Parse a string into an [`Index`], mapping the empty string to `None`.
798+
fn parse_default_index_source(input: &str) -> Result<Maybe<Index>, String> {
799799
if input.is_empty() {
800800
Ok(Maybe::None)
801801
} else {
802-
match IndexSource::from_str(input) {
803-
Ok(index) => Ok(Maybe::Some(IndexSource {
802+
match Index::from_str(input) {
803+
Ok(index) => Ok(Maybe::Some(Index {
804804
default: true,
805805
..index
806806
})),
@@ -2250,8 +2250,8 @@ pub struct VenvArgs {
22502250
///
22512251
/// By default, uv will stop at the first index on which a given package is available, and
22522252
/// limit resolutions to those present on that first index (`first-match`). This prevents
2253-
/// "dependency confusion" attacks, whereby an attack can upload a malicious package under the
2254-
/// same name to a secondary.
2253+
/// "dependency confusion" attacks, whereby an attacker can upload a malicious package under the
2254+
/// same name to an alternate index.
22552255
#[arg(long, value_enum, env = "UV_INDEX_STRATEGY")]
22562256
pub index_strategy: Option<IndexStrategy>,
22572257

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

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

37263726
/// The URL of the Python package index (by default: <https://pypi.org/simple>).
37273727
///
@@ -3868,8 +3868,8 @@ pub struct InstallerArgs {
38683868
///
38693869
/// By default, uv will stop at the first index on which a given package is available, and
38703870
/// limit resolutions to those present on that first index (`first-match`). This prevents
3871-
/// "dependency confusion" attacks, whereby an attack can upload a malicious package under the
3872-
/// same name to a secondary.
3871+
/// "dependency confusion" attacks, whereby an attacker can upload a malicious package under the
3872+
/// same name to an alternate index.
38733873
#[arg(
38743874
long,
38753875
value_enum,
@@ -4030,8 +4030,8 @@ pub struct ResolverArgs {
40304030
///
40314031
/// By default, uv will stop at the first index on which a given package is available, and
40324032
/// limit resolutions to those present on that first index (`first-match`). This prevents
4033-
/// "dependency confusion" attacks, whereby an attack can upload a malicious package under the
4034-
/// same name to a secondary.
4033+
/// "dependency confusion" attacks, whereby an attacker can upload a malicious package under the
4034+
/// same name to an alternate index.
40354035
#[arg(
40364036
long,
40374037
value_enum,
@@ -4222,8 +4222,8 @@ pub struct ResolverInstallerArgs {
42224222
///
42234223
/// By default, uv will stop at the first index on which a given package is available, and
42244224
/// limit resolutions to those present on that first index (`first-match`). This prevents
4225-
/// "dependency confusion" attacks, whereby an attack can upload a malicious package under the
4226-
/// same name to a secondary.
4225+
/// "dependency confusion" attacks, whereby an attacker can upload a malicious package under the
4226+
/// same name to an alternate index.
42274227
#[arg(
42284228
long,
42294229
value_enum,

crates/uv-distribution/src/metadata/lowering.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use thiserror::Error;
66
use url::Url;
77

88
use distribution_filename::DistExtension;
9-
use distribution_types::IndexSource;
9+
use distribution_types::Index;
1010
use pep440_rs::VersionSpecifiers;
1111
use pep508_rs::{VerbatimUrl, VersionOrUrl};
1212
use pypi_types::{ParsedUrlError, Requirement, RequirementSource, VerbatimParsedUrl};
@@ -34,7 +34,7 @@ impl LoweredRequirement {
3434
project_name: &PackageName,
3535
project_dir: &Path,
3636
project_sources: &BTreeMap<PackageName, Source>,
37-
project_indexes: &[IndexSource],
37+
project_indexes: &[Index],
3838
workspace: &Workspace,
3939
) -> Result<Self, LoweringError> {
4040
let (source, origin) = if let Some(source) = project_sources.get(&requirement.name) {
@@ -115,15 +115,13 @@ impl LoweredRequirement {
115115
// in that order.
116116
let Some(index) = project_indexes
117117
.iter()
118-
.find(|IndexSource { name, .. }| {
119-
name.as_ref().is_some_and(|name| *name == index)
120-
})
118+
.find(|Index { name, .. }| name.as_ref().is_some_and(|name| *name == index))
121119
.or_else(|| {
122-
workspace.indexes().iter().find(|IndexSource { name, .. }| {
120+
workspace.indexes().iter().find(|Index { name, .. }| {
123121
name.as_ref().is_some_and(|name| *name == index)
124122
})
125123
})
126-
.map(|IndexSource { url: index, .. }| index.clone())
124+
.map(|Index { url: index, .. }| index.clone())
127125
else {
128126
return Err(LoweringError::MissingIndex(requirement.name, index));
129127
};
@@ -205,7 +203,7 @@ impl LoweredRequirement {
205203
requirement: pep508_rs::Requirement<VerbatimParsedUrl>,
206204
dir: &Path,
207205
sources: &BTreeMap<PackageName, Source>,
208-
indexes: &[IndexSource],
206+
indexes: &[Index],
209207
) -> Result<Self, LoweringError> {
210208
let source = sources.get(&requirement.name).cloned();
211209

@@ -247,10 +245,8 @@ impl LoweredRequirement {
247245
Source::Registry { index } => {
248246
let Some(index) = indexes
249247
.iter()
250-
.find(|IndexSource { name, .. }| {
251-
name.as_ref().is_some_and(|name| *name == index)
252-
})
253-
.map(|IndexSource { url: index, .. }| index.clone())
248+
.find(|Index { name, .. }| name.as_ref().is_some_and(|name| *name == index))
249+
.map(|Index { url: index, .. }| index.clone())
254250
else {
255251
return Err(LoweringError::MissingIndex(requirement.name, index));
256252
};

crates/uv-scripts/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::path::{Path, PathBuf};
44
use std::str::FromStr;
55
use std::sync::LazyLock;
66

7-
use distribution_types::IndexSource;
7+
use distribution_types::Index;
88
use memchr::memmem::Finder;
99
use pep440_rs::VersionSpecifiers;
1010
use pep508_rs::PackageName;
@@ -194,7 +194,7 @@ pub struct ToolUv {
194194
#[serde(flatten)]
195195
pub top_level: ResolverInstallerOptions,
196196
pub sources: Option<BTreeMap<PackageName, Source>>,
197-
pub indexes: Option<Vec<IndexSource>>,
197+
pub indexes: Option<Vec<Index>>,
198198
}
199199

200200
#[derive(Debug, Error)]

crates/uv-settings/src/settings.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{fmt::Debug, num::NonZeroUsize, path::PathBuf};
22

3-
use distribution_types::{FlatIndexLocation, IndexSource, IndexUrl, StaticMetadata};
3+
use distribution_types::{FlatIndexLocation, Index, IndexUrl, StaticMetadata};
44
use install_wheel_rs::linker::LinkMode;
55
use pep508_rs::Requirement;
66
use pypi_types::{SupportedEnvironments, VerbatimParsedUrl};
@@ -234,7 +234,7 @@ pub struct GlobalOptions {
234234
#[serde(rename_all = "kebab-case")]
235235
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
236236
pub struct InstallerOptions {
237-
pub index: Option<Vec<IndexSource>>,
237+
pub index: Option<Vec<Index>>,
238238
pub index_url: Option<IndexUrl>,
239239
pub extra_index_url: Option<Vec<IndexUrl>>,
240240
pub no_index: Option<bool>,
@@ -262,7 +262,7 @@ pub struct InstallerOptions {
262262
#[serde(rename_all = "kebab-case")]
263263
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
264264
pub struct ResolverOptions {
265-
pub index: Option<Vec<IndexSource>>,
265+
pub index: Option<Vec<Index>>,
266266
pub index_url: Option<IndexUrl>,
267267
pub extra_index_url: Option<Vec<IndexUrl>>,
268268
pub no_index: Option<bool>,
@@ -329,7 +329,7 @@ pub struct ResolverInstallerOptions {
329329
url = "https://download.pytorch.org/whl/cu121"
330330
"#
331331
)]
332-
pub index: Option<Vec<IndexSource>>,
332+
pub index: Option<Vec<Index>>,
333333
/// The URL of the Python package index (by default: <https://pypi.org/simple>).
334334
///
335335
/// Accepts either a repository compliant with [PEP 503](https://peps.python.org/pep-0503/)
@@ -398,8 +398,8 @@ pub struct ResolverInstallerOptions {
398398
///
399399
/// By default, uv will stop at the first index on which a given package is available, and
400400
/// limit resolutions to those present on that first index (`first-match`). This prevents
401-
/// "dependency confusion" attacks, whereby an attack can upload a malicious package under the
402-
/// same name to a secondary.
401+
/// "dependency confusion" attacks, whereby an attacker can upload a malicious package under the
402+
/// same name to an alternate index.
403403
#[option(
404404
default = "\"first-index\"",
405405
value_type = "str",
@@ -773,7 +773,7 @@ pub struct PipOptions {
773773
/// Additionally, marking an index as default will disable the PyPI default index.
774774
#[serde(skip)]
775775
#[cfg_attr(feature = "schemars", schemars(skip))]
776-
pub index: Option<Vec<IndexSource>>,
776+
pub index: Option<Vec<Index>>,
777777
/// The URL of the Python package index (by default: <https://pypi.org/simple>).
778778
///
779779
/// Accepts either a repository compliant with [PEP 503](https://peps.python.org/pep-0503/)
@@ -837,8 +837,8 @@ pub struct PipOptions {
837837
///
838838
/// By default, uv will stop at the first index on which a given package is available, and
839839
/// limit resolutions to those present on that first index (`first-match`). This prevents
840-
/// "dependency confusion" attacks, whereby an attack can upload a malicious package under the
841-
/// same name to a secondary.
840+
/// "dependency confusion" attacks, whereby an attacker can upload a malicious package under the
841+
/// same name to an alternate index.
842842
#[option(
843843
default = "\"first-index\"",
844844
value_type = "str",
@@ -1444,7 +1444,7 @@ impl From<ResolverInstallerOptions> for InstallerOptions {
14441444
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
14451445
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
14461446
pub struct ToolOptions {
1447-
pub index: Option<Vec<IndexSource>>,
1447+
pub index: Option<Vec<Index>>,
14481448
pub index_url: Option<IndexUrl>,
14491449
pub extra_index_url: Option<Vec<IndexUrl>>,
14501450
pub no_index: Option<bool>,
@@ -1550,7 +1550,7 @@ pub struct OptionsWire {
15501550

15511551
// #[serde(flatten)]
15521552
// top_level: ResolverInstallerOptions,
1553-
index: Option<Vec<IndexSource>>,
1553+
index: Option<Vec<Index>>,
15541554
index_url: Option<IndexUrl>,
15551555
extra_index_url: Option<Vec<IndexUrl>>,
15561556
no_index: Option<bool>,

0 commit comments

Comments
 (0)