Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MRG: Use ruff-format instead of Black #12261

Merged
merged 20 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
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
20 changes: 12 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
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:
# lint
- id: ruff
name: ruff mne
name: lint mne
args: ["--fix"]
files: ^mne/
# format
- id: ruff-format
name: format mne
files: ^mne/

# Ruff tutorials and examples
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.6
hooks:
# Lint
- id: ruff
name: ruff tutorials and examples
name: 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/
# Format
- id: ruff-format
name: 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))
Copy link
Member

Choose a reason for hiding this comment

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

I was wondering why we had a ton of lines removed... I'm guessing it's mostly from this. I consider this a nice readability win

Copy link
Member Author

Choose a reason for hiding this comment

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

Same.

)

mu, sigma = 0.075, 0.008
Expand Down
78 changes: 23 additions & 55 deletions mne/channels/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,14 +585,16 @@ 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)
"'ch_names' must be iterable, got " "type {} ({}).".format(
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])
"Each element in 'ch_names' must be str, got " "{}.".format(
[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 +1059,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"), # noqa: E501
),
_BuiltinChannelAdjacency(
name="ctf64",
Expand All @@ -1083,25 +1083,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"), # noqa: E501
),
_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"), # noqa: E501
),
_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"), # noqa: E501
),
_BuiltinChannelAdjacency(
name="easycapM1",
Expand All @@ -1113,25 +1107,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 +1167,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 +1239,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: 3 additions & 2 deletions mne/channels/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ 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))
"Computing interpolation matrix from {} sensor " "positions".format(
len(pos_good)
)
)
interpolation = _make_interpolation_matrix(pos_good, 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
5 changes: 3 additions & 2 deletions mne/commands/mne_freeview_bem_surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ 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)
"Wrong path: '{}'. Check subjects-dir or" "subject argument.".format(
subject_dir
)
)

env = os.environ.copy()
Expand Down
5 changes: 3 additions & 2 deletions mne/coreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,9 @@ 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 (got " "{}, {})".format(
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" # noqa: E501
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/" # noqa: E501


@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