From 5ff7aee8378b721280a1a12f039c07641635f957 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Wed, 5 May 2021 23:48:14 +0100 Subject: [PATCH] build: remove dependency on `distutils.spawn` Debian based packages of Python 3 do not include `distutils.spawn` and require an additional apt package to be installed (`python3-distutils`). Replace use of `distutils.spawn` with `shutil.which`, available in all versions of Python currently allowed by our configure scripts. For the `configure` script only, fall back to `distutils.spawn` to allow friendlier error messages when run on older unsupported versions of Python (e.g. 2.7). `configure.py` also uses `distutils.version` -- this appears to be available in Debian packaged Python 3 without installing `python3-distutils` so has been left as-is. PR-URL: https://github.com/nodejs/node/pull/38600 Refs: https://github.com/nodejs/node/issues/30189 Reviewed-By: Darshan Sen Reviewed-By: Rich Trott Reviewed-By: Christian Clauss Reviewed-By: James M Snell --- BUILDING.md | 7 ------- configure | 7 +++++-- configure.py | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/BUILDING.md b/BUILDING.md index 2b29b444414625..21bb35fa922daf 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -250,8 +250,6 @@ Installation via Linux package manager can be achieved with: FreeBSD and OpenBSD users may also need to install `libexecinfo`. -Python 3 users may also need to install `python3-distutils`. - #### macOS prerequisites * Xcode Command Line Tools >= 10 for macOS @@ -277,11 +275,6 @@ $ ./configure $ make -j4 ``` -If you run into a `No module named 'distutils.spawn'` error when executing -`./configure`, please try `python3 -m pip install --upgrade setuptools` or -`sudo apt install python3-distutils -y`. -For more information, see . - The `-j4` option will cause `make` to run 4 simultaneous compilation jobs which may reduce build time. For more information, see the [GNU Make Documentation](https://www.gnu.org/software/make/manual/html_node/Parallel.html). diff --git a/configure b/configure index ca2cd8aa9e6358..4fec68abf979e1 100755 --- a/configure +++ b/configure @@ -18,7 +18,10 @@ exec python "$0" "$@" del _ import sys -from distutils.spawn import find_executable +try: + from shutil import which +except ImportError: + from distutils.spawn import find_executable as which print('Node.js configure: Found Python {0}.{1}.{2}...'.format(*sys.version_info)) acceptable_pythons = ((3, 9), (3, 8), (3, 7), (3, 6), (3, 5), (2, 7)) @@ -28,7 +31,7 @@ else: python_cmds = ['python{0}.{1}'.format(*vers) for vers in acceptable_pythons] sys.stderr.write('Please use {0}.\n'.format(' or '.join(python_cmds))) for python_cmd in python_cmds: - python_cmd_path = find_executable(python_cmd) + python_cmd_path = which(python_cmd) if python_cmd_path and 'pyenv/shims' not in python_cmd_path: sys.stderr.write('\t{0} {1}\n'.format(python_cmd_path, ' '.join(sys.argv[:1]))) diff --git a/configure.py b/configure.py index a477bd1c9578d0..a9bf9af68b0643 100755 --- a/configure.py +++ b/configure.py @@ -14,7 +14,7 @@ import bz2 import io -from distutils.spawn import find_executable as which +from shutil import which from distutils.version import StrictVersion # If not run from node/, cd to node/.