Skip to content

Gen version file

gen_version_file

Generate the Windows version resource that PyInstaller stamps into the executable.

Generated rather than committed: the version comes from the git tag at build time, so a checked-in copy could only ever go stale. Needs the project installed, which is why it carries no PEP 723 metadata block: run it as uv run python <path>.

Functions:

Name Description
main

OUTPUT

OUTPUT = Path(__file__).resolve().parents[1] / 'version_info.txt'

TEMPLATE

TEMPLATE = "VSVersionInfo(\n  ffi=FixedFileInfo(filevers={numbers}, prodvers={numbers}, mask=0x3f, flags=0x0, OS=0x40004, fileType=0x1, subtype=0x0, date=(0,0)),\n  kids=[StringFileInfo([StringTable('040904B0', [\n    StringStruct('CompanyName', '{organisation}'),\n    StringStruct('FileDescription', '{name}'),\n    StringStruct('FileVersion', '{version}'),\n    StringStruct('InternalName', '{package}'),\n    StringStruct('OriginalFilename', '{package}.exe'),\n    StringStruct('ProductName', '{name}'),\n    StringStruct('ProductVersion', '{version}')\n  ])]), VarFileInfo([VarStruct('Translation', [1033, 1200])])]\n)\n"

main

main() -> None
Source code in scripts/gen_version_file.py
def main() -> None:
    # Take the version CI resolved from the tag. Reading it back from the installed
    # metadata instead would stamp pyproject's placeholder without a word whenever
    # the sync that rewrites that metadata did not happen.
    version = sys.argv[1] if len(sys.argv) > 1 else __version__
    # Windows wants exactly four integers, so pad; a dev version such as
    # 0.2.3.dev2 already carries four and keeps its build number.
    found = [int(number) for number in re.findall(r"\d+", version)]
    numbers = tuple(([*found, 0, 0, 0, 0])[:4])
    OUTPUT.write_text(
        TEMPLATE.format(
            numbers=numbers,
            version=version,
            name=APP_NAME,
            package=package_name,
            organisation=ORGANISATION,
        ),
        encoding="utf-8",
    )