]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41282: Fix distutils.utils.byte_compile() DeprecationWarning (GH-25406)
authorVictor Stinner <vstinner@python.org>
Fri, 16 Apr 2021 09:26:40 +0000 (11:26 +0200)
committerGitHub <noreply@github.com>
Fri, 16 Apr 2021 09:26:40 +0000 (11:26 +0200)
* byte_compile() of distutils.utils no longer logs a
  DeprecationWarning
* test_distutils no longer logs a DeprecationWarning

Lib/distutils/__init__.py
Lib/distutils/util.py
Lib/test/test_distutils.py

index 8eef902f7d6204b09d29b70d269e4db65f91e5be..fdad6f65a785627e107950f535bc1180922fb86a 100644 (file)
@@ -13,7 +13,8 @@ import warnings
 
 __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)
index 4b002ecef1df8ffd79a9aa067640eb43027a9bf2..2ce5c5b64d62fa0731dfffd0d85c25c0affadd55 100644 (file)
@@ -9,6 +9,7 @@ import re
 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 @@ byte_compile(files, optimize=%r, force=%r,
              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,
index a37f11791754d2645a127d26d9db8940465bd088..de94da54798ce38ec32a421b46b5833475dc58b0 100644 (file)
@@ -5,14 +5,20 @@ the test_suite() function there returns a test suite that's ready to
 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(*_):