Exemple #1
0
def test_reverse_environment_modifications(working_env):
    start_env = {
        'PREPEND_PATH': '/path/to/prepend/to',
        'APPEND_PATH': '/path/to/append/to',
        'UNSET': 'var_to_unset',
        'APPEND_FLAGS': 'flags to append to',
    }

    to_reverse = envutil.EnvironmentModifications()

    to_reverse.prepend_path('PREPEND_PATH', '/new/path/prepended')
    to_reverse.append_path('APPEND_PATH', '/new/path/appended')
    to_reverse.set_path('SET_PATH', ['/one/set/path', '/two/set/path'])
    to_reverse.set('SET', 'a var')
    to_reverse.unset('UNSET')
    to_reverse.append_flags('APPEND_FLAGS', 'more_flags')

    reversal = to_reverse.reversed()

    os.environ = start_env.copy()

    print(os.environ)
    to_reverse.apply_modifications()
    print(os.environ)
    reversal.apply_modifications()
    print(os.environ)

    start_env.pop('UNSET')
    assert os.environ == start_env
Exemple #2
0
def parse(config_obj):
    """Returns an EnvironmentModifications object containing the modifications
    parsed from input.

    Args:
        config_obj: a configuration dictionary conforming to the
            schema definition for environment modifications
    """
    import sys

    import spack.util.environment as ev
    if sys.version_info >= (3, 5):
        from collections.abc import Sequence  # novm
    else:
        from collections import Sequence  # novm

    env = ev.EnvironmentModifications()
    for command, variable in config_obj.items():
        # Distinguish between commands that take only a name as argument
        # (e.g. unset) and commands that take a name and a value.
        if isinstance(variable, Sequence):
            for name in variable:
                getattr(env, command)(name)
        else:
            for name, value in variable.items():
                getattr(env, command)(name, value)

    return env
Exemple #3
0
def unconditional_environment_modifications(view):
    """List of environment (shell) modifications to be processed for view.

    This list does not depend on the specs in this environment"""
    env = environment.EnvironmentModifications()

    for subdir, vars in prefix_inspections(sys.platform).items():
        full_subdir = os.path.join(view.root, subdir)
        for var in vars:
            env.prepend_path(var, full_subdir)

    return env