Skip to content

Commit 9b5eb4f

Browse files
author
Vasileios Karakasis
authored
Merge branch 'master' into update_maintenance_mode
2 parents aa04c63 + 7c22acc commit 9b5eb4f

File tree

15 files changed

+134
-45
lines changed

15 files changed

+134
-45
lines changed

ci-scripts/ci-runner.bash

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ if [ $CI_GENERIC -eq 1 ]; then
142142
# Run unit tests for the public release
143143
echo "[INFO] Running unit tests with generic settings"
144144
checked_exec ./test_reframe.py --workers=auto --forked \
145-
-W=error::reframe.core.exceptions.ReframeDeprecationWarning -ra
145+
-W=error::reframe.core.warnings.ReframeDeprecationWarning -ra
146146
checked_exec ! ./bin/reframe.py --system=generic -l 2>&1 | \
147147
grep -- '--- Logging error ---'
148148
elif [ $CI_TUTORIAL -eq 1 ]; then
@@ -174,15 +174,15 @@ else
174174
echo "[INFO] Running unit tests with ${backend}"
175175
TMPDIR=$tempdir checked_exec ./test_reframe.py --workers=auto --forked \
176176
--rfm-user-config=config/cscs-ci.py \
177-
-W=error::reframe.core.exceptions.ReframeDeprecationWarning \
177+
-W=error::reframe.core.warnings.ReframeDeprecationWarning \
178178
--rfm-user-system=dom:${backend} -ra
179179
done
180180
export PATH=$PATH_save
181181
else
182182
echo "[INFO] Running unit tests"
183183
TMPDIR=$tempdir checked_exec ./test_reframe.py --workers=auto --forked \
184184
--rfm-user-config=config/cscs-ci.py \
185-
-W=error::reframe.core.exceptions.ReframeDeprecationWarning -ra
185+
-W=error::reframe.core.warnings.ReframeDeprecationWarning -ra
186186
fi
187187

188188
if [ $CI_EXITCODE -eq 0 ]; then

reframe/core/config.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
import reframe.utility as util
2020
import reframe.utility.osext as osext
2121
import reframe.utility.typecheck as types
22-
from reframe.core.exceptions import (ConfigError,
23-
ReframeDeprecationWarning,
24-
ReframeFatalError)
22+
from reframe.core.exceptions import ConfigError, ReframeFatalError
2523
from reframe.core.logging import getlogger
24+
from reframe.core.warnings import ReframeDeprecationWarning
2625
from reframe.utility import ScopedDict
2726

2827

reframe/core/deferrable.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import builtins
77
import functools
88

9-
from reframe.core.exceptions import user_deprecation_warning
10-
119

1210
def deferrable(func):
1311
'''Function decorator for converting a function to a deferred

reframe/core/exceptions.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,6 @@ class DependencyError(ReframeError):
270270
'''Raised when a dependency problem is encountered.'''
271271

272272

273-
class ReframeDeprecationWarning(DeprecationWarning):
274-
'''Warning raised for deprecated features of the framework.'''
275-
276-
277-
warnings.filterwarnings('default', category=ReframeDeprecationWarning)
278-
279-
280273
def user_frame(tb):
281274
if not inspect.istraceback(tb):
282275
raise ValueError('could not retrieve frame: argument not a traceback')
@@ -326,24 +319,3 @@ def format_user_frame(frame):
326319

327320
exc_str = ''.join(traceback.format_exception(exc_type, exc_value, tb))
328321
return 'unexpected error: %s\n%s' % (exc_value, exc_str)
329-
330-
331-
def user_deprecation_warning(message):
332-
'''Raise a deprecation warning at the user stack frame that eventually
333-
calls this function.
334-
335-
As "user stack frame" is considered a stack frame that is outside the
336-
:py:mod:`reframe` base module.
337-
'''
338-
339-
# Unroll the stack and issue the warning from the first stack frame that is
340-
# outside the framework.
341-
stack_level = 1
342-
for s in inspect.stack():
343-
module = inspect.getmodule(s.frame)
344-
if module is None or not module.__name__.startswith('reframe'):
345-
break
346-
347-
stack_level += 1
348-
349-
warnings.warn(message, ReframeDeprecationWarning, stacklevel=stack_level)

reframe/core/fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import re
1414

1515
import reframe.utility.typecheck as types
16-
from reframe.core.exceptions import user_deprecation_warning
16+
from reframe.core.warnings import user_deprecation_warning
1717
from reframe.utility import ScopedDict
1818

1919

reframe/core/meta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Met-class for creating regression tests.
88
#
99

10-
from reframe.core.exceptions import user_deprecation_warning
10+
from reframe.core.warnings import user_deprecation_warning
1111

1212

1313
class RegressionTestMeta(type):

reframe/core/pipeline.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@
3434
from reframe.core.deferrable import _DeferredExpression
3535
from reframe.core.exceptions import (BuildError, DependencyError,
3636
PipelineError, SanityError,
37-
PerformanceError, user_deprecation_warning)
37+
PerformanceError)
3838
from reframe.core.meta import RegressionTestMeta
3939
from reframe.core.schedulers import Job
40+
from reframe.core.warnings import user_deprecation_warning
4041

4142

4243
# Dependency kinds

reframe/core/systems.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def launcher(self):
155155
Please use :attr:`launcher_type` instead.
156156
'''
157157

158-
from reframe.core.exceptions import user_deprecation_warning
158+
from reframe.core.warnings import user_deprecation_warning
159159

160160
user_deprecation_warning("the 'launcher' attribute is deprecated; "
161161
"please use 'launcher_type' instead")

reframe/core/warnings.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import contextlib
2+
import inspect
3+
import warnings
4+
5+
from reframe.core.exceptions import ReframeFatalError
6+
7+
8+
class ReframeDeprecationWarning(DeprecationWarning):
9+
'''Warning raised for deprecated features of the framework.'''
10+
11+
12+
warnings.filterwarnings('default', category=ReframeDeprecationWarning)
13+
14+
15+
_format_warning_orig = warnings.formatwarning
16+
17+
18+
def _format_warning(message, category, filename, lineno, line=None):
19+
import reframe.core.runtime as rt
20+
import reframe.utility.color as color
21+
22+
if category != ReframeDeprecationWarning:
23+
return _format_warning_orig(message, category, filename, lineno, line)
24+
25+
if line is None:
26+
# Read in the line from the file
27+
with open(filename) as fp:
28+
try:
29+
line = fp.readlines()[lineno-1]
30+
except IndexError:
31+
line = '<no line information>'
32+
33+
message = f'{filename}:{lineno}: WARNING: {message}\n{line}\n'
34+
35+
# Ignore coloring if runtime has not been initialized; this can happen
36+
# when generating the documentation of deprecated APIs
37+
with contextlib.suppress(ReframeFatalError):
38+
if rt.runtime().get_option('general/0/colorize'):
39+
message = color.colorize(message, color.YELLOW)
40+
41+
return message
42+
43+
44+
warnings.formatwarning = _format_warning
45+
46+
47+
def user_deprecation_warning(message):
48+
'''Raise a deprecation warning at the user stack frame that eventually
49+
calls this function.
50+
51+
As "user stack frame" is considered a stack frame that is outside the
52+
:py:mod:`reframe` base module.
53+
'''
54+
55+
# Unroll the stack and issue the warning from the first stack frame that is
56+
# outside the framework.
57+
stack_level = 1
58+
for s in inspect.stack():
59+
module = inspect.getmodule(s.frame)
60+
if module is None or not module.__name__.startswith('reframe'):
61+
break
62+
63+
stack_level += 1
64+
65+
warnings.warn(message, ReframeDeprecationWarning, stacklevel=stack_level)

reframe/frontend/cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
import reframe.utility.osext as osext
2525
from reframe.core.exceptions import (
2626
EnvironError, ConfigError, ReframeError,
27-
ReframeDeprecationWarning, ReframeFatalError, format_exception
27+
ReframeFatalError, format_exception
2828
)
29+
from reframe.core.warnings import ReframeDeprecationWarning
2930
from reframe.frontend.executors import Runner, generate_testcases
3031
from reframe.frontend.executors.policies import (SerialExecutionPolicy,
3132
AsynchronousExecutionPolicy)

0 commit comments

Comments
 (0)