From bfa00fc63805b8dc2ed7bce9821b351dd718d47e Mon Sep 17 00:00:00 2001 From: Robert Smith Date: Tue, 30 Jul 2024 11:44:05 +1000 Subject: [PATCH] Deprecated distutils module in Python 3.12 For 3.0.x, alias shutil.which() as find_executable(); load distutils.find_executable() as itself on Python 2. Reverts and replaces fcf0ba9c0394c77ec7bb81f07756dd26cae8cf23, which had erroneous indentation. --- bin/mrtrix3.py | 1 - lib/mrtrix3/path.py | 7 ++++++- lib/mrtrix3/run.py | 7 ++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/bin/mrtrix3.py b/bin/mrtrix3.py index 21c9b827e0..12c0164325 100644 --- a/bin/mrtrix3.py +++ b/bin/mrtrix3.py @@ -15,7 +15,6 @@ # For more details, see http://www.mrtrix.org/. import os, sys -from distutils.spawn import find_executable try: # since importlib code below only works on Python 3.5+ diff --git a/lib/mrtrix3/path.py b/lib/mrtrix3/path.py index 7542dbcec3..53c7e8a8cf 100644 --- a/lib/mrtrix3/path.py +++ b/lib/mrtrix3/path.py @@ -21,13 +21,18 @@ import ctypes, errno, inspect, os, random, string, subprocess, time -from distutils.spawn import find_executable # Function can be used in isolation if potentially needing to place quotation marks around a # filesystem path that is to be included as part of a command string try: from shlex import quote except ImportError: from pipes import quote +# Distutils removed in 3.12, but shutil.which not available in 2.7 +try: + from shutil import which as find_executable +except ImportError: + from distutils.spawn import find_executable + from mrtrix3 import CONFIG from mrtrix3.utils import STRING_TYPES diff --git a/lib/mrtrix3/run.py b/lib/mrtrix3/run.py index b4af7dc8b7..f2b7bc2f0e 100644 --- a/lib/mrtrix3/run.py +++ b/lib/mrtrix3/run.py @@ -17,10 +17,15 @@ # pylint: disable=unspecified-encoding import collections, itertools, os, shlex, signal, string, subprocess, sys, tempfile, threading -from distutils.spawn import find_executable from mrtrix3 import ANSI, BIN_PATH, COMMAND_HISTORY_STRING, EXE_LIST, MRtrixBaseError, MRtrixError from mrtrix3.utils import STRING_TYPES +# Distutils removed in 3.12, but shutil.which not available in 2.7 +try: + from shutil import which as find_executable +except ImportError: + from distutils.spawn import find_executable + IOStream = collections.namedtuple('IOStream', 'handle filename')