Skip to content

Commit 311686e

Browse files
committed
STY: ruff format and ruff --fix [git-blame-ignore-rev]
1 parent 9ecd820 commit 311686e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2580
-2599
lines changed

.maint/paper_author_list.py

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env python3
22
"""Generate an author list for a new paper or abstract."""
3+
import json
34
import sys
45
from pathlib import Path
5-
import json
6-
from update_zenodo import get_git_lines, sort_contributors
76

7+
from update_zenodo import get_git_lines, sort_contributors
88

99
# These authors should go last
1010
AUTHORS_LAST = ['Gorgolewski, Krzysztof J.', 'Poldrack, Russell A.', 'Esteban, Oscar']
@@ -21,9 +21,11 @@ def _aslist(inlist):
2121
contribs = json.loads(Path('.maint/contributors.json').read_text())
2222

2323
author_matches, unmatched = sort_contributors(
24-
devs + contribs, get_git_lines(),
24+
devs + contribs,
25+
get_git_lines(),
2526
exclude=json.loads(Path('.maint/former.json').read_text()),
26-
last=AUTHORS_LAST)
27+
last=AUTHORS_LAST,
28+
)
2729
# Remove position
2830
affiliations = []
2931
for item in author_matches:
@@ -32,18 +34,34 @@ def _aslist(inlist):
3234
if a not in affiliations:
3335
affiliations.append(a)
3436

35-
aff_indexes = [', '.join(['%d' % (affiliations.index(a) + 1)
36-
for a in _aslist(author.get('affiliation', 'Unaffiliated'))])
37-
for author in author_matches]
37+
aff_indexes = [
38+
', '.join(
39+
[
40+
'%d' % (affiliations.index(a) + 1)
41+
for a in _aslist(author.get('affiliation', 'Unaffiliated'))
42+
]
43+
)
44+
for author in author_matches
45+
]
3846

39-
print("Some people made commits, but are missing in .maint/ "
40-
"files: %s." % ', '.join(unmatched), file=sys.stderr)
47+
print(
48+
'Some people made commits, but are missing in .maint/ '
49+
'files: %s.' % ', '.join(unmatched),
50+
file=sys.stderr,
51+
)
4152

4253
print('Authors (%d):' % len(author_matches))
43-
print("%s." % '; '.join([
44-
'%s \\ :sup:`%s`\\ ' % (i['name'], idx)
45-
for i, idx in zip(author_matches, aff_indexes)
46-
]))
54+
print(
55+
'%s.'
56+
% '; '.join(
57+
[
58+
'%s \\ :sup:`%s`\\ ' % (i['name'], idx)
59+
for i, idx in zip(author_matches, aff_indexes, strict=False)
60+
]
61+
)
62+
)
4763

48-
print('\n\nAffiliations:\n%s' % '\n'.join(['{0: >2}. {1}'.format(i + 1, a)
49-
for i, a in enumerate(affiliations)]))
64+
print(
65+
'\n\nAffiliations:\n%s'
66+
% '\n'.join([f'{i + 1: >2}. {a}' for i, a in enumerate(affiliations)])
67+
)

.maint/update_authors.py

Lines changed: 71 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/bin/env python3
22
"""Update and sort the creators list of the zenodo record."""
3+
import json
34
import sys
45
from pathlib import Path
5-
import json
6+
67
import click
78
from fuzzywuzzy import fuzz, process
89

@@ -35,44 +36,35 @@ def read_md_table(md_text):
3536
keys = None
3637
retval = []
3738
for line in md_text.splitlines():
38-
if line.strip().startswith("| --- |"):
39-
keys = (
40-
k.replace("*", "").strip()
41-
for k in prev.split("|")
42-
)
39+
if line.strip().startswith('| --- |'):
40+
keys = (k.replace('*', '').strip() for k in prev.split('|'))
4341
keys = [k.lower() for k in keys if k]
4442
continue
4543
elif not keys:
4644
prev = line
4745
continue
4846

49-
if not line or not line.strip().startswith("|"):
47+
if not line or not line.strip().startswith('|'):
5048
break
5149

52-
values = [v.strip() or None for v in line.split("|")][1:-1]
53-
retval.append({k: v for k, v in zip(keys, values) if v})
50+
values = [v.strip() or None for v in line.split('|')][1:-1]
51+
retval.append({k: v for k, v in zip(keys, values, strict=False) if v})
5452

5553
return retval
5654

5755

5856
def sort_contributors(entries, git_lines, exclude=None, last=None):
5957
"""Return a list of author dictionaries, ordered by contribution."""
6058
last = last or []
61-
sorted_authors = sorted(entries, key=lambda i: i["name"])
59+
sorted_authors = sorted(entries, key=lambda i: i['name'])
6260

63-
first_last = [
64-
" ".join(val["name"].split(",")[::-1]).strip() for val in sorted_authors
65-
]
66-
first_last_excl = [
67-
" ".join(val["name"].split(",")[::-1]).strip() for val in exclude or []
68-
]
61+
first_last = [' '.join(val['name'].split(',')[::-1]).strip() for val in sorted_authors]
62+
first_last_excl = [' '.join(val['name'].split(',')[::-1]).strip() for val in exclude or []]
6963

7064
unmatched = []
7165
author_matches = []
7266
for ele in git_lines:
73-
matches = process.extract(
74-
ele, first_last, scorer=fuzz.token_sort_ratio, limit=2
75-
)
67+
matches = process.extract(ele, first_last, scorer=fuzz.token_sort_ratio, limit=2)
7668
# matches is a list [('First match', % Match), ('Second match', % Match)]
7769
if matches[0][1] > 80:
7870
val = sorted_authors[first_last.index(matches[0][0])]
@@ -85,15 +77,15 @@ def sort_contributors(entries, git_lines, exclude=None, last=None):
8577
if val not in author_matches:
8678
author_matches.append(val)
8779

88-
names = {" ".join(val["name"].split(",")[::-1]).strip() for val in author_matches}
80+
names = {' '.join(val['name'].split(',')[::-1]).strip() for val in author_matches}
8981
for missing_name in first_last:
9082
if missing_name not in names:
9183
missing = sorted_authors[first_last.index(missing_name)]
9284
author_matches.append(missing)
9385

9486
position_matches = []
9587
for i, item in enumerate(author_matches):
96-
pos = item.pop("position", None)
88+
pos = item.pop('position', None)
9789
if pos is not None:
9890
position_matches.append((i, int(pos)))
9991

@@ -105,7 +97,7 @@ def sort_contributors(entries, git_lines, exclude=None, last=None):
10597
return author_matches, unmatched
10698

10799

108-
def get_git_lines(fname="line-contributors.txt"):
100+
def get_git_lines(fname='line-contributors.txt'):
109101
"""Run git-line-summary."""
110102
import shutil
111103
import subprocess as sp
@@ -114,15 +106,15 @@ def get_git_lines(fname="line-contributors.txt"):
114106

115107
lines = []
116108
if contrib_file.exists():
117-
print("WARNING: Reusing existing line-contributors.txt file.", file=sys.stderr)
109+
print('WARNING: Reusing existing line-contributors.txt file.', file=sys.stderr)
118110
lines = contrib_file.read_text().splitlines()
119111

120-
git_line_summary_path = shutil.which("git-line-summary")
112+
git_line_summary_path = shutil.which('git-line-summary')
121113
if not lines and git_line_summary_path:
122-
print("Running git-line-summary on repo")
114+
print('Running git-line-summary on repo')
123115
lines = sp.check_output([git_line_summary_path]).decode().splitlines()
124-
lines = [line for line in lines if "Not Committed Yet" not in line]
125-
contrib_file.write_text("\n".join(lines))
116+
lines = [line for line in lines if 'Not Committed Yet' not in line]
117+
contrib_file.write_text('\n'.join(lines))
126118

127119
if not lines:
128120
raise RuntimeError(
@@ -132,13 +124,13 @@ def get_git_lines(fname="line-contributors.txt"):
132124
git-line-summary not found, please install git-extras. """
133125
* (git_line_summary_path is None)
134126
)
135-
return [" ".join(line.strip().split()[1:-1]) for line in lines if "%" in line]
127+
return [' '.join(line.strip().split()[1:-1]) for line in lines if '%' in line]
136128

137129

138130
def _namelast(inlist):
139131
retval = []
140132
for i in inlist:
141-
i["name"] = (f"{i.pop('name', '')} {i.pop('lastname', '')}").strip()
133+
i['name'] = (f"{i.pop('name', '')} {i.pop('lastname', '')}").strip()
142134
retval.append(i)
143135
return retval
144136

@@ -150,12 +142,13 @@ def cli():
150142

151143

152144
@cli.command()
153-
@click.option("-z", "--zenodo-file", type=click.Path(exists=True), default=".zenodo.json")
154-
@click.option("-m", "--maintainers", type=click.Path(exists=True), default=".maint/MAINTAINERS.md")
155-
@click.option("-c", "--contributors", type=click.Path(exists=True),
156-
default=".maint/CONTRIBUTORS.md")
157-
@click.option("--pi", type=click.Path(exists=True), default=".maint/PIs.md")
158-
@click.option("-f", "--former-file", type=click.Path(exists=True), default=".maint/FORMER.md")
145+
@click.option('-z', '--zenodo-file', type=click.Path(exists=True), default='.zenodo.json')
146+
@click.option('-m', '--maintainers', type=click.Path(exists=True), default='.maint/MAINTAINERS.md')
147+
@click.option(
148+
'-c', '--contributors', type=click.Path(exists=True), default='.maint/CONTRIBUTORS.md'
149+
)
150+
@click.option('--pi', type=click.Path(exists=True), default='.maint/PIs.md')
151+
@click.option('-f', '--former-file', type=click.Path(exists=True), default='.maint/FORMER.md')
159152
def zenodo(
160153
zenodo_file,
161154
maintainers,
@@ -176,65 +169,60 @@ def zenodo(
176169
)
177170

178171
zen_contributors, miss_contributors = sort_contributors(
179-
_namelast(read_md_table(Path(contributors).read_text())),
180-
data,
181-
exclude=former
172+
_namelast(read_md_table(Path(contributors).read_text())), data, exclude=former
182173
)
183174

184175
zen_pi = _namelast(
185176
sorted(
186177
read_md_table(Path(pi).read_text()),
187-
key=lambda v: (int(v.get("position", -1)), v.get("lastname"))
178+
key=lambda v: (int(v.get('position', -1)), v.get('lastname')),
188179
)
189180
)
190181

191-
zenodo["creators"] = zen_creators
192-
zenodo["contributors"] = zen_contributors + zen_pi
182+
zenodo['creators'] = zen_creators
183+
zenodo['contributors'] = zen_contributors + zen_pi
193184

194185
misses = set(miss_creators).intersection(miss_contributors)
195186
if misses:
196187
print(
197-
"Some people made commits, but are missing in .maint/ "
198-
f"files: {', '.join(misses)}",
188+
"Some people made commits, but are missing in .maint/ " f"files: {', '.join(misses)}",
199189
file=sys.stderr,
200190
)
201191

202192
# Remove position
203-
for creator in zenodo["creators"]:
204-
creator.pop("position", None)
205-
creator.pop("handle", None)
206-
if isinstance(creator["affiliation"], list):
207-
creator["affiliation"] = creator["affiliation"][0]
208-
209-
for creator in zenodo["contributors"]:
210-
creator.pop("handle", None)
211-
creator["type"] = "Researcher"
212-
creator.pop("position", None)
213-
214-
if isinstance(creator["affiliation"], list):
215-
creator["affiliation"] = creator["affiliation"][0]
216-
217-
Path(zenodo_file).write_text(
218-
"%s\n" % json.dumps(zenodo, indent=2)
219-
)
193+
for creator in zenodo['creators']:
194+
creator.pop('position', None)
195+
creator.pop('handle', None)
196+
if isinstance(creator['affiliation'], list):
197+
creator['affiliation'] = creator['affiliation'][0]
198+
199+
for creator in zenodo['contributors']:
200+
creator.pop('handle', None)
201+
creator['type'] = 'Researcher'
202+
creator.pop('position', None)
203+
204+
if isinstance(creator['affiliation'], list):
205+
creator['affiliation'] = creator['affiliation'][0]
206+
207+
Path(zenodo_file).write_text('%s\n' % json.dumps(zenodo, indent=2))
220208

221209

222210
@cli.command()
223-
@click.option("-m", "--maintainers", type=click.Path(exists=True), default=".maint/MAINTAINERS.md")
224-
@click.option("-c", "--contributors", type=click.Path(exists=True),
225-
default=".maint/CONTRIBUTORS.md")
226-
@click.option("--pi", type=click.Path(exists=True), default=".maint/PIs.md")
227-
@click.option("-f", "--former-file", type=click.Path(exists=True), default=".maint/FORMER.md")
211+
@click.option('-m', '--maintainers', type=click.Path(exists=True), default='.maint/MAINTAINERS.md')
212+
@click.option(
213+
'-c', '--contributors', type=click.Path(exists=True), default='.maint/CONTRIBUTORS.md'
214+
)
215+
@click.option('--pi', type=click.Path(exists=True), default='.maint/PIs.md')
216+
@click.option('-f', '--former-file', type=click.Path(exists=True), default='.maint/FORMER.md')
228217
def publication(
229218
maintainers,
230219
contributors,
231220
pi,
232221
former_file,
233222
):
234223
"""Generate the list of authors and affiliations for papers."""
235-
members = (
236-
_namelast(read_md_table(Path(maintainers).read_text()))
237-
+ _namelast(read_md_table(Path(contributors).read_text()))
224+
members = _namelast(read_md_table(Path(maintainers).read_text())) + _namelast(
225+
read_md_table(Path(contributors).read_text())
238226
)
239227

240228
hits, misses = sort_contributors(
@@ -246,15 +234,12 @@ def publication(
246234
pi_hits = _namelast(
247235
sorted(
248236
read_md_table(Path(pi).read_text()),
249-
key=lambda v: (int(v.get("position", -1)), v.get("lastname"))
237+
key=lambda v: (int(v.get('position', -1)), v.get('lastname')),
250238
)
251239
)
252240

253-
pi_names = [pi["name"] for pi in pi_hits]
254-
hits = [
255-
hit for hit in hits
256-
if hit["name"] not in pi_names
257-
] + pi_hits
241+
pi_names = [pi['name'] for pi in pi_hits]
242+
hits = [hit for hit in hits if hit['name'] not in pi_names] + pi_hits
258243

259244
def _aslist(value):
260245
if isinstance(value, (list, tuple)):
@@ -264,47 +249,39 @@ def _aslist(value):
264249
# Remove position
265250
affiliations = []
266251
for item in hits:
267-
item.pop("position", None)
268-
for a in _aslist(item.get("affiliation", "Unaffiliated")):
252+
item.pop('position', None)
253+
for a in _aslist(item.get('affiliation', 'Unaffiliated')):
269254
if a not in affiliations:
270255
affiliations.append(a)
271256

272257
aff_indexes = [
273-
", ".join(
258+
', '.join(
274259
[
275-
"%d" % (affiliations.index(a) + 1)
276-
for a in _aslist(author.get("affiliation", "Unaffiliated"))
260+
'%d' % (affiliations.index(a) + 1)
261+
for a in _aslist(author.get('affiliation', 'Unaffiliated'))
277262
]
278263
)
279264
for author in hits
280265
]
281266

282267
if misses:
283268
print(
284-
"Some people made commits, but are missing in .maint/ "
285-
f"files: {', '.join(misses)}",
269+
"Some people made commits, but are missing in .maint/ " f"files: {', '.join(misses)}",
286270
file=sys.stderr,
287271
)
288272

289-
print("Authors (%d):" % len(hits))
273+
print('Authors (%d):' % len(hits))
290274
print(
291-
"%s."
292-
% "; ".join(
293-
[
294-
"%s \\ :sup:`%s`\\ " % (i["name"], idx)
295-
for i, idx in zip(hits, aff_indexes)
296-
]
297-
)
275+
'%s.'
276+
% '; '.join(['%s \\ :sup:`%s`\\ ' % (i['name'], idx) for i, idx in zip(hits, aff_indexes, strict=False)])
298277
)
299278

300279
print(
301-
"\n\nAffiliations:\n%s"
302-
% "\n".join(
303-
["{0: >2}. {1}".format(i + 1, a) for i, a in enumerate(affiliations)]
304-
)
280+
'\n\nAffiliations:\n%s'
281+
% '\n'.join([f'{i + 1: >2}. {a}' for i, a in enumerate(affiliations)])
305282
)
306283

307284

308-
if __name__ == "__main__":
285+
if __name__ == '__main__':
309286
""" Install entry-point """
310287
cli()

0 commit comments

Comments
 (0)