Skip to content

Commit 74192fb

Browse files
authored
STY: Lint and style check full repository (#3221)
Including the wrapper here. No upgrades permitted, to maintain Python 2 compatibility.
2 parents d9ff1cb + 44ff6d0 commit 74192fb

File tree

9 files changed

+67
-26
lines changed

9 files changed

+67
-26
lines changed

.git-blame-ignore-revs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# 2024-02-05 - [email protected] - STY: ruff --fix + 1 ignore [git-blame-ignore-rev]
2+
e7dc59fbc7df88dfabbff154f4cc3d24721b6b4f
13
# 2024-01-16 - [email protected] - STY: ruff --fix --unsafe-fixes (with cleanup) [git-blame-ignore-rev]
24
66734bd0164d1dae3cf299fa9d9d682c22eeda66
35
# 2024-01-16 - [email protected] - STY: ruff format and ruff --fix [git-blame-ignore-rev]

.github/workflows/contrib.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ jobs:
2626
runs-on: ubuntu-latest
2727
steps:
2828
- uses: actions/checkout@v4
29-
- run: pipx run ruff fmriprep
30-
- run: pipx run ruff format --diff fmriprep
29+
- run: pipx run ruff .
30+
- run: pipx run ruff format --diff .
3131

3232
codespell:
3333
name: Check for spelling errors

.maint/paper_author_list.py

100644100755
File mode changed.

.maint/update_authors.py

100644100755
File mode changed.

fmriprep/cli/workflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def build_boilerplate(config_file, workflow):
215215

216216
config.loggers.cli.info('Generating an HTML version of the citation boilerplate...')
217217
try:
218-
check_call(cmd, timeout=10) # noqa: S603
218+
check_call(cmd, timeout=10)
219219
except (FileNotFoundError, CalledProcessError, TimeoutExpired):
220220
config.loggers.cli.warning('Could not generate CITATION.html file:\n%s', ' '.join(cmd))
221221

@@ -232,6 +232,6 @@ def build_boilerplate(config_file, workflow):
232232
]
233233
config.loggers.cli.info('Generating a LaTeX version of the citation boilerplate...')
234234
try:
235-
check_call(cmd, timeout=10) # noqa: S603
235+
check_call(cmd, timeout=10)
236236
except (FileNotFoundError, CalledProcessError, TimeoutExpired):
237237
config.loggers.cli.warning('Could not generate CITATION.tex file:\n%s', ' '.join(cmd))

fmriprep/utils/bids.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def validate_input_dir(exec_env, bids_dir, participant_label, need_T1w=True):
233233
temp.write(json.dumps(validator_config_dict))
234234
temp.flush()
235235
try:
236-
subprocess.check_call(['bids-validator', str(bids_dir), '-c', temp.name]) # noqa: S603, S607
236+
subprocess.check_call(['bids-validator', str(bids_dir), '-c', temp.name]) # noqa: S607
237237
except FileNotFoundError:
238238
print('bids-validator does not appear to be installed', file=sys.stderr)
239239

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ extend-select = [
176176
extend-ignore = [
177177
"S311", # We are not using random for cryptographic purposes
178178
"ISC001",
179+
"S603",
179180
]
180181

181182
[tool.ruff.lint.flake8-quotes]
@@ -185,6 +186,7 @@ inline-quotes = "single"
185186
"*/test_*.py" = ["S101"]
186187
"fmriprep/utils/debug.py" = ["A002", "T100"]
187188
"docs/conf.py" = ["A001"]
189+
"docs/sphinxext/github_link.py" = ["BLE001"]
188190

189191
[tool.ruff.format]
190192
quote-style = "single"

wrapper/pyproject.toml

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,47 @@ universal = true
6363
# Developer tool configurations
6464
#
6565

66+
# Disable black
6667
[tool.black]
68+
exclude = ".*"
69+
70+
[tool.ruff]
6771
line-length = 99
68-
target-version = ['py39']
69-
skip-string-normalization = true
7072

71-
[tool.isort]
72-
profile = 'black'
73+
[tool.ruff.lint]
74+
extend-select = [
75+
"F",
76+
"E",
77+
"W",
78+
"I",
79+
"YTT",
80+
"BLE",
81+
"B",
82+
"A",
83+
# "CPY",
84+
"C4",
85+
"DTZ",
86+
"T10",
87+
# "EM",
88+
"EXE",
89+
"FA",
90+
"ISC",
91+
"ICN",
92+
"PT",
93+
"Q",
94+
]
95+
extend-ignore = [
96+
"S311", # We are not using random for cryptographic purposes
97+
"ISC001",
98+
]
99+
100+
[tool.ruff.lint.flake8-quotes]
101+
inline-quotes = "single"
102+
103+
[tool.ruff.lint.extend-per-file-ignores]
104+
"*/test_*.py" = ["S101"]
105+
"fmriprep/utils/debug.py" = ["A002", "T100"]
106+
"docs/conf.py" = ["A001"]
107+
108+
[tool.ruff.format]
109+
quote-style = "single"

wrapper/src/fmriprep_docker/__main__.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def _run(args, stdout=None, stderr=None):
9393

9494
# De-fang Python 2's input - we don't eval user input
9595
try:
96-
input = raw_input
96+
input = raw_input # noqa: A001
9797
except NameError:
9898
pass
9999

@@ -116,7 +116,7 @@ def check_docker():
116116
if e.errno == ENOENT:
117117
return -1
118118
raise e
119-
if ret.stderr.startswith(b"Cannot connect to the Docker daemon."):
119+
if ret.stderr.startswith(b'Cannot connect to the Docker daemon.'):
120120
return 0
121121
return 1
122122

@@ -154,11 +154,11 @@ def _get_posargs(usage):
154154
line = targ.lstrip()
155155
if line.startswith('usage'):
156156
continue
157-
if line[0].isalnum() or line[0] == "{":
157+
if line[0].isalnum() or line[0] == '{':
158158
posargs.append(line)
159-
elif line[0] == '[' and (line[1].isalnum() or line[1] == "{"):
159+
elif line[0] == '[' and (line[1].isalnum() or line[1] == '{'):
160160
posargs.append(line)
161-
return " ".join(posargs)
161+
return ' '.join(posargs)
162162

163163
# Matches all flags with up to two nested square brackets
164164
# I'm sorry.
@@ -203,7 +203,7 @@ def _get_posargs(usage):
203203
'w',
204204
}
205205

206-
assert overlap == expected_overlap, "Clobbering options: {}".format(
206+
assert overlap == expected_overlap, 'Clobbering options: {}'.format(
207207
', '.join(overlap - expected_overlap)
208208
)
209209

@@ -263,15 +263,15 @@ class ToDict(argparse.Action):
263263
def __call__(self, parser, namespace, values, option_string=None):
264264
d = {}
265265
for kv in values:
266-
k, v = kv.split("=")
266+
k, v = kv.split('=')
267267
d[k] = os.path.abspath(v)
268268
setattr(namespace, self.dest, d)
269269

270270
def _is_file(path, parser):
271271
"""Ensure a given path exists and it is a file."""
272272
path = os.path.abspath(path)
273273
if not os.path.isfile(path):
274-
raise parser.error("Path should point to a file (or symlink of file): <%s>." % path)
274+
raise parser.error('Path should point to a file (or symlink of file): <%s>.' % path)
275275
return path
276276

277277
parser = argparse.ArgumentParser(
@@ -288,7 +288,7 @@ def _is_file(path, parser):
288288
)
289289

290290
parser.add_argument(
291-
'-h', '--help', action='store_true', help="show this help message and exit"
291+
'-h', '--help', action='store_true', help='show this help message and exit'
292292
)
293293
parser.add_argument(
294294
'--version', action='store_true', help="show program's version number and exit"
@@ -319,7 +319,7 @@ def _is_file(path, parser):
319319
)
320320
g_wrap.add_argument(
321321
'--output-spaces',
322-
nargs="*",
322+
nargs='*',
323323
)
324324

325325
g_wrap.add_argument(
@@ -370,8 +370,8 @@ def _is_file(path, parser):
370370
)
371371
g_dev.add_argument(
372372
'--patch',
373-
nargs="+",
374-
metavar="PACKAGE=PATH",
373+
nargs='+',
374+
metavar='PACKAGE=PATH',
375375
action=ToDict,
376376
help='Sequence of PACKAGE=PATH specifications to patch a Python package into the '
377377
'container Python environment.',
@@ -431,7 +431,7 @@ def main():
431431
if opts.help:
432432
parser.print_help()
433433
if check == -1:
434-
print("fmriprep: Could not find docker command... Is it installed?")
434+
print('fmriprep: Could not find docker command... Is it installed?')
435435
else:
436436
print("fmriprep: Make sure you have permission to run 'docker'")
437437
return 1
@@ -477,7 +477,7 @@ def main():
477477
return 0
478478

479479
ret = subprocess.run(
480-
['docker', 'version', '--format', "{{.Server.Version}}"], stdout=subprocess.PIPE
480+
['docker', 'version', '--format', '{{.Server.Version}}'], stdout=subprocess.PIPE
481481
)
482482
docker_version = ret.stdout.decode('ascii').strip()
483483

@@ -566,7 +566,7 @@ def main():
566566
if space.split(':')[0] not in (TF_TEMPLATES + NONSTANDARD_REFERENCES):
567567
tpl = os.path.basename(space)
568568
if not tpl.startswith('tpl-'):
569-
raise RuntimeError("Custom template %s requires a `tpl-` prefix" % tpl)
569+
raise RuntimeError('Custom template %s requires a `tpl-` prefix' % tpl)
570570
target = '/home/fmriprep/.cache/templateflow/' + tpl
571571
command.extend(['-v', ':'.join((os.path.abspath(space), target, 'ro'))])
572572
spaces.append(tpl[4:])
@@ -599,10 +599,10 @@ def main():
599599
command.extend(main_args)
600600
command.extend(unknown_args)
601601

602-
print("RUNNING: " + ' '.join(command))
602+
print('RUNNING: ' + ' '.join(command))
603603
ret = subprocess.run(command)
604604
if ret.returncode:
605-
print("fMRIPrep: Please report errors to {}".format(__bugreports__))
605+
print('fMRIPrep: Please report errors to {}'.format(__bugreports__))
606606
return ret.returncode
607607

608608

0 commit comments

Comments
 (0)