|
10 | 10 | import itertools |
11 | 11 | import os |
12 | 12 | import os.path |
13 | | -import platform |
14 | | -import re |
15 | 13 | import sys |
16 | 14 | import sysconfig |
17 | 15 | import traceback |
|
39 | 37 | from coverage.plugin_support import Plugins |
40 | 38 |
|
41 | 39 |
|
42 | | -modules_we_happen_to_have: list[ModuleType] = [ |
43 | | - inspect, |
44 | | - itertools, |
45 | | - os, |
46 | | - platform, |
47 | | - re, |
48 | | - sysconfig, |
49 | | - traceback, |
50 | | -] |
51 | | - |
52 | | -if env.PYPY: |
53 | | - # Pypy has some unusual stuff in the "stdlib". Consider those locations |
54 | | - # when deciding where the stdlib is. These modules are not used for anything, |
55 | | - # they are modules importable from the pypy lib directories, so that we can |
56 | | - # find those directories. |
57 | | - import _pypy_irc_topic # pylint: disable=import-error |
58 | | - import _structseq # pylint: disable=import-error |
59 | | - |
60 | | - modules_we_happen_to_have.extend([_structseq, _pypy_irc_topic]) |
61 | | - |
62 | | - |
63 | 40 | os = isolate_module(os) |
64 | 41 |
|
65 | 42 |
|
@@ -145,30 +122,24 @@ def file_and_path_for_module(modulename: str) -> tuple[str | None, list[str]]: |
145 | 122 | return filename, path |
146 | 123 |
|
147 | 124 |
|
| 125 | +def add_sysconfig_paths(paths: set[str], path_names: list[str]) -> None: |
| 126 | + """Get paths from `sysconfig.get_paths`""" |
| 127 | + scheme_names = set(sysconfig.get_scheme_names()) |
| 128 | + |
| 129 | + for scheme in scheme_names: |
| 130 | + config_paths = sysconfig.get_paths(scheme) |
| 131 | + for path_name in path_names: |
| 132 | + paths.add(config_paths[path_name]) |
| 133 | + |
| 134 | + |
148 | 135 | def add_stdlib_paths(paths: set[str]) -> None: |
149 | 136 | """Add paths where the stdlib can be found to the set `paths`.""" |
150 | | - # Look at where some standard modules are located. That's the |
151 | | - # indication for "installed with the interpreter". In some |
152 | | - # environments (virtualenv, for example), these modules may be |
153 | | - # spread across a few locations. Look at all the candidate modules |
154 | | - # we've imported, and take all the different ones. |
155 | | - for m in modules_we_happen_to_have: |
156 | | - if hasattr(m, "__file__"): |
157 | | - paths.add(canonical_path(m, directory=True)) |
| 137 | + add_sysconfig_paths(paths, ["stdlib", "platstdlib"]) |
158 | 138 |
|
159 | 139 |
|
160 | 140 | def add_third_party_paths(paths: set[str]) -> None: |
161 | 141 | """Add locations for third-party packages to the set `paths`.""" |
162 | | - # Get the paths that sysconfig knows about. |
163 | | - scheme_names = set(sysconfig.get_scheme_names()) |
164 | | - |
165 | | - for scheme in scheme_names: |
166 | | - # https://foss.heptapod.net/pypy/pypy/-/issues/3433 |
167 | | - better_scheme = "pypy_posix" if scheme == "pypy" else scheme |
168 | | - if os.name in better_scheme.split("_"): |
169 | | - config_paths = sysconfig.get_paths(scheme) |
170 | | - for path_name in ["platlib", "purelib", "scripts"]: |
171 | | - paths.add(config_paths[path_name]) |
| 142 | + add_sysconfig_paths(paths, ["platlib", "purelib", "scripts"]) |
172 | 143 |
|
173 | 144 |
|
174 | 145 | def add_coverage_paths(paths: set[str]) -> None: |
@@ -234,11 +205,16 @@ def _debug(msg: str) -> None: |
234 | 205 | if self.debug: |
235 | 206 | self.debug.write(msg) |
236 | 207 |
|
237 | | - # The matchers for should_trace. |
238 | | - |
239 | 208 | # Generally useful information |
240 | 209 | _debug("sys.path:" + "".join(f"\n {p}" for p in sys.path)) |
241 | 210 |
|
| 211 | + if self.debug: |
| 212 | + _debug("sysconfig paths:") |
| 213 | + for scheme in sorted(sysconfig.get_scheme_names()): |
| 214 | + _debug(f" {scheme}:") |
| 215 | + for k, v in sysconfig.get_paths(scheme).items(): |
| 216 | + _debug(f" {k}: {v}") |
| 217 | + |
242 | 218 | # Create the matchers we need for should_trace |
243 | 219 | self.source_match = None |
244 | 220 | self.source_pkgs_match = None |
|
0 commit comments