Skip to content

Commit

Permalink
hard-code true/false as booleans
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Apr 15, 2024
1 parent 27d0ee4 commit 769355f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/selectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions test-data/recipes/if_else/recipe.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
3 changes: 3 additions & 0 deletions test-data/recipes/if_else/variant.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
new_pydantic:
- true
- false
19 changes: 19 additions & 0 deletions test/end-to-end/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

0 comments on commit 769355f

Please sign in to comment.