Skip to content

Commit 05ffa31

Browse files
authored
[MAINT] switch to ruff (cpp-lln-lab#261)
* [MAINT] switch to ruff * lower complexity thresholds * Apply suggestion from @Remi-Gau
1 parent 4b8b5b2 commit 05ffa31

10 files changed

Lines changed: 168 additions & 87 deletions

File tree

.flake8

Lines changed: 0 additions & 15 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,25 @@ repos:
33
- repo: https://github.com/pre-commit/pre-commit-hooks
44
rev: v6.0.0
55
hooks:
6-
- id: end-of-file-fixer
7-
- id: check-added-large-files
6+
- id: check-ast
87
- id: check-case-conflict
98
- id: check-json
109
- id: check-merge-conflict
10+
- id: check-toml
1111
- id: check-yaml
12-
- id: debug-statements
12+
- id: end-of-file-fixer
13+
- id: mixed-line-ending
14+
args: [--fix=lf]
1315
- id: trailing-whitespace
16+
17+
# Checks for .rst files
18+
- repo: https://github.com/pre-commit/pygrep-hooks
19+
rev: v1.10.0
20+
hooks:
21+
- id: rst-backticks
22+
- id: rst-directive-colons
23+
- id: rst-inline-touching-normal
24+
1425
- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
1526
rev: 0.2.3
1627
hooks:
@@ -22,6 +33,7 @@ repos:
2233
- '4'
2334
- --offset
2435
- '0'
36+
2537
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
2638
rev: v2.16.0
2739
hooks:
@@ -30,35 +42,38 @@ repos:
3042
- --autofix
3143
- --indent
3244
- '4'
45+
3346
- repo: https://github.com/asottile/pyupgrade
3447
rev: v3.21.2
3548
hooks:
3649
- id: pyupgrade
3750
args:
3851
- --py38-plus
52+
3953
- repo: https://github.com/seddonym/import-linter
4054
rev: v2.11
4155
hooks:
4256
- id: import-linter
43-
- repo: https://github.com/pycqa/isort
44-
rev: 8.0.1
45-
hooks:
46-
- id: isort
47-
args:
48-
- --settings-path
49-
- pyproject.toml
57+
args: [--verbose]
58+
language: python
59+
5060
- repo: https://github.com/adamchainz/blacken-docs
5161
rev: 1.20.0
5262
hooks:
5363
- id: blacken-docs
5464
additional_dependencies:
5565
- black==24.2.0
56-
- repo: https://github.com/psf/black-pre-commit-mirror
57-
rev: 26.3.0
66+
67+
# Lint and format Python code
68+
- repo: https://github.com/astral-sh/ruff-pre-commit
69+
rev: v0.15.1
5870
hooks:
59-
- id: black
60-
args:
61-
- --config=pyproject.toml
71+
- id: ruff-check
72+
# args: [--statistics]
73+
args: [--fix, --show-fixes, --unsafe-fixes]
74+
- id: ruff-format
75+
# args: [--diff]
76+
6277
- repo: https://github.com/pre-commit/mirrors-mypy
6378
rev: v1.19.1
6479
hooks:
@@ -71,28 +86,14 @@ repos:
7186
args:
7287
- --config-file
7388
- pyproject.toml
89+
7490
- repo: https://github.com/codespell-project/codespell
7591
rev: v2.4.2
7692
hooks:
7793
- id: codespell
78-
args:
79-
- --toml=pyproject.toml
80-
additional_dependencies:
81-
- tomli
82-
- repo: https://github.com/pycqa/flake8
83-
rev: 7.3.0
84-
hooks:
85-
- id: flake8
86-
exclude: tests_.*.py|version.*.py|setup.py
87-
args:
88-
- --config
89-
- .flake8
90-
- --verbose
91-
additional_dependencies:
92-
- flake8-docstrings
93-
- flake8-use-fstring
94-
- flake8-functions
95-
- flake8-bugbear
94+
args: [--toml=pyproject.toml]
95+
additional_dependencies: [tomli]
96+
9697
ci:
9798
autoupdate_commit_msg: 'chore: update pre-commit hooks'
9899
autoupdate_schedule: monthly

bidsmreye/_parsers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
def _base_parser(formatter_class: type[HelpFormatter] = HelpFormatter) -> ArgumentParser:
1111
parser = ArgumentParser(
1212
description=(
13-
"BIDS app using deepMReye to decode " "eye motion for fMRI time series data."
13+
"BIDS app using deepMReye to decode eye motion for fMRI time series data."
1414
),
1515
epilog="""
1616
For a more readable version of this help section,

bidsmreye/bids_utils.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,8 @@ def check_layout(cfg: Config, layout: BIDSLayout, for_file: str = "bold") -> Non
3636
:raises RuntimeError: _description_
3737
"""
3838
desc = layout.get_dataset_description()
39-
if (
40-
"DatasetType" not in desc
41-
and "PipelineDescription" not in desc
42-
or "DatasetType" in desc
43-
and desc["DatasetType"] != "derivative"
39+
if ("DatasetType" not in desc and "PipelineDescription" not in desc) or (
40+
"DatasetType" in desc and desc["DatasetType"] != "derivative"
4441
):
4542
raise RuntimeError(
4643
"DatasetType must be 'derivative' in dataset_description.json\n."

bidsmreye/configuration.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def __attrs_post_init__(self) -> None:
7474
self.bids_filter = get_bids_filter_config()
7575

7676
self.output_dir = self.output_dir / "bidsmreye"
77-
if not self.output_dir:
77+
if not self.output_dir.exists():
7878
self.output_dir.mkdir(parents=True, exist_ok=True)
7979

8080
database_path = self.input_dir / "pybids_db"
@@ -136,7 +136,7 @@ def check_argument(self, attribute: str, layout_in: BIDSLayout) -> Config:
136136
self.listify(attribute)
137137

138138
# convert all run values to integers
139-
if attribute in {"run"}:
139+
if attribute == "run":
140140
for i, j in enumerate(value):
141141
value[i] = int(j)
142142
tmp = [int(j) for j in getattr(self, attribute)]
@@ -155,7 +155,7 @@ def check_argument(self, attribute: str, layout_in: BIDSLayout) -> Config:
155155
# run and space can be empty if their entity are not used
156156
# we will figure out the values for run
157157
# in subject / task wise manner later on
158-
if attribute not in ["run"]:
158+
if attribute != "run":
159159
setattr(self, attribute, value)
160160

161161
if attribute not in ["run", "space"] and not getattr(self, attribute):
@@ -236,7 +236,7 @@ def get_config(config_file: Path | None = None, default: str = "") -> dict[str,
236236
my_path = Path(__file__).absolute().parent / "config"
237237
config_file = my_path / default
238238

239-
if config_file is None or not Path(config_file).exists():
239+
if not Path(config_file).exists():
240240
raise FileNotFoundError(f"Config file {config_file} not found")
241241

242242
with open(config_file) as ff:

bidsmreye/methods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def methods(
2929
:rtype: Path
3030
"""
3131
if output_dir is None:
32-
output_dir = Path(".")
32+
output_dir = Path()
3333
if isinstance(output_dir, str):
3434
output_dir = Path(output_dir)
3535
output_dir = output_dir / "logs"

bidsmreye/quality_control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def compute_robust_outliers(
325325
indices.pop(i)
326326

327327
tmp = time_series[indices]
328-
tmp.dropna(inplace=True)
328+
tmp = tmp.dropna()
329329

330330
# median of all pair-wise distances
331331
distance.append(np.median(abs(this_timepoint - tmp)))

bidsmreye/report.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def generate_report(output_dir: Path, subject_label: str, action: str) -> None:
6666

6767

6868
if __name__ == "__main__":
69-
7069
cwd = Path("/home/remi/github/cpp-lln-lab/bidsMReye")
7170

7271
output_dir = cwd / "outputs" / "moae_fmriprep" / "derivatives" / "bidsmreye"

bidsmreye/visualize.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
from bidsmreye.utils import check_if_file_found, set_this_filter
1818

1919
LINE_WIDTH = 3
20-
FONT_SIZE = dict(size=14)
20+
FONT_SIZE = {"size": 14}
2121
GRID_COLOR = "grey"
2222
LINE_COLOR = "rgb(0, 150, 175)"
2323
BG_COLOR = "rgb(255,255,255)"
2424
HEAT_MAP_COLOR = "gnbu"
2525
MARKER_SIZE = 10
2626

27-
TICK_FONT = dict(family="arial", color="black", size=14)
27+
TICK_FONT = {"family": "arial", "color": "black", "size": 14}
2828

2929
X_POSITION_1 = 1
3030
X_POSITION_2 = 1.5
@@ -113,7 +113,7 @@ def plot_group_boxplot(
113113
go.Box(
114114
x=np.ones(nb_data_points) * X_POSITION[i],
115115
y=qc_data[this_column],
116-
marker=dict(size=MARKER_SIZE, color=COLORS[i]),
116+
marker={"size": MARKER_SIZE, "color": COLORS[i]},
117117
name=trace_names[i],
118118
),
119119
row=row,
@@ -128,7 +128,7 @@ def plot_group_boxplot(
128128
fig.update_yaxes(
129129
row=row,
130130
col=col,
131-
title=dict(text=yaxes_title, font=FONT_SIZE),
131+
title={"text": yaxes_title, "font": FONT_SIZE},
132132
)
133133

134134

@@ -186,7 +186,7 @@ def group_report(cfg: Config) -> None:
186186
)
187187

188188
fig.update_yaxes(
189-
title=dict(standoff=0, font=FONT_SIZE),
189+
title={"standoff": 0, "font": FONT_SIZE},
190190
showline=True,
191191
linewidth=LINE_WIDTH - 1,
192192
linecolor="black",
@@ -215,9 +215,9 @@ def group_report(cfg: Config) -> None:
215215
boxmean=True,
216216
width=0.2,
217217
hovertext=qc_data["filename"],
218-
marker=dict(size=MARKER_SIZE),
218+
marker={"size": MARKER_SIZE},
219219
fillcolor="rgb(200, 200, 200)",
220-
line=dict(color="black"),
220+
line={"color": "black"},
221221
)
222222

223223
fig.update_layout(
@@ -226,17 +226,17 @@ def group_report(cfg: Config) -> None:
226226
paper_bgcolor=BG_COLOR,
227227
height=800,
228228
width=800,
229-
title=dict(
230-
text=f"""<b>bidsmreye: group report</b><br>
229+
title={
230+
"text": f"""<b>bidsmreye: group report</b><br>
231231
<b>Summary</b><br>
232232
- Date and time: {datetime.now():%Y-%m-%d, %H:%M}<br>
233233
- bidsmreye version: {__version__}<br>
234234
""",
235-
x=0.05,
236-
y=0.95,
237-
font=dict(size=19, color="black"),
238-
),
239-
margin=dict(t=150, b=10, l=100, r=10, pad=0),
235+
"x": 0.05,
236+
"y": 0.95,
237+
"font": {"size": 19, "color": "black"},
238+
},
239+
margin={"t": 150, "b": 10, "l": 100, "r": 10, "pad": 0},
240240
)
241241

242242
fig.show()
@@ -288,7 +288,7 @@ def visualize_eye_gaze_data(
288288
fig.update_xaxes(
289289
row=3,
290290
col=1,
291-
title=dict(text="Time (s)", standoff=16, font=FONT_SIZE),
291+
title={"text": "Time (s)", "standoff": 16, "font": FONT_SIZE},
292292
tickfont=TICK_FONT,
293293
)
294294

@@ -376,7 +376,7 @@ def plot_time_series(
376376
griddash="dot",
377377
gridwidth=0.5,
378378
ticksuffix="°",
379-
title=dict(text=title_text, standoff=0, font=FONT_SIZE),
379+
title={"text": title_text, "standoff": 0, "font": FONT_SIZE},
380380
tickfont=FONT_SIZE,
381381
)
382382

@@ -428,7 +428,7 @@ def plot_heat_map(fig: Any, eye_gaze_data: pd.DataFrame) -> None:
428428
x=X,
429429
y=Y,
430430
opacity=0.4,
431-
line=dict(color="black", width=1, dash="dash"),
431+
line={"color": "black", "width": 1, "dash": "dash"},
432432
),
433433
row=1,
434434
col=3,
@@ -448,15 +448,15 @@ def plot_heat_map(fig: Any, eye_gaze_data: pd.DataFrame) -> None:
448448
col=3,
449449
range=value_range(X),
450450
ticksuffix="°",
451-
title=dict(text="X", standoff=16, font=FONT_SIZE),
451+
title={"text": "X", "standoff": 16, "font": FONT_SIZE},
452452
tickfont=TICK_FONT,
453453
)
454454
fig.update_yaxes(
455455
row=1,
456456
col=3,
457457
range=value_range(Y),
458458
ticksuffix="°",
459-
title=dict(text="Y", standoff=16, font=FONT_SIZE),
459+
title={"text": "Y", "standoff": 16, "font": FONT_SIZE},
460460
tickfont=TICK_FONT,
461461
)
462462

0 commit comments

Comments
 (0)