diff --git a/build.py b/build.py index addce8b..a2b823a 100644 --- a/build.py +++ b/build.py @@ -1,4 +1,5 @@ import shutil +import importlib.util from pathlib import Path import PyInstaller.__main__ import typer @@ -22,6 +23,25 @@ def build(build: bool = True, copy: bool = True, test: bool = False, dest: str | if test: print("Building Windows test one-file bundle with PyInstaller") # On Windows use ';' as add-data separator (src;dest) + add_data_args = ["--add-data", "icon;icon"] + + # Try to include dicognito package data (release_notes.md) which + # PyInstaller may miss. This prevents runtime FileNotFoundError for + # dicognito/release_notes.md when the package expects the file at runtime. + try: + spec = importlib.util.find_spec("dicognito") + if spec and spec.submodule_search_locations: + dicognito_path = Path(spec.submodule_search_locations[0]) + release_notes = dicognito_path / "release_notes.md" + if release_notes.exists(): + # PyInstaller on Windows expects 'src;dest' + add_data_args += ["--add-data", f"{str(release_notes)};dicognito"] + else: + # include whole package folder if the single file wasn't found + add_data_args += ["--add-data", f"{str(dicognito_path)};dicognito"] + except Exception as e: + print(f"Warning: couldn't locate dicognito package: {e}") + PyInstaller.__main__.run([ str(project_root / "nice.py"), "--onefile", @@ -33,8 +53,8 @@ def build(build: bool = True, copy: bool = True, test: bool = False, dest: str | str(project_root / "build" / "test"), "--specpath", str(project_root / "build" / "specs"), - "--add-data", - "icon;icon", + ] + add_data_args + [ + # add some common hidden imports that PyInstaller sometimes misses "--hidden-import", "bs4", "--hidden-import",