diff --git a/src/metadata.rs b/src/metadata.rs index 63f6cd530..c973fb0fb 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -634,7 +634,7 @@ mod test { use rattler_digest::{parse_digest_from_hex, Md5, Sha256}; use url::Url; - use crate::render::resolved_dependencies::{self, DependencyInfo}; + use crate::render::resolved_dependencies::{self, SourceDependency}; use super::{Directories, Output}; @@ -663,9 +663,10 @@ mod test { #[test] fn test_resolved_dependencies_rendering() { let resolved_dependencies = resolved_dependencies::ResolvedDependencies { - specs: vec![DependencyInfo::Raw { + specs: vec![SourceDependency { spec: MatchSpec::from_str("python 3.12.* h12332", ParseStrictness::Strict).unwrap(), - }], + } + .into()], resolved: vec![RepoDataRecord { package_record: PackageRecord { arch: Some("x86_64".into()), diff --git a/src/post_process/checks.rs b/src/post_process/checks.rs index cd4d82d82..111bcc806 100644 --- a/src/post_process/checks.rs +++ b/src/post_process/checks.rs @@ -4,15 +4,13 @@ use std::{ path::{Path, PathBuf}, }; +use crate::post_process::{package_nature::PackageNature, relink}; use crate::{ metadata::Output, post_process::{package_nature::PrefixInfo, relink::RelinkError}, }; -use crate::{ - post_process::{package_nature::PackageNature, relink}, - render::resolved_dependencies::DependencyInfo, -}; +use crate::render::resolved_dependencies::RunExportDependency; use globset::{Glob, GlobSet, GlobSetBuilder}; use rattler_conda_types::{PackageName, PrefixRecord}; @@ -121,7 +119,7 @@ fn resolved_run_dependencies( .depends .iter() .filter(|dep| { - if let DependencyInfo::RunExport { from, .. } = dep { + if let Some(RunExportDependency { from, .. }) = dep.as_run_export() { from != &String::from("build") } else { true diff --git a/src/recipe/jinja.rs b/src/recipe/jinja.rs index 668768158..16a723ac3 100644 --- a/src/recipe/jinja.rs +++ b/src/recipe/jinja.rs @@ -7,6 +7,7 @@ use minijinja::value::Object; use minijinja::{Environment, Value}; use rattler_conda_types::{PackageName, ParseStrictness, Version}; +use crate::render::pin::PinArgs; pub use crate::render::pin::{Pin, PinExpression}; pub use crate::selectors::SelectorConfig; @@ -95,9 +96,7 @@ fn jinja_pin_function( // we translate the compiler into a YAML string let mut pin_subpackage = Pin { name, - max_pin: None, - min_pin: None, - exact: false, + args: PinArgs::default(), }; let pin_expr_from_value = |pin_expr: &minijinja::value::Value| { @@ -113,16 +112,16 @@ fn jinja_pin_function( let max_pin = kwargs.get_attr("max_pin")?; if max_pin != minijinja::value::Value::UNDEFINED { let pin_expr = pin_expr_from_value(&max_pin)?; - pin_subpackage.max_pin = Some(pin_expr); + pin_subpackage.args.max_pin = Some(pin_expr); } let min = kwargs.get_attr("min_pin")?; if min != minijinja::value::Value::UNDEFINED { let pin_expr = pin_expr_from_value(&min)?; - pin_subpackage.min_pin = Some(pin_expr); + pin_subpackage.args.min_pin = Some(pin_expr); } let exact = kwargs.get_attr("exact")?; if exact != minijinja::value::Value::UNDEFINED { - pin_subpackage.exact = exact.is_true(); + pin_subpackage.args.exact = exact.is_true(); } } diff --git a/src/recipe/parser/requirements.rs b/src/recipe/parser/requirements.rs index 123fbba4b..0c6cdbe10 100644 --- a/src/recipe/parser/requirements.rs +++ b/src/recipe/parser/requirements.rs @@ -538,6 +538,7 @@ mod test { use std::str::FromStr; use crate::recipe::jinja::PinExpression; + use crate::render::pin::PinArgs; use super::*; @@ -569,27 +570,33 @@ mod test { let pin_subpackage = PinSubpackage { pin_subpackage: Pin { name: PackageName::from_str("foo").unwrap(), - max_pin: Some(PinExpression::from_str("x.x").unwrap()), - min_pin: Some(PinExpression::from_str("x.x.x.x").unwrap()), - exact: false, + args: PinArgs { + max_pin: Some(PinExpression::from_str("x.x").unwrap()), + min_pin: Some(PinExpression::from_str("x.x.x.x").unwrap()), + exact: false, + }, }, }; let pin_compatible = PinCompatible { pin_compatible: Pin { name: PackageName::from_str("bar").unwrap(), - max_pin: Some(PinExpression::from_str("x.x.x").unwrap()), - min_pin: Some(PinExpression::from_str("x.x").unwrap()), - exact: false, + args: PinArgs { + max_pin: Some(PinExpression::from_str("x.x.x").unwrap()), + min_pin: Some(PinExpression::from_str("x.x").unwrap()), + exact: false, + }, }, }; let pin_compatible_2 = PinCompatible { pin_compatible: Pin { name: PackageName::from_str("bar").unwrap(), - max_pin: None, - min_pin: Some(PinExpression::from_str("x.x").unwrap()), - exact: true, + args: PinArgs { + max_pin: None, + min_pin: Some(PinExpression::from_str("x.x").unwrap()), + exact: true, + }, }, }; diff --git a/src/recipe/parser/snapshots/rattler_build__recipe__parser__requirements__test__pin_package.snap b/src/recipe/parser/snapshots/rattler_build__recipe__parser__requirements__test__pin_package.snap index fdf3f6fb7..e09619c8c 100644 --- a/src/recipe/parser/snapshots/rattler_build__recipe__parser__requirements__test__pin_package.snap +++ b/src/recipe/parser/snapshots/rattler_build__recipe__parser__requirements__test__pin_package.snap @@ -1,5 +1,6 @@ --- source: src/recipe/parser/requirements.rs +assertion_line: 619 expression: "serde_yaml::to_string(&requirements).unwrap()" --- build: @@ -8,15 +9,12 @@ build: name: foo max_pin: x.x min_pin: x.x.x.x - exact: false - pin_compatible: name: bar max_pin: x.x.x min_pin: x.x - exact: false - pin_compatible: name: bar - max_pin: null min_pin: x.x exact: true - compiler: gcc diff --git a/src/render/pin.rs b/src/render/pin.rs index a35339490..c0b35e403 100644 --- a/src/render/pin.rs +++ b/src/render/pin.rs @@ -46,14 +46,23 @@ pub struct Pin { /// The name of the package to pin pub name: PackageName, + /// The pin arguments + #[serde(flatten)] + pub args: PinArgs, +} + +#[derive(Debug, Clone, Serialize, Deserialize, Default)] +pub struct PinArgs { /// A pin to a version, using `x.x.x...` as syntax + #[serde(skip_serializing_if = "Option::is_none")] pub max_pin: Option, /// A minimum pin to a version, using `x.x.x...` as syntax + #[serde(skip_serializing_if = "Option::is_none")] pub min_pin: Option, /// If an exact pin is given, we pin the exact version & hash - #[serde(default)] + #[serde(default, skip_serializing_if = "std::ops::Not::not")] pub exact: bool, } @@ -73,7 +82,7 @@ impl Pin { /// Apply the pin to a version and hash of a resolved package. If a max_pin, min_pin or exact pin /// are given, the pin is applied to the version accordingly. pub fn apply(&self, version: &Version, hash: &str) -> Result { - if self.exact { + if self.args.exact { return Ok(MatchSpec::from_str( &format!("{} {} {}", self.name.as_normalized(), version, hash), ParseStrictness::Strict, @@ -86,6 +95,7 @@ impl Pin { // extract same amount of digits as the pin expression (in the form of x.x.x) from version str let min_pin = self + .args .min_pin .clone() .unwrap_or_else(|| PinExpression("x.x.x.x.x.x".to_string())); @@ -104,6 +114,7 @@ impl Pin { spec.push_str(&format!(" >={}", pin)); let max_pin = self + .args .max_pin .clone() .unwrap_or_else(|| PinExpression("x".to_string())); @@ -143,13 +154,13 @@ impl Pin { } pub(crate) fn internal_repr(&self) -> String { - let max_pin_str = if let Some(max_pin) = &self.max_pin { + let max_pin_str = if let Some(max_pin) = &self.args.max_pin { format!("{}", max_pin) } else { "".to_string() }; - let min_pin_str = if let Some(min_pin) = &self.min_pin { + let min_pin_str = if let Some(min_pin) = &self.args.min_pin { format!("{}", min_pin) } else { "".to_string() @@ -160,7 +171,7 @@ impl Pin { self.name.as_normalized(), max_pin_str, min_pin_str, - self.exact + self.args.exact ) } @@ -194,9 +205,11 @@ impl Pin { .expect("could not parse back package name from internal representation"); Pin { name: package_name, - max_pin, - min_pin, - exact, + args: PinArgs { + max_pin, + min_pin, + exact, + }, } } } @@ -209,9 +222,11 @@ mod test { fn test_apply_pin() { let pin = Pin { name: PackageName::from_str("foo").unwrap(), - max_pin: Some(PinExpression("x.x.x".to_string())), - min_pin: Some(PinExpression("x.x.x".to_string())), - exact: false, + args: PinArgs { + max_pin: Some(PinExpression("x.x.x".to_string())), + min_pin: Some(PinExpression("x.x.x".to_string())), + exact: false, + }, }; let version = Version::from_str("1.2.3").unwrap(); @@ -225,9 +240,11 @@ mod test { let pin = Pin { name: PackageName::from_str("foo").unwrap(), - max_pin: Some(PinExpression("x.x.x".to_string())), - min_pin: None, - exact: false, + args: PinArgs { + max_pin: Some(PinExpression("x.x.x".to_string())), + min_pin: None, + exact: false, + }, }; let spec = pin.apply(&version, hash).unwrap(); @@ -235,9 +252,11 @@ mod test { let pin = Pin { name: PackageName::from_str("foo").unwrap(), - max_pin: None, - min_pin: Some(PinExpression("x.x.x".to_string())), - exact: false, + args: PinArgs { + max_pin: None, + min_pin: Some(PinExpression("x.x.x".to_string())), + exact: false, + }, }; let spec = pin.apply(&version, hash).unwrap(); @@ -248,9 +267,11 @@ mod test { fn test_apply_exact_pin() { let pin = Pin { name: PackageName::from_str("foo").unwrap(), - max_pin: Some(PinExpression("x.x.x".to_string())), - min_pin: Some(PinExpression("x.x.x".to_string())), - exact: true, + args: PinArgs { + max_pin: Some(PinExpression("x.x.x".to_string())), + min_pin: Some(PinExpression("x.x.x".to_string())), + exact: true, + }, }; let version = Version::from_str("1.2.3").unwrap(); diff --git a/src/render/resolved_dependencies.rs b/src/render/resolved_dependencies.rs index f8801480f..9d833ee80 100644 --- a/src/render/resolved_dependencies.rs +++ b/src/render/resolved_dependencies.rs @@ -23,95 +23,237 @@ use thiserror::Error; use super::{pin::PinError, solver::create_environment}; use crate::recipe::parser::Dependency; +use crate::render::pin::PinArgs; use crate::render::solver::install_packages; use serde_with::{serde_as, DisplayFromStr}; /// A enum to keep track of where a given Dependency comes from #[serde_as] #[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(tag = "source", rename_all = "snake_case")] +#[serde(untagged)] pub enum DependencyInfo { /// The dependency is a direct dependency of the package, with a variant applied /// from the variant config - Variant { - #[serde_as(as = "DisplayFromStr")] - spec: MatchSpec, - variant: String, - }, + Variant(VariantDependency), + /// This is a special compiler dependency (e.g. `{{ compiler('c') }}` - Compiler { - #[serde_as(as = "DisplayFromStr")] - spec: MatchSpec, - }, + Compiler(CompilerDependency), + /// This is a special pin dependency (e.g. `{{ pin_subpackage('foo', exact=True) }}` - PinSubpackage { - #[serde_as(as = "DisplayFromStr")] - spec: MatchSpec, - }, + PinSubpackage(PinSubpackageDependency), + /// This is a special run_exports dependency (e.g. `{{ pin_compatible('foo') }}` - PinCompatible { - #[serde_as(as = "DisplayFromStr")] - spec: MatchSpec, - }, + PinCompatible(PinCompatibleDependency), + /// This is a special run_exports dependency from another package - RunExport { - #[serde_as(as = "DisplayFromStr")] - spec: MatchSpec, - from: String, - source_package: String, - }, + RunExport(RunExportDependency), + /// This is a regular dependency of the package without any modifications - Raw { - #[serde_as(as = "DisplayFromStr")] - spec: MatchSpec, - }, + Source(SourceDependency), +} + +/// The dependency is a direct dependency of the package, with a variant applied +/// from the variant config +#[serde_as] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct VariantDependency { + /// The key in the config file. + pub variant: String, + + /// The spec from the config file + #[serde_as(as = "DisplayFromStr")] + pub spec: MatchSpec, +} + +impl From for DependencyInfo { + fn from(value: VariantDependency) -> Self { + DependencyInfo::Variant(value) + } +} + +/// This is a special compiler dependency (e.g. `{{ compiler('c') }}` +#[serde_as] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct CompilerDependency { + /// The language in the `{{ compiler('c') }}` call. + #[serde(rename = "compiler")] + pub language: String, + + /// The resolved compiler spec + #[serde_as(as = "DisplayFromStr")] + pub spec: MatchSpec, +} + +impl From for DependencyInfo { + fn from(value: CompilerDependency) -> Self { + DependencyInfo::Compiler(value) + } +} + +/// This is a special pin dependency (e.g. `{{ pin_subpackage('foo', exact=True) }}` +#[serde_as] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct PinSubpackageDependency { + #[serde(rename = "pin_subpackage")] + pub name: String, + + #[serde(flatten)] + pub args: PinArgs, + + #[serde_as(as = "DisplayFromStr")] + pub spec: MatchSpec, +} + +impl From for DependencyInfo { + fn from(value: PinSubpackageDependency) -> Self { + DependencyInfo::PinSubpackage(value) + } +} + +/// This is a special run_exports dependency (e.g. `{{ pin_compatible('foo') }}` +#[serde_as] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct PinCompatibleDependency { + #[serde(rename = "pin_compatible")] + pub name: String, + + #[serde(flatten)] + pub args: PinArgs, + + #[serde_as(as = "DisplayFromStr")] + pub spec: MatchSpec, +} + +impl From for DependencyInfo { + fn from(value: PinCompatibleDependency) -> Self { + DependencyInfo::PinCompatible(value) + } +} + +/// This is a special run_exports dependency from another package +#[serde_as] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct RunExportDependency { + #[serde_as(as = "DisplayFromStr")] + pub spec: MatchSpec, + pub from: String, + #[serde(rename = "run_export")] + pub source_package: String, +} + +impl From for DependencyInfo { + fn from(value: RunExportDependency) -> Self { + DependencyInfo::RunExport(value) + } +} + +/// This is a regular dependency of the package without any modifications +#[serde_as] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct SourceDependency { + #[serde(rename = "source")] + #[serde_as(as = "DisplayFromStr")] + pub spec: MatchSpec, +} + +impl From for DependencyInfo { + fn from(value: SourceDependency) -> Self { + DependencyInfo::Source(value) + } } impl DependencyInfo { /// Get the matchspec from a dependency info pub fn spec(&self) -> &MatchSpec { match self { - DependencyInfo::Variant { spec, .. } => spec, - DependencyInfo::Compiler { spec } => spec, - DependencyInfo::PinSubpackage { spec } => spec, - DependencyInfo::PinCompatible { spec } => spec, - DependencyInfo::RunExport { spec, .. } => spec, - DependencyInfo::Raw { spec } => spec, + DependencyInfo::Variant(spec) => &spec.spec, + DependencyInfo::Compiler(spec) => &spec.spec, + DependencyInfo::PinSubpackage(spec) => &spec.spec, + DependencyInfo::PinCompatible(spec) => &spec.spec, + DependencyInfo::RunExport(spec) => &spec.spec, + DependencyInfo::Source(spec) => &spec.spec, } } pub fn render(&self, long: bool) -> String { if !long { match self { - DependencyInfo::Variant { spec, .. } => format!("{} (V)", spec), - DependencyInfo::Compiler { spec } => format!("{} (C)", spec), - DependencyInfo::PinSubpackage { spec } => format!("{} (PS)", spec), - DependencyInfo::PinCompatible { spec } => format!("{} (PC)", spec), - DependencyInfo::RunExport { - spec, - from, - source_package, - } => format!("{} (RE of [{}: {}])", spec, from, source_package), - DependencyInfo::Raw { spec } => spec.to_string(), + DependencyInfo::Variant(spec) => format!("{} (V)", &spec.spec), + DependencyInfo::Compiler(spec) => format!("{} (C)", &spec.spec), + DependencyInfo::PinSubpackage(spec) => format!("{} (PS)", &spec.spec), + DependencyInfo::PinCompatible(spec) => format!("{} (PC)", &spec.spec), + DependencyInfo::RunExport(spec) => format!( + "{} (RE of [{}: {}])", + &spec.spec, &spec.from, &spec.source_package + ), + DependencyInfo::Source(spec) => spec.spec.to_string(), } } else { match self { - DependencyInfo::Variant { spec, .. } => format!("{} (from variant config)", spec), - DependencyInfo::Compiler { spec } => format!("{} (from compiler)", spec), - DependencyInfo::PinSubpackage { spec } => format!("{} (from pin subpackage)", spec), - DependencyInfo::PinCompatible { spec } => format!("{} (from pin compatible)", spec), - DependencyInfo::RunExport { - spec, - from, - source_package, - } => format!( + DependencyInfo::Variant(spec) => format!("{} (from variant config)", &spec.spec), + DependencyInfo::Compiler(spec) => format!("{} (from compiler)", &spec.spec), + DependencyInfo::PinSubpackage(spec) => { + format!("{} (from pin subpackage)", &spec.spec) + } + DependencyInfo::PinCompatible(spec) => { + format!("{} (from pin compatible)", &spec.spec) + } + DependencyInfo::RunExport(spec) => format!( "{} (run export by {} in {} env)", - spec, source_package, from + &spec.spec, &spec.from, &spec.source_package ), - DependencyInfo::Raw { spec } => spec.to_string(), + DependencyInfo::Source(spec) => spec.spec.to_string(), } } } + + pub fn as_variant(&self) -> Option<&VariantDependency> { + match self { + DependencyInfo::Variant(spec) => Some(spec), + _ => None, + } + } + + pub fn as_source(&self) -> Option<&SourceDependency> { + match self { + DependencyInfo::Source(spec) => Some(spec), + _ => None, + } + } + + pub fn as_run_export(&self) -> Option<&RunExportDependency> { + match self { + DependencyInfo::RunExport(spec) => Some(spec), + _ => None, + } + } + + pub fn as_pin_subpackage(&self) -> Option<&PinSubpackageDependency> { + match self { + DependencyInfo::PinSubpackage(spec) => Some(spec), + _ => None, + } + } + + pub fn as_pin_compatible(&self) -> Option<&PinCompatibleDependency> { + match self { + DependencyInfo::PinCompatible(spec) => Some(spec), + _ => None, + } + } + + pub fn as_compiler(&self) -> Option<&CompilerDependency> { + match self { + DependencyInfo::Compiler(spec) => Some(spec), + _ => None, + } + } } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -334,19 +476,20 @@ pub fn apply_variant( let mut splitter = spec.split_whitespace(); let version_spec = splitter.next().map(|v| VersionSpec::from_str(v, ParseStrictness::Strict)).transpose()?; let build_spec = splitter.next().map(StringMatcher::from_str).transpose()?; + let variant = name.as_normalized().to_string(); let final_spec = MatchSpec { version: version_spec, build: build_spec, ..m }; - return Ok(DependencyInfo::Variant { + return Ok(VariantDependency { spec: final_spec, - variant: version.clone(), - }); + variant, + }.into()); } } } - Ok(DependencyInfo::Raw { spec: m }) + Ok(SourceDependency { spec: m }.into()) } Dependency::PinSubpackage(pin) => { let name = &pin.pin_value().name; @@ -357,7 +500,7 @@ pub fn apply_variant( &Version::from_str(&subpackage.version)?, &subpackage.build_string, )?; - Ok(DependencyInfo::PinSubpackage { spec: pinned }) + Ok(PinSubpackageDependency { spec: pinned, name: name.as_normalized().to_string(), args: pin.pin_value().args.clone() }.into()) } Dependency::PinCompatible(pin) => { let name = &pin.pin_value().name; @@ -370,7 +513,7 @@ pub fn apply_variant( &pin_package.version, &pin_package.build, )?; - Ok(DependencyInfo::PinCompatible { spec: pinned }) + Ok(PinCompatibleDependency { spec: pinned, name: name.as_normalized().to_string(), args: pin.pin_value().args.clone() }.into()) } Dependency::Compiler(compiler) => { if target_platform == &Platform::NoArch { @@ -433,9 +576,10 @@ pub fn apply_variant( format!("{}_{}", compiler_name, target_platform) }; - Ok(DependencyInfo::Compiler { + Ok(CompilerDependency { + language: compiler_name, spec: MatchSpec::from_str(&final_compiler, ParseStrictness::Strict)?, - }) + }.into()) } } }) @@ -601,12 +745,12 @@ async fn resolve_dependencies( continue; } - let dep = DependencyInfo::RunExport { + let dep = RunExportDependency { spec, from: env.to_string(), source_package: name.as_normalized().to_string(), }; - cloned.push(dep); + cloned.push(dep.into()); } Ok(cloned) }; @@ -812,23 +956,41 @@ mod tests { #[test] fn test_dependency_info_render() { - let dep_info = vec![ - DependencyInfo::Raw { + let dep_info: Vec = vec![ + SourceDependency { spec: MatchSpec::from_str("xyz", ParseStrictness::Strict).unwrap(), - }, - DependencyInfo::Variant { + } + .into(), + VariantDependency { spec: MatchSpec::from_str("foo", ParseStrictness::Strict).unwrap(), variant: "bar".to_string(), - }, - DependencyInfo::Compiler { + } + .into(), + CompilerDependency { + language: "c".to_string(), spec: MatchSpec::from_str("foo", ParseStrictness::Strict).unwrap(), - }, - DependencyInfo::PinSubpackage { + } + .into(), + PinSubpackageDependency { + name: "baz".to_string(), spec: MatchSpec::from_str("baz", ParseStrictness::Strict).unwrap(), - }, - DependencyInfo::PinCompatible { + args: PinArgs { + max_pin: Some("x.x".parse().unwrap()), + min_pin: Some("x.x.x".parse().unwrap()), + exact: true, + }, + } + .into(), + PinCompatibleDependency { + name: "bat".to_string(), spec: MatchSpec::from_str("bat", ParseStrictness::Strict).unwrap(), - }, + args: PinArgs { + max_pin: Some("x.x".parse().unwrap()), + min_pin: Some("x.x.x".parse().unwrap()), + exact: true, + }, + } + .into(), ]; let yaml_str = serde_yaml::to_string(&dep_info).unwrap(); insta::assert_snapshot!(yaml_str); @@ -836,10 +998,10 @@ mod tests { // test deserialize let dep_info: Vec = serde_yaml::from_str(&yaml_str).unwrap(); assert_eq!(dep_info.len(), 5); - assert!(matches!(dep_info[0], DependencyInfo::Raw { .. })); - assert!(matches!(dep_info[1], DependencyInfo::Variant { .. })); - assert!(matches!(dep_info[2], DependencyInfo::Compiler { .. })); - assert!(matches!(dep_info[3], DependencyInfo::PinSubpackage { .. })); - assert!(matches!(dep_info[4], DependencyInfo::PinCompatible { .. })); + assert!(matches!(dep_info[0], DependencyInfo::Source(_))); + assert!(matches!(dep_info[1], DependencyInfo::Variant(_))); + assert!(matches!(dep_info[2], DependencyInfo::Compiler(_))); + assert!(matches!(dep_info[3], DependencyInfo::PinSubpackage(_))); + assert!(matches!(dep_info[4], DependencyInfo::PinCompatible(_))); } } diff --git a/src/render/snapshots/rattler_build__render__resolved_dependencies__tests__dependency_info_render.snap b/src/render/snapshots/rattler_build__render__resolved_dependencies__tests__dependency_info_render.snap index 1dc99117c..9b765c4c3 100644 --- a/src/render/snapshots/rattler_build__render__resolved_dependencies__tests__dependency_info_render.snap +++ b/src/render/snapshots/rattler_build__render__resolved_dependencies__tests__dependency_info_render.snap @@ -1,16 +1,20 @@ --- source: src/render/resolved_dependencies.rs +assertion_line: 994 expression: yaml_str --- -- source: raw - spec: xyz -- source: variant +- source: xyz +- variant: bar spec: foo - variant: bar -- source: compiler +- compiler: c spec: foo -- source: pin_subpackage +- pin_subpackage: baz + max_pin: x.x + min_pin: x.x.x + exact: true spec: baz -- source: pin_compatible +- pin_compatible: bat + max_pin: x.x + min_pin: x.x.x + exact: true spec: bat - diff --git a/src/snapshots/rattler_build__metadata__test__curl_recipe.yaml.snap b/src/snapshots/rattler_build__metadata__test__curl_recipe.yaml.snap index ff070cf35..1ad1c502a 100644 --- a/src/snapshots/rattler_build__metadata__test__curl_recipe.yaml.snap +++ b/src/snapshots/rattler_build__metadata__test__curl_recipe.yaml.snap @@ -1,6 +1,6 @@ --- source: src/metadata.rs -assertion_line: 729 +assertion_line: 730 expression: output --- recipe: @@ -58,16 +58,12 @@ build_configuration: finalized_dependencies: build: specs: - - source: compiler + - compiler: c spec: clang_osx-arm64 - - source: raw - spec: make - - source: raw - spec: perl - - source: raw - spec: pkg-config - - source: raw - spec: libtool + - source: make + - source: perl + - source: pkg-config + - source: libtool resolved: - build: he57ea6c_1 build_number: 1 diff --git a/src/snapshots/rattler_build__metadata__test__resolved_dependencies_rendering.snap b/src/snapshots/rattler_build__metadata__test__resolved_dependencies_rendering.snap index d2ef13576..5411dea5e 100644 --- a/src/snapshots/rattler_build__metadata__test__resolved_dependencies_rendering.snap +++ b/src/snapshots/rattler_build__metadata__test__resolved_dependencies_rendering.snap @@ -1,10 +1,10 @@ --- source: src/metadata.rs +assertion_line: 703 expression: resolved_dependencies --- specs: - - source: raw - spec: python 3.12.* h12332 + - source: python 3.12.* h12332 resolved: - arch: x86_64 build: h123 @@ -23,4 +23,3 @@ resolved: url: "https://test.com/test/linux-64/test-1.2.3-h123.tar.bz2" channel: test run_exports: {} - diff --git a/src/snapshots/rattler_build__metadata__test__rich_recipe.yaml.snap b/src/snapshots/rattler_build__metadata__test__rich_recipe.yaml.snap index 63b2058dc..f8f56ed1b 100644 --- a/src/snapshots/rattler_build__metadata__test__rich_recipe.yaml.snap +++ b/src/snapshots/rattler_build__metadata__test__rich_recipe.yaml.snap @@ -1,6 +1,6 @@ --- source: src/metadata.rs -assertion_line: 729 +assertion_line: 730 expression: output --- recipe: @@ -76,12 +76,9 @@ finalized_dependencies: build: ~ host: specs: - - source: raw - spec: pip - - source: raw - spec: poetry-core >=1.0.0 - - source: raw - spec: python ==3.10 + - source: pip + - source: poetry-core >=1.0.0 + - source: python ==3.10 resolved: - build: h43b31ca_3_cpython build_number: 3 @@ -375,18 +372,13 @@ finalized_dependencies: - python run: depends: - - source: raw - spec: markdown-it-py >=2.2.0 - - source: raw - spec: "pygments >=2.13.0,<3.0.0" - - source: raw - spec: python ==3.10 - - source: raw - spec: "typing_extensions >=4.0.0,<5.0.0" - - source: run_export - spec: python + - source: markdown-it-py >=2.2.0 + - source: "pygments >=2.13.0,<3.0.0" + - source: python ==3.10 + - source: "typing_extensions >=4.0.0,<5.0.0" + - spec: python from: host - source_package: python + run_export: python constrains: [] run_exports: ~ finalized_sources: ~ diff --git a/src/utils.rs b/src/utils.rs index dc1695017..89b55abcc 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -185,6 +185,7 @@ pub fn remove_dir_all_force(path: &Path) -> std::io::Result<()> { #[cfg(unix)] permissions.set_mode(permissions.mode() | 0o200); #[cfg(windows)] + #[allow(clippy::permissions_set_readonly_false)] permissions.set_readonly(false); fs::set_permissions(file_path, permissions)?; } diff --git a/src/variant_config.rs b/src/variant_config.rs index 52d472051..9577ab169 100644 --- a/src/variant_config.rs +++ b/src/variant_config.rs @@ -631,14 +631,14 @@ impl VariantConfig { Dependency::PinSubpackage(pin_sub) => { let pin = pin_sub.pin_value(); let val = pin.name.as_normalized().to_owned(); - if pin.exact { + if pin.args.exact { exact_pins.insert(val); } } Dependency::PinCompatible(pin_compatible) => { let pin = pin_compatible.pin_value(); let val = pin.name.as_normalized().to_owned(); - if pin.exact { + if pin.args.exact { exact_pins.insert(val); } } @@ -673,7 +673,7 @@ impl VariantConfig { .try_for_each(|dep| -> Result<(), VariantError> { if let Dependency::PinSubpackage(pin_sub) = dep { let pin = pin_sub.pin_value(); - if pin.exact { + if pin.args.exact { let val = pin.name.as_normalized(); if val != *name { // if other_recipes does not contain val, throw an error diff --git a/test-data/rendered_recipes/curl_recipe.yaml b/test-data/rendered_recipes/curl_recipe.yaml index ca1d730c7..f4ab6c5ad 100644 --- a/test-data/rendered_recipes/curl_recipe.yaml +++ b/test-data/rendered_recipes/curl_recipe.yaml @@ -55,16 +55,12 @@ build_configuration: finalized_dependencies: build: specs: - - source: compiler + - compiler: c spec: clang_osx-arm64 - - source: raw - spec: make - - source: raw - spec: perl - - source: raw - spec: pkg-config - - source: raw - spec: libtool + - source: make + - source: perl + - source: pkg-config + - source: libtool resolved: - build: he57ea6c_1 build_number: 1 diff --git a/test-data/rendered_recipes/dependencies.yaml b/test-data/rendered_recipes/dependencies.yaml index 9406c1904..063f4556a 100644 --- a/test-data/rendered_recipes/dependencies.yaml +++ b/test-data/rendered_recipes/dependencies.yaml @@ -1,10 +1,7 @@ specs: - - source: raw - spec: pip - - source: raw - spec: poetry-core >=1.0.0 - - source: raw - spec: python ==3.10 + - source: pip + - source: poetry-core >=1.0.0 + - source: python ==3.10 resolved: - build: h43b31ca_3_cpython build_number: 3 diff --git a/test-data/rendered_recipes/rich_recipe.yaml b/test-data/rendered_recipes/rich_recipe.yaml index 269064ab4..9815ca865 100644 --- a/test-data/rendered_recipes/rich_recipe.yaml +++ b/test-data/rendered_recipes/rich_recipe.yaml @@ -76,12 +76,9 @@ finalized_dependencies: build: null host: specs: - - source: raw - spec: pip - - source: raw - spec: poetry-core >=1.0.0 - - source: raw - spec: python ==3.10 + - source: pip + - source: poetry-core >=1.0.0 + - source: python ==3.10 resolved: - build: h43b31ca_3_cpython build_number: 3 @@ -375,18 +372,13 @@ finalized_dependencies: - python run: depends: - - source: raw - spec: markdown-it-py >=2.2.0 - - source: raw - spec: pygments >=2.13.0,<3.0.0 - - source: raw - spec: python ==3.10 - - source: raw - spec: typing_extensions >=4.0.0,<5.0.0 - - source: run_export + - source: markdown-it-py >=2.2.0 + - source: pygments >=2.13.0,<3.0.0 + - source: python ==3.10 + - source: typing_extensions >=4.0.0,<5.0.0 + - run_export: python spec: python from: host - source_package: python constrains: [] run_exports: null system_tools: diff --git a/test/end-to-end/test_simple.py b/test/end-to-end/test_simple.py index 3a09a7183..449ca36d6 100644 --- a/test/end-to-end/test_simple.py +++ b/test/end-to-end/test_simple.py @@ -736,8 +736,6 @@ def test_noarch_variants(rattler_build: RattlerBuild, recipes: Path, tmp_path: P pin = { "pin_subpackage": { "name": "rattler-build-demo", - "max_pin": None, - "min_pin": None, "exact": True, } } @@ -762,8 +760,6 @@ def test_noarch_variants(rattler_build: RattlerBuild, recipes: Path, tmp_path: P pin = { "pin_subpackage": { "name": "rattler-build-demo", - "max_pin": None, - "min_pin": None, "exact": True, } } @@ -834,9 +830,10 @@ def test_double_license(rattler_build: RattlerBuild, recipes: Path, tmp_path: Pa tmp_path, ) # make sure that two license files in $SRC_DIR and $RECIPE_DIR raise an exception - with pytest.raises(Exception): + with pytest.raises(CalledProcessError): rattler_build(*args) + @pytest.mark.skipif( os.name == "nt", reason="recipe does not support execution on windows" )