Skip to content

Commit 3c1f2a5

Browse files
committed
chore: copy zenodo/papers update scripts [skip ci]
1 parent 6399e0a commit 3c1f2a5

File tree

8 files changed

+268
-108
lines changed

8 files changed

+268
-108
lines changed

.maint/contributors.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"affiliation": "Perelman School of Medicine, University of Pennsylvania, PA, USA",
4+
"name": "Cieslak, Matthew",
5+
"orcid": "0000-0002-1931-4734",
6+
"type": "Researcher"
7+
},
8+
{
9+
"affiliation": "Neuroscience Program, University of Iowa",
10+
"name": "Kent, James D.",
11+
"orcid": "0000-0002-4892-2659",
12+
"type": "Researcher"
13+
},
14+
{
15+
"affiliation": "Department of Psychology, Stanford University",
16+
"name": "Poldrack, Russell A.",
17+
"orcid": "0000-0001-6755-0259",
18+
"type": "Researcher"
19+
}
20+
]

.maint/developers.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[
2+
{
3+
"affiliation": "Dep. of Radiology, Lausanne University Hospital and University of Lausanne",
4+
"name": "Esteban, Oscar",
5+
"orcid": "0000-0001-8435-6191"
6+
},
7+
{
8+
"affiliation": "The Centre for Addiction and Mental Health",
9+
"name": "Joseph, Michael",
10+
"orcid": "0000-0002-0068-230X"
11+
},
12+
{
13+
"affiliation": "The University of Washington, eScience Institute",
14+
"name": "Keshavan, Anisha",
15+
"orcid": "0000-0003-3554-043X"
16+
},
17+
{
18+
"affiliation": "Department of Psychology, Stanford University, CA, USA",
19+
"name": "Lerma-Usabiaga, Garikoitz",
20+
"orcid": "0000-0001-9800-4816"
21+
},
22+
{
23+
"affiliation": "Department of Psychology, University of Texas at Austin, TX, USA",
24+
"name": "Pisner, Derek",
25+
"orcid": "0000-0002-1228-0201"
26+
},
27+
{
28+
"affiliation": "The University of Washington, eScience Institute",
29+
"name": "Richie-Halford, Adam",
30+
"orcid": "0000-0001-9276-9084"
31+
},
32+
{
33+
"affiliation": "The University of Washington eScience Institute",
34+
"name": "Rokem, Ariel",
35+
"orcid": "0000-0003-0679-1985"
36+
}
37+
]

.maint/former.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
{
3+
"name": "nrajamani3"
4+
}
5+
]

.maint/paper_author_list.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
"""Generate an author list for a new paper or abstract."""
3+
import sys
4+
from pathlib import Path
5+
import json
6+
from update_zenodo import get_git_lines, sort_contributors
7+
8+
9+
# These authors should go last
10+
AUTHORS_LAST = ['Rokem, Ariel', 'Esteban, Oscar']
11+
12+
13+
def _aslist(inlist):
14+
if not isinstance(inlist, list):
15+
return [inlist]
16+
return inlist
17+
18+
19+
if __name__ == '__main__':
20+
devs = json.loads(Path('.maint/developers.json').read_text())
21+
contribs = json.loads(Path('.maint/contributors.json').read_text())
22+
23+
author_matches, unmatched = sort_contributors(
24+
devs + contribs, get_git_lines(),
25+
exclude=json.loads(Path('.maint/former.json').read_text()),
26+
last=AUTHORS_LAST)
27+
# Remove position
28+
affiliations = []
29+
for item in author_matches:
30+
del item['position']
31+
for a in _aslist(item.get('affiliation', 'Unaffiliated')):
32+
if a not in affiliations:
33+
affiliations.append(a)
34+
35+
aff_indexes = [', '.join(['%d' % (affiliations.index(a) + 1)
36+
for a in _aslist(author.get('affiliation', 'Unaffiliated'))])
37+
for author in author_matches]
38+
39+
print("Some people made commits, but are missing in .maint/ "
40+
"files: %s." % ', '.join(unmatched), file=sys.stderr)
41+
42+
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+
]))
47+
48+
print('\n\nAffiliations:\n%s' % '\n'.join(['{0: >2}. {1}'.format(i + 1, a)
49+
for i, a in enumerate(affiliations)]))
File renamed without changes.

.maint/update_zenodo.py

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/usr/bin/env python3
2+
"""Update and sort the creators list of the zenodo record."""
3+
import sys
4+
from pathlib import Path
5+
import json
6+
from fuzzywuzzy import fuzz, process
7+
8+
# These ORCIDs should go last
9+
CREATORS_LAST = ['Rokem, Ariel', 'Esteban, Oscar']
10+
CONTRIBUTORS_LAST = ['Poldrack, Russell A.']
11+
12+
13+
def sort_contributors(entries, git_lines, exclude=None, last=None):
14+
"""Return a list of author dictionaries, ordered by contribution."""
15+
last = last or []
16+
sorted_authors = sorted(entries, key=lambda i: i['name'])
17+
18+
first_last = [' '.join(val['name'].split(',')[::-1]).strip()
19+
for val in sorted_authors]
20+
first_last_excl = [' '.join(val['name'].split(',')[::-1]).strip()
21+
for val in exclude or []]
22+
23+
unmatched = []
24+
author_matches = []
25+
position = 1
26+
for ele in git_lines:
27+
matches = process.extract(ele, first_last, scorer=fuzz.token_sort_ratio,
28+
limit=2)
29+
# matches is a list [('First match', % Match), ('Second match', % Match)]
30+
if matches[0][1] > 80:
31+
val = sorted_authors[first_last.index(matches[0][0])]
32+
else:
33+
# skip unmatched names
34+
if ele not in first_last_excl:
35+
unmatched.append(ele)
36+
continue
37+
38+
if val not in author_matches:
39+
val['position'] = position
40+
author_matches.append(val)
41+
position += 1
42+
43+
names = {' '.join(val['name'].split(',')[::-1]).strip() for val in author_matches}
44+
for missing_name in first_last:
45+
if missing_name not in names:
46+
missing = sorted_authors[first_last.index(missing_name)]
47+
missing['position'] = position
48+
author_matches.append(missing)
49+
position += 1
50+
51+
all_names = [val['name'] for val in author_matches]
52+
for last_author in last:
53+
author_matches[all_names.index(last_author)]['position'] = position
54+
position += 1
55+
56+
author_matches = sorted(author_matches, key=lambda k: k['position'])
57+
58+
return author_matches, unmatched
59+
60+
61+
def get_git_lines(fname='line-contributors.txt'):
62+
"""Run git-line-summary."""
63+
import shutil
64+
import subprocess as sp
65+
contrib_file = Path(fname)
66+
67+
lines = []
68+
if contrib_file.exists():
69+
print('WARNING: Reusing existing line-contributors.txt file.', file=sys.stderr)
70+
lines = contrib_file.read_text().splitlines()
71+
72+
git_line_summary_path = shutil.which('git-line-summary')
73+
if not lines and git_line_summary_path:
74+
print("Running git-line-summary on repo")
75+
lines = sp.check_output([git_line_summary_path]).decode().splitlines()
76+
lines = [l for l in lines if "Not Committed Yet" not in l]
77+
contrib_file.write_text('\n'.join(lines))
78+
79+
if not lines:
80+
raise RuntimeError("""\
81+
Could not find line-contributors from git repository.%s""" % """ \
82+
git-line-summary not found, please install git-extras. """ * (git_line_summary_path is None))
83+
return [' '.join(line.strip().split()[1:-1]) for line in lines if '%' in line]
84+
85+
86+
if __name__ == '__main__':
87+
data = get_git_lines()
88+
89+
zenodo_file = Path('.zenodo.json')
90+
zenodo = json.loads(zenodo_file.read_text())
91+
92+
creators = json.loads(Path('.maint/developers.json').read_text())
93+
zen_creators, miss_creators = sort_contributors(
94+
creators, data,
95+
exclude=json.loads(Path('.maint/former.json').read_text()),
96+
last=CREATORS_LAST)
97+
contributors = json.loads(Path('.maint/contributors.json').read_text())
98+
zen_contributors, miss_contributors = sort_contributors(
99+
contributors, data,
100+
exclude=json.loads(Path('.maint/former.json').read_text()),
101+
last=CONTRIBUTORS_LAST)
102+
zenodo['creators'] = zen_creators
103+
zenodo['contributors'] = zen_contributors
104+
105+
print("Some people made commits, but are missing in .maint/ "
106+
"files: %s." % ', '.join(set(miss_creators).intersection(miss_contributors)),
107+
file=sys.stderr)
108+
109+
# Remove position
110+
for creator in zenodo['creators']:
111+
del creator['position']
112+
if isinstance(creator['affiliation'], list):
113+
creator['affiliation'] = creator['affiliation'][0]
114+
115+
for creator in zenodo['contributors']:
116+
creator['type'] = 'Researcher'
117+
del creator['position']
118+
if isinstance(creator['affiliation'], list):
119+
creator['affiliation'] = creator['affiliation'][0]
120+
121+
zenodo_file.write_text('%s\n' % json.dumps(zenodo, indent=2))

.maintenance/update_zenodo.py

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)