Cray: fix extracting paths from module files (#23472)

Co-authored-by: Tiziano Müller <tm@dev-zero.ch>
This commit is contained in:
Harmen Stoppels 2021-05-20 14:35:35 +02:00 committed by GitHub
parent 6d42be5739
commit 5846079028
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View file

@ -123,3 +123,9 @@ def test_get_argument_from_module_line():
for bl in bad_lines:
with pytest.raises(ValueError):
get_path_args_from_module_line(bl)
def test_lmod_quote_parsing():
lines = ['setenv("SOME_PARTICULAR_DIR","-L/opt/cray/pe/mpich/8.1.4/gtl/lib")']
result = get_path_from_module_contents(lines, 'some-module')
assert '/opt/cray/pe/mpich/8.1.4/gtl' == result

View file

@ -195,9 +195,13 @@ def match_pattern_and_strip(line, pattern, strip=[]):
def match_flag_and_strip(line, flag, strip=[]):
flag_idx = line.find(flag)
if flag_idx >= 0:
end = line.find(' ', flag_idx)
if end >= 0:
path = line[flag_idx + len(flag):end]
# Search for the first occurence of any separator marking the end of
# the path.
separators = (' ', '"', "'")
occurrences = [line.find(s, flag_idx) for s in separators]
indices = [idx for idx in occurrences if idx >= 0]
if indices:
path = line[flag_idx + len(flag):min(indices)]
else:
path = line[flag_idx + len(flag):]
path = strip_path(path, strip)