summaryrefslogtreecommitdiff
path: root/pip/_vendor/distlib/version.py
diff options
context:
space:
mode:
Diffstat (limited to 'pip/_vendor/distlib/version.py')
-rw-r--r--pip/_vendor/distlib/version.py35
1 files changed, 29 insertions, 6 deletions
diff --git a/pip/_vendor/distlib/version.py b/pip/_vendor/distlib/version.py
index a2192274c..f0e62c4ee 100644
--- a/pip/_vendor/distlib/version.py
+++ b/pip/_vendor/distlib/version.py
@@ -181,7 +181,7 @@ class Matcher(object):
return self._string
-PEP426_VERSION_RE = re.compile(r'^(\d+\.\d+(\.\d+)*)((a|b|c|rc)(\d+))?'
+PEP426_VERSION_RE = re.compile(r'^(\d+(\.\d+)*)((a|b|c|rc)(\d+))?'
r'(\.(post)(\d+))?(\.(dev)(\d+))?'
r'(-(\d+(\.\d+)?))?$')
@@ -297,7 +297,22 @@ class NormalizedMatcher(Matcher):
'!=': '_match_ne',
}
+ def _adjust_local(self, version, constraint, prefix):
+ if prefix:
+ strip_local = '-' not in constraint and version._parts[-1]
+ else:
+ # both constraint and version are
+ # NormalizedVersion instances.
+ # If constraint does not have a local component,
+ # ensure the version doesn't, either.
+ strip_local = not constraint._parts[-1] and version._parts[-1]
+ if strip_local:
+ s = version._string.split('-', 1)[0]
+ version = self.version_class(s)
+ return version, constraint
+
def _match_lt(self, version, constraint, prefix):
+ version, constraint = self._adjust_local(version, constraint, prefix)
if version >= constraint:
return False
release_clause = constraint._release_clause
@@ -305,6 +320,7 @@ class NormalizedMatcher(Matcher):
return not _match_prefix(version, pfx)
def _match_gt(self, version, constraint, prefix):
+ version, constraint = self._adjust_local(version, constraint, prefix)
if version <= constraint:
return False
release_clause = constraint._release_clause
@@ -312,12 +328,15 @@ class NormalizedMatcher(Matcher):
return not _match_prefix(version, pfx)
def _match_le(self, version, constraint, prefix):
+ version, constraint = self._adjust_local(version, constraint, prefix)
return version <= constraint
def _match_ge(self, version, constraint, prefix):
+ version, constraint = self._adjust_local(version, constraint, prefix)
return version >= constraint
def _match_eq(self, version, constraint, prefix):
+ version, constraint = self._adjust_local(version, constraint, prefix)
if not prefix:
result = (version == constraint)
else:
@@ -325,6 +344,7 @@ class NormalizedMatcher(Matcher):
return result
def _match_ne(self, version, constraint, prefix):
+ version, constraint = self._adjust_local(version, constraint, prefix)
if not prefix:
result = (version != constraint)
else:
@@ -332,6 +352,7 @@ class NormalizedMatcher(Matcher):
return result
def _match_compatible(self, version, constraint, prefix):
+ version, constraint = self._adjust_local(version, constraint, prefix)
if version == constraint:
return True
if version < constraint:
@@ -569,13 +590,15 @@ class LegacyVersion(Version):
def parse(self, s):
return _legacy_key(s)
- PREREL_TAGS = set(
- ['*a', '*alpha', '*b', '*beta', '*c', '*rc', '*r', '*@', '*pre']
- )
-
@property
def is_prerelease(self):
- return any(x in self.PREREL_TAGS for x in self._parts)
+ result = False
+ for x in self._parts:
+ if (isinstance(x, string_types) and x.startswith('*') and
+ x < '*final'):
+ result = True
+ break
+ return result
class LegacyMatcher(Matcher):