Skip to content

Commit 3a5a9bd

Browse files
wolfvHofer-Julian
andauthored
Py rattler build refactor (#1966)
Co-authored-by: Julian Hofer <[email protected]>
1 parent b6a32f6 commit 3a5a9bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+11775
-1792
lines changed

crates/rattler_build_jinja/src/variable.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,36 @@ impl Variable {
6262
pub fn from_string(value: &str) -> Self {
6363
Variable(Value::from_safe_string(value.to_string()))
6464
}
65+
66+
/// Try to extract as a boolean value using serde deserialization
67+
pub fn as_bool(&self) -> Option<bool> {
68+
bool::deserialize(self.0.clone()).ok()
69+
}
70+
71+
/// Try to extract as an i64 value using serde deserialization
72+
pub fn as_i64(&self) -> Option<i64> {
73+
i64::deserialize(self.0.clone()).ok()
74+
}
75+
76+
/// Check if this variable is a number
77+
pub fn is_number(&self) -> bool {
78+
self.0.is_number()
79+
}
80+
81+
/// Try to extract as a string slice
82+
pub fn as_str(&self) -> Option<&str> {
83+
self.0.as_str()
84+
}
85+
86+
/// Check if this is a sequence/list
87+
pub fn is_sequence(&self) -> bool {
88+
self.0.len().is_some() && self.0.as_str().is_none()
89+
}
90+
91+
/// Try to iterate over the variable if it's a sequence
92+
pub fn try_iter(&self) -> Result<impl Iterator<Item = Value> + '_, minijinja::Error> {
93+
self.0.try_iter()
94+
}
6595
}
6696

6797
impl Display for Variable {

crates/rattler_build_script/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
authors.workspace = true
55
edition.workspace = true
66
license.workspace = true
7-
readme = "README.md"
7+
readme.workspace = true
88
repository.workspace = true
99
description = "Script execution and data model for rattler-build"
1010

0 commit comments

Comments
 (0)