Skip to content

v0.70.0 - Strict ty type checking, command timeouts, and structured logging

Latest

Choose a tag to compare

@tony tony released this 28 Nov 23:22
· 2 commits to master since this release

libtmux 0.70.0 moves static type checking from mypy to Astral's ty (all = "error") paired with Ruff ANN annotations and @overload return types on show_option() and QueryList. It also adds opt-in command, channel, and listing timeouts raising TmuxCommandTimeout, defines single-owner failure routing and structured logging with symmetric environment masking, and adds Client.request_clipboard() on tmux 3.6a+.

Highlights

Upgrading

Read typed options and query collections without casts under ty or mypy:

from libtmux import Server, Window

with Server(socket_name="ci-types", kill_on_exit=True) as server:
    session = server.new_session(session_name="build")
    base_index: int | None = session.show_option("base-index", global_=True)
    mouse: bool | None = session.show_option("mouse", global_=True)
    session.new_window(window_name="compile", attach=False)
    compile_window: Window | None = session.windows.get(
        window_name="compile",
        default=None,
    )
    assert isinstance(base_index, int)
    assert isinstance(mouse, bool)
    assert compile_window is not None and compile_window.window_name == "compile"

Bound commands, listings, and channel waits explicitly when a server or producer may stall:

import logging

from libtmux import Server, exc

logger = logging.getLogger(__name__)

with Server(socket_name="ci-timeout", kill_on_exit=True, timeout=2.0) as server:
    server.new_session(session_name="build")
    try:
        server.wait_for("build-ready", timeout=0.1)
    except exc.TmuxCommandTimeout as error:
        logger.warning(
            "channel %s timed out after %.1fs",
            error.argv[-1],
            error.timeout,
        )

Log raised failures at your own exception boundary, catch TmuxCommandNotFound for unusable tmux binaries, and configure command DEBUG filters on libtmux.common:

import logging

from libtmux import Server, exc

command_logger = logging.getLogger("libtmux.common")
previous_level = command_logger.level
command_logger.setLevel(logging.DEBUG)
logger = logging.getLogger(__name__)

try:
    with Server(socket_name="ci-logging", kill_on_exit=True) as server:
        session = server.new_session(session_name="build")
        try:
            session.kill_window("missing-window")
        except exc.TmuxCommandNotFound:
            logger.error("tmux executable is missing or not runnable")
        except exc.LibTmuxException:
            logger.exception("tmux command failed")
finally:
    command_logger.setLevel(previous_level)

Pass options after window_name by keyword in temp_window():

from libtmux import Server
from libtmux.test.temporary import temp_window

with Server(socket_name="ci-temp", kill_on_exit=True) as server:
    session = server.new_session(session_name="build")
    with temp_window(session, "work", attach=False) as window:
        assert window.window_name == "work"

See the migration notes and the changelog for the full list.

What's Changed

  • ci(tests): Exercise tmux 3.7c in place of 3.7b by @tony in #746
  • Just(chore): Clean ignored build output by @tony in #783
  • dev(chore): Remove unused Node version pin by @tony in #834
  • Server(fix[raise_if_dead]): Suppress check_call output by @tony in #641
  • Temporary(fix[temp_window]): Remove unused *args by @tony in #619
  • README(docs): Link the AI policy by @tony in #793
  • README(docs): Pin a minor series without naming one by @tony in #824
  • docs(feat[brand]): Add Python logo and brand kit by @tony in #760
  • docs(feat[brand]): Show a query on the sharing card by @tony in #816
  • Docs(fix[api]): Refresh native tmux API citations by @tony in #774
  • Server(docs[overview]): Group members by purpose by @tony in #785
  • Server(docs): Complete the capability directory by @tony in #813
  • docs(fix): Correct library setup and terminal examples by @tony in #797
  • Client(feat): Request a terminal clipboard by @tony in #889
  • logging(feat): Document logging and define failure ownership by @tony in #748
  • Command(feat[timeout]): Bound commands, waits, and listings by @tony in #807
  • dev(ty): Replace mypy with strict ty and Ruff ANN by @tony in #682

Full Changelog: v0.69.0...v0.70.0