Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove conditional type checking #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
from typing import (
TYPE_CHECKING,
)

if TYPE_CHECKING:
from nomad.datamodel.datamodel import (
EntryArchive,
)
from structlog.stdlib import (
BoundLogger,
)

from nomad.config import config
from nomad.datamodel.datamodel import EntryArchive
from nomad.normalizing import Normalizer
from structlog.stdlib import BoundLogger

configuration = config.get_plugin_entry_point(
'nomad_{{cookiecutter.module_name}}.normalizers:mynormalizer'
)


class MyNormalizer(Normalizer):
def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
def normalize(self, archive: EntryArchive, logger: BoundLogger) -> None:
super().normalize(archive, logger)
logger.info('MyNormalizer.normalize', parameter=configuration.parameter)
if archive.results and archive.results.material:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
from typing import (
TYPE_CHECKING,
)

if TYPE_CHECKING:
from nomad.datamodel.datamodel import (
EntryArchive,
)
from structlog.stdlib import (
BoundLogger,
)

from nomad.config import config
from nomad.datamodel.datamodel import EntryArchive
from nomad.datamodel.results import Material, Results
from nomad.normalizing import Normalizer
from nomad.parsing.parser import MatchingParser
from structlog.stdlib import BoundLogger

configuration = config.get_plugin_entry_point(
'nomad_{{cookiecutter.module_name}}.parsers:myparser'
Expand All @@ -23,8 +14,8 @@ class MyParser(MatchingParser):
def parse(
self,
mainfile: str,
archive: 'EntryArchive',
logger: 'BoundLogger',
archive: EntryArchive,
logger: BoundLogger,
child_archives: dict[str, 'EntryArchive'] = None,
) -> None:
logger.info('MyParser.parse', parameter=configuration.parameter)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
from typing import (
TYPE_CHECKING,
)

if TYPE_CHECKING:
from nomad.datamodel.datamodel import (
EntryArchive,
)
from structlog.stdlib import (
BoundLogger,
)

from nomad.config import config
from nomad.datamodel.data import Schema
from nomad.datamodel.datamodel import EntryArchive
from nomad.datamodel.metainfo.annotations import ELNAnnotation, ELNComponentEnum
from nomad.metainfo import Quantity, SchemaPackage
from structlog.stdlib import BoundLogger

configuration = config.get_plugin_entry_point(
'nomad_{{cookiecutter.module_name}}.schema_packages:mypackage'
Expand All @@ -28,7 +18,7 @@ class MySchema(Schema):
)
message = Quantity(type=str)

def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
def normalize(self, archive: EntryArchive, logger: BoundLogger) -> None:
super().normalize(archive, logger)

logger.info('MySchema.normalize', parameter=configuration.parameter)
Expand Down
4 changes: 2 additions & 2 deletions nomad-{{cookiecutter.plugin_name}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ maintainers = [
{ name = "{{cookiecutter.full_name}}", email = "{{cookiecutter.email}}" },
]
license = { file = "LICENSE" }
dependencies = ["nomad-lab>=1.2.2dev578"]
dependencies = ["nomad-lab>=1.2.2dev578", "structlog"]

[project.urls]
Repository = "https://github.com/{{cookiecutter.github_username}}/nomad-{{cookiecutter.plugin_name}}"

[project.optional-dependencies]
dev = ["ruff", "pytest", "structlog"]
dev = ["ruff", "pytest"]

[tool.ruff]
# Exclude a variety of commonly ignored directories.
Expand Down