setup: avoid the deprecated `distutils.spawn.find_executable`
authorMatt Harbison <mharbison@atto.com>
Thu, 05 Sep 2024 17:12:52 -0400
changeset 51849 4dc1fc2b2f3a
parent 51848 3f0db3b6bf14
child 51850 f5c46c3518a5
setup: avoid the deprecated `distutils.spawn.find_executable` I noticed this was flagged with `DeprecationWarning` in py3.12 with `setuptools` 74.1.2, and it suggested `shutil.which()` instead. The signatures aren't the same, but the additional `mode` argument in the middle of the latter defaults to `os.F_OK | os.X_OK`, which maintains the same semantics.
setup.py
--- a/setup.py	Thu Sep 05 16:59:36 2024 -0400
+++ b/setup.py	Thu Sep 05 17:12:52 2024 -0400
@@ -125,7 +125,7 @@
 from distutils.command.install_lib import install_lib
 from distutils.command.install_scripts import install_scripts
 from distutils import log
-from distutils.spawn import spawn, find_executable
+from distutils.spawn import spawn
 from distutils import file_util
 from distutils.errors import (
     CCompilerError,
@@ -464,6 +464,12 @@
     description = "build translations (.mo files)"
 
     def run(self):
+        try:
+            from shutil import which as find_executable
+        except ImportError:
+            # Deprecated in py3.12
+            from distutils.spawn import find_executable
+
         if not find_executable('msgfmt'):
             self.warn(
                 "could not find msgfmt executable, no translations "