Skip to content

Commit d35e59f

Browse files
committed
common.py(refactor): Bump TMUX_MIN_VERSION to 3.2a
why: tmux versions below 3.2a are no longer supported as of libtmux 0.49.0 what: - Change TMUX_MIN_VERSION from "1.8" to "3.2a" - Remove TMUX_SOFT_MIN_VERSION constant (no longer needed) - Remove _version_deprecation_checked flag - Remove _check_deprecated_version() function - Remove deprecation warning call from get_version() - Update has_minimum_version() docstring to reflect 3.2a requirement - Update error message to mention v0.48.x backport
1 parent 1df438a commit d35e59f

File tree

2 files changed

+7
-170
lines changed

2 files changed

+7
-170
lines changed

src/libtmux/common.py

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,49 +24,16 @@
2424

2525

2626
#: Minimum version of tmux required to run libtmux
27-
TMUX_MIN_VERSION = "1.8"
27+
TMUX_MIN_VERSION = "3.2a"
2828

2929
#: Most recent version of tmux supported
3030
TMUX_MAX_VERSION = "3.6"
3131

32-
#: Minimum version before deprecation warning is shown
33-
TMUX_SOFT_MIN_VERSION = "3.2a"
34-
3532
SessionDict = dict[str, t.Any]
3633
WindowDict = dict[str, t.Any]
3734
WindowOptionDict = dict[str, t.Any]
3835
PaneDict = dict[str, t.Any]
3936

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-
FutureWarning,
67-
stacklevel=4,
68-
)
69-
7037

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

337304
version = re.sub(r"[a-z-]", "", version)
338305

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

343308

344309
def has_version(version: str) -> bool:
@@ -422,7 +387,7 @@ def has_lt_version(max_version: str) -> bool:
422387

423388

424389
def has_minimum_version(raises: bool = True) -> bool:
425-
"""Return True if tmux meets version requirement. Version >1.8 or above.
390+
"""Return True if tmux meets version requirement. Version >= 3.2a.
426391
427392
Parameters
428393
----------
@@ -441,6 +406,9 @@ def has_minimum_version(raises: bool = True) -> bool:
441406
442407
Notes
443408
-----
409+
.. versionchanged:: 0.49.0
410+
Minimum version bumped to 3.2a. For older tmux, use libtmux v0.48.x.
411+
444412
.. versionchanged:: 0.7.0
445413
No longer returns version, returns True or False
446414
@@ -454,7 +422,7 @@ def has_minimum_version(raises: bool = True) -> bool:
454422
msg = (
455423
f"libtmux only supports tmux {TMUX_MIN_VERSION} and greater. This "
456424
f"system has {get_version()} installed. Upgrade your tmux to use "
457-
"libtmux."
425+
"libtmux, or use libtmux v0.48.x for older tmux versions."
458426
)
459427
raise exc.VersionTooLow(msg)
460428
return False

tests/test_common.py

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -508,134 +508,3 @@ def mock_get_version() -> LooseVersion:
508508
elif check_type == "type_check":
509509
assert mock_version is not None # For type checker
510510
assert isinstance(has_version(mock_version), bool)
511-
512-
513-
class VersionDeprecationFixture(t.NamedTuple):
514-
"""Test fixture for version deprecation warning."""
515-
516-
test_id: str
517-
version: str
518-
suppress_env: bool
519-
expected_warning: bool
520-
521-
522-
VERSION_DEPRECATION_FIXTURES: list[VersionDeprecationFixture] = [
523-
VersionDeprecationFixture(
524-
test_id="deprecated_version_warns",
525-
version="3.1",
526-
suppress_env=False,
527-
expected_warning=True,
528-
),
529-
VersionDeprecationFixture(
530-
test_id="old_deprecated_version_warns",
531-
version="2.9",
532-
suppress_env=False,
533-
expected_warning=True,
534-
),
535-
VersionDeprecationFixture(
536-
test_id="current_version_no_warning",
537-
version="3.2a",
538-
suppress_env=False,
539-
expected_warning=False,
540-
),
541-
VersionDeprecationFixture(
542-
test_id="newer_version_no_warning",
543-
version="3.5",
544-
suppress_env=False,
545-
expected_warning=False,
546-
),
547-
VersionDeprecationFixture(
548-
test_id="env_var_suppresses_warning",
549-
version="3.0",
550-
suppress_env=True,
551-
expected_warning=False,
552-
),
553-
]
554-
555-
556-
@pytest.mark.parametrize(
557-
list(VersionDeprecationFixture._fields),
558-
VERSION_DEPRECATION_FIXTURES,
559-
ids=[test.test_id for test in VERSION_DEPRECATION_FIXTURES],
560-
)
561-
def test_version_deprecation_warning(
562-
test_id: str,
563-
version: str,
564-
suppress_env: bool,
565-
expected_warning: bool,
566-
monkeypatch: pytest.MonkeyPatch,
567-
) -> None:
568-
"""Test version deprecation warning behavior."""
569-
import warnings
570-
571-
import libtmux.common
572-
573-
# Reset the warning flag for each test
574-
monkeypatch.setattr(libtmux.common, "_version_deprecation_checked", False)
575-
576-
# Set or clear the suppress env var
577-
if suppress_env:
578-
monkeypatch.setenv("LIBTMUX_SUPPRESS_VERSION_WARNING", "1")
579-
else:
580-
monkeypatch.delenv("LIBTMUX_SUPPRESS_VERSION_WARNING", raising=False)
581-
582-
with warnings.catch_warnings(record=True) as w:
583-
warnings.simplefilter("always")
584-
libtmux.common._check_deprecated_version(LooseVersion(version))
585-
586-
if expected_warning:
587-
assert len(w) == 1
588-
assert issubclass(w[0].category, FutureWarning)
589-
assert version in str(w[0].message)
590-
assert "3.2a" in str(w[0].message)
591-
else:
592-
assert len(w) == 0
593-
594-
595-
def test_version_deprecation_warns_once(monkeypatch: pytest.MonkeyPatch) -> None:
596-
"""Test that deprecation warning only fires once per process."""
597-
import warnings
598-
599-
import libtmux.common
600-
601-
monkeypatch.setattr(libtmux.common, "_version_deprecation_checked", False)
602-
monkeypatch.delenv("LIBTMUX_SUPPRESS_VERSION_WARNING", raising=False)
603-
604-
with warnings.catch_warnings(record=True) as w:
605-
warnings.simplefilter("always")
606-
libtmux.common._check_deprecated_version(LooseVersion("3.1"))
607-
libtmux.common._check_deprecated_version(LooseVersion("3.1"))
608-
609-
assert len(w) == 1
610-
611-
612-
def test_version_deprecation_via_get_version(monkeypatch: pytest.MonkeyPatch) -> None:
613-
"""Test deprecation warning fires through get_version() call.
614-
615-
This integration test verifies the warning is emitted when calling
616-
get_version() with an old tmux version, testing the full call chain.
617-
"""
618-
import warnings
619-
620-
import libtmux.common
621-
622-
class MockTmuxOutput:
623-
stdout: t.ClassVar = ["tmux 3.1"]
624-
stderr: t.ClassVar[list[str]] = []
625-
626-
def mock_tmux_cmd(*args: t.Any, **kwargs: t.Any) -> MockTmuxOutput:
627-
return MockTmuxOutput()
628-
629-
monkeypatch.setattr(libtmux.common, "_version_deprecation_checked", False)
630-
monkeypatch.setattr(libtmux.common, "tmux_cmd", mock_tmux_cmd)
631-
monkeypatch.delenv("LIBTMUX_SUPPRESS_VERSION_WARNING", raising=False)
632-
633-
with warnings.catch_warnings(record=True) as w:
634-
warnings.simplefilter("always")
635-
version = libtmux.common.get_version()
636-
637-
assert str(version) == "3.1"
638-
assert len(w) == 1
639-
assert issubclass(w[0].category, FutureWarning)
640-
assert "3.1" in str(w[0].message)
641-
assert "3.2a" in str(w[0].message)

0 commit comments

Comments
 (0)