This commit is contained in:
2026-01-21 23:01:18 -08:00
parent 201663bb62
commit 8225221fd3
2 changed files with 63 additions and 44 deletions

View File

@@ -1,6 +1,47 @@
<#
.SYNOPSIS
Bootstrap a Python virtualenv and install the project on Windows (PowerShell).
.DESCRIPTION
Creates a Python virtual environment (default: .venv), upgrades pip, installs the project
(either editable or normal), and optionally creates Desktop and Start Menu shortcuts.
.EXAMPLE
# Create .venv and install in editable mode, create Desktop shortcut
.\scripts\bootstrap.ps1 -Editable -CreateDesktopShortcut
.EXAMPLE
# Use a specific python executable and force overwrite existing venv
.\scripts\bootstrap.ps1 -Python "C:\\Python39\\python.exe" -Force
# Note: you may need to run PowerShell with ExecutionPolicy Bypass:
# powershell -ExecutionPolicy Bypass -File .\scripts\bootstrap.ps1 -Editable
#>
param(
[switch]$Editable,
[switch]$CreateDesktopShortcut,
[switch]$CreateStartMenuShortcut,
[string]$VenvPath = ".venv",
[string]$Python = "",
[switch]$Force,
[switch]$NoInstall,
[switch]$NoPlaywright,
[string]$PlaywrightBrowsers = "chromium",
[switch]$FixUrllib3,
[switch]$RemovePth,
[switch]$Quiet
)
# Resolve OS detection in a broad-compatible way
try { $IsWindowsPlatform = [System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Windows) } catch { $IsWindowsPlatform = $env:OS -match 'Windows' }
function Write-Log {
param([string]$msg,[string]$lvl="INFO")
if (-not $Quiet) {
if ($lvl -eq "ERROR") { Write-Host "[$lvl] $msg" -ForegroundColor Red } else { Write-Host "[$lvl] $msg" }
}
}
function Ensure-Mpv {
# mpv is used by some pipelines; try to ensure it's available on PATH.
try {
@@ -39,7 +80,7 @@ function Ensure-Mpv {
$mpvCmd2 = Get-Command mpv -ErrorAction SilentlyContinue
if ($mpvCmd2) {
try {
$v2 = & mpv --version 2>$null | Select-Object -First 1
$v2 = & mpv --version 2> $null | Select-Object -First 1
if ($v2) { Write-Log "mpv installed: $v2" "INFO" } else { Write-Log "mpv installed: $($mpvCmd2.Path)" "INFO" }
} catch {
Write-Log "mpv installed: $($mpvCmd2.Path)" "INFO"
@@ -54,46 +95,8 @@ if ($IsWindowsPlatform) {
Ensure-Mpv
}
.DESCRIPTION
Creates a Python virtual environment (default: .venv), upgrades pip, installs the project
(either editable or normal), and optionally creates Desktop and Start Menu shortcuts.
.EXAMPLE
# Create .venv and install in editable mode, create Desktop shortcut
.\scripts\bootstrap.ps1 -Editable -CreateDesktopShortcut
.EXAMPLE
# Use a specific python executable and force overwrite existing venv
.\scripts\bootstrap.ps1 -Python "C:\\Python39\\python.exe" -Force
# Note: you may need to run PowerShell with ExecutionPolicy Bypass:
# powershell -ExecutionPolicy Bypass -File .\scripts\bootstrap.ps1 -Editable
#>
param(
[switch]$Editable,
[switch]$CreateDesktopShortcut,
[switch]$CreateStartMenuShortcut,
[string]$VenvPath = ".venv",
[string]$Python = "",
[switch]$Force,
[switch]$NoInstall,
[switch]$NoPlaywright,
[string]$PlaywrightBrowsers = "chromium",
[switch]$FixUrllib3,
[switch]$RemovePth,
[switch]$Quiet
)
# Track whether the user chose an interactive auto-fix (so we can auto-remove .pth files)
$AutoFixInteractive = $false
)
function Write-Log {
param([string]$msg,[string]$lvl="INFO")
if (-not $Quiet) {
if ($lvl -eq "ERROR") { Write-Host "[$lvl] $msg" -ForegroundColor Red } else { Write-Host "[$lvl] $msg" }
}
}
function Find-Python {
param([string]$preferred)
@@ -114,9 +117,6 @@ function Find-Python {
return $null
}
# Resolve OS detection in a broad-compatible way
try { $IsWindowsPlatform = [System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Windows) } catch { $IsWindowsPlatform = $env:OS -match 'Windows' }
# operate from repo root (parent of scripts dir)
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$repoRoot = (Resolve-Path (Join-Path $scriptDir "..")).Path
@@ -628,5 +628,5 @@ Write-Host " $ .\$VenvPath\Scripts\mm.exe (Windows) or"
Write-Host " $ ./$VenvPath/bin/mm (Linux) or"
Write-Host " $ $venvPython -m scripts.cli_entry"
Write-Host ""
Write-Host "If the global 'mm' launcher fails, collect runtime diagnostics by setting MM_DEBUG and re-running the command:""
Write-Host "If the global 'mm' launcher fails, collect runtime diagnostics by setting MM_DEBUG and re-running the command:"
if ($IsWindowsPlatform) { Write-Host " PowerShell: $env:MM_DEBUG = '1'; mm" } else { Write-Host " POSIX: MM_DEBUG=1 mm" }