Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions src/py/esse/functionals.py → functionals.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os
import sys
import json
from string import Template
import os
from esse.utils import read_json_file, dump_json_file

DIR = os.path.dirname(__file__)
UNIT_FUNCTIONALS_PATH = os.path.join(DIR, "data/schema/models_directory/pb/qm/dft")
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
REL_DIR = "schema/models_directory/pb/qm/dft"
UNIT_FUNCTIONALS_PATH = os.path.join(BASE_DIR, REL_DIR)
PROTOTYPE_FILENAME = os.path.join(UNIT_FUNCTIONALS_PATH, "dft_unit_functionals_proto.json")
UNIT_FILENAME = os.path.join(UNIT_FUNCTIONALS_PATH, "dft_unit_functionals.json")

Expand All @@ -28,6 +29,18 @@
}
}""")


def remove(fpath):
try:
os.unlink(fpath)
except FileNotFoundError:
pass
try:
os.remove(fpath)
except FileNotFoundError:
pass


def generate_dft_unit_functionals():
"""
Generate list of functionals suitable for validation by 'oneOf'.
Expand All @@ -36,7 +49,9 @@ def generate_dft_unit_functionals():
to read and prone to errors. Thus, it is generated automatically from
a prototype file that is easier to maintain.
"""
proto = read_json_file(PROTOTYPE_FILENAME)
with open(PROTOTYPE_FILENAME, "r") as f:
proto = json.loads(f.read())

del proto["description"]
output = {}
for rung, configs in proto.items():
Expand All @@ -45,4 +60,12 @@ def generate_dft_unit_functionals():
o["oneOf"].append(json.loads(SCHEMA_WITH_PROPERTIES_TEMPLATE.substitute(config)))
output[rung] = o

dump_json_file(UNIT_FILENAME, output)
remove(UNIT_FILENAME)

with open(UNIT_FILENAME, "w") as f:
f.write("".join((json.dumps(output, separators=(',', ': '), indent=4, sort_keys=True), "\n")))


if __name__ == "__main__":
# add comment
generate_dft_unit_functionals()
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "2022.1.9-2",
"description": "Exabyte Source of Schemas and Examples",
"scripts": {
"preinstall": "python functionals.py",
"prepublishOnly": "rm -rf lib; npm run transpile",
"transpile": "mkdir -p lib; babel src/js --out-dir lib/js",
"test": "nyc --reporter=text mocha --bail --require @babel/register src/js/esse/tests",
Expand Down
3 changes: 0 additions & 3 deletions schema/models_directory/pb/qm/dft/dft_unit_functionals.json

This file was deleted.

5 changes: 5 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import os
from setuptools import find_packages, setup
import subprocess as sp


BASE_DIR = os.path.abspath(os.path.dirname(__file__))
sp.check_call(['python', os.path.join(BASE_DIR, 'functionals.py')])


def get_files_by_path(path):
Expand Down