Example #1
0
def override(path_or_scope, value=None):
    """Simple way to override config settings within a context.

    Arguments:
        path_or_scope (ConfigScope or str): scope or single option to override
        value (object or None): value for the single option

    Temporarily push a scope on the current configuration, then remove it
    after the context completes. If a single option is provided, create
    an internal config scope for it and push/pop that scope.

    """
    if isinstance(path_or_scope, ConfigScope):
        overrides = path_or_scope
        config.push_scope(path_or_scope)
    else:
        base_name = overrides_base_name
        # Ensure the new override gets a unique scope name
        current_overrides = [
            s.name for s in config.matching_scopes(r'^{0}'.format(base_name))
        ]
        num_overrides = len(current_overrides)
        while True:
            scope_name = '{0}{1}'.format(base_name, num_overrides)
            if scope_name in current_overrides:
                num_overrides += 1
            else:
                break

        overrides = InternalConfigScope(scope_name)
        config.push_scope(overrides)
        config.set(path_or_scope, value, scope=scope_name)

    try:
        yield config
    finally:
        scope = config.remove_scope(overrides.name)
        assert scope is overrides
Example #2
0
def override(path_or_scope, value=None):
    """Simple way to override config settings within a context.

    Arguments:
        path_or_scope (ConfigScope or str): scope or single option to override
        value (object, optional): value for the single option

    Temporarily push a scope on the current configuration, then remove it
    after the context completes. If a single option is provided, create
    an internal config scope for it and push/pop that scope.

    """
    if isinstance(path_or_scope, ConfigScope):
        overrides = path_or_scope
        config.push_scope(path_or_scope)
    else:
        overrides = InternalConfigScope('overrides')
        config.push_scope(overrides)
        config.set(path_or_scope, value, scope='overrides')

    yield config

    scope = config.remove_scope(overrides.name)
    assert scope is overrides
Example #3
0
File: config.py Project: LLNL/spack
def override(path_or_scope, value=None):
    """Simple way to override config settings within a context.

    Arguments:
        path_or_scope (ConfigScope or str): scope or single option to override
        value (object, optional): value for the single option

    Temporarily push a scope on the current configuration, then remove it
    after the context completes. If a single option is provided, create
    an internal config scope for it and push/pop that scope.

    """
    if isinstance(path_or_scope, ConfigScope):
        overrides = path_or_scope
        config.push_scope(path_or_scope)
    else:
        overrides = InternalConfigScope('overrides')
        config.push_scope(overrides)
        config.set(path_or_scope, value, scope='overrides')

    yield config

    scope = config.remove_scope(overrides.name)
    assert scope is overrides
Example #4
0
def add_default_platform_scope(platform):
    plat_name = os.path.join('defaults', platform)
    plat_path = os.path.join(configuration_defaults_path[1], platform)
    config.push_scope(ConfigScope(plat_name, plat_path))