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/MANIFEST.in b/MANIFEST.in index 4276f0d..a9fd2cb 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,5 @@ prune * exclude * -recursive-include pynxtools_mpes *.py -include pyproject.toml README.md dev-requirements.txt \ No newline at end of file +recursive-include src/pynxtools_mpes *.py +include pyproject.toml README.md dev-requirements.txt +recursive-include src/pynxtools_mpes/nomad/examples \ No newline at end of file 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..2f1259c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,13 +55,18 @@ docs = [ [project.entry-points."pynxtools.reader"] mpes = "pynxtools_mpes.reader:MPESReader" -[tool.setuptools] -packages = ["pynxtools_mpes"] +[project.entry-points.'nomad.plugin'] +mpes_example = "pynxtools_mpes.nomad.entrypoints:mpes_example" + +[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/src/pynxtools_mpes/nomad/entrypoints.py b/src/pynxtools_mpes/nomad/entrypoints.py new file mode 100644 index 0000000..fcccdb5 --- /dev/null +++ b/src/pynxtools_mpes/nomad/entrypoints.py @@ -0,0 +1,40 @@ +# +# 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 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", +) 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 diff --git a/tests/test_nomad_example.py b/tests/test_nomad_example.py new file mode 100644 index 0000000..0b13ee1 --- /dev/null +++ b/tests/test_nomad_example.py @@ -0,0 +1,62 @@ +# +# 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=config, + expected_local_path=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