From 7f29dd238f43a99c74a0967e5392ecc0ef69c8ab Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Thu, 20 May 2021 14:35:35 +0200 Subject: Cray: fix extracting paths from module files (#23472) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tiziano Müller --- lib/spack/spack/test/module_parsing.py | 6 ++++++ lib/spack/spack/util/module_cmd.py | 10 +++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/spack/spack/test/module_parsing.py b/lib/spack/spack/test/module_parsing.py index 8dc06b058b..068b40762b 100644 --- a/lib/spack/spack/test/module_parsing.py +++ b/lib/spack/spack/test/module_parsing.py @@ -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 diff --git a/lib/spack/spack/util/module_cmd.py b/lib/spack/spack/util/module_cmd.py index bc994fd4b4..18522002ce 100644 --- a/lib/spack/spack/util/module_cmd.py +++ b/lib/spack/spack/util/module_cmd.py @@ -195,9 +195,13 @@ def get_path_from_module_contents(text, module_name): 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) -- cgit v1.2.3-60-g2f50