-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: move all YAML operations to ruamel (#51)
- Loading branch information
Showing
13 changed files
with
314 additions
and
2,208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import io | ||
from typing import Any | ||
|
||
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 | ||
yaml.indent(mapping=2, sequence=4, offset=2) | ||
return yaml | ||
|
||
|
||
def _dump_yaml_to_string(data: Any) -> str: # noqa: ANN401 | ||
yaml = _yaml_object() | ||
with io.StringIO() as f: | ||
yaml.dump(data, f) | ||
return f.getvalue() |
Oops, something went wrong.