Skip to content

Commit

Permalink
Merge pull request #9549 from sklam/misc/deprecate_old_style
Browse files Browse the repository at this point in the history
Make new_style the default error capturing mode
  • Loading branch information
sklam committed Apr 30, 2024
2 parents 4318ee4 + 999b95f commit e467ae6
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 30 deletions.
2 changes: 0 additions & 2 deletions buildscripts/azure/azure-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,13 @@ jobs:
- script: |
call activate %CONDA_ENV%
set NUMBA_CAPTURED_ERRORS=new_style
set NUMBA_ENABLE_CUDASIM=1
echo "Running shard of discovered tests: %TEST_START_INDEX%,None,%TEST_COUNT%"
python -m numba.runtests -b -v -g -m 2 -- numba.tests
displayName: 'Test modified test files'
- script: |
call activate %CONDA_ENV%
set NUMBA_CAPTURED_ERRORS=new_style
set NUMBA_ENABLE_CUDASIM=1
echo "Running shard of discovered tests: %TEST_START_INDEX%:%TEST_COUNT%"
python runtests.py -m 2 -b -j "%TEST_START_INDEX%:%TEST_COUNT%" --exclude-tags='long_running' --junit -- numba.tests
Expand Down
1 change: 0 additions & 1 deletion buildscripts/condarecipe.local/run_test.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
set NUMBA_DEVELOPER_MODE=1
set NUMBA_DISABLE_ERROR_MESSAGE_HIGHLIGHTING=1
set NUMBA_CAPTURED_ERRORS=new_style
set PYTHONFAULTHANDLER=1

@rem Check Numba executable is there
Expand Down
1 change: 0 additions & 1 deletion buildscripts/condarecipe.local/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ set -e

export NUMBA_DEVELOPER_MODE=1
export NUMBA_DISABLE_ERROR_MESSAGE_HIGHLIGHTING=1
export NUMBA_CAPTURED_ERRORS="new_style"
export PYTHONFAULTHANDLER=1

# Disable NumPy dispatching to AVX512_SKX feature extensions if the chip is
Expand Down
5 changes: 1 addition & 4 deletions buildscripts/incremental/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ export NUMBA_DEVELOPER_MODE=1
# enable the fault handler
export PYTHONFAULTHANDLER=1

# enable new style error handling
export NUMBA_CAPTURED_ERRORS="new_style"

# Disable NumPy dispatching to AVX512_SKX feature extensions if the chip is
# reported to support the feature and NumPy >= 1.22 as this results in the use
# of low accuracy SVML libm replacements in ufunc loops.
Expand Down Expand Up @@ -147,5 +144,5 @@ fi
# Now run with RVSDG enabled for a subset of tests
if [[ "$TEST_RVSDG" == "yes" ]]; then
echo "Running RVSDG tests..."
NUMBA_USE_RVSDG_FRONTEND=1 NUMBA_CAPTURED_ERRORS=new_style NUMBA_ENABLE_CUDASIM=1 $SEGVCATCH python -m numba.runtests -b -v -m $TEST_NPROCS --junit -- numba.tests.test_usecases
NUMBA_USE_RVSDG_FRONTEND=1 NUMBA_ENABLE_CUDASIM=1 $SEGVCATCH python -m numba.runtests -b -v -m $TEST_NPROCS --junit -- numba.tests.test_usecases
fi
5 changes: 5 additions & 0 deletions docs/upcoming_changes/9549.deprecation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Deprecate `old_style` error-capturing
-------------------------------------

Per deprecation schedule, `old_style` error-capturing is deprecated and the
`default` is now `new_style`.
12 changes: 6 additions & 6 deletions numba/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ def _os_supports_avx():


_old_style_deprecation_msg = (
"Explicitly setting NUMBA_CAPTURED_ERRORS=old_style is deprecated. "
"See details at "
"NUMBA_CAPTURED_ERRORS=old_style is deprecated. "
"It will be removed in the next release. See details at "
"https://numba.readthedocs.io/en/latest/reference/deprecation.html#deprecation-of-old-style-numba-captured-errors" # noqa: E501
)


# Choose how to handle captured errors
def _validate_captured_errors_style(style_str):
# to prevent circular import
from numba.core.errors import NumbaPendingDeprecationWarning
from numba.core.errors import NumbaDeprecationWarning

rendered_style = str(style_str)
if rendered_style not in ('new_style', 'old_style', 'default'):
Expand All @@ -89,10 +89,10 @@ def _validate_captured_errors_style(style_str):
raise ValueError(msg)
else:
if rendered_style == 'default':
rendered_style = 'old_style'
rendered_style = 'new_style'
elif rendered_style == 'old_style':
warnings.warn(_old_style_deprecation_msg,
NumbaPendingDeprecationWarning)
NumbaDeprecationWarning)
return rendered_style


Expand Down Expand Up @@ -424,7 +424,7 @@ def avx_default():

CAPTURED_ERRORS = _readenv("NUMBA_CAPTURED_ERRORS",
_validate_captured_errors_style,
'old_style')
'new_style')

# CUDA Configs

Expand Down
4 changes: 2 additions & 2 deletions numba/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def shutting_down(globals=globals):
_old_style_deprecation_msg = (
"Code using Numba extension API maybe depending on 'old_style' "
"error-capturing, which is deprecated and will be replaced by 'new_style' "
"in a future release. See details at "
"in the next release. See details at "
"https://numba.readthedocs.io/en/latest/reference/deprecation.html#deprecation-of-old-style-numba-captured-errors" # noqa: E501
)

Expand All @@ -207,7 +207,7 @@ def _warn_old_style():
tb_last = traceback.format_tb(tb)[-1]
msg = f"{_old_style_deprecation_msg}\nException origin:\n{tb_last}"
warnings.warn(msg,
errors.NumbaPendingDeprecationWarning)
errors.NumbaDeprecationWarning)


def use_new_style_errors():
Expand Down
13 changes: 13 additions & 0 deletions numba/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ def test_illegal_error_style_handling(self):
self.assertIn(ex_expected, err_msg)
self.assertIn(source_compiled, out.decode('utf-8'))

def test_default_error_style_handling(self):
# ensure that the default is new_style
new_env = os.environ.copy()
new_env['NUMBA_CAPTURED_ERRORS'] = 'default'
code = ("from numba.core import config\n"
"print('---->', config.CAPTURED_ERRORS)\n"
"assert config.CAPTURED_ERRORS == 'new_style'")
out, err = run_in_subprocess(dedent(code), env=new_env)
err_msg = err.decode('utf-8')
out_msg = out.decode('utf-8')
ex_expected = "----> new_style"
self.assertIn(ex_expected, out_msg, msg=err_msg)


class TestNumbaOptLevel(TestCase):
# Tests that the setting of NUMBA_OPT influences the "cheap" module pass.
Expand Down
29 changes: 15 additions & 14 deletions numba/tests/test_errorhandling.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ def test_old_style_deprecation_on_import(self):

def _test_old_style_deprecation(self):
# Verify that old_style error raise the correct deprecation warning
warnings.simplefilter("always", errors.NumbaPendingDeprecationWarning)
warnings.simplefilter("always", errors.NumbaDeprecationWarning)

def bar(x):
pass
Expand All @@ -529,7 +529,7 @@ def bar(x):
def ol_bar(x):
raise AttributeError("Invalid attribute")

with self.assertWarns(errors.NumbaPendingDeprecationWarning) as warns:
with self.assertWarns(errors.NumbaDeprecationWarning) as warns:
with self.assertRaises(errors.TypingError):
@njit('void(int64)')
def foo(x):
Expand All @@ -546,18 +546,12 @@ def foo(x):
envvars={"NUMBA_CAPTURED_ERRORS": "old_style"},
)(_test_old_style_deprecation)

# Check deprecation warning when NUMBA_CAPTURED_ERRORS=default
# ("default" means "old_style")
test_default_old_style_deprecation = TestCase.run_test_in_subprocess(
envvars={"NUMBA_CAPTURED_ERRORS": "default"},
)(_test_old_style_deprecation)

@TestCase.run_test_in_subprocess(
envvars={"NUMBA_CAPTURED_ERRORS": "old_style"},
)
def test_old_style_no_deprecation(self):
# Verify that old_style error with NumbaError does not raise warnings
warnings.simplefilter("always", errors.NumbaPendingDeprecationWarning)
warnings.simplefilter("always", errors.NumbaDeprecationWarning)

def bar(x):
pass
Expand All @@ -575,12 +569,9 @@ def foo(x):
self.assertEqual(len(warns), 0,
msg="There should not be any warnings")

@TestCase.run_test_in_subprocess(
envvars={"NUMBA_CAPTURED_ERRORS": "new_style"},
)
def test_new_style_no_warnings(self):
def _test_new_style_no_warnings(self):
# Verify that new_style error raise no warnings
warnings.simplefilter("always", errors.NumbaPendingDeprecationWarning)
warnings.simplefilter("always", errors.NumbaDeprecationWarning)

def bar(x):
pass
Expand All @@ -598,6 +589,16 @@ def foo(x):
self.assertEqual(len(warns), 0,
msg="There should not be any warnings")

test_new_style_no_warnings = TestCase.run_test_in_subprocess(
envvars={"NUMBA_CAPTURED_ERRORS": "new_style"},
)(_test_new_style_no_warnings)

# Check deprecation warning when NUMBA_CAPTURED_ERRORS=default
# ("default" means "old_style")
test_default_new_style_no_deprecation = TestCase.run_test_in_subprocess(
envvars={"NUMBA_CAPTURED_ERRORS": "default"},
)(_test_new_style_no_warnings)


if __name__ == '__main__':
unittest.main()

0 comments on commit e467ae6

Please sign in to comment.