diff --git a/deluge/common.py b/deluge/common.py index 64d76b685..aef5a3d3c 100644 --- a/deluge/common.py +++ b/deluge/common.py @@ -992,25 +992,27 @@ class VersionSplit(object): self.version = [int(x) for x in vs[0].split('.') if x.isdigit()] self.version_string = ''.join(str(x) for x in vs[0].split('.') if x.isdigit()) self.suffix = None - self.dev = False + self.dev = None if len(vs) > 1: if vs[1].startswith(('rc', 'a', 'b', 'c')): self.suffix = vs[1] if vs[-1].startswith('dev'): - self.dev = vs[-1] + try: + # Store only the dev numeral. + self.dev = int(vs[-1].rsplit('dev')[1]) + except ValueError: + # Implicit dev numeral is 0. + self.dev = 0 def get_comparable_versions(self, other): """ Returns a 2-tuple of lists for use in the comparison methods. """ - # PEP 386 versions with .devN precede release version - if bool(self.dev) != bool(other.dev): - if self.dev != 'dev': - self.dev = not self.dev - if other.dev != 'dev': - other.dev = not other.dev - + # PEP 386 versions with .devN precede release version so default + # non-dev versions to infinity while dev versions are ints. + self.dev = float('inf') if self.dev is None else self.dev + other.dev = float('inf') if other.dev is None else other.dev # If there is no suffix we use z because we want final # to appear after alpha, beta, and rc alphabetically. v1 = [self.version, self.suffix or 'z', self.dev] diff --git a/deluge/tests/test_common.py b/deluge/tests/test_common.py index 404a6c405..846783166 100644 --- a/deluge/tests/test_common.py +++ b/deluge/tests/test_common.py @@ -99,10 +99,10 @@ class CommonTestCase(unittest.TestCase): self.assertTrue(VersionSplit('1.2.1') < VersionSplit('1.2.2')) self.assertTrue(VersionSplit('1.1.9') < VersionSplit('1.2.2')) self.assertTrue(VersionSplit('1.2.2') > VersionSplit('1.2.1')) - self.assertTrue(VersionSplit('1.2.2') < VersionSplit('1.2.2-dev')) + self.assertTrue(VersionSplit('1.2.2') > VersionSplit('1.2.2-dev0')) self.assertTrue(VersionSplit('1.2.2-dev') < VersionSplit('1.3.0-rc2')) self.assertTrue(VersionSplit('1.2.2') > VersionSplit('1.2.2-rc2')) - self.assertTrue(VersionSplit('1.2.2-rc2-dev') > VersionSplit('1.2.2-rc2')) + self.assertTrue(VersionSplit('1.2.2-rc2-dev') < VersionSplit('1.2.2-rc2')) self.assertTrue(VersionSplit('1.2.2-rc3') > VersionSplit('1.2.2-rc2')) self.assertTrue(VersionSplit('0.14.9') == VersionSplit('0.14.9')) self.assertTrue(VersionSplit('0.14.9') > VersionSplit('0.14.5'))