Skip to content

Commit

Permalink
Adds standard parsings
Browse files Browse the repository at this point in the history
  • Loading branch information
domna committed Feb 23, 2024
1 parent 11e0cb2 commit 44c4928
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions pynxtools/dataconverter/readers/multi/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from typing import Any, Callable, Dict, List, Optional, Tuple

from pynxtools.dataconverter.readers.base.reader import BaseReader
from pynxtools.dataconverter.readers.utils import parse_flatten_json, parse_yml
from pynxtools.dataconverter.template import Template


Expand All @@ -30,7 +31,11 @@ class MultiFormatReader(BaseReader):

# Whitelist for the NXDLs that the reader supports and can process
supported_nxdls: List[str] = []
extensions: Dict[str, Callable[[Any], dict]] = {}
extensions: Dict[str, Callable[[Any], dict]] = {
".json": parse_flatten_json,
".yaml": parse_yml,
".yml": parse_yml,
}
kwargs: Optional[Dict[str, Any]] = None

def setup_template(self) -> Dict[str, Any]:
Expand All @@ -47,6 +52,12 @@ def handle_objects(self, objects: Tuple[Any]) -> Dict[str, Any]:
"""
return {}

def get_data(self, path: str) -> Dict[str, Any]:
"""
Returns the data from the given path.
"""
return {}

def read(
self,
template: dict = None,
Expand All @@ -61,7 +72,14 @@ def read(
template = Template()
self.kwargs = kwargs

sorted_paths = sorted(file_paths, key=lambda f: os.path.splitext(f)[1])
def sort_keys(filename: str) -> str:
"""
Makes sure to read json and yaml files last
"""
ending = os.path.splitext(filename)[1]
return ".zzzzz" if ending in (".json", ".yaml", ".yml") else ending

sorted_paths = sorted(file_paths, key=sort_keys)
for file_path in sorted_paths:
extension = os.path.splitext(file_path)[1].lower()
if extension not in self.extensions:
Expand Down

0 comments on commit 44c4928

Please sign in to comment.