Skip to content

Commit

Permalink
Merge branch 'master' of github.com:conda/conda
Browse files Browse the repository at this point in the history
  • Loading branch information
asmeurer committed Sep 2, 2015
2 parents 8cf9787 + ca93d5e commit d38aab0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 15 additions & 6 deletions conda/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,34 @@ def ver_eval(version, constraint):
constraint)


class VersionSpec(object):
class VersionSpecAtom(object):

def __init__(self, spec):
assert '|' not in spec
assert ',' not in spec
self.spec = spec
if spec.startswith(('=', '<', '>', '!')):
self.regex = False
self.constraints = spec.split(',')
else:
self.regex = True
rx = spec.replace('.', r'\.')
rx = rx.replace('*', r'.*')
rx = r'(%s)$' % rx
self.pat = re.compile(rx)
self.regex = re.compile(rx)

def match(self, version):
if self.regex:
return bool(self.pat.match(version))
return bool(self.regex.match(version))
else:
return all(ver_eval(version, c) for c in self.constraints)
return ver_eval(version, self.spec)

class VersionSpec(object):

def __init__(self, spec):
assert '|' not in spec
self.constraints = [VersionSpecAtom(vs) for vs in spec.split(',')]

def match(self, version):
return all(c.match(version) for c in self.constraints)


class MatchSpec(object):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def test_match(self):
('numpy >1.8,<2|==1.7', False),('numpy >1.8,<2|>=1.7.1', True),
('numpy >=1.8|1.7*', True), ('numpy ==1.7', False),
('numpy >=1.5,>1.6', True), ('numpy ==1.7.1', True),
('numpy >=1,*.7.*', True), ('numpy *.7.*,>=1', True),
('numpy >=1,*.8.*', False), ('numpy >=2,*.7.*', False),
('numpy 1.6*|1.7*', True), ('numpy 1.6*|1.8*', False),
('numpy 1.6.2|1.7*', True), ('numpy 1.6.2|1.7.1', True),
('numpy 1.6.2|1.7.0', False), ('numpy 1.7.1 py27_0', True),
Expand Down

0 comments on commit d38aab0

Please sign in to comment.