Skip to content
Snippets Groups Projects
Commit acefdd5d authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Merge branch '883-unit-not-defined-error' into 'v1.1.1'

Resolve ""Unit not defined" error"

See merge request !701
parents ede86576 1107acc5
Branches
Tags
1 merge request!701Resolve ""Unit not defined" error"
Pipeline #133989 passed
...@@ -469,43 +469,11 @@ def units(ctx): ...@@ -469,43 +469,11 @@ def units(ctx):
value['definition'] = str(a).replace('**', '^') value['definition'] = str(a).replace('**', '^')
value['offset'] = b / a.magnitude value['offset'] = b / a.magnitude
# Reorder unit list so that base dimensions come first. Units are # Reorder unit list so that base dimensions come first. Units are registered
# registered in the list order and base units need to be registered before # in the list order and base units need to be registered before derived
# derived ones. # ones.
unit_list.sort(key=lambda x: 0 if x.get('definition') is None else 1) unit_list.sort(key=lambda x: 0 if x.get('definition') is None else 1)
# Go through the metainfo and check that all units are defined. Note that
# this will break if complex derived units are used in the metainfo. In
# this case they can only be validated in a GUI test.
unit_names = set()
for unit in unit_list:
unit_names.add(unit['name'])
for alias in unit.get('aliases', []):
unit_names.add(alias)
all_metainfo = _all_metainfo_packages()
units = set()
packages = all_metainfo.m_to_dict(with_meta=True)['packages']
for package in packages:
sections = package.get('section_definitions', [])
for section in sections:
quantities = section.get('quantities', [])
for quantity in quantities:
unit = quantity.get('unit')
if unit is not None:
parts = unit.split()
for part in parts:
is_operator = part in {'/', '**', '*'}
is_number = True
try:
int(part)
except Exception:
is_number = False
if not is_operator and not is_number:
units.add(part)
for unit in units:
assert unit in unit_names, 'The unit "{}" is not defined in the unit definitions.'.format(unit)
# Print unit conversion table and unit systems as a Javascript source file # Print unit conversion table and unit systems as a Javascript source file
output = '''/* output = '''/*
* Copyright The NOMAD Authors. * Copyright The NOMAD Authors.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment