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

Method tmpdir_with_python

Lib/test/test_embed.py:1447–1472  ·  view source on GitHub ↗
(self, subdir=None)

Source from the content-addressed store, hash-verified

1445
1446 @contextlib.contextmanager
1447 def tmpdir_with_python(self, subdir=None):
1448 # Temporary directory with a copy of the Python program
1449 with tempfile.TemporaryDirectory() as tmpdir:
1450 # bpo-38234: On macOS and FreeBSD, the temporary directory
1451 # can be symbolic link. For example, /tmp can be a symbolic link
1452 # to /var/tmp. Call realpath() to resolve all symbolic links.
1453 tmpdir = os.path.realpath(tmpdir)
1454 if subdir:
1455 tmpdir = os.path.normpath(os.path.join(tmpdir, subdir))
1456 os.makedirs(tmpdir)
1457
1458 if MS_WINDOWS:
1459 # Copy pythonXY.dll (or pythonXY_d.dll)
1460 import fnmatch
1461 exedir = os.path.dirname(self.test_exe)
1462 for f in os.listdir(exedir):
1463 if fnmatch.fnmatch(f, '*.dll'):
1464 shutil.copyfile(os.path.join(exedir, f), os.path.join(tmpdir, f))
1465
1466 # Copy Python program
1467 exec_copy = os.path.join(tmpdir, os.path.basename(self.test_exe))
1468 shutil.copyfile(self.test_exe, exec_copy)
1469 shutil.copystat(self.test_exe, exec_copy)
1470 self.test_exe = exec_copy
1471
1472 yield tmpdir
1473
1474 def test_init_setpythonhome(self):
1475 # Test Py_SetPythonHome(home) with PYTHONPATH env var

Callers 3

test_init_pybuilddirMethod · 0.95
test_init_pyvenv_cfgMethod · 0.95

Calls 7

listdirMethod · 0.80
fnmatchMethod · 0.80
copyfileMethod · 0.80
realpathMethod · 0.45
joinMethod · 0.45
dirnameMethod · 0.45
basenameMethod · 0.45

Tested by

no test coverage detected