-
Notifications
You must be signed in to change notification settings - Fork 1
added the config system #26
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
hl1
wants to merge
2
commits into
master
Choose a base branch
from
restructure
base: master
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 all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
app_name: OpenFDA | ||
secret_key: a passphrase for peppering | ||
base_dir: !PY base_dir | ||
app_dir: !PY app_dir | ||
data_dir: !PY data_dir | ||
log_dir: !PY log_dir | ||
fda_data_url: https://download.open.fda.gov/drug/ndc/drug-ndc-0001-of-0001.json.zip | ||
server: | ||
host: 0.0.0.0 | ||
sqllite_db_name: drugs.db | ||
json_file_name: !PY json_file_name |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env python | ||
"""apps.utils.config: imports and finalize config.yml""" | ||
|
||
from pathlib import Path | ||
import glob | ||
import yaml | ||
import os | ||
|
||
class PyVar(yaml.YAMLObject): | ||
""" | ||
a class to create a custom !PY tag in yaml | ||
The !PY tag allows calling python code stored in a dictionary | ||
""" | ||
# this is a PYYAML requirment and is case sensitive | ||
yaml_tag = u'!PY' | ||
|
||
def __init__(self): | ||
""" | ||
starts with empty dictionary | ||
""" | ||
self.py_dict = {} | ||
|
||
def get(self,key): | ||
""" | ||
retrieves a value from the dictionary | ||
""" | ||
return self.py_dict[key] | ||
|
||
def add(self,key,value): | ||
""" | ||
adds a new key value pair to a dictionary | ||
""" | ||
self.py_dict[key] = value | ||
|
||
|
||
# construct all they key value pairs that can be referenced by the yaml file | ||
# creating a function like this is required for yaml.SafeLoader.add_constructor | ||
def yaml_construct(loader,node): | ||
c = PyVar() | ||
## start adding python variables here | ||
c.add('base_dir',Path(__file__).resolve(strict=True).parent.parent.parent.absolute()) | ||
c.add('app_dir', c.get('base_dir') / 'app') | ||
c.add('data_dir', c.get('app_dir') / 'data') | ||
c.add('log_dir', c.get('app_dir') / 'log') | ||
c.add('json_file_name',os.path.basename(max(glob.glob(str(c.get('data_dir')) + '/*.json'), key=os.path.getctime))) | ||
return c.get(node.value) | ||
|
||
# Required for safe_load | ||
yaml.SafeLoader.add_constructor('!PY', yaml_construct) | ||
|
||
# config.yml location | ||
configyml_path = Path(__file__).resolve(strict=True).parent.parent.absolute() / "config.yml" | ||
|
||
# load config.yml | ||
config = yaml.safe_load(open(configyml_path)) | ||
|
||
if __name__ == "__main__": | ||
print(config) |
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.
I have a drugs-ndc.json in the data folder however the following error occurs:
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.
Correct. this is an independent system that could be added to master without impacting anything. integration is coming.
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.
hmmm... is the data folder in
/app/data
or/data
?