feat: add binary build instructions and __main__ guard for pyinstaller

- Add __main__ guard to cli.py for pyinstaller packaging
- Document clean-venv build producing ~11 MB binary
- Add *.spec to .gitignore
- Exclude heavy stdlib modules in build command
This commit is contained in:
Maksim Totmin 2026-06-24 11:14:32 +07:00
parent 9feb14a33a
commit 28f5a407c9
3 changed files with 45 additions and 0 deletions

1
.gitignore vendored
View File

@ -5,6 +5,7 @@ __pycache__/
*.egg *.egg
dist/ dist/
build/ build/
*.spec
# --- Virtual environment --- # --- Virtual environment ---
.venv/ .venv/

View File

@ -220,6 +220,46 @@ ses-test my_scenario.yaml --ses-url http://ses-host:6190 --dry-run
Подробнее — см. раздел [«Как адаптировать под ваш проект»](#как-адаптировать-под-ваш-проект). Подробнее — см. раздел [«Как адаптировать под ваш проект»](#как-адаптировать-под-ваш-проект).
### Сборка исполняемого файла (без Python)
`ses-test` можно собрать в один бинарник (~11 MB), не требующий Python на целевой машине.
Сборка производится в чистом виртуальном окружении — чтобы в бинарник не попали
лишние системные пакеты (numpy, pillow и др.):
```bash
# 1. Клонируем репозиторий
git clone https://git.totmin.ru/en2zmax/ses-monitor.git
cd ses-monitor
# 2. Чистое окружение
python -m venv /tmp/build
/tmp/build/bin/pip install ./cli pyinstaller
# 3. Сборка
/tmp/build/bin/pyinstaller --onefile --name ses-test \
--paths src/ \
--hidden-import ses_monitor.utils \
--strip \
--exclude-module tkinter \
--exclude-module turtle \
--exclude-module sqlite3 \
--exclude-module curses \
--exclude-module idlelib \
--exclude-module pydoc \
--exclude-module venv \
--exclude-module ensurepip \
--exclude-module unittest \
--exclude-module test \
--exclude-module multiprocessing \
src/ses_monitor/cli.py
```
Готовый бинарник: `dist/ses-test` (~11 MB, Linux) или `dist/ses-test.exe` (Windows —
запустить те же команды на Windows).
Для сборки под другую ОС нужна эта ОС — PyInstaller не кросс-компилирует.
## Формат сценариев ## Формат сценариев
Сценарии описываются в YAML-файлах в каталоге `config/scenarios/`. Это гибкий DSL, который не зависит от конкретного проекта SES. Сценарии описываются в YAML-файлах в каталоге `config/scenarios/`. Это гибкий DSL, который не зависит от конкретного проекта SES.

View File

@ -297,3 +297,7 @@ async def _async_main(args: argparse.Namespace, scenario) -> int:
finally: finally:
await client.close() await client.close()
if __name__ == "__main__":
sys.exit(main())