Skip to content

Commit e7dd158

Browse files
hoechenbergerlarsonerdrammock
authored
MRG: Use ruff-format instead of Black (#12261)
Co-authored-by: Eric Larson <larson.eric.d@gmail.com> Co-authored-by: Daniel McCloy <dan@mccloy.info>
1 parent 092cf90 commit e7dd158

71 files changed

Lines changed: 541 additions & 1381 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/tests.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ jobs:
2323
- uses: actions/setup-python@v4
2424
with:
2525
python-version: '3.11'
26-
- uses: psf/black@stable
2726
- uses: pre-commit/action@v3.0.0
2827

2928
bandit:

.pre-commit-config.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
repos:
2-
- repo: https://github.com/psf/black
3-
rev: 23.11.0
4-
hooks:
5-
- id: black
6-
args: [--quiet]
7-
82
# Ruff mne
93
- repo: https://github.com/astral-sh/ruff-pre-commit
104
rev: v0.1.6
115
hooks:
126
- id: ruff
13-
name: ruff mne
7+
name: ruff lint mne
148
args: ["--fix"]
159
files: ^mne/
10+
- id: ruff-format
11+
name: ruff format mne
12+
files: ^mne/
1613

1714
# Ruff tutorials and examples
1815
- repo: https://github.com/astral-sh/ruff-pre-commit
1916
rev: v0.1.6
2017
hooks:
2118
- id: ruff
22-
name: ruff tutorials and examples
19+
name: ruff lint tutorials and examples
2320
# D103: missing docstring in public function
2421
# D400: docstring first line must end with period
2522
args: ["--ignore=D103,D400", "--fix"]
2623
files: ^tutorials/|^examples/
24+
- id: ruff-format
25+
name: ruff format tutorials and examples
26+
files: ^tutorials/|^examples/
2727

2828
# Codespell
2929
- repo: https://github.com/codespell-project/codespell

mne/_fiff/tag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Tag:
4545
Position of Tag is the original file.
4646
"""
4747

48-
def __init__(self, kind, type_, size, next, pos=None): # noqa: D102
48+
def __init__(self, kind, type_, size, next, pos=None):
4949
self.kind = int(kind)
5050
self.type = int(type_)
5151
self.size = int(size)

mne/_fiff/tests/test_constants.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -385,16 +385,16 @@ def test_constants(tmp_path):
385385
for key in fif["coil"]:
386386
if key not in _missing_coil_def and key not in coil_def:
387387
bad_list.append((" %s," % key).ljust(10) + " # " + fif["coil"][key][1])
388-
assert (
389-
len(bad_list) == 0
390-
), "\nIn fiff-constants, missing from coil_def:\n" + "\n".join(bad_list)
388+
assert len(bad_list) == 0, (
389+
"\nIn fiff-constants, missing from coil_def:\n" + "\n".join(bad_list)
390+
)
391391
# Assert that enum(coil) has all `coil_def.dat` entries
392392
for key, desc in zip(coil_def, coil_desc):
393393
if key not in fif["coil"]:
394394
bad_list.append((" %s," % key).ljust(10) + " # " + desc)
395-
assert (
396-
len(bad_list) == 0
397-
), "In coil_def, missing from fiff-constants:\n" + "\n".join(bad_list)
395+
assert len(bad_list) == 0, (
396+
"In coil_def, missing from fiff-constants:\n" + "\n".join(bad_list)
397+
)
398398

399399

400400
@pytest.mark.parametrize(

mne/annotations.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,7 @@ class Annotations:
276276
:meth:`Raw.save() <mne.io.Raw.save>` notes for details.
277277
""" # noqa: E501
278278

279-
def __init__(
280-
self, onset, duration, description, orig_time=None, ch_names=None
281-
): # noqa: D102
279+
def __init__(self, onset, duration, description, orig_time=None, ch_names=None):
282280
self._orig_time = _handle_meas_date(orig_time)
283281
self.onset, self.duration, self.description, self.ch_names = _check_o_d_s_c(
284282
onset, duration, description, ch_names

mne/beamformer/tests/test_rap_music.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ def simu_data(evoked, forward, noise_cov, n_dipoles, times, nave=1):
5050
# Generate the two dipoles data
5151
mu, sigma = 0.1, 0.005
5252
s1 = (
53-
1
54-
/ (sigma * np.sqrt(2 * np.pi))
55-
* np.exp(-((times - mu) ** 2) / (2 * sigma**2))
53+
1 / (sigma * np.sqrt(2 * np.pi)) * np.exp(-((times - mu) ** 2) / (2 * sigma**2))
5654
)
5755

5856
mu, sigma = 0.075, 0.008

mne/channels/channels.py

Lines changed: 19 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -585,14 +585,13 @@ def drop_channels(self, ch_names, on_missing="raise"):
585585
all_str = all([isinstance(ch, str) for ch in ch_names])
586586
except TypeError:
587587
raise ValueError(
588-
"'ch_names' must be iterable, got "
589-
"type {} ({}).".format(type(ch_names), ch_names)
588+
f"'ch_names' must be iterable, got type {type(ch_names)} ({ch_names})."
590589
)
591590

592591
if not all_str:
593592
raise ValueError(
594593
"Each element in 'ch_names' must be str, got "
595-
"{}.".format([type(ch) for ch in ch_names])
594+
f"{[type(ch) for ch in ch_names]}."
596595
)
597596

598597
missing = [ch for ch in ch_names if ch not in self.ch_names]
@@ -1057,9 +1056,7 @@ class _BuiltinChannelAdjacency:
10571056
name="bti248grad",
10581057
description="BTI 248 gradiometer system",
10591058
fname="bti248grad_neighb.mat",
1060-
source_url=_ft_neighbor_url_t.substitute(
1061-
fname="bti248grad_neighb.mat"
1062-
), # noqa: E501
1059+
source_url=_ft_neighbor_url_t.substitute(fname="bti248grad_neighb.mat"),
10631060
),
10641061
_BuiltinChannelAdjacency(
10651062
name="ctf64",
@@ -1083,25 +1080,19 @@ class _BuiltinChannelAdjacency:
10831080
name="easycap32ch-avg",
10841081
description="",
10851082
fname="easycap32ch-avg_neighb.mat",
1086-
source_url=_ft_neighbor_url_t.substitute(
1087-
fname="easycap32ch-avg_neighb.mat"
1088-
), # noqa: E501
1083+
source_url=_ft_neighbor_url_t.substitute(fname="easycap32ch-avg_neighb.mat"),
10891084
),
10901085
_BuiltinChannelAdjacency(
10911086
name="easycap64ch-avg",
10921087
description="",
10931088
fname="easycap64ch-avg_neighb.mat",
1094-
source_url=_ft_neighbor_url_t.substitute(
1095-
fname="easycap64ch-avg_neighb.mat"
1096-
), # noqa: E501
1089+
source_url=_ft_neighbor_url_t.substitute(fname="easycap64ch-avg_neighb.mat"),
10971090
),
10981091
_BuiltinChannelAdjacency(
10991092
name="easycap128ch-avg",
11001093
description="",
11011094
fname="easycap128ch-avg_neighb.mat",
1102-
source_url=_ft_neighbor_url_t.substitute(
1103-
fname="easycap128ch-avg_neighb.mat"
1104-
), # noqa: E501
1095+
source_url=_ft_neighbor_url_t.substitute(fname="easycap128ch-avg_neighb.mat"),
11051096
),
11061097
_BuiltinChannelAdjacency(
11071098
name="easycapM1",
@@ -1113,25 +1104,19 @@ class _BuiltinChannelAdjacency:
11131104
name="easycapM11",
11141105
description="Easycap M11",
11151106
fname="easycapM11_neighb.mat",
1116-
source_url=_ft_neighbor_url_t.substitute(
1117-
fname="easycapM11_neighb.mat"
1118-
), # noqa: E501
1107+
source_url=_ft_neighbor_url_t.substitute(fname="easycapM11_neighb.mat"), # noqa: E501
11191108
),
11201109
_BuiltinChannelAdjacency(
11211110
name="easycapM14",
11221111
description="Easycap M14",
11231112
fname="easycapM14_neighb.mat",
1124-
source_url=_ft_neighbor_url_t.substitute(
1125-
fname="easycapM14_neighb.mat"
1126-
), # noqa: E501
1113+
source_url=_ft_neighbor_url_t.substitute(fname="easycapM14_neighb.mat"), # noqa: E501
11271114
),
11281115
_BuiltinChannelAdjacency(
11291116
name="easycapM15",
11301117
description="Easycap M15",
11311118
fname="easycapM15_neighb.mat",
1132-
source_url=_ft_neighbor_url_t.substitute(
1133-
fname="easycapM15_neighb.mat"
1134-
), # noqa: E501
1119+
source_url=_ft_neighbor_url_t.substitute(fname="easycapM15_neighb.mat"), # noqa: E501
11351120
),
11361121
_BuiltinChannelAdjacency(
11371122
name="KIT-157",
@@ -1179,49 +1164,37 @@ class _BuiltinChannelAdjacency:
11791164
name="neuromag306mag",
11801165
description="Neuromag306, only magnetometers",
11811166
fname="neuromag306mag_neighb.mat",
1182-
source_url=_ft_neighbor_url_t.substitute(
1183-
fname="neuromag306mag_neighb.mat"
1184-
), # noqa: E501
1167+
source_url=_ft_neighbor_url_t.substitute(fname="neuromag306mag_neighb.mat"), # noqa: E501
11851168
),
11861169
_BuiltinChannelAdjacency(
11871170
name="neuromag306planar",
11881171
description="Neuromag306, only planar gradiometers",
11891172
fname="neuromag306planar_neighb.mat",
1190-
source_url=_ft_neighbor_url_t.substitute(
1191-
fname="neuromag306planar_neighb.mat"
1192-
), # noqa: E501
1173+
source_url=_ft_neighbor_url_t.substitute(fname="neuromag306planar_neighb.mat"), # noqa: E501
11931174
),
11941175
_BuiltinChannelAdjacency(
11951176
name="neuromag122cmb",
11961177
description="Neuromag122, only combined planar gradiometers",
11971178
fname="neuromag122cmb_neighb.mat",
1198-
source_url=_ft_neighbor_url_t.substitute(
1199-
fname="neuromag122cmb_neighb.mat"
1200-
), # noqa: E501
1179+
source_url=_ft_neighbor_url_t.substitute(fname="neuromag122cmb_neighb.mat"), # noqa: E501
12011180
),
12021181
_BuiltinChannelAdjacency(
12031182
name="neuromag306cmb",
12041183
description="Neuromag306, only combined planar gradiometers",
12051184
fname="neuromag306cmb_neighb.mat",
1206-
source_url=_ft_neighbor_url_t.substitute(
1207-
fname="neuromag306cmb_neighb.mat"
1208-
), # noqa: E501
1185+
source_url=_ft_neighbor_url_t.substitute(fname="neuromag306cmb_neighb.mat"), # noqa: E501
12091186
),
12101187
_BuiltinChannelAdjacency(
12111188
name="ecog256",
12121189
description="ECOG 256channels, average referenced",
12131190
fname="ecog256_neighb.mat",
1214-
source_url=_ft_neighbor_url_t.substitute(
1215-
fname="ecog256_neighb.mat"
1216-
), # noqa: E501
1191+
source_url=_ft_neighbor_url_t.substitute(fname="ecog256_neighb.mat"), # noqa: E501
12171192
),
12181193
_BuiltinChannelAdjacency(
12191194
name="ecog256bipolar",
12201195
description="ECOG 256channels, bipolar referenced",
12211196
fname="ecog256bipolar_neighb.mat",
1222-
source_url=_ft_neighbor_url_t.substitute(
1223-
fname="ecog256bipolar_neighb.mat"
1224-
), # noqa: E501
1197+
source_url=_ft_neighbor_url_t.substitute(fname="ecog256bipolar_neighb.mat"), # noqa: E501
12251198
),
12261199
_BuiltinChannelAdjacency(
12271200
name="eeg1010_neighb",
@@ -1263,33 +1236,25 @@ class _BuiltinChannelAdjacency:
12631236
name="language29ch-avg",
12641237
description="MPI for Psycholinguistic: Averaged 29-channel cap",
12651238
fname="language29ch-avg_neighb.mat",
1266-
source_url=_ft_neighbor_url_t.substitute(
1267-
fname="language29ch-avg_neighb.mat"
1268-
), # noqa: E501
1239+
source_url=_ft_neighbor_url_t.substitute(fname="language29ch-avg_neighb.mat"), # noqa: E501
12691240
),
12701241
_BuiltinChannelAdjacency(
12711242
name="mpi_59_channels",
12721243
description="MPI for Psycholinguistic: 59-channel cap",
12731244
fname="mpi_59_channels_neighb.mat",
1274-
source_url=_ft_neighbor_url_t.substitute(
1275-
fname="mpi_59_channels_neighb.mat"
1276-
), # noqa: E501
1245+
source_url=_ft_neighbor_url_t.substitute(fname="mpi_59_channels_neighb.mat"), # noqa: E501
12771246
),
12781247
_BuiltinChannelAdjacency(
12791248
name="yokogawa160",
12801249
description="",
12811250
fname="yokogawa160_neighb.mat",
1282-
source_url=_ft_neighbor_url_t.substitute(
1283-
fname="yokogawa160_neighb.mat"
1284-
), # noqa: E501
1251+
source_url=_ft_neighbor_url_t.substitute(fname="yokogawa160_neighb.mat"), # noqa: E501
12851252
),
12861253
_BuiltinChannelAdjacency(
12871254
name="yokogawa440",
12881255
description="",
12891256
fname="yokogawa440_neighb.mat",
1290-
source_url=_ft_neighbor_url_t.substitute(
1291-
fname="yokogawa440_neighb.mat"
1292-
), # noqa: E501
1257+
source_url=_ft_neighbor_url_t.substitute(fname="yokogawa440_neighb.mat"), # noqa: E501
12931258
),
12941259
]
12951260

mne/channels/interpolation.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,7 @@ def _interpolate_bads_eeg(inst, origin, exclude=None, verbose=None):
165165

166166
pos_good = pos[goods_idx_pos] - origin
167167
pos_bad = pos[bads_idx_pos] - origin
168-
logger.info(
169-
"Computing interpolation matrix from {} sensor "
170-
"positions".format(len(pos_good))
171-
)
168+
logger.info(f"Computing interpolation matrix from {len(pos_good)} sensor positions")
172169
interpolation = _make_interpolation_matrix(pos_good, pos_bad)
173170

174171
logger.info("Interpolating {} sensors".format(len(pos_bad)))

mne/channels/layout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Layout:
5858
The type of Layout (e.g. 'Vectorview-all').
5959
"""
6060

61-
def __init__(self, box, pos, names, ids, kind): # noqa: D102
61+
def __init__(self, box, pos, names, ids, kind):
6262
self.box = box
6363
self.pos = pos
6464
self.names = names

mne/commands/mne_freeview_bem_surfaces.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ def freeview_bem_surfaces(subject, subjects_dir, method):
4141

4242
if not op.isdir(subject_dir):
4343
raise ValueError(
44-
"Wrong path: '{}'. Check subjects-dir or"
45-
"subject argument.".format(subject_dir)
44+
f"Wrong path: '{subject_dir}'. Check subjects-dir or subject argument."
4645
)
4746

4847
env = os.environ.copy()

0 commit comments

Comments
 (0)