|
| 1 | +[CmdletBinding()] |
| 2 | +param( |
| 3 | + [ValidateSet("pipx", "pip")] |
| 4 | + [string]$Mode = "pipx", |
| 5 | + [string]$SourcePath |
| 6 | +) |
| 7 | + |
| 8 | +$ErrorActionPreference = "Stop" |
| 9 | + |
| 10 | +function Test-Command { |
| 11 | + param([Parameter(Mandatory = $true)][string]$Name) |
| 12 | + return [bool](Get-Command $Name -ErrorAction SilentlyContinue) |
| 13 | +} |
| 14 | + |
| 15 | +function Invoke-Py { |
| 16 | + param([Parameter(Mandatory = $true)][string[]]$Args) |
| 17 | + if (Test-Command "py") { |
| 18 | + & py @Args |
| 19 | + return |
| 20 | + } |
| 21 | + if (Test-Command "python") { |
| 22 | + & python @Args |
| 23 | + return |
| 24 | + } |
| 25 | + throw "Python was not found. Install Python 3.10+ from https://www.python.org/downloads/windows/ and re-run this script." |
| 26 | +} |
| 27 | + |
| 28 | +Write-Host "[lore/windows] Bootstrap starting (mode=$Mode)" |
| 29 | + |
| 30 | +if ($Mode -eq "pipx") { |
| 31 | + Write-Host "[lore/windows] Installing/upgrading pip + pipx" |
| 32 | + Invoke-Py -Args @("-m", "pip", "install", "--user", "--upgrade", "pip", "pipx") |
| 33 | + |
| 34 | + Write-Host "[lore/windows] Ensuring pipx path" |
| 35 | + Invoke-Py -Args @("-m", "pipx", "ensurepath") |
| 36 | + |
| 37 | + if ([string]::IsNullOrWhiteSpace($SourcePath)) { |
| 38 | + Write-Host "[lore/windows] Installing lore-book from PyPI via pipx" |
| 39 | + Invoke-Py -Args @("-m", "pipx", "install", "--force", "lore-book") |
| 40 | + } |
| 41 | + else { |
| 42 | + Write-Host "[lore/windows] Installing lore-book from source path: $SourcePath" |
| 43 | + Invoke-Py -Args @("-m", "pipx", "install", "--force", $SourcePath) |
| 44 | + } |
| 45 | + |
| 46 | + Write-Host "[lore/windows] Verifying CLI" |
| 47 | + Invoke-Py -Args @("-m", "pipx", "run", "--spec", "lore-book", "lore", "version") |
| 48 | +} |
| 49 | +else { |
| 50 | + if ([string]::IsNullOrWhiteSpace($SourcePath)) { |
| 51 | + Write-Host "[lore/windows] Installing lore-book from PyPI via pip" |
| 52 | + Invoke-Py -Args @("-m", "pip", "install", "--user", "--upgrade", "lore-book") |
| 53 | + } |
| 54 | + else { |
| 55 | + Write-Host "[lore/windows] Installing lore-book from source path: $SourcePath" |
| 56 | + Invoke-Py -Args @("-m", "pip", "install", "--user", "--upgrade", $SourcePath) |
| 57 | + } |
| 58 | + |
| 59 | + Write-Host "[lore/windows] Verifying package import" |
| 60 | + Invoke-Py -Args @("-c", "import lore; print(f'lore {lore.__version__}')") |
| 61 | +} |
| 62 | + |
| 63 | +Write-Host "[lore/windows] Install complete." |
| 64 | +Write-Host "[lore/windows] If 'lore' is not recognized yet, open a new terminal session." |
0 commit comments