@@ -65,18 +65,18 @@ def read_md_table(md_text):
65
65
keys = None
66
66
retval = []
67
67
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 ('|' ))
70
70
keys = [k .lower () for k in keys if k ]
71
71
continue
72
72
elif not keys :
73
73
prev = line
74
74
continue
75
75
76
- if not line or not line .strip ().startswith ("|" ):
76
+ if not line or not line .strip ().startswith ('|' ):
77
77
break
78
78
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 ]
80
80
retval .append ({k : v for k , v in zip (keys , values , strict = False ) if v })
81
81
82
82
return retval
@@ -85,10 +85,10 @@ def read_md_table(md_text):
85
85
def sort_contributors (entries , git_lines , exclude = None , last = None ):
86
86
"""Return a list of author dictionaries, ordered by contribution."""
87
87
last = last or []
88
- sorted_authors = sorted (entries , key = lambda i : i [" name" ])
88
+ sorted_authors = sorted (entries , key = lambda i : i [' name' ])
89
89
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 []]
92
92
93
93
unmatched = []
94
94
author_matches = []
@@ -106,15 +106,15 @@ def sort_contributors(entries, git_lines, exclude=None, last=None):
106
106
if val not in author_matches :
107
107
author_matches .append (val )
108
108
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 }
110
110
for missing_name in first_last :
111
111
if missing_name not in names :
112
112
missing = sorted_authors [first_last .index (missing_name )]
113
113
author_matches .append (missing )
114
114
115
115
position_matches = []
116
116
for i , item in enumerate (author_matches ):
117
- pos = item .pop (" position" , None )
117
+ pos = item .pop (' position' , None )
118
118
if pos is not None :
119
119
position_matches .append ((i , int (pos )))
120
120
@@ -126,7 +126,7 @@ def sort_contributors(entries, git_lines, exclude=None, last=None):
126
126
return author_matches , unmatched
127
127
128
128
129
- def get_git_lines (fname = " line-contributors.txt" ):
129
+ def get_git_lines (fname = ' line-contributors.txt' ):
130
130
"""Run git-line-summary."""
131
131
import shutil
132
132
import subprocess as sp
@@ -135,35 +135,35 @@ def get_git_lines(fname="line-contributors.txt"):
135
135
136
136
lines = []
137
137
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 )
139
139
lines = contrib_file .read_text ().splitlines ()
140
140
141
- git_line_summary_path = shutil .which (" git-line-summary" )
141
+ git_line_summary_path = shutil .which (' git-line-summary' )
142
142
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 (' ' )
144
144
else :
145
145
git_line_summary_path = [git_line_summary_path ]
146
146
147
147
if not lines and git_line_summary_path :
148
- print (" Running git-line-summary on repo" )
148
+ print (' Running git-line-summary on repo' )
149
149
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 ))
152
152
153
153
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 ' * (
155
155
git_line_summary_path is None
156
156
)
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 ]
159
159
160
160
161
161
def _namelast (inlist ):
162
162
retval = []
163
163
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>' )
167
167
retval .append (i )
168
168
return retval
169
169
@@ -175,13 +175,13 @@ def cli():
175
175
176
176
177
177
@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' )
180
180
@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'
182
182
)
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' )
185
185
def zenodo (
186
186
zenodo_file ,
187
187
maintainers ,
@@ -207,48 +207,48 @@ def zenodo(
207
207
208
208
zen_pi = _namelast (reversed (read_md_table (Path (pi ).read_text ())))
209
209
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>' }
213
213
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 ]
215
215
216
216
misses = set (miss_creators ).intersection (miss_contributors )
217
217
if misses :
218
218
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 )} ' ,
220
220
file = sys .stderr ,
221
221
)
222
222
223
223
# 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 ]
231
231
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 )
236
236
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 ]
241
241
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 ))
243
243
244
244
245
245
@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' )
247
247
@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'
249
249
)
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' )
252
252
def publication (
253
253
maintainers ,
254
254
contributors ,
@@ -268,8 +268,8 @@ def publication(
268
268
)
269
269
270
270
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
273
273
274
274
def _aslist (value ):
275
275
if isinstance (value , (list , tuple )):
@@ -279,44 +279,44 @@ def _aslist(value):
279
279
# Remove position
280
280
affiliations = []
281
281
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' )):
284
284
if a not in affiliations :
285
285
affiliations .append (a )
286
286
287
287
aff_indexes = [
288
- ", " .join (
288
+ ', ' .join (
289
289
[
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' ))
292
292
]
293
293
)
294
294
for author in hits
295
295
]
296
296
297
297
if misses :
298
298
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 )} ' ,
300
300
file = sys .stderr ,
301
301
)
302
302
303
- print (" Authors (%d):" % len (hits ))
303
+ print (' Authors (%d):' % len (hits ))
304
304
print (
305
- " %s."
306
- % "; " .join (
305
+ ' %s.'
306
+ % '; ' .join (
307
307
[
308
- " {} \\ :sup:`{}`\\ " .format (i [" name" ], idx )
308
+ ' {} \\ :sup:`{}`\\ ' .format (i [' name' ], idx )
309
309
for i , idx in zip (hits , aff_indexes , strict = False )
310
310
]
311
311
)
312
312
)
313
313
314
314
print (
315
- " \n \n Affiliations:\n %s"
316
- % " \n " .join ([f" { i + 1 : >2} . { a } " for i , a in enumerate (affiliations )])
315
+ ' \n \n Affiliations:\n %s'
316
+ % ' \n ' .join ([f' { i + 1 : >2} . { a } ' for i , a in enumerate (affiliations )])
317
317
)
318
318
319
319
320
- if __name__ == " __main__" :
320
+ if __name__ == ' __main__' :
321
321
""" Install entry-point """
322
322
cli ()
0 commit comments