Windows installer; ship the dashboard template

- packaging/: PyInstaller spec (one folder, windowed, Python included), Inno Setup script
  (per-user install, Start menu, optional desktop icon, WebView2 check), build.ps1, app icon.
- Bundled exe also runs the CLI (output to %LOCALAPPDATA%\myGarmin\cli.log).
- Fix: .gitignore pattern dashboard*.html also hid src/mygarmin/report/dashboard.html, so the
  template was never committed and fresh clones could not build a dashboard. Patterns anchored;
  data file types (*.gpx, *.csv, *.json, *.gz, *.log) ignored too.
- Self-test runs beside an open app (own WebView2 data folder, no single-instance check).
- Neutral example values in a docstring and the tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-17 14:10:05 +02:00
parent 7b1276f0b1
commit 39ce4e73a0
12 changed files with 692 additions and 10 deletions

26
packaging/build.ps1 Normal file
View File

@@ -0,0 +1,26 @@
# Build myGarmin-setup-<version>.exe: PyInstaller (one folder, Python included) -> Inno Setup installer.
# Needs: pip install pyinstaller ; Inno Setup 6 (winget install JRSoftware.InnoSetup).
# usage (from the repo): powershell -ExecutionPolicy Bypass -File packaging\build.ps1
$ErrorActionPreference = 'Stop'
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $here
$version = (Select-String -Path ..\pyproject.toml -Pattern '^version = "(.+)"').Matches[0].Groups[1].Value
$v4 = (($version -split '\.') + @('0', '0', '0'))[0..3] -join ', '
# Windows file version resource for myGarmin.exe
@"
VSVersionInfo(ffi=FixedFileInfo(filevers=($v4), prodvers=($v4)),
kids=[StringFileInfo([StringTable('040904B0', [StringStruct('ProductName', 'myGarmin'), StringStruct('FileDescription', 'myGarmin activity and health logbook'),
StringStruct('FileVersion', '$version'), StringStruct('ProductVersion', '$version'), StringStruct('LegalCopyright', 'MIT licence')])]),
VarFileInfo([VarStruct('Translation', [1033, 1200])])])
"@ | Out-File -Encoding utf8 version_info.txt
python -m PyInstaller --noconfirm --clean --distpath ..\build\dist --workpath ..\build\work myGarmin.spec
if ($LASTEXITCODE) { throw 'PyInstaller failed' }
$iscc = @("$env:LOCALAPPDATA\Programs\Inno Setup 6\ISCC.exe", "${env:ProgramFiles(x86)}\Inno Setup 6\ISCC.exe", "$env:ProgramFiles\Inno Setup 6\ISCC.exe") |
Where-Object { Test-Path $_ } | Select-Object -First 1
if (-not $iscc) { throw 'Inno Setup 6 not found (winget install JRSoftware.InnoSetup)' }
& $iscc "/DAppVersion=$version" myGarmin.iss
if ($LASTEXITCODE) { throw 'Inno Setup failed' }
Get-Item ..\build\installer\*.exe | Select-Object Name, @{n='MB'; e={[math]::Round($_.Length / 1MB, 1)}}

19
packaging/launcher.py Normal file
View File

@@ -0,0 +1,19 @@
# Entry point of the bundled myGarmin.exe (PyInstaller).
# No arguments: the app window. With arguments: the mygarmin command line (myGarmin.exe import <library> <path> ...);
# the exe has no console, so its output goes to %LOCALAPPDATA%\myGarmin\cli.log.
import os, sys
if len(sys.argv) > 1:
log = os.path.join(os.environ.get('LOCALAPPDATA', os.path.expanduser('~')), 'myGarmin', 'cli.log')
os.makedirs(os.path.dirname(log), exist_ok=True)
sys.stdout = sys.stderr = open(log, 'a', encoding='utf-8', buffering=1)
print('>', ' '.join(sys.argv[1:]))
from mygarmin.cli import main
try: main(sys.argv[1:])
except SystemExit as e:
if e.code not in (None, 0): print('exit:', e.code); raise
except Exception:
import traceback; traceback.print_exc(); sys.exit(1)
else:
from mygarmin.app import main
main()

BIN
packaging/myGarmin.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

69
packaging/myGarmin.iss Normal file
View File

@@ -0,0 +1,69 @@
; Inno Setup script for myGarmin. Built by packaging\build.ps1 (passes /DAppVersion=x.y.z).
; Installs per user (no admin rights) into %LOCALAPPDATA%\Programs\myGarmin. The user's library folder,
; settings and Garmin token live elsewhere and are never touched by setup or uninstall.
#ifndef AppVersion
#define AppVersion "0.0.0"
#endif
[Setup]
AppId={{6B0E8C5A-3F2D-4C1B-9E7A-2D5F8A1C4B90}
AppName=myGarmin
AppVersion={#AppVersion}
AppVerName=myGarmin {#AppVersion}
AppPublisher=myGarmin (open source, MIT)
AppPublisherURL=https://services.doorduin.co.za/gitea/public/myGarminApp
DefaultDirName={autopf}\myGarmin
DefaultGroupName=myGarmin
DisableProgramGroupPage=yes
PrivilegesRequired=lowest
PrivilegesRequiredOverridesAllowed=dialog
ArchitecturesAllowed=x64compatible
ArchitecturesInstallIn64BitMode=x64compatible
MinVersion=10.0
OutputDir=..\build\installer
OutputBaseFilename=myGarmin-setup-{#AppVersion}
SetupIconFile=myGarmin.ico
UninstallDisplayIcon={app}\myGarmin.exe
LicenseFile=..\LICENSE
Compression=lzma2/max
SolidCompression=yes
WizardStyle=modern
CloseApplications=yes
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"
[Files]
Source: "..\build\dist\myGarmin\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
[Icons]
Name: "{group}\myGarmin"; Filename: "{app}\myGarmin.exe"
Name: "{group}\Uninstall myGarmin"; Filename: "{uninstallexe}"
Name: "{autodesktop}\myGarmin"; Filename: "{app}\myGarmin.exe"; Tasks: desktopicon
[Run]
Filename: "{app}\myGarmin.exe"; Description: "{cm:LaunchProgram,myGarmin}"; Flags: nowait postinstall skipifsilent
[Code]
// The app window uses Microsoft Edge WebView2 (part of Windows 11; usually present on Windows 10).
function HasWebView2(): Boolean;
var v: String;
begin
Result := RegQueryStringValue(HKLM, 'SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}', 'pv', v)
or RegQueryStringValue(HKCU, 'Software\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}', 'pv', v);
Result := Result and (v <> '') and (v <> '0.0.0.0');
end;
function InitializeSetup(): Boolean;
var code: Integer;
begin
Result := True;
if not HasWebView2() then
if MsgBox('myGarmin needs the Microsoft Edge WebView2 Runtime, which is not installed on this PC.' + #13#10#13#10 +
'Open the Microsoft download page now? (Install the "Evergreen Bootstrapper", then run this setup again.)',
mbConfirmation, MB_YESNO) = IDYES then
begin
ShellExec('open', 'https://developer.microsoft.com/microsoft-edge/webview2/', '', '', SW_SHOWNORMAL, ewNoWait, code);
Result := False;
end;
end;

BIN
packaging/myGarmin.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

16
packaging/myGarmin.spec Normal file
View File

@@ -0,0 +1,16 @@
# PyInstaller spec: one-folder, windowed build of the myGarmin app. Build with packaging\build.ps1.
from PyInstaller.utils.hooks import collect_all, collect_data_files
datas = collect_data_files('mygarmin', includes=['**/*.html'])
datas += collect_data_files('timezonefinder') + collect_data_files('tzdata')
binaries, hidden = [], []
for pkg in ('webview', 'clr_loader', 'pythonnet', 'garminconnect', 'curl_cffi', 'timezonefinder'): # js files, .NET bridge, native libs, tz data (needs numpy)
d, b, h = collect_all(pkg); datas += d; binaries += b; hidden += h
a = Analysis(['launcher.py'], pathex=['../src'], binaries=binaries, datas=datas,
hiddenimports=hidden + ['mygarmin.sources.garmin_api', 'mygarmin.sources.watch', 'mygarmin.cli', 'mygarmin.export', 'mygarmin.report', 'mygarmin.dedupe', 'clr'],
excludes=['tkinter', 'matplotlib', 'pandas', 'PIL', 'pytest'], noarchive=False)
pyz = PYZ(a.pure)
exe = EXE(pyz, a.scripts, [], exclude_binaries=True, name='myGarmin', icon='myGarmin.ico',
console=False, upx=False, version='version_info.txt')
coll = COLLECT(exe, a.binaries, a.datas, name='myGarmin', upx=False)