Skip to content

Commit 3bb12db

Browse files
richardlautargos
authored andcommitted
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: #38600 Refs: #30189 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Christian Clauss <cclauss@me.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent d3de0ef commit 3bb12db

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

BUILDING.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,6 @@ Installation via Linux package manager can be achieved with:
246246

247247
FreeBSD and OpenBSD users may also need to install `libexecinfo`.
248248

249-
Python 3 users may also need to install `python3-distutils`.
250-
251249
#### macOS prerequisites
252250

253251
* Xcode Command Line Tools >= 11 for macOS
@@ -271,11 +269,6 @@ $ ./configure
271269
$ make -j4
272270
```
273271

274-
If you run into a `No module named 'distutils.spawn'` error when executing
275-
`./configure`, please try `python3 -m pip install --upgrade setuptools` or
276-
`sudo apt install python3-distutils -y`.
277-
For more information, see <https://github.com/nodejs/node/issues/30189>.
278-
279272
The `-j4` option will cause `make` to run 4 simultaneous compilation jobs which
280273
may reduce build time. For more information, see the
281274
[GNU Make Documentation](https://www.gnu.org/software/make/manual/html_node/Parallel.html).

configure

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ exec python "$0" "$@"
1515
del _
1616

1717
import sys
18-
from distutils.spawn import find_executable
18+
try:
19+
from shutil import which
20+
except ImportError:
21+
from distutils.spawn import find_executable as which
1922

2023
print('Node.js configure: Found Python {}.{}.{}...'.format(*sys.version_info))
2124
acceptable_pythons = ((3, 9), (3, 8), (3, 7), (3, 6))
@@ -25,7 +28,7 @@ else:
2528
python_cmds = ['python{}.{}'.format(*vers) for vers in acceptable_pythons]
2629
sys.stderr.write('Please use {}.\n'.format(' or '.join(python_cmds)))
2730
for python_cmd in python_cmds:
28-
python_cmd_path = find_executable(python_cmd)
31+
python_cmd_path = which(python_cmd)
2932
if python_cmd_path and 'pyenv/shims' not in python_cmd_path:
3033
sys.stderr.write('\t{} {}\n'.format(python_cmd_path, ' '.join(sys.argv[:1])))
3134
sys.exit(1)

configure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import bz2
1515
import io
1616

17-
from distutils.spawn import find_executable as which
17+
from shutil import which
1818
from distutils.version import StrictVersion
1919

2020
# If not run from node/, cd to node/.

0 commit comments

Comments
 (0)