# -*- mode: python ; coding: utf-8 -*-
# PyInstaller spec for lf_mri_gui
#
# Build:  pyinstaller lf_mri_gui.spec
# Output: dist\lf_mri_gui\lf_mri_gui.exe   (one-folder mode)
#
# Run from the lf_mri_gui directory with venv activated.

import sys
from pathlib import Path

HERE = Path(SPECPATH)           # lf_mri_gui/
REPO = HERE.parent              # MRI-testing/

block_cipher = None

a = Analysis(
    [str(HERE / 'app.py')],
    pathex=[str(HERE), str(REPO)],
    binaries=[],
    datas=[
        # ── Config files ──────────────────────────────────────────
        (str(HERE / 'cfg' / 'server_config.json'),  'cfg'),
        (str(HERE / 'cfg' / 'hw_config.json'),      'cfg'),
        # ── LF Constraints preset ─────────────────────────────────
        (str(HERE / 'cfg' / 'updated_constraints_lf.json'), 'cfg'),
        # ── LF_scanner / pypulseq ─────────────────────────────────
        (str(REPO / 'LF_scanner'), 'LF_scanner'),
    ],
    hiddenimports=[
        # PySide6 plugins needed at runtime
        'PySide6.QtSvg',
        'PySide6.QtPrintSupport',
        # pyqtgraph internals
        'pyqtgraph.graphicsItems.ViewBox.axisCtrlTemplate_pyqt5',
        'pyqtgraph.graphicsItems.PlotItem.plotConfigTemplate_pyqt5',
        'pyqtgraph.imageview.ImageViewTemplate_pyqt5',
        # numba
        'numba',
        'numba.core.compiler_lock',
        # scipy
        'scipy._lib.messagestream',
        # httpx
        'httpx',
        # yattag
        'yattag',
        # src modules (discovered via pathex but listed as safety net)
        'src.app_window',
        'src.tabs.seq_interp_tab',
        'src.tabs.scanner_tab',
        'src.tabs.fid_tab',
        'src.clients.orchestrator_client',
        'src.clients.seq_interp_client',
        'src.gui.workers',
        'src.fid.seqgen_FID',
    ],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[
        # Not needed in packaged app
        'pytest',
        'tkinter',
        'IPython',
        'notebook',
        'jupyter',
    ],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher,
    noarchive=False,
)

pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
    pyz,
    a.scripts,
    [],
    exclude_binaries=True,
    name='lf_mri_gui',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    console=False,            # no console window
    disable_windowed_traceback=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
    icon=None,                # add icon=r'path\to\icon.ico' if available
)

coll = COLLECT(
    exe,
    a.binaries,
    a.zipfiles,
    a.datas,
    strip=False,
    upx=True,
    upx_exclude=[],
    name='lf_mri_gui',
)
