Skip to content

Commit

Permalink
fixing ci/cd workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
RubelMozumder committed Oct 20, 2023
1 parent 4203e88 commit 2d866ba
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
1 change: 1 addition & 0 deletions pynxtools/dataconverter/readers/xrd/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def get_template_from_nxdl_name(nxdl_name):
def_path = current_path.parent.parent.parent.parent / 'definitions'
# Check contributed defintions
full_nxdl_path = Path(def_path, 'contributed_definitions', nxdl_file)
root = None
if full_nxdl_path.exists():
root = ET.parse(full_nxdl_path).getroot()
else:
Expand Down
61 changes: 35 additions & 26 deletions pynxtools/dataconverter/readers/xrd/xrd_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@
from xrayutilities.io.panalytical_xml import XRDMLFile # for reading XRDML files


def remove_namespace(node_tag):
"""
"""
return node_tag.split('}')[-1]


def fill_slash_sep_dict_from_nested_dict(parent_path, nested_dict, slash_sep_dict):
"""Convert a nested dict into slash separated dict.
Expand Down Expand Up @@ -61,32 +55,35 @@ def fill_slash_sep_dict_from_nested_dict(parent_path, nested_dict, slash_sep_dic


class IgnoreNodeTextWarning(Warning):
"""Special class to warn node text skip."""
pass


class XRDMLParser:
"""_summary_
Returns
-------
_type_
_description_
"""
"""Parser for xrdml file with the help of other XRD library e.g. panalytical_xml."""

def __init__(self, file_path):
"""Construct XRDMLParser obj.
Parameters
----------
file_path : str
"""
import xml.etree.ElementTree as ET
# In future it can be utilised later it different versions of file
self.__version = None
self.__xrd_dict = {}
self.__file_path = file_path

def get_slash_separated_xrd_dict(self):
"""_summary_
"""Return a dict with slash separated key and value from xrd file.
The key is the slash separated string path for nested xml elements.
Returns
-------
_type_
_description_
dict:
Dictionary where key maps xml nested elements by slash separated str.
"""
# To navigate different functions in future according to some parameters
# such as version, and data analysis module from panalytical_xml
Expand All @@ -95,6 +92,9 @@ def get_slash_separated_xrd_dict(self):

def handle_with_panalytical_module(self):
"""Handeling XRDml file by parsing xml file and Pnanalytical_xml parser
Panalytical module extends and constructs some array data from experiment settings
comes with xml file.
"""
xml_root = ET.parse(self.__file_path).getroot()

Expand All @@ -113,7 +113,14 @@ def handle_with_panalytical_module(self):
fill_slash_sep_dict_from_nested_dict('/', nested_data_dict, self.__xrd_dict)

def process_node_text(self, parent_path, node_txt):
"""
"""Processing text of node
Parameters
----------
parent_path : str
Starting str of the key when forming a string key.
node_txt : str
text from node.
"""
key_val_pairs = []
# get key-val pair
Expand Down Expand Up @@ -170,7 +177,7 @@ def parse_general_elm(self, parent_path, xml_node):
xml_node : XML.Element
Any element except process instruction and entry nodes.
"""
tag = remove_namespace(xml_node.tag)
tag = remove_namespace_from_tag(xml_node.tag)

if parent_path == '/':
parent_path = '/' + tag
Expand All @@ -182,7 +189,7 @@ def parse_general_elm(self, parent_path, xml_node):
if node_attr:
for key, val in node_attr.items():
# Some attr has namespace
key = remove_namespace(key)
key = remove_namespace_from_tag(key)
key = key.replace(' ', '_')
path_extend = '/'.join([parent_path, key])
self.__xrd_dict[path_extend] = val
Expand All @@ -203,7 +210,7 @@ def parse_entry_elm(self, parent_path, xml_node):
xml_node : XML.Element
Any entry nodes.
"""
tag = remove_namespace(xml_node.tag)
tag = remove_namespace_from_tag(xml_node.tag)

if parent_path == '/':
parent_path = '/' + tag
Expand All @@ -215,7 +222,7 @@ def parse_entry_elm(self, parent_path, xml_node):
if node_attr:
for key, val in node_attr.items():
# Some attr has namespace
key = remove_namespace(key)
key = remove_namespace_from_tag(key)
path_extend = '/'.join([parent_path, key])
self.__xrd_dict[path_extend] = val

Expand All @@ -228,13 +235,15 @@ def parse_entry_elm(self, parent_path, xml_node):


class FormatParser:
'''A class to identify and parse different file formats.'''
"""A class to identify and parse different file formats."""

def __init__(self, file_path):
'''
Args:
file_path (str): The path of the file to be identified and parsed.
'''
"""Construct obj.
Parameters
----------
file_path : str
"""
self.file_path = file_path

def get_file_format(self):
Expand Down

0 comments on commit 2d866ba

Please sign in to comment.