Skip to content

Commit 83872e6

Browse files
committed
Use packaging
1 parent 0ee20cf commit 83872e6

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/libtmux/_compat.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,9 @@ def str_from_console(s: t.Union[str, bytes]) -> str:
3131
return str(s)
3232
except UnicodeDecodeError:
3333
return str(s, encoding="utf_8") if isinstance(s, bytes) else s
34+
35+
36+
try:
37+
from packaging.version import LegacyVersion as LooseVersion, Version # type: ignore
38+
except ImportError:
39+
from distutils.version import LooseVersion, Version

src/libtmux/common.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import subprocess
1212
import sys
1313
import typing as t
14-
from distutils.version import LooseVersion
1514
from typing import Dict, Generic, KeysView, List, Optional, TypeVar, Union, overload
1615

1716
from . import exc
@@ -25,6 +24,9 @@
2524
from libtmux.window import Window
2625

2726

27+
from . import exc
28+
from ._compat import LooseVersion, console_to_str, str_from_console
29+
2830
logger = logging.getLogger(__name__)
2931

3032

@@ -273,7 +275,7 @@ def __init__(self, *args: t.Any, **kwargs: t.Any) -> None:
273275

274276
# class TmuxMappingObject(t.Mapping[str, t.Union[str,int,bool]]):
275277
class TmuxMappingObject(t.Mapping[t.Any, t.Any]):
276-
r"""Base: :py:class:`MutableMapping`.
278+
r"""Base: :py:class:`typing.Mapping`.
277279
278280
Convenience container. Base class for :class:`Pane`, :class:`Window`,
279281
:class:`Session` and :class:`Server`.

tests/test_common.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import re
44
import sys
55
import typing as t
6-
from distutils.version import LooseVersion
76
from typing import Optional
87

98
import pytest
109

1110
import libtmux
11+
from libtmux._compat import LooseVersion
1212
from libtmux.common import (
1313
TMUX_MAX_VERSION,
1414
TMUX_MIN_VERSION,
@@ -43,7 +43,7 @@ def mock_tmux_cmd(*args: t.Any, **kwargs: t.Any) -> Hi:
4343
assert has_gte_version(TMUX_MIN_VERSION)
4444
assert has_gt_version(TMUX_MAX_VERSION), "Greater than the max-supported version"
4545
assert (
46-
"%s-master" % TMUX_MAX_VERSION == get_version()
46+
LooseVersion("%s-master" % TMUX_MAX_VERSION) == get_version()
4747
), "Is the latest supported version with -master appended"
4848

4949

@@ -63,6 +63,7 @@ def mock_tmux_cmd(*args: t.Any, **kwargs: t.Any) -> Hi:
6363
assert has_gte_version(TMUX_MIN_VERSION)
6464
assert has_gt_version(TMUX_MAX_VERSION), "Greater than the max-supported version"
6565
assert TMUX_NEXT_VERSION == get_version()
66+
assert LooseVersion("2.9") == get_version()
6667

6768

6869
def test_get_version_openbsd(monkeypatch: pytest.MonkeyPatch) -> None:
@@ -78,7 +79,7 @@ def mock_tmux_cmd(*args: t.Any, **kwargs: t.Any) -> Hi:
7879
assert has_gte_version(TMUX_MIN_VERSION)
7980
assert has_gt_version(TMUX_MAX_VERSION), "Greater than the max-supported version"
8081
assert (
81-
"%s-openbsd" % TMUX_MAX_VERSION == get_version()
82+
LooseVersion("%s-openbsd" % TMUX_MAX_VERSION) == get_version()
8283
), "Is the latest supported version with -openbsd appended"
8384

8485

0 commit comments

Comments
 (0)