Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_ConfigEnvFileEnv(datadir):
env_filename = os.path.join(datadir, ".env")
cefe = ConfigEnvFileEnv(["/does/not/exist/.env", env_filename])
assert cefe.get("not_a", namespace="youre") == "golfer"
assert cefe.get("loglevel") == "walter"
assert cefe.get("LOGLEVEL") == "walter"
assert cefe.get("missing") is NO_VALUE
assert cefe.data == {
"LOGLEVEL": "walter",
"DEBUG": "True",
"YOURE_NOT_A": "golfer",
"DATABASE_URL": "sqlite:///kahlua.db",
}
cefe = ConfigEnvFileEnv(env_filename)
assert cefe.get("not_a", namespace="youre") == "golfer"
cefe = ConfigEnvFileEnv("/does/not/exist/.env")
assert cefe.get("loglevel") is NO_VALUE
cefe = ConfigEnvFileEnv(["/does/not/exist/.env", env_filename])
assert cefe.get("not_a", namespace="youre") == "golfer"
assert cefe.get("loglevel") == "walter"
assert cefe.get("LOGLEVEL") == "walter"
assert cefe.get("missing") is NO_VALUE
assert cefe.data == {
"LOGLEVEL": "walter",
"DEBUG": "True",
"YOURE_NOT_A": "golfer",
"DATABASE_URL": "sqlite:///kahlua.db",
}
cefe = ConfigEnvFileEnv(env_filename)
assert cefe.get("not_a", namespace="youre") == "golfer"
cefe = ConfigEnvFileEnv("/does/not/exist/.env")
assert cefe.get("loglevel") is NO_VALUE
def test_ConfigEnvFileEnv(datadir):
env_filename = os.path.join(datadir, ".env")
cefe = ConfigEnvFileEnv(["/does/not/exist/.env", env_filename])
assert cefe.get("not_a", namespace="youre") == "golfer"
assert cefe.get("loglevel") == "walter"
assert cefe.get("LOGLEVEL") == "walter"
assert cefe.get("missing") is NO_VALUE
assert cefe.data == {
"LOGLEVEL": "walter",
"DEBUG": "True",
"YOURE_NOT_A": "golfer",
"DATABASE_URL": "sqlite:///kahlua.db",
}
cefe = ConfigEnvFileEnv(env_filename)
assert cefe.get("not_a", namespace="youre") == "golfer"
cefe = ConfigEnvFileEnv("/does/not/exist/.env")
assert cefe.get("loglevel") is NO_VALUE
config_file_locations = self._discover_config_file_locations(profile)
help_doc = ('Check https://docs.rastervision.io/ for docs.')
self.config = ConfigManager(
# Specify one or more configuration environments in
# the order they should be checked
[
# Allow overrides
ConfigDictEnv(config_overrides),
# Looks in OS environment first
ConfigOSEnv(),
# Look for an .env file
ConfigEnvFileEnv('.env'),
# Looks in INI files in order specified
ConfigIniEnv(config_file_locations),
],
# Make it easy for users to find your configuration docs
doc=help_doc)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.ENVIRON = EnvironProxy(
ConfigManager(
[
ConfigOSEnv(),
ConfigEnvFileEnv(".env"),
DumbConfigIniEnv([os.environ.get("ARA_CFG"), "~/.config/ara/server.cfg", "/etc/ara/server.cfg"]),
]
).with_namespace("ara")
)
if builds < min_builds:
raise ValueError('Too few builds for {}'.format(version_key))
def validate_data():
for key in FIREFOX_VERSION_KEYS:
count_firefox_builds(key)
for key in THUNDERBIRD_VERSION_KEYS:
count_thunderbird_builds(key)
# setup and run
config = ConfigManager([ConfigOSEnv(),
ConfigEnvFileEnv(path('.env'))])
settings.configure(
DEBUG=False,
PROD_DETAILS_DIR=path('product-details'),
PROD_DETAILS_URL=config('PROD_DETAILS_URL',
default='https://product-details.mozilla.org/1.0/'),
PROD_DETAILS_STORAGE='product_details.storage.PDFileStorage',
INSTALLED_APPS=['product_details'],
# disable cache
CACHES={'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}},
)
django.setup()
from product_details import product_details as pd # noqa
if __name__ == '__main__':
update_data()
This is shorthand for::
config = ConfigManager(
environments=[
ConfigOSEnv(),
ConfigEnvFileEnv(['.env'])
]
)
:arg env_file: the name of the env file to use
:returns: a :py:class:`everett.manager.ConfigManager`
"""
return cls(environments=[ConfigOSEnv(), ConfigEnvFileEnv([env_file])])
from pathlib import Path
from everett.manager import ConfigManager, ConfigEnvFileEnv, ConfigOSEnv, ListOf
import django_cache_url
ROOT_PATH = Path(__file__).resolve().parents[1]
def path(*paths):
return str(ROOT_PATH.joinpath(*paths))
config = ConfigManager([
ConfigEnvFileEnv(path('.env')),
ConfigOSEnv(),
])
# Build paths inside the project like this: path(...)
BASE_DIR = str(ROOT_PATH)
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = config('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config('DEBUG', default='false', parser=bool)