1111import os .path
1212import posixpath
1313import re
14+ import site
1415import sys
15- import sysconfig
1616
1717from pathlib import Path
1818from typing import Callable
19- from collections .abc import Iterable , Iterator
19+ from collections .abc import Iterable
2020
2121from coverage import env
2222from coverage .exceptions import ConfigError
@@ -220,8 +220,8 @@ def prep_patterns(patterns: Iterable[str]) -> list[str]:
220220
221221def create_pth_file () -> Path | None :
222222 """Create .pth file for measuring subprocesses."""
223- for pth_dir in _possible_pth_dirs (): # pragma: part covered
224- pth_file = pth_dir / "subcover.pth"
223+ for pth_dir in site . getsitepackages (): # pragma: part covered
224+ pth_file = Path ( pth_dir ) / "subcover.pth"
225225 try :
226226 pth_file .write_text ("import coverage; coverage.process_startup()\n " , encoding = "utf-8" )
227227 except OSError : # pragma: cant happen
@@ -231,20 +231,6 @@ def create_pth_file() -> Path | None:
231231 return None # pragma: cant happen
232232
233233
234- def _possible_pth_dirs () -> Iterator [Path ]:
235- """Produce a sequence of directories for trying to write .pth files."""
236- # First look through sys.path, and if we find a .pth file, then it's a good
237- # place to put ours.
238- for pth_dir in map (Path , sys .path ): # pragma: part covered
239- pth_files = list (pth_dir .glob ("*.pth" ))
240- if pth_files :
241- yield pth_dir
242-
243- # If we're still looking, then try the Python library directory.
244- # https://github.com/nedbat/coveragepy/issues/339
245- yield Path (sysconfig .get_path ("purelib" )) # pragma: cant happen
246-
247-
248234class TreeMatcher :
249235 """A matcher for files in a tree.
250236
0 commit comments