-
Notifications
You must be signed in to change notification settings - Fork 4
Feature/sof 5666 - generate dft_functionals.json in install hook
#197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
adewyer
wants to merge
6
commits into
epic/SOF-5386
Choose a base branch
from
feature/SOF-5666
base: epic/SOF-5386
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1bbb983
generate JSON schema for dft_unit_functionals instead of tracking is …
adewyer e27edd4
moved functionals.py from esse/src/py/esse to esse
adewyer 7120bea
removed dft_unit_functionals.json because we will be generating it on…
adewyer f77b72e
removed uneccessary lines
adewyer e69f570
Merge branch 'dev' into feature/SOF-5666
adewyer 9a4bd75
Merge branch 'epic/SOF-5386' into feature/SOF-5666
adewyer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,15 @@ | ||
| import os | ||
| import sys | ||
| import json | ||
| import errno | ||
| 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") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the |
||
|
|
||
| SCHEMA_WITH_PROPERTIES_TEMPLATE = Template("""{ | ||
| "properties": { | ||
|
|
@@ -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'. | ||
|
|
@@ -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(): | ||
|
|
@@ -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() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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_symlinkfunction so this import is no longer needed.