MCPcopy Index your code
hub / github.com/python/mypy / virtualenv

Function virtualenv

mypy/test/testpep561.py:31–46  ·  view source on GitHub ↗

Context manager that creates a virtualenv in a temporary directory Returns the path to the created Python executable

(python_executable: str = sys.executable)

Source from the content-addressed store, hash-verified

29
30@contextmanager
31def virtualenv(python_executable: str = sys.executable) -> Iterator[tuple[str, str]]:
32 """Context manager that creates a virtualenv in a temporary directory
33
34 Returns the path to the created Python executable
35 """
36 with tempfile.TemporaryDirectory() as venv_dir:
37 proc = subprocess.run(
38 [python_executable, "-m", "venv", venv_dir], cwd=os.getcwd(), capture_output=True
39 )
40 if proc.returncode != 0:
41 err = proc.stdout.decode("utf-8") + proc.stderr.decode("utf-8")
42 raise Exception("Failed to create venv.\n" + err)
43 if sys.platform == "win32":
44 yield venv_dir, os.path.abspath(os.path.join(venv_dir, "Scripts", "python"))
45 else:
46 yield venv_dir, os.path.abspath(os.path.join(venv_dir, "bin", "python"))
47
48
49def upgrade_pip(python_executable: str) -> None:

Callers 1

test_pep561Function · 0.85

Calls 4

ExceptionClass · 0.85
runMethod · 0.45
decodeMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…