Skip to content

Commit

Permalink
MRG: Use ruff-format instead of Black (mne-tools#12261)
Browse files Browse the repository at this point in the history
Co-authored-by: Eric Larson <[email protected]>
Co-authored-by: Daniel McCloy <[email protected]>
  • Loading branch information
3 people authored Dec 5, 2023
1 parent 092cf90 commit e7dd158
Show file tree
Hide file tree
Showing 71 changed files with 541 additions and 1,381 deletions.
1 change: 0 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- uses: psf/black@stable
- uses: pre-commit/[email protected]

bandit:
Expand Down
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
repos:
- repo: https://github.com/psf/black
rev: 23.11.0
hooks:
- id: black
args: [--quiet]

# Ruff mne
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.6
hooks:
- id: ruff
name: ruff mne
name: ruff lint mne
args: ["--fix"]
files: ^mne/
- id: ruff-format
name: ruff format mne
files: ^mne/

# Ruff tutorials and examples
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.6
hooks:
- id: ruff
name: ruff tutorials and examples
name: ruff lint tutorials and examples
# D103: missing docstring in public function
# D400: docstring first line must end with period
args: ["--ignore=D103,D400", "--fix"]
files: ^tutorials/|^examples/
- id: ruff-format
name: ruff format tutorials and examples
files: ^tutorials/|^examples/

# Codespell
- repo: https://github.com/codespell-project/codespell
Expand Down
2 changes: 1 addition & 1 deletion mne/_fiff/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Tag:
Position of Tag is the original file.
"""

def __init__(self, kind, type_, size, next, pos=None): # noqa: D102
def __init__(self, kind, type_, size, next, pos=None):
self.kind = int(kind)
self.type = int(type_)
self.size = int(size)
Expand Down
12 changes: 6 additions & 6 deletions mne/_fiff/tests/test_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,16 +385,16 @@ def test_constants(tmp_path):
for key in fif["coil"]:
if key not in _missing_coil_def and key not in coil_def:
bad_list.append((" %s," % key).ljust(10) + " # " + fif["coil"][key][1])
assert (
len(bad_list) == 0
), "\nIn fiff-constants, missing from coil_def:\n" + "\n".join(bad_list)
assert len(bad_list) == 0, (
"\nIn fiff-constants, missing from coil_def:\n" + "\n".join(bad_list)
)
# Assert that enum(coil) has all `coil_def.dat` entries
for key, desc in zip(coil_def, coil_desc):
if key not in fif["coil"]:
bad_list.append((" %s," % key).ljust(10) + " # " + desc)
assert (
len(bad_list) == 0
), "In coil_def, missing from fiff-constants:\n" + "\n".join(bad_list)
assert len(bad_list) == 0, (
"In coil_def, missing from fiff-constants:\n" + "\n".join(bad_list)
)


@pytest.mark.parametrize(
Expand Down
4 changes: 1 addition & 3 deletions mne/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,7 @@ class Annotations:
:meth:`Raw.save() <mne.io.Raw.save>` notes for details.
""" # noqa: E501

def __init__(
self, onset, duration, description, orig_time=None, ch_names=None
): # noqa: D102
def __init__(self, onset, duration, description, orig_time=None, ch_names=None):
self._orig_time = _handle_meas_date(orig_time)
self.onset, self.duration, self.description, self.ch_names = _check_o_d_s_c(
onset, duration, description, ch_names
Expand Down
4 changes: 1 addition & 3 deletions mne/beamformer/tests/test_rap_music.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ def simu_data(evoked, forward, noise_cov, n_dipoles, times, nave=1):
# Generate the two dipoles data
mu, sigma = 0.1, 0.005
s1 = (
1
/ (sigma * np.sqrt(2 * np.pi))
* np.exp(-((times - mu) ** 2) / (2 * sigma**2))
1 / (sigma * np.sqrt(2 * np.pi)) * np.exp(-((times - mu) ** 2) / (2 * sigma**2))
)

mu, sigma = 0.075, 0.008
Expand Down
73 changes: 19 additions & 54 deletions mne/channels/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,14 +585,13 @@ def drop_channels(self, ch_names, on_missing="raise"):
all_str = all([isinstance(ch, str) for ch in ch_names])
except TypeError:
raise ValueError(
"'ch_names' must be iterable, got "
"type {} ({}).".format(type(ch_names), ch_names)
f"'ch_names' must be iterable, got type {type(ch_names)} ({ch_names})."
)

if not all_str:
raise ValueError(
"Each element in 'ch_names' must be str, got "
"{}.".format([type(ch) for ch in ch_names])
f"{[type(ch) for ch in ch_names]}."
)

missing = [ch for ch in ch_names if ch not in self.ch_names]
Expand Down Expand Up @@ -1057,9 +1056,7 @@ class _BuiltinChannelAdjacency:
name="bti248grad",
description="BTI 248 gradiometer system",
fname="bti248grad_neighb.mat",
source_url=_ft_neighbor_url_t.substitute(
fname="bti248grad_neighb.mat"
), # noqa: E501
source_url=_ft_neighbor_url_t.substitute(fname="bti248grad_neighb.mat"),
),
_BuiltinChannelAdjacency(
name="ctf64",
Expand All @@ -1083,25 +1080,19 @@ class _BuiltinChannelAdjacency:
name="easycap32ch-avg",
description="",
fname="easycap32ch-avg_neighb.mat",
source_url=_ft_neighbor_url_t.substitute(
fname="easycap32ch-avg_neighb.mat"
), # noqa: E501
source_url=_ft_neighbor_url_t.substitute(fname="easycap32ch-avg_neighb.mat"),
),
_BuiltinChannelAdjacency(
name="easycap64ch-avg",
description="",
fname="easycap64ch-avg_neighb.mat",
source_url=_ft_neighbor_url_t.substitute(
fname="easycap64ch-avg_neighb.mat"
), # noqa: E501
source_url=_ft_neighbor_url_t.substitute(fname="easycap64ch-avg_neighb.mat"),
),
_BuiltinChannelAdjacency(
name="easycap128ch-avg",
description="",
fname="easycap128ch-avg_neighb.mat",
source_url=_ft_neighbor_url_t.substitute(
fname="easycap128ch-avg_neighb.mat"
), # noqa: E501
source_url=_ft_neighbor_url_t.substitute(fname="easycap128ch-avg_neighb.mat"),
),
_BuiltinChannelAdjacency(
name="easycapM1",
Expand All @@ -1113,25 +1104,19 @@ class _BuiltinChannelAdjacency:
name="easycapM11",
description="Easycap M11",
fname="easycapM11_neighb.mat",
source_url=_ft_neighbor_url_t.substitute(
fname="easycapM11_neighb.mat"
), # noqa: E501
source_url=_ft_neighbor_url_t.substitute(fname="easycapM11_neighb.mat"), # noqa: E501
),
_BuiltinChannelAdjacency(
name="easycapM14",
description="Easycap M14",
fname="easycapM14_neighb.mat",
source_url=_ft_neighbor_url_t.substitute(
fname="easycapM14_neighb.mat"
), # noqa: E501
source_url=_ft_neighbor_url_t.substitute(fname="easycapM14_neighb.mat"), # noqa: E501
),
_BuiltinChannelAdjacency(
name="easycapM15",
description="Easycap M15",
fname="easycapM15_neighb.mat",
source_url=_ft_neighbor_url_t.substitute(
fname="easycapM15_neighb.mat"
), # noqa: E501
source_url=_ft_neighbor_url_t.substitute(fname="easycapM15_neighb.mat"), # noqa: E501
),
_BuiltinChannelAdjacency(
name="KIT-157",
Expand Down Expand Up @@ -1179,49 +1164,37 @@ class _BuiltinChannelAdjacency:
name="neuromag306mag",
description="Neuromag306, only magnetometers",
fname="neuromag306mag_neighb.mat",
source_url=_ft_neighbor_url_t.substitute(
fname="neuromag306mag_neighb.mat"
), # noqa: E501
source_url=_ft_neighbor_url_t.substitute(fname="neuromag306mag_neighb.mat"), # noqa: E501
),
_BuiltinChannelAdjacency(
name="neuromag306planar",
description="Neuromag306, only planar gradiometers",
fname="neuromag306planar_neighb.mat",
source_url=_ft_neighbor_url_t.substitute(
fname="neuromag306planar_neighb.mat"
), # noqa: E501
source_url=_ft_neighbor_url_t.substitute(fname="neuromag306planar_neighb.mat"), # noqa: E501
),
_BuiltinChannelAdjacency(
name="neuromag122cmb",
description="Neuromag122, only combined planar gradiometers",
fname="neuromag122cmb_neighb.mat",
source_url=_ft_neighbor_url_t.substitute(
fname="neuromag122cmb_neighb.mat"
), # noqa: E501
source_url=_ft_neighbor_url_t.substitute(fname="neuromag122cmb_neighb.mat"), # noqa: E501
),
_BuiltinChannelAdjacency(
name="neuromag306cmb",
description="Neuromag306, only combined planar gradiometers",
fname="neuromag306cmb_neighb.mat",
source_url=_ft_neighbor_url_t.substitute(
fname="neuromag306cmb_neighb.mat"
), # noqa: E501
source_url=_ft_neighbor_url_t.substitute(fname="neuromag306cmb_neighb.mat"), # noqa: E501
),
_BuiltinChannelAdjacency(
name="ecog256",
description="ECOG 256channels, average referenced",
fname="ecog256_neighb.mat",
source_url=_ft_neighbor_url_t.substitute(
fname="ecog256_neighb.mat"
), # noqa: E501
source_url=_ft_neighbor_url_t.substitute(fname="ecog256_neighb.mat"), # noqa: E501
),
_BuiltinChannelAdjacency(
name="ecog256bipolar",
description="ECOG 256channels, bipolar referenced",
fname="ecog256bipolar_neighb.mat",
source_url=_ft_neighbor_url_t.substitute(
fname="ecog256bipolar_neighb.mat"
), # noqa: E501
source_url=_ft_neighbor_url_t.substitute(fname="ecog256bipolar_neighb.mat"), # noqa: E501
),
_BuiltinChannelAdjacency(
name="eeg1010_neighb",
Expand Down Expand Up @@ -1263,33 +1236,25 @@ class _BuiltinChannelAdjacency:
name="language29ch-avg",
description="MPI for Psycholinguistic: Averaged 29-channel cap",
fname="language29ch-avg_neighb.mat",
source_url=_ft_neighbor_url_t.substitute(
fname="language29ch-avg_neighb.mat"
), # noqa: E501
source_url=_ft_neighbor_url_t.substitute(fname="language29ch-avg_neighb.mat"), # noqa: E501
),
_BuiltinChannelAdjacency(
name="mpi_59_channels",
description="MPI for Psycholinguistic: 59-channel cap",
fname="mpi_59_channels_neighb.mat",
source_url=_ft_neighbor_url_t.substitute(
fname="mpi_59_channels_neighb.mat"
), # noqa: E501
source_url=_ft_neighbor_url_t.substitute(fname="mpi_59_channels_neighb.mat"), # noqa: E501
),
_BuiltinChannelAdjacency(
name="yokogawa160",
description="",
fname="yokogawa160_neighb.mat",
source_url=_ft_neighbor_url_t.substitute(
fname="yokogawa160_neighb.mat"
), # noqa: E501
source_url=_ft_neighbor_url_t.substitute(fname="yokogawa160_neighb.mat"), # noqa: E501
),
_BuiltinChannelAdjacency(
name="yokogawa440",
description="",
fname="yokogawa440_neighb.mat",
source_url=_ft_neighbor_url_t.substitute(
fname="yokogawa440_neighb.mat"
), # noqa: E501
source_url=_ft_neighbor_url_t.substitute(fname="yokogawa440_neighb.mat"), # noqa: E501
),
]

Expand Down
5 changes: 1 addition & 4 deletions mne/channels/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,7 @@ def _interpolate_bads_eeg(inst, origin, exclude=None, verbose=None):

pos_good = pos[goods_idx_pos] - origin
pos_bad = pos[bads_idx_pos] - origin
logger.info(
"Computing interpolation matrix from {} sensor "
"positions".format(len(pos_good))
)
logger.info(f"Computing interpolation matrix from {len(pos_good)} sensor positions")
interpolation = _make_interpolation_matrix(pos_good, pos_bad)

logger.info("Interpolating {} sensors".format(len(pos_bad)))
Expand Down
2 changes: 1 addition & 1 deletion mne/channels/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Layout:
The type of Layout (e.g. 'Vectorview-all').
"""

def __init__(self, box, pos, names, ids, kind): # noqa: D102
def __init__(self, box, pos, names, ids, kind):
self.box = box
self.pos = pos
self.names = names
Expand Down
3 changes: 1 addition & 2 deletions mne/commands/mne_freeview_bem_surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def freeview_bem_surfaces(subject, subjects_dir, method):

if not op.isdir(subject_dir):
raise ValueError(
"Wrong path: '{}'. Check subjects-dir or"
"subject argument.".format(subject_dir)
f"Wrong path: '{subject_dir}'. Check subjects-dir or subject argument."
)

env = os.environ.copy()
Expand Down
4 changes: 2 additions & 2 deletions mne/coreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,8 @@ def fit_matched_points(
tgt_pts = np.atleast_2d(tgt_pts)
if src_pts.shape != tgt_pts.shape:
raise ValueError(
"src_pts and tgt_pts must have same shape (got "
"{}, {})".format(src_pts.shape, tgt_pts.shape)
"src_pts and tgt_pts must have same shape "
f"(got {src_pts.shape}, {tgt_pts.shape})"
)
if weights is not None:
weights = np.asarray(weights, src_pts.dtype)
Expand Down
4 changes: 1 addition & 3 deletions mne/datasets/sleep_physionet/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
)
TEMAZEPAM_RECORDS_URL_SHA1 = "f52fffe5c18826a2bd4c5d5cb375bb4a9008c885"

AGE_RECORDS_URL = (
"https://physionet.org/physiobank/database/sleep-edfx/SC-subjects.xls" # noqa: E501
)
AGE_RECORDS_URL = "https://physionet.org/physiobank/database/sleep-edfx/SC-subjects.xls"
AGE_RECORDS_URL_SHA1 = "0ba6650892c5d33a8e2b3f62ce1cc9f30438c54f"

sha1sums_fname = op.join(op.dirname(__file__), "SHA1SUMS")
Expand Down
4 changes: 1 addition & 3 deletions mne/datasets/sleep_physionet/age.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@

data_path = _data_path # expose _data_path(..) as data_path(..)

BASE_URL = (
"https://physionet.org/physiobank/database/sleep-edfx/sleep-cassette/" # noqa: E501
)
BASE_URL = "https://physionet.org/physiobank/database/sleep-edfx/sleep-cassette/"


@verbose
Expand Down
2 changes: 1 addition & 1 deletion mne/decoding/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class LinearModel(BaseEstimator):
"classes_",
)

def __init__(self, model=None): # noqa: D102
def __init__(self, model=None):
if model is None:
from sklearn.linear_model import LogisticRegression

Expand Down
2 changes: 1 addition & 1 deletion mne/decoding/search_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(
position=0,
allow_2d=False,
verbose=None,
): # noqa: D102
):
_check_estimator(base_estimator)
self.base_estimator = base_estimator
self.n_jobs = n_jobs
Expand Down
2 changes: 1 addition & 1 deletion mne/decoding/time_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(
output="complex",
n_jobs=1,
verbose=None,
): # noqa: D102
):
"""Init TimeFrequency transformer."""
# Check non-average output
output = _check_option("output", output, ["complex", "power", "phase"])
Expand Down
Loading

0 comments on commit e7dd158

Please sign in to comment.