Skip to content

Commit

Permalink
STY: Apply ruff/pyupgrade rule UP031 (#3280)
Browse files Browse the repository at this point in the history
New in [ruff
v0.4.2](https://github.com/astral-sh/ruff/releases/tag/v0.4.2).

---------

Co-authored-by: Chris Markiewicz <[email protected]>
  • Loading branch information
DimitriPapadopoulos and effigies authored May 4, 2024
1 parent 1e45712 commit 3cbf147
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 38 deletions.
23 changes: 13 additions & 10 deletions .maint/paper_author_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,26 @@ def _aslist(inlist):
]

print(
'Some people made commits, but are missing in .maint/ '
'files: %s.' % ', '.join(unmatched),
'Some people made commits, but are missing in .maint/ files: {}.'.format(
', '.join(unmatched)
),
file=sys.stderr,
)

print('Authors (%d):' % len(author_matches))
print(
'%s.'
% '; '.join(
[
'{} \\ :sup:`{}`\\ '.format(i['name'], idx)
for i, idx in zip(author_matches, aff_indexes, strict=False)
]
'{}.'.format(
'; '.join(
[
rf'{i["name"]} \ :sup:`{idx}`\ '
for i, idx in zip(author_matches, aff_indexes, strict=False)
]
)
)
)

print(
'\n\nAffiliations:\n%s'
% '\n'.join([f'{i + 1: >2}. {a}' for i, a in enumerate(affiliations)])
'\n\nAffiliations:\n{}'.format(
'\n'.join([f'{i + 1: >2}. {a}' for i, a in enumerate(affiliations)])
)
)
24 changes: 13 additions & 11 deletions .maint/update_authors.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def zenodo(
misses = set(miss_creators).intersection(miss_contributors)
if misses:
print(
"Some people made commits, but are missing in .maint/ " f"files: {', '.join(misses)}",
f"Some people made commits, but are missing in .maint/ files: {', '.join(misses)}",
file=sys.stderr,
)

Expand All @@ -206,7 +206,7 @@ def zenodo(
if isinstance(creator['affiliation'], list):
creator['affiliation'] = creator['affiliation'][0]

Path(zenodo_file).write_text('%s\n' % json.dumps(zenodo, indent=2))
Path(zenodo_file).write_text(f'{json.dumps(zenodo, indent=2)}\n')


@cli.command()
Expand Down Expand Up @@ -268,24 +268,26 @@ def _aslist(value):

if misses:
print(
"Some people made commits, but are missing in .maint/ " f"files: {', '.join(misses)}",
f"Some people made commits, but are missing in .maint/ files: {', '.join(misses)}",
file=sys.stderr,
)

print('Authors (%d):' % len(hits))
print(
'%s.'
% '; '.join(
[
'{} \\ :sup:`{}`\\ '.format(i['name'], idx)
for i, idx in zip(hits, aff_indexes, strict=False)
]
'{}.'.format(
'; '.join(
[
rf'{i["name"]} \ :sup:`{idx}`\ '
for i, idx in zip(hits, aff_indexes, strict=False)
]
)
)
)

print(
'\n\nAffiliations:\n%s'
% '\n'.join([f'{i + 1: >2}. {a}' for i, a in enumerate(affiliations)])
'\n\nAffiliations:\n{}'.format(
'\n'.join([f'{i + 1: >2}. {a}' for i, a in enumerate(affiliations)])
)
)


Expand Down
7 changes: 4 additions & 3 deletions .maint/update_zenodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ def loads_contributors(s):
zenodo['contributors'] = zen_contributors

print(
'Some people made commits, but are missing in .maint/ '
'files: %s.' % ', '.join(set(miss_creators).intersection(miss_contributors)),
'Some people made commits, but are missing in .maint/ files: {}.'.format(
', '.join(set(miss_creators).intersection(miss_contributors))
),
file=sys.stderr,
)

Expand All @@ -162,4 +163,4 @@ def loads_contributors(s):
if isinstance(creator['affiliation'], list):
creator['affiliation'] = creator['affiliation'][0]

zenodo_file.write_text('%s\n' % json.dumps(zenodo, indent=2, ensure_ascii=False))
zenodo_file.write_text(f'{json.dumps(zenodo, indent=2, ensure_ascii=False)}\n')
12 changes: 6 additions & 6 deletions fmriprep/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,10 +881,9 @@ def parse_args(args=None, namespace=None):
if output_dir == bids_dir:
parser.error(
'The selected output folder is the same as the input BIDS folder. '
'Please modify the output path (suggestion: %s).'
% bids_dir
/ 'derivatives'
/ ('fmriprep-%s' % version.split('+')[0])
'Please modify the output path (suggestion: {}).'.format(
bids_dir / 'derivatives' / f'fmriprep-{version.split("+")[0]}'
)
)

if bids_dir in work_dir.parents:
Expand Down Expand Up @@ -924,8 +923,9 @@ def parse_args(args=None, namespace=None):
missing_subjects = participant_label - set(all_subjects)
if missing_subjects:
parser.error(
'One or more participant labels were not found in the BIDS directory: '
'%s.' % ', '.join(missing_subjects)
'One or more participant labels were not found in the BIDS directory: {}.'.format(
', '.join(missing_subjects)
)
)

config.execution.participant_label = sorted(participant_label)
Expand Down
2 changes: 1 addition & 1 deletion fmriprep/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def main():

config.loggers.workflow.log(
15,
'\n'.join(['fMRIPrep config:'] + ['\t\t%s' % s for s in config.dumps().splitlines()]),
'\n'.join(['fMRIPrep config:'] + [f'\t\t{s}' for s in config.dumps().splitlines()]),
)
config.loggers.workflow.log(25, 'fMRIPrep started!')
errno = 1 # Default is error exit unless otherwise set
Expand Down
4 changes: 1 addition & 3 deletions fmriprep/cli/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ def build_boilerplate(config_file, workflow):
config.load(config_file)
logs_path = config.execution.fmriprep_dir / 'logs'
boilerplate = workflow.visit_desc()
citation_files = {
ext: logs_path / ('CITATION.%s' % ext) for ext in ('bib', 'tex', 'md', 'html')
}
citation_files = {ext: logs_path / f'CITATION.{ext}' for ext in ('bib', 'tex', 'md', 'html')}

if boilerplate:
# To please git-annex users and also to guarantee consistency
Expand Down
4 changes: 2 additions & 2 deletions fmriprep/utils/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def collect_derivatives(
item = layout.get(return_type='filename', **query)
if not item:
continue
derivs_cache['%s_boldref' % k] = item[0] if len(item) == 1 else item
derivs_cache[f'{k}_boldref'] = item[0] if len(item) == 1 else item

for xfm, q in spec['transforms'].items():
query = {**q, **entities}
Expand Down Expand Up @@ -237,7 +237,7 @@ def validate_input_dir(exec_env, bids_dir, participant_label, need_T1w=True):
ignored_subs = all_subs.difference(selected_subs)
if ignored_subs:
for sub in ignored_subs:
validator_config_dict['ignoredFiles'].append('/sub-%s/**' % sub)
validator_config_dict['ignoredFiles'].append(f'/sub-{sub}/**')
with tempfile.NamedTemporaryFile(mode='w+', suffix='.json') as temp:
temp.write(json.dumps(validator_config_dict))
temp.flush()
Expand Down
2 changes: 1 addition & 1 deletion fmriprep/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def init_fmriprep_wf():
spaces=config.workflow.spaces.get_fs_spaces(),
minimum_fs_version='7.0.0',
),
name='fsdir_run_%s' % config.execution.run_uuid.replace('-', '_'),
name='fsdir_run_{}'.format(config.execution.run_uuid.replace('-', '_')),
run_without_submitting=True,
)
if config.execution.fs_subjects_dir is not None:
Expand Down
2 changes: 1 addition & 1 deletion fmriprep/workflows/bold/resampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def init_bold_surf_wf(
The BOLD time-series were resampled onto the following surfaces
(FreeSurfer reconstruction nomenclature):
{out_spaces}.
""".format(out_spaces=', '.join(['*%s*' % s for s in surface_spaces]))
""".format(out_spaces=', '.join([f'*{s}*' for s in surface_spaces]))

inputnode = pe.Node(
niu.IdentityInterface(
Expand Down

0 comments on commit 3cbf147

Please sign in to comment.