|
| 1 | +"""Generate InnoSetup script with current version from __init__.py.""" |
| 2 | + |
| 3 | +import re |
| 4 | +from pathlib import Path |
| 5 | + |
| 6 | +PROJECT_ROOT = Path(__file__).parent.parent |
| 7 | +SRC_DIR = PROJECT_ROOT / "src" |
| 8 | +INIT_PATH = SRC_DIR / "dbs_annotator" / "__init__.py" |
| 9 | + |
| 10 | + |
| 11 | +def read_version() -> str: |
| 12 | + """Read version from __init__.py.""" |
| 13 | + text = INIT_PATH.read_text(encoding="utf-8") |
| 14 | + m = re.search( |
| 15 | + r'^__version__\s*=\s*["\']([^"\']+)["\']\s*$', text, flags=re.MULTILINE |
| 16 | + ) |
| 17 | + if not m: |
| 18 | + raise RuntimeError(f"Could not determine version from {INIT_PATH}") |
| 19 | + return m.group(1) |
| 20 | + |
| 21 | + |
| 22 | +def generate_iss(version: str) -> None: |
| 23 | + """Generate ClinicalDBSAnnotator.iss with current version.""" |
| 24 | + version_underscore = version.replace(".", "_") |
| 25 | + # Use $V$ and $VU$ as placeholders to avoid any conflict with InnoSetup braces |
| 26 | + iss_content = """\ |
| 27 | +; Inno Setup installer script for ClinicalDBSAnnotator |
| 28 | +; Requires Inno Setup 6.x or later to compile |
| 29 | +; Auto-generated by generate_iss.py - DO NOT EDIT MANUALLY |
| 30 | +
|
| 31 | +#define AppName "ClinicalDBSAnnotator" |
| 32 | +#define AppVersion "$V$" |
| 33 | +#define AppPublisher "Brain Modulation Lab" |
| 34 | +#define AppURL "https://github.com/bml/dbs-annotator" |
| 35 | +#define AppExeName "ClinicalDBSAnnotator_Windows_$VU$.exe" |
| 36 | +
|
| 37 | +[Setup] |
| 38 | +AppId={{A1B2C3D4-E5F6-7890-ABCD-EF1234567890} |
| 39 | +AppName={#AppName} |
| 40 | +AppVersion={#AppVersion} |
| 41 | +AppPublisher={#AppPublisher} |
| 42 | +AppPublisherURL={#AppURL} |
| 43 | +AppSupportURL={#AppURL} |
| 44 | +AppUpdatesURL={#AppURL} |
| 45 | +DefaultDirName={autopf}\\{#AppName} |
| 46 | +DefaultGroupName={#AppName} |
| 47 | +AllowNoIcons=yes |
| 48 | +OutputDir=installer_output |
| 49 | +OutputBaseFilename={#AppName}_Setup_{#AppVersion}_Windows |
| 50 | +Compression=lzma2/max |
| 51 | +SolidCompression=yes |
| 52 | +WizardStyle=Modern |
| 53 | +SetupIconFile=..\\icons\\logoneutral.ico |
| 54 | +UninstallDisplayIcon={app}\\{#AppExeName} |
| 55 | +ChangesAssociations=yes |
| 56 | +
|
| 57 | +[Languages] |
| 58 | +Name: "english"; MessagesFile: "compiler:Default.isl" |
| 59 | +Name: "italian"; MessagesFile: "compiler:Languages\\Italian.isl" |
| 60 | +
|
| 61 | +[Tasks] |
| 62 | +Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}" |
| 63 | +Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; OnlyBelowVersion: 6.1 |
| 64 | +
|
| 65 | +[Files] |
| 66 | +; Main application files from PyInstaller onedir build |
| 67 | +Source: "dist\\ClinicalDBSAnnotator_Windows_$VU$\\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs |
| 68 | +; Icon file for shortcuts |
| 69 | +Source: "..\\icons\\logoneutral.ico"; DestDir: "{app}"; Flags: ignoreversion |
| 70 | +
|
| 71 | +[Icons] |
| 72 | +Name: "{group}\\{#AppName}"; Filename: "{app}\\{#AppExeName}"; IconFilename: "{app}\\logoneutral.ico" |
| 73 | +Name: "{commondesktop}\\{#AppName}"; Filename: "{app}\\{#AppExeName}"; IconFilename: "{app}\\logoneutral.ico"; Tasks: desktopicon |
| 74 | +Name: "{userappdata}\\Microsoft\\Internet Explorer\\Quick Launch\\{#AppName}"; Filename: "{app}\\{#AppExeName}"; IconFilename: "{app}\\logoneutral.ico"; Tasks: quicklaunchicon |
| 75 | +
|
| 76 | +[Run] |
| 77 | +Filename: "{app}\\{#AppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(AppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent |
| 78 | +
|
| 79 | +[Registry] |
| 80 | +; File association for .tsv annotation files |
| 81 | +Root: HKCR; Subkey: ".tsv\\OpenWithProgids"; ValueType: string; ValueName: "ClinicalDBSAnnotator.tsv"; ValueData: ""; Flags: uninsdeletevalue |
| 82 | +Root: HKCR; Subkey: "ClinicalDBSAnnotator.tsv"; ValueType: string; ValueName: ""; ValueData: "Clinical DBS Annotator File"; Flags: uninsdeletekey |
| 83 | +Root: HKCR; Subkey: "ClinicalDBSAnnotator.tsv\\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\\logoneutral.ico,0" |
| 84 | +Root: HKCR; Subkey: "ClinicalDBSAnnotator.tsv\\shell\\open\\command"; ValueType: string; ValueName: ""; ValueData: "$DQ${app}\\{#AppExeName}$DQ$ $DQ$%1$DQ$" |
| 85 | +
|
| 86 | +[UninstallDelete] |
| 87 | +Type: filesandordirs; Name: "{app}" |
| 88 | +""" |
| 89 | + iss_content = ( |
| 90 | + iss_content.replace("$V$", version) |
| 91 | + .replace("$VU$", version_underscore) |
| 92 | + .replace("$DQ$", '"') |
| 93 | + ) |
| 94 | + iss_path = PROJECT_ROOT / "scripts" / "ClinicalDBSAnnotator.iss" |
| 95 | + iss_path.write_text(iss_content, encoding="utf-8") |
| 96 | + print(f"Generated {iss_path} with version {version}") |
| 97 | + |
| 98 | + |
| 99 | +if __name__ == "__main__": |
| 100 | + version = read_version() |
| 101 | + generate_iss(version) |
0 commit comments