Skip to content

Commit

Permalink
ci/cd
Browse files Browse the repository at this point in the history
  • Loading branch information
RubelMozumder committed Dec 1, 2023
1 parent f47c8c5 commit ead1b4b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
34 changes: 25 additions & 9 deletions pynxtools/dataconverter/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,29 @@

from pynxtools.dataconverter.logger import logger as pynx_logger

if sys.version_info >= (3, 10):
from importlib.metadata import entry_points
else:
from importlib_metadata import entry_points


def get_reader(reader_name) -> BaseReader:
"""Helper function to get the reader object from it's given name"""
path_prefix = f"{os.path.dirname(__file__)}{os.sep}" if os.path.dirname(__file__) else ""
path = os.path.join(path_prefix, "readers", reader_name, "reader.py")
spec = importlib.util.spec_from_file_location("reader.py", path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module) # type: ignore[attr-defined]
try:
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module) # type: ignore[attr-defined]
except FileNotFoundError as exc:
# pylint: disable=unexpected-keyword-arg
importlib_module = entry_points(group='pynxtools.reader')
if (
importlib_module
and reader_name in map(lambda ep: ep.name, entry_points(group='pynxtools.reader'))
):
return importlib_module[reader_name].load()
raise ValueError(f"The reader, {reader_name}, was not found.") from exc
return module.READER # type: ignore[attr-defined]


Expand Down Expand Up @@ -158,7 +173,7 @@ def transfer_data_into_template(input_file,
return data


# pylint: disable=too-many-arguments,too-many-locals
# pylint: disable=too-many-arguments, W1203
def convert(input_file: Tuple[str, ...],
reader: str,
nxdl: str,
Expand Down Expand Up @@ -211,12 +226,13 @@ def convert(input_file: Tuple[str, ...],
if fair and data.undocumented.keys():
logger.warning("There are undocumented paths in the template. This is not acceptable!")
return
for path in data.undocumented.keys():
if "/@default" in path:
continue
logger.info(
f"NO DOCUMENTATION: The path, {path} is being written but has no documentation."
)
if undocumented:
for path in data.undocumented.keys():
if "/@default" in path:
continue
logger.info(
f"NO DOCUMENTATION: The path, {path} is being written but has no documentation."
)
helpers.add_default_root_attributes(data=data, filename=os.path.basename(output))
Writer(data=data, nxdl_f_path=nxdl_f_path, output_path=output).write()

Expand Down
12 changes: 8 additions & 4 deletions pynxtools/dataconverter/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from pynxtools.nexus import nexus
from pynxtools.nexus.nexus import NxdlAttributeError

logger = logging.getLogger(__name__)
pynx_logger = logging.getLogger(__name__)


def is_a_lone_group(xml_element) -> bool:
Expand Down Expand Up @@ -447,7 +447,9 @@ def does_group_exist(path_to_group, data):
return False


def ensure_all_required_fields_exist(template, data, nxdl_root, logger):
# pylint: disable=W1203
def ensure_all_required_fields_exist(template, data,
nxdl_root, logger=pynx_logger):
"""Checks whether all the required fields are in the returned data object."""
for path in template["required"]:
entry_name = get_name_from_data_dict_entry(path[path.rindex('/') + 1:])
Expand Down Expand Up @@ -498,7 +500,9 @@ def try_undocumented(data, nxdl_root: ET.Element):
pass


def validate_data_dict(template, data, nxdl_root: ET.Element, logger):
def validate_data_dict(template, data,
nxdl_root: ET.Element,
logger=pynx_logger):
"""Checks whether all the required paths from the template are returned in data dict."""
assert nxdl_root is not None, "The NXDL file hasn't been loaded."

Expand Down Expand Up @@ -590,7 +594,7 @@ def convert_to_hill(atoms_typ):
return atom_list + list(atoms_typ)


def add_default_root_attributes(data, filename):
def add_default_root_attributes(data, filename, logger=pynx_logger):
"""
Takes a dict/Template and adds NXroot fields/attributes that are inherently available
"""
Expand Down

0 comments on commit ead1b4b

Please sign in to comment.