Skip to content

Commit ea56146

Browse files
committed
common(fix[has_minimum_version]): cache get_version() to avoid double subprocess
why: has_minimum_version called get_version(tmux_bin=tmux_bin) twice — once for the version comparison and again in the error message f-string — spawning two tmux subprocesses on the error path. what: - Assign get_version(tmux_bin=tmux_bin) to current_version before the check - Use current_version in both the comparison and the error message
1 parent 85ace72 commit ea56146

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/libtmux/common.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,11 +485,12 @@ def has_minimum_version(raises: bool = True, tmux_bin: str | None = None) -> boo
485485
Versions will now remove trailing letters per
486486
`Issue 55 <https://github.com/tmux-python/tmuxp/issues/55>`_.
487487
"""
488-
if get_version(tmux_bin=tmux_bin) < LooseVersion(TMUX_MIN_VERSION):
488+
current_version = get_version(tmux_bin=tmux_bin)
489+
if current_version < LooseVersion(TMUX_MIN_VERSION):
489490
if raises:
490491
msg = (
491492
f"libtmux only supports tmux {TMUX_MIN_VERSION} and greater. This "
492-
f"system has {get_version(tmux_bin=tmux_bin)} installed. Upgrade your "
493+
f"system has {current_version} installed. Upgrade your "
493494
"tmux to use libtmux, or use libtmux v0.48.x for older tmux versions."
494495
)
495496
raise exc.VersionTooLow(msg)

0 commit comments

Comments
 (0)