Skip to content
Closed
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
42 changes: 39 additions & 3 deletions semver.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# -*- coding: utf-8 -*-

import re
Expand Down Expand Up @@ -68,7 +69,7 @@ def match(version, match_expr):
prefix = match_expr[:2]
if prefix in ('>=', '<=', '=='):
match_version = match_expr[2:]
elif prefix and prefix[0] in ('>', '<', '='):
elif prefix and prefix[0] in ('>', '<', '=', '~', '^'):
prefix = prefix[0]
match_version = match_expr[1:]
else:
Expand All @@ -81,13 +82,48 @@ def match(version, match_expr):
'<': (-1,),
'==': (0,),
'>=': (0, 1),
'<=': (-1, 0)
'<=': (-1, 0),
'~': (0, 1),
'^': (0, 1)
}

possibilities = possibilities_dict[prefix]

cmp_res = compare(version, match_version)

return cmp_res in possibilities
if prefix in ('^',):
if cmp_res in possibilities:
v = parse(match_version)
if v.get('major') is 0:
if v.get('minor') is 0:
cmp_res = compare(version, bump_patch(match_version))
if cmp_res in possibilities_dict['<']:
return True
else:
return False
else:
cmp_res = compare(version, bump_minor(match_version))
if cmp_res in possibilities_dict['<']:
return True
else:
return False
else:
cmp_res = compare(version, bump_major(match_version))
if cmp_res in possibilities_dict['<']:
return True
else:
return False
elif prefix in ('~',):
if cmp_res in possibilities:
cmp_res = compare(version, bump_minor(match_version))
if cmp_res in possibilities_dict['<']:
return True
else:
return False
else:
return False
else:
return cmp_res in possibilities


def max_ver(ver1, ver2):
Expand Down