modules tcl: simplify env modification block in template (#36334)
Simplify environment modification block in modulefile Tcl template by always setting a path delimiter to the prepend-path, append-path and remove-path commands. Remove --delim option to the setenv command as this command does not allow such option. Update test_prepend_path_separator test to explicitly check the 6 path-like commands that should be present in generated modulefile.
This commit is contained in:
parent
d0d5526110
commit
906151075d
@ -0,0 +1,5 @@
|
||||
enable:
|
||||
- tcl
|
||||
tcl:
|
||||
all:
|
||||
autoload: none
|
@ -2,7 +2,7 @@
|
||||
# Spack Project Developers. See the top-level COPYRIGHT file for details.
|
||||
#
|
||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||
import re
|
||||
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
@ -128,21 +128,22 @@ def test_alter_environment(self, modulefile_content, module_configuration, confi
|
||||
|
||||
content = modulefile_content("libdwarf platform=test target=core2")
|
||||
|
||||
assert len([x for x in content if x.startswith('prepend-path("CMAKE_PREFIX_PATH"')]) == 0
|
||||
assert len([x for x in content if x.startswith('prepend_path("CMAKE_PREFIX_PATH"')]) == 0
|
||||
assert len([x for x in content if 'setenv("FOO", "foo")' in x]) == 0
|
||||
assert len([x for x in content if 'unsetenv("BAR")' in x]) == 0
|
||||
|
||||
def test_prepend_path_separator(self, modulefile_content, module_configuration):
|
||||
"""Tests modifications to run-time environment."""
|
||||
"""Tests that we can use custom delimiters to manipulate path lists."""
|
||||
|
||||
module_configuration("module_path_separator")
|
||||
content = modulefile_content("module-path-separator")
|
||||
|
||||
for line in content:
|
||||
if re.match(r'[a-z]+_path\("COLON"', line):
|
||||
assert line.endswith('"foo", ":")')
|
||||
elif re.match(r'[a-z]+_path\("SEMICOLON"', line):
|
||||
assert line.endswith('"bar", ";")')
|
||||
assert len([x for x in content if 'append_path("COLON", "foo", ":")' in x]) == 1
|
||||
assert len([x for x in content if 'prepend_path("COLON", "foo", ":")' in x]) == 1
|
||||
assert len([x for x in content if 'remove_path("COLON", "foo", ":")' in x]) == 1
|
||||
assert len([x for x in content if 'append_path("SEMICOLON", "bar", ";")' in x]) == 1
|
||||
assert len([x for x in content if 'prepend_path("SEMICOLON", "bar", ";")' in x]) == 1
|
||||
assert len([x for x in content if 'remove_path("SEMICOLON", "bar", ";")' in x]) == 1
|
||||
|
||||
@pytest.mark.parametrize("config_name", ["exclude", "blacklist"])
|
||||
def test_exclude(self, modulefile_content, module_configuration, config_name):
|
||||
|
@ -108,6 +108,19 @@ def test_alter_environment(self, modulefile_content, module_configuration, confi
|
||||
assert len([x for x in content if "module load foo/bar" in x]) == 1
|
||||
assert len([x for x in content if "setenv LIBDWARF_ROOT" in x]) == 1
|
||||
|
||||
def test_prepend_path_separator(self, modulefile_content, module_configuration):
|
||||
"""Tests that we can use custom delimiters to manipulate path lists."""
|
||||
|
||||
module_configuration("module_path_separator")
|
||||
content = modulefile_content("module-path-separator")
|
||||
|
||||
assert len([x for x in content if 'append-path --delim ":" COLON "foo"' in x]) == 1
|
||||
assert len([x for x in content if 'prepend-path --delim ":" COLON "foo"' in x]) == 1
|
||||
assert len([x for x in content if 'remove-path --delim ":" COLON "foo"' in x]) == 1
|
||||
assert len([x for x in content if 'append-path --delim ";" SEMICOLON "bar"' in x]) == 1
|
||||
assert len([x for x in content if 'prepend-path --delim ";" SEMICOLON "bar"' in x]) == 1
|
||||
assert len([x for x in content if 'remove-path --delim ";" SEMICOLON "bar"' in x]) == 1
|
||||
|
||||
@pytest.mark.parametrize("config_name", ["exclude", "blacklist"])
|
||||
def test_exclude(self, modulefile_content, module_configuration, config_name):
|
||||
"""Tests excluding the generation of selected modules."""
|
||||
|
@ -41,8 +41,6 @@ conflict {{ name }}
|
||||
|
||||
{% block environment %}
|
||||
{% for command_name, cmd in environment_modifications %}
|
||||
{% if cmd.separator != ':' %}
|
||||
{# A non-standard separator is required #}
|
||||
{% if command_name == 'PrependPath' %}
|
||||
prepend-path --delim "{{ cmd.separator }}" {{ cmd.name }} "{{ cmd.value }}"
|
||||
{% elif command_name == 'AppendPath' %}
|
||||
@ -50,25 +48,11 @@ append-path --delim "{{ cmd.separator }}" {{ cmd.name }} "{{ cmd.value }}"
|
||||
{% elif command_name == 'RemovePath' %}
|
||||
remove-path --delim "{{ cmd.separator }}" {{ cmd.name }} "{{ cmd.value }}"
|
||||
{% elif command_name == 'SetEnv' %}
|
||||
setenv --delim "{{ cmd.separator }}" {{ cmd.name }} "{{ cmd.value }}"
|
||||
{% elif command_name == 'UnsetEnv' %}
|
||||
unsetenv {{ cmd.name }}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{# We are using the usual separator #}
|
||||
{% if command_name == 'PrependPath' %}
|
||||
prepend-path {{ cmd.name }} "{{ cmd.value }}"
|
||||
{% elif command_name == 'AppendPath' %}
|
||||
append-path {{ cmd.name }} "{{ cmd.value }}"
|
||||
{% elif command_name == 'RemovePath' %}
|
||||
remove-path {{ cmd.name }} "{{ cmd.value }}"
|
||||
{% elif command_name == 'SetEnv' %}
|
||||
setenv {{ cmd.name }} "{{ cmd.value }}"
|
||||
{% elif command_name == 'UnsetEnv' %}
|
||||
unsetenv {{ cmd.name }}
|
||||
{% endif %}
|
||||
{# #}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user