Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f3a8932
refactor: move code into src/finance_mosaix package (src-layout)
Developer-Simon Sep 6, 2026
580a8e9
feat(core): resolve data paths via FINANCE_MOSAIX_DATA_DIR
Developer-Simon Oct 21, 2026
2c16263
build: relax numpy/pandas pins and export requirements for electron
Developer-Simon Oct 21, 2026
9903e43
feat(electron): scaffold modular shell with i18n and python locator
Developer-Simon Oct 21, 2026
762f5c0
feat(electron): venv manager for the slim variant
Developer-Simon Oct 21, 2026
1529cd0
feat(electron): runtime resolution (override, dev, bundled, system)
Developer-Simon Oct 21, 2026
4fc8248
feat(electron): streamlit server process with free port, health check…
Developer-Simon Oct 21, 2026
cc06ff7
feat(electron): smoke check, legacy data notice and window chrome hel…
Developer-Simon Oct 21, 2026
9b1d7dc
feat(electron): rewrite main process on top of the new modules
Developer-Simon Oct 21, 2026
e51244d
feat(electron): build relocatable python-build-standalone runtime
Developer-Simon Oct 21, 2026
0666ff2
fix(electron): stop server on startup errors and resolve dev runtime dir
Developer-Simon Oct 21, 2026
4d3ef7a
build(electron): electron-builder configs for slim/full and app icons
Developer-Simon Oct 21, 2026
9bf41d2
fix(electron): use hyphenated appId, electron-builder derives the Fla…
Developer-Simon Oct 21, 2026
a3270d7
ci: build, smoke-test and release electron installers on all platforms
Developer-Simon Oct 21, 2026
9f699bf
docs: document the new electron shell, variants and releases
Developer-Simon Oct 21, 2026
7188376
fix: pass env to legacy notice and install setuptools_scm for CI version
Developer-Simon Oct 21, 2026
4fb855e
feat: new Mosaik-M logo in the title bar, sidebar and app icons
Developer-Simon Oct 21, 2026
337b048
chore(dev): add create-pr and merge-pr scripts with a filled PR template
Developer-Simon Oct 21, 2026
2c4f180
fix(docs): serve the new logo as the Pages favicon
Developer-Simon Oct 21, 2026
8ed0509
fix(electron): stop copying extra resources twice in the full build
Developer-Simon Oct 21, 2026
ddc9963
ci(electron): build installers only on manual runs and releases
Developer-Simon Oct 21, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 33 additions & 21 deletions .github/PULL_REQUEST_TEMPLATE/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
## Pull Request

### Summary
Please describe the purpose of this PR and the user-facing change it contains.

### Changes
- What changed
- Why it changed
- How it was verified

### Checklist
- [ ] Code changes are covered by tests when appropriate
- [ ] Documentation has been updated for user-facing changes
- [ ] The package metadata is correct for installable builds
- [ ] No generated or sensitive files are committed
- [ ] This PR is ready for review

### Notes
- The repository uses `master` as the mainline branch.
- Workflow names: `Python Tests`, `Build package`, `Publish docs`, `Release Please`.
- If AI assistance was used, describe the role of the AI and any verification performed.
## Squash-merge commit message

<!--
`scripts/dev/create-pr.sh` fills every field of this template. Do not edit
the placeholders by hand. Change the inputs and run the script again, or
edit the PR description once and let `scripts/dev/merge-pr.sh` check it.

`master` uses squash merge. The subject of the merge commit is the PR title
(Conventional Commits: `type(scope): imperative summary`, release-please
builds CHANGELOG.md from it), so the fenced block below holds only the BODY.
It never repeats the title and always ends with a
`Co-authored-by: Claude Sonnet|Opus|Fable x.y <noreply@anthropic.com>`
trailer. Haiku is never named there.

`scripts/dev/merge-pr.sh` takes this block as the merge body. GitHub's own
merge button would use the commit list instead, so merge with the script.
-->

```text
{{MESSAGE}}
```

## Summary

{{SUMMARY}}

## Checks

- [{{CHECK_TITLE}}] The title is a Conventional Commits subject.
- [{{CHECK_FILES}}] No database files (`*.duckdb`) or local `settings.json` are tracked.
- [{{CHECK_AI}}] AI assistance disclosed per [CONTRIBUTING.md](../blob/master/CONTRIBUTING.md#ai-transparency): {{AI_MODEL}}
- [{{CHECK_SUITES}}] Suites run locally: {{SUITES}}
- Linked issue: {{ISSUE}}
183 changes: 56 additions & 127 deletions .github/knowledge/electron-python-runtime.md
Original file line number Diff line number Diff line change
@@ -1,156 +1,83 @@
# Finance Mosaix Electron App

This note covers the Electron desktop wrapper and the packaged Python runtime used by
Finance Mosaix.
This note covers the Electron desktop shell and the bundled Python runtime used by
Finance Mosaix. Commands and the variants are described in `electron/README.md`.

## Electron app overview

The `electron/` directory contains the desktop wrapper that launches the Streamlit
dashboard from `dashboard/app.py` inside a native Electron window.
The `electron/` directory contains the desktop shell. It starts the Streamlit dashboard
from `src/finance_mosaix/dashboard/app.py` on a free local port and shows it in an
Electron window. The shell is split into modules under `electron/src/`:

### Local development
- `resolve-runtime.js`: picks the Python interpreter (see below)
- `python-locator.js`, `venv-manager.js`: system Python and the managed venv
- `server-process.js`: starts, health-checks and stops the Streamlit process
- `legacy-notice.js`, `smoke.js`, `chrome.js`, `i18n.js`: legacy data notice, `--smoke`
check, window chrome and texts

1. Open a terminal at the project root.
2. Install Node dependencies inside `electron/`:
## Packaged Python runtime

```bash
cd electron
npm install
```
The full variant ships a relocatable CPython built by
[python-build-standalone](https://github.com/astral-sh/python-build-standalone). The
slim variant has no interpreter and uses a system Python.

3. Start the Electron app:
### How the runtime is built

```bash
npm start
```
`npm run build:runtime` (in `electron/`) runs `runtime/build-runtime.js`:

The app launches the Streamlit dashboard and embeds it in a desktop window.
1. The archive for the current platform is read from `runtime/runtime.lock.json`
(release, Python version, asset name and SHA-256 per target). It is downloaded to
`build/cache/` if it is not cached yet.
2. The SHA-256 sum is checked, both for a cached archive and for a new download. A
cached archive with a wrong sum is deleted and downloaded again.
3. The archive is unpacked into `build/python/`. On Windows the script uses the
system `tar.exe`, because the GNU tar of Git Bash reads `D:\...` as a remote host.
4. `build/requirements.txt` is installed into the runtime with `pip`. The environment
variables `PYTHONNOUSERSITE=1` and the `PYTHONPATH` and `PYTHONHOME` variables are
removed for this step, so the build does not depend on the user's Python.
5. An import check runs for streamlit, duckdb, pandas, numpy, openpyxl, altair,
matplotlib and seaborn.

### Packaging
`build/requirements.txt` comes from `scripts/write_requirements.py` through
`npm run build:requirements`.

From the `electron/` directory:
The packaged app finds the runtime at `<resources>/python/bin/python3` (Windows:
`python.exe`). Packaging copies `electron/build/python/` there (`electron-builder.full.yml`).

```bash
npm run dist
```
### Updating the Python version

The build is configured for Windows with `nsis` and includes the project files
required to launch the dashboard.
Change `release`, `python` and the `asset` and `sha256` values of each target in
`runtime/runtime.lock.json`. Each target needs its own SHA-256 sum. Then run
`npm run build:runtime` on each platform that is packaged.

### Icon regeneration

If the packaged icon needs to be rebuilt from the SVG source, run:

```bash
npm run generate-icon
```

This generates `docs/img/favicon.ico` from `docs/img/favicon.svg` at 256x256.

### Notes

- The Electron wrapper looks for Python either from the host environment or via the
`PYTHON_EXECUTABLE` environment variable.
- For a bundled runtime, use:

```bash
npm run build-runtime
```

- `npm run dist` now builds the embedded Python runtime automatically before packaging.
- Generated Electron folder artifacts include `python-runtime/`, `dist/`, and `build_log.txt`.
- To clean the Electron folder before a fresh build, remove `electron/node_modules/`,
`electron/python-runtime/`, `electron/dist/`, and `electron/build_log.txt`.
- `electron/build_python_runtime.py` is the canonical runtime builder; the shell script
`electron/build-python-runtime.sh` may be removed if you want a smaller folder.

## Electron Packaged Python Runtime

The Electron desktop wrapper (`electron/`) bundles a private Python runtime so the
Streamlit dashboard can run on a machine without a system-wide Python install. This
runtime is built by [`electron/build_python_runtime.py`](../electron/build_python_runtime.py)
into `electron/python-runtime` (gitignored, regenerated locally and in CI — never
committed).

### Why the previous runtime approach broke

The original script created the runtime with a plain `venv.EnvBuilder`, then rewrote
`pyvenv.cfg` to try to make it relocatable, and installed the project with
`pip install -e .`.

This was broken for two independent reasons:

1. **A stock Windows venv is not self-contained.** `Scripts/python.exe` is only a thin
stub — it has no interpreter DLL or standard library of its own. It relies entirely
on `pyvenv.cfg`'s `home = ...` value to locate the *original* base Python
installation's DLL and stdlib. The old script rewrote `home` to point at the venv's
own `Scripts` folder, which doesn't contain the stdlib/DLLs either — so
`python.exe` could no longer initialize. In practice this showed up as `python.exe`
hanging or exiting immediately without useful output whenever Electron tried to
launch Streamlit.
2. **Editable installs aren't relocatable.** `pip install -e ROOT` writes a path finder
pointing at the absolute dev checkout path. That path doesn't exist once the runtime
is packaged and moved to another machine.

Even without those bugs, a regular venv is always tied to whatever base Python produced
it — it can never be a truly portable, drop-in runtime for an end user's machine.

### Current approach

On Windows, `build_python_runtime.py` now:

1. Downloads the official **embeddable CPython distribution**
(`python.org/ftp/python/<version>/python-<version>-embed-amd64.zip`), which ships
its own interpreter DLL and standard library — no dependency on any Python
installation on the build machine or the end user's machine.
2. Enables `site-packages` support by editing the shipped `python311._pth` file
(uncommenting `import site` and adding `Lib\site-packages`).
3. Bootstraps `pip` via `get-pip.py`.
4. Installs the project with a normal (non-editable) `pip install ROOT` so the package
files are copied into the runtime's own `site-packages`, not linked back to the dev
checkout.

The result is a fully self-contained `python-runtime` folder: no external Python
dependency, and no absolute paths back to the build machine. It is genuinely
relocatable, which is what the packaged Electron installer (built by
`npm run dist` / `.github/workflows/electron-package.yml`) requires to work on a fresh
system.

`python.exe` now lives directly at `python-runtime/python.exe` (embeddable layout)
rather than `python-runtime/Scripts/python.exe` (venv layout). `electron/main.js`'s
`getPythonExecutable()` checks the new location first and falls back to the old
`Scripts/python.exe` path for backward compatibility with any previously built runtime.
### Repairing a broken runtime

For non-Windows platforms (no official embeddable distribution exists), the script
falls back to a plain venv via `build_posix_venv_runtime()` — this still requires a
compatible system Python to be present at runtime and is not fully self-contained.
If the bundled interpreter fails to start or the dashboard does not import its
dependencies, delete `electron/build/python/` and run `npm run build:runtime` again.

### Repairing a broken runtime
For the system Python variant, use Tools → Reinstall Python environment in the app, or
delete the `venv/` folder in the data folder. The next start recreates it.

If the packaged app's `python.exe` hangs or fails to start (e.g. after moving the app,
or after `pyvenv.cfg` corruption from an older build), rebuild the runtime from
scratch:
### Interpreter order at runtime

```powershell
cd electron
Remove-Item -Recurse -Force python-runtime
python build_python_runtime.py
npm start
```
`src/resolve-runtime.js` checks, in this order: `FINANCE_MOSAIX_PYTHON`, the development
venv `.venv` (not packaged), the bundled runtime, then the system Python with the managed
venv in the user data folder. The order is also described in `electron/README.md`.

## Electron Version Resolution In CI
## Electron version resolution in CI

### Symptom

During `npm run dist`, the version sync step (`electron/sync_version.js`) can report:
When the version sync step (`electron/sync_version.js`, `npm run sync-version`) runs
without a tag, it can report:

- `Electron package version updated -> 0.0.0`

This causes Electron package metadata to regress to a placeholder version.

### Root cause pattern

`electron/sync_version.js` asks Python for `src.version.get_canonical_version()`.
`electron/sync_version.js` asks Python for `finance_mosaix.core.version.get_canonical_version()`.
If `setuptools_scm` is not available in the Python environment used by the workflow,
SCM-based version resolution may fail and fallback selection becomes critical.

Expand All @@ -160,12 +87,13 @@ Electron version.

### Guardrails implemented

1. `src/version.py` now treats installed metadata version `0.0.0` as a placeholder
1. `finance_mosaix/core/version.py` treats installed metadata version `0.0.0` as a placeholder
and ignores it.
2. `src/version.py` now reads `[tool.setuptools_scm].fallback_version` from
2. `finance_mosaix/core/version.py` reads `[tool.setuptools_scm].fallback_version` from
`pyproject.toml` and uses it before installed package metadata.
3. `.github/workflows/electron-package.yml` now installs `setuptools_scm` in both
Windows and Linux packaging jobs.
3. In `.github/workflows/electron.yml` a release build takes the version from the tag
(`npm version`, `electron/VERSION`). Other runs call `npm run sync-version` after
`actions/checkout` with `fetch-depth: 0`.
4. `test/test_version_sync.py` includes regression tests for this exact fallback
scenario.

Expand All @@ -183,6 +111,7 @@ Electron version.
### CI checklist for future changes

- Keep `actions/checkout` with `fetch-depth: 0` so tags/history are available.
- Ensure `setuptools_scm` is installed before `npm run dist`.
- Make sure the Python used by `npm run sync-version` can resolve the version in the
workflow (`.github/workflows/electron.yml`).
- If versioning behavior changes, run `pytest test/test_version_sync.py -q`.
- Do not rely on installed package metadata alone for canonical versioning.
97 changes: 0 additions & 97 deletions .github/workflows/electron-package.yml

This file was deleted.

Loading
Loading