Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions reframe/utility/os_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,3 +456,21 @@ def unique_abs_paths(paths, prune_children=True):
# FIXME: This should be performed using the minus operator of
# `OrderedSet` once #1165 is fixed.
return [p for p in unique_paths if p not in children]


def cray_cdt_version():
'''Return the Cray CDT version or :class:`None` for non-Cray systems'''
rcfile = os.getenv('MODULERCFILE', '/opt/cray/pe/cdt/default/modulerc')
try:
with open(rcfile) as fp:
header = fp.readline()
if not header:
return None

match = re.search(r'^#%Module CDT (\S+)', header)
if not match:
return None

return match.group(1)
except OSError:
return None
35 changes: 35 additions & 0 deletions unittests/test_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -1136,3 +1136,38 @@ def test_unique_abs_paths(self):

with pytest.raises(TypeError):
os_ext.unique_abs_paths(None)


def test_cray_cdt_version(tmp_path, monkeypatch):
# Mock up a CDT file
rcfile = tmp_path / 'rcfile'
with open(rcfile, 'w') as fp:
fp.write('#%Module CDT 20.06\nblah blah\n')

monkeypatch.setenv('MODULERCFILE', str(rcfile))
assert os_ext.cray_cdt_version() == '20.06'


def test_cray_cdt_version_unknown_fmt(tmp_path, monkeypatch):
# Mock up a CDT file
rcfile = tmp_path / 'rcfile'
with open(rcfile, 'w') as fp:
fp.write('random stuff')

monkeypatch.setenv('MODULERCFILE', str(rcfile))
assert os_ext.cray_cdt_version() is None


def test_cray_cdt_version_empty_file(tmp_path, monkeypatch):
# Mock up a CDT file
rcfile = tmp_path / 'rcfile'
rcfile.touch()
monkeypatch.setenv('MODULERCFILE', str(rcfile))
assert os_ext.cray_cdt_version() is None


def test_cray_cdt_version_no_such_file(tmp_path, monkeypatch):
# Mock up a CDT file
rcfile = tmp_path / 'rcfile'
monkeypatch.setenv('MODULERCFILE', str(rcfile))
assert os_ext.cray_cdt_version() is None