Skip to content

Commit

Permalink
MAINT: Use black
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed May 2, 2023
1 parent 263114e commit 97bbc37
Show file tree
Hide file tree
Showing 23 changed files with 98 additions and 51 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- uses: psf/black@stable
- uses: pre-commit/[email protected]

pytest:
Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
repos:
# - repo: https://github.com/psf/black
# rev: 23.1.0
# hooks:
# - id: black
# args: [--quiet]
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
args: [--quiet]

# Ruff mne
- repo: https://github.com/charliermarsh/ruff-pre-commit
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ stages:
displayName: Install dependencies
- bash: |
make pre-commit
displayName: make ruff
displayName: make pre-commit
condition: always()
- bash: |
make nesting
Expand Down
2 changes: 2 additions & 0 deletions ignore_words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ nd
cas
thes
ba
bu
ist
od
fo
Expand All @@ -33,3 +34,4 @@ recuse
ro
nam
shs
pres
12 changes: 6 additions & 6 deletions mne/channels/tests/test_montage.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,12 @@ def test_documented():
pytest.param(
partial(read_custom_montage, head_size=None, coord_frame='mri'),
('// MatLab Sphere coordinates [degrees] Cartesian coordinates\n' # noqa: E501
'// Label Theta Phi Radius X Y Z off sphere surface\n' # noqa: E501
'E1 37.700 -14.000 1.000 0.7677 0.5934 -0.2419 -0.00000000000000011\n' # noqa: E501
'E3 51.700 11.000 1.000 0.6084 0.7704 0.1908 0.00000000000000000\n' # noqa: E501
'E31 90.000 -11.000 1.000 0.0000 0.9816 -0.1908 0.00000000000000000\n' # noqa: E501
'E61 158.000 -17.200 1.000 -0.8857 0.3579 -0.2957 -0.00000000000000022'), # noqa: E501
"// MatLab Sphere coordinates [degrees] Cartesian coordinates\n" # noqa: E501
"// Label Theta Phi Radius X Y Z off sphere surface\n" # noqa: E501
"E1 37.700 -14.000 1.000 0.7677 0.5934 -0.2419 -0.00000000000000011\n" # noqa: E501
"E3 51.700 11.000 1.000 0.6084 0.7704 0.1908 0.00000000000000000\n" # noqa: E501
"E31 90.000 -11.000 1.000 0.0000 0.9816 -0.1908 0.00000000000000000\n" # noqa: E501
"E61 158.000 -17.200 1.000 -0.8857 0.3579 -0.2957 -0.00000000000000022", # noqa: E501
make_dig_montage(
ch_pos={
'E1': [0.7677, 0.5934, -0.2419],
Expand Down
11 changes: 6 additions & 5 deletions mne/chpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,11 +847,12 @@ def compute_head_pos(info, chpi_locs, dist_limit=0.005, gof_limit=0.98,
# 1. Check number of good ones
#
if len(use_idx) < 3:
msg = (_time_prefix(fit_time) + '%s/%s good HPI fits, cannot '
'determine the transformation (%s GOF)!'
% (len(use_idx), n_coils,
', '.join('%0.2f' % g for g in g_coils)))
warn(msg)
gofs = ', '.join(f"{g:0.2f}" for g in g_coils)
warn(
f"{_time_prefix(fit_time)}{len(use_idx)}/{n_coils} "
"good HPI fits, cannot determine the transformation "
f"({gofs} GOF)!"
)
continue

#
Expand Down
6 changes: 3 additions & 3 deletions mne/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def pytest_configure(config):
first_kind = 'error'
else:
first_kind = 'always'
warning_lines = r"""
{0}::
warning_lines = f" {first_kind}::"
warning_lines += r"""
# matplotlib->traitlets (notebook)
ignore:Passing unrecognized arguments to super.*:DeprecationWarning
# notebook tests
Expand Down Expand Up @@ -142,7 +142,7 @@ def pytest_configure(config):
ignore:pkg_resources is deprecated as an API.*:DeprecationWarning
# h5py
ignore:`product` is deprecated as of NumPy.*:DeprecationWarning
""".format(first_kind) # noqa: E501
""" # noqa: E501
for warning_line in warning_lines.split('\n'):
warning_line = warning_line.strip()
if warning_line and not warning_line.startswith('#'):
Expand Down
14 changes: 10 additions & 4 deletions mne/coreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@
from .io._digitization import _get_data_as_dict_from_dig
# keep get_mni_fiducials for backward compat (no burden to keep in this
# namespace, too)
from ._freesurfer import (_read_mri_info, get_mni_fiducials, # noqa: F401
estimate_head_mri_t) # noqa: F401
from ._freesurfer import (
_read_mri_info,
get_mni_fiducials,
estimate_head_mri_t, # noqa: F401
)
from .label import read_label, Label
from .source_space import (add_source_space_distances, read_source_spaces, # noqa: E501,F401
write_source_spaces)
from .source_space import (
add_source_space_distances,
read_source_spaces, # noqa: F401
write_source_spaces,
)
from .surface import (read_surface, write_surface, _normalize_vectors,
complete_surface_info, decimate_surface,
_DistanceQuery)
Expand Down
19 changes: 12 additions & 7 deletions mne/io/kit/tests/test_kit.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ def test_data(tmp_path):
# check functionality
raw_mrk = read_raw_kit(sqd_path, [mrk2_path, mrk3_path], elp_txt_path,
hsp_txt_path)
assert raw_mrk.info['description'] == \
'NYU 160ch System since Jan24 2009 (34) V2R004 EQ1160C'
assert (
raw_mrk.info['description'] == 'NYU 160ch System since Jan24 2009 (34) V2R004 EQ1160C' # noqa: E501
)
raw_py = _test_raw_reader(read_raw_kit, input_fname=sqd_path, mrk=mrk_path,
elp=elp_txt_path, hsp=hsp_txt_path,
stim=list(range(167, 159, -1)), slope='+',
Expand Down Expand Up @@ -123,8 +124,9 @@ def test_data(tmp_path):
# KIT-UMD data
_test_raw_reader(read_raw_kit, input_fname=sqd_umd_path, test_rank='less')
raw = read_raw_kit(sqd_umd_path)
assert raw.info['description'] == \
'University of Maryland/Kanazawa Institute of Technology/160-channel MEG System (53) V2R004 PQ1160R' # noqa: E501
assert (
raw.info['description'] == 'University of Maryland/Kanazawa Institute of Technology/160-channel MEG System (53) V2R004 PQ1160R' # noqa: E501
)
assert_equal(raw.info['kit_system_id'], KIT.SYSTEM_UMD_2014_12)
# check number/kind of channels
assert_equal(len(raw.info['chs']), 193)
Expand All @@ -135,8 +137,9 @@ def test_data(tmp_path):

# KIT Academia Sinica
raw = read_raw_kit(sqd_as_path, slope='+')
assert raw.info['description'] == \
'Academia Sinica/Institute of Linguistics//Magnetoencephalograph System (261) V2R004 PQ1160R-N2' # noqa: E501
assert (
raw.info['description'] == 'Academia Sinica/Institute of Linguistics//Magnetoencephalograph System (261) V2R004 PQ1160R-N2' # noqa: E501
)
assert_equal(raw.info['kit_system_id'], KIT.SYSTEM_AS_2008)
assert_equal(raw.info['chs'][100]['ch_name'], 'MEG 101')
assert_equal(raw.info['chs'][100]['kind'], FIFF.FIFFV_MEG_CH)
Expand Down Expand Up @@ -374,7 +377,9 @@ def test_berlin():
"""Test data from Berlin."""
# gh-8535
raw = read_raw_kit(berlin_path)
assert raw.info['description'] == 'Physikalisch Technische Bundesanstalt, Berlin/128-channel MEG System (124) V2R004 PQ1128R-N2' # noqa: E501
assert (
raw.info['description'] == 'Physikalisch Technische Bundesanstalt, Berlin/128-channel MEG System (124) V2R004 PQ1128R-N2' # noqa: E501
)
assert raw.info['kit_system_id'] == 124
assert raw.info['highpass'] == 0.
assert raw.info['lowpass'] == 200.
Expand Down
12 changes: 9 additions & 3 deletions mne/io/tests/test_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,9 +739,15 @@ def test_describe_print():
assert re.match(
r'<Raw | test_raw.fif, 376 x 14400 (24\.0 s), '
r'~3\.. MB, data not loaded>', s[0]) is not None, s[0]
assert s[1] == " ch name type unit min Q1 median Q3 max" # noqa
assert s[2] == " 0 MEG 0113 GRAD fT/cm -221.80 -38.57 -9.64 19.29 414.67" # noqa
assert s[-1] == "375 EOG 061 EOG µV -231.41 271.28 277.16 285.66 334.69" # noqa
assert (
s[1] == " ch name type unit min Q1 median Q3 max" # noqa: E501
)
assert (
s[2] == " 0 MEG 0113 GRAD fT/cm -221.80 -38.57 -9.64 19.29 414.67" # noqa: E501
)
assert (
s[-1] == "375 EOG 061 EOG µV -231.41 271.28 277.16 285.66 334.69" # noqa: E501
)


@requires_pandas
Expand Down
3 changes: 2 additions & 1 deletion mne/io/tests/test_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ def test_set_eeg_reference_rest():
# load('leadfield.mat', 'G');
# dat_ref = ft_preproc_rereference(dat, 'all', 'rest', true, G);
# sprintf('%g ', dat_ref(:, 171));
want = np.array('-3.3265e-05 -3.2419e-05 -3.18758e-05 -3.24079e-05 -3.39801e-05 -3.40573e-05 -3.24163e-05 -3.26896e-05 -3.33814e-05 -3.54734e-05 -3.51289e-05 -3.53229e-05 -3.51532e-05 -3.53149e-05 -3.4505e-05 -3.03462e-05 -2.81848e-05 -3.08895e-05 -3.27158e-05 -3.4605e-05 -3.47728e-05 -3.2459e-05 -3.06552e-05 -2.53255e-05 -2.69671e-05 -2.83425e-05 -3.12836e-05 -3.30965e-05 -3.34099e-05 -3.32766e-05 -3.32256e-05 -3.36385e-05 -3.20796e-05 -2.7108e-05 -2.47054e-05 -2.49589e-05 -2.7382e-05 -3.09774e-05 -3.12003e-05 -3.1246e-05 -3.07572e-05 -2.64942e-05 -2.25505e-05 -2.67194e-05 -2.86e-05 -2.94903e-05 -2.96249e-05 -2.92653e-05 -2.86472e-05 -2.81016e-05 -2.69737e-05 -2.48076e-05 -3.00473e-05 -2.73404e-05 -2.60153e-05 -2.41608e-05 -2.61937e-05 -2.5539e-05 -2.47104e-05 -2.35194e-05'.split(' '), float) # noqa: E501
data_array = "-3.3265e-05 -3.2419e-05 -3.18758e-05 -3.24079e-05 -3.39801e-05 -3.40573e-05 -3.24163e-05 -3.26896e-05 -3.33814e-05 -3.54734e-05 -3.51289e-05 -3.53229e-05 -3.51532e-05 -3.53149e-05 -3.4505e-05 -3.03462e-05 -2.81848e-05 -3.08895e-05 -3.27158e-05 -3.4605e-05 -3.47728e-05 -3.2459e-05 -3.06552e-05 -2.53255e-05 -2.69671e-05 -2.83425e-05 -3.12836e-05 -3.30965e-05 -3.34099e-05 -3.32766e-05 -3.32256e-05 -3.36385e-05 -3.20796e-05 -2.7108e-05 -2.47054e-05 -2.49589e-05 -2.7382e-05 -3.09774e-05 -3.12003e-05 -3.1246e-05 -3.07572e-05 -2.64942e-05 -2.25505e-05 -2.67194e-05 -2.86e-05 -2.94903e-05 -2.96249e-05 -2.92653e-05 -2.86472e-05 -2.81016e-05 -2.69737e-05 -2.48076e-05 -3.00473e-05 -2.73404e-05 -2.60153e-05 -2.41608e-05 -2.61937e-05 -2.5539e-05 -2.47104e-05 -2.35194e-05" # noqa: E501
want = np.array(data_array.split(" "), float)
norm = np.linalg.norm(want)
idx = np.argmin(np.abs(evoked.times - 0.083))
assert idx == 170
Expand Down
9 changes: 7 additions & 2 deletions mne/source_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@
complete_surface_info, _compute_nearest, fast_cross_3d,
_CheckInside)
# keep get_mni_fiducials here just for easy backward compat
from ._freesurfer import (_get_mri_info_data, _get_atlas_values, # noqa: F401
read_freesurfer_lut, get_mni_fiducials, _check_mri)
from ._freesurfer import (
_get_mri_info_data,
_get_atlas_values,
read_freesurfer_lut,
get_mni_fiducials, # noqa: F401
_check_mri,
)
from .utils import (get_subjects_dir, check_fname, logger, verbose, fill_doc,
_ensure_int, _get_call_line, warn, object_size, sizeof_fmt,
_check_fname, _path_like, _check_sphere, _import_nibabel,
Expand Down
4 changes: 2 additions & 2 deletions mne/tests/test_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ def test_io_annotation_txt(dummy_annotation_txt_file, tmp_path_factory,
pytest.param(None, None, id='None'),
pytest.param(42, 42.0, id='Scalar'),
pytest.param(3.14, 3.14, id='Float'),
pytest.param((3, 140000), 3.14, id='Scalar touple'),
pytest.param((3, 140000), 3.14, id="Scalar tuple"),
pytest.param('2002-12-03 19:01:11.720100', 1038942071.7201,
id='valid iso8601 string'),
pytest.param('2002-12-03T19:01:11.720100', None,
Expand Down Expand Up @@ -1355,7 +1355,7 @@ def test_annotation_ch_names():
assert raw_2.annotations.ch_names[1] == tuple(raw.ch_names[4:5])
for ch_drop in raw_2.annotations.ch_names:
assert all(name in raw_2.ch_names for name in ch_drop)
with pytest.raises(ValueError, match='channel name in annotations missin'):
with pytest.raises(ValueError, match='channel name in annotations miss'):
raw_2.set_annotations(annot)
with pytest.warns(RuntimeWarning, match='channel name in annotations mis'):
raw_2.set_annotations(annot, on_missing='warn')
Expand Down
5 changes: 4 additions & 1 deletion mne/tests/test_docstring_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ def check_parameters_match(func, cls=None):
msg = str(exc)
# E ValueError: no signature found for builtin type
# <class 'mne.forward.forward.Forward'>
if inspect.isclass(callable_) and 'no signature found for buil' in msg:
if (
inspect.isclass(callable_) and
"no signature found for builtin type" in msg
):
pass
else:
raise
Expand Down
2 changes: 1 addition & 1 deletion mne/tests/test_source_estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1898,5 +1898,5 @@ def test_label_extraction_subject(kind):
with pytest.raises(ValueError, match=r'label\.sub.*not match.* stc\.'):
extract_label_time_course(stc, labels_fs, src)
stc.subject = None
with pytest.raises(ValueError, match=r'label\.sub.*not match.* sourc'):
with pytest.raises(ValueError, match=r"label\.sub.*not match.* sour"):
extract_label_time_course(stc, labels_fs, src)
2 changes: 1 addition & 1 deletion mne/tests/test_source_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def test_setup_source_space(tmp_path):
setup_source_space('sample', spacing='7emm',
add_dist=False, subjects_dir=subjects_dir)
with pytest.raises(ValueError, match='must be a string with values'):
setup_source_space('sample', spacing='alls',
setup_source_space("sample", spacing="ally",
add_dist=False, subjects_dir=subjects_dir)

# ico 5 (fsaverage) - write to temp file
Expand Down
2 changes: 1 addition & 1 deletion mne/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1822,7 +1822,7 @@ def apply_volume_registration(moving, static, reg_affine, sdr_morph=None,
moving.shape, moving_affine)
reg_data = affine_map.transform(moving, interpolation=interpolation)
if sdr_morph is not None:
logger.info('Appling SDR warp ...')
logger.info("Applying SDR warp ...")
reg_data = sdr_morph.transform(
reg_data, interpolation=interpolation,
image_world2grid=np.linalg.inv(static_affine),
Expand Down
4 changes: 3 additions & 1 deletion mne/utils/tests/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ def test_suggest():
sug = _suggest('Left-cerebellum', names)
assert sug == " Did you mean 'Left-Cerebellum-Cortex'?"
sug = _suggest('Cerebellum-Cortex', names)
assert sug == " Did you mean one of ['Left-Cerebellum-Cortex', 'Right-Cerebellum-Cortex', 'Left-Cerebral-Cortex']?" # noqa: E501
assert (
sug == " Did you mean one of ['Left-Cerebellum-Cortex', 'Right-Cerebellum-Cortex', 'Left-Cerebral-Cortex']?" # noqa: E501
)


def test_on_missing():
Expand Down
10 changes: 8 additions & 2 deletions mne/viz/backends/_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@
_AbstractWidgetList, _AbstractAction, _AbstractDialog,
_AbstractKeyPress)
from ._pyvista import _PyVistaRenderer, Plotter
from ._pyvista import (_close_3d_figure, _check_3d_figure, _close_all, # noqa: F401,E501 analysis:ignore
_set_3d_view, _set_3d_title, _take_3d_screenshot) # noqa: F401,E501 analysis:ignore
from ._pyvista import (
_close_3d_figure, # noqa: F401
_check_3d_figure, # noqa: F401
_close_all, # noqa: F401
_set_3d_view, # noqa: F401
_set_3d_title, # noqa: F401
_take_3d_screenshot, # noqa: F401
)
from ._utils import _notebook_vtk_works


Expand Down
12 changes: 9 additions & 3 deletions mne/viz/backends/_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@
QSpinBox, QStyle, QStyleOptionSlider)

from ._pyvista import _PyVistaRenderer
from ._pyvista import (_close_3d_figure, _check_3d_figure, _close_all, # noqa: F401,E501 analysis:ignore
_set_3d_view, _set_3d_title, _take_3d_screenshot, # noqa: F401,E501 analysis:ignore
_is_mesa) # noqa: F401,E501 analysis:ignore
from ._pyvista import (
_close_3d_figure, # noqa: F401
_check_3d_figure, # noqa: F401
_close_all, # noqa: F401
_set_3d_view, # noqa: F401
_set_3d_title, # noqa: F401
_take_3d_screenshot, # noqa: F401
_is_mesa, # noqa: F401
)
from ._abstract import (_AbstractAppWindow, _AbstractHBoxLayout,
_AbstractVBoxLayout, _AbstractGridLayout,
_AbstractWidget, _AbstractCanvas,
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[tool.codespell]
ignore-words = "ignore_words.txt"
uri-ignore-words-list = "bu"
builtin = "clear,rare,informal,names,usage"
skip = "doc/references.bib"

Expand Down Expand Up @@ -48,3 +47,6 @@ addopts = """--durations=20 --doctest-modules -ra --cov-report= --tb=short \
--ignore=mne/report/js_and_css \
--color=yes --capture=sys"""
junit_family = "xunit2"

[tool.black]
exclude = "(dist/)|(build/)|(.*\\.ipynb)"
1 change: 1 addition & 0 deletions requirements_testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ tomli; python_version<'3.11'
twine
wheel
pre-commit
black
2 changes: 1 addition & 1 deletion tutorials/forward/50_background_freesurfer_mne.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def imshow_mri(data, img, vox, xyz, suptitle):
# Figure out the title based on the code of this axis
ori_slice = dict(P='Coronal', A='Coronal',
I='Axial', S='Axial',
L='Sagittal', R='Saggital')
L='Sagittal', R='Sagittal')
ori_names = dict(P='posterior', A='anterior',
I='inferior', S='superior',
L='left', R='right')
Expand Down

0 comments on commit 97bbc37

Please sign in to comment.