-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin_version_commit_hook.py
44 lines (34 loc) · 1.38 KB
/
plugin_version_commit_hook.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
39
40
41
42
43
44
import argparse
import tomllib
from monkeytypes import AgentPluginManifest
import yaml
from pathlib import Path
def main():
parser = argparse.ArgumentParser()
parser.add_argument("filenames", nargs="*")
args = parser.parse_args()
if (
"manifest.yaml" in args.filenames
or "manifest.yml" in args.filenames
or "pyproject.toml" in args.filenames
):
pyproject_version = read_pyproject_toml_version()
agent_plugin_manifest_version = read_agent_plugin_manifest_version(args.filenames)
if pyproject_version != agent_plugin_manifest_version:
print(
"AgentPluginManifest version does not match pyproject.toml version: "
f"{agent_plugin_manifest_version} != {pyproject_version}"
)
exit(1)
def read_agent_plugin_manifest_version(filenames) -> str:
for filename in filenames:
if filename in ["manifest.yaml", "manifest.yml"]:
if Path(filename).exists():
with open(filename, "r") as f:
return AgentPluginManifest(**yaml.safe_load(f)).version
raise FileNotFoundError("Neither manifest.yaml nor manifest.yml was found")
def read_pyproject_toml_version() -> str:
with open("pyproject.toml", "rb") as f:
return tomllib.load(f)["tool"]["poetry"]["version"].strip(" v")
if __name__ == "__main__":
main()