Skip to content

Commit e2b4dba

Browse files
committed
sty: format with ruff
1 parent 9792bb0 commit e2b4dba

File tree

1 file changed

+67
-67
lines changed

1 file changed

+67
-67
lines changed

.maint/update_authors.py

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ def read_md_table(md_text):
6565
keys = None
6666
retval = []
6767
for line in md_text.splitlines():
68-
if line.strip().startswith("| --- |"):
69-
keys = (k.replace("*", "").strip() for k in prev.split("|"))
68+
if line.strip().startswith('| --- |'):
69+
keys = (k.replace('*', '').strip() for k in prev.split('|'))
7070
keys = [k.lower() for k in keys if k]
7171
continue
7272
elif not keys:
7373
prev = line
7474
continue
7575

76-
if not line or not line.strip().startswith("|"):
76+
if not line or not line.strip().startswith('|'):
7777
break
7878

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

8282
return retval
@@ -85,10 +85,10 @@ def read_md_table(md_text):
8585
def sort_contributors(entries, git_lines, exclude=None, last=None):
8686
"""Return a list of author dictionaries, ordered by contribution."""
8787
last = last or []
88-
sorted_authors = sorted(entries, key=lambda i: i["name"])
88+
sorted_authors = sorted(entries, key=lambda i: i['name'])
8989

90-
first_last = [" ".join(val["name"].split(",")[::-1]).strip() for val in sorted_authors]
91-
first_last_excl = [" ".join(val["name"].split(",")[::-1]).strip() for val in exclude or []]
90+
first_last = [' '.join(val['name'].split(',')[::-1]).strip() for val in sorted_authors]
91+
first_last_excl = [' '.join(val['name'].split(',')[::-1]).strip() for val in exclude or []]
9292

9393
unmatched = []
9494
author_matches = []
@@ -106,15 +106,15 @@ def sort_contributors(entries, git_lines, exclude=None, last=None):
106106
if val not in author_matches:
107107
author_matches.append(val)
108108

109-
names = {" ".join(val["name"].split(",")[::-1]).strip() for val in author_matches}
109+
names = {' '.join(val['name'].split(',')[::-1]).strip() for val in author_matches}
110110
for missing_name in first_last:
111111
if missing_name not in names:
112112
missing = sorted_authors[first_last.index(missing_name)]
113113
author_matches.append(missing)
114114

115115
position_matches = []
116116
for i, item in enumerate(author_matches):
117-
pos = item.pop("position", None)
117+
pos = item.pop('position', None)
118118
if pos is not None:
119119
position_matches.append((i, int(pos)))
120120

@@ -126,7 +126,7 @@ def sort_contributors(entries, git_lines, exclude=None, last=None):
126126
return author_matches, unmatched
127127

128128

129-
def get_git_lines(fname="line-contributors.txt"):
129+
def get_git_lines(fname='line-contributors.txt'):
130130
"""Run git-line-summary."""
131131
import shutil
132132
import subprocess as sp
@@ -135,35 +135,35 @@ def get_git_lines(fname="line-contributors.txt"):
135135

136136
lines = []
137137
if contrib_file.exists():
138-
print("WARNING: Reusing existing line-contributors.txt file.", file=sys.stderr)
138+
print('WARNING: Reusing existing line-contributors.txt file.', file=sys.stderr)
139139
lines = contrib_file.read_text().splitlines()
140140

141-
git_line_summary_path = shutil.which("git-line-summary")
141+
git_line_summary_path = shutil.which('git-line-summary')
142142
if not git_line_summary_path:
143-
git_line_summary_path = "git summary --dedup-by-email".split(" ")
143+
git_line_summary_path = 'git summary --dedup-by-email'.split(' ')
144144
else:
145145
git_line_summary_path = [git_line_summary_path]
146146

147147
if not lines and git_line_summary_path:
148-
print("Running git-line-summary on repo")
148+
print('Running git-line-summary on repo')
149149
lines = sp.check_output(git_line_summary_path).decode().splitlines()
150-
lines = [line for line in lines if "Not Committed Yet" not in line]
151-
contrib_file.write_text("\n".join(lines))
150+
lines = [line for line in lines if 'Not Committed Yet' not in line]
151+
contrib_file.write_text('\n'.join(lines))
152152

153153
if not lines:
154-
_msg = ": git-line-summary not found, please install git-extras " * (
154+
_msg = ': git-line-summary not found, please install git-extras ' * (
155155
git_line_summary_path is None
156156
)
157-
raise RuntimeError(f"Could not find line-contributors from git repository{_msg}.")
158-
return [" ".join(line.strip().split()[1:-1]) for line in lines if "%" in line]
157+
raise RuntimeError(f'Could not find line-contributors from git repository{_msg}.')
158+
return [' '.join(line.strip().split()[1:-1]) for line in lines if '%' in line]
159159

160160

161161
def _namelast(inlist):
162162
retval = []
163163
for i in inlist:
164-
i["name"] = (f"{i.pop('name', '')} {i.pop('lastname', '')}").strip()
165-
if not i["name"]:
166-
i["name"] = i.get("handle", "<Unknown Name>")
164+
i['name'] = (f'{i.pop("name", "")} {i.pop("lastname", "")}').strip()
165+
if not i['name']:
166+
i['name'] = i.get('handle', '<Unknown Name>')
167167
retval.append(i)
168168
return retval
169169

@@ -175,13 +175,13 @@ def cli():
175175

176176

177177
@cli.command()
178-
@click.option("-z", "--zenodo-file", type=click.Path(exists=True), default=".zenodo.json")
179-
@click.option("-m", "--maintainers", type=click.Path(exists=True), default=".maint/MAINTAINERS.md")
178+
@click.option('-z', '--zenodo-file', type=click.Path(exists=True), default='.zenodo.json')
179+
@click.option('-m', '--maintainers', type=click.Path(exists=True), default='.maint/MAINTAINERS.md')
180180
@click.option(
181-
"-c", "--contributors", type=click.Path(exists=True), default=".maint/CONTRIBUTORS.md"
181+
'-c', '--contributors', type=click.Path(exists=True), default='.maint/CONTRIBUTORS.md'
182182
)
183-
@click.option("--pi", type=click.Path(exists=True), default=".maint/PIs.md")
184-
@click.option("-f", "--former-file", type=click.Path(exists=True), default=".maint/FORMER.md")
183+
@click.option('--pi', type=click.Path(exists=True), default='.maint/PIs.md')
184+
@click.option('-f', '--former-file', type=click.Path(exists=True), default='.maint/FORMER.md')
185185
def zenodo(
186186
zenodo_file,
187187
maintainers,
@@ -207,48 +207,48 @@ def zenodo(
207207

208208
zen_pi = _namelast(reversed(read_md_table(Path(pi).read_text())))
209209

210-
zenodo["creators"] = zen_creators
211-
zenodo["contributors"] = zen_contributors + [pi for pi in zen_pi if pi not in zen_contributors]
212-
creator_names = {c["name"] for c in zenodo["creators"] if c["name"] != "<Unknown Name>"}
210+
zenodo['creators'] = zen_creators
211+
zenodo['contributors'] = zen_contributors + [pi for pi in zen_pi if pi not in zen_contributors]
212+
creator_names = {c['name'] for c in zenodo['creators'] if c['name'] != '<Unknown Name>'}
213213

214-
zenodo["contributors"] = [c for c in zenodo["contributors"] if c["name"] not in creator_names]
214+
zenodo['contributors'] = [c for c in zenodo['contributors'] if c['name'] not in creator_names]
215215

216216
misses = set(miss_creators).intersection(miss_contributors)
217217
if misses:
218218
print(
219-
f"Some people made commits, but are missing in .maint/ files: {', '.join(misses)}",
219+
f'Some people made commits, but are missing in .maint/ files: {", ".join(misses)}',
220220
file=sys.stderr,
221221
)
222222

223223
# Remove position
224-
for creator in zenodo["creators"]:
225-
creator.pop("position", None)
226-
creator.pop("handle", None)
227-
if "affiliation" not in creator:
228-
creator["affiliation"] = "Unknown affiliation"
229-
elif isinstance(creator["affiliation"], list):
230-
creator["affiliation"] = creator["affiliation"][0]
224+
for creator in zenodo['creators']:
225+
creator.pop('position', None)
226+
creator.pop('handle', None)
227+
if 'affiliation' not in creator:
228+
creator['affiliation'] = 'Unknown affiliation'
229+
elif isinstance(creator['affiliation'], list):
230+
creator['affiliation'] = creator['affiliation'][0]
231231

232-
for creator in zenodo["contributors"]:
233-
creator.pop("handle", None)
234-
creator["type"] = "Researcher"
235-
creator.pop("position", None)
232+
for creator in zenodo['contributors']:
233+
creator.pop('handle', None)
234+
creator['type'] = 'Researcher'
235+
creator.pop('position', None)
236236

237-
if "affiliation" not in creator:
238-
creator["affiliation"] = "Unknown affiliation"
239-
elif isinstance(creator["affiliation"], list):
240-
creator["affiliation"] = creator["affiliation"][0]
237+
if 'affiliation' not in creator:
238+
creator['affiliation'] = 'Unknown affiliation'
239+
elif isinstance(creator['affiliation'], list):
240+
creator['affiliation'] = creator['affiliation'][0]
241241

242-
Path(zenodo_file).write_text("%s\n" % json.dumps(zenodo, indent=2))
242+
Path(zenodo_file).write_text('%s\n' % json.dumps(zenodo, indent=2))
243243

244244

245245
@cli.command()
246-
@click.option("-m", "--maintainers", type=click.Path(exists=True), default=".maint/MAINTAINERS.md")
246+
@click.option('-m', '--maintainers', type=click.Path(exists=True), default='.maint/MAINTAINERS.md')
247247
@click.option(
248-
"-c", "--contributors", type=click.Path(exists=True), default=".maint/CONTRIBUTORS.md"
248+
'-c', '--contributors', type=click.Path(exists=True), default='.maint/CONTRIBUTORS.md'
249249
)
250-
@click.option("--pi", type=click.Path(exists=True), default=".maint/PIs.md")
251-
@click.option("-f", "--former-file", type=click.Path(exists=True), default=".maint/FORMER.md")
250+
@click.option('--pi', type=click.Path(exists=True), default='.maint/PIs.md')
251+
@click.option('-f', '--former-file', type=click.Path(exists=True), default='.maint/FORMER.md')
252252
def publication(
253253
maintainers,
254254
contributors,
@@ -268,8 +268,8 @@ def publication(
268268
)
269269

270270
pi_hits = _namelast(reversed(read_md_table(Path(pi).read_text())))
271-
pi_names = [pi["name"] for pi in pi_hits]
272-
hits = [hit for hit in hits if hit["name"] not in pi_names] + pi_hits
271+
pi_names = [pi['name'] for pi in pi_hits]
272+
hits = [hit for hit in hits if hit['name'] not in pi_names] + pi_hits
273273

274274
def _aslist(value):
275275
if isinstance(value, (list, tuple)):
@@ -279,44 +279,44 @@ def _aslist(value):
279279
# Remove position
280280
affiliations = []
281281
for item in hits:
282-
item.pop("position", None)
283-
for a in _aslist(item.get("affiliation", "Unaffiliated")):
282+
item.pop('position', None)
283+
for a in _aslist(item.get('affiliation', 'Unaffiliated')):
284284
if a not in affiliations:
285285
affiliations.append(a)
286286

287287
aff_indexes = [
288-
", ".join(
288+
', '.join(
289289
[
290-
"%d" % (affiliations.index(a) + 1)
291-
for a in _aslist(author.get("affiliation", "Unaffiliated"))
290+
'%d' % (affiliations.index(a) + 1)
291+
for a in _aslist(author.get('affiliation', 'Unaffiliated'))
292292
]
293293
)
294294
for author in hits
295295
]
296296

297297
if misses:
298298
print(
299-
f"Some people made commits, but are missing in .maint/ files: {', '.join(misses)}",
299+
f'Some people made commits, but are missing in .maint/ files: {", ".join(misses)}',
300300
file=sys.stderr,
301301
)
302302

303-
print("Authors (%d):" % len(hits))
303+
print('Authors (%d):' % len(hits))
304304
print(
305-
"%s."
306-
% "; ".join(
305+
'%s.'
306+
% '; '.join(
307307
[
308-
"{} \\ :sup:`{}`\\ ".format(i["name"], idx)
308+
'{} \\ :sup:`{}`\\ '.format(i['name'], idx)
309309
for i, idx in zip(hits, aff_indexes, strict=False)
310310
]
311311
)
312312
)
313313

314314
print(
315-
"\n\nAffiliations:\n%s"
316-
% "\n".join([f"{i + 1: >2}. {a}" for i, a in enumerate(affiliations)])
315+
'\n\nAffiliations:\n%s'
316+
% '\n'.join([f'{i + 1: >2}. {a}' for i, a in enumerate(affiliations)])
317317
)
318318

319319

320-
if __name__ == "__main__":
320+
if __name__ == '__main__':
321321
""" Install entry-point """
322322
cli()

0 commit comments

Comments
 (0)