Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions scripts/runtime/setup-llm.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,16 @@ function Install-Llm {
exit 1
}

# Create virtual environment
# Create virtual environment. A re-run over an existing venv must not let
# APM's truststore .pth bootstrap inject into ensurepip's bundled pip.
Write-Info "Creating Python virtual environment for LLM..."
python -m venv $llmVenv
$previousDisable = $env:APM_DISABLE_TRUSTSTORE
$env:APM_DISABLE_TRUSTSTORE = "1"
try {
python -m venv $llmVenv
} finally {
$env:APM_DISABLE_TRUSTSTORE = $previousDisable
}

$pipExe = Join-Path (Join-Path $llmVenv "Scripts") "pip.exe"
$llmExe = Join-Path (Join-Path $llmVenv "Scripts") "llm.exe"
Expand Down
6 changes: 4 additions & 2 deletions scripts/runtime/setup-llm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ setup_llm() {

# Create virtual environment for LLM. Bootstrap pip as a separate step:
# `python3 -m venv` hides ensurepip's output, so a failure would only
# report "exit status 1" without the reason.
# report "exit status 1" without the reason. A re-run over an existing venv
# must not let APM's truststore .pth bootstrap inject into ensurepip's
# bundled pip, whose vendored truststore rejects an already-injected ssl.
local python3_bin
python3_bin="$(command -v python3)"
log_info "Creating Python virtual environment for LLM (using $python3_bin)..."
if ! python3 -m venv --without-pip "$llm_venv"; then
log_error "Could not create the LLM virtual environment at $llm_venv."
exit 1
fi
if ! "$llm_venv/bin/python" -m ensurepip --upgrade --default-pip; then
if ! APM_DISABLE_TRUSTSTORE=1 "$llm_venv/bin/python" -m ensurepip --upgrade --default-pip; then
log_error "Could not bootstrap pip into $llm_venv (python3: $python3_bin)."
exit 1
fi
Expand Down
10 changes: 10 additions & 0 deletions tests/integration/test_tls_r3_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,16 @@ def spy(target, data):
)


def test_setup_llm_pip_bootstrap_skips_apm_truststore_injection():
"""Re-running setup over a bootstrapped venv must not inject into ensurepip's pip."""
root = _repo_root()
sh = (root / "scripts" / "runtime" / "setup-llm.sh").read_text(encoding="utf-8")
ps1 = (root / "scripts" / "runtime" / "setup-llm.ps1").read_text(encoding="utf-8")

assert 'APM_DISABLE_TRUSTSTORE=1 "$llm_venv/bin/python" -m ensurepip' in sh
assert '$env:APM_DISABLE_TRUSTSTORE = "1"' in ps1


# --------------------------------------------------------------------------- #
# V4 (M1): runtime setup scripts install truststore best-effort + pinned
# --------------------------------------------------------------------------- #
Expand Down
Loading