Skip to content

Commit

Permalink
Bump ruff to v0.3.0 (mne-tools#12477)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoechenberger authored Mar 2, 2024
1 parent d17d885 commit 64901c4
Show file tree
Hide file tree
Showing 53 changed files with 133 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
# Ruff mne
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.2
rev: v0.3.0
hooks:
- id: ruff
name: ruff lint mne
Expand Down
8 changes: 4 additions & 4 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1194,21 +1194,21 @@ def append_attr_meth_examples(app, what, name, obj, options, lines):
"carousel": [
dict(
title="Source Estimation",
text="Distributed, sparse, mixed-norm, beam\u00ADformers, dipole fitting, and more.", # noqa E501
text="Distributed, sparse, mixed-norm, beam\u00adformers, dipole fitting, and more.", # noqa E501
url="auto_tutorials/inverse/index.html",
img="sphx_glr_30_mne_dspm_loreta_008.gif",
alt="dSPM",
),
dict(
title="Machine Learning",
text="Advanced decoding models including time general\u00ADiza\u00ADtion.", # noqa E501
text="Advanced decoding models including time general\u00adiza\u00adtion.", # noqa E501
url="auto_tutorials/machine-learning/50_decoding.html",
img="sphx_glr_50_decoding_006.png",
alt="Decoding",
),
dict(
title="Encoding Models",
text="Receptive field estima\u00ADtion with optional smooth\u00ADness priors.", # noqa E501
text="Receptive field estima\u00adtion with optional smooth\u00adness priors.", # noqa E501
url="auto_tutorials/machine-learning/30_strf.html",
img="sphx_glr_30_strf_001.png",
alt="STRF",
Expand All @@ -1222,7 +1222,7 @@ def append_attr_meth_examples(app, what, name, obj, options, lines):
),
dict(
title="Connectivity",
text="All-to-all spectral and effective connec\u00ADtivity measures.", # noqa E501
text="All-to-all spectral and effective connec\u00adtivity measures.", # noqa E501
url="https://mne.tools/mne-connectivity/stable/auto_examples/mne_inverse_label_connectivity.html", # noqa E501
img="https://mne.tools/mne-connectivity/stable/_images/sphx_glr_mne_inverse_label_connectivity_001.png", # noqa E501
alt="Connectivity",
Expand Down
2 changes: 1 addition & 1 deletion doc/sphinxext/unit_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def pass_error_to_sphinx(rawtext, text, lineno, inliner):
except ValueError:
return pass_error_to_sphinx(rawtext, text, lineno, inliner)
# input is well-formatted: proceed
node = nodes.Text("\u202F".join(parts))
node = nodes.Text("\u202f".join(parts))
return [node], []


Expand Down
1 change: 0 additions & 1 deletion examples/datasets/hf_sef_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

# %%


import os

import mne
Expand Down
1 change: 0 additions & 1 deletion examples/decoding/decoding_csp_eeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

# %%


import matplotlib.pyplot as plt
import numpy as np
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
Expand Down
1 change: 0 additions & 1 deletion examples/decoding/decoding_csp_timefreq.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

# %%


import matplotlib.pyplot as plt
import numpy as np
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
Expand Down
1 change: 0 additions & 1 deletion examples/decoding/ssd_spatial_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

# %%


import matplotlib.pyplot as plt

import mne
Expand Down
1 change: 0 additions & 1 deletion examples/io/elekta_epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

# %%


import os

import mne
Expand Down
6 changes: 3 additions & 3 deletions examples/preprocessing/css.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def subcortical_waveform(times):
labels=[postcenlab, hiplab],
data_fun=cortical_waveform,
)
stc.data[
np.where(np.isin(stc.vertices[0], hiplab.vertices))[0], :
] = subcortical_waveform(times)
stc.data[np.where(np.isin(stc.vertices[0], hiplab.vertices))[0], :] = (
subcortical_waveform(times)
)
evoked = simulate_evoked(fwd, stc, raw.info, cov, nave=15)

###############################################################################
Expand Down
1 change: 0 additions & 1 deletion examples/preprocessing/eog_artifact_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

# %%


import matplotlib.pyplot as plt
import numpy as np

Expand Down
1 change: 0 additions & 1 deletion examples/preprocessing/xdawn_denoising.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

# %%


from mne import Epochs, compute_raw_covariance, io, pick_types, read_events
from mne.datasets import sample
from mne.preprocessing import Xdawn
Expand Down
1 change: 0 additions & 1 deletion examples/visualization/eyetracking_plot_heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
# :ref:`example data <eyelink-dataset>`: eye-tracking data recorded from SR research's
# ``'.asc'`` file format.


import matplotlib.pyplot as plt

import mne
Expand Down
1 change: 0 additions & 1 deletion examples/visualization/topo_compare_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

# %%


import matplotlib.pyplot as plt

import mne
Expand Down
1 change: 0 additions & 1 deletion examples/visualization/topo_customized.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

# %%


import matplotlib.pyplot as plt
import numpy as np

Expand Down
5 changes: 3 additions & 2 deletions mne/_fiff/tests/test_meas_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,9 @@ def test_read_write_info(tmp_path):
@testing.requires_testing_data
def test_dir_warning():
"""Test that trying to read a bad filename emits a warning before an error."""
with pytest.raises(OSError, match="directory"), pytest.warns(
RuntimeWarning, match="does not conform"
with (
pytest.raises(OSError, match="directory"),
pytest.warns(RuntimeWarning, match="does not conform"),
):
read_info(ctf_fname)

Expand Down
1 change: 1 addition & 0 deletions mne/beamformer/resolution_matrix.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Compute resolution matrix for beamformers."""

# Authors: olaf.hauk@mrc-cbu.cam.ac.uk
#
# License: BSD-3-Clause
Expand Down
8 changes: 5 additions & 3 deletions mne/beamformer/tests/test_lcmv.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,11 @@ def test_make_lcmv_sphere(pick_ori, weight_norm):
fwd_sphere = mne.make_forward_solution(evoked.info, None, src, sphere)

# Test that we get an error if not reducing rank
with pytest.raises(
ValueError, match="Singular matrix detected"
), _record_warnings(), pytest.warns(RuntimeWarning, match="positive semidefinite"):
with (
pytest.raises(ValueError, match="Singular matrix detected"),
_record_warnings(),
pytest.warns(RuntimeWarning, match="positive semidefinite"),
):
make_lcmv(
evoked.info,
fwd_sphere,
Expand Down
1 change: 0 additions & 1 deletion mne/commands/mne_bti2fiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.


import sys

import mne
Expand Down
1 change: 0 additions & 1 deletion mne/commands/mne_clean_eog_ecg.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.


import sys

import mne
Expand Down
1 change: 1 addition & 0 deletions mne/commands/mne_make_scalp_surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
$ mne make_scalp_surfaces --overwrite --subject sample
"""

import os
import sys

Expand Down
5 changes: 3 additions & 2 deletions mne/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,8 +802,9 @@ def src_volume_labels():
"""Create a 7mm source space with labels."""
pytest.importorskip("nibabel")
volume_labels = mne.get_volume_labels_from_aseg(fname_aseg)
with _record_warnings(), pytest.warns(
RuntimeWarning, match="Found no usable.*t-vessel.*"
with (
_record_warnings(),
pytest.warns(RuntimeWarning, match="Found no usable.*t-vessel.*"),
):
src = mne.setup_volume_source_space(
"sample",
Expand Down
10 changes: 6 additions & 4 deletions mne/export/tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ def test_export_raw_pybv(tmp_path, meas_date, orig_time, ext):
raw.set_annotations(annots)

temp_fname = tmp_path / ("test" + ext)
with _record_warnings(), pytest.warns(
RuntimeWarning, match="'short' format. Converting"
with (
_record_warnings(),
pytest.warns(RuntimeWarning, match="'short' format. Converting"),
):
raw.export(temp_fname)
raw_read = read_raw_brainvision(str(temp_fname).replace(".eeg", ".vhdr"))
Expand Down Expand Up @@ -303,8 +304,9 @@ def test_export_edf_signal_clipping(tmp_path, physical_range, exceeded_bound):
raw = read_raw_fif(fname_raw)
raw.pick(picks=["eeg", "ecog", "seeg"]).load_data()
temp_fname = tmp_path / "test.edf"
with _record_warnings(), pytest.warns(
RuntimeWarning, match=f"The {exceeded_bound}"
with (
_record_warnings(),
pytest.warns(RuntimeWarning, match=f"The {exceeded_bound}"),
):
raw.export(temp_fname, physical_range=physical_range)
raw_read = read_raw_edf(temp_fname, preload=True)
Expand Down
5 changes: 3 additions & 2 deletions mne/forward/tests/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,9 @@ def test_apply_forward():
# Evoked
evoked = read_evokeds(fname_evoked, condition=0)
evoked.pick(picks="meg")
with _record_warnings(), pytest.warns(
RuntimeWarning, match="only .* positive values"
with (
_record_warnings(),
pytest.warns(RuntimeWarning, match="only .* positive values"),
):
evoked = apply_forward(fwd, stc, evoked.info, start=start, stop=stop)
data = evoked.data
Expand Down
1 change: 0 additions & 1 deletion mne/io/_read_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.


from functools import partial
from pathlib import Path

Expand Down
5 changes: 3 additions & 2 deletions mne/io/artemis123/tests/test_artemis123.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ def test_dev_head_t():
assert_equal(raw.info["sfreq"], 5000.0)

# test with head loc and digitization
with pytest.warns(RuntimeWarning, match="consistency"), pytest.warns(
RuntimeWarning, match="Large difference"
with (
pytest.warns(RuntimeWarning, match="consistency"),
pytest.warns(RuntimeWarning, match="Large difference"),
):
raw = read_raw_artemis123(
short_HPI_dip_fname, add_head_trans=True, pos_fname=dig_fname
Expand Down
1 change: 1 addition & 0 deletions mne/io/besa/tests/test_besa.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.
"""Test reading BESA fileformats."""

import inspect
from pathlib import Path

Expand Down
5 changes: 3 additions & 2 deletions mne/io/brainvision/tests/test_brainvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,9 @@ def test_brainvision_vectorized_data():
def test_coodinates_extraction():
"""Test reading of [Coordinates] section if present."""
# vhdr 2 has a Coordinates section
with _record_warnings(), pytest.warns(
RuntimeWarning, match="coordinate information"
with (
_record_warnings(),
pytest.warns(RuntimeWarning, match="coordinate information"),
):
raw = read_raw_brainvision(vhdr_v2_path)

Expand Down
2 changes: 1 addition & 1 deletion mne/io/edf/edf.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ def _read_edf_header(fname, exclude, infer_types, include=None):
if i in exclude:
continue
# allow μ (greek mu), µ (micro symbol) and μ (sjis mu) codepoints
if unit in ("\u03BCV", "\u00B5V", "\x83\xCAV", "uV"):
if unit in ("\u03bcV", "\u00b5V", "\x83\xcaV", "uV"):
edf_info["units"].append(1e-6)
elif unit == "mV":
edf_info["units"].append(1e-3)
Expand Down
5 changes: 3 additions & 2 deletions mne/io/eeglab/tests/test_eeglab.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ def test_io_set_raw_more(tmp_path):
shutil.copyfile(
base_dir / "test_raw.fdt", negative_latency_fname.with_suffix(".fdt")
)
with _record_warnings(), pytest.warns(
RuntimeWarning, match="has a sample index of -1."
with (
_record_warnings(),
pytest.warns(RuntimeWarning, match="has a sample index of -1."),
):
read_raw_eeglab(input_fname=negative_latency_fname, preload=True)

Expand Down
1 change: 0 additions & 1 deletion mne/io/eyelink/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.


import re
from datetime import datetime, timedelta, timezone

Expand Down
5 changes: 3 additions & 2 deletions mne/io/eyelink/tests/test_eyelink.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,9 @@ def test_multi_block_misc_channels(fname, tmp_path):
out_file = tmp_path / "tmp_eyelink.asc"
_simulate_eye_tracking_data(fname, out_file)

with _record_warnings(), pytest.warns(
RuntimeWarning, match="Raw eyegaze coordinates"
with (
_record_warnings(),
pytest.warns(RuntimeWarning, match="Raw eyegaze coordinates"),
):
raw = read_raw_eyelink(out_file, apply_offsets=True)

Expand Down
5 changes: 3 additions & 2 deletions mne/io/fiff/tests/test_raw_fiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -2120,8 +2120,9 @@ def test_corrupted(tmp_path, offset):
bad_fname = tmp_path / "test_raw.fif"
with open(bad_fname, "wb") as fid:
fid.write(data)
with _record_warnings(), pytest.warns(
RuntimeWarning, match=".*tag directory.*corrupt.*"
with (
_record_warnings(),
pytest.warns(RuntimeWarning, match=".*tag directory.*corrupt.*"),
):
raw_bad = read_raw_fif(bad_fname)
assert_allclose(raw.get_data(), raw_bad.get_data())
Expand Down
6 changes: 3 additions & 3 deletions mne/io/neuralynx/neuralynx.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ def _read_segment_file(self, data, idx, fi, start, stop, cals, mult):
sel_samples_local[0:-1, 1] = (
sel_samples_global[0:-1, 1] - sel_samples_global[0:-1, 0]
)
sel_samples_local[
1::, 0
] = 0 # now set the start sample for all segments after the first to 0
sel_samples_local[1::, 0] = (
0 # now set the start sample for all segments after the first to 0
)

sel_samples_local[0, 0] = (
start - sel_samples_global[0, 0]
Expand Down
1 change: 1 addition & 0 deletions mne/minimum_norm/resolution_matrix.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Compute resolution matrix for linear estimators."""

# Authors: olaf.hauk@mrc-cbu.cam.ac.uk
#
# License: BSD-3-Clause
Expand Down
1 change: 1 addition & 0 deletions mne/minimum_norm/spatial_resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Resolution metrics: localisation error, spatial extent, relative amplitude.
Metrics can be computed for point-spread and cross-talk functions (PSFs/CTFs).
"""

import numpy as np

from ..source_estimate import SourceEstimate
Expand Down
1 change: 0 additions & 1 deletion mne/preprocessing/_lof.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.


import numpy as np

from .._fiff.pick import _picks_to_idx
Expand Down
Loading

0 comments on commit 64901c4

Please sign in to comment.