forked from fortran-lang/fpm-registry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfpm_validate.py
66 lines (49 loc) · 2.12 KB
/
fpm_validate.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def check_registry_entry(name,version,entry,dump=True):
"""Checks registry toml entry"""
if not isinstance(entry, dict):
raise Exception(f"registry.toml: unexpected format for package "
+ f"'{name}-{version}', entry:\n {entry}")
if dump:
print(f"Package: {name} Version: {version}")
# Required keys
for key in ["git"]:
if key not in entry:
raise Exception(f"registry.toml: missing required key "
+ f"'{key}' for package '{name}-{version}'")
# Exactly one reference (tag/commit) is required for versioned entries
if version != "latest" and sum(k in entry for k in ["tag"]) != 1:
raise Exception(f"registry.toml: versioned package '{name}-{version}'"
+ f" does not have a git reference (tag/commit)")
if dump:
print(" git:", entry["git"])
if "tag" in entry:
print(" tag:", entry["tag"])
def check_fpm_toml(contents):
"""Checks contents of fpm.toml, returns cut-down version for json index"""
import toml
p = toml.loads(contents)
fpm_info = {}
# Must be present, copied to json
required_keys = ["name", "version", "license", "author",
"maintainer", "copyright"]
# Optionally present, copied to json
optional_keys = ["description", "executable", "dependencies",
"dev-dependencies"]
# Optionally present, not copied to json
other_keys = ["test", "library", "build", "extra"]
# Check for required keys
for key in required_keys:
if key not in p:
raise Exception(f"Missing required key '{key}' in fpm.toml.")
for key in p.keys():
if key not in required_keys + optional_keys + other_keys:
print(f" (!) Warning: unexpected key '{key}; in fpm.toml")
# Copy keys to dict for json index
for key in required_keys:
fpm_info[key] = p[key]
for key in optional_keys:
if key in p:
fpm_info[key] = p[key]
else:
fpm_info[key] = None
return fpm_info