Skip to content
Merged
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
15 changes: 0 additions & 15 deletions .flake8

This file was deleted.

67 changes: 34 additions & 33 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: end-of-file-fixer
- id: check-added-large-files
- id: check-ast
- id: check-case-conflict
- id: check-json
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix=lf]
- id: trailing-whitespace

# Checks for .rst files
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal

- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
rev: 0.2.3
hooks:
Expand All @@ -22,6 +33,7 @@ repos:
- '4'
- --offset
- '0'

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.16.0
hooks:
Expand All @@ -30,35 +42,38 @@ repos:
- --autofix
- --indent
- '4'

- repo: https://github.com/asottile/pyupgrade
rev: v3.21.2
hooks:
- id: pyupgrade
args:
- --py38-plus

- repo: https://github.com/seddonym/import-linter
rev: v2.11
hooks:
- id: import-linter
- repo: https://github.com/pycqa/isort
rev: 8.0.1
hooks:
- id: isort
args:
- --settings-path
- pyproject.toml
args: [--verbose]
language: python

- repo: https://github.com/adamchainz/blacken-docs
rev: 1.20.0
hooks:
- id: blacken-docs
additional_dependencies:
- black==24.2.0
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 26.3.0

# Lint and format Python code
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.1
hooks:
- id: black
args:
- --config=pyproject.toml
- id: ruff-check
# args: [--statistics]
args: [--fix, --show-fixes, --unsafe-fixes]
Comment on lines +71 to +73
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Using --unsafe-fixes in ruff-check may introduce semantic changes during pre-commit runs.

Since these transformations can alter runtime behaviour and are applied automatically on developer machines, they may introduce subtle bugs. Consider removing --unsafe-fixes from the pre-commit hook and instead running them only in an explicit context (e.g. a dedicated script or CI job), while keeping pre-commit limited to safer auto-fixes.

Suggested change
- id: ruff-check
# args: [--statistics]
args: [--fix, --show-fixes, --unsafe-fixes]
- id: ruff-check
# args: [--statistics]
args: [--fix, --show-fixes]

- id: ruff-format
# args: [--diff]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.19.1
hooks:
Expand All @@ -71,28 +86,14 @@ repos:
args:
- --config-file
- pyproject.toml

- repo: https://github.com/codespell-project/codespell
rev: v2.4.2
hooks:
- id: codespell
args:
- --toml=pyproject.toml
additional_dependencies:
- tomli
- repo: https://github.com/pycqa/flake8
rev: 7.3.0
hooks:
- id: flake8
exclude: tests_.*.py|version.*.py|setup.py
args:
- --config
- .flake8
- --verbose
additional_dependencies:
- flake8-docstrings
- flake8-use-fstring
- flake8-functions
- flake8-bugbear
args: [--toml=pyproject.toml]
additional_dependencies: [tomli]

ci:
autoupdate_commit_msg: 'chore: update pre-commit hooks'
autoupdate_schedule: monthly
Expand Down
2 changes: 1 addition & 1 deletion bidsmreye/_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def _base_parser(formatter_class: type[HelpFormatter] = HelpFormatter) -> ArgumentParser:
parser = ArgumentParser(
description=(
"BIDS app using deepMReye to decode " "eye motion for fMRI time series data."
"BIDS app using deepMReye to decode eye motion for fMRI time series data."
),
epilog="""
For a more readable version of this help section,
Expand Down
7 changes: 2 additions & 5 deletions bidsmreye/bids_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@ def check_layout(cfg: Config, layout: BIDSLayout, for_file: str = "bold") -> Non
:raises RuntimeError: _description_
"""
desc = layout.get_dataset_description()
if (
"DatasetType" not in desc
and "PipelineDescription" not in desc
or "DatasetType" in desc
and desc["DatasetType"] != "derivative"
if ("DatasetType" not in desc and "PipelineDescription" not in desc) or (
"DatasetType" in desc and desc["DatasetType"] != "derivative"
):
raise RuntimeError(
"DatasetType must be 'derivative' in dataset_description.json\n."
Expand Down
8 changes: 4 additions & 4 deletions bidsmreye/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __attrs_post_init__(self) -> None:
self.bids_filter = get_bids_filter_config()

self.output_dir = self.output_dir / "bidsmreye"
if not self.output_dir:
if not self.output_dir.exists():
self.output_dir.mkdir(parents=True, exist_ok=True)

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

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

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

if config_file is None or not Path(config_file).exists():
if not Path(config_file).exists():
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Calling get_config with default="" now attempts to open a directory as a file.

With this change, when config_file is None and default is "", config_file becomes my_path / "" (the config directory). Path(config_file).exists() will be True, so you’ll now hit an IsADirectoryError from open(config_file) instead of the previous FileNotFoundError.

To keep the clearer failure mode, consider either restoring the config_file is None check, enforcing a non-empty default before building the path, or using Path(config_file).is_file() instead of exists().

raise FileNotFoundError(f"Config file {config_file} not found")

with open(config_file) as ff:
Expand Down
2 changes: 1 addition & 1 deletion bidsmreye/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def methods(
:rtype: Path
"""
if output_dir is None:
output_dir = Path(".")
output_dir = Path()
if isinstance(output_dir, str):
output_dir = Path(output_dir)
output_dir = output_dir / "logs"
Expand Down
2 changes: 1 addition & 1 deletion bidsmreye/quality_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def compute_robust_outliers(
indices.pop(i)

tmp = time_series[indices]
tmp.dropna(inplace=True)
tmp = tmp.dropna()

# median of all pair-wise distances
distance.append(np.median(abs(this_timepoint - tmp)))
Expand Down
1 change: 0 additions & 1 deletion bidsmreye/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def generate_report(output_dir: Path, subject_label: str, action: str) -> None:


if __name__ == "__main__":

cwd = Path("/home/remi/github/cpp-lln-lab/bidsMReye")

output_dir = cwd / "outputs" / "moae_fmriprep" / "derivatives" / "bidsmreye"
Expand Down
38 changes: 19 additions & 19 deletions bidsmreye/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
from bidsmreye.utils import check_if_file_found, set_this_filter

LINE_WIDTH = 3
FONT_SIZE = dict(size=14)
FONT_SIZE = {"size": 14}
GRID_COLOR = "grey"
LINE_COLOR = "rgb(0, 150, 175)"
BG_COLOR = "rgb(255,255,255)"
HEAT_MAP_COLOR = "gnbu"
MARKER_SIZE = 10

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

X_POSITION_1 = 1
X_POSITION_2 = 1.5
Expand Down Expand Up @@ -113,7 +113,7 @@ def plot_group_boxplot(
go.Box(
x=np.ones(nb_data_points) * X_POSITION[i],
y=qc_data[this_column],
marker=dict(size=MARKER_SIZE, color=COLORS[i]),
marker={"size": MARKER_SIZE, "color": COLORS[i]},
name=trace_names[i],
),
row=row,
Expand All @@ -128,7 +128,7 @@ def plot_group_boxplot(
fig.update_yaxes(
row=row,
col=col,
title=dict(text=yaxes_title, font=FONT_SIZE),
title={"text": yaxes_title, "font": FONT_SIZE},
)


Expand Down Expand Up @@ -186,7 +186,7 @@ def group_report(cfg: Config) -> None:
)

fig.update_yaxes(
title=dict(standoff=0, font=FONT_SIZE),
title={"standoff": 0, "font": FONT_SIZE},
showline=True,
linewidth=LINE_WIDTH - 1,
linecolor="black",
Expand Down Expand Up @@ -215,9 +215,9 @@ def group_report(cfg: Config) -> None:
boxmean=True,
width=0.2,
hovertext=qc_data["filename"],
marker=dict(size=MARKER_SIZE),
marker={"size": MARKER_SIZE},
fillcolor="rgb(200, 200, 200)",
line=dict(color="black"),
line={"color": "black"},
)

fig.update_layout(
Expand All @@ -226,17 +226,17 @@ def group_report(cfg: Config) -> None:
paper_bgcolor=BG_COLOR,
height=800,
width=800,
title=dict(
text=f"""<b>bidsmreye: group report</b><br>
title={
"text": f"""<b>bidsmreye: group report</b><br>
<b>Summary</b><br>
- Date and time: {datetime.now():%Y-%m-%d, %H:%M}<br>
- bidsmreye version: {__version__}<br>
""",
x=0.05,
y=0.95,
font=dict(size=19, color="black"),
),
margin=dict(t=150, b=10, l=100, r=10, pad=0),
"x": 0.05,
"y": 0.95,
"font": {"size": 19, "color": "black"},
},
margin={"t": 150, "b": 10, "l": 100, "r": 10, "pad": 0},
)

fig.show()
Expand Down Expand Up @@ -288,7 +288,7 @@ def visualize_eye_gaze_data(
fig.update_xaxes(
row=3,
col=1,
title=dict(text="Time (s)", standoff=16, font=FONT_SIZE),
title={"text": "Time (s)", "standoff": 16, "font": FONT_SIZE},
tickfont=TICK_FONT,
)

Expand Down Expand Up @@ -376,7 +376,7 @@ def plot_time_series(
griddash="dot",
gridwidth=0.5,
ticksuffix="°",
title=dict(text=title_text, standoff=0, font=FONT_SIZE),
title={"text": title_text, "standoff": 0, "font": FONT_SIZE},
tickfont=FONT_SIZE,
)

Expand Down Expand Up @@ -428,7 +428,7 @@ def plot_heat_map(fig: Any, eye_gaze_data: pd.DataFrame) -> None:
x=X,
y=Y,
opacity=0.4,
line=dict(color="black", width=1, dash="dash"),
line={"color": "black", "width": 1, "dash": "dash"},
),
row=1,
col=3,
Expand All @@ -448,15 +448,15 @@ def plot_heat_map(fig: Any, eye_gaze_data: pd.DataFrame) -> None:
col=3,
range=value_range(X),
ticksuffix="°",
title=dict(text="X", standoff=16, font=FONT_SIZE),
title={"text": "X", "standoff": 16, "font": FONT_SIZE},
tickfont=TICK_FONT,
)
fig.update_yaxes(
row=1,
col=3,
range=value_range(Y),
ticksuffix="°",
title=dict(text="Y", standoff=16, font=FONT_SIZE),
title={"text": "Y", "standoff": 16, "font": FONT_SIZE},
tickfont=TICK_FONT,
)

Expand Down
Loading
Loading