Commit e7b711ea authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Resolve "Plug-and-play metainfo not working on v1.1.0"

parent 51fbe2ca
......@@ -68,6 +68,9 @@ app.mount(app_base, WSGIMiddleware(flask_app))
@app.on_event('startup')
async def startup_event():
from nomad.parsing.parsers import import_all_parsers
import_all_parsers()
from nomad import infrastructure
# each subprocess is supposed disconnect connect again: https://jira.mongodb.org/browse/PYTHON-2090
try:
......
......@@ -77,8 +77,8 @@ def _all_metainfo_packages():
# TODO similar to before, due to lazyloading, we need to explicily access parsers
# to actually import all parsers and indirectly all metainfo packages
from nomad.parsing import parsers
parsers.parsers
from nomad.parsing.parsers import import_all_parsers
import_all_parsers()
# Create the ES mapping to populate ES annoations with search keys.
from nomad.search import entry_type
......
......@@ -237,18 +237,27 @@ class MatchingParserInterface(MatchingParser):
def mainfile_parser(self):
if self._mainfile_parser is None:
try:
module_path, parser_class = self._parser_class_name.rsplit('.', 1)
module = importlib.import_module(module_path)
self._mainfile_parser = getattr(module, parser_class)()
Parser = self.import_parser_class()
self._mainfile_parser = Parser()
except Exception as e:
logger = utils.get_logger(__name__)
logger.error('Error importing parser.', exc_info=e)
logger.error('cannot instantiate parser.', exc_info=e)
raise e
return self._mainfile_parser
def parse(self, mainfile: str, archive: EntryArchive, logger=None):
self.mainfile_parser.parse(mainfile, archive, logger)
def import_parser_class(self):
try:
module_path, parser_class = self._parser_class_name.rsplit('.', 1)
module = importlib.import_module(module_path)
return getattr(module, parser_class)
except Exception as e:
logger = utils.get_logger(__name__)
logger.error('cannot import parser', exc_info=e)
raise e
class ArchiveParser(MatchingParser):
def __init__(self):
......
......@@ -545,3 +545,13 @@ for parser in parsers:
code_names = sorted(set(code_names), key=lambda code_name: code_name.lower())
results.Simulation.program_name.a_elasticsearch[0].values = code_names + [
config.services.unavailable_value, config.services.not_processed_value]
def import_all_parsers():
'''
Imports all the parsers. This will instantiate all parser metainfo as a side
effect.
'''
for parser in parsers:
if isinstance(parser, MatchingParserInterface):
parser.import_parser_class()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment