-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathversions.py
74 lines (60 loc) · 2.14 KB
/
versions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""
A simple program to construct the input and ouput Quantum Chemistry Schema's
from the development branch
"""
import json
try:
from pathlib import Path
except ImportError:
from pathlib2 import Path
_data_path = Path(__file__).parent.resolve() / "data"
_aliases = {
"input": ["input", "AtomicInput"],
"output": ["output", "AtomicResult"],
"molecule": ["molecule", "topology", "Molecule"],
"basis": ["basis", "BasisSet"],
"properties": ["properties", "AtomicResultProperties"],
"provenance": ["provenance", "Provenance"],
}
_laliases = {k: [v2.lower() for v2 in v] for k, v in _aliases.items()}
_versions_list = {
"input": [1, 2, "dev"],
"output": [1, 2, "dev"],
"molecule": [1, 2, "dev"],
"basis": ["dev"],
"properties": ["dev"],
"provenance": ["dev"],
}
_sversions_list = {k: [str(v2) for v2 in v] for k, v in _versions_list.items()}
def list_versions(schema_type):
"""
Lists all current JSON schema versions.
"""
for sk, aliases in _laliases.items():
if schema_type.lower() in aliases:
return _versions_list[sk]
raise KeyError("Schema type should be among {} (+aliases), not '{}'.".format(list(_aliases.keys()), schema_type))
def get_schema(schema_type, version="dev"):
"""
Returns the requested schema (input or output) for a given version number.
"""
# temporary
if version == "dev":
version = 2
for sk, aliases in _laliases.items():
if schema_type.lower() in aliases:
if str(version) in _sversions_list[sk]:
if version == "dev" or int(version) > 2:
fname = _aliases[sk][-1]
else: # v1, v2
fname = "qc_schema_" + sk
break
else:
raise KeyError("Schema version should be among {}, not '{}'.".format(_versions_list[sk], version))
else:
raise KeyError(
"Schema type should be among {} (+aliases), not '{}'.".format(list(_aliases.keys()), schema_type)
)
fpath = _data_path / ("v" + str(version)) / (fname + ".schema")
ret = json.loads(fpath.read_text())
return ret