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

Method test_init_pyvenv_cfg

Lib/test/test_embed.py:1681–1750  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1679 ignore_stderr=False, cwd=tmpdir)
1680
1681 def test_init_pyvenv_cfg(self):
1682 # Test path configuration with pyvenv.cfg configuration file
1683
1684 with self.tmpdir_with_python() as tmpdir, \
1685 tempfile.TemporaryDirectory() as pyvenv_home:
1686
1687 ver = sys.version_info
1688 base_prefix = sysconfig.get_config_var("prefix")
1689
1690 # gh-128690: base_exec_prefix depends if PLATSTDLIB_LANDMARK exists
1691 platstdlib = os.path.join(base_prefix, PLATSTDLIB_LANDMARK)
1692 change_exec_prefix = not os.path.isdir(platstdlib)
1693
1694 if not MS_WINDOWS:
1695 lib_dynload = os.path.join(pyvenv_home,
1696 sys.platlibdir,
1697 f'python{ver.major}.{ver.minor}{ABI_THREAD}',
1698 'lib-dynload')
1699 os.makedirs(lib_dynload)
1700 else:
1701 lib_folder = os.path.join(pyvenv_home, 'Lib')
1702 os.makedirs(lib_folder)
1703 # getpath.py uses Lib\os.py as the LANDMARK
1704 shutil.copyfile(
1705 os.path.join(support.STDLIB_DIR, 'os.py'),
1706 os.path.join(lib_folder, 'os.py'),
1707 )
1708
1709 filename = os.path.join(tmpdir, 'pyvenv.cfg')
1710 with open(filename, "w", encoding="utf8") as fp:
1711 print("home = %s" % pyvenv_home, file=fp)
1712 print("include-system-site-packages = false", file=fp)
1713
1714 paths = self.module_search_paths()
1715 if not MS_WINDOWS:
1716 if change_exec_prefix:
1717 paths[-1] = lib_dynload
1718 else:
1719 paths = [
1720 os.path.join(tmpdir, os.path.basename(paths[0])),
1721 pyvenv_home,
1722 os.path.join(pyvenv_home, "Lib"),
1723 ]
1724
1725 executable = self.test_exe
1726 base_executable = os.path.join(pyvenv_home, os.path.basename(executable))
1727 config = {
1728 'base_prefix': base_prefix,
1729 'exec_prefix': tmpdir,
1730 'prefix': tmpdir,
1731 'base_executable': base_executable,
1732 'executable': executable,
1733 'module_search_paths': paths,
1734 }
1735 if change_exec_prefix:
1736 config['base_exec_prefix'] = pyvenv_home
1737 if MS_WINDOWS:
1738 config['base_prefix'] = pyvenv_home

Callers

nothing calls this directly

Calls 9

tmpdir_with_pythonMethod · 0.95
module_search_pathsMethod · 0.95
copy_paths_by_envMethod · 0.95
check_all_configsMethod · 0.95
copyfileMethod · 0.80
openFunction · 0.50
joinMethod · 0.45
isdirMethod · 0.45
basenameMethod · 0.45

Tested by

no test coverage detected