Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STY: Apply pyupgrade suggestions #3147

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions fmriprep/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ def _slice_time_ref(value, parser):
is_release = not any((currentv.is_devrelease, currentv.is_prerelease, currentv.is_postrelease))

parser = ArgumentParser(
description="fMRIPrep: fMRI PREProcessing workflows v{}".format(
config.environment.version
),
description=f"fMRIPrep: fMRI PREProcessing workflows v{config.environment.version}",
formatter_class=ArgumentDefaultsHelpFormatter,
**kwargs,
)
Expand Down
2 changes: 1 addition & 1 deletion fmriprep/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Loader:
.. automethod:: cached
"""

def __init__(self, anchor: Union[str, ModuleType]):
def __init__(self, anchor: str | ModuleType):
self._anchor = anchor
self.files = files(anchor)
self.exit_stack = ExitStack()
Expand Down
17 changes: 8 additions & 9 deletions fmriprep/interfaces/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,9 @@
if counts:
header = '\t\t<ul class="elem-desc">'
footer = '\t\t</ul>'
s = '' if n_runs == 1 else 's'

Check warning on line 172 in fmriprep/interfaces/reports.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/interfaces/reports.py#L172

Added line #L172 was not covered by tests
lines = [
'\t\t\t<li>Task: {task_id} ({n_runs:d} run{s})</li>'.format(
task_id=task_id, n_runs=n_runs, s='' if n_runs == 1 else 's'
)
f'\t\t\t<li>Task: {task_id} ({n_runs:d} run{s})</li>'
for task_id, n_runs in sorted(counts.items())
]
tasks = '\n'.join([header] + lines + [footer])
Expand Down Expand Up @@ -255,20 +254,20 @@

pedir = get_world_pedir(self.inputs.orientation, self.inputs.pe_direction)

dummy_scan_tmp = "{n_dum}"
dummy_scan_tmp = f"{n_dum}"

Check warning on line 257 in fmriprep/interfaces/reports.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/interfaces/reports.py#L257

Added line #L257 was not covered by tests
if self.inputs.dummy_scans == self.inputs.algo_dummy_scans:
dummy_scan_msg = ' '.join(
[dummy_scan_tmp, "(Confirmed: {n_alg} automatically detected)"]
).format(n_dum=self.inputs.dummy_scans, n_alg=self.inputs.algo_dummy_scans)
[dummy_scan_tmp, f"(Confirmed: {self.inputs.algo_dummy_scans} automatically detected)"]
)
# the number of dummy scans was specified by the user and
# it is not equal to the number detected by the algorithm
elif self.inputs.dummy_scans is not None:
dummy_scan_msg = ' '.join(
[dummy_scan_tmp, "(Warning: {n_alg} automatically detected)"]
).format(n_dum=self.inputs.dummy_scans, n_alg=self.inputs.algo_dummy_scans)
[dummy_scan_tmp, f"(Warning: {self.inputs.algo_dummy_scans} automatically detected)"]
)
# the number of dummy scans was not specified by the user
else:
dummy_scan_msg = dummy_scan_tmp.format(n_dum=self.inputs.algo_dummy_scans)
dummy_scan_msg = dummy_scan_tmp

Check warning on line 270 in fmriprep/interfaces/reports.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/interfaces/reports.py#L270

Added line #L270 was not covered by tests

multiecho = "Single-echo EPI sequence."
n_echos = len(self.inputs.echo_idx)
Expand Down
4 changes: 2 additions & 2 deletions fmriprep/interfaces/workbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,15 @@
if opt in ("current_area", "new_area"):
if not self.inputs.area_surfs and not self.inputs.area_metrics:
raise ValueError(
"{} was set but neither area_surfs or" " area_metrics were set".format(opt)
f"{opt} was set but neither area_surfs or area_metrics were set"
)
if opt == "method":
if (
val == "ADAP_BARY_AREA"
and not self.inputs.area_surfs
and not self.inputs.area_metrics
):
raise ValueError("Exactly one of area_surfs or area_metrics" " must be specified")
raise ValueError("Exactly one of area_surfs or area_metrics must be specified")

Check warning on line 293 in fmriprep/interfaces/workbench.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/interfaces/workbench.py#L293

Added line #L293 was not covered by tests
if opt == "valid_roi_out" and val:
# generate a filename and add it to argstr
roi_out = self._gen_filename(self.inputs.in_file, suffix="_roi")
Expand Down
3 changes: 2 additions & 1 deletion fmriprep/utils/asynctools.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
from typing import Callable, TypeVar
from typing import TypeVar
from collections.abc import Callable

R = TypeVar('R')

Expand Down
2 changes: 1 addition & 1 deletion fmriprep/utils/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def check_pipeline_version(pipeline_name, cvers, data_desc):
# Very old style
dvers = desc.get("PipelineDescription", {}).get("Version", "0+unknown")
if Version(cvers).public != Version(dvers).public:
return "Previous output generated by version {} found.".format(dvers)
return f"Previous output generated by version {dvers} found."


def extract_entities(file_list):
Expand Down
36 changes: 14 additions & 22 deletions fmriprep/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,18 @@
from fmriprep.workflows.bold.base import init_bold_wf

workflow = Workflow(name=f'sub_{subject_id}_wf')
workflow.__desc__ = """
workflow.__desc__ = f"""

Check warning on line 171 in fmriprep/workflows/base.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/workflows/base.py#L171

Added line #L171 was not covered by tests
Results included in this manuscript come from preprocessing
performed using *fMRIPrep* {fmriprep_ver}
performed using *fMRIPrep* {config.environment.version}
(@fmriprep1; @fmriprep2; RRID:SCR_016216),
which is based on *Nipype* {nipype_ver}
which is based on *Nipype* {config.environment.nipype_version}
(@nipype1; @nipype2; RRID:SCR_002502).

""".format(
fmriprep_ver=config.environment.version, nipype_ver=config.environment.nipype_version
)
workflow.__postdesc__ = """
"""
workflow.__postdesc__ = f"""

Check warning on line 179 in fmriprep/workflows/base.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/workflows/base.py#L179

Added line #L179 was not covered by tests

Many internal operations of *fMRIPrep* use
*Nilearn* {nilearn_ver} [@nilearn, RRID:SCR_001362],
*Nilearn* {NILEARN_VERSION} [@nilearn, RRID:SCR_001362],
mostly within the functional processing workflow.
For more details of the pipeline, see [the section corresponding
to workflows in *fMRIPrep*'s documentation]\
Expand All @@ -199,9 +197,7 @@

### References

""".format(
nilearn_ver=NILEARN_VERSION
)
"""

subject_data = collect_data(
config.execution.layout,
Expand All @@ -219,12 +215,10 @@
anat_only = config.workflow.anat_only
# Make sure we always go through these two checks
if not anat_only and not subject_data['bold']:
task_id = config.execution.task_id
task_id = config.execution.task_id or '<all>'

Check warning on line 218 in fmriprep/workflows/base.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/workflows/base.py#L218

Added line #L218 was not covered by tests
raise RuntimeError(
"No BOLD images found for participant {} and task {}. "
"All workflows require BOLD images.".format(
subject_id, task_id if task_id else '<all>'
)
f"No BOLD images found for participant {subject_id} and "
f"task {task_id}. All workflows require BOLD images."
)

bold_runs = [
Expand Down Expand Up @@ -613,14 +607,12 @@

# Append the functional section to the existing anatomical excerpt
# That way we do not need to stream down the number of bold datasets
func_pre_desc = """
func_pre_desc = f"""

Check warning on line 610 in fmriprep/workflows/base.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/workflows/base.py#L610

Added line #L610 was not covered by tests
Functional data preprocessing

: For each of the {num_bold} BOLD runs found per subject (across all
tasks and sessions), the following preprocessing was performed.
""".format(
num_bold=len(bold_runs)
)
: For each of the {len(bold_runs)} BOLD runs found per subject (across
all tasks and sessions), the following preprocessing was performed.
"""

for bold_series in bold_runs:
bold_file = bold_series[0]
Expand Down
Loading