-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
338 lines (295 loc) · 12 KB
/
Copy pathinstall.ps1
File metadata and controls
338 lines (295 loc) · 12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
#Requires -Version 5.1
<#
.SYNOPSIS
Traveller World Generator - Quick Install (Windows)
.DESCRIPTION
Creates a Python virtual environment, installs the GUI library (PySide6),
and generates batch-file launchers for the desktop app and command-line tools.
Requirements: Python 3.9 or later
Download from: https://www.python.org/downloads/
(Tick "Add Python to PATH" during installation.)
.EXAMPLE
.\install.ps1
If you see an execution-policy error, first run:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
then re-run .\install.ps1
#>
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
function Info { param([string]$Msg) Write-Host "[install] $Msg" -ForegroundColor Green }
function Warn { param([string]$Msg) Write-Host "[warning] $Msg" -ForegroundColor Yellow }
function Fail { param([string]$Msg) Write-Host "[error] $Msg" -ForegroundColor Red; exit 1 }
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Write-Host ""
Write-Host "Traveller World Generator - Installation" -ForegroundColor Cyan
Write-Host "=========================================" -ForegroundColor Cyan
Write-Host ""
# 1. Locate Python 3.9+
Info "Checking Python..."
$Python = $null
$PyVer = $null
foreach ($cmd in @('python', 'python3', 'py')) {
try {
$output = & $cmd --version 2>&1
if ($output -match 'Python (\d+)\.(\d+)') {
$major = [int]$Matches[1]
$minor = [int]$Matches[2]
if ($major -gt 3 -or ($major -eq 3 -and $minor -ge 9)) {
$Python = $cmd
$PyVer = "$major.$minor"
break
}
}
} catch { continue }
}
if (-not $Python) {
Warn "Python 3.9 or later was not found."
Info "Attempting to install Python 3.11 via winget..."
if (-not (Get-Command winget -ErrorAction SilentlyContinue)) {
Fail ("winget is not available on this system.`n" +
" Download Python 3.11 from: https://www.python.org/downloads/`n" +
" Tick 'Add Python to PATH' during installation, then re-run this script.")
}
& winget install --id Python.Python.3.11 --silent --accept-source-agreements --accept-package-agreements
if ($LASTEXITCODE -ne 0) {
Fail ("winget failed to install Python.`n" +
" Download Python 3.11 from: https://www.python.org/downloads/`n" +
" Tick 'Add Python to PATH' during installation, then re-run this script.")
}
Info "Python installed. Refreshing PATH..."
$machinePath = [System.Environment]::GetEnvironmentVariable('Path', 'Machine')
$userPath = [System.Environment]::GetEnvironmentVariable('Path', 'User')
$env:Path = "$machinePath;$userPath"
foreach ($cmd in @('python', 'python3', 'py')) {
try {
$output = & $cmd --version 2>&1
if ($output -match 'Python (\d+)\.(\d+)') {
$major = [int]$Matches[1]
$minor = [int]$Matches[2]
if ($major -gt 3 -or ($major -eq 3 -and $minor -ge 9)) {
$Python = $cmd
$PyVer = "$major.$minor"
break
}
}
} catch { continue }
}
if (-not $Python) {
Fail ("Python was installed but cannot be found yet.`n" +
" Close this window, open a new PowerShell, and re-run install.ps1")
}
}
Info "Found Python $PyVer ($Python)"
# 2. Create virtual environment
$VenvDir = Join-Path $ScriptDir '.venv'
if (Test-Path $VenvDir) {
Info "Virtual environment already exists - will update packages."
} else {
Info "Creating virtual environment in .venv\ ..."
& $Python -m venv $VenvDir
if ($LASTEXITCODE -ne 0) { Fail "Could not create virtual environment." }
}
$VenvPython = Join-Path $VenvDir 'Scripts\python.exe'
if (-not (Test-Path $VenvPython)) {
Fail "Python was not found in the virtual environment. Try deleting .venv\ and re-running."
}
# 3. Install dependencies
Info "Upgrading pip..."
& $VenvPython -m pip install --quiet --upgrade pip
if ($LASTEXITCODE -ne 0) { Fail "Failed to upgrade pip." }
Info "Installing traveller-gen package (generation modules + CLI entry points)..."
& $VenvPython -m pip install --quiet -e $ScriptDir
if ($LASTEXITCODE -ne 0) { Fail "Failed to install traveller-gen package." }
Info "Installing PySide6 (desktop GUI library) - this may take a few minutes..."
& $VenvPython -m pip install --quiet -r (Join-Path $ScriptDir 'gen-ui\requirements.txt')
if ($LASTEXITCODE -ne 0) {
Fail "Failed to install PySide6. Check your internet connection and try again."
}
Info "Installing dev tools (pytest, pylint)..."
& $VenvPython -m pip install --quiet -r (Join-Path $ScriptDir 'requirements-dev.txt')
if ($LASTEXITCODE -ne 0) { Fail "Failed to install dev tools." }
Info "All dependencies installed."
# 4. Create VS Code settings
$VscodeDir = Join-Path $ScriptDir '.vscode'
$VscodeSettings = Join-Path $VscodeDir 'settings.json'
if (-not (Test-Path $VscodeSettings)) {
Info "Creating VS Code settings (.vscode\settings.json)..."
if (-not (Test-Path $VscodeDir)) { New-Item -ItemType Directory $VscodeDir | Out-Null }
@'
{
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/Scripts/python.exe",
"python.terminal.activateEnvironment": true,
"python.terminal.activateEnvInCurrentTerminal": true,
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.analysis.venvPath": "${workspaceFolder}",
"python.analysis.venv": ".venv",
"python.analysis.extraPaths": [
"${workspaceFolder}"
],
"python.analysis.typeCheckingMode": "basic",
"editor.formatOnSave": true,
"editor.rulers": [
88
],
"files.exclude": {
"**/__pycache__": true,
"**/*.pyc": true,
".pytest_cache": true
},
"[python]": {
"editor.defaultFormatter": "ms-python.python"
},
"azureFunctions.deploySubpath": ".",
"azureFunctions.scmDoBuildDuringDeployment": true,
"azureFunctions.pythonVenv": ".venv",
"azureFunctions.projectLanguage": "Python",
"azureFunctions.projectRuntime": "~4",
"debug.internalConsoleOptions": "neverOpen",
"azureFunctions.projectLanguageModel": 2,
"pylint.path": [
"${workspaceFolder}/.venv/Scripts/pylint.exe"
],
"pylint.interpreter": [
"${workspaceFolder}/.venv/Scripts/python.exe"
],
"pylint.args": [
"--disable=duplicate-code,too-many-lines"
]
}
'@ | Set-Content $VscodeSettings -Encoding utf8
} else {
Info "VS Code settings already exist - skipping."
}
# 5. Create launcher batch files
Info "Creating launcher scripts..."
# Desktop GUI
$guiBat = @'
@echo off
"%~dp0.venv\Scripts\python.exe" "%~dp0gen-ui\app.py"
'@
$guiBat | Set-Content (Join-Path $ScriptDir 'run-gui.bat') -Encoding ASCII
# World generator CLI
$worldBat = @'
@echo off
rem Generate one or more Traveller mainworlds.
rem
rem Options:
rem --name NAME World name (default: auto-numbered)
rem --count N Number of worlds to generate (default: 1)
rem --seed N RNG seed for reproducible results
rem --json Output as JSON instead of text
rem --html Output as an HTML card
rem
rem Examples:
rem run-world
rem run-world --name "New Terra" --count 3
rem run-world --name Zhodane --seed 42 --json
"%~dp0.venv\Scripts\traveller-world.exe" %*
'@
$worldBat | Set-Content (Join-Path $ScriptDir 'run-world.bat') -Encoding ASCII
# TravellerMap lookup CLI
$mapBat = @'
@echo off
rem Fetch a world from TravellerMap and generate a full star system.
rem Requires an internet connection.
rem
rem Options (--sector is always required):
rem --sector SECTOR Sector name, e.g. "Spinward Marches"
rem --name NAME World name within the sector
rem --hex NNNN 4-digit hex position (alternative to --name)
rem --seed N RNG seed for reproducible results
rem --detail Include secondary world and moon profiles
rem --json Output as JSON
rem --html Output as an HTML card
rem
rem Examples:
rem run-mapfetch --sector "Spinward Marches" --name Regina
rem run-mapfetch --sector "Spinward Marches" --hex 1910 --detail
"%~dp0.venv\Scripts\traveller-mapfetch.exe" %*
'@
$mapBat | Set-Content (Join-Path $ScriptDir 'run-mapfetch.bat') -Encoding ASCII
# FastAPI server — batch file
$fastapiBat = @'
@echo off
rem Start the Traveller World Generator FastAPI server.
rem
rem The server listens on http://localhost:8000 by default.
rem
rem Options (passed through to uvicorn):
rem --host HOST Bind address (default: 127.0.0.1)
rem --port PORT Port number (default: 8000)
rem --reload Auto-reload on source changes (development only)
rem
rem Examples:
rem run-fastapi
rem run-fastapi --host 0.0.0.0 --port 8080
cd /d "%~dp0fastapi"
"%~dp0.venv\Scripts\uvicorn.exe" app:app --host 127.0.0.1 --port 8000 %*
'@
$fastapiBat | Set-Content (Join-Path $ScriptDir 'run-fastapi.bat') -Encoding ASCII
# FastAPI server — PowerShell script
$fastapiPs1 = @'
#Requires -Version 5.1
<#
.SYNOPSIS
Start the Traveller World Generator FastAPI server.
.DESCRIPTION
Starts uvicorn serving app:app from the fastapi/ subdirectory.
The server listens on http://localhost:8000 by default.
Any extra arguments are forwarded to uvicorn, for example:
.\run-fastapi.ps1 --host 0.0.0.0 --port 8080
.\run-fastapi.ps1 --reload
.EXAMPLE
.\run-fastapi.ps1
.EXAMPLE
.\run-fastapi.ps1 --host 0.0.0.0 --port 8080
#>
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$Uvicorn = Join-Path $ScriptDir '.venv\Scripts\uvicorn.exe'
$FastApiDir = Join-Path $ScriptDir 'fastapi'
if (-not (Test-Path $Uvicorn)) {
Write-Host "[error] uvicorn not found at $Uvicorn" -ForegroundColor Red
Write-Host " Run install.ps1 first to create the virtual environment." -ForegroundColor Yellow
exit 1
}
Set-Location $FastApiDir
& $Uvicorn app:app --host 127.0.0.1 --port 8000 @args
'@
$fastapiPs1 | Set-Content (Join-Path $ScriptDir 'run-fastapi.ps1') -Encoding UTF8
# 6. Activate virtual environment
if ($env:VIRTUAL_ENV -ne $VenvDir) {
Info "Activating virtual environment..."
& "$VenvDir\Scripts\Activate.ps1"
} else {
Info "Virtual environment already active."
}
# 7. Done
Write-Host ""
Info "Installation complete!"
Write-Host ""
Write-Host " +----------------------------------------------------------------+" -ForegroundColor Cyan
Write-Host " | Desktop app |" -ForegroundColor Cyan
Write-Host " | Double-click run-gui.bat in File Explorer |" -ForegroundColor Cyan
Write-Host " | or run from this window: .\run-gui.bat |" -ForegroundColor Cyan
Write-Host " | |" -ForegroundColor Cyan
Write-Host " | World generator (command line) |" -ForegroundColor Cyan
Write-Host " | run-world [--name NAME] [--count N] [--seed N] |" -ForegroundColor Cyan
Write-Host " | |" -ForegroundColor Cyan
Write-Host " | TravellerMap lookup (command line, needs internet) |" -ForegroundColor Cyan
Write-Host " | run-mapfetch --sector SECTOR --name NAME |" -ForegroundColor Cyan
Write-Host " +----------------------------------------------------------------+" -ForegroundColor Cyan
Write-Host ""
Write-Host " Examples:" -ForegroundColor White
Write-Host " .\run-world.bat" -ForegroundColor White
Write-Host ' .\run-world.bat --name "New Terra" --count 5' -ForegroundColor White
Write-Host ' .\run-mapfetch.bat --sector "Spinward Marches" --name Regina' -ForegroundColor White
Write-Host ""
Write-Host " To activate the venv in a new terminal:" -ForegroundColor Yellow
Write-Host ' . .\install.ps1 # dot-source to activate in this session' -ForegroundColor Yellow
Write-Host ' # or manually:' -ForegroundColor Yellow
Write-Host ' .\.venv\Scripts\Activate.ps1' -ForegroundColor Yellow
Write-Host ""