torchwrench.extras.yaml package¶
- class torchwrench.extras.yaml.IgnoreTagLoader(stream)[source]¶
Bases:
SafeLoaderSafeLoader that ignores yaml tags.
1
- 2”
>>> yaml.load(dumped, Loader=IgnoreTagLoader) ... {"a": [1, 2]} >>> yaml.load(dumped, Loader=FullLoader) ... {"a": (1, 2)} >>> yaml.load(dumped, Loader=SafeLoader) # raises ConstructorError ```
-
yaml_multi_constructors =
{'!': <function IgnoreTagLoader.construct_with_tag>, 'tag:': <function IgnoreTagLoader.construct_with_tag>}¶
-
class torchwrench.extras.yaml.SplitTagLoader(stream, *, tag_key: str =
'_target_', args_key: str ='_args_')[source]¶ Bases:
SafeLoaderSafeLoader that store tags inside value.
1
- 2”
>>> yaml.load(dumped, Loader=SplitTagLoader) ... {'a': {'_target_': 'yaml.org,2002:python/tuple', '_args_': [1, 2]}} ```
-
yaml_multi_constructors =
{'!': <function SplitTagLoader.construct_with_tag>, 'tag:': <function SplitTagLoader.construct_with_tag>}¶
-
torchwrench.extras.yaml.dump_yaml(data: Iterable[Any] | Mapping[str, Any] | Namespace | DataclassInstance | NamedTupleInstance, fpath: str | Path | None =
None, *, overwrite: bool =True, to_builtins: bool =False, make_parents: bool =True, resolve: bool =False, encoding: str | None ='utf-8', sort_keys: bool =False, indent: int | None =None, width: int | None =1000, allow_unicode: bool =True, **yaml_dump_kwds) str[source]¶ Dump content to yaml format.
-
torchwrench.extras.yaml.dumps_yaml(data: Iterable[Any] | Mapping[str, Any] | Namespace | DataclassInstance | NamedTupleInstance, fpath: str | Path | None =
None, *, overwrite: bool =True, to_builtins: bool =False, make_parents: bool =True, resolve: bool =False, encoding: str | None ='utf-8', sort_keys: bool =False, indent: int | None =None, width: int | None =1000, allow_unicode: bool =True, **yaml_dump_kwds) str[source]¶ Dump content to yaml format.
- torchwrench.extras.yaml.load_yaml(file: str | Path | TextIOBase, *, Loader: type[Loader] | type[BaseLoader] | type[FullLoader] | type[SafeLoader] | type[UnsafeLoader] | type[CLoader] | type[CBaseLoader] | type[CFullLoader] | type[CSafeLoader] | type[CUnsafeLoader] = <class 'yaml.loader.SafeLoader'>, on_error: Literal['raise', 'ignore']='raise') Any[source]¶
Load YAML from filepath or opened file.
- torchwrench.extras.yaml.loads_yaml(content: str | TextIOBase, *, Loader: type[Loader] | type[BaseLoader] | type[FullLoader] | type[SafeLoader] | type[UnsafeLoader] | type[CLoader] | type[CBaseLoader] | type[CFullLoader] | type[CSafeLoader] | type[CUnsafeLoader] = <class 'yaml.loader.SafeLoader'>, on_error: Literal['raise', 'ignore']='raise') Any[source]¶
Load YAML from string and text-io stream.
- torchwrench.extras.yaml.read_yaml(file: str | Path | TextIOBase, *, Loader: type[Loader] | type[BaseLoader] | type[FullLoader] | type[SafeLoader] | type[UnsafeLoader] | type[CLoader] | type[CBaseLoader] | type[CFullLoader] | type[CSafeLoader] | type[CUnsafeLoader] = <class 'yaml.loader.SafeLoader'>, on_error: Literal['raise', 'ignore']='raise') Any[source]¶
Load YAML from filepath or opened file.
-
torchwrench.extras.yaml.save_yaml(data: Iterable[Any] | Mapping[str, Any] | Namespace | DataclassInstance | NamedTupleInstance, fpath: str | Path | None =
None, *, overwrite: bool =True, to_builtins: bool =False, make_parents: bool =True, resolve: bool =False, encoding: str | None ='utf-8', sort_keys: bool =False, indent: int | None =None, width: int | None =1000, allow_unicode: bool =True, **yaml_dump_kwds) str[source]¶ Dump content to yaml format.
Submodules¶
- torchwrench.extras.yaml.definitions module
- torchwrench.extras.yaml.yaml module
- torchwrench.extras.yaml.yaml.IgnoreTagLoader
- torchwrench.extras.yaml.yaml.SplitTagLoader
- torchwrench.extras.yaml.yaml.dump_yaml
- torchwrench.extras.yaml.yaml.dumps_yaml
- torchwrench.extras.yaml.yaml.load_yaml
- torchwrench.extras.yaml.yaml.loads_yaml
- torchwrench.extras.yaml.yaml.read_yaml
- torchwrench.extras.yaml.yaml.save_yaml