Skip to content
Open
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
2 changes: 1 addition & 1 deletion crates/rattler-bin/src/commands/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ fn print_transaction(
) {
let format_record = |r: &RepoDataRecord| {
let direct_url_print = if let Some(channel) = &r.channel {
channel.clone()
channel.to_string()
} else {
String::new()
};
Expand Down
4 changes: 2 additions & 2 deletions crates/rattler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use rattler_conda_types::RepoDataRecord;
pub(crate) fn get_repodata_record(package_path: impl AsRef<std::path::Path>) -> RepoDataRecord {
use std::fs;

use rattler_conda_types::{package::IndexJson, PackageRecord};
use rattler_conda_types::{package::IndexJson, Channel, PackageRecord};
use rattler_digest::{Md5, Sha256};
use rattler_package_streaming::seek::read_package_file;

Expand All @@ -78,6 +78,6 @@ pub(crate) fn get_repodata_record(package_path: impl AsRef<std::path::Path>) ->
.unwrap()
.to_string(),
url: url::Url::from_file_path(package_path).unwrap(),
channel: Some(String::from("test")),
channel: Some(Channel::from_directory(package_path.parent().unwrap()).base_url),
}
}
2 changes: 1 addition & 1 deletion crates/rattler_conda_types/src/channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl serde::Serialize for NamedChannelOrUrl {
}

/// `Channel`s are the primary source of package information.
#[derive(Debug, Clone, Serialize, Eq, PartialEq, Hash)]
#[derive(Debug, Clone, Deserialize, Serialize, Eq, PartialEq, Hash)]
pub struct Channel {
/// The platforms supported by this channel, or None if no explicit
/// platforms have been specified.
Expand Down
11 changes: 6 additions & 5 deletions crates/rattler_conda_types/src/match_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,13 @@ mod tests {
use itertools::Itertools;
use rstest::rstest;
use std::str::FromStr;
use url::Url;

use rattler_digest::{parse_digest_from_hex, Md5, Sha256};

use crate::{
match_spec::Matches, MatchSpec, NamelessMatchSpec, PackageName, PackageRecord,
ParseStrictness::*, RepoDataRecord, StringMatcher, Version, VersionSpec,
match_spec::Matches, Channel, ChannelUrl, MatchSpec, NamelessMatchSpec, PackageName,
PackageRecord, ParseStrictness::*, RepoDataRecord, StringMatcher, Version, VersionSpec,
};
use insta::assert_snapshot;
use std::hash::{Hash, Hasher};
Expand Down Expand Up @@ -763,7 +764,7 @@ mod tests {
),
file_name: String::from("mamba-1.0-py37_0"),
url: url::Url::parse("https://mamba.io/mamba-1.0-py37_0.conda").unwrap(),
channel: Some(String::from("mamba")),
channel: Some(Channel::from_url(url::Url::parse("https://mamba.io").unwrap()).base_url),
};
let package_record = repodata_record.clone().package_record;

Expand Down Expand Up @@ -797,7 +798,7 @@ mod tests {
),
file_name: String::from("mamba-1.0-py37_0"),
url: url::Url::parse("https://mamba.io/mamba-1.0-py37_0.conda").unwrap(),
channel: Some(String::from("mamba")),
channel: Some(ChannelUrl::from(Url::from_str("https://mamba.io").unwrap())),
};
repodata_record.package_record.license = Some("BSD-3-Clause".into());
let package_record = repodata_record.clone().package_record;
Expand All @@ -824,7 +825,7 @@ mod tests {
),
file_name: String::from("mamba-1.0-py37_0"),
url: url::Url::parse("https://mamba.io/mamba-1.0-py37_0.conda").unwrap(),
channel: Some(String::from("mamba")),
channel: Some(ChannelUrl::from(Url::from_str("https://mamba.io").unwrap())),
};
let package_record_no_license = repodata_record_no_license.clone().package_record;
assert!(!match_spec.matches(&repodata_record_no_license));
Expand Down
2 changes: 1 addition & 1 deletion crates/rattler_conda_types/src/repo_data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl RepoData {
base_url.as_deref(),
&filename,
),
channel: Some(channel.base_url.as_str().to_string()),
channel: Some(channel.base_url.clone()),
package_record,
file_name: filename,
});
Expand Down
5 changes: 2 additions & 3 deletions crates/rattler_conda_types/src/repo_data_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::{collections::HashMap, vec::Vec};

use crate::{PackageName, PackageRecord};
use crate::{ChannelUrl, PackageName, PackageRecord};
use serde::{Deserialize, Serialize};
use url::Url;

Expand All @@ -24,8 +24,7 @@ pub struct RepoDataRecord {
/// String representation of the channel where the package comes from. This could be a URL but
/// it could also be a channel name. Personally I would always add the complete URL here to be
/// explicit about where the package came from.
/// TODO: Refactor this into `Source` which can be a "name", "channelurl", or "direct url".
pub channel: Option<String>,
pub channel: Option<ChannelUrl>,
}

impl AsRef<PackageRecord> for RepoDataRecord {
Expand Down
8 changes: 2 additions & 6 deletions crates/rattler_lock/src/conda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use rattler_conda_types::{
use rattler_digest::Sha256Hash;
use std::collections::BTreeMap;
use std::{borrow::Cow, cmp::Ordering, hash::Hash};
use url::Url;

/// A locked conda dependency can be either a binary package or a source
/// package.
Expand Down Expand Up @@ -228,10 +227,7 @@ impl From<RepoDataRecord> for CondaPackageData {
Self::Binary(CondaBinaryData {
package_record: value.package_record,
file_name: value.file_name,
channel: value
.channel
.and_then(|channel| Url::parse(&channel).ok())
.map(Into::into),
channel: value.channel,
location,
})
}
Expand All @@ -253,7 +249,7 @@ impl TryFrom<CondaBinaryData> for RepoDataRecord {
package_record: value.package_record,
file_name: value.file_name,
url: value.location.try_into_url()?,
channel: value.channel.map(|channel| channel.to_string()),
channel: value.channel,
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::borrow::Cow;

use cfg_if::cfg_if;
use rattler_conda_types::{ChannelUrl, RepoDataRecord, Shard};
use rattler_redaction::Redact;
use url::Url;

use crate::{fetch::FetchRepoDataError, GatewayError};
Expand Down Expand Up @@ -67,7 +66,7 @@ async fn parse_records<R: AsRef<[u8]> + Send + 'static>(
url: base_url
.join(&file_name)
.expect("filename is not a valid url"),
channel: Some(channel_base_url.url().clone().redact().to_string()),
channel: Some(channel_base_url.clone()),
package_record,
file_name,
})
Expand Down
5 changes: 2 additions & 3 deletions crates/rattler_repodata_gateway/src/sparse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use itertools::Itertools;
use rattler_conda_types::{
compute_package_url, Channel, ChannelInfo, PackageName, PackageRecord, RepoDataRecord,
};
use rattler_redaction::Redact;
use serde::{
de::{Error, MapAccess, Visitor},
Deserialize, Deserializer,
Expand Down Expand Up @@ -311,7 +310,7 @@ fn parse_records<'i>(
subdir: &str,
patch_function: Option<fn(&mut PackageRecord)>,
) -> io::Result<Vec<RepoDataRecord>> {
let channel_name = channel.base_url.clone();
let channel_base_url = &channel.base_url;

let package_indices =
packages.equal_range_by(|(package, _)| package.package.cmp(package_name.as_normalized()));
Expand All @@ -332,7 +331,7 @@ fn parse_records<'i>(
base_url,
key.filename,
),
channel: Some(channel_name.url().clone().redact().to_string()),
channel: Some(channel_base_url.clone()),
package_record,
file_name: key.filename.to_owned(),
});
Expand Down
15 changes: 7 additions & 8 deletions crates/rattler_solve/src/libsolv_c/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub use input::cache_repodata;
use input::{add_repodata_records, add_solv_file, add_virtual_packages};
pub use libc_byte_slice::LibcByteSlice;
use output::get_required_packages;
use rattler_conda_types::{MatchSpec, NamelessMatchSpec, RepoDataRecord, SolverResult};
use rattler_conda_types::{ChannelUrl, MatchSpec, NamelessMatchSpec, RepoDataRecord, SolverResult};
use wrapper::{
flags::SolverFlag,
pool::{Pool, Verbosity},
Expand Down Expand Up @@ -175,19 +175,18 @@ impl super::SolverImpl for Solver {
if repodata.records.is_empty() {
continue;
}
let channel_name = &repodata.records[0].channel;
let channel = &repodata.records[0].channel;

// We dont want to drop the Repo, its stored in the pool anyway.
let priority: i32 = if task.channel_priority == ChannelPriority::Strict {
*channel_priority.get(channel_name).unwrap()
*channel_priority.get(channel).unwrap()
} else {
0
};
let repo = ManuallyDrop::new(Repo::new(
&pool,
channel_name.as_ref().map_or("<direct>", String::as_str),
priority,
));
let channel_url: String = channel
.as_ref()
.map_or("<direct>".to_string(), ChannelUrl::to_string);
let repo = ManuallyDrop::new(Repo::new(&pool, &channel_url, priority));

if let Some(solv_file) = repodata.solv_file {
add_solv_file(&pool, &repo, solv_file);
Expand Down
15 changes: 8 additions & 7 deletions crates/rattler_solve/src/resolvo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ use chrono::{DateTime, Utc};
use conda_sorting::SolvableSorter;
use itertools::Itertools;
use rattler_conda_types::{
package::ArchiveType, version_spec::EqualityOperator, BuildNumberSpec, GenericVirtualPackage,
MatchSpec, Matches, NamelessMatchSpec, OrdOperator, PackageName, PackageRecord,
ParseMatchSpecError, ParseStrictness, RepoDataRecord, SolverResult, StringMatcher, VersionSpec,
package::ArchiveType, version_spec::EqualityOperator, BuildNumberSpec, ChannelUrl,
GenericVirtualPackage, MatchSpec, Matches, NamelessMatchSpec, OrdOperator, PackageName,
PackageRecord, ParseMatchSpecError, ParseStrictness, RepoDataRecord, SolverResult,
StringMatcher, VersionSpec,
};
use resolvo::{
utils::{Pool, VersionSet},
Expand Down Expand Up @@ -303,7 +304,7 @@ impl<'a> CondaDependencyProvider<'a> {
.collect::<Vec<_>>();

// Hashmap that maps the package name to the channel it was first found in.
let mut package_name_found_in_channel = HashMap::<String, &Option<String>>::new();
let mut package_name_found_in_channel = HashMap::<String, &Option<ChannelUrl>>::new();

// Add additional records
for repo_data in repodata {
Expand Down Expand Up @@ -433,9 +434,9 @@ impl<'a> CondaDependencyProvider<'a> {
// Check if the spec has a channel, and compare it to the repodata
// channel
if let Some(spec_channel) = &spec.channel {
if record.channel.as_ref() != Some(&spec_channel.canonical_name()) {
if record.channel.as_ref() != Some(&spec_channel.base_url) {
tracing::debug!("Ignoring {} {} because it was not requested from that channel.", &record.package_record.name.as_normalized(), match &record.channel {
Some(channel) => format!("from {}", &channel),
Some(channel) => format!("from {channel}"),
None => "without a channel".to_string(),
});
// Add record to the excluded with reason of being in the non
Expand Down Expand Up @@ -468,7 +469,7 @@ impl<'a> CondaDependencyProvider<'a> {
tracing::debug!(
"Ignoring '{}' from '{}' because of strict channel priority.",
&record.package_record.name.as_normalized(),
channel
channel.to_string(),
);
candidates.excluded.push((
solvable,
Expand Down
24 changes: 14 additions & 10 deletions crates/rattler_solve/tests/backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::{collections::BTreeMap, str::FromStr, time::Instant};
use chrono::{DateTime, Utc};
use once_cell::sync::Lazy;
use rattler_conda_types::{
Channel, ChannelConfig, GenericVirtualPackage, MatchSpec, NoArchType, PackageRecord,
ParseStrictness, RepoData, RepoDataRecord, SolverResult, Version,
Channel, ChannelConfig, ChannelUrl, GenericVirtualPackage, MatchSpec, NoArchType,
PackageRecord, ParseStrictness, RepoData, RepoDataRecord, SolverResult, Version,
};
use rattler_repodata_gateway::sparse::SparseRepoData;
use rattler_solve::{ChannelPriority, SolveError, SolveStrategy, SolverImpl, SolverTask};
Expand Down Expand Up @@ -84,7 +84,7 @@ fn read_sparse_repodata(path: &str) -> SparseRepoData {
}

fn installed_package(
channel: &str,
channel_url: &str,
subdir: &str,
name: &str,
version: &str,
Expand All @@ -93,7 +93,7 @@ fn installed_package(
) -> RepoDataRecord {
RepoDataRecord {
url: Url::from_str("http://example.com").unwrap(),
channel: Some(channel.to_string()),
channel: Some(Channel::from_url(Url::parse(channel_url).unwrap()).base_url),
file_name: "dummy-filename".to_string(),
package_record: PackageRecord {
name: name.parse().unwrap(),
Expand Down Expand Up @@ -362,7 +362,7 @@ macro_rules! solver_backend_tests {
"https://conda.anaconda.org/conda-forge/linux-64/foo-3.0.2-py36h1af98f8_3.conda",
info.url.to_string()
);
assert_eq!(Some("https://conda.anaconda.org/conda-forge/"), info.channel.as_deref());
assert_eq!(Some("https://conda.anaconda.org/conda-forge/".to_string()), info.channel.as_ref().map(|chan_url| chan_url.to_string()));
assert_eq!("foo", info.package_record.name.as_normalized());
assert_eq!("linux-64", info.package_record.subdir);
assert_eq!("3.0.2", info.package_record.version.to_string());
Expand Down Expand Up @@ -616,6 +616,7 @@ macro_rules! solver_backend_tests {
mod libsolv_c {
#![allow(unused_imports)] // For some reason windows thinks this is an unused import.

use rattler_conda_types::ChannelUrl;
use rattler_solve::{ChannelPriority, SolveStrategy};

use super::{
Expand Down Expand Up @@ -684,8 +685,8 @@ mod libsolv_c {
info.url.to_string()
);
assert_eq!(
Some("https://conda.anaconda.org/conda-forge/"),
info.channel.as_deref()
Some("https://conda.anaconda.org/conda-forge/".to_string()),
info.channel.as_ref().map(ChannelUrl::to_string),
);
assert_eq!("foo", info.package_record.name.as_normalized());
assert_eq!("linux-64", info.package_record.subdir);
Expand Down Expand Up @@ -736,7 +737,7 @@ mod resolvo {
SimpleSolveTask {
specs: &["bors >=2"],
pinned_packages: vec![installed_package(
"conda-forge",
"https://prefix.dev/conda-forge",
"linux-64",
"bors",
"1.0",
Expand Down Expand Up @@ -958,7 +959,7 @@ mod resolvo {
specs: &["xbar"],
constraints: vec!["xfoo==1"],
pinned_packages: vec![installed_package(
"conda-forge",
"https://prefix.dev/conda-forge",
"linux-64",
"xfoo",
"1",
Expand Down Expand Up @@ -1543,7 +1544,10 @@ fn solve_to_get_channel_of_spec<T: SolverImpl + Default>(
let record = result.iter().find(|record| {
record.package_record.name.as_normalized() == spec.name.as_ref().unwrap().as_normalized()
});
assert_eq!(record.unwrap().channel, Some(expected_channel.to_string()));
assert_eq!(
record.unwrap().channel.as_ref().map(ChannelUrl::to_string),
Some(expected_channel.to_string())
);
}

#[test]
Expand Down
Loading
Loading