Skip to content

Commit

Permalink
STY: Apply pyupgrade suggestions (#3043)
Browse files Browse the repository at this point in the history
pyupgrade --py38-plus
  • Loading branch information
DimitriPapadopoulos committed Jun 19, 2023
1 parent 822e44a commit 01a13ca
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 28 deletions.
4 changes: 1 addition & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# fmriprep documentation build configuration file, created by
# sphinx-quickstart on Mon May 9 09:04:25 2016.
#
Expand Down Expand Up @@ -87,7 +85,7 @@
# General information about the project.
project = "fmriprep"
author = "The fMRIPrep developers"
copyright = "2016-%s, %s" % (datetime.now().year, author)
copyright = f"2016-{datetime.now().year}, {author}"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down
2 changes: 1 addition & 1 deletion fmriprep/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@

# `python -m <module>` typically displays the command as __main__.py
if '__main__.py' in sys.argv[0]:
sys.argv[0] = '%s -m %s' % (sys.executable, module)
sys.argv[0] = f'{sys.executable} -m {module}'
main()
5 changes: 1 addition & 4 deletions fmriprep/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,7 @@ def main():
from ..utils.telemetry import process_crashfile

crashfolders = [
config.execution.fmriprep_dir
/ "sub-{}".format(s)
/ "log"
/ config.execution.run_uuid
config.execution.fmriprep_dir / f"sub-{s}" / "log" / config.execution.run_uuid
for s in config.execution.participant_label
]
for crashfolder in crashfolders:
Expand Down
9 changes: 3 additions & 6 deletions fmriprep/cli/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,10 @@ def _mock_check_latest(*args, **kwargs):
_build_parser()
captured = capsys.readouterr().err

msg = """\
You are using fMRIPrep-%s, and a newer version of fMRIPrep is available: %s.
msg = f"""\
You are using fMRIPrep-{current}, and a newer version of fMRIPrep is available: {latest}.
Please check out our documentation about how and when to upgrade:
https://fmriprep.readthedocs.io/en/latest/faq.html#upgrading""" % (
current,
latest,
)
https://fmriprep.readthedocs.io/en/latest/faq.html#upgrading"""

assert (msg in captured) is expectation

Expand Down
1 change: 0 additions & 1 deletion fmriprep/interfaces/gifti.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""Interfaces for manipulating GIFTI files."""
Expand Down
2 changes: 1 addition & 1 deletion fmriprep/interfaces/multiecho.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class T2SMap(CommandLine):
def _format_arg(self, name, trait_spec, value):
if name == 'echo_times':
value = [te * 1000 for te in value]
return super(T2SMap, self)._format_arg(name, trait_spec, value)
return super()._format_arg(name, trait_spec, value)

def _list_outputs(self):
outputs = self._outputs().get()
Expand Down
4 changes: 2 additions & 2 deletions fmriprep/interfaces/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _run_interface(self, runtime):
failures = 0
while True:
try:
runtime = super(RobustACompCor, self)._run_interface(runtime)
runtime = super()._run_interface(runtime)
break
except LinAlgError:
failures += 1
Expand All @@ -67,7 +67,7 @@ def _run_interface(self, runtime):
failures = 0
while True:
try:
runtime = super(RobustTCompCor, self)._run_interface(runtime)
runtime = super()._run_interface(runtime)
break
except LinAlgError:
failures += 1
Expand Down
4 changes: 2 additions & 2 deletions fmriprep/interfaces/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class SubjectSummary(SummaryInterface):
def _run_interface(self, runtime):
if isdefined(self.inputs.subject_id):
self._results['subject_id'] = self.inputs.subject_id
return super(SubjectSummary, self)._run_interface(runtime)
return super()._run_interface(runtime)

def _generate_segment(self):
BIDS_NAME = re.compile(
Expand Down Expand Up @@ -159,7 +159,7 @@ def _generate_segment(self):

t2w_seg = ''
if self.inputs.t2w:
t2w_seg = '(+ {:d} T2-weighted)'.format(len(self.inputs.t2w))
t2w_seg = f'(+ {len(self.inputs.t2w):d} T2-weighted)'

# Add list of tasks with number of runs
bold_series = self.inputs.bold if isdefined(self.inputs.bold) else []
Expand Down
3 changes: 1 addition & 2 deletions fmriprep/interfaces/workbench.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""This module provides interfaces for workbench surface commands."""
Expand Down Expand Up @@ -297,7 +296,7 @@ def _format_arg(self, opt, spec, val):
roi_out = self._gen_filename(self.inputs.in_file, suffix="_roi")
iflogger.info("Setting roi output file as", roi_out)
spec.argstr += " " + roi_out
return super(MetricResample, self)._format_arg(opt, spec, val)
return super()._format_arg(opt, spec, val)

def _list_outputs(self):
outputs = super()._list_outputs()
Expand Down
2 changes: 1 addition & 1 deletion fmriprep/reports/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _load_config(self, config):
# In this version, pass reportlets_dir and out_dir with fmriprep in the path.

if self.subject_id is not None:
self.root = self.root / "sub-{}".format(self.subject_id)
self.root = self.root / f"sub-{self.subject_id}"

if "template_path" in settings:
self.template_path = config.parent / settings["template_path"]
Expand Down
4 changes: 2 additions & 2 deletions fmriprep/utils/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ def validate_input_dir(exec_env, bids_dir, participant_label):
}
# Limit validation only to data from requested participants
if participant_label:
all_subs = set([s.name[4:] for s in bids_dir.glob('sub-*')])
selected_subs = set([s[4:] if s.startswith('sub-') else s for s in participant_label])
all_subs = {s.name[4:] for s in bids_dir.glob('sub-*')}
selected_subs = {s[4:] if s.startswith('sub-') else s for s in participant_label}
bad_labels = selected_subs.difference(all_subs)
if bad_labels:
error_msg = (
Expand Down
2 changes: 1 addition & 1 deletion fmriprep/utils/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def process_crashfile(crashfile):
scope.set_extra('%s_%02d' % (k, i), chunk)

fingerprint = ''
issue_title = '{}: {}'.format(node_name, gist)
issue_title = f'{node_name}: {gist}'
for new_fingerprint, error_snippets in KNOWN_ERRORS.items():
for error_snippet in error_snippets:
if error_snippet in traceback:
Expand Down
3 changes: 1 addition & 2 deletions fmriprep/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ def init_single_subject_wf(subject_id: str):

if not anat_derivatives and not subject_data['t1w']:
raise Exception(
"No T1w images found for participant {}. "
"All workflows require T1w images.".format(subject_id)
f"No T1w images found for participant {subject_id}. All workflows require T1w images."
)

if subject_data['roi']:
Expand Down

0 comments on commit 01a13ca

Please sign in to comment.