Skip to content

Commit 9566d10

Browse files
DanielNoordcdce8p
andauthored
Use sysconfig.get_path instead of distutils to find stdlib (#1323)
Co-authored-by: Marc Mueller <[email protected]>
1 parent d038b9f commit 9566d10

File tree

2 files changed

+10
-26
lines changed

2 files changed

+10
-26
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ Release date: TBA
2020

2121
Closes #1330
2222

23+
* Use ``sysconfig`` instead of ``distutils`` to determine the location of
24+
python stdlib files and packages.
25+
26+
Related pull requests: #1322, #1323, #1324
27+
Closes #1282
28+
Ref #1103
29+
2330
What's New in astroid 2.9.4?
2431
============================
2532
Release date: TBA

astroid/modutils.py

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@
3939
:var BUILTIN_MODULES: dictionary with builtin module names has key
4040
"""
4141

42-
# We disable the import-error so pylint can work without distutils installed.
43-
# pylint: disable=no-name-in-module,useless-suppression
44-
4542
import importlib
4643
import importlib.machinery
4744
import importlib.util
@@ -51,18 +48,11 @@
5148
import sys
5249
import sysconfig
5350
import types
54-
from distutils.errors import DistutilsPlatformError # pylint: disable=import-error
55-
from distutils.sysconfig import get_python_lib # pylint: disable=import-error
5651
from pathlib import Path
5752
from typing import Dict, Set
5853

5954
from astroid.interpreter._import import spec, util
6055

61-
# distutils is replaced by virtualenv with a module that does
62-
# weird path manipulations in order to get to the
63-
# real distutils module.
64-
65-
6656
if sys.platform.startswith("win"):
6757
PY_SOURCE_EXTS = ("py", "pyw")
6858
PY_COMPILED_EXTS = ("dll", "pyd")
@@ -71,22 +61,9 @@
7161
PY_COMPILED_EXTS = ("so",)
7262

7363

74-
try:
75-
# The explicit sys.prefix is to work around a patch in virtualenv that
76-
# replaces the 'real' sys.prefix (i.e. the location of the binary)
77-
# with the prefix from which the virtualenv was created. This throws
78-
# off the detection logic for standard library modules, thus the
79-
# workaround.
80-
STD_LIB_DIRS = {
81-
get_python_lib(standard_lib=True, prefix=sys.prefix),
82-
# Take care of installations where exec_prefix != prefix.
83-
get_python_lib(standard_lib=True, prefix=sys.exec_prefix),
84-
get_python_lib(standard_lib=True),
85-
}
86-
# get_python_lib(standard_lib=1) is not available on pypy, set STD_LIB_DIR to
87-
# non-valid path, see https://bugs.pypy.org/issue1164
88-
except DistutilsPlatformError:
89-
STD_LIB_DIRS = set()
64+
# TODO: Adding `platstdlib` is a fix for a workaround in virtualenv. At some point we should
65+
# revisit whether this is still necessary. See https://github.com/PyCQA/astroid/pull/1323.
66+
STD_LIB_DIRS = {sysconfig.get_path("stdlib"), sysconfig.get_path("platstdlib")}
9067

9168
if os.name == "nt":
9269
STD_LIB_DIRS.add(os.path.join(sys.prefix, "dlls"))

0 commit comments

Comments
 (0)