Skip to content

Commit

Permalink
Use CanonicalUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Mar 22, 2024
1 parent a281951 commit d9cd56c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 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.

2 changes: 1 addition & 1 deletion crates/distribution-types/src/index_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub enum IndexUrl {

impl IndexUrl {
/// Return the raw URL for the index.
pub(crate) fn url(&self) -> &Url {
pub fn url(&self) -> &Url {
match self {
Self::Pypi(url) => url.raw(),
Self::Url(url) => url.raw(),
Expand Down
1 change: 1 addition & 0 deletions crates/uv-requirements/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ authors.workspace = true
license.workspace = true

[dependencies]
cache-key = { workspace = true }
distribution-filename = { workspace = true }
distribution-types = { workspace = true }
pep508_rs = { workspace = true }
Expand Down
28 changes: 15 additions & 13 deletions crates/uv-requirements/src/specification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use indexmap::IndexMap;
use rustc_hash::FxHashSet;
use tracing::{instrument, Level};

use crate::{ExtrasSpecification, RequirementsSource};
use cache_key::CanonicalUrl;
use distribution_types::{FlatIndexLocation, IndexUrl};
use pep508_rs::{Requirement, RequirementsTxtRequirement};
use requirements_txt::{EditableRequirement, FindLink, RequirementsTxt};
Expand All @@ -14,6 +14,8 @@ use uv_fs::Simplified;
use uv_normalize::{ExtraName, PackageName};
use uv_warnings::warn_user;

use crate::{ExtrasSpecification, RequirementsSource};

#[derive(Debug, Default)]
pub struct RequirementsSpecification {
/// The name of the project specifying requirements.
Expand Down Expand Up @@ -205,15 +207,15 @@ impl RequirementsSpecification {
spec.project = source.project;
}

if let Some(url) = source.index_url {
if let Some(index_url) = source.index_url {
if let Some(existing) = spec.index_url {
if url != existing {
if CanonicalUrl::new(index_url.url()) != CanonicalUrl::new(existing.url()) {
return Err(anyhow::anyhow!(
"Multiple index URLs specified: `{existing}` vs. `{url}`",
"Multiple index URLs specified: `{existing}` vs. `{index_url}`",
));
}
}
spec.index_url = Some(url);
spec.index_url = Some(index_url);
}
spec.no_index |= source.no_index;
spec.extra_index_urls.extend(source.extra_index_urls);
Expand All @@ -238,15 +240,15 @@ impl RequirementsSpecification {
spec.constraints.extend(source.constraints);
spec.constraints.extend(source.overrides);

if let Some(url) = source.index_url {
if let Some(index_url) = source.index_url {
if let Some(existing) = spec.index_url {
if url != existing {
if CanonicalUrl::new(index_url.url()) != CanonicalUrl::new(existing.url()) {
return Err(anyhow::anyhow!(
"Multiple index URLs specified: `{existing}` vs. `{url}`",
"Multiple index URLs specified: `{existing}` vs. `{index_url}`",
));
}
}
spec.index_url = Some(url);
spec.index_url = Some(index_url);
}
spec.no_index |= source.no_index;
spec.extra_index_urls.extend(source.extra_index_urls);
Expand All @@ -271,15 +273,15 @@ impl RequirementsSpecification {
spec.overrides.extend(source.constraints);
spec.overrides.extend(source.overrides);

if let Some(url) = source.index_url {
if let Some(index_url) = source.index_url {
if let Some(existing) = spec.index_url {
if url != existing {
if CanonicalUrl::new(index_url.url()) != CanonicalUrl::new(existing.url()) {
return Err(anyhow::anyhow!(
"Multiple index URLs specified: `{existing}` vs. `{url}`",
"Multiple index URLs specified: `{existing}` vs. `{index_url}`",
));
}
}
spec.index_url = Some(url);
spec.index_url = Some(index_url);
}
spec.no_index |= source.no_index;
spec.extra_index_urls.extend(source.extra_index_urls);
Expand Down

0 comments on commit d9cd56c

Please sign in to comment.