-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversioning.py
More file actions
43 lines (39 loc) · 1.2 KB
/
Copy pathversioning.py
File metadata and controls
43 lines (39 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Versioning for PPM
Versions are just one number
MUST be increasing, never decreases
Version spec format:
package==version: Package is EXACTLY version
package<=version: Package is less than or equal to version
package=<version: Same as <=
package>=version: Package is greater than or equal to version
package=>version: Same as >=
package<<version: Package is less than version
package>>version: Package is greater than version
"""
class VersionError(ValueError):
"""An error with the version of a package."""
pass
class VersionSpecError(VersionError):
"""An error with the spec of a version comparison."""
pass
def _check(a,b,c):
match c:
case "=":
return a==b
case ">":
return a>b
case "<":
return a<b
case _:
raise VersionSpecError(f"Invalid character: {c}")
def check(a: int, b: int, spec: str) -> bool:
"""Parse and check a version
a: The package's version
b: The wanted version
spec: The two-character comparison
"""
if len(spec) != 2:
raise VersionSpecError(f"Invalid version spec: {spec}")
if spec[0]==spec[1]:
return _check(a,b,spec[0])
return _check(a,b,spec[0]) or _check(a,b,spec[1])