~homeworkprod/byceps

12d5f2bc573f78177050b58ef60aec7e8d6fca52 — Jochen Kupperschmidt 5 years ago 8a5d52d
Extract constants for configuration environment variable name
2 files changed, 12 insertions(+), 5 deletions(-)

M byceps/util/system.py
M serve.py
M byceps/util/system.py => byceps/util/system.py +6 -3
@@ 11,19 11,22 @@ byceps.util.system
import os


CONFIG_ENV_VAR_NAME = 'ENV'


def get_config_env_name_from_env(*, default=None):
    """Return the configuration environment name set via environment
    variable.

    Raise an exception if it isn't set.
    """
    env = os.environ.get('ENV')
    env = os.environ.get(CONFIG_ENV_VAR_NAME)

    if env is None:
        if default is None:
            raise Exception(
                "No configuration environment was specified via the 'ENV' "
                "environment variable.")
                "No configuration environment was specified via the '{}' "
                "environment variable.".format(CONFIG_ENV_VAR_NAME))

        env = default


M serve.py => serve.py +6 -2
@@ 6,10 6,14 @@ import sys
from byceps.application import create_app, init_app


environment = os.environ.get('ENVIRONMENT')
CONFIG_ENV_VAR_NAME = 'ENVIRONMENT'


environment = os.environ.get(CONFIG_ENV_VAR_NAME)

if environment is None:
    sys.stderr.write("Environment variable 'ENVIRONMENT' must be set but isn't.")
    sys.stderr.write("Environment variable '{}' must be set but isn't."
                     .format(CONFIG_ENV_VAR_NAME))
    sys.exit()

app = create_app(environment)