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

feat: add direct url repodata building #725

Merged
merged 54 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
a52ac91
wip: allow for repodata to be created from a url based dependency
ruben-arts Jun 4, 2024
5eb36b3
fix: local test, ignore lineno in env
ruben-arts Jun 5, 2024
2793fc8
feat: implement direct_url_query for fetching package from url and ge…
ruben-arts Jun 5, 2024
5ee5d0f
feat: solve for direct url
ruben-arts Jun 5, 2024
88cba3a
fmt
ruben-arts Jun 5, 2024
35492b2
fix: test, download example package
ruben-arts Jun 5, 2024
6cd59d8
fmt
ruben-arts Jun 5, 2024
8b573c6
fix: test, use same archive type
ruben-arts Jun 5, 2024
a3da32f
fix: repodata result, tested in py-rattler
ruben-arts Jun 5, 2024
1b9d3fc
fix: test, use temp_dir
ruben-arts Jun 5, 2024
df6b092
fmt
ruben-arts Jun 5, 2024
a54111a
fix: build/test
ruben-arts Jun 10, 2024
3c74946
feat: add matcher trait to remove direct url from package record
ruben-arts Jun 10, 2024
f05d3ea
fix: remove wrong defaults
ruben-arts Jun 10, 2024
0b3e6df
Merge branch 'main' into feature/direct_url_query
ruben-arts Jun 10, 2024
26dfc1c
feat: move the direct url query into a future which is called by the …
ruben-arts Jun 10, 2024
1c41a89
fix: tests
ruben-arts Jun 10, 2024
4a7f67d
fix: speed back up matches
ruben-arts Jun 10, 2024
cb45f15
fix: module rename to direct url query
ruben-arts Jun 10, 2024
2749332
fix: improve direct url error
ruben-arts Jun 10, 2024
7e93696
fix: share package cache in the inner gateway
ruben-arts Jun 10, 2024
55f9e1e
fix: py-rattler
ruben-arts Jun 10, 2024
1e5e5c4
misc: add package cache to gateway builder
ruben-arts Jun 12, 2024
dbc4838
misc: add error for missing name in matchspec
ruben-arts Jun 12, 2024
d520aa0
misc: check package name compatibility between package from url and t…
ruben-arts Jun 12, 2024
f34afe5
fix: remove dbg!
ruben-arts Jun 12, 2024
98cc73f
fix: remove unsafe check from root req
ruben-arts Jun 12, 2024
179b126
misc: print with direct url in create command
ruben-arts Jun 12, 2024
c126693
fix: add direct url specific subdir
ruben-arts Jun 12, 2024
b108da2
Merge branch 'main' into feature/direct_url_query
ruben-arts Jun 13, 2024
885ea5b
fmt
ruben-arts Jun 13, 2024
27bf7e2
fix: use correct dir for cache and make a const for pkgs and repodata…
ruben-arts Jun 13, 2024
9f0cd3d
fix: merge conflict
ruben-arts Jun 13, 2024
304a838
fmt
ruben-arts Jun 13, 2024
d03a1d3
clippy
ruben-arts Jun 13, 2024
c868b5a
Update crates/rattler_repodata_gateway/src/gateway/error.rs
ruben-arts Jun 13, 2024
cce373a
Update crates/rattler_repodata_gateway/src/gateway/query.rs
ruben-arts Jun 13, 2024
87c8b5a
fix: Make the direct url the first subdir
ruben-arts Jun 13, 2024
c296eda
fix: Make the direct url the first subdir
ruben-arts Jun 13, 2024
600ed22
fix: reduce amount of name checking by providing url in direct_url_specs
ruben-arts Jun 13, 2024
7a19f32
fix tests
ruben-arts Jun 13, 2024
97d3cbd
fmt
ruben-arts Jun 13, 2024
cb7a0cc
fix: subdirs only used for channels but in the result reserve a spot …
ruben-arts Jun 13, 2024
d2404de
fix: docstring
ruben-arts Jun 13, 2024
0f09dd8
fix: make channel nameless for direct urls
ruben-arts Jun 13, 2024
bee860c
fix intra-docs test
ruben-arts Jun 13, 2024
b7eeede
fix: match on record not package record
ruben-arts Jun 13, 2024
7ea414a
fix: improve error name and only unpack spec once.
ruben-arts Jun 13, 2024
44c2864
fix: Add new subdir with offset
ruben-arts Jun 13, 2024
268df39
fmt
ruben-arts Jun 13, 2024
4cc3c50
test: subdir asignment for direct url
ruben-arts Jun 13, 2024
e2b2848
fmt
ruben-arts Jun 13, 2024
e74d4dc
fix: windows issues
baszalmstra Jun 13, 2024
8ab4d68
fix: clippy
baszalmstra Jun 13, 2024
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
15 changes: 15 additions & 0 deletions crates/rattler_cache/src/package_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ impl From<&PackageRecord> for CacheKey {
}
}

impl From<&Url> for CacheKey {
fn from(url: &Url) -> Self {
if let Some(archive) = ArchiveIdentifier::try_from_url(url) {
return archive.into();
}
// Not a normal archive, so we use the url as the cache key
CacheKey {
name: url.to_string(),
version: "_".to_string(),
build_string: "_".to_string(),
sha256: None,
}
}
}

impl Display for CacheKey {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}-{}-{}", &self.name, &self.version, &self.build_string)
Expand Down
7 changes: 7 additions & 0 deletions crates/rattler_conda_types/src/match_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,13 @@ impl NamelessMatchSpec {
}
}

// Match on the url, only happens with direct url dependencies
if let Some(url_spec) = self.url.as_ref() {
ruben-arts marked this conversation as resolved.
Show resolved Hide resolved
if Some(url_spec) != record.direct_url.as_ref() {
return false;
}
}

true
}
}
Expand Down
39 changes: 27 additions & 12 deletions crates/rattler_conda_types/src/match_spec/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use super::{
matcher::{StringMatcher, StringMatcherParseError},
MatchSpec,
};
use crate::package::ArchiveIdentifier;
use crate::utils::url::parse_scheme;
use crate::{
build_spec::{BuildNumberSpec, ParseBuildNumberSpecError},
Expand Down Expand Up @@ -388,8 +389,18 @@ fn matchspec_parser(
// 2.a Is the spec an url, parse it as an url
if parse_scheme(input).is_some() {
let url = Url::parse(input)?;

let archive = ArchiveIdentifier::try_from_url(&url);
let name = archive.and_then(|a| a.try_into().ok());

// TODO: This should also work without a proper name from the url filename
if name.is_none() {
return Err(ParseMatchSpecError::MissingPackageName);
}

return Ok(MatchSpec {
url: Some(url),
name,
..MatchSpec::default()
});
}
Expand All @@ -398,8 +409,18 @@ fn matchspec_parser(
let path = Utf8TypedPath::from(input);
let url = file_url::file_path_to_url(path)
.map_err(|_error| ParseMatchSpecError::InvalidPackagePathOrUrl)?;

let archive = ArchiveIdentifier::try_from_url(&url);
let name = archive.and_then(|a| a.try_into().ok());

// TODO: This should also work without a proper name from the url filename
if name.is_none() {
return Err(ParseMatchSpecError::MissingPackageName);
}

return Ok(MatchSpec {
url: Some(url),
name,
..MatchSpec::default()
});
}
Expand Down Expand Up @@ -870,22 +891,16 @@ mod tests {
spec.url,
Some(Url::parse("file:/home/user/conda-bld/linux-64/foo-1.0-py27_0.tar.bz2").unwrap())
);

let spec = MatchSpec::from_str("C:\\Users\\user\\Downloads\\package", Strict).unwrap();
assert_eq!(
spec.url,
Some(Url::parse("file://C:/Users/user/Downloads/package").unwrap())
);
let spec = MatchSpec::from_str("/home/user/Downloads/package", Strict).unwrap();

assert_eq!(
spec.url,
Some(Url::parse("file:/home/user/Downloads/package").unwrap())
);
}

#[test]
fn test_non_happy_url_parsing() {
let spec = MatchSpec::from_str("C:\\Users\\user\\Downloads\\package", Strict).unwrap_err();
assert_matches!(spec, ParseMatchSpecError::MissingPackageName);

let spec = MatchSpec::from_str("/home/user/Downloads/package", Strict).unwrap_err();
assert_matches!(spec, ParseMatchSpecError::MissingPackageName);

let err = MatchSpec::from_str("http://username@", Strict).expect_err("Invalid url");
assert_eq!(err.to_string(), "invalid package spec url");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ assertion_line: 794
expression: evaluated
---
/home/user/conda-bld/linux-64/foo-1.0-py27_0.tar.bz2:
name: foo
url: "file:///home/user/conda-bld/linux-64/foo-1.0-py27_0.tar.bz2"
"C:\\Users\\user\\conda-bld\\linux-64\\foo-1.0-py27_0.tar.bz2":
name: foo
url: "file:///C:/Users/user/conda-bld/linux-64/foo-1.0-py27_0.tar.bz2"
blas *.* mkl:
name: blas
Expand Down Expand Up @@ -35,8 +37,10 @@ foo==1.0=py27_0:
version: "==1.0"
build: py27_0
"https://conda.anaconda.org/conda-forge/linux-64/py-rattler-0.6.1-py39h8169da8_0.conda":
name: py-rattler
url: "https://conda.anaconda.org/conda-forge/linux-64/py-rattler-0.6.1-py39h8169da8_0.conda"
"https://repo.prefix.dev/ruben-arts/linux-64/boost-cpp-1.78.0-h75c5d50_1.tar.bz2":
name: boost-cpp
url: "https://repo.prefix.dev/ruben-arts/linux-64/boost-cpp-1.78.0-h75c5d50_1.tar.bz2"
python 3.8.* *_cpython:
name: python
Expand Down
11 changes: 10 additions & 1 deletion crates/rattler_conda_types/src/package_name.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::package::ArchiveIdentifier;
use crate::utils::serde::DeserializeFromStrUnchecked;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_with::{DeserializeAs, DeserializeFromStr};
Expand All @@ -16,7 +17,7 @@ use thiserror::Error;
/// This struct explicitly does not implement [`std::fmt::Display`] because its ambiguous if that
/// would display the source or the normalized version. Simply call `as_source` or `as_normalized`
/// to make the distinction.
#[derive(Debug, Clone, Eq, DeserializeFromStr)]
#[derive(Debug, Default, Clone, Eq, DeserializeFromStr)]
ruben-arts marked this conversation as resolved.
Show resolved Hide resolved
pub struct PackageName {
normalized: Option<String>,
source: String,
Expand Down Expand Up @@ -62,6 +63,14 @@ impl TryFrom<&String> for PackageName {
}
}

impl TryFrom<ArchiveIdentifier> for PackageName {
type Error = InvalidPackageNameError;

fn try_from(value: ArchiveIdentifier) -> Result<Self, Self::Error> {
value.name.try_into()
}
}

impl TryFrom<String> for PackageName {
type Error = InvalidPackageNameError;

Expand Down
18 changes: 16 additions & 2 deletions crates/rattler_conda_types/src/repo_data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub struct ChannelInfo {
#[serde_as]
#[skip_serializing_none]
#[sorted]
#[derive(Debug, Deserialize, Serialize, Eq, PartialEq, Clone, Hash)]
#[derive(Debug, Default, Deserialize, Serialize, Eq, PartialEq, Clone, Hash)]
ruben-arts marked this conversation as resolved.
Show resolved Hide resolved
pub struct PackageRecord {
/// Optionally the architecture the package supports
pub arch: Option<String>,
Expand All @@ -103,6 +103,10 @@ pub struct PackageRecord {
#[serde(default)]
pub depends: Vec<String>,

/// The package's url which isn't part of an real pacakge record but injected by the direct url query.
#[serde(skip)]
pub direct_url: Option<Url>,
ruben-arts marked this conversation as resolved.
Show resolved Hide resolved

/// Features are a deprecated way to specify different feature sets for the
/// conda solver. This is not supported anymore and should not be used.
/// Instead, `mutex` packages should be used to specify
Expand Down Expand Up @@ -187,7 +191,9 @@ pub struct PackageRecord {

impl Display for PackageRecord {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
if self.build.is_empty() {
if let Some(url) = &self.direct_url {
write!(f, "{url}")
} else if self.build.is_empty() {
write!(f, "{} {}", self.name.as_normalized(), self.version,)
} else {
write!(
Expand Down Expand Up @@ -311,6 +317,7 @@ impl PackageRecord {
version: version.into(),
purls: None,
run_exports: None,
direct_url: None,
}
}

Expand Down Expand Up @@ -429,8 +436,15 @@ impl PackageRecord {
version: index.version,
purls: None,
run_exports: None,
direct_url: None,
})
}

/// Add url to the [`PackageRecord`]
pub fn with_package_url(mut self, url: Url) -> Self {
self.direct_url = Some(url);
self
}
}

fn sort_map_alphabetically<T: Serialize, S: serde::Serializer>(
Expand Down
2 changes: 1 addition & 1 deletion crates/rattler_conda_types/src/version/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub use with_source::VersionWithSource;
/// this problem by appending an underscore to plain version numbers:
///
/// 1.0.1_ < 1.0.1a => True # ensure correct ordering for openssl
#[derive(Clone, Eq)]
#[derive(Clone, Eq, Default)]
ruben-arts marked this conversation as resolved.
Show resolved Hide resolved
pub struct Version {
/// Individual components of the version.
///
Expand Down
2 changes: 1 addition & 1 deletion crates/rattler_conda_types/src/version/with_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::{
///
/// It is also possible to convert directly from a [`Version`] but the [`Display`] implementation
/// is then used to generate the string representation.
#[derive(Debug, Clone)]
#[derive(Debug, Default, Clone)]
ruben-arts marked this conversation as resolved.
Show resolved Hide resolved
pub struct VersionWithSource {
version: Version,
source: Option<Box<str>>,
Expand Down
1 change: 1 addition & 0 deletions crates/rattler_index/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ fn package_record_from_index_json<T: Read>(
legacy_bz2_size: None,
purls: None,
run_exports: None,
direct_url: None,
};

Ok(package_record)
Expand Down
1 change: 1 addition & 0 deletions crates/rattler_lock/src/parse/v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ pub fn parse_v3_or_lower(
version: value.version,
purls: value.purls.is_empty().not().then_some(value.purls),
run_exports: None,
direct_url: None,
},
url: value.url,
file_name: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ impl<'a> From<RawCondaPackageData<'a>> for CondaPackageData {
track_features: value.track_features.into_owned(),
version: value.version.into_owned(),
run_exports: None,
direct_url: None,
},
url: value.url.into_owned(),
file_name: value.file_name.into_owned(),
Expand Down
3 changes: 3 additions & 0 deletions crates/rattler_repodata_gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ tracing = { workspace = true }
url = { workspace = true, features = ["serde"] }
zstd = { workspace = true }
percent-encoding = { workspace = true }
rattler_cache = { version = "0.1.0", path = "../rattler_cache" }
rattler_package_streaming = { version = "0.21.2", path = "../rattler_package_streaming", default-features = false, features = ["reqwest"] }

[target.'cfg(unix)'.dependencies]
libc = { workspace = true }
Expand All @@ -72,6 +74,7 @@ tower-http = { workspace = true, features = ["fs", "compression-gzip", "trace"]
tracing-test = { workspace = true }
rattler_conda_types = { path = "../rattler_conda_types", version = "0.25.2", default-features = false }
fslock = { workspace = true }
tools = { path="../tools" }

[features]
default = ['native-tls']
Expand Down
Loading
Loading