Skip to content

Commit 89ba1f1

Browse files
committed
Move config loading into config.py and allow overriding with environment variables
1 parent 0b45de7 commit 89ba1f1

2 files changed

Lines changed: 17 additions & 18 deletions

File tree

hackyplayer/app.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,6 @@
1515
app = tasks.flask_app
1616
app_cel = tasks.celery_app
1717

18-
# Load default settings
19-
app.config.update(config.DEFAULT_CONFIG)
20-
21-
# Load local settings
22-
try:
23-
import config_local
24-
app.config.update(config_local.CONFIG)
25-
except (ImportError, AttributeError):
26-
pass
27-
2818
app.config["api_route"] = "/api/v1"
2919

3020
def get_files(target, ext_filter = []):

hackyplayer/config.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@
2828
"NAME": "input",
2929
"FULLPATH": pathlib.Path("static/video/input"),
3030
"OUTPUT_DIR": pathlib.Path("static/video/source")
31-
}]
31+
}],
32+
"CELERY": {
33+
"broker_url": "redis://localhost",
34+
"result_backend": "redis://localhost",
35+
"task_ignore_result": False,
36+
},
3237
}
3338

3439
def celery_init_app(app):
@@ -45,13 +50,17 @@ def __call__(self, *args: object, **kwargs: object) -> object:
4550

4651
def create_app():
4752
app = flask.Flask(__name__)
48-
app.config.from_mapping(
49-
CELERY=dict(
50-
broker_url="redis://localhost",
51-
result_backend="redis://localhost",
52-
task_ignore_result=False,
53-
),
54-
)
53+
54+
# Load default settings
55+
app.config.update(DEFAULT_CONFIG)
56+
57+
# Load local settings
58+
try:
59+
import config_local
60+
app.config.update(config_local.CONFIG)
61+
except (ImportError, AttributeError):
62+
pass
63+
5564
app.config.from_prefixed_env()
5665
celery_init_app(app)
5766
return app

0 commit comments

Comments
 (0)