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

MNT: Use f-strings where possible #369

Closed
wants to merge 1 commit into from
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
2 changes: 1 addition & 1 deletion smriprep/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@

# `python -m smriprep` typically displays the command as __main__.py
if "__main__.py" in sys.argv[0]:
sys.argv[0] = "%s -m smriprep" % sys.executable
sys.argv[0] = f"{sys.executable} -m smriprep"
main()
6 changes: 3 additions & 3 deletions smriprep/interfaces/cifti.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@ def _prepare_cifti(grayordinates: str) -> ty.Tuple[list, dict]:

tf_url = "https://templateflow.s3.amazonaws.com"
surfaces_url = ( # midthickness is the default, but varying levels of inflation are all valid
f"{tf_url}/tpl-fsLR/tpl-fsLR_den-{surface_density}_hemi-%s_midthickness.surf.gii"
f"{tf_url}/tpl-fsLR/tpl-fsLR_den-{surface_density}_hemi-{{}}_midthickness.surf.gii" # noqa: E501
)
metadata = {
"Density": (
f"{total_grayords} grayordinates corresponding to all of the grey matter sampled at a "
f"{res_mm} average vertex spacing on the surface"
),
"SpatialReference": {
"CIFTI_STRUCTURE_CORTEX_LEFT": surfaces_url % "L",
"CIFTI_STRUCTURE_CORTEX_RIGHT": surfaces_url % "R",
"CIFTI_STRUCTURE_CORTEX_LEFT": surfaces_url.format("L"),
"CIFTI_STRUCTURE_CORTEX_RIGHT": surfaces_url.format("R"),
},
}
return surface_labels, metadata
Expand Down
4 changes: 2 additions & 2 deletions smriprep/utils/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ def _check_item(item):
return None

if space:
derivs_cache["std_%s" % k] += item if len(item) == 1 else [item]
derivs_cache[f"std_{k}"] += item if len(item) == 1 else [item]
else:
derivs_cache["t1w_%s" % k] = item[0] if len(item) == 1 else item
derivs_cache[f"t1w_{k}"] = item[0] if len(item) == 1 else item

for space in std_spaces:
for k, q in spec["std_xfms"].items():
Expand Down
10 changes: 3 additions & 7 deletions smriprep/workflows/anatomical.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,11 @@ def init_anat_preproc_wf(
"""
workflow = Workflow(name=name)
num_t1w = len(t1w)
desc = """
desc = f"""
Anatomical data preprocessing

: """
desc += """\
A total of {num_t1w} T1-weighted (T1w) images were found within the input
BIDS dataset.""".format(
num_t1w=num_t1w
)
: A total of {num_t1w} T1-weighted (T1w) images were found within the input
DimitriPapadopoulos marked this conversation as resolved.
Show resolved Hide resolved
BIDS dataset."""

inputnode = pe.Node(
niu.IdentityInterface(fields=["t1w", "t2w", "roi", "flair", "subjects_dir", "subject_id"]),
Expand Down
16 changes: 7 additions & 9 deletions smriprep/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def init_smriprep_wf(
freesurfer_home=os.getenv("FREESURFER_HOME"),
spaces=spaces.get_fs_spaces(),
),
name="fsdir_run_%s" % run_uuid.replace("-", "_"),
name="fsdir_run_{}".format(run_uuid.replace("-", "_")),
run_without_submitting=True,
)
if fs_subjects_dir is not None:
Expand All @@ -181,7 +181,7 @@ def init_smriprep_wf(
longitudinal=longitudinal,
low_mem=low_mem,
msm_sulc=msm_sulc,
name="single_subject_%s_wf" % subject_id,
name=f"single_subject_%{subject_id}_wf",
omp_nthreads=omp_nthreads,
output_dir=output_dir,
skull_strip_fixed_seed=skull_strip_fixed_seed,
Expand Down Expand Up @@ -329,21 +329,19 @@ def init_single_subject_wf(

if 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}. "
f"All workflows require T1w images."
)

workflow = Workflow(name=name)
workflow.__desc__ = """
workflow.__desc__ = f"""
Results included in this manuscript come from preprocessing
performed using *sMRIPprep* {smriprep_ver}
performed using *sMRIPprep* {__version__}
(@fmriprep1; @fmriprep2; RRID:SCR_016216),
which is based on *Nipype* {nipype_ver}
(@nipype1; @nipype2; RRID:SCR_002502).

""".format(
smriprep_ver=__version__, nipype_ver=nipype_ver
)
"""
workflow.__postdesc__ = """

For more details of the pipeline, see [the section corresponding
Expand Down
7 changes: 3 additions & 4 deletions smriprep/workflows/norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ def init_anat_norm_wf(
and accessed with *TemplateFlow* [{tf_ver}, @templateflow]:
""".format(
ants_ver=ANTsInfo.version() or "(version unknown)",
targets="%s standard space%s"
% (
targets="{} standard space{}".format(
defaultdict("several".format, {1: "one", 2: "two", 3: "three", 4: "four"})[ntpls],
"s" * (ntpls != 1),
),
Expand All @@ -148,10 +147,10 @@ def init_anat_norm_wf(
# Append template citations to description
for template in templates:
template_meta = get_metadata(template.split(":")[0])
template_refs = ["@%s" % template.split(":")[0].lower()]
template_refs = ["@{}".format(template.split(":")[0].lower())]

if template_meta.get("RRID", None):
template_refs += ["RRID:%s" % template_meta["RRID"]]
template_refs += ["RRID:{}".format(template_meta["RRID"])]

workflow.__desc__ += """\
*{template_name}* [{template_refs}; TemplateFlow ID: {template}]""".format(
Expand Down
14 changes: 7 additions & 7 deletions wrapper/smriprep_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def _is_file(path, parser):
"--image",
metavar="IMG",
type=str,
default="nipreps/smriprep:{}".format(__version__),
default=f"nipreps/smriprep:{__version__}",
help="image name",
)

Expand Down Expand Up @@ -356,7 +356,7 @@ def main():
check = check_docker()
if check < 1:
if opts.version:
print("smriprep wrapper {!s}".format(__version__))
print(f"smriprep wrapper {__version__}")
if opts.help:
parser.print_help()
if check == -1:
Expand All @@ -369,7 +369,7 @@ def main():
if not check_image(opts.image):
resp = "Y"
if opts.version:
print("smriprep wrapper {!s}".format(__version__))
print(f"smriprep wrapper {__version__}")
if opts.help:
parser.print_help()
if opts.version or opts.help:
Expand Down Expand Up @@ -424,7 +424,7 @@ def main():
# Patch working repositories into installed package directories
if opts.patch:
for pkg, repo_path in opts.patch.items():
command.extend(['-v', '{}:{}/{}:ro'.format(repo_path, PKG_PATH, pkg)])
command.extend(['-v', f'{repo_path}:{PKG_PATH}/{pkg}:ro'])

if opts.env:
for envvar in opts.env:
Expand All @@ -434,7 +434,7 @@ def main():
command.extend(["-u", opts.user])

if opts.fs_license_file:
command.extend(["-v", "{}:/opt/freesurfer/license.txt:ro".format(opts.fs_license_file)])
command.extend(["-v", f"{opts.fs_license_file}:/opt/freesurfer/license.txt:ro"]) # noqa: E501

main_args = []
if opts.bids_dir:
Expand All @@ -450,7 +450,7 @@ def main():
unknown_args.extend(["-w", "/scratch"])

if opts.fs_subjects_dir:
command.extend(['-v', '{}:/opt/subjects'.format(opts.fs_subjects_dir)])
command.extend(['-v', f'{opts.fs_subjects_dir}:/opt/subjects'])
unknown_args.extend(['--fs-subjects-dir', '/opt/subjects'])

if opts.config:
Expand Down Expand Up @@ -485,7 +485,7 @@ def main():
print("RUNNING: " + " ".join(command))
ret = subprocess.run(command)
if ret.returncode:
print("sMRIPrep: Please report errors to {}".format(__bugreports__))
print(f"sMRIPrep: Please report errors to {__bugreports__}")
return ret.returncode


Expand Down
Loading