diff --git a/README.md b/README.md index d1fd3fb..a2bde44 100644 --- a/README.md +++ b/README.md @@ -73,8 +73,9 @@ Will create the following python file: # limitations under the License. # -from structlog.stdlib import ( - BoundLogger, +from nomad.datamodel.data import ArchiveSection +from typing import ( + TYPE_CHECKING, ) from nomad.metainfo import ( Package, @@ -85,6 +86,13 @@ from nomad.metainfo import ( from nomad.datamodel.data import ( ArchiveSection, ) +if TYPE_CHECKING: + from nomad.datamodel.datamodel import ( + EntryArchive, + ) + from structlog.stdlib import ( + BoundLogger, + ) m_package = Package(name='Example Schema') @@ -114,7 +122,7 @@ class Activity(ArchiveSection): }, ) - def normalize(self, archive, logger: BoundLogger) -> None: + def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None: ''' The normalizer for the `Activity` class. @@ -132,7 +140,7 @@ class Entity(ArchiveSection): ''' m_def = Section() - def normalize(self, archive, logger: BoundLogger) -> None: + def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None: ''' The normalizer for the `Entity` class. diff --git a/example/__init__.py b/example/example.py similarity index 84% rename from example/__init__.py rename to example/example.py index 9cc0759..c665678 100644 --- a/example/__init__.py +++ b/example/example.py @@ -16,8 +16,9 @@ # limitations under the License. # -from structlog.stdlib import ( - BoundLogger, +from nomad.datamodel.data import ArchiveSection +from typing import ( + TYPE_CHECKING, ) from nomad.metainfo import ( Package, @@ -28,6 +29,13 @@ from nomad.datamodel.data import ( ArchiveSection, ) +if TYPE_CHECKING: + from nomad.datamodel.datamodel import ( + EntryArchive, + ) + from structlog.stdlib import ( + BoundLogger, + ) m_package = Package(name='Example Schema') @@ -57,7 +65,7 @@ class Activity(ArchiveSection): }, ) - def normalize(self, archive, logger: BoundLogger) -> None: + def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None: ''' The normalizer for the `Activity` class. @@ -75,7 +83,7 @@ class Entity(ArchiveSection): ''' m_def = Section() - def normalize(self, archive, logger: BoundLogger) -> None: + def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None: ''' The normalizer for the `Entity` class. diff --git a/src/metainfoyaml2py/metainfoyaml2py.py b/src/metainfoyaml2py/metainfoyaml2py.py index a9013b4..ce05f2a 100644 --- a/src/metainfoyaml2py/metainfoyaml2py.py +++ b/src/metainfoyaml2py/metainfoyaml2py.py @@ -396,7 +396,7 @@ def yaml2py(yaml_path: str, output_dir: str = '', normalizers: bool = False, flake8_cleaned_code = autoflake.fix_code( code, remove_all_unused_imports=True) cleaned_code = autopep8.fix_code( - flake8_cleaned_code, options={'aggressive': 2}) + flake8_cleaned_code, options={'aggressive': 2, 'max_line_length': 90}) # write the code to file file.write(cleaned_code) diff --git a/src/metainfoyaml2py/resources/standard_file_content.yaml b/src/metainfoyaml2py/resources/standard_file_content.yaml index 6ad3d79..a16682f 100644 --- a/src/metainfoyaml2py/resources/standard_file_content.yaml +++ b/src/metainfoyaml2py/resources/standard_file_content.yaml @@ -18,8 +18,8 @@ header: | # imports: | import numpy as np - from structlog.stdlib import ( - BoundLogger, + from typing import ( + TYPE_CHECKING, ) from nomad.metainfo import ( MSection, @@ -35,12 +35,19 @@ imports: | EntryData, ArchiveSection, ) + if TYPE_CHECKING: + from nomad.datamodel.datamodel import ( + EntryArchive, + ) + from structlog.stdlib import ( + BoundLogger, + ) package_name: | m_package = Package(name='%s') footer: | m_package.__init_metainfo__() normalizer: | - def normalize(self, archive, logger: BoundLogger) -> None: + def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None: ''' The normalizer for the `%s` class.