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: added experimental fields to conda lock #221

Merged
merged 7 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
147 changes: 146 additions & 1 deletion crates/rattler_conda_types/src/conda_lock/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::conda_lock::{
content_hash, Channel, CondaLock, GitMeta, LockMeta, LockedDependency, Manager, PackageHashes,
TimeMeta, VersionConstraint,
};
use crate::{MatchSpec, Platform};
use crate::{MatchSpec, NoArchType, Platform};
use fxhash::{FxHashMap, FxHashSet};
use url::Url;

Expand Down Expand Up @@ -139,6 +139,25 @@ impl LockedPackages {
category: super::default_category(),
source: None,
build: Some(locked_package.build_string),
arch: locked_package.arch,
subdir: locked_package.subdir,
build_number: locked_package.build_number,
constrains: if locked_package.constrains.is_empty() {
None
} else {
Some(locked_package.constrains)
},
features: locked_package.features,
track_features: if locked_package.track_features.is_empty() {
None
} else {
Some(locked_package.track_features)
},
license: locked_package.license,
license_family: locked_package.license_family,
noarch: locked_package.noarch,
size: locked_package.size,
timestamp: locked_package.timestamp,
}
})
.collect()
Expand All @@ -161,6 +180,40 @@ pub struct LockedPackage {
pub dependency_list: FxHashMap<String, VersionConstraint>,
/// Check if package is optional
pub optional: Option<bool>,

/// Experimental: architecture field
pub arch: Option<String>,

/// Experimental: the subdir where the package can be found
pub subdir: Option<String>,

/// Experimental: conda build number of the package
pub build_number: Option<u64>,

/// Experimental: see: [Constrains](crate::repo_data::PackageRecord::constrains)
pub constrains: Vec<String>,

/// Experimental: see: [Features](crate::repo_data::PackageRecord::features)
pub features: Option<String>,

/// Experimental: see: [Track features](crate::repo_data::PackageRecord::track_features)
pub track_features: Vec<String>,

/// Experimental: the specific license of the package
pub license: Option<String>,

/// Experimental: the license family of the package
pub license_family: Option<String>,

/// Experimental: If this package is independent of architecture this field specifies in what way. See
/// [`NoArchType`] for more information.
pub noarch: NoArchType,

/// Experimental: The size of the package archive in bytes
pub size: Option<u64>,

/// Experimental: The date this entry was created.
pub timestamp: Option<chrono::DateTime<chrono::Utc>>,
}

impl LockedPackage {
Expand Down Expand Up @@ -189,6 +242,87 @@ impl LockedPackage {
self.dependency_list.extend(value);
self
}

/// Set the subdir for for the package
pub fn set_arch<S: AsRef<str>>(mut self, arch: String) -> Self {
self.subdir = Some(arch);
self
}

/// Set the subdir for for the package
pub fn set_subdir<S: AsRef<str>>(mut self, subdir: String) -> Self {
self.subdir = Some(subdir);
self
}

/// Set the subdir for for the package
pub fn set_build_number<S: AsRef<str>>(mut self, build_number: u64) -> Self {
self.build_number = Some(build_number);
self
}

/// Add the constrains for this package
pub fn add_constrain<S: AsRef<str>>(mut self, constrain: S) -> Self {
self.constrains.push(constrain.as_ref().to_string());
self
}

/// Add the constrains for this package
pub fn add_constrains<S: AsRef<str>>(
mut self,
constrain: impl IntoIterator<Item = String>,
) -> Self {
self.constrains.extend(constrain);
self
}

/// Set the features for for the package
pub fn set_features<S: AsRef<str>>(mut self, features: S) -> Self {
self.features = Some(features.as_ref().to_string());
self
}

/// Add a track feature for the package
pub fn add_track_feature<S: AsRef<str>>(mut self, track_feature: S) -> Self {
self.track_features.push(track_feature.as_ref().to_string());
self
}

/// Add multiple track features for for the package
pub fn add_track_features(mut self, value: impl IntoIterator<Item = String>) -> Self {
self.track_features.extend(value);
self
}

/// Set the licence for for the package
pub fn add_license<S: AsRef<str>>(mut self, license: S) -> Self {
self.license = Some(license.as_ref().to_string());
self
}

/// Set the license family for for the package
pub fn add_license_family<S: AsRef<str>>(mut self, license_family: S) -> Self {
self.license_family = Some(license_family.as_ref().to_string());
self
}

/// Set the noarch type for for the package
pub fn add_noarch(mut self, noarch_type: NoArchType) -> Self {
self.noarch = noarch_type;
self
}

/// Set the size of the package
pub fn set_size(mut self, size: u64) -> Self {
self.size = Some(size);
self
}

/// Set the timestamp of the package
pub fn set_timestamp(mut self, timestamp: chrono::DateTime<chrono::Utc>) -> Self {
self.timestamp = Some(timestamp);
self
}
}

#[cfg(test)]
Expand Down Expand Up @@ -218,6 +352,17 @@ mod tests {
parse_digest_from_hex::<rattler_digest::Sha256>("7c58de8c7d98b341bd9be117feec64782e704fec5c30f6e14713ebccaab9b5d8").unwrap()),
dependency_list: Default::default(),
optional: None,
arch: None,
subdir: None,
build_number: None,
constrains: vec![],
features: None,
track_features: vec![],
license: None,
license_family: None,
noarch: Default::default(),
size: None,
timestamp: None,
}))
.build().unwrap();

Expand Down
49 changes: 48 additions & 1 deletion crates/rattler_conda_types/src/conda_lock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! Most names were kept the same as in the models file. So you can refer to those exactly.
//! However, some types were added to enforce a bit more type safety.
use self::PackageHashes::{Md5, Md5Sha256, Sha256};
use crate::{utils::serde::Ordered, NamelessMatchSpec, ParsePlatformError, Platform};
use crate::{utils::serde::Ordered, NamelessMatchSpec, NoArchType, ParsePlatformError, Platform};
use fxhash::FxHashMap;
use rattler_digest::{serde::SerializableHash, Md5Hash, Sha256Hash};
use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer};
Expand Down Expand Up @@ -238,6 +238,7 @@ fn default_category() -> String {
}

/// A locked single dependency / package
#[serde_as]
#[derive(Serialize, Deserialize, Eq, PartialEq, Clone, Debug)]
pub struct LockedDependency {
/// Package name of dependency
Expand All @@ -263,6 +264,52 @@ pub struct LockedDependency {
pub source: Option<Url>,
/// Build string
pub build: Option<String>,

/// Experimental: architecture field
#[serde(skip_serializing_if = "Option::is_none")]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use:

https://docs.rs/serde_with/3.0.0/serde_with/attr.skip_serializing_none.html

To avoid having to repeat this everywhere.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

pub arch: Option<String>,

/// Experimental: the subdir where the package can be found
#[serde(skip_serializing_if = "Option::is_none")]
pub subdir: Option<String>,

/// Experimental: conda build number of the package
#[serde(skip_serializing_if = "Option::is_none")]
pub build_number: Option<u64>,

/// Experimental: see: [Constrains](crate::repo_data::PackageRecord::constrains)
#[serde(skip_serializing_if = "Option::is_none")]
pub constrains: Option<Vec<String>>,

/// Experimental: see: [Features](crate::repo_data::PackageRecord::features)
#[serde(skip_serializing_if = "Option::is_none")]
pub features: Option<String>,

/// Experimental: see: [Track features](crate::repo_data::PackageRecord::track_features)
#[serde(skip_serializing_if = "Option::is_none")]
pub track_features: Option<Vec<String>>,

/// Experimental: the specific license of the package
#[serde(skip_serializing_if = "Option::is_none")]
pub license: Option<String>,

/// Experimental: the license family of the package
#[serde(skip_serializing_if = "Option::is_none")]
pub license_family: Option<String>,

/// Experimental: If this package is independent of architecture this field specifies in what way. See
/// [`NoArchType`] for more information.
#[serde(skip_serializing_if = "NoArchType::is_none")]
pub noarch: NoArchType,

/// Experimental: The size of the package archive in bytes
#[serde(skip_serializing_if = "Option::is_none")]
pub size: Option<u64>,

/// Experimental: The date this entry was created.
#[serde_as(as = "Option<crate::utils::serde::Timestamp>")]
#[serde(skip_serializing_if = "Option::is_none")]
pub timestamp: Option<chrono::DateTime<chrono::Utc>>,
}

/// The URL for the dependency (currently only used for pip packages)
Expand Down