Skip to content

feat: add uv / PEP 723 support#67

Open
al-bashkir wants to merge 2 commits into
ofirgall:masterfrom
al-bashkir:master
Open

feat: add uv / PEP 723 support#67
al-bashkir wants to merge 2 commits into
ofirgall:masterfrom
al-bashkir:master

Conversation

@al-bashkir

Copy link
Copy Markdown

Adds uv / PEP 723 inline script metadata support so users can run the plugin without manually installing libtmux. Existing
python3 + system libtmux path is unchanged.

What changes

  • scripts/rename_session_windows.py — PEP 723 metadata block added after the shebang. The block is a Python comment so the file still runs as-is under python3; uv parses it and provisions a cached venv
    with libtmux.
  • tmux_window_name.tmux — auto-detects uv on PATH. If found, all script invocations route through uv run --script. Otherwise the original python3 + libtmux import check runs unchanged. Zero config;
    existing users see no behavior change.
  • enable_user_rename_hook — the after-rename-window hook value previously hardcoded the bare script path and relied on the python3 shebang. That bypassed the launcher under the uv path. Now it reads
    TMUX_WINDOW_NAME_LAUNCHER (exported from .tmux) and prefixes the hook's run-shell command. Pre-existing unbalanced quotes around the run-shell argument are also fixed (they broke once the path string
    contained spaces from the uv run --script prefix).
  • README.md
    • New ### Recommended: install uv section above the libtmux install instructions, explaining pip install is not needed when uv is present.
    • The nvim Lua autocmd, vim job_start, and zsh chpwd snippets gain parallel uv run --script variants below the originals (originals kept as-is).

How to verify

# uv path — works without system libtmux
uv run --script scripts/rename_session_windows.py --help

# python3 path — works with system libtmux installed (existing behaviour)
python3 scripts/rename_session_windows.py --help

Manual smoke (4 quadrants):

┌────────────┬────────────────┬──────────────────────────────────────────────┐
│ uv on PATH │ system libtmux │                   Expected                   │
├────────────┼────────────────┼──────────────────────────────────────────────┤
│ yes        │ no             │ hooks register with uv run --script prefix   │
├────────────┼────────────────┼──────────────────────────────────────────────┤
│ yes        │ yes            │ uv branch wins (prefix in hook value)        │
├────────────┼────────────────┼──────────────────────────────────────────────┤
│ no         │ yes            │ original python3 branch, no behaviour change │
├────────────┼────────────────┼──────────────────────────────────────────────┤
│ no         │ no             │ existing tmux error display, plugin disabled │
└────────────┴────────────────┴──────────────────────────────────────────────┘

Verify hook strings:
tmux show-hooks -g | grep 8921

Notes

- requires-python = ">=3.7" matches the existing pyproject.toml ruff target-version.
- No automated test changes. Existing pytest suite continues to use system-installed libtmux.
- path_utils.py is unchanged — PEP 723 metadata only goes on the entrypoint script.

al-bashkir added 2 commits May 4, 2026 17:53
* feat: add PEP 723 inline script metadata for uv

Allows running rename_session_windows.py via 'uv run --script' so
libtmux is provisioned automatically. Block is a comment for plain
python3, behaviour is unchanged on that path.

Refs ofirgall#56

* feat: auto-detect uv in tmux entrypoint

If 'uv' is on PATH, route all rename_session_windows.py invocations
through 'uv run --script' so libtmux is resolved from PEP 723
metadata. Otherwise fall back to the existing python3 + libtmux
import check. Zero config; existing users unaffected.

Refs ofirgall#56

* docs: document uv auto-detect path in README

Tell users uv is auto-detected and pip-install of libtmux is not
required when uv is present.

Refs ofirgall#56

* fix: route after-rename-window hook through uv launcher

enable_user_rename_hook() registered a tmux hook with the bare script
path, relying on the python3 shebang. Under the uv adoption path,
that bypasses uv and tries system python3 + libtmux, which silently
fails when libtmux is not installed system-wide.

Pass the launcher through env var TMUX_WINDOW_NAME_LAUNCHER from the
.tmux entrypoint, and prefix the hook's run-shell command with it.
The pre-existing unbalanced quotes around run-shell's path also broke
once the path contained spaces ("uv run --script /path"); use
properly escaped \"...\" so tmux parses the run-shell argument as a
single quoted token.

Refs ofirgall#56

---------
The nvim Lua autocmd, vim job_start, and zsh chpwd snippets all
invoked the script via its python3 shebang, which fails when libtmux
is not installed system-wide (the uv path skips that install). Add a
parallel 'uv run --script' variant under each snippet so users on the
uv path can pick the one that works for them. Original direct-shebang
snippets are kept as-is.

Refs ofirgall#56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant