bootstrap: add automatic .pth write for editable installs so top-level CLI is importable
Some checks failed
smoke-mm / Install & smoke test mm --help (push) Has been cancelled

This commit is contained in:
nose
2025-12-24 04:05:35 -08:00
parent 7598fd5b2a
commit 7c8b0edb5c
4 changed files with 211 additions and 9 deletions

View File

@@ -170,6 +170,68 @@ if (-not $NoInstall) {
Write-Log "pip install failed: $_" "ERROR"; exit 6
}
# Verify top-level 'CLI' import and (if missing) attempt to make it available
Write-Log "Verifying installed CLI import..."
try {
& $venvPython -c "import importlib; importlib.import_module('medeia_macina.cli_entry')" 2>$null
if ($LASTEXITCODE -eq 0) { Write-Log "OK: 'medeia_macina.cli_entry' is importable in the venv." }
} catch {}
try {
& $venvPython -c "import importlib; importlib.import_module('CLI')" 2>$null
if ($LASTEXITCODE -eq 0) { Write-Log "Top-level 'CLI' is importable in the venv." }
else {
Write-Log "Top-level 'CLI' not importable; attempting to add repo root to venv site-packages via .pth" "INFO"
$sites = Get-SitePackages -python $venvPython
$siteDir = $sites | Where-Object { Test-Path $_ } | Select-Object -First 1
if ($siteDir) {
$pth = Join-Path $siteDir 'medeia_repo.pth'
if (Test-Path $pth) {
if (-not (Select-String -Path $pth -Pattern ([regex]::Escape($repoRoot)) -Quiet)) {
Add-Content -Path $pth -Value $repoRoot
Write-Log "Appended repo root to existing .pth: $pth" "INFO"
} else {
Write-Log ".pth already contains repo root: $pth" "INFO"
}
} else {
Set-Content -LiteralPath $pth -Value $repoRoot -Encoding UTF8
Write-Log "Wrote .pth adding repo root to venv site-packages: $pth" "INFO"
}
# Re-check import
& $venvPython -c "import importlib; importlib.import_module('CLI')" 2>$null
if ($LASTEXITCODE -eq 0) {
Write-Log "Top-level 'CLI' import works after adding .pth" "INFO"
} else {
Write-Log "Adding .pth did not make top-level 'CLI' importable." "ERROR"
if ($Editable) {
Write-Log "Editable install already requested; attempting editable reinstall for good measure..." "INFO"
try { & $venvPython -m pip install -e . } catch { Write-Log "Editable reinstall failed: $_" "ERROR"; exit 6 }
& $venvPython -c "import importlib; importlib.import_module('CLI')" 2>$null
if ($LASTEXITCODE -eq 0) { Write-Log "Top-level 'CLI' is now importable after reinstall." "INFO" }
else { Write-Log "Editable reinstall did not make 'CLI' importable; inspect the venv or create an egg-link manually." "ERROR"; exit 6 }
} else {
if (-not $Quiet) {
$ans = Read-Host "Top-level 'CLI' not importable; install project in editable mode now? (Y/n)"
if ($ans -eq 'y' -or $ans -eq 'Y') { try { & $venvPython -m pip install -e . } catch { Write-Log "Editable install failed: $_" "ERROR"; exit 6 } }
else { Write-Log "Warning: continuing without top-level 'CLI' importable; some entrypoints may fail." "ERROR" }
} else { Write-Log "Top-level 'CLI' not importable and cannot prompt (quiet mode); aborting." "ERROR"; exit 6 }
}
}
} else {
Write-Log "Unable to determine site-packages to write .pth; falling back to editable install prompt" "WARNING"
if ($Editable) { try { & $venvPython -m pip install -e . } catch { Write-Log "Editable install failed: $_" "ERROR"; exit 6 } }
elseif (-not $Quiet) {
$ans = Read-Host "Top-level 'CLI' not importable; install project in editable mode now? (Y/n)"
if ($ans -eq 'y' -or $ans -eq 'Y') { try { & $venvPython -m pip install -e . } catch { Write-Log "Editable install failed: $_" "ERROR"; exit 6 } }
} else { Write-Log "Top-level 'CLI' not importable and cannot prompt (quiet mode); aborting." "ERROR"; exit 6 }
}
}
} catch {
Write-Log "Failed to verify top-level 'CLI': $_" "ERROR"
exit 6
}
# Install Playwright browsers (default: chromium) unless explicitly disabled
if (-not $NoPlaywright) {
Write-Log "Ensuring Playwright browsers are installed (browsers=$PlaywrightBrowsers)..."