From 84fa165548c101f42481e8319863132c893086f4 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Thu, 7 Feb 2019 11:29:51 -0500 Subject: [PATCH 1/6] TEST: Extending ArraySequences corrupts sliced data --- nibabel/streamlines/tests/test_array_sequence.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nibabel/streamlines/tests/test_array_sequence.py b/nibabel/streamlines/tests/test_array_sequence.py index 45f50075f8..33421f45c7 100644 --- a/nibabel/streamlines/tests/test_array_sequence.py +++ b/nibabel/streamlines/tests/test_array_sequence.py @@ -219,6 +219,10 @@ def test_arraysequence_extend(self): seq = SEQ_DATA['seq'].copy() # Copy because of in-place modification. assert_raises(ValueError, seq.extend, data) + # Extend after extracting some slice + working_slice = seq[:2] + seq.extend(ArraySequence(new_data)) + def test_arraysequence_getitem(self): # Get one item for i, e in enumerate(SEQ_DATA['seq']): From e9eb6f967994afa6547fa7184138bfeeab2a16f0 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Thu, 7 Feb 2019 10:38:29 -0500 Subject: [PATCH 2/6] CI: Run coverage on as many tests as possible --- .travis.yml | 43 +++++++++++++++++-------------------------- tools/travis_tools.sh | 32 -------------------------------- 2 files changed, 17 insertions(+), 58 deletions(-) delete mode 100644 tools/travis_tools.sh diff --git a/.travis.yml b/.travis.yml index e54f8d5ed6..60db941f48 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,12 +30,6 @@ matrix: - python: 3.4 dist: trusty sudo: false - - python: 2.7 - env: - - COVERAGE=1 - - python: 3.5 - env: - - COVERAGE=1 # Absolute minimum dependencies - python: 2.7 env: @@ -99,25 +93,20 @@ matrix: env: - OPTIONAL_DEPENDS="indexed_gzip" before_install: - - source tools/travis_tools.sh - - python -m pip install --upgrade pip - - pip install --upgrade virtualenv + - travis_retry python -m pip install --upgrade pip + - travis_retry pip install --upgrade virtualenv - virtualenv --python=python venv - source venv/bin/activate - python --version # just to check - - pip install -U pip setuptools>=27.0 wheel + - travis_retry pip install -U pip setuptools>=27.0 wheel + - travis_retry pip install coverage - if [ "${CHECK_TYPE}" == "test" ]; then - retry pip install nose mock; + travis_retry pip install nose mock; fi - if [ "${CHECK_TYPE}" == "style" ]; then - retry pip install flake8; - fi - - pip install $EXTRA_PIP_FLAGS $DEPENDS $OPTIONAL_DEPENDS - - if [ "${COVERAGE}" == "1" ]; then - pip install coverage; - pip install coveralls; - pip install codecov; + travis_retry pip install flake8; fi + - travis_retry pip install $EXTRA_PIP_FLAGS $DEPENDS $OPTIONAL_DEPENDS # command to install dependencies install: - | @@ -128,7 +117,6 @@ install: python setup_egg.py sdist pip install $EXTRA_PIP_FLAGS dist/*.tar.gz elif [ "$INSTALL_TYPE" == "wheel" ]; then - pip install wheel python setup_egg.py bdist_wheel pip install $EXTRA_PIP_FLAGS dist/*.whl elif [ "$INSTALL_TYPE" == "requirements" ]; then @@ -146,7 +134,9 @@ script: elif [ "${CHECK_TYPE}" == "import" ]; then # Import nibabel without attempting to test # Allows us to check missing dependencies masked by testing libraries - python -c 'import nibabel; print(nibabel.__version__)' + printf 'import nibabel\nprint(nibabel.__version__)\n' > import_only.py + cat import_only.py + coverage run import_only.py elif [ "${CHECK_TYPE}" == "doc_doctests" ]; then cd doc pip install -r ../doc-requirements.txt @@ -156,16 +146,17 @@ script: # Change into an innocuous directory and find tests from installation mkdir for_testing cd for_testing - if [ "${COVERAGE}" == "1" ]; then - cp ../.coveragerc .; - COVER_ARGS="--with-coverage --cover-package nibabel"; - fi - nosetests --with-doctest $COVER_ARGS nibabel; + nosetests --with-doctest --with-coverage --cover-package nibabel nibabel else false fi after_success: - - if [ "${COVERAGE}" == "1" ]; then coveralls; codecov; fi + - | + if [ "${CHECK_TYPE}" == "test" ]; then + travis_retry pip install coveralls codecov + coveralls + codecov + fi notifications: webhooks: http://nipy.bic.berkeley.edu:54856/travis diff --git a/tools/travis_tools.sh b/tools/travis_tools.sh deleted file mode 100644 index 3242d6ef24..0000000000 --- a/tools/travis_tools.sh +++ /dev/null @@ -1,32 +0,0 @@ -# Tools for working with travis-ci -WHEELHOSTS="travis-wheels.scikit-image.org travis-dev-wheels.scipy.org" - -PIP_FLAGS="--timeout=60 --no-index" - -for host in $WHEELHOSTS; do - PIP_FLAGS="${PIP_FLAGS} --trusted-host ${host} --find-links=http://${host}" -done - - -retry () { - # https://gist.github.com/fungusakafungus/1026804 - local retry_max=5 - local count=$retry_max - while [ $count -gt 0 ]; do - "$@" && break - count=$(($count - 1)) - sleep 1 - done - - [ $count -eq 0 ] && { - echo "Retry failed [$retry_max]: $@" >&2 - return 1 - } - return 0 -} - - -wheelhouse_pip_install() { - # Install pip requirements via travis wheelhouse - retry pip install $PIP_FLAGS $@ -} From 989e6bb54c2b68a0c57f527ab7a504bdeda15cd4 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Thu, 7 Feb 2019 22:58:03 -0500 Subject: [PATCH 3/6] RF: Use _safe_resize helper function --- nibabel/streamlines/array_sequence.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/nibabel/streamlines/array_sequence.py b/nibabel/streamlines/array_sequence.py index 333f717321..5e6df6bf26 100644 --- a/nibabel/streamlines/array_sequence.py +++ b/nibabel/streamlines/array_sequence.py @@ -23,6 +23,16 @@ def is_ndarray_of_int_or_bool(obj): np.issubdtype(obj.dtype, np.bool_))) +def _safe_resize(a, shape): + """ Resize an ndarray safely, using minimal memory """ + try: + a.resize(shape) + except ValueError: + a = a.copy() + a.resize(shape, refcheck=False) + return a + + class _BuildCache(object): def __init__(self, arr_seq, common_shape, dtype): self.offsets = list(arr_seq._offsets) @@ -196,7 +206,7 @@ def _resize_data_to(self, n_rows, build_cache): if self._data.size == 0: self._data = np.empty(new_shape, dtype=build_cache.dtype) else: - self._data.resize(new_shape) + self._data = _safe_resize(self._data, new_shape) def shrink_data(self): self._data.resize((self._get_next_offset(),) + self.common_shape, From 40a2eb863602855f6e5bb1e80cfcc2643dfa1625 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Thu, 7 Feb 2019 23:17:21 -0500 Subject: [PATCH 4/6] CI: Ignore tests, benchmarks and externals for Codecov --- codecov.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 codecov.yml diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000000..c19e2a57fe --- /dev/null +++ b/codecov.yml @@ -0,0 +1,5 @@ +coverage: + ignore: + - "**/externals" + - "**/benchmarks" + - "**/tests" From d5c1c0726d9194879188e7aaf61feb481d9fbf8e Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Fri, 8 Feb 2019 08:59:20 -0500 Subject: [PATCH 5/6] CI: Restore coverage config, remove codecov config --- .travis.yml | 1 + codecov.yml | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) delete mode 100644 codecov.yml diff --git a/.travis.yml b/.travis.yml index 60db941f48..ef154584f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -146,6 +146,7 @@ script: # Change into an innocuous directory and find tests from installation mkdir for_testing cd for_testing + cp ../.coveragerc . nosetests --with-doctest --with-coverage --cover-package nibabel nibabel else false diff --git a/codecov.yml b/codecov.yml deleted file mode 100644 index c19e2a57fe..0000000000 --- a/codecov.yml +++ /dev/null @@ -1,5 +0,0 @@ -coverage: - ignore: - - "**/externals" - - "**/benchmarks" - - "**/tests" From bc0f6e7d96418974af77105f8cc4a6b2e9d78a06 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Fri, 8 Feb 2019 09:00:13 -0500 Subject: [PATCH 6/6] CI: Run coverage on Windows --- appveyor.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 93438cfc0f..4b34c61447 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -23,7 +23,8 @@ install: # Install the dependencies of the project. - python -m pip install --upgrade pip setuptools wheel - - pip install numpy scipy matplotlib nose h5py mock pydicom + - pip install numpy scipy matplotlib h5py pydicom + - pip install nose mock coverage codecov - pip install . - SET NIBABEL_DATA_DIR=%CD%\nibabel-data @@ -33,4 +34,8 @@ test_script: # Change into an innocuous directory and find tests from installation - mkdir for_testing - cd for_testing - - nosetests --with-doctest nibabel + - cp ../.coveragerc . + - nosetests --with-doctest --with-coverage --cover-package nibabel nibabel + +after_test: + - codecov