# Building the Windows .exe (diesel_gui.py)

`diesel_gui.py` is a tkinter front-end for `diesel.py` so the script can be
run without a terminal. This doc covers packaging it as a standalone
`DieselConsolidation.exe` for Windows 10 using PyInstaller.

PyInstaller does **not** cross-compile — this must be run on an actual
Windows 10 machine with Python installed, not from macOS/Linux.

## Prerequisites

- Python 3.7+ installed on the Windows 10 machine
- Project dependencies installed: `pip install -r requirements.txt`

## 1. Install PyInstaller

```
pip install pyinstaller
```

## 2. Build the executable

From inside `scripts\diesel-consolidation\`:

```
pyinstaller --onefile --windowed --name DieselConsolidation diesel_gui.py
```

- `--onefile` — bundles everything into a single `.exe`.
- `--windowed` — suppresses the console window (this is a GUI app). Drop
  this flag temporarily if you need to see raw tracebacks while testing a
  build.
- PyInstaller automatically detects and bundles the local `diesel.py`
  import — no extra `--add-data`/`--hidden-import` flags needed, as long
  as `diesel.py` sits in the same folder as `diesel_gui.py` when you run
  the build.

Optional: add `--icon=myicon.ico` for a custom icon.

## 3. Output

```
dist\DieselConsolidation.exe
```

This is the file to copy/distribute. The `build\` and `dist\` folders
PyInstaller creates can be deleted/rebuilt at any time — only
`DieselConsolidation.exe` itself matters.

## 4. Place `estimulos.csv` / `estimulos.xlsx` next to the .exe

The app resolves the stimulus schedule file relative to the running
executable's own folder (via `diesel.get_base_dir()`), not to a temp
extraction folder — this is required because PyInstaller's `--onefile`
mode unpacks bundled files into a throwaway temp directory at runtime,
which `estimulos.csv` would otherwise be read from and silently lost on
each run.

So: copy `estimulos.xlsx` (preferred) or `estimulos.csv` into the same
folder as `DieselConsolidation.exe`. You can edit the stimulus schedule
later without rebuilding the `.exe`.

As with the CLI, `estimulos.xlsx` is tried first; `estimulos.csv` is only
used as a fallback if the `.xlsx` isn't present.

## 5. First run on a clean machine

If a missing-DLL or VC++ runtime error appears on a bare-metal Windows 10
box (no Python/dev tools ever installed), install the "Microsoft Visual
C++ Redistributable" from Microsoft and retry.

## 6. Rebuilding after code changes

Re-run the same `pyinstaller` command — it regenerates `build\` and
`dist\DieselConsolidation.exe` from scratch. There's no incremental/watch
mode; every change to `diesel.py` or `diesel_gui.py` requires a full
rebuild.
