Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: allow ChannelUrl in Channel::from_url interface #944

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions crates/rattler_conda_types/src/channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,11 @@ impl Channel {
}

/// Constructs a new [`Channel`] from a `Url` and associated platforms.
pub fn from_url(url: Url) -> Self {
pub fn from_url(url: impl Into<ChannelUrl>) -> Self {
// Get the path part of the URL but trim the directory suffix
let path = url.path().trim_end_matches('/');
let url: ChannelUrl = url.into();

let path = url.url().path().trim_end_matches('/');

// Case 1: No path give, channel name is ""

Expand All @@ -262,13 +264,13 @@ impl Channel {
// Case 4: custom_channels matches
// Case 5: channel_alias match

if url.has_host() {
if url.url().has_host() {
// Case 7: Fallback
let name = path.trim_start_matches('/');
Self {
platforms: None,
name: (!name.is_empty()).then_some(name).map(str::to_owned),
base_url: url.into(),
base_url: url,
}
} else {
// Case 6: non-otherwise-specified file://-type urls
Expand All @@ -278,7 +280,7 @@ impl Channel {
Self {
platforms: None,
name: (!name.is_empty()).then_some(name).map(str::to_owned),
base_url: url.into(),
base_url: url,
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions py-rattler/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading