Skip to content

Commit

Permalink
CI: pre-download packages + run tests with --offline
Browse files Browse the repository at this point in the history
  • Loading branch information
pv committed May 1, 2018
1 parent 8bf5429 commit 1bbbb1f
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 10 deletions.
98 changes: 98 additions & 0 deletions .continuous-integration/download_reqs.py
Original file line number Diff line number Diff line change
@@ -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()
11 changes: 9 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 6 additions & 8 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,29 @@ 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
# trying to cleanup environments during the tests
- "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"

# Not a .NET project
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
Expand Down

0 comments on commit 1bbbb1f

Please sign in to comment.