Skip to content

Commit eeeb650

Browse files
committed
fix: pin Chris G. to second-last author of the creators list [skip ci]
1 parent eb12503 commit eeeb650

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

Diff for: tools/update_zenodo.py

+25-27
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
from fuzzywuzzy import fuzz, process
88
import subprocess as sp
99

10-
CREATORS_LAST_ORCID = '0000-0002-5312-6729' # This ORCID should go last
10+
# These ORCIDs should go last
11+
CREATORS_LAST = ['Gorgolewski, Krzysztof J.', 'Ghosh, Satrajit']
1112
# for entries not found in line-contributions
1213
MISSING_ENTRIES = [
1314
{"name": "Varada, Jan"},
@@ -30,39 +31,23 @@
3031
{"name": "Lai, Jeff"}
3132
]
3233

33-
34-
def fix_position(creators):
35-
"""Place Satra last."""
36-
# position first / last authors
37-
l_authr = None
38-
39-
for info in creators:
40-
if 'orcid' in info and info['orcid'] == CREATORS_LAST_ORCID:
41-
l_authr = info
42-
43-
if l_authr is None:
44-
raise AttributeError('Missing important people')
45-
46-
creators.remove(l_authr)
47-
creators.append(l_authr)
48-
return creators
49-
50-
5134
if __name__ == '__main__':
5235
contrib_file = Path('line-contributors.txt')
5336
lines = []
5437
if contrib_file.exists():
5538
print('WARNING: Reusing existing line-contributors.txt file.', file=sys.stderr)
5639
lines = contrib_file.read_text().splitlines()
5740

58-
if not lines and shutil.which('git-line-summary'):
41+
git_line_summary_path = shutil.which('git-line-summary')
42+
if not lines and git_line_summary_path:
5943
print("Running git-line-summary on nipype repo")
60-
lines = sp.check_output(['git-line-summary']).decode().splitlines()
44+
lines = sp.check_output([git_line_summary_path]).decode().splitlines()
6145
contrib_file.write_text('\n'.join(lines))
6246

6347
if not lines:
64-
raise RuntimeError('Could not find line-contributors from git repository '
65-
'(hint: please install git-extras).')
48+
raise RuntimeError("""\
49+
Could not find line-contributors from git repository.%s""" % """ \
50+
git-line-summary not found, please install git-extras. """ * (git_line_summary_path is None))
6651

6752
data = [' '.join(line.strip().split()[1:-1]) for line in lines if '%' in line]
6853

@@ -71,8 +56,10 @@ def fix_position(creators):
7156
zenodo = json.loads(zenodo_file.read_text())
7257
zen_names = [' '.join(val['name'].split(',')[::-1]).strip()
7358
for val in zenodo['creators']]
59+
total_names = len(zen_names) + len(MISSING_ENTRIES)
7460

7561
name_matches = []
62+
position = 1
7663
for ele in data:
7764
matches = process.extract(ele, zen_names, scorer=fuzz.token_sort_ratio,
7865
limit=2)
@@ -85,10 +72,21 @@ def fix_position(creators):
8572
continue
8673

8774
if val not in name_matches:
75+
if val['name'] not in CREATORS_LAST:
76+
val['position'] = position
77+
position += 1
78+
else:
79+
val['position'] = total_names + CREATORS_LAST.index(val['name'])
8880
name_matches.append(val)
8981

90-
for entry in MISSING_ENTRIES:
91-
name_matches.append(entry)
82+
for missing in MISSING_ENTRIES:
83+
missing['position'] = position
84+
position += 1
85+
name_matches.append(missing)
86+
87+
zenodo['creators'] = sorted(name_matches, key=lambda k: k['position'])
88+
# Remove position
89+
for creator in zenodo['creators']:
90+
del creator['position']
9291

93-
zenodo['creators'] = fix_position(name_matches)
94-
zenodo_file.write_text(json.dumps(zenodo, indent=2, sort_keys=True))
92+
zenodo_file.write_text('%s\n' % json.dumps(zenodo, indent=2, sort_keys=True))

0 commit comments

Comments
 (0)