Ejemplo n.º 1
0
 def test_multiple_files(self, datadir):
     ini_filename = os.path.join(datadir, 'config_test.ini')
     ini_filename_original = os.path.join(datadir, 'config_test_original.ini')
     cie = ConfigIniEnv([ini_filename, ini_filename_original])
     # Only the first found file is loaded, so foo_original does not exist
     assert cie.get('foo_original') == NO_VALUE
     cie = ConfigIniEnv([ini_filename_original])
     # ... but it is there if only the original is loaded (safety check)
     assert cie.get('foo_original') == 'original'
Ejemplo n.º 2
0
    def test_basic_usage(self, datadir):
        ini_filename = os.path.join(datadir, "config_test.ini")
        cie = ConfigIniEnv([ini_filename])
        assert cie.get("foo") == "bar"
        assert cie.get("FOO") == "bar"
        assert cie.get("foo", namespace="nsbaz") == "bat"
        assert cie.get("foo", namespace=["nsbaz"]) == "bat"
        assert cie.get("foo", namespace=["nsbaz", "nsbaz2"]) == "bat2"

        cie = ConfigIniEnv(["/a/b/c/bogus/filename"])
        assert cie.get("foo") == NO_VALUE
Ejemplo n.º 3
0
    def test_basic_usage(self, datadir):
        ini_filename = os.path.join(datadir, 'config_test.ini')
        cie = ConfigIniEnv([ini_filename])
        assert cie.get('foo') == 'bar'
        assert cie.get('FOO') == 'bar'
        assert cie.get('foo', namespace='nsbaz') == 'bat'
        assert cie.get('foo', namespace=['nsbaz']) == 'bat'
        assert cie.get('foo', namespace=['nsbaz', 'nsbaz2']) == 'bat2'

        cie = ConfigIniEnv(['/a/b/c/bogus/filename'])
        assert cie.get('foo') == NO_VALUE
Ejemplo n.º 4
0
def get_config():
    return ConfigManager([
        ConfigIniEnv([
            os.environ.get("CIS_CONFIG_INI"), "~/.mozilla-cis.ini",
            "/etc/mozilla-cis.ini"
        ]),
        ConfigOSEnv()
    ])
Ejemplo n.º 5
0
def get_config():
    return ConfigManager([
        ConfigIniEnv([
            os.environ.get('THREATRESPONSE_INI'), '~/.threatresponse.ini',
            '/etc/threatresponse.ini'
        ]),
        ConfigOSEnv()
    ])
Ejemplo n.º 6
0
    def test_basic_usage(self, datadir):
        ini_filename = os.path.join(datadir, 'config_test.ini')
        cie = ConfigIniEnv([ini_filename])
        assert cie.get('foo') == 'bar'
        assert cie.get('FOO') == 'bar'
        assert cie.get('foo', namespace='nsbaz') == 'bat'
        assert cie.get('foo', namespace=['nsbaz']) == 'bat'
        assert cie.get('foo', namespace=['nsbaz', 'nsbaz2']) == 'bat2'

        cie = ConfigIniEnv(['/a/b/c/bogus/filename'])
        assert cie.get('foo') == NO_VALUE
Ejemplo n.º 7
0
 def test_multiple_files(self, datadir):
     ini_filename = os.path.join(datadir, "config_test.ini")
     ini_filename_original = os.path.join(datadir, "config_test_original.ini")
     cie = ConfigIniEnv([ini_filename, ini_filename_original])
     # Only the first found file is loaded, so foo_original does not exist
     assert cie.get("foo_original") == NO_VALUE
     cie = ConfigIniEnv([ini_filename_original])
     # ... but it is there if only the original is loaded (safety check)
     assert cie.get("foo_original") == "original"
Ejemplo n.º 8
0
 def __init__(self, config_map):
     self.config_map = config_map
     self.override = {}  # type: Dict[str, Any]
     self.backend_override = ConfigDictEnv({})
     config_override = os.environ.get("COMET_INI")
     if config_override is not None:
         log_once_at_level(logging.WARNING,
                           "COMET_INI is deprecated; use COMET_CONFIG")
     else:
         config_override = os.environ.get("COMET_CONFIG")
     self.manager = ConfigManager(
         [  # User-defined overrides
             ConfigOSEnv(),
             ConfigEnvFileEnv(".env"),
             ConfigIniEnv(config_override),
             ConfigIniEnv("./.comet.config"),
             ConfigIniEnv("~/.comet.config"),
             # Comet-defined overrides
             self.backend_override,
         ],
         doc=
         ("See https://comet.ml/docs/python-sdk/getting-started/ for more "
          + "information on configuration."),
     )
Ejemplo n.º 9
0
def read_config(config_path: str):
    """
    Read the configuration from the config ini file given.
    :return:
    """
    return ConfigManager(
        # Specify one or more configuration environments in
        # the order they should be checked
        environments=[
            # Look in OS process environment first
            ConfigOSEnv(),

            # Look in INI file given in parameter
            ConfigIniEnv([config_path]),
        ],

        # Provide users a link to documentation for when they hit
        # configuration errors
        doc='Check https://example.com/configuration for docs.')
Ejemplo n.º 10
0
 def test_does_not_parse_lists(self, datadir):
     ini_filename = os.path.join(datadir, 'config_test.ini')
     cie = ConfigIniEnv([ini_filename])
     assert cie.get('bar') == 'test1,test2'
Ejemplo n.º 11
0
import os
from everett.ext.inifile import ConfigIniEnv
from everett.manager import ConfigDictEnv, ConfigManager, ConfigOSEnv

config = ConfigManager([
    # Pull from the OS environment first
    ConfigOSEnv(),
    # Fall back to the file specified by the FOO_INI OS environment
    # variable if such file exists
    ConfigIniEnv(os.environ.get("FOO_INI")),
    # Fall back to this dict of defaults
    ConfigDictEnv({"FOO_VAR": "bar"}),
])

assert config("foo_var") == "bar"
Ejemplo n.º 12
0
    def set_everett_config(self,
                           profile: str = None,
                           rv_home: str = None,
                           config_overrides: Dict[str, str] = None):
        """Set Everett config.

        This sets up any other configuration using the Everett library.
        See https://everett.readthedocs.io/

        It roughly mimics the behavior of how the AWS CLI is configured, if that
        is a helpful analogy. Configuration can be specified through configuration
        files, environment variables, and the config_overrides argument in increasing
        order of precedence.

        Configuration files are in the following format:
        ```
        [namespace_1]
        key_11=val_11
        ...
        key_1n=val_1n

        ...

        [namespace_m]
        key_m1=val_m1
        ...
        key_mn=val_mn
        ```

        Each namespace can be used for the configuration of a different plugin.
        Each configuration file is a "profile" with the name of the file being the name
        of the profile. This supports switching between different configuration sets.
        The corresponding environment variable setting for namespace_i and key_ij is
        `namespace_i_key_ij=val_ij`.

        Args:
            profile: name of the RV configuration profile to use. If not set, defaults
                to value of RV_PROFILE env var, or DEFAULT_PROFILE.
            rv_home: a local dir with RV configuration files. If not set, attempts to
                use ~/.rastervision.
            config_overrides: any configuration to override. Each key is of form
                namespace_i_key_ij with corresponding value val_ij.
        """
        if profile is None:
            if os.environ.get('RV_PROFILE'):
                profile = os.environ.get('RV_PROFILE')
            else:
                profile = RVConfig.DEFAULT_PROFILE
        self.profile = 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(
            self.profile)
        config_ini_env = ConfigIniEnv(config_file_locations)

        self.config = ConfigManager(
            [
                ConfigOSEnv(),
                ConfigDictEnv(config_overrides),
                config_ini_env,
            ],
            doc=(
                'Check https://docs.rastervision.io/ for docs. '
                'Switch to the version being run and search for Raster Vision '
                'Configuration.'))
Ejemplo n.º 13
0
import os
from everett.ext.inifile import ConfigIniEnv
from everett.manager import (
    ConfigDictEnv,
    ConfigManager,
    ConfigOSEnv
)

config = ConfigManager([
    # Pull from the OS environment first
    ConfigOSEnv(),

    # Fall back to the file specified by the FOO_INI OS environment
    # variable if such file exists
    ConfigIniEnv(os.environ.get('FOO_INI')),

    # Fall back to this dict of defaults
    ConfigDictEnv({
        'FOO_VAR': 'bar'
    })
])

assert config('foo_var') == 'bar'
Ejemplo n.º 14
0
 def test_does_not_parse_lists(self, datadir):
     ini_filename = os.path.join(datadir, "config_test.ini")
     cie = ConfigIniEnv([ini_filename])
     assert cie.get("bar") == "test1,test2"
Ejemplo n.º 15
0
 def test_does_not_parse_lists(self, datadir):
     ini_filename = os.path.join(datadir, 'config_test.ini')
     cie = ConfigIniEnv([ini_filename])
     assert cie.get('bar') == 'test1,test2'