diff options
Diffstat (limited to 'src/semantic_version/base.py')
-rw-r--r-- | src/semantic_version/base.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/semantic_version/base.py b/src/semantic_version/base.py index 16a1404..67ffe92 100644 --- a/src/semantic_version/base.py +++ b/src/semantic_version/base.py @@ -127,8 +127,8 @@ class Version(object): return version def __repr__(self): - return '<%sSemVer(%s, %s, %s, %r, %r)>' % ( - '~' if self.partial else '', + return '<%sVersion(%s, %s, %s, %r, %r)>' % ( + ', partial=True' if self.partial else '', self.major, self.minor, self.patch, @@ -311,6 +311,19 @@ class Spec(object): """Check whether a Version satisfies the Spec.""" return all(spec.match(version) for spec in self.specs) + def filter(self, versions): + """Filter an iterable of versions satisfying the Spec.""" + for version in versions: + if self.match(version): + yield version + + def select(self, versions): + """Select the best compatible version among an iterable of options.""" + options = list(self.filter(versions)) + if options: + return max(options) + return None + def __contains__(self, version): if isinstance(version, Version): return self.match(version) |