diff --git a/doc/conf.py b/doc/conf.py index f1bb43563..38db22561 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -7,7 +7,6 @@ import sys from datetime import date -import sphinx_gallery # noqa: F401 from sphinx.config import is_serializable import mne_bids @@ -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" diff --git a/doc/whats_new.rst b/doc/whats_new.rst index 502182fa9..03390d434 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -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 ` diff --git a/examples/bidspath.py b/examples/bidspath.py index 943821398..0430e4c72 100644 --- a/examples/bidspath.py +++ b/examples/bidspath.py @@ -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 diff --git a/examples/convert_eeg_to_bids.py b/examples/convert_eeg_to_bids.py index b3191bf8c..1ad26448f 100644 --- a/examples/convert_eeg_to_bids.py +++ b/examples/convert_eeg_to_bids.py @@ -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 diff --git a/examples/convert_empty_room.py b/examples/convert_empty_room.py index 2c6767d77..09c496bad 100644 --- a/examples/convert_empty_room.py +++ b/examples/convert_empty_room.py @@ -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 diff --git a/examples/convert_group_studies.py b/examples/convert_group_studies.py index 0990762e0..1b40010fc 100644 --- a/examples/convert_group_studies.py +++ b/examples/convert_group_studies.py @@ -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 `_ 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 diff --git a/examples/convert_ieeg_to_bids.py b/examples/convert_ieeg_to_bids.py index 32db9d8ca..74812f627 100644 --- a/examples/convert_ieeg_to_bids.py +++ b/examples/convert_ieeg_to_bids.py @@ -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 diff --git a/examples/convert_mne_sample.py b/examples/convert_mne_sample.py index 0fa6ea4fe..32be750a3 100644 --- a/examples/convert_mne_sample.py +++ b/examples/convert_mne_sample.py @@ -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 diff --git a/examples/convert_mri_and_trans.py b/examples/convert_mri_and_trans.py index 5bd3df88e..807974d82 100644 --- a/examples/convert_mri_and_trans.py +++ b/examples/convert_mri_and_trans.py @@ -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 diff --git a/examples/convert_nirs_to_bids.py b/examples/convert_nirs_to_bids.py index 8553f52ba..1400169ee 100644 --- a/examples/convert_nirs_to_bids.py +++ b/examples/convert_nirs_to_bids.py @@ -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 diff --git a/examples/create_bids_folder.py b/examples/create_bids_folder.py index b050b97b6..cdca659f0 100644 --- a/examples/create_bids_folder.py +++ b/examples/create_bids_folder.py @@ -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 diff --git a/examples/mark_bad_channels.py b/examples/mark_bad_channels.py index bd6ad7630..ce4e45309 100644 --- a/examples/mark_bad_channels.py +++ b/examples/mark_bad_channels.py @@ -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. diff --git a/examples/read_bids_datasets.py b/examples/read_bids_datasets.py index 00263d3b8..995c8c661 100644 --- a/examples/read_bids_datasets.py +++ b/examples/read_bids_datasets.py @@ -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 diff --git a/examples/rename_brainvision_files.py b/examples/rename_brainvision_files.py index 8c479dafe..a38bd46e2 100644 --- a/examples/rename_brainvision_files.py +++ b/examples/rename_brainvision_files.py @@ -27,7 +27,7 @@ for the :ref:`Python Command Line Interface `. .. _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 diff --git a/examples/update_bids_datasets.py b/examples/update_bids_datasets.py index 9e2383972..8a8aed2c5 100644 --- a/examples/update_bids_datasets.py +++ b/examples/update_bids_datasets.py @@ -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 diff --git a/mne_bids/config.py b/mne_bids/config.py index eb68544a0..d225f02b7 100644 --- a/mne_bids/config.py +++ b/mne_bids/config.py @@ -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", @@ -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", } diff --git a/mne_bids/path.py b/mne_bids/path.py index f3709c4e3..dd99b6b9c 100644 --- a/mne_bids/path.py +++ b/mne_bids/path.py @@ -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 diff --git a/mne_bids/read.py b/mne_bids/read.py index e31fc8067..ba0b649fd 100644 --- a/mne_bids/read.py +++ b/mne_bids/read.py @@ -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) diff --git a/mne_bids/report/_report.py b/mne_bids/report/_report.py index e61269803..6f91326a1 100644 --- a/mne_bids/report/_report.py +++ b/mne_bids/report/_report.py @@ -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 ( diff --git a/mne_bids/tests/test_path.py b/mne_bids/tests/test_path.py index eaa331c2e..92bd354ec 100644 --- a/mne_bids/tests/test_path.py +++ b/mne_bids/tests/test_path.py @@ -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", ], ) @@ -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"): diff --git a/mne_bids/tests/test_report.py b/mne_bids/tests/test_report.py index f41271c78..dfe7ff59d 100644 --- a/mne_bids/tests/test_report.py +++ b/mne_bids/tests/test_report.py @@ -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 @@ -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 diff --git a/mne_bids/tests/test_update.py b/mne_bids/tests/test_update.py index 6bfb13d77..0a1b6cf8a 100644 --- a/mne_bids/tests/test_update.py +++ b/mne_bids/tests/test_update.py @@ -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], ] ) diff --git a/mne_bids/tests/test_write.py b/mne_bids/tests/test_write.py index 2eab55959..e39a8d4ee 100644 --- a/mne_bids/tests/test_write.py +++ b/mne_bids/tests/test_write.py @@ -133,7 +133,7 @@ def fn(fname, *args, **kwargs): "Persyst", "sub-pt1_ses-02_task-monitor_acq-ecog_run-01_clip2.lay", _read_raw_persyst, - ), # noqa + ), ("NihonKohden", "MB0400FU.EEG", _read_raw_nihon), ("CNT", "scan41_short.cnt", _read_raw_cnt), ("EGI", "test_egi.mff", _read_raw_egi), @@ -150,13 +150,13 @@ def fn(fname, *args, **kwargs): # parametrization for testing converting file formats for EEG/iEEG test_converteeg_data = [ - ("EEGLAB", "EEGLAB", "test_raw.set", _read_raw_eeglab), # noqa + ("EEGLAB", "EEGLAB", "test_raw.set", _read_raw_eeglab), ( "Persyst", "BrainVision", "sub-pt1_ses-02_task-monitor_acq-ecog_run-01_clip2.lay", _read_raw_persyst, - ), # noqa + ), ("NihonKohden", "BrainVision", "MB0400FU.EEG", _read_raw_nihon), ("CNT", "BrainVision", "scan41_short.cnt", _read_raw_cnt), ( @@ -164,13 +164,13 @@ def fn(fname, *args, **kwargs): "BrainVision", "test_bdf_stim_channel Curry 8.cdt", _read_raw_curry, - ), # noqa + ), ( "Persyst", "EDF", "sub-pt1_ses-02_task-monitor_acq-ecog_run-01_clip2.lay", _read_raw_persyst, - ), # noqa + ), ("NihonKohden", "EDF", "MB0400FU.EEG", _read_raw_nihon), ("CNT", "EDF", "scan41_short.cnt", _read_raw_cnt), ("curry", "EDF", "test_bdf_stim_channel Curry 8.cdt", _read_raw_curry), @@ -720,7 +720,7 @@ def test_fif(_bids_validate, tmp_path): "sex": 2, "hand": 1, } - with pytest.raises(FileExistsError, match="already exists"): # noqa: F821 + with pytest.raises(FileExistsError, match="already exists"): write_raw_bids( raw, bids_path2, events=events, event_id=event_id, overwrite=False ) @@ -832,23 +832,23 @@ def test_fif(_bids_validate, tmp_path): ) -@pytest.mark.parametrize("format", ("fif_no_chpi", "fif", "ctf", "kit")) +@pytest.mark.parametrize("fmt", ("fif_no_chpi", "fif", "ctf", "kit")) @pytest.mark.filterwarnings(warning_str["maxshield"]) @testing.requires_testing_data -def test_chpi(_bids_validate, tmp_path, format): +def test_chpi(_bids_validate, tmp_path, fmt): """Test writing of cHPI information.""" - if format == "fif_no_chpi": + if fmt == "fif_no_chpi": fif_raw_fname = op.join( data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif" ) raw = _read_raw_fif(fif_raw_fname) - elif format == "fif": + elif fmt == "fif": fif_raw_fname = op.join(data_path, "SSS", "test_move_anon_raw.fif") raw = _read_raw_fif(fif_raw_fname, allow_maxshield="yes") - elif format == "ctf": + elif fmt == "ctf": ctf_raw_fname = op.join(data_path, "CTF", "testdata_ctf.ds") raw = _read_raw_ctf(ctf_raw_fname) - elif format == "kit": + elif fmt == "kit": kit_data_path = op.join(base_path, "kit", "tests", "data") kit_raw_fname = op.join(kit_data_path, "test.sqd") kit_hpi_fname = op.join(kit_data_path, "test_mrk.sqd") @@ -870,20 +870,20 @@ def test_chpi(_bids_validate, tmp_path, format): meg_json = bids_path.copy().update(suffix="meg", extension=".json") meg_json_data = json.loads(meg_json.fpath.read_text(encoding="utf-8")) - if format in ["fif_no_chpi", "fif"]: - if format == "fif_no_chpi": + if fmt in ["fif_no_chpi", "fif"]: + if fmt == "fif_no_chpi": assert meg_json_data["ContinuousHeadLocalization"] is False assert meg_json_data["HeadCoilFrequency"] == [] - elif format == "fif": + elif fmt == "fif": assert meg_json_data["ContinuousHeadLocalization"] is True assert_array_almost_equal( meg_json_data["HeadCoilFrequency"], [83.0, 143.0, 203.0, 263.0, 323.0] ) - elif format == "kit": + elif fmt == "kit": # no cHPI info is contained in the sample data assert meg_json_data["ContinuousHeadLocalization"] is False assert meg_json_data["HeadCoilFrequency"] == [] - elif format == "ctf": + elif fmt == "ctf": assert meg_json_data["ContinuousHeadLocalization"] is True assert meg_json_data["HeadCoilFrequency"] == [] @@ -1185,7 +1185,7 @@ def test_ctf(_bids_validate, tmp_path): raw = read_raw_bids(bids_path=bids_path, extra_params=dict(clean_names=False)) # test to check that running again with overwrite == False raises an error - with pytest.raises(FileExistsError, match="already exists"): # noqa: F821 + with pytest.raises(FileExistsError, match="already exists"): write_raw_bids(raw, bids_path) assert op.exists(tmp_path / "participants.tsv") @@ -1918,7 +1918,7 @@ def test_set(_bids_validate, tmp_path): with pytest.raises(TypeError, match="unexpected keyword argument 'foo'"): read_raw_bids(bids_path=bids_path, extra_params=dict(foo="bar")) - with pytest.raises(FileExistsError, match="already exists"): # noqa: F821 + with pytest.raises(FileExistsError, match="already exists"): write_raw_bids(raw, bids_path, overwrite=False) _bids_validate(bids_root) @@ -2972,7 +2972,7 @@ def test_event_storage(tmp_path): ("EDF", "test_reduced.edf", _read_raw_edf, "eeg", "mri"), ("EDF", "test_reduced.edf", _read_raw_edf, "eeg", "unknown"), ("CTF", "testdata_ctf.ds", _read_raw_ctf, "meg", ""), - ("MEG", "sample/sample_audvis_trunc_raw.fif", _read_raw_fif, "meg", ""), # noqa + ("MEG", "sample/sample_audvis_trunc_raw.fif", _read_raw_fif, "meg", ""), ], ) @pytest.mark.filterwarnings(warning_str["channel_unit_changed"]) @@ -3126,7 +3126,7 @@ def test_coordsystem_json_compliance( "Persyst", "sub-pt1_ses-02_task-monitor_acq-ecog_run-01_clip2.lay", _read_raw_persyst, - ), # noqa + ), ("03", "NihonKohden", "MB0400FU.EEG", _read_raw_nihon), ("emptyroom", "MEG/sample", "sample_audvis_trunc_raw.fif", _read_raw_fif), ], @@ -3324,7 +3324,7 @@ def test_sidecar_encoding(_bids_validate, tmp_path): assert_array_equal(raw.annotations.description, raw_read.annotations.description) -@pytest.mark.parametrize("dir_name, format, fname, reader", test_converteeg_data) +@pytest.mark.parametrize("dir_name, fmt, fname, reader", test_converteeg_data) @pytest.mark.filterwarnings( warning_str["channel_unit_changed"], warning_str["edfblocks"], @@ -3333,11 +3333,11 @@ def test_sidecar_encoding(_bids_validate, tmp_path): warning_str["no_hand"], ) @testing.requires_testing_data -def test_convert_eeg_formats(dir_name, format, fname, reader, tmp_path): +def test_convert_eeg_formats(dir_name, fmt, fname, reader, tmp_path): """Test conversion of EEG/iEEG manufacturer fmt to BrainVision/EDF.""" pytest.importorskip("pybv", PYBV_VERSION) pytest.importorskip("eeglabio", EEGLABIO_VERSION) - bids_root = tmp_path / format + bids_root = tmp_path / fmt raw_fname = data_path / dir_name / fname # the BIDSPath for test datasets to get written to @@ -3347,15 +3347,13 @@ def test_convert_eeg_formats(dir_name, format, fname, reader, tmp_path): # drop 'misc' type channels when exporting raw = raw.pick(["eeg"]) kwargs = dict( - raw=raw, format=format, bids_path=bids_path, overwrite=True, verbose=False + raw=raw, format=fmt, bids_path=bids_path, overwrite=True, verbose=False ) # test formatting to BrainVision, EDF, or auto (BrainVision) - if format in ["BrainVision", "auto"]: + if fmt in ["BrainVision", "auto"]: if dir_name == "NihonKohden": - with pytest.warns( - RuntimeWarning, match='Encountered data in "short" format' - ): + with pytest.warns(RuntimeWarning, match='Encountered data in "short"'): bids_output_path = write_raw_bids(**kwargs) elif dir_name == "CNT": with pytest.warns( @@ -3377,13 +3375,13 @@ def test_convert_eeg_formats(dir_name, format, fname, reader, tmp_path): else: if dir_name in ["EEGLAB", "NihonKohden", "curry"]: with pytest.warns( - RuntimeWarning, match=f"Converting data files to {format} format" + RuntimeWarning, match=f"Converting data files to {fmt} format" ): bids_output_path = write_raw_bids(**kwargs) else: with ( pytest.warns( - RuntimeWarning, match=f"Converting data files to {format} format" + RuntimeWarning, match=f"Converting data files to {fmt} format" ), pytest.warns( RuntimeWarning, match="EDF format requires equal-length data blocks" @@ -3406,10 +3404,10 @@ def test_convert_eeg_formats(dir_name, format, fname, reader, tmp_path): channels_tsv = _from_tsv(channels_fname) assert channels_tsv["units"][0] == "V" - if format == "BrainVision": + if fmt == "BrainVision": assert raw2.filenames[0].endswith(".eeg") assert bids_output_path.extension == ".vhdr" - elif format == "EDF": + elif fmt == "EDF": assert raw2.filenames[0].endswith(".edf") assert bids_output_path.extension == ".edf" @@ -3423,7 +3421,7 @@ def test_convert_eeg_formats(dir_name, format, fname, reader, tmp_path): assert_array_almost_equal(raw.get_data(), raw2.get_data()[:, :orig_len], decimal=6) -@pytest.mark.parametrize("dir_name, format, fname, reader", test_converteeg_data) +@pytest.mark.parametrize("dir_name, fmt, fname, reader", test_converteeg_data) @pytest.mark.filterwarnings( warning_str["channel_unit_changed"], warning_str["edfblocks"], @@ -3432,11 +3430,11 @@ def test_convert_eeg_formats(dir_name, format, fname, reader, tmp_path): warning_str["no_hand"], ) @testing.requires_testing_data -def test_format_conversion_overwrite(dir_name, format, fname, reader, tmp_path): +def test_format_conversion_overwrite(dir_name, fmt, fname, reader, tmp_path): """Test that overwrite works when format is passed to write_raw_bids.""" pytest.importorskip("pybv", PYBV_VERSION) pytest.importorskip("eeglabio", EEGLABIO_VERSION) - bids_root = tmp_path / format + bids_root = tmp_path / fmt raw_fname = data_path / dir_name / fname # the BIDSPath for test datasets to get written to @@ -3445,7 +3443,7 @@ def test_format_conversion_overwrite(dir_name, format, fname, reader, tmp_path): raw = reader(raw_fname) # drop 'misc' type channels when exporting raw = raw.pick(["eeg"]) - kwargs = dict(raw=raw, format=format, bids_path=bids_path, verbose=False) + kwargs = dict(raw=raw, format=fmt, bids_path=bids_path, verbose=False) with warnings.catch_warnings(): # ignore all warnings for this case to remove verbosity @@ -3458,7 +3456,7 @@ def test_format_conversion_overwrite(dir_name, format, fname, reader, tmp_path): write_raw_bids(**kwargs, overwrite=True) -@pytest.mark.parametrize("dir_name, format, fname, reader", test_converteeg_data) +@pytest.mark.parametrize("dir_name, fmt, fname, reader", test_converteeg_data) @pytest.mark.filterwarnings( warning_str["channel_unit_changed"], warning_str["cnt_warning1"], @@ -3466,7 +3464,7 @@ def test_format_conversion_overwrite(dir_name, format, fname, reader, tmp_path): warning_str["no_hand"], ) @testing.requires_testing_data -def test_error_write_meg_as_eeg(dir_name, format, fname, reader, tmp_path): +def test_error_write_meg_as_eeg(dir_name, fmt, fname, reader, tmp_path): """Test error writing as BrainVision EEG data for MEG.""" bids_root = tmp_path / "bids1" raw_fname = data_path / dir_name / fname @@ -3483,12 +3481,12 @@ def test_error_write_meg_as_eeg(dir_name, format, fname, reader, tmp_path): write_raw_bids(**kwargs) -@pytest.mark.parametrize("dir_name, format, fname, reader", test_convertmeg_data) +@pytest.mark.parametrize("dir_name, fmt, fname, reader", test_convertmeg_data) @pytest.mark.filterwarnings(warning_str["channel_unit_changed"]) @testing.requires_testing_data -def test_convert_meg_formats(dir_name, format, fname, reader, tmp_path): +def test_convert_meg_formats(dir_name, fmt, fname, reader, tmp_path): """Test conversion of MEG manufacturer format to FIF.""" - bids_root = tmp_path / format + bids_root = tmp_path / fmt raw_fname = data_path / dir_name / fname # the BIDSPath for test datasets to get written to @@ -3496,7 +3494,7 @@ def test_convert_meg_formats(dir_name, format, fname, reader, tmp_path): raw = reader(raw_fname) kwargs = dict( - raw=raw, format=format, bids_path=bids_path, overwrite=True, verbose=False + raw=raw, format=fmt, bids_path=bids_path, overwrite=True, verbose=False ) # test formatting to FIF, or auto (FIF) @@ -3505,7 +3503,7 @@ def test_convert_meg_formats(dir_name, format, fname, reader, tmp_path): # channel units should stay the same raw2 = read_raw_bids(bids_output_path) - if format == "FIF": + if fmt == "FIF": assert raw2.filenames[0].endswith(".fif") assert bids_output_path.extension == ".fif" diff --git a/mne_bids/utils.py b/mne_bids/utils.py index 1978b1433..0bc80c2c1 100644 --- a/mne_bids/utils.py +++ b/mne_bids/utils.py @@ -509,7 +509,7 @@ def _check_datatype(raw, datatype): def _import_nibabel(why="work with MRI data"): try: - import nibabel # noqa + import nibabel except ImportError as exc: raise exc.__class__( f"nibabel is required to {why} but could not be imported, " f"got: {exc}" @@ -523,7 +523,7 @@ def warn( category=RuntimeWarning, module="mne_bids", ignore_namespaces=("mne", "mne_bids"), -): # noqa: D103 +): """Emit a warning.""" _warn( message, diff --git a/mne_bids/write.py b/mne_bids/write.py index 7d03ad322..d34b0dbb4 100644 --- a/mne_bids/write.py +++ b/mne_bids/write.py @@ -2671,7 +2671,7 @@ def write_meg_crosstalk(fname, bids_path, verbose=None): ... root=op.join(data_path, 'mne_bids')) # doctest: +SKIP >>> write_meg_crosstalk(crosstalk_fname, bids_path) # doctest: +SKIP Writing crosstalk file to ...sub-01_ses-test_acq-crosstalk_meg.fif - """ # noqa: E501 + """ if bids_path.root is None or bids_path.subject is None: raise ValueError("bids_path must have root and subject set.") if bids_path.datatype not in (None, "meg"): diff --git a/pyproject.toml b/pyproject.toml index 5cf48fb05..bd35aa6bb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -108,7 +108,8 @@ source = "vcs" raw-options = { version_scheme = "release-branch-semver" } [tool.ruff.lint] -select = ["E", "F", "W", "D", "I"] +select = ["A", "D", "E", "F", "I", "UP", "W"] +ignore = ["A002"] exclude = ["__init__.py"] [tool.ruff.lint.pydocstyle]