-
-
Notifications
You must be signed in to change notification settings - Fork 25.5k
/
generate_authors_table.py
255 lines (213 loc) · 7.99 KB
/
generate_authors_table.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
"""
This script generates an html table of contributors, with names and avatars.
The list is generated from scikit-learn's teams on GitHub, plus a small number
of hard-coded contributors.
The table should be updated for each new inclusion in the teams.
Generating the table requires admin rights.
"""
import getpass
import sys
import time
from os import path
from pathlib import Path
import requests
print("Input user:", file=sys.stderr)
user = input()
token = getpass.getpass("Input access token:\n")
auth = (user, token)
LOGO_URL = "https://avatars2.githubusercontent.com/u/365630?v=4"
REPO_FOLDER = Path(path.abspath(__file__)).parent.parent
def get(url):
for sleep_time in [10, 30, 0]:
reply = requests.get(url, auth=auth)
api_limit = (
"message" in reply.json()
and "API rate limit exceeded" in reply.json()["message"]
)
if not api_limit:
break
print("API rate limit exceeded, waiting..")
time.sleep(sleep_time)
reply.raise_for_status()
return reply
def get_contributors():
"""Get the list of contributor profiles. Require admin rights."""
# get core devs and contributor experience team
core_devs = []
documentation_team = []
contributor_experience_team = []
comm_team = []
core_devs_slug = "core-devs"
contributor_experience_team_slug = "contributor-experience-team"
comm_team_slug = "communication-team"
documentation_team_slug = "documentation-team"
entry_point = "https://api.github.com/orgs/scikit-learn/"
for team_slug, lst in zip(
(
core_devs_slug,
contributor_experience_team_slug,
comm_team_slug,
documentation_team_slug,
),
(core_devs, contributor_experience_team, comm_team, documentation_team),
):
print(f"Retrieving {team_slug}\n")
for page in [1, 2]: # 30 per page
reply = get(f"{entry_point}teams/{team_slug}/members?page={page}")
lst.extend(reply.json())
# get members of scikit-learn on GitHub
print("Retrieving members\n")
members = []
for page in [1, 2, 3]: # 30 per page
reply = get(f"{entry_point}members?page={page}")
members.extend(reply.json())
# keep only the logins
core_devs = set(c["login"] for c in core_devs)
documentation_team = set(c["login"] for c in documentation_team)
contributor_experience_team = set(c["login"] for c in contributor_experience_team)
comm_team = set(c["login"] for c in comm_team)
members = set(c["login"] for c in members)
# add missing contributors with GitHub accounts
members |= {"dubourg", "mbrucher", "thouis", "jarrodmillman"}
# add missing contributors without GitHub accounts
members |= {"Angel Soler Gollonet"}
# remove CI bots
members -= {"sklearn-ci", "sklearn-wheels", "sklearn-lgtm"}
contributor_experience_team -= (
core_devs # remove ogrisel from contributor_experience_team
)
emeritus = (
members
- core_devs
- contributor_experience_team
- comm_team
- documentation_team
)
# hard coded
emeritus_contributor_experience_team = {
"cmarmo",
}
emeritus_comm_team = {"reshamas"}
# Up-to-now, we can subtract the team emeritus from the original emeritus
emeritus -= emeritus_contributor_experience_team | emeritus_comm_team
comm_team -= {"reshamas"} # in the comm team but not on the web page
# get profiles from GitHub
core_devs = [get_profile(login) for login in core_devs]
emeritus = [get_profile(login) for login in emeritus]
contributor_experience_team = [
get_profile(login) for login in contributor_experience_team
]
emeritus_contributor_experience_team = [
get_profile(login) for login in emeritus_contributor_experience_team
]
comm_team = [get_profile(login) for login in comm_team]
emeritus_comm_team = [get_profile(login) for login in emeritus_comm_team]
documentation_team = [get_profile(login) for login in documentation_team]
# sort by last name
core_devs = sorted(core_devs, key=key)
emeritus = sorted(emeritus, key=key)
contributor_experience_team = sorted(contributor_experience_team, key=key)
emeritus_contributor_experience_team = sorted(
emeritus_contributor_experience_team, key=key
)
documentation_team = sorted(documentation_team, key=key)
comm_team = sorted(comm_team, key=key)
emeritus_comm_team = sorted(emeritus_comm_team, key=key)
return (
core_devs,
emeritus,
contributor_experience_team,
emeritus_contributor_experience_team,
comm_team,
emeritus_comm_team,
documentation_team,
)
def get_profile(login):
"""Get the GitHub profile from login"""
print("get profile for %s" % (login,))
try:
profile = get("https://api.github.com/users/%s" % login).json()
except requests.exceptions.HTTPError:
return dict(name=login, avatar_url=LOGO_URL, html_url="")
if profile["name"] is None:
profile["name"] = profile["login"]
# fix missing names
missing_names = {
"bthirion": "Bertrand Thirion",
"dubourg": "Vincent Dubourg",
"Duchesnay": "Edouard Duchesnay",
"Lars": "Lars Buitinck",
"MechCoder": "Manoj Kumar",
}
if profile["name"] in missing_names:
profile["name"] = missing_names[profile["name"]]
return profile
def key(profile):
"""Get a sorting key based on the lower case last name, then firstname"""
components = profile["name"].lower().split(" ")
return " ".join([components[-1]] + components[:-1])
def generate_table(contributors):
lines = [
".. raw :: html\n",
" <!-- Generated by generate_authors_table.py -->",
' <div class="sk-authors-container">',
" <style>",
" img.avatar {border-radius: 10px;}",
" </style>",
]
for contributor in contributors:
lines.append(" <div>")
lines.append(
" <a href='%s'><img src='%s' class='avatar' /></a> <br />"
% (contributor["html_url"], contributor["avatar_url"])
)
lines.append(" <p>%s</p>" % (contributor["name"],))
lines.append(" </div>")
lines.append(" </div>")
return "\n".join(lines) + "\n"
def generate_list(contributors):
lines = []
for contributor in contributors:
lines.append("- %s" % (contributor["name"],))
return "\n".join(lines) + "\n"
if __name__ == "__main__":
(
core_devs,
emeritus,
contributor_experience_team,
emeritus_contributor_experience_team,
comm_team,
emeritus_comm_team,
documentation_team,
) = get_contributors()
print("Generating rst files")
with open(
REPO_FOLDER / "doc" / "maintainers.rst", "w+", encoding="utf-8"
) as rst_file:
rst_file.write(generate_table(core_devs))
with open(
REPO_FOLDER / "doc" / "maintainers_emeritus.rst", "w+", encoding="utf-8"
) as rst_file:
rst_file.write(generate_list(emeritus))
with open(
REPO_FOLDER / "doc" / "contributor_experience_team.rst", "w+", encoding="utf-8"
) as rst_file:
rst_file.write(generate_table(contributor_experience_team))
with open(
REPO_FOLDER / "doc" / "contributor_experience_team_emeritus.rst",
"w+",
encoding="utf-8",
) as rst_file:
rst_file.write(generate_list(emeritus_contributor_experience_team))
with open(
REPO_FOLDER / "doc" / "communication_team.rst", "w+", encoding="utf-8"
) as rst_file:
rst_file.write(generate_table(comm_team))
with open(
REPO_FOLDER / "doc" / "communication_team_emeritus.rst", "w+", encoding="utf-8"
) as rst_file:
rst_file.write(generate_list(emeritus_comm_team))
with open(
REPO_FOLDER / "doc" / "documentation_team.rst", "w+", encoding="utf-8"
) as rst_file:
rst_file.write(generate_table(documentation_team))