diff --git a/smriprep/__main__.py b/smriprep/__main__.py index a749a3d377..0a44693454 100644 --- a/smriprep/__main__.py +++ b/smriprep/__main__.py @@ -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() diff --git a/smriprep/interfaces/cifti.py b/smriprep/interfaces/cifti.py index c36e012751..4db8211766 100644 --- a/smriprep/interfaces/cifti.py +++ b/smriprep/interfaces/cifti.py @@ -117,7 +117,7 @@ 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": ( @@ -125,8 +125,8 @@ def _prepare_cifti(grayordinates: str) -> ty.Tuple[list, dict]: 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 diff --git a/smriprep/utils/bids.py b/smriprep/utils/bids.py index 9f3d6c9293..a9ac82e031 100644 --- a/smriprep/utils/bids.py +++ b/smriprep/utils/bids.py @@ -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(): diff --git a/smriprep/workflows/anatomical.py b/smriprep/workflows/anatomical.py index 738ec03941..e325960410 100644 --- a/smriprep/workflows/anatomical.py +++ b/smriprep/workflows/anatomical.py @@ -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 +BIDS dataset.""" inputnode = pe.Node( niu.IdentityInterface(fields=["t1w", "t2w", "roi", "flair", "subjects_dir", "subject_id"]), diff --git a/smriprep/workflows/base.py b/smriprep/workflows/base.py index 9ef3884b2f..21b5155a76 100644 --- a/smriprep/workflows/base.py +++ b/smriprep/workflows/base.py @@ -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: @@ -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, @@ -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 diff --git a/smriprep/workflows/norm.py b/smriprep/workflows/norm.py index 46f89d5bf4..bf8b965688 100644 --- a/smriprep/workflows/norm.py +++ b/smriprep/workflows/norm.py @@ -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), ), @@ -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( diff --git a/wrapper/smriprep_docker.py b/wrapper/smriprep_docker.py index 4ccf0d12f9..526e2cca4e 100755 --- a/wrapper/smriprep_docker.py +++ b/wrapper/smriprep_docker.py @@ -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", ) @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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