Skip to content

Commit

Permalink
Fix entry point with new MatchingParserInterface
Browse files Browse the repository at this point in the history
Add testing files from electronicparsers
  • Loading branch information
JosePizarro3 committed Sep 26, 2024
1 parent ef1759a commit c3ff735
Show file tree
Hide file tree
Showing 61 changed files with 1,146,200 additions and 48 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ Alternatively and only valid for your local NOMAD installation, you can modify `
plugins:
entry_points:
include:
- ["nomad_parser_vasp.parsers:nomad_parser_vasp_plugin"]
- ["nomad_parser_vasp.schema_packages:nomad_parser_vasp_schema"]
- ["nomad_parser_vasp.parsers:parser_entry_point"]
- ["nomad_parser_vasp.schema_packages:schema_package_entry_point"]
```
**Note!**
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ maintainers = [
]
license = { file = "LICENSE" }
dependencies = [
"nomad-lab>=1.3.0",
"nomad-lab@git+https://gitlab.mpcdf.mpg.de/nomad-lab/nomad-FAIR.git@ea0e5cbc632a514ea4d7e0bca1fab105d452f94c",
"nomad-simulations@git+https://github.com/nomad-coe/nomad-simulations.git@7c101b80f14d500d6c8bc266a001444b4ba35ea9",
"python-magic-bin; sys_platform == 'win32'",
]
Expand Down
39 changes: 31 additions & 8 deletions src/nomad_parser_vasp/parsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,40 @@
from pydantic import Field


class NewParserEntryPoint(ParserEntryPoint):
parameter: int = Field(0, description='Custom configuration parameter')
class SimulationParserEntryPoint(ParserEntryPoint):
parser_class_name: str = Field(
description="""
The fully qualified name of the Python class that implements the parser.
This class must have a function `def parse(self, mainfile, archive, logger)`.
"""
)
level: int = Field(
0,
description="""
Order of execution of parser with respect to other parsers.
""",
)

def load(self):
from nomad_parser_vasp.parsers.parser import NewParser
from nomad.parsing import MatchingParserInterface

return NewParser(**self.dict())
return MatchingParserInterface(**self.dict())


parser_entry_point = NewParserEntryPoint(
name='NewParser',
description='New parser entry point configuration.',
mainfile_name_re='.*\.newmainfilename',
parser_entry_point = SimulationParserEntryPoint(
name='parsers/vasp',
aliases=['parsers/vasp'],
description='Entry point for the VASP parser.',
python_package='nomad_parser_vasp.parsers',
parser_class_name='nomad_parser_vasp.parsers.parser.VASPParser',
level=0,
supported_compressions=['gz', 'bz2', 'xz'],
mainfile_mime_re='(application/.*)|(text/.*)',
mainfile_name_re='.*[^/]*xml[^/]*',
mainfile_contents_re=(
r'^\s*<\?xml version="1\.0" encoding="ISO-8859-1"\?>\s*?\s*<modeling>?\s*<generator>?\s*<i '
r'name="program" type="string">\s*vasp\s*</i>?|^\svasp[\.\d]+.+?(?:\(build|complex)[\s\S]+?executed '
r'on'
),
# mainfile_alternative=True,
)
17 changes: 7 additions & 10 deletions src/nomad_parser_vasp/parsers/parser.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from typing import (
TYPE_CHECKING,
)
Expand All @@ -11,22 +12,18 @@
)

from nomad.config import config
from nomad.datamodel.metainfo.workflow import Workflow
from nomad.parsing.parser import MatchingParser

configuration = config.get_plugin_entry_point(
'nomad_parser_vasp.parsers:parser_entry_point'
)


class NewParser(MatchingParser):
class VASPParser(MatchingParser):
def parse(
self,
mainfile: str,
archive: 'EntryArchive',
logger: 'BoundLogger',
child_archives: dict[str, 'EntryArchive'] = None,
self, filepath: str, archive: 'EntryArchive', logger: 'BoundLogger'
) -> None:
logger.info('NewParser.parse', parameter=configuration.parameter)

archive.workflow2 = Workflow(name='test')
self.mainfile = filepath
self.maindir = os.path.dirname(self.mainfile)
self.basename = os.path.basename(self.mainfile)
self.archive = archive
3 changes: 3 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from nomad import utils

logger = utils.get_logger(__name__)
Loading

1 comment on commit c3ff735

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/nomad_parser_vasp/parsers
   __init__.py9278%20–22
   parser.py14657%7–10, 26–29
src/nomad_parser_vasp/schema_packages
   __init__.py8275%9–11
   schema_package.py18180%1–38
TOTAL492843% 

Tests Skipped Failures Errors Time
1 0 💤 0 ❌ 0 🔥 9.788s ⏱️

Please sign in to comment.