Browse Source

drop yamily.yaml.read

Fabian Peter Hammerle 4 years ago
parent
commit
6ff147315f
2 changed files with 6 additions and 25 deletions
  1. 2 1
      yamily/_cli.py
  2. 4 24
      yamily/yaml.py

+ 2 - 1
yamily/_cli.py

@@ -15,7 +15,8 @@ def _read(path: pathlib.Path) -> typing.Iterator[yamily.Person]:
             for person in _read(file_path):
                 yield person
     else:
-        yield yamily.yaml.read(path)
+        with path.open("r") as yaml_file:
+            yield yaml.load(yaml_file, Loader=yamily.yaml.Loader)
 
 
 def _list() -> None:

+ 4 - 24
yamily/yaml.py

@@ -1,13 +1,11 @@
 import datetime  # pylint: disable=unused-import; doctest
-import pathlib
-import typing
 
 import yaml
 
 from yamily import Person
 
 
-class _Loader(yaml.SafeLoader):
+class Loader(yaml.SafeLoader):
 
     # pylint: disable=too-many-ancestors
 
@@ -20,7 +18,7 @@ class _Loader(yaml.SafeLoader):
     ... mother: mum
     ... father: dad
     ... '''
-    >>> alice = yaml.load(alice_yaml, Loader=_Loader)
+    >>> alice = yaml.load(alice_yaml, Loader=Loader)
     >>> alice
     Person(alice, Alice Test, *1976-02-01)
     >>> alice.mother
@@ -39,7 +37,7 @@ class _Loader(yaml.SafeLoader):
     ...   identifier: dad
     ...   name: Dad Test
     ... '''
-    >>> alice = yaml.load(alice_yaml, Loader=_Loader)
+    >>> alice = yaml.load(alice_yaml, Loader=Loader)
     >>> alice
     Person(alice, Alice Test, *1976-02-01)
     >>> alice.mother
@@ -53,7 +51,7 @@ class _Loader(yaml.SafeLoader):
         self.add_constructor("!person", self._construct_person)
 
     @staticmethod
-    def _construct_person(loader: "_Loader", node: yaml.nodes.MappingNode) -> Person:
+    def _construct_person(loader: "Loader", node: yaml.nodes.MappingNode) -> Person:
         (person_attrs,) = loader.construct_yaml_map(node)
         person = Person(person_attrs["identifier"])
         if "name" in person_attrs:
@@ -117,21 +115,3 @@ class Dumper(yaml.SafeDumper):
         if person.father is not None:
             person_attrs["father"] = person.father
         return dumper.represent_mapping("!person", person_attrs)
-
-
-def read(yaml_path: typing.Union[str, pathlib.Path]) -> Person:
-    """
-    >>> read('persons/erika-mustermann.yml')
-    Person(erika-mustermann, Erika Mustermann, *1957-08-12)
-    >>> maxl = read('persons/max-mustermann.yml')
-    >>> maxl
-    Person(max-mustermann, Max Mustermann, *1976-02-01)
-    >>> maxl.mother
-    Person(erika-mustermann)
-    >>> maxl.father
-    Person(thomas-mustermann)
-    """
-    if isinstance(yaml_path, str):
-        return read(pathlib.Path(yaml_path))
-    with yaml_path.open("r") as yaml_file:
-        return yaml.load(yaml_file, Loader=_Loader)