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 ruff/pyupgrade rule UP031 #3280

Merged
merged 8 commits into from
May 4, 2024
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)])
)
)
20 changes: 11 additions & 9 deletions .maint/update_authors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -274,18 +274,20 @@ def _aslist(value):

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(
[
'{} \\ :sup:`{}`\\ '.format(i['name'], idx)
DimitriPapadopoulos marked this conversation as resolved.
Show resolved Hide resolved
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')
10 changes: 5 additions & 5 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
f'Please modify the output path (suggestion: {bids_dir}).'
/ 'derivatives'
DimitriPapadopoulos marked this conversation as resolved.
Show resolved Hide resolved
/ ('fmriprep-%s' % version.split('+')[0])
/ ('fmriprep-{}'.format(version.split('+')[0]))
DimitriPapadopoulos marked this conversation as resolved.
Show resolved Hide resolved
)

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 @@
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')}

Check warning on line 176 in fmriprep/cli/workflow.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/cli/workflow.py#L176

Added line #L176 was not covered by tests
DimitriPapadopoulos marked this conversation as resolved.
Show resolved Hide resolved

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 @@
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

Check warning on line 69 in fmriprep/utils/bids.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/utils/bids.py#L69

Added line #L69 was not covered by tests

for xfm, q in spec['transforms'].items():
query = {**q, **entities}
Expand Down Expand Up @@ -237,7 +237,7 @@
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}/**')

Check warning on line 240 in fmriprep/utils/bids.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/utils/bids.py#L240

Added line #L240 was not covered by tests
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