Skip to content

Commit

Permalink
MAINT: Add authorship
Browse files Browse the repository at this point in the history
  • Loading branch information
mgxd committed May 5, 2022
1 parent 32b276f commit 8b25733
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Christopher J. Markiewicz <[email protected]>
Christopher J. Markiewicz <[email protected]> <[email protected]>
Christopher J. Markiewicz <[email protected]> <[email protected]>
Mathias Goncalves <[email protected]>
Mathias Goncalves <[email protected]> <[email protected]>
Mathias Goncalves <[email protected]> <[email protected]>
Oscar Esteban <[email protected]>
Oscar Esteban <[email protected]> <[email protected]>
1 change: 1 addition & 0 deletions .maint/contributors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
30 changes: 30 additions & 0 deletions .maint/developers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"affiliation": "Department of Psychology, Stanford University",
"name": "Goncalves, Mathias",
"orcid": "0000-0002-7252-7771"
},
{
"affiliation": "Department of Psychology, Stanford University",
"name": "Markiewicz, Christopher J.",
"orcid": "0000-0002-6533-164X"
},
{
"affiliation": "Department of Psychology, Stanford University",
"name": "Poldrack, Russell A.",
"orcid": "0000-0001-6755-0259"
},
{
"affiliation": "Lausanne University Hospital and University of Lausanne, Lausanne, Switzerland",
"name": "Esteban, Oscar",
"orcid": "0000-0001-8435-6191"
},
{
"affiliation": "University of Minnesota",
"name": "Feczko, Eric"
},
{
"affiliation": "University of Minnesota",
"name": "Fair, Damien A."
}
]
1 change: 1 addition & 0 deletions .maint/former.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
125 changes: 125 additions & 0 deletions .maint/update_zenodo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/usr/bin/env python3
"""Update and sort the creators list of the zenodo record."""
import sys
from pathlib import Path
import json
from fuzzywuzzy import fuzz, process

# These ORCIDs should go last
CREATORS_LAST = ['Poldrack, Russell A.', 'Fair, Damien A.']
CONTRIBUTORS_LAST = []


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

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

unmatched = []
author_matches = []
position = 1
for ele in git_lines:
matches = process.extract(ele, first_last, scorer=fuzz.token_sort_ratio,
limit=2)
if not matches:
return [], []
# matches is a list [('First match', % Match), ('Second match', % Match)]
if matches[0][1] > 80:
val = sorted_authors[first_last.index(matches[0][0])]
else:
# skip unmatched names
if ele not in first_last_excl:
unmatched.append(ele)
continue

if val not in author_matches:
val['position'] = position
author_matches.append(val)
position += 1

names = {' '.join(val['name'].split(',')[::-1]).strip() for val in author_matches}
for missing_name in first_last:
if missing_name not in names:
missing = sorted_authors[first_last.index(missing_name)]
missing['position'] = position
author_matches.append(missing)
position += 1

all_names = [val['name'] for val in author_matches]
for last_author in last:
author_matches[all_names.index(last_author)]['position'] = position
position += 1

author_matches = sorted(author_matches, key=lambda k: k['position'])

return author_matches, unmatched


def get_git_lines(fname='line-contributors.txt'):
"""Run git-line-summary."""
import shutil
import subprocess as sp
contrib_file = Path(fname)

lines = []
if contrib_file.exists():
print('WARNING: Reusing existing line-contributors.txt file.', file=sys.stderr)
lines = contrib_file.read_text().splitlines()

cmd = [shutil.which('git-line-summary')]
if cmd == [None]:
cmd = [shutil.which('git-summary'), "--line"]
if not lines and cmd[0]:
print(f"Running {' '.join(cmd)!r} on repo")
lines = sp.check_output(cmd).decode().splitlines()
lines = [l for l in lines if "Not Committed Yet" not in l]
contrib_file.write_text('\n'.join(lines))

if not lines:
raise RuntimeError("""\
Could not find line-contributors from git repository.%s""" % """ \
git-(line-)summary not found, please install git-extras. """ * (cmd[0] is None))
return [' '.join(line.strip().split()[1:-1]) for line in lines if '%' in line]


if __name__ == '__main__':
data = get_git_lines()

zenodo_file = Path('.zenodo.json')
zenodo = json.loads(zenodo_file.read_text())

creators = json.loads(Path('.maint/developers.json').read_text())
zen_creators, miss_creators = sort_contributors(
creators, data,
exclude=json.loads(Path('.maint/former.json').read_text()),
last=CREATORS_LAST)
contributors = json.loads(Path('.maint/contributors.json').read_text())
zen_contributors, miss_contributors = sort_contributors(
contributors, data,
exclude=json.loads(Path('.maint/former.json').read_text()),
last=CONTRIBUTORS_LAST)
zenodo['creators'] = zen_creators
zenodo['contributors'] = zen_contributors

print("Some people made commits, but are missing in .maint/ "
"files: %s." % ', '.join(set(miss_creators).intersection(miss_contributors)),
file=sys.stderr)

# Remove position
for creator in zenodo['creators']:
del creator['position']
if isinstance(creator['affiliation'], list):
creator['affiliation'] = creator['affiliation'][0]

for creator in zenodo['contributors']:
creator['type'] = 'Researcher'
del creator['position']
if isinstance(creator['affiliation'], list):
creator['affiliation'] = creator['affiliation'][0]

zenodo_file.write_text('%s\n' % json.dumps(zenodo, indent=2))
4 changes: 3 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ repos:
rev: 22.3.0
hooks:
- id: black
files: ^nibabies/
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
- id: isort
files: ^nibabies/
58 changes: 58 additions & 0 deletions .zenodo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"title": "NiBabies: a robust preprocessing pipeline for infant functional MRI",
"description": "<p>NiBabies is a robust and easy-to-use pipeline for preprocessing of diverse infant and neonate fMRI data. The transparent workflow dispenses of manual intervention, thereby ensuring the reproducibility of the results.</p>",
"contributors": [],
"creators": [
{
"affiliation": "Department of Psychology, Stanford University",
"name": "Goncalves, Mathias",
"orcid": "0000-0002-7252-7771"
},
{
"affiliation": "Department of Psychology, Stanford University",
"name": "Markiewicz, Christopher J.",
"orcid": "0000-0002-6533-164X"
},
{
"affiliation": "Lausanne University Hospital and University of Lausanne, Lausanne, Switzerland",
"name": "Esteban, Oscar",
"orcid": "0000-0001-8435-6191"
},
{
"affiliation": "University of Minnesota",
"name": "Feczko, Eric"
},
{
"affiliation": "Department of Psychology, Stanford University",
"name": "Poldrack, Russell A.",
"orcid": "0000-0001-6755-0259"
},
{
"affiliation": "University of Minnesota",
"name": "Fair, Damien A."
}
],
"keywords": [
"neuroimaging",
"workflow",
"pipeline",
"preprocessing",
"fMRI",
"BIDS",
"infant"
],
"license": "Apache-2.0",
"related_identifiers": [
{
"identifier": "https://github.com/nipreps/nibabies",
"relation": "documents",
"scheme": "url"
},
{
"identifier": "10.5281/zenodo.6418986",
"relation": "isPartOf",
"scheme": "doi"
}
],
"upload_type": "software"
}
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ docs =
duecredit =
duecredit
citeproc-py != 0.5.0
maint =
fuzzywuzzy
python-Levenshtein
pointclouds =
pyntcloud
style =
Expand All @@ -90,6 +93,7 @@ all =
%(aroma)s
%(doc)s
%(duecredit)s
%(maint)s
%(pointclouds)s
%(style)s
%(test)s
Expand Down

0 comments on commit 8b25733

Please sign in to comment.