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

Function venv

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

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.85

Calls 10

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…