1) set the required textual version to version 8.2.8

2) generated installers which bundle the required .venv
This commit is contained in:
2026-09-19 14:38:49 +02:00
parent fccd2def59
commit 1471a342d8
11 changed files with 322 additions and 8 deletions
+81
View File
@@ -0,0 +1,81 @@
# Installers
Two ways to build a distributable bundle, both producing a single file
under `dist/`. Both bundle the app's own code, the i18n library, the i18n
translation data, and `app/styles.tcss`. Neither bundles `yt-dlp` or
`ffmpeg` — the app runs them as external command-line tools via
`subprocess`, never imports them as Python libraries, so **both still need
to be installed separately and be on `PATH`** on the machine that runs the
installer's output, regardless of which installer you use.
| | `build_pyinstaller.sh` | `build_pex.sh` |
|---|---|---|
| Bundles a Python interpreter | Yes | No — needs a compatible `python3` already on the target machine |
| Bundles Textual 8.2.8 + deps | Yes | Yes |
| Output | `dist/ytdlp-tui` (native executable) | `dist/ytdlp-tui.pex` (zipapp) |
| Run it with | `./dist/ytdlp-tui` | `python3 dist/ytdlp-tui.pex` |
| Typical size | ~35-40 MB | ~3-4 MB |
Both scripts create their own throwaway build `venv` (`.build-venv-*`,
already git-ignored) so they don't touch whatever environment you're
already using, and both read dependency versions from
`requirements-installer.txt` — the subset of `requirements.txt` the app
actually imports (just `textual==8.2.8`). `yt-dlp` is deliberately *not*
pip-installed into either bundle: even if it were, that would only add the
`yt_dlp` Python package inside the bundle, not put a `yt-dlp` executable on
the target machine's `PATH` — which is what the app's subprocess calls
actually need.
## Build
```bash
# Bundled-Python installer (PyInstaller)
packaging/build_pyinstaller.sh
./dist/ytdlp-tui
# No-bundled-Python zipapp (pex)
packaging/build_pex.sh
python3 dist/ytdlp-tui.pex
```
Run either from the project root. Both are Bash scripts (Linux/macOS); on
Windows use WSL or adapt them to PowerShell — the underlying `pyinstaller`/
`pex` invocations are unchanged.
## How the data files travel
`app/tui_app.py`'s `CSS_PATH` and `main.py`'s `PROJECT_ROOT` are both
resolved through `app/runtime_paths.bundle_root()` rather than a plain
`Path(__file__).parent`, because a frozen PyInstaller build's Python
modules run from inside an embedded archive with no real file on disk —
`__file__`-relative resolution would silently point at a path that
doesn't exist. `bundle_root()` returns:
* `sys._MEIPASS` when running under a PyInstaller build (where
`--add-data` files are actually extracted to), or
* the directory containing `main.py` otherwise — true for a plain source
checkout, and also for a pex zipapp, since pex extracts its bundled
sources to a cache directory on first run and imports them from there
like a normal checkout.
The PyInstaller spec (`packaging/pyinstaller/ytdlp-tui.spec`) explicitly
adds `i18n/` and `app/styles.tcss` as `datas` so they land next to
`_MEIPASS` at the same relative paths `bundle_root()` expects. It also
runs `collect_all("textual")` — without it, the frozen build fails the
first time a lazily-loaded widget (e.g. `MarkdownViewer`, opened via
Ctrl+A) is used, since Textual imports some of its own widgets on demand
through `__getattr__`, which PyInstaller's static analysis can't see.
The pex build doesn't need any of this special-casing: `-D <staging dir>`
bundles a plain copy of `main.py`, `app/`, `lib/`, `i18n/` verbatim
(code *and* data files alike), preserving the exact same relative layout
as a normal checkout.
## Verifying a build
Both scripts were smoke-tested end to end (not just "it starts"): run
under a pty, the full main screen renders with translated labels and the
external stylesheet applied, and `Ctrl+A` correctly opens the
`MarkdownViewer` showing `i18n/en/help.md`'s actual content — confirming
both the bundled stylesheet and the bundled translation/help data resolve
correctly in each packaging mode.
+47
View File
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
# Build a self-contained Python zipapp (.pex) with Textual 8.2.8 and its
# other dependencies bundled, but WITHOUT a bundled Python interpreter — the
# target machine needs a compatible `python3` already on PATH.
#
# Usage: packaging/build_pex.sh
# Output: dist/ytdlp-tui.pex
# Run it with: python3 dist/ytdlp-tui.pex (or ./dist/ytdlp-tui.pex directly,
# since the shebang points at /usr/bin/env python3 on Unix)
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
cd "$PROJECT_ROOT"
# pex bundles whatever's under the -D directory verbatim (code AND
# non-Python data files alike), so stage only the runtime files the app
# actually needs at runtime — not tests/, README.md, packaging/, etc.
STAGE="$(mktemp -d)"
trap 'rm -rf "$STAGE"' EXIT
cp -r main.py app lib i18n "$STAGE"/
find "$STAGE" -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
VENV_DIR=".build-venv-pex"
python3 -m venv "$VENV_DIR"
# shellcheck disable=SC1091
source "$VENV_DIR/bin/activate"
pip install --upgrade pip -q
pip install "pex>=2.3" -q
mkdir -p dist
pex \
-o dist/ytdlp-tui.pex \
-D "$STAGE" \
-r requirements-installer.txt \
-e main:main \
--python-shebang '/usr/bin/env python3'
deactivate
echo
echo "Built: dist/ytdlp-tui.pex"
echo "Run with: python3 dist/ytdlp-tui.pex"
echo "Note: needs a compatible python3 (and yt-dlp/ffmpeg on PATH) on the target machine — see packaging/README.md."
+28
View File
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
# Build a single-file, self-contained executable (bundled Python interpreter
# + Textual 8.2.8 + all deps + i18n data) using PyInstaller.
#
# Usage: packaging/build_pyinstaller.sh
# Output: dist/ytdlp-tui (or dist/ytdlp-tui.exe on Windows)
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
cd "$PROJECT_ROOT"
VENV_DIR=".build-venv-pyinstaller"
python3 -m venv "$VENV_DIR"
# shellcheck disable=SC1091
source "$VENV_DIR/bin/activate"
pip install --upgrade pip -q
pip install -r requirements-installer.txt -q
pip install "pyinstaller>=6.0" -q
pyinstaller --noconfirm --clean packaging/pyinstaller/ytdlp-tui.spec
deactivate
echo
echo "Built: dist/ytdlp-tui"
echo "Note: yt-dlp and ffmpeg are still required on PATH at runtime (see packaging/README.md)."