From 1ee7a383b09df88b0c260405a5fbac93b5a8dedb Mon Sep 17 00:00:00 2001 From: Andrea Albino Date: Wed, 21 Aug 2024 14:46:18 +0200 Subject: [PATCH] updated toml file and relaunched ruff linting --- nomad.yaml | 10 -- pyproject.toml | 104 +++++++++++------- .../combinatorial.py | 24 ++-- .../crystal_growth.py | 2 + src/nomad_material_processing/epitaxy.py | 2 + src/nomad_material_processing/general.py | 36 +++--- .../solution/__init__.py | 2 +- .../solution/{schema.py => general.py} | 29 ++--- .../solution/utils.py | 6 +- src/nomad_material_processing/utils.py | 1 + .../vapor_deposition/cvd/general.py | 33 ++---- .../vapor_deposition/general.py | 24 ++-- .../vapor_deposition/pvd/general.py | 17 +-- .../vapor_deposition/pvd/mbe.py | 5 +- .../vapor_deposition/pvd/pld.py | 17 +-- .../vapor_deposition/pvd/sputtering.py | 3 +- .../vapor_deposition/pvd/thermal.py | 14 +-- tests/solution/test_solution_schema.py | 7 +- tests/test_schema.py | 4 +- 19 files changed, 171 insertions(+), 169 deletions(-) delete mode 100644 nomad.yaml rename src/nomad_material_processing/solution/{schema.py => general.py} (98%) diff --git a/nomad.yaml b/nomad.yaml deleted file mode 100644 index 1d169ac..0000000 --- a/nomad.yaml +++ /dev/null @@ -1,10 +0,0 @@ -normalize: - normalizers: - include: - - MetainfoNormalizer -plugins: - include: - - schemas/example - options: - schemas/example: - python_package: nomad_material_processing diff --git a/pyproject.toml b/pyproject.toml index 29f06b2..8c98e3f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,34 +6,30 @@ requires = [ build-backend = "setuptools.build_meta" [project] +classifiers = [ + "Intended Audience :: Developers", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "License :: OSI Approved :: MIT License", +] name = "nomad-material-processing" dynamic = ["version"] description = "A plugin for NOMAD containing base sections for material processing." readme = "README.md" authors = [ + { name = "Sarthak Kapoor", email = 'sarthak.kapoor@physik.hu-berlin.de' }, { name = "Hampus Näsström", email = 'hampus.naesstroem@physik.hu-berlin.de' }, { name = "Andrea Albino", email = 'andrea.albino@physik.hu-berlin.de' }, { name = "Sebastian Brückner", email = 'sebastian.brueckner@ikz-berlin.de' }, ] -requires-python = ">=3.9" -classifiers = [ - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.9", - "License :: OSI Approved :: Apache Software License", -] +license = { file = "LICENSE" } dependencies = [ - "nomad-lab>=1.3.3.dev86", + "nomad-lab>=1.3.4", ] -[project.optional-dependencies] -dev = [ - "pytest", - "ruff", - "structlog>=22.3.0", -] - -[project.license] -file = "LICENSE" [project.urls] "Homepage" = "https://github.com/FAIRmat-NFDI/nomad-material-processing" @@ -42,10 +38,40 @@ file = "LICENSE" [tool.uv] index-url = "https://gitlab.mpcdf.mpg.de/api/v4/projects/2187/packages/pypi/simple" + +[project.optional-dependencies] +dev = [ + "pytest", + "ruff", + "structlog", +] + [tool.ruff] include = ["src/*.py", "tests/*.py"] - -exclude = ["dependencies"] +# Exclude a variety of commonly ignored directories. +exclude = [ + ".bzr", + ".direnv", + ".eggs", + ".git", + ".git-rewrite", + ".hg", + ".mypy_cache", + ".nox", + ".pants.d", + ".pytype", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + "venv", +] # Same as Black. line-length = 88 @@ -53,27 +79,28 @@ indent-width = 4 [tool.ruff.lint] select = [ - "E", # pycodestyle - "W", # pycodestyle - "PL", # pylint + # pycodestyle + "E", + # Pyflakes + "F", + # pyupgrade + "UP", + # isort + "I", + # pylint + "PL", ] + ignore = [ - "E501", # Line too long ({width} > {limit} characters) - "E701", # Multiple statements on one line (colon) - "E731", # Do not assign a lambda expression, use a def - "E402", # Module level import not at top of file - "PLR0911", # Too many return statements - "PLR0912", # Too many branches - "PLR0913", # Too many arguments in function definition - "PLR0915", # Too many statements - "PLR2004", # Magic value used instead of constant - "PLW0603", # Using the global statement - "PLW2901", # redefined-loop-name - "PLR1714", # consider-using-in - "PLR5501", # else-if-used + "F403", # 'from module import *' used; unable to detect undefined names ] + fixable = ["ALL"] +# Allow unused variables when underscore-prefixed. +dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" + +# this is entirely optional, you can remove this if you wish to [tool.ruff.format] # use single quotes for strings. quote-style = "single" @@ -87,10 +114,11 @@ skip-magic-trailing-comma = false # Like Black, automatically detect the appropriate line ending. line-ending = "auto" +[tool.setuptools] +package-dir = { "" = "src" } + [tool.setuptools.packages.find] -where = [ - "src", -] +where = ["src"] [project.entry-points.'nomad.plugin'] diff --git a/src/nomad_material_processing/combinatorial.py b/src/nomad_material_processing/combinatorial.py index 541f987..ff92a35 100644 --- a/src/nomad_material_processing/combinatorial.py +++ b/src/nomad_material_processing/combinatorial.py @@ -1,4 +1,3 @@ -import json # # Copyright The NOMAD Authors. @@ -20,17 +19,8 @@ from typing import ( TYPE_CHECKING, ) + import plotly.graph_objects as go -from nomad.datamodel.metainfo.plot import ( - PlotlyFigure, - PlotSection, -) -from nomad.metainfo import ( - Package, - Quantity, - SubSection, - Section, -) from nomad.datamodel.data import ( ArchiveSection, EntryData, @@ -44,6 +34,16 @@ CompositeSystem, CompositeSystemReference, ) +from nomad.datamodel.metainfo.plot import ( + PlotlyFigure, + PlotSection, +) +from nomad.metainfo import ( + Package, + Quantity, + Section, + SubSection, +) if TYPE_CHECKING: from nomad.datamodel.datamodel import ( @@ -65,8 +65,8 @@ class CombinatorialLibrary(CompositeSystem, EntryData, PlotSection): def plot(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None: from nomad.search import ( - search, MetadataPagination, + search, ) query = { diff --git a/src/nomad_material_processing/crystal_growth.py b/src/nomad_material_processing/crystal_growth.py index e980ecd..1a4c91c 100644 --- a/src/nomad_material_processing/crystal_growth.py +++ b/src/nomad_material_processing/crystal_growth.py @@ -18,10 +18,12 @@ from typing import ( TYPE_CHECKING, ) + from nomad.metainfo import ( Package, Section, ) + from nomad_material_processing.general import ( SampleDeposition, ) diff --git a/src/nomad_material_processing/epitaxy.py b/src/nomad_material_processing/epitaxy.py index 1e25115..501682b 100644 --- a/src/nomad_material_processing/epitaxy.py +++ b/src/nomad_material_processing/epitaxy.py @@ -18,10 +18,12 @@ from typing import ( TYPE_CHECKING, ) + from nomad.metainfo import ( Package, Section, ) + from nomad_material_processing.general import ( SampleDeposition, ) diff --git a/src/nomad_material_processing/general.py b/src/nomad_material_processing/general.py index b81d808..3f82985 100644 --- a/src/nomad_material_processing/general.py +++ b/src/nomad_material_processing/general.py @@ -8,42 +8,32 @@ BoundLogger, ) -from nomad.datamodel.metainfo.annotations import ELNAnnotation, ELNComponentEnum - import numpy as np -from nomad.datamodel.data import EntryData, ArchiveSection - -from nomad.metainfo import ( - SchemaPackage, - Quantity, - SubSection, - Section, - MEnum, -) - +from nomad.config import config +from nomad.datamodel.data import ArchiveSection, EntryData +from nomad.datamodel.metainfo.annotations import ELNAnnotation, ELNComponentEnum from nomad.datamodel.metainfo.basesections import ( - ElementalComposition, CompositeSystem, - SynthesisMethod, - ProcessStep, + CompositeSystemReference, + ElementalComposition, Process, + ProcessStep, + SynthesisMethod, SystemComponent, - CompositeSystemReference, -) -from nomad.datamodel.metainfo.annotations import ( - ELNAnnotation, - ELNComponentEnum, ) from nomad.datamodel.metainfo.workflow import ( Link, ) from nomad.metainfo import ( - SectionProxy, + MEnum, + Quantity, Reference, + SchemaPackage, + Section, + SectionProxy, + SubSection, ) -from nomad.config import config - m_package = SchemaPackage(name='Material Processing') configuration = config.get_plugin_entry_point('nomad_material_processing:schema') diff --git a/src/nomad_material_processing/solution/__init__.py b/src/nomad_material_processing/solution/__init__.py index 56d9976..af1a71a 100644 --- a/src/nomad_material_processing/solution/__init__.py +++ b/src/nomad_material_processing/solution/__init__.py @@ -3,7 +3,7 @@ class SolutionSchemaPackageEntryPoint(SchemaPackageEntryPoint): def load(self): - from nomad_material_processing.solution.schema import m_package + from nomad_material_processing.solution.general import m_package return m_package diff --git a/src/nomad_material_processing/solution/schema.py b/src/nomad_material_processing/solution/general.py similarity index 98% rename from src/nomad_material_processing/solution/schema.py rename to src/nomad_material_processing/solution/general.py index 11f9654..6fac7ce 100644 --- a/src/nomad_material_processing/solution/schema.py +++ b/src/nomad_material_processing/solution/general.py @@ -1,5 +1,5 @@ from typing import TYPE_CHECKING, Union -from nomad.units import ureg + import numpy as np from nomad.datamodel.data import ( ArchiveSection, @@ -7,36 +7,38 @@ ) from nomad.datamodel.metainfo.annotations import ( ELNAnnotation, - SectionProperties, Filter, + SectionProperties, ) from nomad.datamodel.metainfo.basesections import ( Component, CompositeSystem, CompositeSystemReference, - SystemComponent, InstrumentReference, Process, ProcessStep, - PureSubstanceComponent, PubChemPureSubstanceSection, + PureSubstanceComponent, + SystemComponent, ) from nomad.metainfo import ( - SchemaPackage, Datetime, MEnum, Quantity, + SchemaPackage, Section, SubSection, ) +from nomad.units import ureg + from nomad_material_processing.solution.utils import ( create_archive, create_unique_filename, ) if TYPE_CHECKING: - from structlog.stdlib import BoundLogger from nomad.datamodel import EntryArchive + from structlog.stdlib import BoundLogger from nomad.config import config @@ -599,14 +601,13 @@ def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None: if not self.volume: # assume entire volume of the solution is used self.volume = available_volume - else: - if self.volume > available_volume: - logger.warning( - f'The volume used for the "{self.name}" is greater than the ' - 'available volume of the solution. Setting it to the available ' - 'volume.' - ) - self.volume = available_volume + elif self.volume > available_volume: + logger.warning( + f'The volume used for the "{self.name}" is greater than the ' + 'available volume of the solution. Setting it to the available ' + 'volume.' + ) + self.volume = available_volume if self.system.density: self.mass = self.system.density * self.volume super().normalize(archive, logger) diff --git a/src/nomad_material_processing/solution/utils.py b/src/nomad_material_processing/solution/utils.py index 532d49e..6873df5 100644 --- a/src/nomad_material_processing/solution/utils.py +++ b/src/nomad_material_processing/solution/utils.py @@ -15,13 +15,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from typing import TYPE_CHECKING - import json import math -import re +from typing import TYPE_CHECKING -import pandas as pd import yaml if TYPE_CHECKING: @@ -84,7 +81,6 @@ def create_archive( entry_dict, context, filename, file_type, logger, *, overwrite: bool = False ): from nomad.datamodel.context import ClientContext - from nomad.datamodel import EntryArchive file_exists = context.raw_path_exists(filename) dicts_are_equal = None diff --git a/src/nomad_material_processing/utils.py b/src/nomad_material_processing/utils.py index 984132b..9f43b7d 100644 --- a/src/nomad_material_processing/utils.py +++ b/src/nomad_material_processing/utils.py @@ -28,6 +28,7 @@ def get_entry_id_from_file_name(file_name, archive): def create_archive(entity, archive, file_name) -> str: import json + from nomad.datamodel.context import ClientContext if isinstance(archive.m_context, ClientContext): return None diff --git a/src/nomad_material_processing/vapor_deposition/cvd/general.py b/src/nomad_material_processing/vapor_deposition/cvd/general.py index 7a9ca36..8009ad1 100644 --- a/src/nomad_material_processing/vapor_deposition/cvd/general.py +++ b/src/nomad_material_processing/vapor_deposition/cvd/general.py @@ -18,48 +18,37 @@ from typing import ( TYPE_CHECKING, ) -from nomad.metainfo import ( - SchemaPackage, - Section, - SubSection, - Quantity, - MEnum, -) from nomad.datamodel.metainfo.annotations import ( ELNAnnotation, ELNComponentEnum, ) - -from nomad.datamodel.data import ( - ArchiveSection, -) -from nomad.datamodel.metainfo.plot import PlotSection, PlotlyFigure - from nomad.datamodel.metainfo.basesections import ( PubChemPureSubstanceSection, PureSubstanceComponent, ) +from nomad.metainfo import ( + Quantity, + SchemaPackage, + Section, + SubSection, +) + from nomad_material_processing.general import ( TimeSeries, ) from nomad_material_processing.vapor_deposition.general import ( EvaporationSource, - VaporDepositionSource, + GasFlow, MolarFlowRate, - VolumetricFlowRate, Pressure, Temperature, - GasFlow, + VaporDepositionSource, + VolumetricFlowRate, ) if TYPE_CHECKING: - from nomad.datamodel.datamodel import ( - EntryArchive, - ) - from structlog.stdlib import ( - BoundLogger, - ) + pass from nomad.config import config diff --git a/src/nomad_material_processing/vapor_deposition/general.py b/src/nomad_material_processing/vapor_deposition/general.py index 2be3493..65ce41b 100644 --- a/src/nomad_material_processing/vapor_deposition/general.py +++ b/src/nomad_material_processing/vapor_deposition/general.py @@ -18,13 +18,7 @@ from typing import ( TYPE_CHECKING, ) -from nomad.metainfo import ( - SchemaPackage, - Section, - SubSection, - Quantity, - MEnum, -) + from nomad.datamodel.data import ( ArchiveSection, ) @@ -33,12 +27,12 @@ ELNComponentEnum, ) from nomad.datamodel.metainfo.basesections import ( - Entity, ActivityStep, - PureSubstanceSection, Component, CompositeSystemReference, + Entity, PubChemPureSubstanceSection, + PureSubstanceSection, ) from nomad.datamodel.metainfo.plot import ( PlotSection, @@ -47,12 +41,20 @@ Link, Task, ) +from nomad.metainfo import ( + MEnum, + Quantity, + SchemaPackage, + Section, + SubSection, +) + from nomad_material_processing.general import ( + Geometry, SampleDeposition, - ThinFilmStackReference, ThinFilmReference, + ThinFilmStackReference, TimeSeries, - Geometry, ) if TYPE_CHECKING: diff --git a/src/nomad_material_processing/vapor_deposition/pvd/general.py b/src/nomad_material_processing/vapor_deposition/pvd/general.py index 4cc3e16..a2f5ee4 100644 --- a/src/nomad_material_processing/vapor_deposition/pvd/general.py +++ b/src/nomad_material_processing/vapor_deposition/pvd/general.py @@ -18,16 +18,17 @@ from typing import ( TYPE_CHECKING, ) + +from nomad.datamodel.metainfo.annotations import ( + ELNAnnotation, + ELNComponentEnum, +) from nomad.metainfo import ( + MEnum, + Quantity, SchemaPackage, Section, SubSection, - Quantity, - MEnum, -) -from nomad.datamodel.metainfo.annotations import ( - ELNAnnotation, - ELNComponentEnum, ) from nomad_material_processing.general import ( @@ -35,10 +36,10 @@ ) from nomad_material_processing.vapor_deposition.general import ( EvaporationSource, - VaporDepositionSource, SampleParameters, - VaporDepositionStep, VaporDeposition, + VaporDepositionSource, + VaporDepositionStep, ) if TYPE_CHECKING: diff --git a/src/nomad_material_processing/vapor_deposition/pvd/mbe.py b/src/nomad_material_processing/vapor_deposition/pvd/mbe.py index d688616..ddd6916 100644 --- a/src/nomad_material_processing/vapor_deposition/pvd/mbe.py +++ b/src/nomad_material_processing/vapor_deposition/pvd/mbe.py @@ -16,17 +16,16 @@ # limitations under the License. # +from nomad.config import config from nomad.metainfo import ( SchemaPackage, - Quantity, Section, ) + from nomad_material_processing.vapor_deposition.pvd.general import ( PhysicalVaporDeposition, ) -from nomad.config import config - m_package = SchemaPackage(name='Molecular Beam Epitaxy') configuration = config.get_plugin_entry_point( diff --git a/src/nomad_material_processing/vapor_deposition/pvd/pld.py b/src/nomad_material_processing/vapor_deposition/pvd/pld.py index a149fd0..c10a25c 100644 --- a/src/nomad_material_processing/vapor_deposition/pvd/pld.py +++ b/src/nomad_material_processing/vapor_deposition/pvd/pld.py @@ -18,27 +18,28 @@ from typing import ( TYPE_CHECKING, ) -from nomad.metainfo import ( - SchemaPackage, - Section, - SubSection, - Quantity, -) + from nomad.datamodel.metainfo.annotations import ( ELNAnnotation, ELNComponentEnum, ) from nomad.datamodel.metainfo.basesections import ( CompositeSystem, - SystemComponent, ReadableIdentifiers, + SystemComponent, +) +from nomad.metainfo import ( + Quantity, + SchemaPackage, + Section, + SubSection, ) from nomad_material_processing.vapor_deposition.pvd.general import ( + PhysicalVaporDeposition, PVDEvaporationSource, PVDSource, PVDStep, - PhysicalVaporDeposition, ) if TYPE_CHECKING: diff --git a/src/nomad_material_processing/vapor_deposition/pvd/sputtering.py b/src/nomad_material_processing/vapor_deposition/pvd/sputtering.py index 5633560..965a623 100644 --- a/src/nomad_material_processing/vapor_deposition/pvd/sputtering.py +++ b/src/nomad_material_processing/vapor_deposition/pvd/sputtering.py @@ -18,10 +18,11 @@ from typing import ( TYPE_CHECKING, ) + from nomad.metainfo import ( + Quantity, SchemaPackage, Section, - Quantity, ) from nomad_material_processing.vapor_deposition.pvd.general import ( diff --git a/src/nomad_material_processing/vapor_deposition/pvd/thermal.py b/src/nomad_material_processing/vapor_deposition/pvd/thermal.py index 06a7786..1099dd7 100644 --- a/src/nomad_material_processing/vapor_deposition/pvd/thermal.py +++ b/src/nomad_material_processing/vapor_deposition/pvd/thermal.py @@ -18,26 +18,26 @@ from typing import ( TYPE_CHECKING, ) + +from nomad.datamodel.metainfo.annotations import ( + ELNAnnotation, + ELNComponentEnum, +) from nomad.metainfo import ( + Quantity, SchemaPackage, Section, SubSection, - Quantity, ) from nomad_material_processing.general import ( TimeSeries, ) from nomad_material_processing.vapor_deposition.pvd.general import ( + PhysicalVaporDeposition, PVDEvaporationSource, PVDSource, PVDStep, - PhysicalVaporDeposition, -) - -from nomad.datamodel.metainfo.annotations import ( - ELNAnnotation, - ELNComponentEnum, ) if TYPE_CHECKING: diff --git a/tests/solution/test_solution_schema.py b/tests/solution/test_solution_schema.py index ae90308..4f55727 100644 --- a/tests/solution/test_solution_schema.py +++ b/tests/solution/test_solution_schema.py @@ -1,10 +1,9 @@ import pytest - -from nomad.client import parse, normalize_all -from nomad.units import ureg +from nomad.client import normalize_all, parse from nomad.datamodel.metainfo.basesections import PubChemPureSubstanceSection +from nomad.units import ureg -from nomad_material_processing.solution.schema import ( +from nomad_material_processing.solution.general import ( Solution, SolutionComponent, SolutionComponentReference, diff --git a/tests/test_schema.py b/tests/test_schema.py index b9ca038..116810d 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -1,7 +1,7 @@ -import os.path import glob +import os.path -from nomad.client import parse, normalize_all +from nomad.client import normalize_all, parse def test_schema():