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

Function setup_venv_with_pip_setuptools

Lib/test/support/__init__.py:2601–2637  ·  view source on GitHub ↗
(venv_dir)

Source from the content-addressed store, hash-verified

2599# and returns the paths to the venv directory and the python executable
2600@contextlib.contextmanager
2601def setup_venv_with_pip_setuptools(venv_dir):
2602 import subprocess
2603 from .os_helper import temp_cwd
2604
2605 def run_command(cmd):
2606 if verbose:
2607 import shlex
2608 print()
2609 print('Run:', ' '.join(map(shlex.quote, cmd)))
2610 subprocess.run(cmd, check=True)
2611 else:
2612 subprocess.run(cmd,
2613 stdout=subprocess.PIPE,
2614 stderr=subprocess.STDOUT,
2615 check=True)
2616
2617 with temp_cwd() as temp_dir:
2618 # Create virtual environment to get setuptools
2619 cmd = [sys.executable, '-X', 'dev', '-m', 'venv', venv_dir]
2620 run_command(cmd)
2621
2622 venv = os.path.join(temp_dir, venv_dir)
2623
2624 # Get the Python executable of the venv
2625 python_exe = os.path.basename(sys.executable)
2626 if sys.platform == 'win32':
2627 python = os.path.join(venv, 'Scripts', python_exe)
2628 else:
2629 python = os.path.join(venv, 'bin', python_exe)
2630
2631 cmd = (python, '-X', 'dev',
2632 '-m', 'pip', 'install',
2633 _findwheel('setuptools'),
2634 )
2635 run_command(cmd)
2636
2637 yield python
2638
2639
2640# True if Python is built with the Py_DEBUG macro defined: if

Callers

nothing calls this directly

Calls 5

temp_cwdFunction · 0.85
run_commandFunction · 0.85
_findwheelFunction · 0.85
joinMethod · 0.45
basenameMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…