MCPcopy Index your code
hub / github.com/python/cpython / getsitepackages

Function getsitepackages

Lib/site.py:382–419  ·  view source on GitHub ↗

Returns a list containing all global site-packages directories. For each directory present in ``prefixes`` (or the global ``PREFIXES``), this function will find its `site-packages` subdirectory depending on the system environment, and will return a list of full paths.

(prefixes=None)

Source from the content-addressed store, hash-verified

380 return known_paths
381
382def getsitepackages(prefixes=None):
383 """Returns a list containing all global site-packages directories.
384
385 For each directory present in ``prefixes`` (or the global ``PREFIXES``),
386 this function will find its `site-packages` subdirectory depending on the
387 system environment, and will return a list of full paths.
388 """
389 sitepackages = []
390 seen = set()
391
392 if prefixes is None:
393 prefixes = PREFIXES
394
395 for prefix in prefixes:
396 if not prefix or prefix in seen:
397 continue
398 seen.add(prefix)
399
400 implementation = _get_implementation().lower()
401 ver = sys.version_info
402 if hasattr(sys, 'abiflags') and 't' in sys.abiflags:
403 abi_thread = 't'
404 else:
405 abi_thread = ''
406 if os.sep == '/':
407 libdirs = [sys.platlibdir]
408 if sys.platlibdir != "lib":
409 libdirs.append("lib")
410
411 for libdir in libdirs:
412 path = os.path.join(prefix, libdir,
413 f"{implementation}{ver[0]}.{ver[1]}{abi_thread}",
414 "site-packages")
415 sitepackages.append(path)
416 else:
417 sitepackages.append(prefix)
418 sitepackages.append(os.path.join(prefix, "Lib", "site-packages"))
419 return sitepackages
420
421def addsitepackages(known_paths, prefixes=None):
422 """Add site-packages to sys.path"""

Callers 1

addsitepackagesFunction · 0.85

Calls 6

setFunction · 0.85
_get_implementationFunction · 0.70
addMethod · 0.45
lowerMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…