MCPcopy
hub / github.com/pex-tool/pex / ensure_uv_python

Function ensure_uv_python

testing/__init__.py:546–568  ·  view source on GitHub ↗
(
    python,  # type: Union[UvPython, str]
    install_if_missing=True,  # type: bool
)

Source from the content-addressed store, hash-verified

544
545
546def ensure_uv_python(
547 python, # type: Union[UvPython, str]
548 install_if_missing=True, # type: bool
549):
550 # type: (...) -> str
551
552 python_spec = python.spec() if isinstance(python, UvPython) else python
553
554 env = make_env(UV_PYTHON_INSTALL_DIR=os.path.join(PEX_TEST_DEV_ROOT, "uv-pythons"))
555 process = subprocess.Popen(
556 args=["uv", "python", "find", python_spec], env=env, stdout=subprocess.PIPE
557 )
558 stdout, _ = process.communicate()
559 if process.returncode == 0:
560 return cast(str, stdout.decode("utf-8").strip())
561
562 assert install_if_missing, "The {python} interpreter was not found by uv on the system.".format(
563 python=python
564 )
565 subprocess.check_call(
566 args=["uv", "python", "install", "--managed-python", "--force", python_spec], env=env
567 )
568 return ensure_uv_python(python_spec, install_if_missing=False)
569
570
571def run_pex_command(

Callers 3

run_pex3Function · 0.90
run_pex_commandFunction · 0.85

Calls 7

castFunction · 0.90
specMethod · 0.80
communicateMethod · 0.80
stripMethod · 0.80
decodeMethod · 0.80
make_envFunction · 0.70
joinMethod · 0.45

Tested by 1