diff --git a/.continuous-integration/download_reqs.py b/.continuous-integration/download_reqs.py new file mode 100644 index 000000000..cbd5d84a4 --- /dev/null +++ b/.continuous-integration/download_reqs.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python +""" +download_reqs.py [OPTIONS] + +Pre-download required packages to cache for pip and/or conda. +""" +from __future__ import (absolute_import, division, print_function, + unicode_literals) + +import sys +import argparse +import subprocess +import shlex +import time + + +PY_VERSIONS = [sys.version_info] +if sys.version_info < (3,): + PY_VERSIONS.append((3, 6)) +else: + PY_VERSIONS.append((2, 7)) + + +def main(): + p = argparse.ArgumentParser(usage=__doc__.strip()) + p.add_argument('--pip', action='store', default=None, + help="download files for offline pip cache") + p.add_argument('--conda', action='store_true', + help=("download files to conda cache.\n" + "NOTE: modifies current conda environment!")) + args = p.parse_args() + + start_time = time.time() + + if args.pip: + do_pip(args.pip) + if args.conda: + do_conda() + + end_time = time.time() + print("Downloading took {} sec".format(end_time - start_time)) + + +def do_conda(): + subs = dict(index_cache='', ver=sys.version_info) + + call(""" + conda create --download-only -n tmp --channel conda-forge -q --yes python={ver[0]}.{ver[1]} + """, subs) + + for pyver in PY_VERSIONS: + subs['ver'] = pyver + call(""" + conda create --download-only -n tmp -q --yes --use-index-cache python={ver[0]}.{ver[1]} wheel pip six=1.10 colorama=0.3.7 + conda create --download-only -n tmp -q --yes --use-index-cache python={ver[0]}.{ver[1]} wheel pip six colorama=0.3.9 + """, subs) + + +def do_pip(cache_dir): + subs = dict(cache_dir=cache_dir) + for pyver in PY_VERSIONS: + if pyver == sys.version_info: + python = sys.executable + else: + python = 'python{ver[0]}.{ver[1]}'.format(ver=pyver) + if has_python(python): + subs['python'] = python + call(""" + {python} -mpip download -d {cache_dir} six==1.10 colorama==0.3.7 + {python} -mpip download -d {cache_dir} six colorama==0.3.9 + """, subs) + + +def has_python(cmd): + try: + ret = subprocess.call([cmd, '--version']) + return (ret == 0) + except OSError: + return False + + +def call(cmds, subs=None): + if subs is None: + subs = {} + cmds = cmds.splitlines() + for line in cmds: + line = line.strip() + if not line: + continue + parts = [x.format(**subs) for x in shlex.split(line)] + parts = [x for x in parts if x] + print("$ {}".format(" ".join(parts))) + sys.stdout.flush() + subprocess.check_call(parts) + + +if __name__ == "__main__": + main() diff --git a/.travis.yml b/.travis.yml index b1e8e4990..ec2256598 100644 --- a/.travis.yml +++ b/.travis.yml @@ -67,15 +67,22 @@ install: echo -e '\ntravis_retry "$HOME/miniconda3/bin/conda.real" "$@"' >> $HOME/miniconda3/bin/conda; chmod +x $HOME/miniconda3/bin/conda; if $TRAVIS_PYTHON -c 'import virtualenv'; then echo "ERROR: virtualenv package is installed"; exit 1; fi; + $TRAVIS_PYTHON .continuous-integration/download_reqs.py --conda --pip=$HOME/download/pip-cache else - $TRAVIS_PIP install virtualenv; + if $TRAVIS_PYTHON -c 'import sys; sys.exit(0 if "__pypy__" in sys.modules else 1)'; then + $TRAVIS_PIP install virtualenv; + else + $TRAVIS_PIP install virtualenv numpy scipy; + fi + $TRAVIS_PYTHON .continuous-integration/download_reqs.py --pip=$HOME/download/pip-cache fi $TRAVIS_PIP install selenium six "pytest>=3.5" pytest-xdist feedparser python-hglib; if [[ "$COVERAGE" != '' ]]; then $TRAVIS_PIP install pytest-cov codecov; fi; - $TRAVIS_PYTHON setup.py build_ext -i + - export PIP_FIND_LINKS=file://$HOME/download/pip-cache script: - - $TRAVIS_PYTHON -m pytest -l $COVERAGE -vv --webdriver=PhantomJS -n 3 --dist=loadscope test + - $TRAVIS_PYTHON -m pytest -l $COVERAGE -vv --webdriver=PhantomJS -n 3 --offline test after_script: - if [[ "$COVERAGE" != '' ]]; then diff --git a/appveyor.yml b/appveyor.yml index 56c92b690..6b41257ef 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -30,6 +30,11 @@ install: # Install the build and runtime dependencies of the project. - "conda update -q --yes conda" + - "conda install -q --yes python=%PYTHON_VERSION% conda six pip pytest pytest-xdist lockfile" + + # Pre-download all necessary packages + - "python .continuous-integration/download_reqs.py --conda --pip=pip-cache" + - "set PIP_FIND_LINKS=file:///projects/asv/pip-cache" # Tell conda to not use hardlinks: on Windows it's not possible # to delete hard links to files in use, which causes problem when @@ -37,16 +42,9 @@ install: - "conda config --set always_copy True" - "conda config --set allow_softlinks False" - # Create a conda environment - - "conda create -q --yes -n test python=%PYTHON_VERSION%" - - "activate test" - # Check that we have the expected version of Python - "python --version" - # Install specified version of dependencies - - "conda install -q --yes six pip pytest pytest-xdist numpy" - # In-place build - "%CMD_IN_ENV% python setup.py build_ext -i" @@ -54,7 +52,7 @@ install: build: false test_script: - - "python -m pytest -l --basetemp=%APPVEYOR_BUILD_FOLDER%\\tmp -vv -n 5 --dist=loadscope test" + - "python -m pytest -l --basetemp=%APPVEYOR_BUILD_FOLDER%\\tmp -vv -n 3 --offline test" after_build: # Clear up pip cache