Skip to content

STY: Enforce more ruff rules #3437

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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
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 .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repos:
- id: check-toml
- id: check-added-large-files
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.2
rev: v0.12.7
hooks:
- id: ruff-check
args: [ --fix ]
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
sys.path.append(os.path.abspath('sphinxext'))
sys.path.insert(0, os.path.abspath('../wrapper'))

from github_link import make_linkcode_resolve # noqa: E402
from github_link import make_linkcode_resolve

# -- General configuration ------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion fmriprep/cli/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def test_derivatives(tmp_path):
# Providing --derivatives with names should use them
temp_args = args + [
'--derivatives',
f'anat={str(bids_path / "derivatives/smriprep")}',
f'anat={bids_path / "derivatives/smriprep"}',
]
opts = parser.parse_args(temp_args)
assert opts.derivatives == {'anat': bids_path / 'derivatives/smriprep'}
Expand Down
2 changes: 1 addition & 1 deletion fmriprep/cli/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def check_latest():
versions = [Version(rel) for rel in response.json()['releases'].keys()]
versions = [rel for rel in versions if not rel.is_prerelease]
if versions:
latest = sorted(versions)[-1]
latest = max(versions)
else:
latest = None

Expand Down
7 changes: 2 additions & 5 deletions fmriprep/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,7 @@ def _process_value(value):
'raw': cls.bids_dir,
'templateflow': Path(TF_LAYOUT.root),
}
for deriv_name, deriv_path in cls.derivatives.items():
dataset_links[deriv_name] = deriv_path
dataset_links.update(cls.derivatives)
cls.dataset_links = dataset_links

if 'all' in cls.debug:
Expand Down Expand Up @@ -780,9 +779,7 @@ def get(flat=False):
return settings

return {
'.'.join((section, k)): v
for section, configs in settings.items()
for k, v in configs.items()
f'{section}.{k}': v for section, configs in settings.items() for k, v in configs.items()
}


Expand Down
4 changes: 2 additions & 2 deletions fmriprep/interfaces/confounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,8 @@ def less_breakable(a_string):
# Taken from https://stackoverflow.com/questions/1175208/
# If we end up using it more than just here, probably worth pulling in a well-tested package
def camel_to_snake(name):
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
s1 = re.sub(r'(.)([A-Z][a-z]+)', r'\1_\2', name)
return re.sub(r'([a-z0-9])([A-Z])', r'\1_\2', s1).lower()

def _adjust_indices(left_df, right_df):
# This forces missing values to appear at the beginning of the DataFrame
Expand Down
2 changes: 1 addition & 1 deletion fmriprep/interfaces/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import os
from contextlib import contextmanager

@contextmanager # type: ignore
@contextmanager
def _chdir(path):
cwd = os.getcwd()
os.chdir(path)
Expand Down
23 changes: 9 additions & 14 deletions fmriprep/interfaces/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ def _run_interface(self, runtime):
def _generate_segment(self):
BIDS_NAME = re.compile(
r'^(.*\/)?'
'(?P<subject_id>sub-[a-zA-Z0-9]+)'
'(_(?P<session_id>ses-[a-zA-Z0-9]+))?'
'(_(?P<task_id>task-[a-zA-Z0-9]+))?'
'(_(?P<acq_id>acq-[a-zA-Z0-9]+))?'
'(_(?P<rec_id>rec-[a-zA-Z0-9]+))?'
'(_(?P<run_id>run-[a-zA-Z0-9]+))?'
r'(?P<subject_id>sub-[a-zA-Z0-9]+)'
r'(_(?P<session_id>ses-[a-zA-Z0-9]+))?'
r'(_(?P<task_id>task-[a-zA-Z0-9]+))?'
r'(_(?P<acq_id>acq-[a-zA-Z0-9]+))?'
r'(_(?P<rec_id>rec-[a-zA-Z0-9]+))?'
r'(_(?P<run_id>run-[a-zA-Z0-9]+))?'
)

if not isdefined(self.inputs.subjects_dir):
Expand Down Expand Up @@ -261,20 +261,15 @@ def _generate_segment(self):

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

dummy_scan_tmp = '{n_dum}'
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_msg = f'{self.inputs.dummy_scans} (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_msg = f'{self.inputs.dummy_scans} (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 = f'{self.inputs.algo_dummy_scans}'

multiecho = 'Single-echo EPI sequence.'
n_echos = len(self.inputs.echo_idx)
Expand Down
2 changes: 1 addition & 1 deletion fmriprep/interfaces/workbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def _format_arg(self, opt, spec, val):
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')
iflogger.info('Setting roi output file as', roi_out)
iflogger.info('Setting roi output file as %s', roi_out)
spec.argstr += ' ' + roi_out
return super()._format_arg(opt, spec, val)

Expand Down
2 changes: 1 addition & 1 deletion fmriprep/utils/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def before_send(event, hints):
return None
if msg.startswith('Saving crash info to '):
return None
if re.match('Node .+ failed to run on host .+', msg):
if re.match(r'Node .+ failed to run on host .+', msg):
return None

if 'breadcrumbs' in event and isinstance(event['breadcrumbs'], list):
Expand Down
4 changes: 2 additions & 2 deletions fmriprep/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,8 +876,8 @@ def map_fieldmap_estimation(
fmap_estimators = find_estimators(
layout=layout,
subject=subject_id,
fmapless=bool(use_syn) or ignore_fieldmaps and force_syn,
force_fmapless=force_syn or ignore_fieldmaps and use_syn,
fmapless=bool(use_syn) or (ignore_fieldmaps and force_syn),
force_fmapless=force_syn or (ignore_fieldmaps and use_syn),
bids_filters=filters,
)

Expand Down
2 changes: 1 addition & 1 deletion fmriprep/workflows/bold/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
def init_bold_wf(
*,
bold_series: list[str],
precomputed: dict = None,
precomputed: dict | None = None,
fieldmap_id: str | None = None,
jacobian: bool = False,
) -> pe.Workflow:
Expand Down
8 changes: 4 additions & 4 deletions fmriprep/workflows/bold/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def get_sbrefs(
def init_bold_fit_wf(
*,
bold_series: list[str],
precomputed: dict = None,
precomputed: dict | None = None,
fieldmap_id: str | None = None,
jacobian: bool = False,
omp_nthreads: int = 1,
Expand Down Expand Up @@ -231,7 +231,7 @@ def init_bold_fit_wf(
metadata = layout.get_metadata(bold_file)
orientation = ''.join(nb.aff2axcodes(nb.load(bold_file).affine))

bold_tlen, mem_gb = estimate_bold_mem_usage(bold_file)
_bold_tlen, mem_gb = estimate_bold_mem_usage(bold_file)

# Boolean used to update workflow self-descriptions
multiecho = len(bold_series) > 1
Expand Down Expand Up @@ -793,7 +793,7 @@ def init_bold_native_wf(
bold_file = bold_series[0]
metadata = all_metadata[0]

bold_tlen, mem_gb = estimate_bold_mem_usage(bold_file)
_bold_tlen, mem_gb = estimate_bold_mem_usage(bold_file)

if multiecho:
shapes = [nb.load(echo).shape for echo in bold_series]
Expand Down Expand Up @@ -841,7 +841,7 @@ def init_bold_native_wf(
# Multiecho outputs
'bold_echos', # Individual corrected echos
't2star_map', # T2* map
], # fmt:skip
],
),
name='outputnode',
)
Expand Down
6 changes: 3 additions & 3 deletions fmriprep/workflows/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ def _make_params(
skull_strip_t1w: str = 'auto',
use_syn_sdc: str | bool = False,
freesurfer: bool = True,
ignore: list[str] = None,
force: list[str] = None,
bids_filters: dict = None,
ignore: list[str] | None = None,
force: list[str] | None = None,
bids_filters: dict | None = None,
):
if ignore is None:
ignore = []
Expand Down
26 changes: 22 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -154,31 +154,49 @@ line-length = 99

[tool.ruff.lint]
extend-select = [
"F",
"E",
"W",
"I",
"UP",
"YTT",
"S",
"BLE",
"B",
"A",
# "CPY",
"C4",
# "CPY",
"DTZ",
"T10",
# "EM",
"EXE",
"FA",
"ISC",
"ICN",
"LOG",
"PIE",
"PYI",
"PT",
"Q",
# "SIM",
# "TID",
"FLY",
# "PD",
"PERF",
"W",
"PGH",
"PLC",
"PLE",
"PLW",
"FURB",
"RUF",
]
ignore = [
"S311", # We are not using random for cryptographic purposes
"S603",
"PIE790",
"PERF203",
"PLC0415",
"PLW2901",
"RUF005",
"RUF012",
]

[tool.ruff.lint.flake8-quotes]
Expand Down
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ skip_install = true
commands =
ruff check --fix
ruff format
ruff check --select ISC001

[testenv:spellcheck]
description = Check spelling
Expand Down
Loading