|
39 | 39 | :var BUILTIN_MODULES: dictionary with builtin module names has key
|
40 | 40 | """
|
41 | 41 |
|
42 |
| -# We disable the import-error so pylint can work without distutils installed. |
43 |
| -# pylint: disable=no-name-in-module,useless-suppression |
44 |
| - |
45 | 42 | import importlib
|
46 | 43 | import importlib.machinery
|
47 | 44 | import importlib.util
|
|
51 | 48 | import sys
|
52 | 49 | import sysconfig
|
53 | 50 | import types
|
54 |
| -from distutils.errors import DistutilsPlatformError # pylint: disable=import-error |
55 |
| -from distutils.sysconfig import get_python_lib # pylint: disable=import-error |
56 | 51 | from pathlib import Path
|
57 | 52 | from typing import Dict, Set
|
58 | 53 |
|
59 | 54 | from astroid.interpreter._import import spec, util
|
60 | 55 |
|
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 |
| - |
66 | 56 | if sys.platform.startswith("win"):
|
67 | 57 | PY_SOURCE_EXTS = ("py", "pyw")
|
68 | 58 | PY_COMPILED_EXTS = ("dll", "pyd")
|
|
71 | 61 | PY_COMPILED_EXTS = ("so",)
|
72 | 62 |
|
73 | 63 |
|
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")} |
90 | 67 |
|
91 | 68 | if os.name == "nt":
|
92 | 69 | STD_LIB_DIRS.add(os.path.join(sys.prefix, "dlls"))
|
|
0 commit comments