-
Notifications
You must be signed in to change notification settings - Fork 11
/
check_version.py
38 lines (26 loc) · 1022 Bytes
/
check_version.py
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
#!/usr/bin/env python3
import argparse
from pathlib import Path
import toml
def operation(path_toml: Path, path_py: Path) -> None:
with path_toml.open() as inf:
pyproject = toml.load(inf)
pyproject_version = pyproject["tool"]["poetry"]["version"]
bunkai_version: str = ""
with path_py.open() as inf:
for line in inf:
if line.startswith("__version_info__ ="):
bunkai_version = ".".join([d.strip() for d in line.strip().split("(")[-1][:-1].split(",")])
break
if pyproject_version != bunkai_version:
raise KeyError(f"Version mismatch: {pyproject_version} != {bunkai_version}")
def get_opts() -> argparse.Namespace:
oparser = argparse.ArgumentParser()
oparser.add_argument("--toml", type=Path, required=True)
oparser.add_argument("--py", type=Path, required=True)
return oparser.parse_args()
def main() -> None:
opts = get_opts()
operation(opts.toml, opts.py)
if __name__ == "__main__":
main()