-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap ruamel yaml library import due to type support
Signed-off-by: Wei-Chun, Chang <[email protected]>
- Loading branch information
1 parent
02b474b
commit 35eee78
Showing
9 changed files
with
140 additions
and
69 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 |
---|---|---|
@@ -1,60 +0,0 @@ | ||
from pathlib import Path | ||
from typing import Any, Callable, Optional, Union | ||
|
||
from ruamel import yaml | ||
from ruamel.yaml import StreamTextType, StreamType, VersionType | ||
from ruamel.yaml import CommentedMap as _cm, CommentedSeq as _cs | ||
|
||
_yaml = yaml.YAML() | ||
|
||
CommentedMap = _cm | ||
CommentedSeq = _cs | ||
YAMLError = yaml.YAMLError | ||
|
||
|
||
def load(stream: Union[Path, StreamTextType]) -> Any: | ||
return _yaml.load(stream) | ||
|
||
|
||
def allow_duplicate_keys_loader() -> Callable: | ||
yml = yaml.YAML() | ||
yml.allow_duplicate_keys = True | ||
return yml.load | ||
|
||
|
||
def safe_load(stream: StreamTextType, version: Optional[VersionType] = None) -> Any: | ||
return yaml.safe_load(stream, version) | ||
|
||
|
||
def dump( | ||
data: Union[Path, StreamType], stream: Any = None, *, transform: Any = None | ||
) -> Any: | ||
return _yaml.dump(data, stream, transform=transform) | ||
|
||
|
||
def safe_load_yaml(file_path): | ||
try: | ||
with open(file_path, 'r') as f: | ||
payload = safe_load(f) | ||
except yaml.YAMLError as e: | ||
print(e) | ||
return None | ||
except FileNotFoundError: | ||
return None | ||
return payload | ||
|
||
|
||
def round_trip_load_yaml(file_path): | ||
with open(file_path, 'r') as f: | ||
try: | ||
payload = load(f) | ||
except yaml.YAMLError as e: | ||
print(e) | ||
return None | ||
return payload | ||
|
||
|
||
def round_trip_dump( | ||
data: Any, | ||
stream: Optional[StreamType] = None): | ||
return yaml.round_trip_dump(data, stream) | ||
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,54 @@ | ||
from typing import Any, Callable | ||
|
||
from ruamel import yaml | ||
from ruamel.yaml import CommentedMap as _cm, CommentedSeq as _cs | ||
|
||
_yaml = yaml.YAML() | ||
|
||
CommentedMap = _cm | ||
CommentedSeq = _cs | ||
YAMLError = yaml.YAMLError | ||
|
||
|
||
def load(stream) -> Any: | ||
return _yaml.load(stream) | ||
|
||
|
||
def allow_duplicate_keys_loader() -> Callable: | ||
yml = yaml.YAML() | ||
yml.allow_duplicate_keys = True | ||
return yml.load | ||
|
||
|
||
def safe_load(stream, version=None) -> Any: | ||
return yaml.safe_load(stream, version) | ||
|
||
|
||
def dump(data, stream=None, *, transform=None) -> Any: | ||
return _yaml.dump(data, stream, transform=transform) | ||
|
||
|
||
def safe_load_yaml(file_path): | ||
try: | ||
with open(file_path, 'r') as f: | ||
payload = safe_load(f) | ||
except yaml.YAMLError as e: | ||
print(e) | ||
return None | ||
except FileNotFoundError: | ||
return None | ||
return payload | ||
|
||
|
||
def round_trip_load_yaml(file_path): | ||
with open(file_path, 'r') as f: | ||
try: | ||
payload = load(f) | ||
except yaml.YAMLError as e: | ||
print(e) | ||
return None | ||
return payload | ||
|
||
|
||
def round_trip_dump(data, stream=None): | ||
return yaml.round_trip_dump(data, stream) | ||
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,60 @@ | ||
from pathlib import Path | ||
from typing import Any, Callable, Optional, Union | ||
|
||
from ruamel import yaml | ||
from ruamel.yaml import StreamTextType, StreamType, VersionType | ||
from ruamel.yaml import CommentedMap as _cm, CommentedSeq as _cs | ||
|
||
_yaml = yaml.YAML() | ||
|
||
CommentedMap = _cm | ||
CommentedSeq = _cs | ||
YAMLError = yaml.YAMLError | ||
|
||
|
||
def load(stream: Union[Path, StreamTextType]) -> Any: | ||
return _yaml.load(stream) | ||
|
||
|
||
def allow_duplicate_keys_loader() -> Callable: | ||
yml = yaml.YAML() | ||
yml.allow_duplicate_keys = True | ||
return yml.load | ||
|
||
|
||
def safe_load(stream: StreamTextType, version: Optional[VersionType] = None) -> Any: | ||
return yaml.safe_load(stream, version) | ||
|
||
|
||
def dump( | ||
data: Union[Path, StreamType], stream: Any = None, *, transform: Any = None | ||
) -> Any: | ||
return _yaml.dump(data, stream, transform=transform) | ||
|
||
|
||
def safe_load_yaml(file_path): | ||
try: | ||
with open(file_path, 'r') as f: | ||
payload = safe_load(f) | ||
except yaml.YAMLError as e: | ||
print(e) | ||
return None | ||
except FileNotFoundError: | ||
return None | ||
return payload | ||
|
||
|
||
def round_trip_load_yaml(file_path): | ||
with open(file_path, 'r') as f: | ||
try: | ||
payload = load(f) | ||
except yaml.YAMLError as e: | ||
print(e) | ||
return None | ||
return payload | ||
|
||
|
||
def round_trip_dump( | ||
data: Any, | ||
stream: Optional[StreamType] = None): | ||
return yaml.round_trip_dump(data, stream) | ||