From 9184e7348aed94018e4b57cf0e273ef630aa4339 Mon Sep 17 00:00:00 2001 From: Lukas Pielsticker <50139597+lukaspie@users.noreply.github.com> Date: Fri, 11 Oct 2024 13:21:18 +0200 Subject: [PATCH 1/6] switch to src layout --- .github/workflows/pylint.yml | 6 +++--- docs/reference/mpes.md | 2 +- mkdocs.yaml | 2 +- pyproject.toml | 8 +++++--- {pynxtools_mpes => src/pynxtools_mpes}/__init__.py | 0 {pynxtools_mpes => src/pynxtools_mpes}/mkdocs.py | 0 {pynxtools_mpes => src/pynxtools_mpes}/reader.py | 0 7 files changed, 10 insertions(+), 8 deletions(-) rename {pynxtools_mpes => src/pynxtools_mpes}/__init__.py (100%) rename {pynxtools_mpes => src/pynxtools_mpes}/mkdocs.py (100%) rename {pynxtools_mpes => src/pynxtools_mpes}/reader.py (100%) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index e5696a0..de851dc 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -21,10 +21,10 @@ jobs: uv pip install -r dev-requirements.txt - name: ruff check run: | - ruff check pynxtools_mpes tests + ruff check src/pynxtools_mpes tests - name: ruff format run: | - ruff format --check pynxtools_mpes tests + ruff format --check src/pynxtools_mpes tests - name: mypy run: | - mypy pynxtools_mpes tests + mypy src/pynxtools_mpes tests diff --git a/docs/reference/mpes.md b/docs/reference/mpes.md index 4d1cb7e..648d694 100644 --- a/docs/reference/mpes.md +++ b/docs/reference/mpes.md @@ -2,7 +2,7 @@ The reader supports [HDF5](https://www.hdfgroup.org/solutions/hdf5/) files created using the MPES instruments at the Department of Physical Chemistry of the [Fritz Haber Institute of the Max Planck Society (FHI)](https://pc.fhi-berlin.mpg.de). -The reader for can be found [here](https://github.com/FAIRmat-NFDI/pynxtools-mpes/blob/main/pynxtools_mpes/reader.py). +The reader for can be found [here](https://github.com/FAIRmat-NFDI/pynxtools-mpes/blob/main/src/pynxtools_mpes/reader.py). Example data for the MPES reader is available [here](https://github.com/FAIRmat-NFDI/pynxtools-mpes/tree/main/tests/data). diff --git a/mkdocs.yaml b/mkdocs.yaml index 1dc9de4..4362a0d 100644 --- a/mkdocs.yaml +++ b/mkdocs.yaml @@ -20,7 +20,7 @@ nav: plugins: - search - macros: - module_name: pynxtools_mpes/mkdocs + module_name: src/pynxtools_mpes/mkdocs theme: name: material diff --git a/pyproject.toml b/pyproject.toml index c155370..1e3b2a9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,13 +55,15 @@ docs = [ [project.entry-points."pynxtools.reader"] mpes = "pynxtools_mpes.reader:MPESReader" -[tool.setuptools] -packages = ["pynxtools_mpes"] +[tool.setuptools.packages.find] +where = [ + "src", +] [tool.setuptools_scm] [tool.ruff] -include = ["pynxtools_mpes/*.py", "tests/*.py"] +include = ["src/*.py", "tests/*.py"] line-length = 88 indent-width = 4 diff --git a/pynxtools_mpes/__init__.py b/src/pynxtools_mpes/__init__.py similarity index 100% rename from pynxtools_mpes/__init__.py rename to src/pynxtools_mpes/__init__.py diff --git a/pynxtools_mpes/mkdocs.py b/src/pynxtools_mpes/mkdocs.py similarity index 100% rename from pynxtools_mpes/mkdocs.py rename to src/pynxtools_mpes/mkdocs.py diff --git a/pynxtools_mpes/reader.py b/src/pynxtools_mpes/reader.py similarity index 100% rename from pynxtools_mpes/reader.py rename to src/pynxtools_mpes/reader.py From 2f81b8dbb892f94cc495826233935daf10d96623 Mon Sep 17 00:00:00 2001 From: Lukas Pielsticker <50139597+lukaspie@users.noreply.github.com> Date: Fri, 11 Oct 2024 13:59:08 +0200 Subject: [PATCH 2/6] add src in MANIFEST.IN --- MANIFEST.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index 4276f0d..a9131e3 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ prune * exclude * -recursive-include pynxtools_mpes *.py +recursive-include src/pynxtools_mpes *.py include pyproject.toml README.md dev-requirements.txt \ No newline at end of file From 544cfc367cbbf65493826baee72558d5352a2156 Mon Sep 17 00:00:00 2001 From: Lukas Pielsticker <50139597+lukaspie@users.noreply.github.com> Date: Fri, 11 Oct 2024 14:33:18 +0200 Subject: [PATCH 3/6] add entrypoint for NOMAD example --- MANIFEST.in | 3 +- pyproject.toml | 3 ++ src/pynxtools_mpes/nomad/entrypoints.py | 43 +++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/pynxtools_mpes/nomad/entrypoints.py diff --git a/MANIFEST.in b/MANIFEST.in index a9131e3..a9fd2cb 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,5 @@ prune * exclude * recursive-include src/pynxtools_mpes *.py -include pyproject.toml README.md dev-requirements.txt \ No newline at end of file +include pyproject.toml README.md dev-requirements.txt +recursive-include src/pynxtools_mpes/nomad/examples \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 1e3b2a9..2f1259c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,6 +55,9 @@ docs = [ [project.entry-points."pynxtools.reader"] mpes = "pynxtools_mpes.reader:MPESReader" +[project.entry-points.'nomad.plugin'] +mpes_example = "pynxtools_mpes.nomad.entrypoints:mpes_example" + [tool.setuptools.packages.find] where = [ "src", diff --git a/src/pynxtools_mpes/nomad/entrypoints.py b/src/pynxtools_mpes/nomad/entrypoints.py new file mode 100644 index 0000000..ad61201 --- /dev/null +++ b/src/pynxtools_mpes/nomad/entrypoints.py @@ -0,0 +1,43 @@ +# +# Copyright The NOMAD Authors. +# +# This file is part of NOMAD. See https://nomad-lab.eu for further info. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +"""Entry points for mpes examples.""" +try: + from nomad.config.models.plugins import ( + ParserEntryPoint, + SchemaPackageEntryPoint, + ExampleUploadEntryPoint, + ) +except ImportError as exc: + raise ImportError( + "Could not import nomad package. Please install the package 'nomad-lab'." + ) from exc + +mpes_example = ExampleUploadEntryPoint( + title="Multidimensional photoemission spectroscopy (MPES)", + category="FAIRmat examples", + description=""" + This example presents the capabilities of the NOMAD platform to store and standardize multidimensional photoemission spectroscopy (MPES) experimental data. It contains three major examples: + + - Taking a pre-binned file, here stored in a h5 file, and converting it into the standardized MPES NeXus format. + There exists a [NeXus application definition for MPES](https://manual.nexusformat.org/classes/contributed_definitions/NXmpes.html#nxmpes) which details the internal structure of such a file. + - Binning of raw data (see [here](https://www.nature.com/articles/s41597-020-00769-8) for additional resources) into a h5 file and consecutively generating a NeXus file from it. + - An analysis example using data in the NeXus format and employing the [pyARPES](https://github.com/chstan/arpes) analysis tool to reproduce the main findings of [this paper](https://arxiv.org/pdf/2107.07158.pdf). + """, + path="nomad/examples", + local_path="examples/data/uploads/mpes.zip", +) \ No newline at end of file From e05d2c19530539d035af1d15c224a81ae97bc2df Mon Sep 17 00:00:00 2001 From: Lukas Pielsticker <50139597+lukaspie@users.noreply.github.com> Date: Fri, 11 Oct 2024 14:33:42 +0200 Subject: [PATCH 4/6] test for NOMAD example entry point --- tests/test_nomad_example.py | 58 +++++++++++++++++++++++++++++++++++++ tests/test_reader.py | 19 +++++++++++- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 tests/test_nomad_example.py diff --git a/tests/test_nomad_example.py b/tests/test_nomad_example.py new file mode 100644 index 0000000..52e264a --- /dev/null +++ b/tests/test_nomad_example.py @@ -0,0 +1,58 @@ +# +# Copyright The NOMAD Authors. +# +# This file is part of NOMAD. See https://nomad-lab.eu for further info. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +"""Test for NOMAD examples in reader plugins.""" + +import pytest + +try: + from nomad.parsing.parser import ArchiveParser + from nomad.datamodel import EntryArchive, Context +except ImportError: + pytest.skip( + "Skipping NOMAD example tests because nomad is not installed", + allow_module_level=True, + ) + +from pynxtools.testing.nomad_example import get_file_parameter, test_nomad_example + + +@pytest.mark.parametrize( + "mainfile", get_file_parameter("../src/pynxtools_mpes/nomad/examples") +) +def test_nomad_examples(mainfile, no_warn): + """Test if NOMAD examples work.""" + test_nomad_example(mainfile) + + +@pytest.mark.parametrize( + "config, expected_local_path", + [ + pytest.param( + { + "title": "mpes_example", + "description": "mpes_example", + "category": "test", + "path": "nomad/examples", + }, + f"examples/data/uploads/mpes.zip", + id="mpes_example", + ), + ], +) +def test_nomad_example_upload_entry_point_valid(config, expected_local_path): + test_example_upload_entry_point_valid(plugin_package="pynxtools-mpes", config, expected_local_path) diff --git a/tests/test_reader.py b/tests/test_reader.py index e54d589..d730c4b 100644 --- a/tests/test_reader.py +++ b/tests/test_reader.py @@ -1,5 +1,22 @@ +# +# Copyright The NOMAD Authors. +# +# This file is part of NOMAD. See https://nomad-lab.eu for further info. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# """ -Basic example based test for the stm reader +Basic example based test for the MPES reader """ from pathlib import Path From be8abc4f9de8316858ae12ff30bc55274c7e678c Mon Sep 17 00:00:00 2001 From: Lukas Pielsticker <50139597+lukaspie@users.noreply.github.com> Date: Fri, 11 Oct 2024 14:35:08 +0200 Subject: [PATCH 5/6] remove unneeded imports --- src/pynxtools_mpes/nomad/entrypoints.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/pynxtools_mpes/nomad/entrypoints.py b/src/pynxtools_mpes/nomad/entrypoints.py index ad61201..15b0f05 100644 --- a/src/pynxtools_mpes/nomad/entrypoints.py +++ b/src/pynxtools_mpes/nomad/entrypoints.py @@ -17,11 +17,7 @@ # """Entry points for mpes examples.""" try: - from nomad.config.models.plugins import ( - ParserEntryPoint, - SchemaPackageEntryPoint, - ExampleUploadEntryPoint, - ) + from nomad.config.models.plugins import ExampleUploadEntryPoint except ImportError as exc: raise ImportError( "Could not import nomad package. Please install the package 'nomad-lab'." From 7e9558f3d2773c4a872a762ae72f5f0ef4d3af71 Mon Sep 17 00:00:00 2001 From: Lukas Pielsticker <50139597+lukaspie@users.noreply.github.com> Date: Fri, 11 Oct 2024 14:37:53 +0200 Subject: [PATCH 6/6] linitng --- src/pynxtools_mpes/nomad/entrypoints.py | 3 ++- tests/test_nomad_example.py | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/pynxtools_mpes/nomad/entrypoints.py b/src/pynxtools_mpes/nomad/entrypoints.py index 15b0f05..fcccdb5 100644 --- a/src/pynxtools_mpes/nomad/entrypoints.py +++ b/src/pynxtools_mpes/nomad/entrypoints.py @@ -16,6 +16,7 @@ # limitations under the License. # """Entry points for mpes examples.""" + try: from nomad.config.models.plugins import ExampleUploadEntryPoint except ImportError as exc: @@ -36,4 +37,4 @@ """, path="nomad/examples", local_path="examples/data/uploads/mpes.zip", -) \ No newline at end of file +) diff --git a/tests/test_nomad_example.py b/tests/test_nomad_example.py index 52e264a..0b13ee1 100644 --- a/tests/test_nomad_example.py +++ b/tests/test_nomad_example.py @@ -55,4 +55,8 @@ def test_nomad_examples(mainfile, no_warn): ], ) def test_nomad_example_upload_entry_point_valid(config, expected_local_path): - test_example_upload_entry_point_valid(plugin_package="pynxtools-mpes", config, expected_local_path) + test_example_upload_entry_point_valid( + plugin_package="pynxtools-mpes", + config=config, + expected_local_path=expected_local_path, + )