Skip to content

Commit

Permalink
feat: add a check function for empty lockfiles (#1023)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruben-arts authored Jan 9, 2025
1 parent 899ab59 commit fe4f365
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
20 changes: 20 additions & 0 deletions crates/rattler_lock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ impl LockFile {
pub fn version(&self) -> FileFormatVersion {
self.inner.version
}

/// Check if there are any packages in the lockfile
pub fn is_empty(&self) -> bool {
self.inner.conda_packages.is_empty() && self.inner.pypi_packages.is_empty()
}
}

/// Information about a specific environment in the lock-file.
Expand Down Expand Up @@ -641,4 +646,19 @@ mod test {
.unwrap()
.has_pypi_packages(Platform::OsxArm64));
}

#[test]
fn test_is_empty() {
let path = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../../test-data/conda-lock")
.join("v6/empty-lock.yml");
let conda_lock = LockFile::from_path(&path).unwrap();
assert!(conda_lock.is_empty());

let path = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../../test-data/conda-lock")
.join("v6/python-from-conda-only-lock.yml");
let conda_lock = LockFile::from_path(&path).unwrap();
assert!(!conda_lock.is_empty());
}
}
7 changes: 7 additions & 0 deletions test-data/conda-lock/v6/empty-lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 6
environments:
default:
channels:
- url: https://prefix.dev/conda-forge/
packages: {}
packages: []

0 comments on commit fe4f365

Please sign in to comment.