Skip to content

Commit f9fd3cb

Browse files
minijacksontony
authored andcommitted
Fix error when using is_version with lettered tmux version (#22)
* Fix error when using is_version with lettered tmux version is_version('something') fails with installed tmux 1.9a To allow tmux-python/tmuxp#197 ;-) * Parse versions before comparing them in is_version * Add is_version tests with lettered tmux versions * Use LooseVersion instead of StrictVersion
1 parent cfbaabe commit f9fd3cb

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

libtmux/common.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import os
1111
import re
1212
import subprocess
13-
from distutils.version import StrictVersion
13+
from distutils.version import StrictVersion, LooseVersion
1414

1515
from . import exc
1616
from ._compat import console_to_str
@@ -387,7 +387,7 @@ def is_version(version):
387387

388388
installed_version = proc.stdout[0].split('tmux ')[1]
389389

390-
return StrictVersion(installed_version) == StrictVersion(version)
390+
return LooseVersion(installed_version) == LooseVersion(version)
391391

392392

393393
def has_required_tmux_version(version=None):

tests/test_common.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import pytest
77

8-
from libtmux.common import has_required_tmux_version, which, session_check_name
8+
from libtmux.common import has_required_tmux_version, which, session_check_name, is_version
99
from libtmux.exc import LibTmuxException, BadSessionName
1010

1111
version_regex = re.compile(r'[0-9]\.[0-9]')
@@ -32,6 +32,10 @@ def test_ignores_letter_versions():
3232
result = has_required_tmux_version('1.8a')
3333
assert result == r'1.8'
3434

35+
# Should not throw
36+
assert type(is_version('1.8')) is bool
37+
assert type(is_version('1.8a')) is bool
38+
assert type(is_version('1.9a')) is bool
3539

3640
def test_error_version_less_1_7():
3741
with pytest.raises(LibTmuxException) as excinfo:

0 commit comments

Comments
 (0)