Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
38 changes: 32 additions & 6 deletions src/py/esse/functionals.py → functionals.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import os
import sys
import json
import errno

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We stopped using the force_symlink function so this import is no longer needed.

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")
DATA_FILENAME = os.path.join(BASE_DIR, "src/py/esse/data", REL_DIR, "dft_unit_functionals.json")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the schema directory itself is where the symlinking occurs, DATA_FILENAME should no longer be necessary.


SCHEMA_WITH_PROPERTIES_TEMPLATE = Template("""{
"properties": {
Expand All @@ -28,6 +31,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 +51,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 +62,13 @@ 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)
remove(DATA_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-compile -p es2015 src/js:lib/js",
"test": "mocha $NODE_DEBUG_OPTION --bail --require babel-register src/js/esse/tests/*.js"
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