Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ testing =
pytest-xdist >= 2
aboutcode-toolkit >= 6.0.0
black
commoncode

docs =
Sphinx >= 3.3.1
Expand Down
38 changes: 36 additions & 2 deletions src/univers/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from functools import total_ordering
import functools
import re

import attr
import semantic_version
Expand Down Expand Up @@ -385,6 +384,19 @@ class LegacyOpensslVersion(Version):
univers.versions.InvalidVersion: '3.0.2' is not a valid <class 'univers.versions.LegacyOpensslVersion'>
"""

major = attr.ib(type=int, default=None, repr=False)
minor = attr.ib(type=int, default=None, repr=False)
build = attr.ib(type=int, default=None, repr=False)
patch = attr.ib(type=str, default=None, repr=False)

def __attrs_post_init__(self):
super().__attrs_post_init__()
major, minor, build, patch = self.value
object.__setattr__(self, "major", major)
object.__setattr__(self, "minor", minor)
object.__setattr__(self, "build", build)
object.__setattr__(self, "patch", patch)

Comment thread
pombredanne marked this conversation as resolved.
@classmethod
def is_valid(cls, string):
return bool(cls.parse(string))
Expand Down Expand Up @@ -445,7 +457,29 @@ def build_value(cls, string):
return cls.parse(string)

def __str__(self):
return f"{self.value[0]}.{self.value[1]}.{self.value[2]}{self.value[3]}"
return f"{self.major}.{self.minor}.{self.build}{self.patch}"

def __lt__(self, other):
if not isinstance(other, self.__class__):
return NotImplemented
# Check if versions have the same base, and `one and only one` of them is a pre-release.
if (self.major, self.minor, self.build) == (other.major, other.minor, other.build) and (
self.is_prerelease() != other.is_prerelease()
):
return self.is_prerelease()
return self.value.__lt__(other.value)

def __gt__(self, other):
if not isinstance(other, self.__class__):
return NotImplemented
if (self.major, self.minor, self.build) == (other.major, other.minor, other.build) and (
self.is_prerelease() != other.is_prerelease()
):
return other.is_prerelease()
return self.value.__gt__(other.value)

def is_prerelease(self):
return self.patch.startswith(("-beta", "-alpha"))


@attr.s(frozen=True, order=False, eq=False, hash=True)
Expand Down
172 changes: 172 additions & 0 deletions tests/data/openssl/openssl_all_versions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
3.0.0
3.0.1
1.1.1
1.1.1a
1.1.1b
1.1.1c
1.1.1d
1.1.1e
1.1.1f
1.1.1g
1.1.1h
1.1.1i
1.1.1j
1.1.1k
1.1.1l
1.1.1m
1.0.2
1.0.2a
1.0.2b
1.0.2c
1.0.2d
1.0.2e
1.0.2f
1.0.2g
1.0.2h
1.0.2i
1.0.2j
1.0.2k
1.0.2l
1.0.2m
1.0.2n
1.0.2o
1.0.2p
1.0.2q
1.0.2r
1.0.2s
1.0.2t
1.0.2u
1.0.2v
1.0.2w
1.0.2x
1.0.2y
1.0.2za
1.0.2zb
1.0.2zc
3.0.2
1.1.1n
1.0.2zd
1.0.2zc-dev
1.1.0
1.1.0a
1.1.0b
1.1.0c
1.1.0d
1.1.0e
1.1.0f
1.1.0g
1.1.0h
1.1.0i
1.1.0j
1.1.0k
1.1.0l
1.0.1
1.0.1a
1.0.1b
1.0.1c
1.0.1d
1.0.1e
1.0.1f
1.0.1g
1.0.1h
1.0.1i
1.0.1j
1.0.1k
1.0.1l
1.0.1m
1.0.1n
1.0.1o
1.0.1p
1.0.1q
1.0.1r
1.0.1s
1.0.1t
1.0.1u
0.9.8
0.9.8a
0.9.8b
0.9.8c
0.9.8d
0.9.8e
0.9.8f
0.9.8g
0.9.8h
0.9.8i
0.9.8j
0.9.8k
0.9.8l
0.9.8m
0.9.8n
0.9.8o
0.9.8p
0.9.8q
0.9.8r
0.9.8s
0.9.8t
0.9.8u
0.9.8v
0.9.8w
0.9.8x
0.9.8y
0.9.8za
0.9.8zb
0.9.8zc
0.9.8zd
0.9.8ze
1.0.0
1.0.0a
1.0.0b
1.0.0c
1.0.0d
1.0.0e
1.0.0f
1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