diff --git a/.travis.yml b/.travis.yml index e54f8d5ed6..ef154584f5 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,18 @@ 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; + cp ../.coveragerc . + 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/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 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, 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']): 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 $@ -}