-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
285 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from collections import OrderedDict | ||
|
||
from dvclive.error import DvcLiveError | ||
|
||
|
||
class YAMLError(DvcLiveError): | ||
pass | ||
|
||
|
||
class YAMLFileCorruptedError(YAMLError): | ||
def __init__(self, path): | ||
super().__init__(path, "YAML file structure is corrupted") | ||
|
||
|
||
def load_yaml(path, typ="safe"): | ||
from ruamel.yaml import YAML | ||
from ruamel.yaml import YAMLError as _YAMLError | ||
|
||
yaml = YAML(typ=typ) | ||
with open(path, encoding="utf-8") as fd: | ||
try: | ||
return yaml.load(fd.read()) | ||
except _YAMLError: | ||
raise YAMLFileCorruptedError(path) | ||
|
||
|
||
def _get_yaml(): | ||
from ruamel.yaml import YAML | ||
|
||
yaml = YAML() | ||
yaml.default_flow_style = False | ||
|
||
# tell Dumper to represent OrderedDict as normal dict | ||
yaml_repr_cls = yaml.Representer | ||
yaml_repr_cls.add_representer(OrderedDict, yaml_repr_cls.represent_dict) | ||
return yaml | ||
|
||
|
||
def dump_yaml(path, data): | ||
yaml = _get_yaml() | ||
with open(path, "w", encoding="utf-8") as fd: | ||
yaml.dump(data, fd) |
Oops, something went wrong.