From 769355f3d887d54a6b5f5cbe5f7f1705baf135df Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Mon, 15 Apr 2024 20:48:18 +0200 Subject: [PATCH] hard-code true/false as booleans --- src/selectors.rs | 6 +++++- test-data/recipes/if_else/recipe.yaml | 18 ++++++++++++++++++ test-data/recipes/if_else/variant.yaml | 3 +++ test/end-to-end/test_simple.py | 19 +++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 test-data/recipes/if_else/recipe.yaml create mode 100644 test-data/recipes/if_else/variant.yaml diff --git a/src/selectors.rs b/src/selectors.rs index 23e989d2a..bc15dc66e 100644 --- a/src/selectors.rs +++ b/src/selectors.rs @@ -67,7 +67,11 @@ impl SelectorConfig { ); for (key, v) in self.variant { - context.insert(key, Value::from_safe_string(v)); + match v.to_lowercase().as_str() { + "true" => context.insert(key.clone(), Value::from(true)), + "false" => context.insert(key.clone(), Value::from(false)), + _ => context.insert(key, Value::from_safe_string(v)), + }; } context diff --git a/test-data/recipes/if_else/recipe.yaml b/test-data/recipes/if_else/recipe.yaml new file mode 100644 index 000000000..ccc616c26 --- /dev/null +++ b/test-data/recipes/if_else/recipe.yaml @@ -0,0 +1,18 @@ +package: + name: if_else_test + version: '0.1.0' + +build: + noarch: python + number: 0 + +requirements: + host: + - if: new_pydantic + then: + - pydantic >=2 + else: + - pydantic >=1,<2 + # test inline if else + - ${{ 'test' if new_pydantic }} + - ${{ 'notest' if not new_pydantic }} \ No newline at end of file diff --git a/test-data/recipes/if_else/variant.yaml b/test-data/recipes/if_else/variant.yaml new file mode 100644 index 000000000..22385d057 --- /dev/null +++ b/test-data/recipes/if_else/variant.yaml @@ -0,0 +1,3 @@ +new_pydantic: + - true + - false diff --git a/test/end-to-end/test_simple.py b/test/end-to-end/test_simple.py index 743d7605d..6ae5a2afe 100644 --- a/test/end-to-end/test_simple.py +++ b/test/end-to-end/test_simple.py @@ -712,3 +712,22 @@ def test_read_only_removal(rattler_build: RattlerBuild, recipes: Path, tmp_path: pkg = get_extracted_package(tmp_path, "read-only-build-files") assert (pkg / "info/index.json").exists() + +def test_pydantic_true_false(rattler_build: RattlerBuild, recipes: Path, tmp_path: Path): + path_to_recipe = recipes / "if_else" + args = rattler_build.build_args( + path_to_recipe, + tmp_path, + ) + + output = rattler_build(*args, "--variant-config", recipes / "if_else/variant.yaml", "--render-only") + print(output) + # parse json + render = json.loads(output) + + assert len(render) == 2 + assert render[0]["recipe"]["package"]["name"] == "if_else_test" + assert render[0]["recipe"]["requirements"]["host"] == ['pydantic >=2', 'test'] + + assert render[1]["recipe"]["package"]["name"] == "if_else_test" + assert render[1]["recipe"]["requirements"]["host"] == ['pydantic >=1,<2', 'notest'] \ No newline at end of file