From 3497f0f281153325e438ba565540899e0d46a2e2 Mon Sep 17 00:00:00 2001 From: Lukas Pielsticker <50139597+lukaspie@users.noreply.github.com> Date: Tue, 14 Jan 2025 16:43:27 +0100 Subject: [PATCH 1/3] process yaml and json files last --- src/pynxtools_xps/reader.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/pynxtools_xps/reader.py b/src/pynxtools_xps/reader.py index 56d1ae71..22c7dcac 100644 --- a/src/pynxtools_xps/reader.py +++ b/src/pynxtools_xps/reader.py @@ -176,6 +176,12 @@ def __init__(self, *args, **kwargs): for ext in XPSReader.__prmt_file_ext__: self.extensions[ext] = self.handle_data_file + self.processing_order = [ext for ext in XPSReader.__prmt_file_ext__] + [ + ".yml", + ".yaml", + ".json", + ] + def set_config_file(self, file_path: str) -> Dict[str, Any]: if self.config_file is not None: logger.info( From eafe4cbc9f4ef5b8383ac158dd71c6e8fa3e4117 Mon Sep 17 00:00:00 2001 From: Lukas Pielsticker <50139597+lukaspie@users.noreply.github.com> Date: Tue, 14 Jan 2025 16:46:29 +0100 Subject: [PATCH 2/3] ruff formatting --- .pre-commit-config.yaml | 2 +- pyproject.toml | 2 +- src/pynxtools_xps/reader.py | 2 +- src/pynxtools_xps/reader_utils.py | 4 ++-- src/pynxtools_xps/specs/sle/sle_specs.py | 6 +++--- src/pynxtools_xps/specs/xml/xml_specs.py | 6 ++---- tests/test_helpers.py | 18 +++++++++--------- 7 files changed, 19 insertions(+), 21 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 907ca728..f608a57f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.8.0 + rev: v0.9.1 hooks: # Run the linter. - id: ruff diff --git a/pyproject.toml b/pyproject.toml index 337aa26f..622737a9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,7 +32,7 @@ dependencies = [ [project.optional-dependencies] dev = [ "mypy", - "ruff>=0.6.0", + "ruff>=0.9.0", "pytest", "pytest-cov", "pytest-timeout", diff --git a/src/pynxtools_xps/reader.py b/src/pynxtools_xps/reader.py index 22c7dcac..164eb1ef 100644 --- a/src/pynxtools_xps/reader.py +++ b/src/pynxtools_xps/reader.py @@ -157,7 +157,7 @@ class XPSReader(MultiFormatReader): ) __vndr_err_msg__ = ( - "Need an XPS data file from one of the following vendors: " f"{__vendors__}" + f"Need an XPS data file from one of the following vendors: {__vendors__}" ) def __init__(self, *args, **kwargs): diff --git a/src/pynxtools_xps/reader_utils.py b/src/pynxtools_xps/reader_utils.py index 6c6ce436..49f1f8f2 100644 --- a/src/pynxtools_xps/reader_utils.py +++ b/src/pynxtools_xps/reader_utils.py @@ -414,12 +414,12 @@ def construct_data_key(spectrum: Dict[str, Any]) -> str: """ if "loop_no" in spectrum: - cycle_key = f'cycle{spectrum["loop_no"]}' + cycle_key = f"cycle{spectrum['loop_no']}" else: cycle_key = "cycle0" if "scan_no" in spectrum: - scan_key = f'scan{spectrum["scan_no"]}' + scan_key = f"scan{spectrum['scan_no']}" else: scan_key = "scan0" diff --git a/src/pynxtools_xps/specs/sle/sle_specs.py b/src/pynxtools_xps/specs/sle/sle_specs.py index 6d0808a1..bd9b268d 100644 --- a/src/pynxtools_xps/specs/sle/sle_specs.py +++ b/src/pynxtools_xps/specs/sle/sle_specs.py @@ -266,8 +266,8 @@ def _update_xps_dict_with_spectrum( if units is not None: self._xps_dict[f"{root}/{mpes_key}/@units"] = units - self._xps_dict[f'{path_map["electronanalyser"]}/name'] = spectrum["devices"][0] - self._xps_dict[f'{path_map["source"]}/name'] = spectrum["devices"][1] + self._xps_dict[f"{path_map['electronanalyser']}/name"] = spectrum["devices"][0] + self._xps_dict[f"{path_map['source']}/name"] = spectrum["devices"][1] # Create keys for writing to data scan_key = construct_data_key(spectrum) @@ -298,7 +298,7 @@ def _update_xps_dict_with_spectrum( # TODO: fix this hotfix so that all data can be written # Add energy axis to energy_calibration - calib_energy_key = f'{path_map["process/energy_calibration"]}/energy' + calib_energy_key = f"{path_map['process/energy_calibration']}/energy" self._xps_dict[calib_energy_key] = energy self._xps_dict["data"][entry][scan_key.split("_")[0]] = xr.DataArray( diff --git a/src/pynxtools_xps/specs/xml/xml_specs.py b/src/pynxtools_xps/specs/xml/xml_specs.py index 5b8e8e26..f075de8e 100644 --- a/src/pynxtools_xps/specs/xml/xml_specs.py +++ b/src/pynxtools_xps/specs/xml/xml_specs.py @@ -400,9 +400,7 @@ def struct_fc_name_sc_value(self, element_, first_child, parent_path, skip_child for unit in units: if f"_[{unit}]" in section_nm_reslvr: section_nm_reslvr, _ = section_nm_reslvr.split("_") - self.metadata_dict[f"{parent_path}/" f"{section_nm_reslvr}/@units"] = ( - unit - ) + self.metadata_dict[f"{parent_path}/{section_nm_reslvr}/@units"] = unit parent_path, self.tail_part_frm_struct = self.check_last_part_repetition( parent_path, self.tail_part_frm_struct, section_nm_reslvr @@ -513,7 +511,7 @@ def last_element_parser(self, element_: EmtT.Element, parent_path: str) -> None: if child_num == 0: if "name" in elmt_attr.keys(): - section_nm_reslvr = f'{elmt_attr["name"]}' + section_nm_reslvr = f"{elmt_attr['name']}" value = self.restructure_value(element_.text, element_.tag) parent_path, self.tail_part_frm_othr = self.check_last_part_repetition( diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 261a5a69..d2a47c7e 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -80,16 +80,16 @@ def test_extract_unit( ): result_value, result_unit = extract_unit(key, value, unit_missing) - assert isinstance( - result_value, type(expected_value) - ), f"Expected type {type(expected_value)} but got type {type(result_value)}" + assert isinstance(result_value, type(expected_value)), ( + f"Expected type {type(expected_value)} but got type {type(result_value)}" + ) - assert ( - result_value == expected_value - ), f"Expected {expected_value} but got {result_value}" - assert ( - result_unit == expected_unit - ), f"Expected {expected_unit} but got {result_unit}" + assert result_value == expected_value, ( + f"Expected {expected_value} but got {result_value}" + ) + assert result_unit == expected_unit, ( + f"Expected {expected_unit} but got {result_unit}" + ) @pytest.mark.parametrize( From d94b6730de5390aaf384a6c1504274549d5b19fc Mon Sep 17 00:00:00 2001 From: Lukas Pielsticker <50139597+lukaspie@users.noreply.github.com> Date: Tue, 14 Jan 2025 16:49:46 +0100 Subject: [PATCH 3/3] dont iterate __prmt_file_ext__ in processing_order --- src/pynxtools_xps/reader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pynxtools_xps/reader.py b/src/pynxtools_xps/reader.py index 164eb1ef..adfac76f 100644 --- a/src/pynxtools_xps/reader.py +++ b/src/pynxtools_xps/reader.py @@ -176,7 +176,7 @@ def __init__(self, *args, **kwargs): for ext in XPSReader.__prmt_file_ext__: self.extensions[ext] = self.handle_data_file - self.processing_order = [ext for ext in XPSReader.__prmt_file_ext__] + [ + self.processing_order = XPSReader.__prmt_file_ext__ + [ ".yml", ".yaml", ".json",