From 700bf93631b8c999f0421fffd74b4a29eb2685a3 Mon Sep 17 00:00:00 2001 From: Enno Hermann Date: Thu, 9 Nov 2023 11:49:12 +0100 Subject: [PATCH] [tools] Replace uses of Python distutils The `distutils` packages has been removed in Python 3.12: https://docs.python.org/3.11/distutils/index.html The `sysconfig` package is available since Python 3.2 and provides the necessary replacement functionality: https://docs.python.org/3/library/sysconfig.html --- tools/extras/install_cffi.sh | 2 +- tools/extras/install_mmseg.sh | 8 ++++---- tools/extras/install_phonetisaurus.sh | 8 ++++---- tools/extras/install_sequitur.sh | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tools/extras/install_cffi.sh b/tools/extras/install_cffi.sh index dc7f91724a7..5ac9904173e 100755 --- a/tools/extras/install_cffi.sh +++ b/tools/extras/install_cffi.sh @@ -35,7 +35,7 @@ echo "**** Installing Cffi and dependencies" echo "Checking for Python-Dev" # copied from https://stackoverflow.com/questions/4848566/check-for-existence-of-python-dev-files-from-bash-script -if [ ! -e $(python -c 'from distutils.sysconfig import get_makefile_filename as m; print m()') ]; then +if [ ! -e $(python -c 'from sysconfig import get_makefile_filename as m; print m()') ]; then echo "On Debian/Ubuntu like system install by 'sudo apt-get python-dev' package." echo "On Fedora by 'yum install python-devel'" echo "On Mac OS X by 'brew install python'" diff --git a/tools/extras/install_mmseg.sh b/tools/extras/install_mmseg.sh index a76b98e2061..e6e17716718 100755 --- a/tools/extras/install_mmseg.sh +++ b/tools/extras/install_mmseg.sh @@ -16,13 +16,13 @@ fi # Install python-devel package if not already available -# first, makes sure distutils.sysconfig usable -if ! $(python -c "import distutils.sysconfig" &> /dev/null); then - echo "$0: WARNING: python library distutils.sysconfig not usable, this is necessary to figure out the path of Python.h." >&2 +# first, makes sure sysconfig is usable +if ! $(python -c "import sysconfig" &> /dev/null); then + echo "$0: WARNING: python library sysconfig not usable, this is necessary to figure out the path of Python.h." >&2 echo "Proceeding with installation." >&2 else # get include path for this python version - INCLUDE_PY=$(python -c "from distutils import sysconfig as s; print(s.get_python_inc())") + INCLUDE_PY=$(python -c "import sysconfig as s; print(s.get_path('include'))") if [ ! -f "${INCLUDE_PY}/Python.h" ]; then echo "$0 : ERROR: python-devel/python-dev not installed" >&2 if which yum >&/dev/null; then diff --git a/tools/extras/install_phonetisaurus.sh b/tools/extras/install_phonetisaurus.sh index 8a07c5f5ca5..e407978972f 100755 --- a/tools/extras/install_phonetisaurus.sh +++ b/tools/extras/install_phonetisaurus.sh @@ -15,16 +15,16 @@ fi echo "You must call this script from the tools/ directory" && exit 1; # Install python-devel package if not already available -# first, makes sure distutils.sysconfig usable +# first, makes sure sysconfig is usable # We are not currently compiling the bindings by default, but it seems # worth it to keep this section as we do have them and they will # probably be used. -if ! $(python -c "import distutils.sysconfig" &> /dev/null); then - echo "$0: WARNING: python library distutils.sysconfig not usable, this is necessary to figure out the path of Python.h." >&2 +if ! $(python -c "import sysconfig" &> /dev/null); then + echo "$0: WARNING: python library sysconfig not usable, this is necessary to figure out the path of Python.h." >&2 echo "Proceeding with installation." >&2 else # get include path for this python version - INCLUDE_PY=$(python -c "from distutils import sysconfig as s; print(s.get_python_inc())") + INCLUDE_PY=$(python -c "import sysconfig as s; print(s.get_path('include'))") if [ ! -f "${INCLUDE_PY}/Python.h" ]; then echo "$0 : ERROR: python-devel/python-dev not installed" >&2 if which yum >&/dev/null; then diff --git a/tools/extras/install_sequitur.sh b/tools/extras/install_sequitur.sh index b70e6cbb447..62b27e451ac 100755 --- a/tools/extras/install_sequitur.sh +++ b/tools/extras/install_sequitur.sh @@ -15,13 +15,13 @@ fi echo "You must call this script from the tools/ directory" && exit 1; # Install python-devel package if not already available -# first, makes sure distutils.sysconfig usable -if ! $(python -c "import distutils.sysconfig" &> /dev/null); then - echo "$0: WARNING: python library distutils.sysconfig not usable, this is necessary to figure out the path of Python.h." >&2 +# first, makes sure sysconfig is usable +if ! $(python -c "import sysconfig" &> /dev/null); then + echo "$0: WARNING: python library sysconfig not usable, this is necessary to figure out the path of Python.h." >&2 echo "Proceeding with installation." >&2 else # get include path for this python version - INCLUDE_PY=$(python -c "from distutils import sysconfig as s; print(s.get_python_inc())") + INCLUDE_PY=$(python -c "import sysconfig as s; print(s.get_path('include'))") if [ ! -f "${INCLUDE_PY}/Python.h" ]; then echo "$0 : ERROR: python-devel/python-dev not installed" >&2 if which yum >&/dev/null; then