From 762bcc4b1f8c22d83624a93af10c04f60b190b36 Mon Sep 17 00:00:00 2001 From: Henning Peters Date: Fri, 18 Dec 2015 17:47:06 +0100 Subject: [PATCH] streamline ci/build systems --- .appveyor.yml | 16 +++------------ .travis.yml | 34 ++++++++++-------------------- build.py | 57 +++++++++++++++++++++++++++++++++------------------ pip-clear.py | 28 +++++++++++++++++++++++++ venv.ps1 | 4 +++- venv.sh | 4 +++- 6 files changed, 85 insertions(+), 58 deletions(-) create mode 100755 pip-clear.py diff --git a/.appveyor.yml b/.appveyor.yml index 5415b8f4a..fdec992e9 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -43,30 +43,20 @@ install: - "python --version" - "python -c \"import struct; print(struct.calcsize('P') * 8)\"" - # Upgrade to the latest version of pip to avoid it displaying warnings - # about it being out of date. - - "pip install --disable-pip-version-check --user --upgrade pip" - # Install the build dependencies of the project. If some dependencies contain # compiled extensions and are not provided as pre-built wheel packages, # pip will build them from source using the MSVC compiler matching the # target Python version and architecture - - "pip install --upgrade setuptools" - - "%CMD_IN_ENV% pip install cython fabric fabtools" - - "%CMD_IN_ENV% pip install -r requirements.txt" + - "%CMD_IN_ENV% python build.py prepare" build_script: # Build the compiled extension - - "%CMD_IN_ENV% python setup.py build_ext --inplace" - - ps: appveyor\download.ps1 - - "tar -xzf corpora/en/wordnet.tar.gz" - - "%CMD_IN_ENV% python bin/init_model.py en lang_data/ corpora/ spacy/en/data" + - "%CMD_IN_ENV% python build.py pip" test_script: # Run the project tests - - "pip install pytest" - - "%CMD_IN_ENV% py.test spacy/ -x" + - "%CMD_IN_ENV% python build.py test" after_test: # If tests are successful, create binary packages for the project. diff --git a/.travis.yml b/.travis.yml index dc1a71eeb..52413b714 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,28 +17,16 @@ env: - PIP_DATE=2015-10-01 PIP=0 INSTALL=0 DEVELOP=1 install: - - pip install -U pip - - python pip-date.py $PIP_DATE pip setuptools wheel six - - pip install -r requirements.txt - - - if [[ "$PIP" == "1" ]]; then - python setup.py sdist; - pip install dist/*; - fi - - - if [[ "$INSTALL" == "1" ]]; then - python setup.py install; - fi - - - if [[ "$DEVELOP" == "1" ]]; then - python setup.py develop; - pip install -e .; - fi - - - pip install pytest - - pip list + - python build.py prepare $PIP_DATE script: - - mkdir tmp; cd tmp - - python -m spacy.en.download - - python -m pytest ../spacy/ -x --models --vectors --slow + - if [[ "$PIP" == "1" ]]; then + python build.py pip; + fi + - if [[ "$INSTALL" == "1" ]]; then + python build.py setup-install; + fi + - if [[ "$DEVELOP" == "1" ]]; then + python build.py setup-develop; + fi + - python build.py test diff --git a/build.py b/build.py index 07785e951..170b5603d 100644 --- a/build.py +++ b/build.py @@ -19,41 +19,58 @@ if len(sys.argv) < 2: install_mode = sys.argv[1] -pip_date = len(sys.argv) > 2 and sys.argv[2] -x('pip install -U pip') -if pip_date: - x('python pip-date.py %s pip setuptools wheel six' % pip_date) -x('pip install -r requirements.txt') +if install_mode == 'prepare': + x('python pip-clear.py') + x('pip install --disable-pip-version-check -U pip setuptools') -if install_mode == 'pip': - for filename in os.listdir('dist'): - os.unlink(os.path.join('dist', filename)) + pip_date = len(sys.argv) > 2 and sys.argv[2] + if pip_date: + x('python pip-date.py %s pip setuptools wheel six' % pip_date) + + x('pip install -r requirements.txt') + x('pip list') + + +elif install_mode == 'pip': + if os.path.exists('dist'): + shutil.rmtree('dist') x('python setup.py sdist') + x('python pip-clear.py') + filenames = os.listdir('dist') assert len(filenames) == 1 + x('pip list') x('pip install dist/%s' % filenames[0]) + elif install_mode == 'setup-install': x('python setup.py install') + elif install_mode == 'setup-develop': + x('python setup.py develop') + x('python pip-clear.py') + + x('pip list') x('pip install -e .') -x('pip install pytest') -x('pip list') -if os.path.exists('tmp'): - shutil.rmtree('tmp') -os.mkdir('tmp') +elif install_mode == 'test': + x('pip install pytest') + x('pip list') -try: - old = os.getcwd() - os.chdir('tmp') + if os.path.exists('tmp'): + shutil.rmtree('tmp') + os.mkdir('tmp') - x('python -m spacy.en.download') - x('python -m pytest ../spacy/ --models --vectors --slow') + try: + old = os.getcwd() + os.chdir('tmp') -finally: - os.chdir(old) + x('python -m spacy.en.download') + x('python -m pytest ../spacy/ --models --vectors --slow') + + finally: + os.chdir(old) diff --git a/pip-clear.py b/pip-clear.py new file mode 100755 index 000000000..573a20dcd --- /dev/null +++ b/pip-clear.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +from __future__ import print_function + +from pip.commands.uninstall import UninstallCommand +from pip import get_installed_distributions + + +packages = [] +for package in get_installed_distributions(): + if package.location.endswith('dist-packages'): + continue + elif package.project_name in ('pip', 'setuptools'): + continue + packages.append(package.project_name) + + +if packages: + pip = UninstallCommand() + options, args = pip.parse_args(packages) + options.yes = True + + try: + pip.run(options, args) + except OSError as e: + if e.errno != 13: + raise e + print("You lack permissions to uninstall this package. Perhaps run with sudo? Exiting.") + exit(13) diff --git a/venv.ps1 b/venv.ps1 index ad6c7cd9d..0b1a7d726 100644 --- a/venv.ps1 +++ b/venv.ps1 @@ -10,5 +10,7 @@ if(!(Test-Path -Path ".build")) } .build\Scripts\activate.ps1 -python build.py $install_mode $pip_date +python build.py prepare $pip_date +python build.py $install_mode +python build.py test exit $LASTEXITCODE diff --git a/venv.sh b/venv.sh index 832d90b43..9fb233e9c 100755 --- a/venv.sh +++ b/venv.sh @@ -6,4 +6,6 @@ if [ ! -d ".build" ]; then fi . .build/bin/activate -python build.py $2 $3 +python build.py prepare $3 +python build.py $2 +python build.py test