Skip to content

Commit 247f9b8

Browse files
committed
Fixing structure and performance improvements
1 parent be8da16 commit 247f9b8

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from conditional import app
22

33
if __name__ == "__main__":
4-
app.run(host=app.config['IP'], port=app.config['PORT'])
4+
app.run(host=app.config['IP'], port=app.config['PORT'], threaded=False)
55

66
application = app

conditional/__init__.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
# pylint: disable=wrong-import-order
2-
from ._version import __version__
3-
41
import os
52
from datetime import datetime
63

4+
import structlog
75
from csh_ldap import CSHLDAP
86
from flask import Flask, redirect, render_template, g
97
from flask_migrate import Migrate
8+
from flask_gzip import Gzip
109
from flask_pyoidc.flask_pyoidc import OIDCAuthentication
1110
from flask_sqlalchemy import SQLAlchemy
1211
from raven.contrib.flask import Sentry
13-
import structlog
14-
15-
from conditional import config
1612

1713
app = Flask(__name__)
14+
gzip = Gzip(app)
1815

19-
app.config.from_object(config)
20-
if os.path.exists(os.path.join(os.getcwd(), "config.py")):
21-
app.config.from_pyfile(os.path.join(os.getcwd(), "config.py"))
22-
23-
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
16+
# Load default configuration and any environment variable overrides
17+
_root_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
18+
app.config.from_pyfile(os.path.join(_root_dir, "config.env.py"))
2419

25-
app.config["VERSION"] = __version__
20+
# Load file based configuration overrides if present
21+
_pyfile_config = os.path.join(_root_dir, "config.py")
22+
if os.path.exists(_pyfile_config):
23+
app.config.from_pyfile(_pyfile_config)
2624

2725
db = SQLAlchemy(app)
2826
migrate = Migrate(app, db)

conditional/_version.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

conditional/config.py renamed to config.env.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
import json
12
import secrets
3+
import os
24
from os import environ as env
35

4-
from conditional import __version__
6+
# Fetch the version number from the npm package file
7+
with open(os.path.join(os.getcwd(), "package.json")) as package_file:
8+
VERSION = json.load(package_file)["version"]
59

610
# Flask config
711
DEBUG = env.get("CONDITIONAL_DEBUG", "false").lower() == "true"
@@ -13,6 +17,7 @@
1317

1418
# DB Info
1519
SQLALCHEMY_DATABASE_URI = env.get("SQLALCHEMY_DATABASE_URI", "")
20+
SQLALCHEMY_TRACK_MODIFICATIONS = False
1621

1722
# LDAP config
1823
LDAP_RO = env.get("CONDITIONAL_LDAP_RO", "true").lower() == "true"
@@ -23,7 +28,7 @@
2328
# Do not set the DSN for local development
2429
SENTRY_CONFIG = {
2530
'dsn': env.get("CONDITIONAL_SENTRY_DSN", ""),
26-
'release': __version__,
31+
'release': VERSION,
2732
}
2833

2934
# OIDC Config

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ click~=6.7
55
csh-ldap~=2.0.2
66
Flask~=1.1.0
77
Flask-Migrate~=2.1.1
8+
Flask-Gzip~=0.2
89
Flask-pyoidc~=1.3.0
910
Flask-SQLAlchemy~=2.3.2
1011
gunicorn~=19.7.1

0 commit comments

Comments
 (0)