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

Function venv

Lib/site.py:596–648  ·  view source on GitHub ↗
(known_paths)

Source from the content-addressed store, hash-verified

594
595
596def venv(known_paths):
597 global PREFIXES, ENABLE_USER_SITE
598
599 env = os.environ
600 if sys.platform == 'darwin' and '__PYVENV_LAUNCHER__' in env:
601 executable = sys._base_executable = os.environ['__PYVENV_LAUNCHER__']
602 else:
603 executable = sys.executable
604 exe_dir = os.path.dirname(os.path.abspath(executable))
605 site_prefix = os.path.dirname(exe_dir)
606 sys._home = None
607 conf_basename = 'pyvenv.cfg'
608 candidate_conf = next(
609 (
610 conffile for conffile in (
611 os.path.join(exe_dir, conf_basename),
612 os.path.join(site_prefix, conf_basename)
613 )
614 if os.path.isfile(conffile)
615 ),
616 None
617 )
618
619 if candidate_conf:
620 virtual_conf = candidate_conf
621 system_site = "true"
622 # Issue 25185: Use UTF-8, as that's what the venv module uses when
623 # writing the file.
624 with open(virtual_conf, encoding='utf-8') as f:
625 for line in f:
626 if '=' in line:
627 key, _, value = line.partition('=')
628 key = key.strip().lower()
629 value = value.strip()
630 if key == 'include-system-site-packages':
631 system_site = value.lower()
632 elif key == 'home':
633 sys._home = value
634
635 if sys.prefix != site_prefix:
636 _warn(f'Unexpected value in sys.prefix, expected {site_prefix}, got {sys.prefix}', RuntimeWarning)
637 if sys.exec_prefix != site_prefix:
638 _warn(f'Unexpected value in sys.exec_prefix, expected {site_prefix}, got {sys.exec_prefix}', RuntimeWarning)
639
640 # Doing this here ensures venv takes precedence over user-site
641 addsitepackages(known_paths, [sys.prefix])
642
643 if system_site == "true":
644 PREFIXES += [sys.base_prefix, sys.base_exec_prefix]
645 else:
646 ENABLE_USER_SITE = False
647
648 return known_paths
649
650
651def execsitecustomize():

Callers 1

mainFunction · 0.85

Calls 9

nextFunction · 0.85
addsitepackagesFunction · 0.85
openFunction · 0.70
_warnFunction · 0.70
joinMethod · 0.45
isfileMethod · 0.45
partitionMethod · 0.45
lowerMethod · 0.45
stripMethod · 0.45

Tested by

no test coverage detected