-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #201 from epics-containers/semver-compare
Add semver comparrison
- Loading branch information
Showing
4 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import operator | ||
|
||
from semantic_version import Version | ||
|
||
|
||
def semver_compare(base: str, target: str) -> bool: | ||
""" | ||
Compare two semVer strings similarly to pip's requirements specifier syntax | ||
""" | ||
ops = { | ||
">=": operator.ge, | ||
"<=": operator.le, | ||
"==": operator.eq, | ||
">": operator.gt, | ||
"<": operator.lt, | ||
} | ||
for op in ops.keys(): | ||
if op in target: | ||
in_op = op | ||
target = target.strip(op) | ||
break | ||
|
||
if ops[in_op](Version.coerce(base), Version.coerce(target)): | ||
return True | ||
else: | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters