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

refactor: lock-file v4 #484

Merged
merged 26 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2337e34
refactor: rattler-lock overhaul
baszalmstra Jan 17, 2024
08559c6
refactor: use inner arc structure
baszalmstra Jan 18, 2024
6a3f8d2
fix: docs
baszalmstra Jan 18, 2024
c004992
fix: order of fields in conda package
baszalmstra Jan 18, 2024
b03fc60
feat: add into_(conda|pypi)
baszalmstra Jan 18, 2024
d61a778
feat: add functionality to match a matchspec
baszalmstra Jan 18, 2024
3a8205a
fix: as_ should return a reference
baszalmstra Jan 18, 2024
8cd62f2
feat: implement satisfiability for pypi
baszalmstra Jan 18, 2024
adf4bfa
feat: TryFrom instead of TryInto
baszalmstra Jan 18, 2024
3770b45
fix: clippy
baszalmstra Jan 18, 2024
d40ff6f
feat: add Default to LockFile
baszalmstra Jan 19, 2024
971b806
fix: dont take into account extras
baszalmstra Jan 19, 2024
7cc5e63
feat: return all packages of an environment
baszalmstra Jan 19, 2024
98e75b9
feat: enable returning environment data
baszalmstra Jan 19, 2024
6cfd240
refactor: add combined package data
baszalmstra Jan 19, 2024
729aae3
feat: derive Copy Clone
baszalmstra Jan 19, 2024
f52e6ee
fix: with_channels retured reference
baszalmstra Jan 19, 2024
4448ad8
feat: add simpel way to access conda and pypi entries
baszalmstra Jan 22, 2024
7c2b873
feat: add simpel way to access conda and pypi entries
baszalmstra Jan 22, 2024
7714257
Merge remote-tracking branch 'upstream/main' into refactor/rattler_lo…
baszalmstra Jan 22, 2024
c8878cc
chore: rename conda to repodata
baszalmstra Jan 23, 2024
7115a87
fix: clipper errors
baszalmstra Jan 23, 2024
a8e022d
fix: indexing with wrong index
baszalmstra Jan 23, 2024
c340dba
fix: shell escaping
baszalmstra Jan 23, 2024
5829808
fix: docs
baszalmstra Jan 23, 2024
7901353
Merge remote-tracking branch 'upstream/main' into refactor/rattler_lo…
baszalmstra Jan 23, 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
6 changes: 3 additions & 3 deletions crates/async_http_range_reader/src/async_http_range_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl AsyncHttpRangeReader {
.get(reqwest::header::CONTENT_RANGE)
.ok_or(AsyncHttpRangeReaderError::ContentRangeMissing)?
.to_str()
.map_err(|_| AsyncHttpRangeReaderError::ContentRangeMissing)?,
.map_err(|_err| AsyncHttpRangeReaderError::ContentRangeMissing)?,
);
let (start, finish, complete_length) = match content_range {
ContentRange::Bytes(ContentRangeBytes {
Expand Down Expand Up @@ -297,9 +297,9 @@ impl AsyncHttpRangeReader {
.get(reqwest::header::CONTENT_LENGTH)
.ok_or(AsyncHttpRangeReaderError::ContentLengthMissing)?
.to_str()
.map_err(|_| AsyncHttpRangeReaderError::ContentLengthMissing)?
.map_err(|_err| AsyncHttpRangeReaderError::ContentLengthMissing)?
.parse()
.map_err(|_| AsyncHttpRangeReaderError::ContentLengthMissing)?;
.map_err(|_err| AsyncHttpRangeReaderError::ContentLengthMissing)?;

// Allocate a memory map to hold the data
let memory_map = memmap2::MmapOptions::new()
Expand Down
22 changes: 9 additions & 13 deletions crates/async_http_range_reader/src/sparse_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ impl SparseRange {
// Compute the bounds of covered range taking into account existing covered ranges.
let start = left_slice
.first()
.map(|&left_bound| left_bound.min(range_start))
.unwrap_or(range_start);
.map_or(range_start, |&left_bound| left_bound.min(range_start));

// Get the ranges that are missing
let mut bound = start;
Expand All @@ -79,8 +78,7 @@ impl SparseRange {

let end = right_slice
.last()
.map(|&right_bound| right_bound.max(range_end))
.unwrap_or(range_end);
.map_or(range_end, |&right_bound| right_bound.max(range_end));

bound > end
}
Expand All @@ -93,7 +91,7 @@ impl SparseRange {
}

/// Find the ranges that are uncovered for the specified range together with what the
/// SparseRange would look like if we covered that range.
/// [`SparseRange`] would look like if we covered that range.
pub fn cover(&self, range: Range<u64>) -> Option<(SparseRange, Vec<RangeInclusive<u64>>)> {
let range_start = range.start;
let range_end = range.end - 1;
Expand All @@ -109,12 +107,10 @@ impl SparseRange {
// Compute the bounds of covered range taking into account existing covered ranges.
let start = left_slice
.first()
.map(|&left_bound| left_bound.min(range_start))
.unwrap_or(range_start);
.map_or(range_start, |&left_bound| left_bound.min(range_start));
let end = right_slice
.last()
.map(|&right_bound| right_bound.max(range_end))
.unwrap_or(range_end);
.map_or(range_end, |&right_bound| right_bound.max(range_end));

// Get the ranges that are missing
let mut ranges = Vec::new();
Expand All @@ -126,10 +122,12 @@ impl SparseRange {
bound = right_bound + 1;
}
if bound <= end {
ranges.push(bound..=end)
ranges.push(bound..=end);
}

if !ranges.is_empty() {
if ranges.is_empty() {
None
} else {
let mut new_left = self.left.clone();
new_left.splice(left_index..right_index, [start]);
let mut new_right = self.right.clone();
Expand All @@ -141,8 +139,6 @@ impl SparseRange {
},
ranges,
))
} else {
None
}
}
}
Expand Down
24 changes: 14 additions & 10 deletions crates/rattler/src/install/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,10 +618,9 @@ mod test {
package_cache::PackageCache,
};
use futures::{stream, StreamExt};
use itertools::Itertools;
use rattler_conda_types::package::ArchiveIdentifier;
use rattler_conda_types::{ExplicitEnvironmentSpec, Platform, Version};
use rattler_lock::CondaLock;
use rattler_lock::LockFile;
use rattler_networking::AuthenticatedClient;

use std::env::temp_dir;
Expand All @@ -642,7 +641,7 @@ mod test {
assert_eq!(env.platform, Some(current_platform), "the platform for which the explicit lock file was created does not match the current platform");

test_install_python(
env.packages.iter().map(|p| &p.url),
env.packages.into_iter().map(|p| p.url),
"explicit",
current_platform,
)
Expand All @@ -653,23 +652,28 @@ mod test {
#[tokio::test]
pub async fn test_conda_lock() {
// Load a prepared explicit environment file for the current platform.
let lock_path = get_test_data_dir().join("conda-lock/python-conda-lock.yml");
let lock = CondaLock::from_path(&lock_path).unwrap();
let lock_path = get_test_data_dir().join("conda-lock/v4/python-lock.yml");
let lock = LockFile::from_path(&lock_path).unwrap();

let current_platform = Platform::current();
assert!(lock.metadata.platforms.iter().contains(&current_platform), "the platform for which the explicit lock file was created does not match the current platform");
let lock_env = lock
.default_environment()
.expect("no default environment in lock file");

let Some(packages) = lock_env.packages(current_platform) else {
panic!("the platform for which the explicit lock file was created does not match the current platform")
};

test_install_python(
lock.get_packages_by_platform(current_platform)
.filter_map(|p| Some(&p.as_conda()?.url)),
packages.filter_map(|p| Some(p.as_conda()?.url().clone())),
"conda-lock",
current_platform,
)
.await;
}

pub async fn test_install_python(
urls: impl Iterator<Item = &Url>,
urls: impl Iterator<Item = Url>,
cache_name: &str,
platform: Platform,
) {
Expand Down Expand Up @@ -697,7 +701,7 @@ mod test {
let python_version = &python_version;
async move {
// Populate the cache
let package_info = ArchiveIdentifier::try_from_url(package_url).unwrap();
let package_info = ArchiveIdentifier::try_from_url(&package_url).unwrap();
let package_dir = package_cache
.get_or_fetch_from_url(package_info, package_url.clone(), client.clone())
.await
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rattler_conda_types/src/repo_data/mod.rs
assertion_line: 477
expression: repodata
---
info:
Expand Down Expand Up @@ -182,3 +181,4 @@ packages:
version: "2.1"
packages.conda: {}
repodata_version: 2

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rattler_conda_types/src/repo_data/mod.rs
assertion_line: 448
expression: repodata
---
info:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rattler_conda_types/src/prefix_record.rs
assertion_line: 266
expression: prefix_record
---
build: pyhd8ed1ab_0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rattler_conda_types/src/prefix_record.rs
assertion_line: 266
expression: prefix_record
---
build: pyhd8ed1ab_0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rattler_conda_types/src/prefix_record.rs
assertion_line: 266
expression: prefix_record
---
arch: x86_64
Expand Down
4 changes: 4 additions & 0 deletions crates/rattler_lock/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ readme.workspace = true
chrono = "0.4.27"
fxhash = "0.2.1"
indexmap = { version = "2.0.0", features = ["serde"] }
itertools = "0.12.0"
rattler_conda_types = { version = "0.16.2", path = "../rattler_conda_types" }
rattler_digest = { version = "0.16.2", path = "../rattler_digest" }
pep508_rs = { version = "0.2.3", features = ["serde"] }
Expand All @@ -25,6 +26,9 @@ serde_yaml = "0.9.25"
serde_with = { version = "3.3.0", features = ["indexmap_2"] }
thiserror = "1.0.47"
url = { version = "2.4.1", features = ["serde"] }
purl = { version = "0.1.2", features = ["serde"] }

[dev-dependencies]
insta = { version = "1.31.0", features = ["yaml"] }
similar-asserts = "1.5.0"
rstest = "0.18.2"
Loading
Loading