-
Notifications
You must be signed in to change notification settings - Fork 9
/
build_credit.py
92 lines (78 loc) · 2.32 KB
/
build_credit.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import os
import re
import json
import pathlib
from python_graphql_client import GraphqlClient
root = pathlib.Path(__file__).parent.resolve()
client = GraphqlClient(endpoint="https://api.github.com/graphql")
with open(f"{root}/credit.json", "r", encoding="utf-8") as credit_file:
credit = json.loads(credit_file.read())
TOKEN = os.environ.get("GITHUB_TOKEN", "")
def replace_chunk(content, marker, chunk, inline=False):
r = re.compile(
f"<!\-\- {marker} starts \-\->.*<!\-\- {marker} ends \-\->", re.DOTALL
)
if not inline:
chunk = f"\n{chunk}\n"
chunk = f"<!-- {marker} starts -->{chunk}<!-- {marker} ends -->"
return r.sub(chunk, content)
def fetch_mlf_denpendices():
dependencies = credit["MachineLearningFramework"]
return [
{
"name": _["name"],
"version": _["versionInfo"],
"license": _["license"],
"repo": _["repo"],
"licenseUrl": _["licenseUrl"],
"description": _["description"],
"icon": _["icon"],
}
for _ in dependencies
]
def fetch_cprf_denpendices():
dependencies = credit["RobotFramework"]
return [
{
"name": _["name"],
"version": _["versionInfo"],
"license": _["license"],
"repo": _["repo"],
"licenseUrl": _["licenseUrl"],
"description": _["description"],
"icon": _["icon"],
}
for _ in dependencies
]
if __name__ == "__main__":
readme = root / "credits.md"
readme_contents = readme.open().read()
# MLF
MLF = fetch_mlf_denpendices()
MLF_md = "\n\n".join(
[
"[{name}]({repo})({version}) with [{license}]({licenseUrl}). {icon} `{description}`".format(
**_
)
for _ in MLF
]
)
print()
print(MLF_md)
print()
rewritten = replace_chunk(readme_contents, "MLF", MLF_md)
# CPRF
CPRF = fetch_cprf_denpendices()
CPRF_md = "\n\n".join(
[
"[{name}]({repo})({version}) with [{license}]({licenseUrl}). {icon} `{description}`".format(
**_
)
for _ in CPRF
]
)
print()
print(CPRF_md)
print()
rewritten = replace_chunk(rewritten, "CPRF", CPRF_md)
readme.open("w").write(rewritten)