Skip to content

Commit

Permalink
refactor: lock-file v4 (#484)
Browse files Browse the repository at this point in the history
This completely refactors the lock-file implementation in `rattler-lock`
significantly changing the format. Old lock-files can still be read by
the current implementation.

The goal of the refactor is to allow multiple environments to be stored
in the lock-file as well as significantly simplifying the format itself.

See the top-level crate documentation for more information about the
design and considerations.

@ruben-arts I also added behavior to write packages non-alphabetic but
in a more "human-readable" friendly style.

> [!NOTE]
> This significantly deviates from our previous implementation loosely
based on conda-lock.
> The code is still able to parse `conda-lock.yml` files! Its just not
able to output a compatible conda-lock file.
> Note that this has already been the case for a long time but the
differences didn't used to be so big.

> [!IMPORTANT]  
> This PR is still in previous because I want to first test out the API
in Pixi. Nonetheless, reviews are already welcome!
> 
> I also realize this is a huge change, Id be happy to walk anyone
through the code on discord!

Closes #465
  • Loading branch information
baszalmstra authored Jan 23, 2024
1 parent dbbd11b commit 0e03603
Show file tree
Hide file tree
Showing 51 changed files with 252,492 additions and 22,959 deletions.
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

0 comments on commit 0e03603

Please sign in to comment.