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_default_must_be_string():
config = ConfigManager([])
with pytest.raises(ConfigurationError):
assert config("DOESNOTEXIST", default=True)
def test_with_options():
"""Verify .with_options() restricts configuration"""
config = ConfigManager(
[ConfigDictEnv({"FOO_BAR": "a", "FOO_BAZ": "b", "BAR": "c", "BAZ": "d"})]
)
class SomeComponent(RequiredConfigMixin):
required_config = ConfigOptions()
required_config.add_option("baz", default="", doc="some help here", parser=str)
def __init__(self, config):
self.config = config.with_options(self)
# Create the component with regular config
comp = SomeComponent(config)
assert comp.config("baz") == "d"
with pytest.raises(ConfigurationError):
# This is not a valid option for this component
comp.config("bar")
profile = os.environ.get('RV_PROFILE')
else:
profile = RVConfig.DEFAULT_PROFILE
if config_overrides is None:
config_overrides = {}
if rv_home is None:
home = os.path.expanduser('~')
rv_home = os.path.join(home, '.rastervision')
self.rv_home = rv_home
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),
],
def main():
config = ConfigManager(
environments=[ConfigOSEnv()],
doc='For configuration help, see https://example.com/configuration'
)
debug_mode = config(
'debug', default='false', parser=bool,
doc='True to put the app in debug mode. Don\'t use this in production!'
)
if debug_mode:
print('Debug mode is on!')
else:
print('Debug mode off.')
def get_config():
return ConfigManager(
[ConfigIniEnv([os.environ.get("CIS_CONFIG_INI"), "~/.mozilla-cis.ini", "/etc/mozilla-cis.ini"]), ConfigOSEnv()]
)
def get_config():
return ConfigManager(
[
ConfigIniEnv([
os.environ.get('CIS_CONFIG_INI'),
'~/.mozilla-cis.ini',
'/etc/mozilla-cis.ini'
]),
ConfigOSEnv()
]
def get_config():
return ConfigManager(
[ConfigIniEnv([os.environ.get("CIS_CONFIG_INI"), "~/.mozilla-cis.ini", "/etc/mozilla-cis.ini"]), ConfigOSEnv()]
)