Commit 5eb86a04 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Improved legacy metainfo support.

parent 783a9e4f
Pipeline #79214 failed with stages
in 29 minutes and 46 seconds
......@@ -29,3 +29,4 @@ build/
dist/
setup.json
parser.osio.log
gui/src/metainfo.json
Subproject commit 56e9412d0d322fd88240fe2af41716a0016831c7
Subproject commit e7077c9a824e01b45b0e4989858ecd35f59f4cc7
Subproject commit 7decbdcf25ef48b019bde17c472f54d65a124c9a
Subproject commit cc6c9545300cf6ea3347357fedffc6798415a299
Subproject commit 059d4c7f1a452383d67f0ecf0c9bc267580083dc
Subproject commit fa54fe567a1250af3009ecc9692d14c64a399f29
Subproject commit f7f156204c16b54e4df998a8a275bcf4a5aaf901
Subproject commit 2310b63ff3904ddd6f912c32789568787c6ab250
Subproject commit 8d896ede93e794d0fdb905e42281ef7c871bc05d
Subproject commit b7d913f0d8f82a9bb564e346bb60f66008ac791b
Subproject commit 97b653e3fe695775f53a96249a0bb9ad694ef742
Subproject commit a741cfe607e9dfd1f2d65aeddbcc4bc5a15bbc13
Subproject commit 85cc99b320454f8c8a68bdf376e128c156cf2ac2
Subproject commit 7f5fc6a358dc7e40e716cc5205fa04e8cf9c6d6c
Subproject commit cf843eda3e4650bc240eb0d1a1ab5b0cea6dda96
Subproject commit afdd0937aab2681ca3912cfd9d95c7633fdcd7b9
......@@ -102,21 +102,12 @@ class LegacyMetainfoResource(Resource):
Other required packages might also be returned, e.g. a parser might organize its
definitions in multiple packages.
'''
package = metainfo_package_name
if package.endswith('.nomadmetainfo.json'):
package = package[:-19]
if package.endswith('.json'):
package = package[:-5]
try:
python_package_name, _ = python_package_mapping(package)
python_package_name = '.'.join(python_package_name.split('.')[:-1])
python_module = importlib.import_module(python_package_name)
metainfo = getattr(python_module, 'm_env')
metainfo = LegacyMetainfoEnvironment.from_legacy_package_path(metainfo_package_name)
except (ImportError, KeyError, FileNotFoundError, AttributeError):
abort(404, message='Metainfo package %s does not exist.' % package)
abort(404, message='Metainfo package %s does not exist.' % metainfo_package_name)
if isinstance(metainfo, LegacyMetainfoEnvironment):
return metainfo.to_legacy_dict(metainfo.packages)
else:
abort(404, message='Metainfo package %s is not a legacy package.' % package)
abort(404, message='Metainfo package %s is not a legacy package.' % metainfo_package_name)
......@@ -43,6 +43,22 @@ def qa(skip_tests: bool, exitfirst: bool):
sys.exit(ret_code)
@dev.command(help='Generates a JSON with all metainfo.')
def metainfo():
import json
from nomad.metainfo import Package
from nomad.parsing.parsers import parsers
# Ensure all metainfo is loaded
for parser in parsers:
_ = parser.metainfo_env
data = {key: value.m_to_dict() for key, value in Package.registry.items()}
print(json.dumps(data, indent=2))
@dev.command(help='Generates source-code for the new metainfo from .json files of the old.')
@click.argument('path', nargs=-1)
def legacy_metainfo(path):
......
......@@ -22,6 +22,7 @@ from typing import cast, Dict, List, Union, Any, Set, Iterable, Tuple
import numpy as np
from pint.errors import UndefinedUnitError
import os.path
import importlib
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl, InfoKindEnv
......@@ -105,6 +106,22 @@ class LegacyMetainfoEnvironment(Environment):
the environment.
'''
@staticmethod
def from_legacy_package_path(path):
metainfo_package_name = os.path.basename(path)
package = metainfo_package_name
if package.endswith('.nomadmetainfo.json'):
package = package[:-19]
if package.endswith('.json'):
package = package[:-5]
python_package_name, _ = python_package_mapping(package)
python_package_name = '.'.join(python_package_name.split('.')[:-1])
python_module = importlib.import_module(python_package_name)
metainfo = getattr(python_module, 'm_env')
return metainfo
legacy_package_name = Quantity(type=str)
def __init__(self, *args, **kwargs):
......
......@@ -23,7 +23,7 @@ from elasticsearch.exceptions import NotFoundError
from datetime import datetime
import json
from nomad import config, datamodel, infrastructure, datamodel, utils
from nomad import config, datamodel, infrastructure, utils
from nomad.metainfo.search_extension import search_quantities, metrics, order_default_quantities
......
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