Skip to content

Commit

Permalink
MAINT: Update BIDS Validator infrastructure (#1303)
Browse files Browse the repository at this point in the history
* try remove error

* remove env vars, simplify install

* updates to bids-validator infrastructure
  • Loading branch information
sappelhoff authored Sep 2, 2024
1 parent 100d594 commit 780bad2
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 33 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,29 +208,26 @@ jobs:
if: matrix.bids-validator-version == 'validator-stable'
run: |
npm install -g bids-validator
echo "BIDS_VALIDATOR_BRANCH=stable" >> $GITHUB_ENV
- name: Download BIDS validator (main)
if: matrix.bids-validator-version == 'validator-main'
run: |
pushd ..
git clone --depth 1 https://github.com/bids-standard/bids-validator
popd
echo "BIDS_VALIDATOR_BRANCH=main" >> $GITHUB_ENV
- name: Install BIDS validator (main)
if: matrix.bids-validator-version == 'validator-main'
run: |
pushd ..
cd bids-validator
pushd ../bids-validator
# Generate the full development node_modules
npm install
# Build & bundle the bids-validator CLI package
npm -w bids-validator run build
# Generate a package to install globally
npm -w bids-validator pack
# Install the package globally
bash -c "npm install -g bids-validator-*.tgz"
npm install -g bids-validator-*.tgz
popd
- name: Display versions and environment information
Expand Down
7 changes: 0 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,6 @@ you can then simply use the following command from the root of the `mne-bids` re
make test
```

If you have installed the `bids-validator` on a per-user basis (that is, *not* globally),
set the environment variable `VALIDATOR_EXECUTABLE` to point to the path of the `bids-validator` before invoking `pytest`:

```Shell
VALIDATOR_EXECUTABLE=../bids-validator/bids-validator/bin/bids-validator pytest
```

## Building the documentation

The documentation can be built using [Sphinx](https://www.sphinx-doc.org).
Expand Down
18 changes: 3 additions & 15 deletions mne_bids/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,24 @@
# Authors: The MNE-BIDS developers
# SPDX-License-Identifier: BSD-3-Clause

import os
import platform

import pytest
from mne.utils import run_subprocess


# WINDOWS issues:
# the bids-validator development version does not work properly on Windows as
# of 2019-06-25 --> https://github.com/bids-standard/bids-validator/issues/790
# As a workaround, we try to get the path to the executable from an environment
# variable VALIDATOR_EXECUTABLE ... if this is not possible we assume to be
# using the stable bids-validator and make a direct call of bids-validator
# also: for windows, shell = True is needed to call npm, bids-validator etc.
# see: https://stackoverflow.com/q/28891053/5201771
@pytest.fixture(scope="session")
def _bids_validate():
"""Fixture to run BIDS validator."""
vadlidator_args = ["--config.error=41"]
exe = os.getenv("VALIDATOR_EXECUTABLE", "bids-validator")

# See: https://stackoverflow.com/q/28891053/5201771
# On Windows, shell must be True
if platform.system() == "Windows":
shell = True
else:
shell = False

bids_validator_exe = [exe, *vadlidator_args]

def _validate(bids_root):
cmd = [*bids_validator_exe, bids_root]
cmd = ["bids-validator", bids_root]
run_subprocess(cmd, shell=shell)

return _validate
Expand Down
6 changes: 4 additions & 2 deletions mne_bids/tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def test_report(tmp_path):

report = make_report(bids_root)

expected_report = f"""This dataset was created by [Unspecified] and conforms to BIDS version {BIDS_VERSION}.
expected_report = f""" The [Unspecified] dataset was created by [Unspecified1], and [Unspecified2] and
conforms to BIDS version {BIDS_VERSION}.
This report was generated with MNE-BIDS (https://doi.org/10.21105/joss.01896).
The dataset consists of 1 participants (sex were all unknown; handedness were
all unknown; ages all unknown) and 1 recording sessions: 01. Data was recorded
Expand Down Expand Up @@ -79,7 +80,8 @@ def test_report_no_participant_information(tmp_path):

report = make_report(bids_root)

expected_report = f"""This dataset was created by [Unspecified] and conforms to BIDS version {BIDS_VERSION}.
expected_report = f""" The [Unspecified] dataset was created by [Unspecified1], and [Unspecified2] and
conforms to BIDS version {BIDS_VERSION}.
This report was generated with MNE-BIDS (https://doi.org/10.21105/joss.01896).
The dataset consists of 1 participants (sex were all unknown; handedness were
all unknown; ages all unknown) and 1 recording sessions: 01. Data was recorded
Expand Down
10 changes: 8 additions & 2 deletions mne_bids/tests/test_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,10 @@ def test_make_dataset_description(tmp_path, monkeypatch):

with open(op.join(tmp_path, "dataset_description.json"), encoding="utf-8") as fid:
dataset_description_json = json.load(fid)
assert dataset_description_json["Authors"] == ["[Unspecified]"]
assert dataset_description_json["Authors"] == [
"[Unspecified1]",
"[Unspecified2]",
]

make_dataset_description(
path=tmp_path,
Expand All @@ -365,7 +368,10 @@ def test_make_dataset_description(tmp_path, monkeypatch):

with open(op.join(tmp_path, "dataset_description.json"), encoding="utf-8") as fid:
dataset_description_json = json.load(fid)
assert dataset_description_json["Authors"] == ["[Unspecified]"]
assert dataset_description_json["Authors"] == [
"[Unspecified1]",
"[Unspecified2]",
]

make_dataset_description(
path=tmp_path,
Expand Down
4 changes: 2 additions & 2 deletions mne_bids/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,7 @@ def make_dataset_description(
# if the user passed an author don't overwrite,
# if there was an author there, only overwrite if `overwrite=True`
if authors is None and (description["Authors"] is None or overwrite):
description["Authors"] = ["[Unspecified]"]
description["Authors"] = ["[Unspecified1]", "[Unspecified2]"]

# Only write data that is not None
pop_keys = [key for key, val in description.items() if val is None]
Expand Down Expand Up @@ -2055,7 +2055,7 @@ def write_raw_bids(
# already exist. Always set overwrite to False here. If users
# want to edit their dataset_description, they can directly call
# this function.
make_dataset_description(path=bids_path.root, name=" ", overwrite=False)
make_dataset_description(path=bids_path.root, name="[Unspecified]", overwrite=False)

_sidecar_json(
raw,
Expand Down

0 comments on commit 780bad2

Please sign in to comment.