Skip to content

Commit 6b4d46e

Browse files
author
Vasileios Karakasis
authored
Merge branch 'master' into ci/superlinter
2 parents b527ad4 + 1897374 commit 6b4d46e

File tree

5 files changed

+44
-50
lines changed

5 files changed

+44
-50
lines changed

docs/manpage.rst

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -893,21 +893,6 @@ Here is an alphabetical list of the environment variables recognized by ReFrame:
893893
================================== ==================
894894

895895

896-
.. versionadded:: 3.3
897-
898-
.. envvar:: RFM_UNUSE_MODULE_PATHS
899-
900-
A colon-separated list of module paths to be unused before acting on any tests.
901-
902-
.. table::
903-
:align: left
904-
905-
================================== ==================
906-
Associated command line option :option:`--unuse-module-path`
907-
Associated configuration parameter :js:attr:`unuse_module_paths` general configuration parameter
908-
================================== ==================
909-
910-
911896
.. envvar:: RFM_USE_LOGIN_SHELL
912897

913898
Use a login shell for the generated job scripts.

reframe/frontend/cli.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -737,34 +737,47 @@ def print_infoline(param, value):
737737
printer.debug(str(e))
738738
raise
739739

740+
def module_use(*paths):
741+
try:
742+
rt.modules_system.searchpath_add(*paths)
743+
except errors.EnvironError as e:
744+
printer.warning(f'could not add module paths correctly')
745+
printer.debug(str(e))
746+
747+
def module_unuse(*paths):
748+
try:
749+
rt.modules_system.searchpath_remove(*paths)
750+
except errors.EnvironError as e:
751+
printer.warning(f'could not remove module paths correctly')
752+
printer.debug(str(e))
753+
740754
printer.debug('(Un)using module paths from command line')
755+
module_paths = {}
741756
for d in options.module_paths:
742757
if d.startswith('-'):
743-
try:
744-
rt.modules_system.searchpath_remove(d[1:])
745-
except errors.EnvironError as e:
746-
printer.warning(
747-
f'could not remove module path {d} correctly; '
748-
f'skipping...'
749-
)
750-
printer.verbose(str(e))
758+
module_paths.setdefault('-', [])
759+
module_paths['-'].append(d[1:])
751760
elif d.startswith('+'):
752-
try:
753-
rt.modules_system.searchpath_add(d[1:])
754-
except errors.EnvironError as e:
755-
printer.warning(
756-
f'could not add module path {d} correctly; '
757-
f'skipping...'
758-
)
759-
printer.verbose(str(e))
761+
module_paths.setdefault('+', [])
762+
module_paths['+'].append(d[1:])
763+
else:
764+
module_paths.setdefault('x', [])
765+
module_paths['x'].append(d)
766+
767+
for op, paths in module_paths.items():
768+
if op == '+':
769+
module_use(*paths)
770+
elif op == '-':
771+
module_unuse(*paths)
760772
else:
761-
# Here we make sure that we don't try to remove an empty path
762-
# from the searchpath
773+
# First empty the current module path in a portable way
763774
searchpath = [p for p in rt.modules_system.searchpath if p]
764775
if searchpath:
765776
rt.modules_system.searchpath_remove(*searchpath)
766777

767-
rt.modules_system.searchpath_add(d)
778+
# Treat `A:B` syntax as well in this case
779+
paths = itertools.chain(*(p.split(':') for p in paths))
780+
module_use(*paths)
768781

769782
printer.debug('Loading user modules from command line')
770783
for m in site_config.get('general/0/user_modules'):

unittests/test_buildsystems.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
#
44
# SPDX-License-Identifier: BSD-3-Clause
55

6-
import abc
7-
import functools
86
import pytest
97

108
import reframe.core.buildsystems as bs

unittests/test_cli.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
#
44
# SPDX-License-Identifier: BSD-3-Clause
55

6+
import contextlib
7+
import io
68
import itertools
79
import os
8-
import pathlib
910
import pytest
1011
import re
1112
import sys
12-
from contextlib import redirect_stdout, redirect_stderr, suppress
13-
from io import StringIO
1413

15-
import reframe.core.config as config
1614
import reframe.core.environments as env
1715
import reframe.core.logging as logging
1816
import reframe.core.runtime as rt
@@ -26,11 +24,11 @@ def run_command_inline(argv, funct, *args, **kwargs):
2624
sys.argv = argv
2725
exitcode = None
2826

29-
captured_stdout = StringIO()
30-
captured_stderr = StringIO()
27+
captured_stdout = io.StringIO()
28+
captured_stderr = io.StringIO()
3129
print(*sys.argv)
32-
with redirect_stdout(captured_stdout):
33-
with redirect_stderr(captured_stderr):
30+
with contextlib.redirect_stdout(captured_stdout):
31+
with contextlib.redirect_stderr(captured_stderr):
3432
try:
3533
with rt.temp_runtime(None):
3634
exitcode = funct(*args, **kwargs)
@@ -591,13 +589,13 @@ def test_unload_module(run_reframe, user_exec_ctx):
591589
assert returncode == 0
592590

593591

594-
def test_unuse_module_path(run_reframe, user_exec_ctx, monkeypatch):
592+
def test_unuse_module_path(run_reframe, user_exec_ctx):
595593
ms = rt.runtime().modules_system
596594
if ms.name == 'nomod':
597595
pytest.skip('no modules system found')
598596

599597
module_path = 'unittests/modules'
600-
monkeypatch.setenv('MODULEPATH', module_path)
598+
ms.searchpath_add(module_path)
601599
returncode, stdout, stderr = run_reframe(
602600
more_options=[f'--module-path=-{module_path}', '--module=testmod_foo'],
603601
config_file=fixtures.USER_CONFIG_FILE, action='run',
@@ -632,6 +630,9 @@ def test_overwrite_module_path(run_reframe, user_exec_ctx):
632630
pytest.skip('no modules system found')
633631

634632
module_path = 'unittests/modules'
633+
with contextlib.suppress(KeyError):
634+
module_path += f':{os.environ["MODULEPATH"]}'
635+
635636
returncode, stdout, stderr = run_reframe(
636637
more_options=[f'--module-path={module_path}', '--module=testmod_foo'],
637638
config_file=fixtures.USER_CONFIG_FILE, action='run',

unittests/test_pipeline.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# SPDX-License-Identifier: BSD-3-Clause
55

66
import os
7-
import pathlib
87
import pytest
98
import re
109

@@ -14,8 +13,7 @@
1413
import reframe.utility.sanity as sn
1514
import unittests.fixtures as fixtures
1615
from reframe.core.exceptions import (BuildError, PipelineError, ReframeError,
17-
ReframeSyntaxError, PerformanceError,
18-
SanityError)
16+
PerformanceError, SanityError)
1917
from reframe.frontend.loader import RegressionCheckLoader
2018
from unittests.resources.checks.hellocheck import HelloTest
2119
from unittests.resources.checks.pinnedcheck import PinnedTest
@@ -827,7 +825,6 @@ def __init__(self, a, b):
827825

828826

829827
def test_registration_of_tests():
830-
import sys
831828
import unittests.resources.checks_unlisted.good as mod
832829

833830
checks = mod._rfm_gettests()

0 commit comments

Comments
 (0)