|
| 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 / "clinical_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 | + iss_content = """; Inno Setup installer script for ClinicalDBSAnnotator |
| 26 | +; Requires Inno Setup 6.x or later to compile |
| 27 | +; Auto-generated by generate_iss.py - DO NOT EDIT MANUALLY |
| 28 | +
|
| 29 | +#define AppName "ClinicalDBSAnnotator" |
| 30 | +#define AppVersion "{version}" |
| 31 | +#define AppPublisher "Brain Modulation Lab" |
| 32 | +#define AppURL "https://github.com/bml/clinical-dbs-annotator" |
| 33 | +#define AppExeName "ClinicalDBSAnnotator_Windows_{version_underscore}.exe" |
| 34 | +
|
| 35 | +[Setup] |
| 36 | +AppId={{{{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}}}} |
| 37 | +AppName={{{{#AppName}}}} |
| 38 | +AppVersion={{{{#AppVersion}}}} |
| 39 | +AppPublisher={{{{#AppPublisher}}}} |
| 40 | +AppPublisherURL={{{{#AppURL}}}} |
| 41 | +AppSupportURL={{{{#AppURL}}}} |
| 42 | +AppUpdatesURL={{{{#AppURL}}}} |
| 43 | +DefaultDirName={{{{autopf}}}}\\{{{{{#AppName}}}}} |
| 44 | +DefaultGroupName={{{{#AppName}}}} |
| 45 | +AllowNoIcons=yes |
| 46 | +OutputDir=installer_output |
| 47 | +OutputBaseFilename={{{{#AppName}}}}_Setup_{{{{{#AppVersion}}}}_Windows |
| 48 | +Compression=lzma2/max |
| 49 | +SolidCompression=yes |
| 50 | +WizardStyle=Modern |
| 51 | +WizardImageFile=..\\icons\\logoneutral.bmp |
| 52 | +WizardSmallImageFile=..\\icons\\logoneutral-small.bmp |
| 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_{version_underscore}\\*"; 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: '"{{{{app}}}}\\{{{{{#AppExeName}}}}" "%1"' |
| 85 | +
|
| 86 | +[UninstallDelete] |
| 87 | +Type: filesandordirs; Name: "{{{{app}}}} |
| 88 | +""" |
| 89 | + iss_content = iss_content.replace("{version}", version).replace( |
| 90 | + "{version_underscore}", version_underscore |
| 91 | + ) |
| 92 | + iss_path = PROJECT_ROOT / "scripts" / "ClinicalDBSAnnotator.iss" |
| 93 | + iss_path.write_text(iss_content, encoding="utf-8") |
| 94 | + print(f"Generated {iss_path} with version {version}") |
| 95 | + |
| 96 | + |
| 97 | +if __name__ == "__main__": |
| 98 | + version = read_version() |
| 99 | + generate_iss(version) |
0 commit comments