Skip to content

Commit

Permalink
Add new lint rules, remove unneeded noqa calls, refine noqa calls (#1283
Browse files Browse the repository at this point in the history
)

* handle noqa

* fixes of fixes

* fix fmt -> format

* add whatsnew

* silly fix
  • Loading branch information
sappelhoff authored Jul 28, 2024
1 parent 9165526 commit 1c9361c
Show file tree
Hide file tree
Showing 26 changed files with 79 additions and 84 deletions.
3 changes: 1 addition & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import sys
from datetime import date

import sphinx_gallery # noqa: F401
from sphinx.config import is_serializable

import mne_bids
Expand Down Expand Up @@ -96,7 +95,7 @@
# General information about the project.
project = "MNE-BIDS"
today = date.today().isoformat()
copyright = f"2017, The MNE-BIDS developers. Last updated on {today}"
copyright = f"2017, The MNE-BIDS developers. Last updated on {today}" # noqa: A001

author = "The MNE-BIDS developers"

Expand Down
1 change: 1 addition & 0 deletions doc/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Detailed list of changes
^^^^^^^^^^^^^^

- Keep MNE-BIDS up to date with recent changes on participant birthday date handling in MNE-Python, by `Eric Larson`_ (gh:1278:)
- Make rules for linting more strict, make quality assessment exceptions less permissive, by `Stefan Appelhoff`_ (gh:1283:)

:doc:`Find out what was new in previous releases <whats_new_previous_releases>`

Expand Down
2 changes: 1 addition & 1 deletion examples/bidspath.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
BIDSPath is MNE-BIDS's working horse when it comes to file and folder
operations. Learn here how to use it.
"""
""" # noqa: D400

# Authors: The MNE-BIDS developers
# SPDX-License-Identifier: BSD-3-Clause
Expand Down
3 changes: 1 addition & 2 deletions examples/convert_eeg_to_bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
.. _BrainVision format: https://www.brainproducts.com/support-resources/brainvision-core-data-format-1-0/
.. _CapTrak: https://www.fieldtriptoolbox.org/faq/coordsys/#details-of-the-captrak-coordinate-system
""" # noqa: E501
""" # noqa: E501 D205 D400

# Authors: The MNE-BIDS developers
# SPDX-License-Identifier: BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion examples/convert_empty_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
This example demonstrates how to store empty room data "manually" in the BIDS
format and how to retrieve them.
"""
""" # noqa: E501 D400

# Authors: The MNE-BIDS developers
# SPDX-License-Identifier: BSD-3-Clause
Expand Down
3 changes: 2 additions & 1 deletion examples/convert_group_studies.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
=====================================
05. BIDS conversion for group studies
=====================================
Here, we show how to do BIDS conversion for group studies.
We will use the
`EEG Motor Movement/Imagery Dataset <https://doi.org/10.13026/C28G6P>`_
available on the PhysioBank database.
We recommend that you go through the more basic BIDS conversion example before
checking out this group conversion example: :ref:`ex-convert-mne-sample`
"""
""" # noqa: E501 D205 D400

# Authors: The MNE-BIDS developers
# SPDX-License-Identifier: BSD-3-Clause
Expand Down
3 changes: 1 addition & 2 deletions examples/convert_ieeg_to_bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
.. _appendix VIII: https://bids-specification.readthedocs.io/en/stable/appendices/coordinate-systems.html
.. _background on FreeSurfer: https://mne.tools/dev/auto_tutorials/source-modeling/plot_background_freesurfer_mne
.. _MNE-Python coordinate frames: https://mne.tools/dev/auto_tutorials/source-modeling/plot_source_alignment.html
""" # noqa: E501
""" # noqa: E501 D400

# Authors: The MNE-BIDS developers
# SPDX-License-Identifier: BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion examples/convert_mne_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
.. _BIDS dataset_description.json definition: https://bids-specification.readthedocs.io/en/latest/modality-agnostic-files.html#dataset-description
.. _ds000248 dataset_description.json: https://github.com/sappelhoff/bids-examples/blob/master/ds000248/dataset_description.json
""" # noqa: D400 D205 E501
""" # noqa: D400 E501

# Authors: The MNE-BIDS developers
# SPDX-License-Identifier: BSD-3-Clause
Expand Down
3 changes: 1 addition & 2 deletions examples/convert_mri_and_trans.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
.. note:: For this example you will need to install ``matplotlib`` and
``nilearn`` on top of your usual ``mne-bids`` installation.
"""
""" # noqa: E501 D205 D400

# Authors: The MNE-BIDS developers
# SPDX-License-Identifier: BSD-3-Clause
Expand Down
3 changes: 1 addition & 2 deletions examples/convert_nirs_to_bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
4. Cite ``mne-bids``.
.. currentmodule:: mne_bids
""" # noqa: E501
""" # noqa: E501 D205 D400

# Authors: The MNE-BIDS developers
# SPDX-License-Identifier: BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion examples/create_bids_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
You may automatically convert Raw objects to BIDS-compatible files with
``write_raw_bids``. This example is for manually creating files/folders.
"""
""" # noqa: E501 D205 D400

# Authors: The MNE-BIDS developers
# SPDX-License-Identifier: BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion examples/mark_bad_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
You can use MNE-BIDS interactively inspect your MEG or (i)EEG data.
Problematic channels can be marked as "bad", for example if the connected
sensor produced mostly noise or no signal at all. Similarly, you can declare
sensor produced mostly noise - or no signal at all. Similarly, you can declare
channels as "good", should you discover they were incorrectly marked as bad.
Bad channel selection can also be performed non-interactively.
Expand Down
3 changes: 1 addition & 2 deletions examples/read_bids_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
In this tutorial, we show how ``read_raw_bids`` can be used to load and
inspect BIDS-formatted data.
"""
""" # noqa: D400

# Authors: The MNE-BIDS developers
# SPDX-License-Identifier: BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion examples/rename_brainvision_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
for the :ref:`Python Command Line Interface <python_cli>`.
.. _BrainVision data format: https://www.brainproducts.com/support-resources/brainvision-core-data-format-1-0/
""" # noqa:E501
""" # noqa: E501 D205 D400

# Authors: The MNE-BIDS developers
# SPDX-License-Identifier: BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion examples/update_bids_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
In this tutorial, we show how ``update_sidecar_json`` can be used to update and
modify BIDS-formatted data.
"""
""" # noqa: D205 D400

# Authors: The MNE-BIDS developers
# SPDX-License-Identifier: BSD-3-Clause
Expand Down
6 changes: 3 additions & 3 deletions mne_bids/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@
ALLOWED_SPACES["anat"] = None
ALLOWED_SPACES["beh"] = None

# See: https://bids-specification.readthedocs.io/en/latest/appendices/entity-table.html#encephalography-eeg-ieeg-and-meg # noqa
# See: https://bids-specification.readthedocs.io/en/latest/appendices/entity-table.html#encephalography-eeg-ieeg-and-meg # noqa: E501
ENTITY_VALUE_TYPE = {
"subject": "label",
"session": "label",
Expand All @@ -340,8 +340,8 @@
"ElektaNeuromag": "head",
"ChietiItab": "head",
"CapTrak": "head",
"ACPC": "ras", # assumes T1 is ACPC-aligned, if not the coordinates are lost # noqa
"fsaverage": "mni_tal", # XXX: note fsaverage and MNI305 are the same # noqa
"ACPC": "ras", # assumes T1 is ACPC-aligned, if not the coordinates are lost
"fsaverage": "mni_tal", # XXX: note fsaverage and MNI305 are the same
"MNI305": "mni_tal",
}

Expand Down
8 changes: 4 additions & 4 deletions mne_bids/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -1861,13 +1861,13 @@ def get_datatypes(root, verbose=None):
"""
# Take all possible data types from "entity" table
# (Appendix in BIDS spec)
# https://bids-specification.readthedocs.io/en/latest/appendices/entity-table.html # noqa
# https://bids-specification.readthedocs.io/en/latest/appendices/entity-table.html
datatype_list = ("anat", "func", "dwi", "fmap", "beh", "meg", "eeg", "ieeg", "nirs")
datatypes = list()
for root, dirs, files in os.walk(root):
for dir in dirs:
if dir in datatype_list and dir not in datatypes:
datatypes.append(dir)
for _dir in dirs:
if _dir in datatype_list and _dir not in datatypes:
datatypes.append(_dir)

return datatypes

Expand Down
2 changes: 1 addition & 1 deletion mne_bids/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ def _handle_channels_reading(channels_fname, raw):

if updated_ch_type is None:
# XXX Try again with uppercase spelling – this should be removed
# XXX once https://github.com/bids-standard/bids-validator/issues/1018 # noqa:E501
# XXX once https://github.com/bids-standard/bids-validator/issues/1018
# XXX has been resolved.
# XXX x-ref https://github.com/mne-tools/mne-bids/issues/481
updated_ch_type = bids_to_mne_ch_types.get(ch_type.upper(), None)
Expand Down
4 changes: 2 additions & 2 deletions mne_bids/report/_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ def _pretty_str(listed):
return "{}, and {}".format(", ".join(listed[:-1]), listed[-1])


def _range_str(minval, maxval, meanval, stdval, n_unknown, type):
def _range_str(minval, maxval, meanval, stdval, n_unknown, typ):
if minval == "n/a":
return "ages all unknown"

if n_unknown > 0:
unknown_str = f"; {n_unknown} with unknown {type}"
unknown_str = f"; {n_unknown} with unknown {typ}"
else:
unknown_str = ""
return (
Expand Down
4 changes: 2 additions & 2 deletions mne_bids/tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def test_parse_ext():
[
"sub-01_ses-02_task-test_run-3_split-1_meg.fif",
"sub-01_ses-02_task-test_run-3_split-1",
"/bids_root/sub-01/ses-02/meg/sub-01_ses-02_task-test_run-3_split-1_meg.fif", # noqa: E501
"/bids_root/sub-01/ses-02/meg/sub-01_ses-02_task-test_run-3_split-1_meg.fif",
"sub-01/ses-02/meg/sub-01_ses-02_task-test_run-3_split-1_meg.fif",
],
)
Expand Down Expand Up @@ -898,7 +898,7 @@ def test_make_filenames():
assert (
basename.basename
== "sub-one_ses-two_task-three_acq-four_run-1_proc-six_rec-seven_ieeg.h5"
) # noqa
)

# what happens with scans.tsv file
with pytest.raises(ValueError, match="scans.tsv file name can only contain"):
Expand Down
4 changes: 2 additions & 2 deletions mne_bids/tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_report(tmp_path):
20.0 to 20.0 seconds (mean = 20.0, std = 0.0), for a total of 20.0 seconds of
data recorded over all scans. For each dataset, there were on average 376.0 (std
= 0.0) recording channels per scan, out of which 374.0 (std = 0.0) were used in
analysis (2.0 +/- 0.0 were removed from analysis).""" # noqa
analysis (2.0 +/- 0.0 were removed from analysis).""" # noqa: E501

expected_report = "\n".join(textwrap.wrap(expected_report, width=80))
assert report == expected_report
Expand Down Expand Up @@ -89,7 +89,7 @@ def test_report_no_participant_information(tmp_path):
20.0 to 20.0 seconds (mean = 20.0, std = 0.0), for a total of 20.0 seconds of
data recorded over all scans. For each dataset, there were on average 376.0 (std
= 0.0) recording channels per scan, out of which 374.0 (std = 0.0) were used in
analysis (2.0 +/- 0.0 were removed from analysis).""" # noqa
analysis (2.0 +/- 0.0 were removed from analysis).""" # noqa: E501

expected_report = "\n".join(textwrap.wrap(expected_report, width=80))
assert report == expected_report
4 changes: 2 additions & 2 deletions mne_bids/tests/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ def test_update_anat_landmarks(tmp_path):
)
expected_coords_in_voxels = np.array(
[
[68.38202, 45.24057, 43.439808], # noqa: E241
[42.27006, 30.758774, 74.09837], # noqa: E202, E241
[68.38202, 45.24057, 43.439808],
[42.27006, 30.758774, 74.09837],
[17.044853, 46.586075, 42.618504],
]
)
Expand Down
Loading

0 comments on commit 1c9361c

Please sign in to comment.