mirror of
https://github.com/LukeHagar/pypistats.org.git
synced 2025-12-10 04:21:20 +00:00
force env variables
This commit is contained in:
@@ -11,7 +11,7 @@ from pypistats.settings import configs
|
|||||||
|
|
||||||
|
|
||||||
# change this for migrations
|
# change this for migrations
|
||||||
env = os.environ.get("ENV", "prod")
|
env = os.environ.get("ENV", "dev")
|
||||||
|
|
||||||
app = create_app(configs[env])
|
app = create_app(configs[env])
|
||||||
celery = create_celery(app)
|
celery = create_celery(app)
|
||||||
|
|||||||
@@ -1,21 +1,9 @@
|
|||||||
"""Application configuration."""
|
"""Application configuration."""
|
||||||
import json
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from celery.schedules import crontab
|
from celery.schedules import crontab
|
||||||
|
|
||||||
|
|
||||||
# For local use.
|
|
||||||
def load_env_vars(env="dev"):
|
|
||||||
"""Load environment variables."""
|
|
||||||
local_path = os.path.join(
|
|
||||||
os.path.dirname(os.path.abspath(__file__)),
|
|
||||||
"secret",
|
|
||||||
f"env_vars_{env}.json")
|
|
||||||
for key, value in json.load(open(local_path, "r")).items():
|
|
||||||
os.environ[key] = value
|
|
||||||
|
|
||||||
|
|
||||||
def get_db_uri(env):
|
def get_db_uri(env):
|
||||||
"""Get the database URI."""
|
"""Get the database URI."""
|
||||||
return \
|
return \
|
||||||
@@ -52,8 +40,6 @@ class ProdConfig(Config):
|
|||||||
|
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
ENV = "prod"
|
ENV = "prod"
|
||||||
if os.environ.get("ENV", None) is None:
|
|
||||||
load_env_vars(ENV)
|
|
||||||
SQLALCHEMY_DATABASE_URI = get_db_uri(ENV)
|
SQLALCHEMY_DATABASE_URI = get_db_uri(ENV)
|
||||||
|
|
||||||
|
|
||||||
@@ -62,8 +48,6 @@ class DevConfig(Config):
|
|||||||
|
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
ENV = "dev"
|
ENV = "dev"
|
||||||
if os.environ.get("ENV", None) is None:
|
|
||||||
load_env_vars(ENV)
|
|
||||||
SQLALCHEMY_DATABASE_URI = get_db_uri(ENV)
|
SQLALCHEMY_DATABASE_URI = get_db_uri(ENV)
|
||||||
|
|
||||||
|
|
||||||
@@ -72,8 +56,6 @@ class TestConfig(Config):
|
|||||||
|
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
ENV = "dev"
|
ENV = "dev"
|
||||||
if os.environ.get("ENV", None) is None:
|
|
||||||
load_env_vars(ENV)
|
|
||||||
SQLALCHEMY_DATABASE_URI = get_db_uri(ENV)
|
SQLALCHEMY_DATABASE_URI = get_db_uri(ENV)
|
||||||
TESTING = True
|
TESTING = True
|
||||||
WTF_CSRF_ENABLED = False # Allows form testing
|
WTF_CSRF_ENABLED = False # Allows form testing
|
||||||
|
|||||||
Reference in New Issue
Block a user