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

MEG: Add git pre-commit configuration #1173

Merged
merged 19 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
@@ -0,0 +1,20 @@
repos:
- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
args: [--quiet]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.291
hooks:
- id: ruff
name: ruff mne_bids/
files: ^mne_bids/
- id: ruff
name: ruff examples/
# D103: missing docstring in public function
# D400: docstring first line must end with period
# D205: 1 blank line required between summary line and description
args: ["--ignore=D103,D400,D205"]
files: ^examples/
18 changes: 17 additions & 1 deletion CONTRIBUTING.md
Expand Up @@ -109,7 +109,7 @@ bids-validator --version
We use [GNU Make](https://www.gnu.org/software/make/) for developing `mne-bids`.
We recommend that you install GNU Make and make use of our `Makefile` at the root
of the repository.
For most Linux and OSX operating systems, GNU Make will be already installed by default.
For most Linux and macOS operating systems, GNU Make will be already installed by default.
Windows users can download the [Chocolatey package manager](https://chocolatey.org/)
and install [GNU Make from their repository](https://community.chocolatey.org/packages/make).

Expand All @@ -131,6 +131,22 @@ We use [Black](https://github.com/psf/black) to format our code.
You can simply call `black .` from the root of the `mne-bids` repository
to automatically convert your code to follow the appropriate style.

### git pre-commit hooks

We suggest installing our git pre-commit hooks to automatically run style
checks before a commit is created:

```Shell
pip install pre-commit
pre-commit install
```

You can also manually run the hooks via

```Shell
pre-commit run -a
```

## Running tests

We run tests using `pytest`.
Expand Down
2 changes: 1 addition & 1 deletion mne_bids/path.py
Expand Up @@ -1981,7 +1981,7 @@ def get_entity_vals(

References
----------
.. [1] https://bids-specification.rtfd.io/en/latest/common-principles.html#entities # noqa: E501
.. [1] https://bids-specification.rtfd.io/en/latest/common-principles.html#entities

"""
root = _check_fname(
Expand Down
2 changes: 1 addition & 1 deletion mne_bids/tests/test_dig.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""Test the digitizations.

For each supported coordinate frame, implement a test.
"""
# Authors: Alex Rockhill <aprockhill@mailbox.org>
Expand Down
12 changes: 10 additions & 2 deletions mne_bids/tests/test_path.py
Expand Up @@ -355,6 +355,7 @@ def test_parse_ext():
],
)
def test_get_bids_path_from_fname(fname):
"""Test get_bids_path_from_fname()."""
bids_path = get_bids_path_from_fname(fname)
assert bids_path.basename == Path(fname).name

Expand Down Expand Up @@ -1039,8 +1040,10 @@ def test_match(return_bids_test_dir):

@testing.requires_testing_data
def test_find_matching_paths(return_bids_test_dir):
"""We test by yielding the same results as BIDSPath.match() which
is extensively tested above."""
"""We test by yielding the same results as BIDSPath.match().

BIDSPath.match() is extensively tested above.
"""
bids_root = Path(return_bids_test_dir)

# Check a few exemplary entities
Expand Down Expand Up @@ -1336,6 +1339,7 @@ def test_find_emptyroom_no_meas_date(tmp_path):


def test_bids_path_label_vs_index_entity():
"""Test entities that must be strings vs those that may be an int."""
match = "subject must be an instance of None or str"
with pytest.raises(TypeError, match=match):
BIDSPath(subject=1)
Expand All @@ -1348,6 +1352,7 @@ def test_bids_path_label_vs_index_entity():

@testing.requires_testing_data
def test_meg_calibration_fpath(return_bids_test_dir):
"""Test BIDSPath.meg_calibration_fpath."""
bids_root = return_bids_test_dir

# File exists, so BIDSPath.meg_calibration_fpath should return a non-None
Expand Down Expand Up @@ -1379,6 +1384,7 @@ def test_meg_calibration_fpath(return_bids_test_dir):

@testing.requires_testing_data
def test_meg_crosstalk_fpath(return_bids_test_dir):
"""Test BIDSPath.meg_crosstalk_fpath."""
bids_root = return_bids_test_dir

# File exists, so BIDSPath.crosstalk_fpath should return a non-None
Expand Down Expand Up @@ -1410,6 +1416,7 @@ def test_meg_crosstalk_fpath(return_bids_test_dir):

@testing.requires_testing_data
def test_datasetdescription_with_bidspath(return_bids_test_dir):
"""Test a BIDSPath can generate a valid path to dataset_description.json."""
with pytest.raises(ValueError, match="Unallowed"):
bids_path = BIDSPath(
root=return_bids_test_dir, suffix="dataset_description", extension=".json"
Expand Down Expand Up @@ -1437,6 +1444,7 @@ def test_datasetdescription_with_bidspath(return_bids_test_dir):


def test_update_fail_check_no_change():
"""Test BIDSPath.check works in preventing invalid changes."""
bids_path = BIDSPath(subject="test")
try:
bids_path.update(suffix="ave")
Expand Down
3 changes: 2 additions & 1 deletion mne_bids/tests/test_read.py
Expand Up @@ -619,7 +619,7 @@ def test_handle_scans_reading(tmp_path):

@pytest.mark.filterwarnings(warning_str["channel_unit_changed"])
def test_handle_scans_reading_brainvision(tmp_path):
"""Test stability of BrainVision's different file extensions"""
"""Test stability of BrainVision's different file extensions."""
test_scan_eeg = OrderedDict(
[
("filename", [Path("eeg/sub-01_ses-eeg_task-rest_eeg.eeg")]),
Expand Down Expand Up @@ -1152,6 +1152,7 @@ def test_handle_non_mne_channel_type(tmp_path):
@pytest.mark.filterwarnings(warning_str["channel_unit_changed"])
@testing.requires_testing_data
def test_bads_reading(tmp_path):
"""Test reading bad channels."""
bids_path = _bids_path.copy().update(root=tmp_path, datatype="meg")
bads_raw = ["MEG 0112", "MEG 0113"]
bads_sidecar = ["EEG 053", "MEG 2443"]
Expand Down
1 change: 1 addition & 0 deletions mne_bids/utils.py
Expand Up @@ -529,6 +529,7 @@ def warn(
module="mne_bids",
ignore_namespaces=("mne", "mne_bids"),
): # noqa: D103
"""Emit a warning."""
_warn(
message,
category=category,
Expand Down
12 changes: 12 additions & 0 deletions pyproject.toml
@@ -0,0 +1,12 @@
[tool.ruff]
select = ["E", "F", "W", "D"]
exclude = ["__init__.py"]

[tool.ruff.pydocstyle]
convention = "numpy"

[tool.black]
exclude = "(dist/)|(build/)|(.*\\.ipynb)"

[tool.check-manifest]
ignore = [".pre-commit-config.yaml"]