Skip to content

Commit 18cdf4e

Browse files
committed
consoliate scheamtic config variables in flask config dictionary
1 parent 7d1de2c commit 18cdf4e

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

api/__init__.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,18 @@
44

55
from schematic import CONFIG
66

7-
# path to `config.yml` file as constant
8-
CONFIG_PATH = os.path.abspath(os.path.join(__file__, "../../config.yml"))
9-
107

118
def create_app():
129
connexionapp = connexion.FlaskApp(__name__, specification_dir="openapi/")
1310
connexionapp.add_api("api.yaml")
11+
12+
# get the underlying Flask app instance
1413
app = connexionapp.app
1514

16-
# Configure schematic and do the error handling
17-
# check if file exists at the path created, i.e., CONFIG_PATH
18-
if os.path.isfile(CONFIG_PATH):
19-
CONFIG.load_config(CONFIG_PATH)
20-
else:
21-
FileNotFoundError(
22-
f"No configuration file was found at this path: {CONFIG_PATH}"
23-
)
15+
# path to config.yml file saved as a Flask config variable
16+
app.config["SCHEMATIC_CONFIG"] = os.path.abspath(
17+
os.path.join(__file__, "../../config.yml")
18+
)
2419

2520
# Configure flask app
2621
# app.config[] = schematic[]

api/routes.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import urllib.request
55

66
import connexion
7-
from flask import current_app, request, g
7+
from flask import current_app as app, request, g
8+
9+
from schematic import CONFIG
810

911
from schematic.manifest.generator import ManifestGenerator
1012

@@ -18,6 +20,16 @@
1820

1921
# @before_request
2022
def get_manifest_route(schema_url, title, oauth, use_annotations):
23+
# check if file exists at the path created, i.e., app.config['SCHEMATIC_CONFIG']
24+
path_to_config = app.config["SCHEMATIC_CONFIG"]
25+
26+
if os.path.isfile(path_to_config):
27+
CONFIG.load_config(path_to_config)
28+
else:
29+
raise FileNotFoundError(
30+
f"No configuration file was found at this path: {path_to_config}"
31+
)
32+
2133
# retrieve a JSON-LD via URL and store it in a temporary location
2234
with urllib.request.urlopen(schema_url) as response:
2335
with tempfile.NamedTemporaryFile(delete=False, suffix=".jsonld") as tmp_file:
@@ -26,11 +38,6 @@ def get_manifest_route(schema_url, title, oauth, use_annotations):
2638
# get path to temporary JSON-LD file
2739
jsonld = tmp_file.name
2840

29-
# Move schematic config parameters into FlaskApp config object if any
30-
# current_app.config['model']
31-
# current_app.config['input']
32-
# current_app.config['location']
33-
3441
# request.data[]
3542
data_type = connexion.request.args["data_type"]
3643

0 commit comments

Comments
 (0)