-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathcheck_metadata.py
More file actions
64 lines (45 loc) · 1.44 KB
/
check_metadata.py
File metadata and controls
64 lines (45 loc) · 1.44 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import configparser
import re
import sys
def read_setup_cfg():
config = configparser.ConfigParser()
config.read("setup.cfg")
return {
"name": config.get("metadata", "name", fallback=None),
"version": config.get("metadata", "version", fallback=None),
}
def read_setup_py():
with open("setup.py", "r") as f:
content = f.read()
name_match = re.search(r"name\s*=\s*['\"](.+?)['\"]", content)
return {
"name": name_match.group(1) if name_match else None,
}
def read_version_file():
with open("metaflow/version.py", "r") as f:
line = f.read().splitlines()[0]
version = line.split("=")[1].strip(" \"'")
return version
def main():
cfg = read_setup_cfg()
py = read_setup_py()
version = read_version_file()
errors = []
# Compare package name
if cfg["name"] and py["name"] and cfg["name"] != py["name"]:
errors.append(
f"Name mismatch: setup.cfg='{cfg['name']}' vs setup.py='{py['name']}'"
)
# Compare version
if cfg["version"] and version and cfg["version"] != version:
errors.append(
f"Version mismatch: setup.cfg='{cfg['version']}' vs version.py='{version}'"
)
if errors:
print(" Metadata consistency check FAILED:\n")
for err in errors:
print(f"- {err}")
sys.exit(1)
print(" Metadata consistency check PASSED")
if __name__ == "__main__":
main()