Skip to content

Commit b105b83

Browse files
committed
common(feat): Add deprecation warning for tmux < 3.2a
1 parent 72c5735 commit b105b83

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/libtmux/common.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,44 @@
2929
#: Most recent version of tmux supported
3030
TMUX_MAX_VERSION = "3.5a"
3131

32+
#: Minimum version before deprecation warning is shown
33+
TMUX_SOFT_MIN_VERSION = "3.2a"
34+
3235
SessionDict = dict[str, t.Any]
3336
WindowDict = dict[str, t.Any]
3437
WindowOptionDict = dict[str, t.Any]
3538
PaneDict = dict[str, t.Any]
3639

40+
#: Flag to ensure deprecation warning is only shown once per process
41+
_version_deprecation_checked: bool = False
42+
43+
44+
def _check_deprecated_version(version: LooseVersion) -> None:
45+
"""Check if tmux version is deprecated and warn once.
46+
47+
This is called from get_version() on first invocation.
48+
"""
49+
global _version_deprecation_checked
50+
if _version_deprecation_checked:
51+
return
52+
_version_deprecation_checked = True
53+
54+
import os
55+
import warnings
56+
57+
if os.environ.get("LIBTMUX_SUPPRESS_VERSION_WARNING"):
58+
return
59+
60+
if version < LooseVersion(TMUX_SOFT_MIN_VERSION):
61+
warnings.warn(
62+
f"tmux {version} is deprecated and will be unsupported in a future "
63+
f"libtmux release. Please upgrade to tmux {TMUX_SOFT_MIN_VERSION} "
64+
"or newer. Set LIBTMUX_SUPPRESS_VERSION_WARNING=1 to suppress this "
65+
"warning.",
66+
DeprecationWarning,
67+
stacklevel=4,
68+
)
69+
3770

3871
class EnvironmentMixin:
3972
"""Mixin for manager session and server level environment variables in tmux."""
@@ -303,7 +336,9 @@ def get_version() -> LooseVersion:
303336

304337
version = re.sub(r"[a-z-]", "", version)
305338

306-
return LooseVersion(version)
339+
version_obj = LooseVersion(version)
340+
_check_deprecated_version(version_obj)
341+
return version_obj
307342

308343

309344
def has_version(version: str) -> bool:

0 commit comments

Comments
 (0)