MCPcopy Index your code
hub / github.com/RustPython/RustPython / getsitepackages

Function getsitepackages

Lib/site.py:385–422  ·  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

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

Callers 1

addsitepackagesFunction · 0.85

Calls 7

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

Tested by

no test coverage detected