Skip to content

Commit

Permalink
load floats as strings
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Aug 9, 2024
1 parent 4fa83c8 commit a8f40bc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/rattler_build_conda_compat/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
from ruamel.yaml import YAML


# Custom constructor for loading floats as strings
def float_as_string_constructor(loader, node) -> str: # noqa: ANN001
return loader.construct_scalar(node)


def _yaml_object() -> YAML:
yaml = YAML(typ="rt")
yaml.Constructor.add_constructor("tag:yaml.org,2002:float", float_as_string_constructor)
yaml.allow_duplicate_keys = False
yaml.preserve_quotes = True
yaml.width = 320
Expand Down
10 changes: 7 additions & 3 deletions tests/__snapshots__/test_rattler_loader.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@
# ---
# name: test_load_variants
dict({
'liboost': list([
'0.10.01.001',
'0.10',
]),
'numpy': list([
1.22,
1.22,
'1.22',
'1.22',
]),
'python': list([
'3.8.* *_cpython',
Expand All @@ -62,7 +66,7 @@
'cpython',
]),
'ruby': list([
2.5,
'2.5',
]),
})
# ---
5 changes: 5 additions & 0 deletions tests/data/variants.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ numpy:
- 1.22
- 1.22

liboost:
# test trailing zeros
- 0.10.01.001
- 0.10

ruby:
- if : unix
then: 2.5

0 comments on commit a8f40bc

Please sign in to comment.