-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.py
97 lines (77 loc) · 2.7 KB
/
build.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
93
94
95
96
97
#!/usr/bin/env python3
from typing import List
import json
import click
import os
def format_entry(a):
entry = "**"
if 'displayname' in a:
entry += a['displayname']
if 'affiliation' in a:
entry += " (%s)" % a['affiliation']
entry += "**"
if 'orcid' in a:
entry += " [ORCID](https://orcid.org/%s)" % a['orcid']
if 'github' in a:
entry += " [GitHub](https://github.com/%s)" % a['github']
if 'contribution' in a:
entry += "\n: %s" % a['contribution']
entry += "\n\n"
return entry
INTRO = """
# Acknowledgements
We are very grateful for your continuing support for LiberTEM!
Please help us keeping these lists up-to-date and complete! If you feel that
you should be listed here, please contact us or open a pull request.
We are grateful for every contribution, and if your contribution
is not listed here we'd like to extend our apologies and update
this as soon as possible.
"""
@click.command()
@click.option(
'--project',
type=click.Path(file_okay=False, dir_okay=True),
multiple=True,
)
@click.option(
'--out',
type=click.File('w', encoding='utf-8'),
default='acknowledgements.md',
)
def main(project: List[click.Path], out: click.File):
def author(d):
return d['authorname']
out.write("---\ntitle: Acknowledgements\n---\n")
out.write(INTRO)
out.write("## Jump to project\n")
for p in project:
p_basename = os.path.basename(os.path.normpath(p))
out.write(f"- [{p_basename}](#{p_basename.lower()})\n")
out.write('\n\n')
for p in project:
p_basename = os.path.basename(os.path.normpath(p))
creators = os.path.join(p, 'packaging', 'creators.json')
with open(creators, "r") as f:
creators_list = sorted(json.load(f), key=author)
contributors = os.path.join(p, 'packaging', 'contributors.json')
with open(contributors, 'r') as f:
contributors_list = sorted(json.load(f), key=author)
out.write(f'## {p_basename}\n\n')
out.write('### Creators\n')
out.write(
'The following people in alphabetical order contributed to'
' source code, documentation, design and management '
'following our [Authorship Policy]'
'(https://libertem.github.io/LiberTEM/authorship.html)\n\n'
)
for c in creators_list:
out.write(format_entry(c))
out.write('## Contributors\n')
out.write(
f'The following people in alphabetical order contributed to '
f'the {p_basename} project in other ways.\n\n'
)
for c in contributors_list:
out.write(format_entry(c))
if __name__ == '__main__':
main()