Skip to content

Commit 6553573

Browse files
committed
[MAINT] switch to ruff
1 parent e1ea064 commit 6553573

10 files changed

Lines changed: 162 additions & 71 deletions

File tree

.flake8

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

.pre-commit-config.yaml

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,25 @@ repos:
55
- repo: https://github.com/pre-commit/pre-commit-hooks
66
rev: v6.0.0
77
hooks:
8-
- id: end-of-file-fixer
9-
- id: check-added-large-files
8+
- id: check-ast
109
- id: check-case-conflict
1110
- id: check-json
1211
- id: check-merge-conflict
12+
- id: check-toml
1313
- id: check-yaml
14-
- id: debug-statements
14+
- id: end-of-file-fixer
15+
- id: mixed-line-ending
16+
args: [--fix=lf]
1517
- id: trailing-whitespace
1618

19+
# Checks for .rst files
20+
- repo: https://github.com/pre-commit/pygrep-hooks
21+
rev: v1.10.0
22+
hooks:
23+
- id: rst-backticks
24+
- id: rst-directive-colons
25+
- id: rst-inline-touching-normal
26+
1727
- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
1828
rev: 0.2.3
1929
hooks:
@@ -36,12 +46,8 @@ repos:
3646
rev: v2.10
3747
hooks:
3848
- id: import-linter
39-
40-
- repo: https://github.com/pycqa/isort
41-
rev: 8.0.1
42-
hooks:
43-
- id: isort
44-
args: [--settings-path, pyproject.toml]
49+
args: [--verbose]
50+
language: python
4551

4652
- repo: https://github.com/adamchainz/blacken-docs
4753
rev: 1.20.0
@@ -56,6 +62,16 @@ repos:
5662
- id: black
5763
args: [--config=pyproject.toml]
5864

65+
# Lint and format Python code
66+
- repo: https://github.com/astral-sh/ruff-pre-commit
67+
rev: v0.15.1
68+
hooks:
69+
- id: ruff-check
70+
# args: [--statistics]
71+
args: [--fix, --show-fixes, --unsafe-fixes]
72+
- id: ruff-format
73+
# args: [--diff]
74+
5975
- repo: https://github.com/pre-commit/mirrors-mypy
6076
rev: v1.19.1
6177
hooks:
@@ -71,13 +87,7 @@ repos:
7187
args: [--toml=pyproject.toml]
7288
additional_dependencies: [tomli]
7389

74-
- repo: https://github.com/pycqa/flake8
75-
rev: 7.3.0
76-
hooks:
77-
- id: flake8
78-
exclude: tests_.*.py|version.*.py|setup.py # ignore tests and versioneer related code
79-
args: [--config, .flake8, --verbose]
80-
additional_dependencies: [flake8-docstrings, flake8-use-fstring, flake8-functions, flake8-bugbear]
81-
8290
ci:
8391
autoupdate_commit_msg: 'chore: update pre-commit hooks'
92+
autofix_commit_msg: 'style: pre-commit fixes'
93+
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)