From 8df33973a378c941ad3c64775df0574420f03610 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Tue, 17 Dec 2024 18:11:25 +0100 Subject: [PATCH 1/3] test variant rendering some more, fix __unix issue --- src/render/resolved_dependencies.rs | 15 ++++++++++++-- test-data/recipes/recipe_variant/recipe.yaml | 3 +++ .../test_recipe_variant_render.1.json | 14 +++++++++++++ .../test_recipe_variant_render.json | 20 +++++++++++++++++++ test/end-to-end/test_simple.py | 11 ++++++++++ 5 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 test/end-to-end/__snapshots__/test_simple/test_recipe_variant_render.1.json create mode 100644 test/end-to-end/__snapshots__/test_simple/test_recipe_variant_render.json diff --git a/src/render/resolved_dependencies.rs b/src/render/resolved_dependencies.rs index b801e824e..ffb934859 100644 --- a/src/render/resolved_dependencies.rs +++ b/src/render/resolved_dependencies.rs @@ -454,6 +454,7 @@ pub fn apply_variant( raw_specs: &[Dependency], build_configuration: &BuildConfiguration, compatibility_specs: &HashMap, + build_time: bool, ) -> Result, ResolveError> { let variant = &build_configuration.variant; let subpackages = &build_configuration.subpackages; @@ -464,7 +465,7 @@ pub fn apply_variant( match s { Dependency::Spec(m) => { let m = m.clone(); - if m.version.is_none() && m.build.is_none() { + if build_time && m.version.is_none() && m.build.is_none() { if let Some(name) = &m.name { if let Some(version) = variant.get(&name.into()) { // if the variant starts with an alphanumeric character, @@ -633,7 +634,12 @@ fn render_run_exports( compatibility_specs: &HashMap, ) -> Result { let render_run_exports = |run_export: &[Dependency]| -> Result, ResolveError> { - let rendered = apply_variant(run_export, &output.build_configuration, compatibility_specs)?; + let rendered = apply_variant( + run_export, + &output.build_configuration, + compatibility_specs, + false, + )?; Ok(rendered .iter() .map(|dep| dep.spec().to_string()) @@ -680,6 +686,7 @@ pub(crate) async fn resolve_dependencies( requirements.build(), &output.build_configuration, &compatibility_specs, + true, )?; let match_specs = build_env_specs @@ -737,6 +744,7 @@ pub(crate) async fn resolve_dependencies( requirements.host(), &output.build_configuration, &compatibility_specs, + true, )?; // Apply the strong run exports from the build environment to the host @@ -776,6 +784,7 @@ pub(crate) async fn resolve_dependencies( requirements.build(), &output.build_configuration, &compatibility_specs, + true, )?; match_specs.extend(specs.iter().map(|s| s.spec().clone())); } @@ -830,12 +839,14 @@ pub(crate) async fn resolve_dependencies( &requirements.run, &output.build_configuration, &compatibility_specs, + false, )?; let mut constraints = apply_variant( &requirements.run_constraints, &output.build_configuration, &compatibility_specs, + false, )?; // add in dependencies from the finalized cache diff --git a/test-data/recipes/recipe_variant/recipe.yaml b/test-data/recipes/recipe_variant/recipe.yaml index 7826bddb0..e7162b962 100644 --- a/test-data/recipes/recipe_variant/recipe.yaml +++ b/test-data/recipes/recipe_variant/recipe.yaml @@ -8,3 +8,6 @@ build: requirements: build: - python + run: + - python + - __unix diff --git a/test/end-to-end/__snapshots__/test_simple/test_recipe_variant_render.1.json b/test/end-to-end/__snapshots__/test_simple/test_recipe_variant_render.1.json new file mode 100644 index 000000000..74c5c53bd --- /dev/null +++ b/test/end-to-end/__snapshots__/test_simple/test_recipe_variant_render.1.json @@ -0,0 +1,14 @@ +[ + [ + { + "spec": "python 3.8.*", + "variant": "python" + } + ], + [ + { + "spec": "python 3.9.*", + "variant": "python" + } + ] +] diff --git a/test/end-to-end/__snapshots__/test_simple/test_recipe_variant_render.json b/test/end-to-end/__snapshots__/test_simple/test_recipe_variant_render.json new file mode 100644 index 000000000..1e4bac2b5 --- /dev/null +++ b/test/end-to-end/__snapshots__/test_simple/test_recipe_variant_render.json @@ -0,0 +1,20 @@ +[ + { + "build": [ + "python" + ], + "run": [ + "python", + "__unix" + ] + }, + { + "build": [ + "python" + ], + "run": [ + "python", + "__unix" + ] + } +] diff --git a/test/end-to-end/test_simple.py b/test/end-to-end/test_simple.py index 5dedd6d27..d2d26fde7 100644 --- a/test/end-to-end/test_simple.py +++ b/test/end-to-end/test_simple.py @@ -1160,3 +1160,14 @@ def test_python_min_render( ) assert snapshot_json == rendered[0]["recipe"]["requirements"] + + +def test_recipe_variant_render( + rattler_build: RattlerBuild, recipes: Path, tmp_path: Path, snapshot_json +): + rendered = rattler_build.render( + recipes / "recipe_variant" / "recipe.yaml", tmp_path, "--with-solve" + ) + + assert snapshot_json == [output["recipe"]["requirements"] for output in rendered] + assert snapshot_json == [output["finalized_dependencies"]["build"]["specs"] for output in rendered] \ No newline at end of file From 1e06579399e5d09bd186ffac7b0c1b20b02a7253 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Tue, 17 Dec 2024 18:16:50 +0100 Subject: [PATCH 2/3] lint --- test/end-to-end/test_simple.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/end-to-end/test_simple.py b/test/end-to-end/test_simple.py index d2d26fde7..cfae8ce81 100644 --- a/test/end-to-end/test_simple.py +++ b/test/end-to-end/test_simple.py @@ -1170,4 +1170,10 @@ def test_recipe_variant_render( ) assert snapshot_json == [output["recipe"]["requirements"] for output in rendered] - assert snapshot_json == [output["finalized_dependencies"]["build"]["specs"] for output in rendered] \ No newline at end of file + assert snapshot_json == [ + ( + output["finalized_dependencies"]["build"]["specs"], + output["finalized_dependencies"]["run"], + ) + for output in rendered + ] From 11c3ff9df74caa8be0d844d8fa8ea131cfd2f4b2 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Tue, 17 Dec 2024 18:18:56 +0100 Subject: [PATCH 3/3] improve snapshot --- .../test_recipe_variant_render.1.json | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/test/end-to-end/__snapshots__/test_simple/test_recipe_variant_render.1.json b/test/end-to-end/__snapshots__/test_simple/test_recipe_variant_render.1.json index 74c5c53bd..9f070ede1 100644 --- a/test/end-to-end/__snapshots__/test_simple/test_recipe_variant_render.1.json +++ b/test/end-to-end/__snapshots__/test_simple/test_recipe_variant_render.1.json @@ -1,14 +1,40 @@ [ [ + [ + { + "spec": "python 3.8.*", + "variant": "python" + } + ], { - "spec": "python 3.8.*", - "variant": "python" + "constraints": [], + "depends": [ + { + "source": "python" + }, + { + "source": "__unix" + } + ] } ], [ + [ + { + "spec": "python 3.9.*", + "variant": "python" + } + ], { - "spec": "python 3.9.*", - "variant": "python" + "constraints": [], + "depends": [ + { + "source": "python" + }, + { + "source": "__unix" + } + ] } ] ]