Skip to content

Commit 10649ff

Browse files
committed
sty: run black on the whole project (with minimal exceptions)
Thanks to @richford for his patience on this one :)
1 parent 4f0924a commit 10649ff

23 files changed

+1120
-844
lines changed

.maint/paper_author_list.py

+41-21
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
# These authors should go last
10-
AUTHORS_LAST = ['Rokem, Ariel', 'Esteban, Oscar']
10+
AUTHORS_LAST = ["Rokem, Ariel", "Esteban, Oscar"]
1111

1212

1313
def _aslist(inlist):
@@ -16,34 +16,54 @@ def _aslist(inlist):
1616
return inlist
1717

1818

19-
if __name__ == '__main__':
20-
devs = json.loads(Path('.maint/developers.json').read_text())
21-
contribs = json.loads(Path('.maint/contributors.json').read_text())
19+
if __name__ == "__main__":
20+
devs = json.loads(Path(".maint/developers.json").read_text())
21+
contribs = json.loads(Path(".maint/contributors.json").read_text())
2222

2323
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)
24+
devs + contribs,
25+
get_git_lines(),
26+
exclude=json.loads(Path(".maint/former.json").read_text()),
27+
last=AUTHORS_LAST,
28+
)
2729
# Remove position
2830
affiliations = []
2931
for item in author_matches:
30-
del item['position']
31-
for a in _aslist(item.get('affiliation', 'Unaffiliated')):
32+
del item["position"]
33+
for a in _aslist(item.get("affiliation", "Unaffiliated")):
3234
if a not in affiliations:
3335
affiliations.append(a)
3436

35-
aff_indexes = [', '.join(['%d' % (affiliations.index(a) + 1)
36-
for a in _aslist(author.get('affiliation', 'Unaffiliated'))])
37-
for author in author_matches]
37+
aff_indexes = [
38+
", ".join(
39+
[
40+
"%d" % (affiliations.index(a) + 1)
41+
for a in _aslist(author.get("affiliation", "Unaffiliated"))
42+
]
43+
)
44+
for author in author_matches
45+
]
3846

39-
print("Some people made commits, but are missing in .maint/ "
40-
"files: %s." % ', '.join(unmatched), file=sys.stderr)
47+
print(
48+
"Some people made commits, but are missing in .maint/ "
49+
"files: %s." % ", ".join(unmatched),
50+
file=sys.stderr,
51+
)
4152

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-
]))
53+
print("Authors (%d):" % len(author_matches))
54+
print(
55+
"%s."
56+
% "; ".join(
57+
[
58+
"%s \\ :sup:`%s`\\ " % (i["name"], idx)
59+
for i, idx in zip(author_matches, aff_indexes)
60+
]
61+
)
62+
)
4763

48-
print('\n\nAffiliations:\n%s' % '\n'.join(['{0: >2}. {1}'.format(i + 1, a)
49-
for i, a in enumerate(affiliations)]))
64+
print(
65+
"\n\nAffiliations:\n%s"
66+
% "\n".join(
67+
["{0: >2}. {1}".format(i + 1, a) for i, a in enumerate(affiliations)]
68+
)
69+
)

.maint/update_zenodo.py

+65-51
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,29 @@
66
from fuzzywuzzy import fuzz, process
77

88
# These ORCIDs should go last
9-
CREATORS_LAST = ['Rokem, Ariel', 'Esteban, Oscar']
10-
CONTRIBUTORS_LAST = ['Poldrack, Russell A.']
9+
CREATORS_LAST = ["Rokem, Ariel", "Esteban, Oscar"]
10+
CONTRIBUTORS_LAST = ["Poldrack, Russell A."]
1111

1212

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

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 []]
18+
first_last = [
19+
" ".join(val["name"].split(",")[::-1]).strip() for val in sorted_authors
20+
]
21+
first_last_excl = [
22+
" ".join(val["name"].split(",")[::-1]).strip() for val in exclude or []
23+
]
2224

2325
unmatched = []
2426
author_matches = []
2527
position = 1
2628
for ele in git_lines:
27-
matches = process.extract(ele, first_last, scorer=fuzz.token_sort_ratio,
28-
limit=2)
29+
matches = process.extract(
30+
ele, first_last, scorer=fuzz.token_sort_ratio, limit=2
31+
)
2932
# matches is a list [('First match', % Match), ('Second match', % Match)]
3033
if matches[0][1] > 80:
3134
val = sorted_authors[first_last.index(matches[0][0])]
@@ -36,86 +39,97 @@ def sort_contributors(entries, git_lines, exclude=None, last=None):
3639
continue
3740

3841
if val not in author_matches:
39-
val['position'] = position
42+
val["position"] = position
4043
author_matches.append(val)
4144
position += 1
4245

43-
names = {' '.join(val['name'].split(',')[::-1]).strip() for val in author_matches}
46+
names = {" ".join(val["name"].split(",")[::-1]).strip() for val in author_matches}
4447
for missing_name in first_last:
4548
if missing_name not in names:
4649
missing = sorted_authors[first_last.index(missing_name)]
47-
missing['position'] = position
50+
missing["position"] = position
4851
author_matches.append(missing)
4952
position += 1
5053

51-
all_names = [val['name'] for val in author_matches]
54+
all_names = [val["name"] for val in author_matches]
5255
for last_author in last:
53-
author_matches[all_names.index(last_author)]['position'] = position
56+
author_matches[all_names.index(last_author)]["position"] = position
5457
position += 1
5558

56-
author_matches = sorted(author_matches, key=lambda k: k['position'])
59+
author_matches = sorted(author_matches, key=lambda k: k["position"])
5760

5861
return author_matches, unmatched
5962

6063

61-
def get_git_lines(fname='line-contributors.txt'):
64+
def get_git_lines(fname="line-contributors.txt"):
6265
"""Run git-line-summary."""
6366
import shutil
6467
import subprocess as sp
68+
6569
contrib_file = Path(fname)
6670

6771
lines = []
6872
if contrib_file.exists():
69-
print('WARNING: Reusing existing line-contributors.txt file.', file=sys.stderr)
73+
print("WARNING: Reusing existing line-contributors.txt file.", file=sys.stderr)
7074
lines = contrib_file.read_text().splitlines()
7175

72-
git_line_summary_path = shutil.which('git-line-summary')
76+
git_line_summary_path = shutil.which("git-line-summary")
7377
if not lines and git_line_summary_path:
7478
print("Running git-line-summary on repo")
7579
lines = sp.check_output([git_line_summary_path]).decode().splitlines()
7680
lines = [l for l in lines if "Not Committed Yet" not in l]
77-
contrib_file.write_text('\n'.join(lines))
81+
contrib_file.write_text("\n".join(lines))
7882

7983
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+
raise RuntimeError(
85+
"""\
86+
Could not find line-contributors from git repository.%s"""
87+
% """ \
88+
git-line-summary not found, please install git-extras. """
89+
* (git_line_summary_path is None)
90+
)
91+
return [" ".join(line.strip().split()[1:-1]) for line in lines if "%" in line]
8492

8593

86-
if __name__ == '__main__':
94+
if __name__ == "__main__":
8795
data = get_git_lines()
8896

89-
zenodo_file = Path('.zenodo.json')
97+
zenodo_file = Path(".zenodo.json")
9098
zenodo = json.loads(zenodo_file.read_text())
9199

92-
creators = json.loads(Path('.maint/developers.json').read_text())
100+
creators = json.loads(Path(".maint/developers.json").read_text())
93101
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())
102+
creators,
103+
data,
104+
exclude=json.loads(Path(".maint/former.json").read_text()),
105+
last=CREATORS_LAST,
106+
)
107+
contributors = json.loads(Path(".maint/contributors.json").read_text())
98108
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)
109+
contributors,
110+
data,
111+
exclude=json.loads(Path(".maint/former.json").read_text()),
112+
last=CONTRIBUTORS_LAST,
113+
)
114+
zenodo["creators"] = zen_creators
115+
zenodo["contributors"] = zen_contributors
116+
117+
print(
118+
"Some people made commits, but are missing in .maint/ "
119+
"files: %s." % ", ".join(set(miss_creators).intersection(miss_contributors)),
120+
file=sys.stderr,
121+
)
108122

109123
# 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))
124+
for creator in zenodo["creators"]:
125+
del creator["position"]
126+
if isinstance(creator["affiliation"], list):
127+
creator["affiliation"] = creator["affiliation"][0]
128+
129+
for creator in zenodo["contributors"]:
130+
creator["type"] = "Researcher"
131+
del creator["position"]
132+
if isinstance(creator["affiliation"], list):
133+
creator["affiliation"] = creator["affiliation"][0]
134+
135+
zenodo_file.write_text("%s\n" % json.dumps(zenodo, indent=2))

dmriprep/__about__.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
33
"""Base module variables."""
44
from ._version import get_versions
5-
__version__ = get_versions()['version']
5+
6+
__version__ = get_versions()["version"]
67
del get_versions
78

8-
__packagename__ = 'dmriprep'
9-
__copyright__ = 'Copyright 2019, The dMRIPrep developers'
10-
__credits__ = ('Contributors: please check the ``.zenodo.json`` file at the top-level folder'
11-
'of the repository')
12-
__url__ = 'https://github.com/nipreps/dmriprep'
9+
__packagename__ = "dmriprep"
10+
__copyright__ = "Copyright 2019, The dMRIPrep developers"
11+
__credits__ = (
12+
"Contributors: please check the ``.zenodo.json`` file at the top-level folder"
13+
"of the repository"
14+
)
15+
__url__ = "https://github.com/nipreps/dmriprep"
1316

14-
DOWNLOAD_URL = (
15-
'https://github.com/nipreps/{name}/archive/{ver}.tar.gz'.format(
16-
name=__packagename__, ver=__version__))
17+
DOWNLOAD_URL = "https://github.com/nipreps/{name}/archive/{ver}.tar.gz".format(
18+
name=__packagename__, ver=__version__
19+
)
1720

1821
__ga_id__ = "UA-156165436-1"

dmriprep/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
)
88

99
__all__ = [
10-
'__version__',
11-
'__copyright__',
12-
'__credits__',
13-
'__packagename__',
10+
"__version__",
11+
"__copyright__",
12+
"__credits__",
13+
"__packagename__",
1414
]

dmriprep/cli/parser.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def _min_one(value, parser):
3434
def _to_gb(value):
3535
scale = {"G": 1, "T": 10 ** 3, "M": 1e-3, "K": 1e-6, "B": 1e-9}
3636
digits = "".join([c for c in value if c.isdigit()])
37-
units = value[len(digits):] or "M"
37+
units = value[len(digits) :] or "M"
3838
return int(digits) * scale[units[0]]
3939

4040
def _drop_sub(value):
@@ -115,9 +115,12 @@ def _bids_filter(value):
115115
"(https://github.com/bids-standard/pybids/blob/master/bids/layout/config/bids.json)",
116116
)
117117
g_bids.add_argument(
118-
"--anat-derivatives", action='store', metavar="PATH", type=PathExists,
118+
"--anat-derivatives",
119+
action="store",
120+
metavar="PATH",
121+
type=PathExists,
119122
help="Reuse the anatomical derivatives from another fMRIPrep run or calculated "
120-
"with an alternative processing tool (NOT RECOMMENDED)."
123+
"with an alternative processing tool (NOT RECOMMENDED).",
121124
)
122125

123126
g_perfm = parser.add_argument_group("Options to handle performance")

dmriprep/cli/run.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def main():
102102
25,
103103
"Works derived from this dMRIPrep execution should "
104104
"include the following boilerplate: "
105-
f"{config.execution.output_dir / 'dmriprep' / 'logs' / 'CITATION.md'}."
105+
f"{config.execution.output_dir / 'dmriprep' / 'logs' / 'CITATION.md'}.",
106106
)
107107

108108
if config.workflow.run_reconall:

0 commit comments

Comments
 (0)