[Python-checkins] bpo-41282: Fix distutils.utils.byte_compile() DeprecationWarning (GH-25406)
vstinner
webhook-mailer at python.org
Fri Apr 16 05:26:46 EDT 2021
https://github.com/python/cpython/commit/69ca32e0d34fe17dd242592b6f8754cda7bae684
commit: 69ca32e0d34fe17dd242592b6f8754cda7bae684
branch: master
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2021-04-16T11:26:40+02:00
summary:
bpo-41282: Fix distutils.utils.byte_compile() DeprecationWarning (GH-25406)
* byte_compile() of distutils.utils no longer logs a
DeprecationWarning
* test_distutils no longer logs a DeprecationWarning
files:
M Lib/distutils/__init__.py
M Lib/distutils/util.py
M Lib/test/test_distutils.py
diff --git a/Lib/distutils/__init__.py b/Lib/distutils/__init__.py
index 8eef902f7d620..fdad6f65a7856 100644
--- a/Lib/distutils/__init__.py
+++ b/Lib/distutils/__init__.py
@@ -13,7 +13,8 @@
__version__ = sys.version[:sys.version.index(' ')]
-warnings.warn("The distutils package is deprecated and slated for "
- "removal in Python 3.12. Use setuptools or check "
- "PEP 632 for potential alternatives",
+_DEPRECATION_MESSAGE = ("The distutils package is deprecated and slated for "
+ "removal in Python 3.12. Use setuptools or check "
+ "PEP 632 for potential alternatives")
+warnings.warn(_DEPRECATION_MESSAGE,
DeprecationWarning, 2)
diff --git a/Lib/distutils/util.py b/Lib/distutils/util.py
index 4b002ecef1df8..2ce5c5b64d62f 100644
--- a/Lib/distutils/util.py
+++ b/Lib/distutils/util.py
@@ -9,6 +9,7 @@
import importlib.util
import string
import sys
+import distutils
from distutils.errors import DistutilsPlatformError
from distutils.dep_util import newer
from distutils.spawn import spawn
@@ -419,8 +420,10 @@ def byte_compile (py_files,
direct=1)
""" % (optimize, force, prefix, base_dir, verbose))
+ msg = distutils._DEPRECATION_MESSAGE
cmd = [sys.executable]
cmd.extend(subprocess._optim_args_from_interpreter_flags())
+ cmd.append(f'-Wignore:{msg}:DeprecationWarning')
cmd.append(script_name)
spawn(cmd, dry_run=dry_run)
execute(os.remove, (script_name,), "removing %s" % script_name,
diff --git a/Lib/test/test_distutils.py b/Lib/test/test_distutils.py
index a37f11791754d..de94da54798ce 100644
--- a/Lib/test/test_distutils.py
+++ b/Lib/test/test_distutils.py
@@ -5,14 +5,20 @@
be run.
"""
-import distutils.tests
-import test.support
+import warnings
+from test import support
+from test.support import warnings_helper
+
+with warnings_helper.check_warnings(
+ ("The distutils package is deprecated", DeprecationWarning)):
+
+ import distutils.tests
def test_main():
# used by regrtest
- test.support.run_unittest(distutils.tests.test_suite())
- test.support.reap_children()
+ support.run_unittest(distutils.tests.test_suite())
+ support.reap_children()
def load_tests(*_):
More information about the Python-checkins
mailing list