From ce53ac4b1b3566ba936e1c07859af6eecb553581 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Wed, 26 Feb 2020 10:40:56 -0500 Subject: [PATCH 1/7] WIP: Try to fix PySurfer failures --- azure-pipelines.yml | 1 - environment.yml | 2 +- requirements.txt | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index b2711738d08..1e4690a9db5 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -148,7 +148,6 @@ jobs: conda env update --file $env:CONDA_ENV pip uninstall -yq mne pip install codecov - pip uninstall -yq pysurfer mayavi Write-Host ("##vso[task.setvariable variable=PATH]" + $env:PATH) condition: eq(variables['TEST_MODE'], 'conda') displayName: 'Install dependencies with conda' diff --git a/environment.yml b/environment.yml index d2931f5caf2..9534297bd46 100644 --- a/environment.yml +++ b/environment.yml @@ -35,7 +35,7 @@ dependencies: - vtk - pyvista>=0.23.1 - mayavi - - PySurfer[save_movie] + - PySurfer[save_movie] @ https://api.github.com/repos/larsoner/PySurfer/zipball/force - dipy --only-binary dipy - nibabel - nilearn diff --git a/requirements.txt b/requirements.txt index 413684d8991..fe760969a24 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,11 +23,11 @@ joblib psutil dipy https://api.github.com/repos/numpy/numpydoc/zipball/master -PySurfer[save_movie] +PySurfer[save_movie] @ https://api.github.com/repos/larsoner/PySurfer/zipball/force nilearn neo xlrd pydocstyle flake8 -https://github.com/mcmtroffaes/sphinxcontrib-bibtex/zipball/29694f215b39d64a31b845aafd9ff2ae9329494f +https://api.github.com/repos/mcmtroffaes/sphinxcontrib-bibtex/zipball/29694f215b39d64a31b845aafd9ff2ae9329494f pyvista>=0.23.1 From d8463431244e89337c743fcb49012d22367d7f23 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Wed, 26 Feb 2020 12:40:31 -0500 Subject: [PATCH 2/7] FIX: Try fixing Mayavi --- environment.yml | 4 ++-- requirements.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/environment.yml b/environment.yml index 9534297bd46..7b0255c9608 100644 --- a/environment.yml +++ b/environment.yml @@ -34,8 +34,8 @@ dependencies: - https://api.github.com/repos/numpy/numpydoc/zipball/master - vtk - pyvista>=0.23.1 - - mayavi - - PySurfer[save_movie] @ https://api.github.com/repos/larsoner/PySurfer/zipball/force + - https://api.github.com/repos/larsoner/mayavi/zipball/crash + - PySurfer[save_movie] - dipy --only-binary dipy - nibabel - nilearn diff --git a/requirements.txt b/requirements.txt index fe760969a24..c5ebd6fc0db 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ numpy scipy matplotlib -mayavi pyqt5!=5.14.1 pyqt5-sip sip @@ -23,7 +22,8 @@ joblib psutil dipy https://api.github.com/repos/numpy/numpydoc/zipball/master -PySurfer[save_movie] @ https://api.github.com/repos/larsoner/PySurfer/zipball/force +https://api.github.com/repos/larsoner/mayavi/zipball/crash +PySurfer[save_movie] nilearn neo xlrd From 68f02a03c0f72ef4195635fb4d82026c46f9fe51 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Wed, 26 Feb 2020 14:04:38 -0500 Subject: [PATCH 3/7] ENH: Speed up failure (hopefully) --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 1e4690a9db5..bde23e94320 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -159,7 +159,7 @@ jobs: displayName: Print NumPy config - script: python -c "import mne; mne.datasets.testing.data_path(verbose=True)" displayName: 'Get test data' - - script: pytest -m "not ultraslowtest" --tb=short --cov=mne mne + - script: pytest -m "not ultraslowtest" --tb=short --cov=mne mne/viz displayName: 'Run tests' - script: codecov --root %BUILD_REPOSITORY_LOCALPATH% -t %CODECOV_TOKEN% displayName: 'Codecov' From 7f03c7dd788da5119e0c3ac5945019d6757048ab Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Thu, 27 Feb 2020 09:30:14 -0500 Subject: [PATCH 4/7] FIX: Try again --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index bde23e94320..52dbe0d3d77 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -159,7 +159,7 @@ jobs: displayName: Print NumPy config - script: python -c "import mne; mne.datasets.testing.data_path(verbose=True)" displayName: 'Get test data' - - script: pytest -m "not ultraslowtest" --tb=short --cov=mne mne/viz + - script: pytest -m "not ultraslowtest" --tb=short --cov=mne -vs mne/viz displayName: 'Run tests' - script: codecov --root %BUILD_REPOSITORY_LOCALPATH% -t %CODECOV_TOKEN% displayName: 'Codecov' From fe28f672fc062a08d3ab68c0a07d05c57e677e8a Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Thu, 27 Feb 2020 11:38:17 -0500 Subject: [PATCH 5/7] FIX: Try another --- mne/conftest.py | 10 +++++++++- mne/io/nirx/nirx.py | 5 +++-- mne/viz/tests/test_3d.py | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/mne/conftest.py b/mne/conftest.py index c9c8d1160b5..27aea2daa6e 100644 --- a/mne/conftest.py +++ b/mne/conftest.py @@ -3,6 +3,7 @@ # # License: BSD (3-clause) +import gc import os import os.path as op import shutil @@ -201,7 +202,7 @@ def backend_name(request): @pytest.yield_fixture -def renderer(backend_name): +def renderer(backend_name, garbage_collect): """Yield the 3D backends.""" from mne.viz.backends.renderer import _use_test_3d_backend _check_skip_backend(backend_name) @@ -211,6 +212,13 @@ def renderer(backend_name): renderer._close_all() +@pytest.yield_fixture +def garbage_collect(): + """Garbage collect on exit.""" + yield + gc.collect() + + @pytest.fixture(scope="module", params=[ "pyvista", ]) diff --git a/mne/io/nirx/nirx.py b/mne/io/nirx/nirx.py index 3abb986dd7e..f7a8ec123d9 100644 --- a/mne/io/nirx/nirx.py +++ b/mne/io/nirx/nirx.py @@ -78,8 +78,9 @@ def __init__(self, fname, preload=False, verbose=None): # Read number of rows/samples of wavelength data last_sample = -1 - for line in _open(files['wl1']): - last_sample += 1 + with _open(files['wl1']) as fid: + for line in fid: + last_sample += 1 # Read participant information file inf = ConfigParser(allow_no_value=True) diff --git a/mne/viz/tests/test_3d.py b/mne/viz/tests/test_3d.py index 11cfbc4c501..40d51cffd07 100644 --- a/mne/viz/tests/test_3d.py +++ b/mne/viz/tests/test_3d.py @@ -639,7 +639,7 @@ def test_plot_volume_source_estimates_morph(): @requires_pysurfer @requires_mayavi @traits_test -def test_plot_vector_source_estimates(): +def test_plot_vector_source_estimates(garbage_collect): """Test plotting of vector source estimates.""" sample_src = read_source_spaces(src_fname) @@ -721,7 +721,7 @@ def test_brain_colorbar(orientation, diverging, lims): @requires_pysurfer @testing.requires_testing_data @traits_test -def test_mixed_sources_plot_surface(): +def test_mixed_sources_plot_surface(garbage_collect): """Test plot_surface() for mixed source space.""" src = read_source_spaces(fwd_fname2) N = np.sum([s['nuse'] for s in src]) # number of sources From c7f0f51870b2379bd6d64c572bf9bb6cd27e0f46 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Thu, 27 Feb 2020 12:06:29 -0500 Subject: [PATCH 6/7] FIX: Better testing --- azure-pipelines.yml | 3 ++- environment.yml | 2 +- mne/conftest.py | 11 +++++++++++ mne/viz/utils.py | 2 +- requirements.txt | 2 +- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 52dbe0d3d77..b2711738d08 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -148,6 +148,7 @@ jobs: conda env update --file $env:CONDA_ENV pip uninstall -yq mne pip install codecov + pip uninstall -yq pysurfer mayavi Write-Host ("##vso[task.setvariable variable=PATH]" + $env:PATH) condition: eq(variables['TEST_MODE'], 'conda') displayName: 'Install dependencies with conda' @@ -159,7 +160,7 @@ jobs: displayName: Print NumPy config - script: python -c "import mne; mne.datasets.testing.data_path(verbose=True)" displayName: 'Get test data' - - script: pytest -m "not ultraslowtest" --tb=short --cov=mne -vs mne/viz + - script: pytest -m "not ultraslowtest" --tb=short --cov=mne mne displayName: 'Run tests' - script: codecov --root %BUILD_REPOSITORY_LOCALPATH% -t %CODECOV_TOKEN% displayName: 'Codecov' diff --git a/environment.yml b/environment.yml index 7b0255c9608..d2931f5caf2 100644 --- a/environment.yml +++ b/environment.yml @@ -34,7 +34,7 @@ dependencies: - https://api.github.com/repos/numpy/numpydoc/zipball/master - vtk - pyvista>=0.23.1 - - https://api.github.com/repos/larsoner/mayavi/zipball/crash + - mayavi - PySurfer[save_movie] - dipy --only-binary dipy - nibabel diff --git a/mne/conftest.py b/mne/conftest.py index 27aea2daa6e..6251b46ee48 100644 --- a/mne/conftest.py +++ b/mne/conftest.py @@ -80,6 +80,7 @@ def pytest_configure(config): ignore:The sklearn.*module.*deprecated.*:FutureWarning ignore:.*TraitTuple.*trait.*handler.*deprecated.*:DeprecationWarning ignore:.*rich_compare.*metadata.*deprecated.*:DeprecationWarning + ignore:.*In future, it will be an error for 'np.bool_'.*:DeprecationWarning always:.*get_data.* is deprecated in favor of.*:DeprecationWarning """ # noqa: E501 for warning_line in warning_lines.split('\n'): @@ -92,6 +93,7 @@ def pytest_configure(config): def matplotlib_config(): """Configure matplotlib for viz tests.""" import matplotlib + from matplotlib import cbook # "force" should not really be necessary but should not hurt kwargs = dict() with warnings.catch_warnings(record=True): # ignore warning @@ -111,6 +113,15 @@ def matplotlib_config(): else: ETSConfig.toolkit = 'qt4' + # Make sure that we always reraise exceptions in handlers + orig = cbook.CallbackRegistry + + class CallbackRegistryReraise(orig): + def __init__(self, exception_handler=None): + super(CallbackRegistryReraise, self).__init__(exception_handler) + + cbook.CallbackRegistry = CallbackRegistryReraise + @pytest.fixture() def check_gui_ci(): diff --git a/mne/viz/utils.py b/mne/viz/utils.py index 65c3247c608..c887f65b137 100644 --- a/mne/viz/utils.py +++ b/mne/viz/utils.py @@ -1973,7 +1973,7 @@ def key_press(self, event): elif self.index >= len(self.cycle): self.index = 0 cmap = self.cycle[self.index] - self.cbar.set_cmap(cmap) + self.cbar.mappable.set_cmap(cmap) self.cbar.draw_all() self.mappable.set_cmap(cmap) self.mappable.set_norm(self.cbar.norm) diff --git a/requirements.txt b/requirements.txt index c5ebd6fc0db..21a56e19de4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,7 +22,7 @@ joblib psutil dipy https://api.github.com/repos/numpy/numpydoc/zipball/master -https://api.github.com/repos/larsoner/mayavi/zipball/crash +mayavi PySurfer[save_movie] nilearn neo From eea53e32f3e2b2078b9287ef5372b5650925fdee Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Thu, 27 Feb 2020 14:33:05 -0500 Subject: [PATCH 7/7] FIX: MPL version --- mne/conftest.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mne/conftest.py b/mne/conftest.py index 6251b46ee48..89a275e362b 100644 --- a/mne/conftest.py +++ b/mne/conftest.py @@ -3,6 +3,7 @@ # # License: BSD (3-clause) +from distutils.version import LooseVersion import gc import os import os.path as op @@ -118,7 +119,10 @@ def matplotlib_config(): class CallbackRegistryReraise(orig): def __init__(self, exception_handler=None): - super(CallbackRegistryReraise, self).__init__(exception_handler) + args = () + if LooseVersion(matplotlib.__version__) >= LooseVersion('2.1'): + args += (exception_handler,) + super(CallbackRegistryReraise, self).__init__(*args) cbook.CallbackRegistry = CallbackRegistryReraise