Skip to content

Commit

Permalink
Merge pull request #130 from oesteban/maint/setup-revision
Browse files Browse the repository at this point in the history
STY/MAINT: Preparing the first large overhaul of dMRIPrep
  • Loading branch information
oesteban authored Dec 4, 2020
2 parents 49296ac + 44a8abe commit 7002869
Show file tree
Hide file tree
Showing 24 changed files with 1,145 additions and 854 deletions.
62 changes: 41 additions & 21 deletions .maint/paper_author_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


# These authors should go last
AUTHORS_LAST = ['Rokem, Ariel', 'Esteban, Oscar']
AUTHORS_LAST = ["Rokem, Ariel", "Esteban, Oscar"]


def _aslist(inlist):
Expand All @@ -16,34 +16,54 @@ def _aslist(inlist):
return inlist


if __name__ == '__main__':
devs = json.loads(Path('.maint/developers.json').read_text())
contribs = json.loads(Path('.maint/contributors.json').read_text())
if __name__ == "__main__":
devs = json.loads(Path(".maint/developers.json").read_text())
contribs = json.loads(Path(".maint/contributors.json").read_text())

author_matches, unmatched = sort_contributors(
devs + contribs, get_git_lines(),
exclude=json.loads(Path('.maint/former.json').read_text()),
last=AUTHORS_LAST)
devs + contribs,
get_git_lines(),
exclude=json.loads(Path(".maint/former.json").read_text()),
last=AUTHORS_LAST,
)
# Remove position
affiliations = []
for item in author_matches:
del item['position']
for a in _aslist(item.get('affiliation', 'Unaffiliated')):
del item["position"]
for a in _aslist(item.get("affiliation", "Unaffiliated")):
if a not in affiliations:
affiliations.append(a)

aff_indexes = [', '.join(['%d' % (affiliations.index(a) + 1)
for a in _aslist(author.get('affiliation', 'Unaffiliated'))])
for author in author_matches]
aff_indexes = [
", ".join(
[
"%d" % (affiliations.index(a) + 1)
for a in _aslist(author.get("affiliation", "Unaffiliated"))
]
)
for author in author_matches
]

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

print('Authors (%d):' % len(author_matches))
print("%s." % '; '.join([
'%s \\ :sup:`%s`\\ ' % (i['name'], idx)
for i, idx in zip(author_matches, aff_indexes)
]))
print("Authors (%d):" % len(author_matches))
print(
"%s."
% "; ".join(
[
"%s \\ :sup:`%s`\\ " % (i["name"], idx)
for i, idx in zip(author_matches, aff_indexes)
]
)
)

print('\n\nAffiliations:\n%s' % '\n'.join(['{0: >2}. {1}'.format(i + 1, a)
for i, a in enumerate(affiliations)]))
print(
"\n\nAffiliations:\n%s"
% "\n".join(
["{0: >2}. {1}".format(i + 1, a) for i, a in enumerate(affiliations)]
)
)
116 changes: 65 additions & 51 deletions .maint/update_zenodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,29 @@
from fuzzywuzzy import fuzz, process

# These ORCIDs should go last
CREATORS_LAST = ['Rokem, Ariel', 'Esteban, Oscar']
CONTRIBUTORS_LAST = ['Poldrack, Russell A.']
CREATORS_LAST = ["Rokem, Ariel", "Esteban, Oscar"]
CONTRIBUTORS_LAST = ["Poldrack, Russell A."]


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'])
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 []]
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)
matches = process.extract(
ele, first_last, scorer=fuzz.token_sort_ratio, limit=2
)
# matches is a list [('First match', % Match), ('Second match', % Match)]
if matches[0][1] > 80:
val = sorted_authors[first_last.index(matches[0][0])]
Expand All @@ -36,86 +39,97 @@ def sort_contributors(entries, git_lines, exclude=None, last=None):
continue

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

names = {' '.join(val['name'].split(',')[::-1]).strip() for val in author_matches}
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
missing["position"] = position
author_matches.append(missing)
position += 1

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

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

return author_matches, unmatched


def get_git_lines(fname='line-contributors.txt'):
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)
print("WARNING: Reusing existing line-contributors.txt file.", file=sys.stderr)
lines = contrib_file.read_text().splitlines()

git_line_summary_path = shutil.which('git-line-summary')
git_line_summary_path = shutil.which("git-line-summary")
if not lines and git_line_summary_path:
print("Running git-line-summary on repo")
lines = sp.check_output([git_line_summary_path]).decode().splitlines()
lines = [l for l in lines if "Not Committed Yet" not in l]
contrib_file.write_text('\n'.join(lines))
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. """ * (git_line_summary_path is None))
return [' '.join(line.strip().split()[1:-1]) for line in lines if '%' in line]
raise RuntimeError(
"""\
Could not find line-contributors from git repository.%s"""
% """ \
git-line-summary not found, please install git-extras. """
* (git_line_summary_path is None)
)
return [" ".join(line.strip().split()[1:-1]) for line in lines if "%" in line]


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

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

creators = json.loads(Path('.maint/developers.json').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())
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)
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))
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))
21 changes: 12 additions & 9 deletions dmriprep/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""Base module variables."""
from ._version import get_versions
__version__ = get_versions()['version']

__version__ = get_versions()["version"]
del get_versions

__packagename__ = 'dmriprep'
__copyright__ = 'Copyright 2019, The dMRIPrep developers'
__credits__ = ('Contributors: please check the ``.zenodo.json`` file at the top-level folder'
'of the repository')
__url__ = 'https://github.com/nipreps/dmriprep'
__packagename__ = "dmriprep"
__copyright__ = "Copyright 2019, The dMRIPrep developers"
__credits__ = (
"Contributors: please check the ``.zenodo.json`` file at the top-level folder"
"of the repository"
)
__url__ = "https://github.com/nipreps/dmriprep"

DOWNLOAD_URL = (
'https://github.com/nipreps/{name}/archive/{ver}.tar.gz'.format(
name=__packagename__, ver=__version__))
DOWNLOAD_URL = "https://github.com/nipreps/{name}/archive/{ver}.tar.gz".format(
name=__packagename__, ver=__version__
)

__ga_id__ = "UA-156165436-1"
8 changes: 4 additions & 4 deletions dmriprep/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
)

__all__ = [
'__version__',
'__copyright__',
'__credits__',
'__packagename__',
"__version__",
"__copyright__",
"__credits__",
"__packagename__",
]
9 changes: 6 additions & 3 deletions dmriprep/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _min_one(value, parser):
def _to_gb(value):
scale = {"G": 1, "T": 10 ** 3, "M": 1e-3, "K": 1e-6, "B": 1e-9}
digits = "".join([c for c in value if c.isdigit()])
units = value[len(digits):] or "M"
units = value[len(digits) :] or "M"
return int(digits) * scale[units[0]]

def _drop_sub(value):
Expand Down Expand Up @@ -115,9 +115,12 @@ def _bids_filter(value):
"(https://github.com/bids-standard/pybids/blob/master/bids/layout/config/bids.json)",
)
g_bids.add_argument(
"--anat-derivatives", action='store', metavar="PATH", type=PathExists,
"--anat-derivatives",
action="store",
metavar="PATH",
type=PathExists,
help="Reuse the anatomical derivatives from another fMRIPrep run or calculated "
"with an alternative processing tool (NOT RECOMMENDED)."
"with an alternative processing tool (NOT RECOMMENDED).",
)

g_perfm = parser.add_argument_group("Options to handle performance")
Expand Down
2 changes: 1 addition & 1 deletion dmriprep/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def main():
25,
"Works derived from this dMRIPrep execution should "
"include the following boilerplate: "
f"{config.execution.output_dir / 'dmriprep' / 'logs' / 'CITATION.md'}."
f"{config.execution.output_dir / 'dmriprep' / 'logs' / 'CITATION.md'}.",
)

if config.workflow.run_reconall:
Expand Down
Loading

0 comments on commit 7002869

Please sign in to comment.