diff options
-rw-r--r-- | bsie/base/extractor.py | 5 | ||||
-rw-r--r-- | bsie/base/reader.py | 11 | ||||
-rw-r--r-- | bsie/extractor/generic/path.py | 4 | ||||
-rw-r--r-- | bsie/extractor/generic/stat.py | 4 | ||||
-rw-r--r-- | bsie/reader/path.py | 7 | ||||
-rw-r--r-- | bsie/reader/stat.py | 6 |
6 files changed, 12 insertions, 25 deletions
diff --git a/bsie/base/extractor.py b/bsie/base/extractor.py index a6a69c6..7acf2bd 100644 --- a/bsie/base/extractor.py +++ b/bsie/base/extractor.py @@ -8,8 +8,7 @@ Author: Matthias Baumgartner, 2022 import abc import typing -# inner-module imports -from . import reader +# bsie imports from bsie.utils import node from bsie.utils.bsfs import schema as _schema, typename @@ -50,7 +49,7 @@ class Extractor(abc.ABC): """Produce (node, predicate, value)-triples from some content.""" # what type of content is expected (i.e. reader subclass). - CONTENT_READER: typing.Optional[typing.Type[reader.Reader]] = None + CONTENT_READER: typing.Optional[str] = None # extractor schema. schema: _schema.Schema diff --git a/bsie/base/reader.py b/bsie/base/reader.py index f29e451..e59abef 100644 --- a/bsie/base/reader.py +++ b/bsie/base/reader.py @@ -12,12 +12,11 @@ Author: Matthias Baumgartner, 2022 import abc import typing -# inner-module imports +# bsie imports from bsie.utils.bsfs import URI, typename # exports __all__: typing.Sequence[str] = ( - 'Aggregator', 'Reader', ) @@ -27,20 +26,14 @@ __all__: typing.Sequence[str] = ( class Reader(abc.ABC): """Read and return some content from a file.""" - # In what data structure content is returned - CONTENT_TYPE = typing.Union[typing.Any] - # NOTE: Child classes must also assign a typing.Union even if there's - # only one options - def __str__(self) -> str: return typename(self) def __repr__(self) -> str: return f'{typename(self)}()' - # FIXME: How about using contexts instead of calls? @abc.abstractmethod - def __call__(self, path: URI) -> CONTENT_TYPE: + def __call__(self, path: URI) -> typing.Any: """Return some content of the file at *path*. Raises a `ReaderError` if the reader cannot make sense of the file format. """ diff --git a/bsie/extractor/generic/path.py b/bsie/extractor/generic/path.py index f358a79..f346f97 100644 --- a/bsie/extractor/generic/path.py +++ b/bsie/extractor/generic/path.py @@ -24,7 +24,7 @@ __all__: typing.Sequence[str] = ( class Path(extractor.Extractor): """Extract information from file's path.""" - CONTENT_READER = bsie.reader.path.Path + CONTENT_READER = 'bsie.reader.path.Path' # mapping from predicate to handler function. _callmap: typing.Dict[schema.Predicate, typing.Callable[[str], typing.Any]] @@ -45,7 +45,7 @@ class Path(extractor.Extractor): def extract( self, subject: node.Node, - content: CONTENT_READER.CONTENT_TYPE, + content: str, predicates: typing.Iterable[schema.Predicate], ) -> typing.Iterator[typing.Tuple[node.Node, schema.Predicate, typing.Any]]: for pred in predicates: diff --git a/bsie/extractor/generic/stat.py b/bsie/extractor/generic/stat.py index e5387af..7088c0a 100644 --- a/bsie/extractor/generic/stat.py +++ b/bsie/extractor/generic/stat.py @@ -24,7 +24,7 @@ __all__: typing.Sequence[str] = ( class Stat(extractor.Extractor): """Extract information from the file system.""" - CONTENT_READER = bsie.reader.stat.Stat + CONTENT_READER = 'bsie.reader.stat.Stat' # mapping from predicate to handler function. _callmap: typing.Dict[_schema.Predicate, typing.Callable[[os.stat_result], typing.Any]] @@ -45,7 +45,7 @@ class Stat(extractor.Extractor): def extract( self, subject: node.Node, - content: CONTENT_READER.CONTENT_TYPE, + content: os.stat_result, predicates: typing.Iterable[_schema.Predicate], ) -> typing.Iterator[typing.Tuple[node.Node, _schema.Predicate, typing.Any]]: for pred in predicates: diff --git a/bsie/reader/path.py b/bsie/reader/path.py index d27c664..d60f187 100644 --- a/bsie/reader/path.py +++ b/bsie/reader/path.py @@ -5,10 +5,9 @@ A copy of the license is provided with the project. Author: Matthias Baumgartner, 2022 """ # imports -import os import typing -# inner-module imports +# bsie imports from bsie.base import reader # exports @@ -22,9 +21,7 @@ __all__: typing.Sequence[str] = ( class Path(reader.Reader): """Return the path.""" - CONTENT_TYPE = typing.Union[str] - - def __call__(self, path: str) -> CONTENT_TYPE: + def __call__(self, path: str) -> str: return path diff --git a/bsie/reader/stat.py b/bsie/reader/stat.py index f0b83fb..6d40ab8 100644 --- a/bsie/reader/stat.py +++ b/bsie/reader/stat.py @@ -8,7 +8,7 @@ Author: Matthias Baumgartner, 2022 import os import typing -# inner-module imports +# bsie imports from bsie.base import reader, errors # exports @@ -22,9 +22,7 @@ __all__: typing.Sequence[str] = ( class Stat(reader.Reader): """Read and return the filesystem's stat infos.""" - CONTENT_TYPE = typing.Union[os.stat_result] - - def __call__(self, path: str) -> CONTENT_TYPE: + def __call__(self, path: str) -> os.stat_result: try: return os.stat(path) except Exception: |