From ffa282b7283ad51671b3a019ec3b9bcdb233506d Mon Sep 17 00:00:00 2001 From: Victor Uriarte Date: Thu, 26 Jan 2017 22:17:55 -0700 Subject: [PATCH 1/4] Travis - Speed up, use containers --- .travis.yml | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index b24531f93..035a267af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ -sudo: required -language: python +sudo: false +language: python python: - 2.7 - 3.3 @@ -8,14 +8,21 @@ python: - 3.5 - 3.6 -before_install: - - sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu/ trusty main universe" - - sudo apt-get install software-properties-common - - sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF - - echo "deb http://download.mono-project.com/repo/debian wheezy/snapshots/4.2.4.4 main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list - - echo "deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list - - sudo apt-get update - - sudo DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" install mono-devel mono-complete referenceassemblies-pcl ca-certificates-mono nunit-console +env: + global: + - LD_PRELOAD=/lib/x86_64-linux-gnu/libSegFault.so + - SEGFAULT_SIGNALS=all + - PYTHONUNBUFFERED=True + +addons: + apt: + sources: + - mono + - mono-libtiff-compat + packages: + - mono-devel + - ca-certificates-mono + - nunit-console install: - pip install six From 5cdc0b4ef959b0e45f3898423e244b9114364ba9 Mon Sep 17 00:00:00 2001 From: Victor Uriarte Date: Thu, 26 Jan 2017 23:07:57 -0700 Subject: [PATCH 2/4] Build conda recipe on Pull Requests --- appveyor.yml | 11 +++-------- ci/appveyor_build_recipe.ps1 | 6 ++++++ conda.recipe/README.md | 5 +++++ 3 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 ci/appveyor_build_recipe.ps1 create mode 100644 conda.recipe/README.md diff --git a/appveyor.yml b/appveyor.yml index e61e6dd2c..524e75969 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -47,9 +47,6 @@ init: - python -c "import ctypes; print(ctypes.sizeof(ctypes.c_wchar))" install: - # install conda and deps - - ps: .\ci\install_miniconda.ps1 - # install for wheels - pip install --upgrade pip wheel six @@ -57,16 +54,14 @@ build_script: # build clean sdist & wheel - python setup.py sdist bdist_wheel - # build and dist conda package - - '%CMD_IN_ENV% %CONDA_BLD%\Scripts\conda build conda.recipe' - - ps: $CONDA_PKG=(&"$env:CONDA_BLD\Scripts\conda" build conda.recipe --output -q) - - ps: Copy-Item $CONDA_PKG "$env:APPVEYOR_BUILD_FOLDER\dist\" - test_script: - pip install --no-index --find-links=.\dist\ pythonnet - ps: Copy-Item (Resolve-Path .\build\*\Python.Test.dll) C:\testdir - python src\tests\runtests.py # - "%NUNIT% src/embed_tests/bin/%PLATFORM%/ReleaseWin/Python.EmbeddingTest.dll" + # Build conda-recipe on Pull Requests + - ps: .\ci\appveyor_build_recipe.ps1 + artifacts: - path: dist\* diff --git a/ci/appveyor_build_recipe.ps1 b/ci/appveyor_build_recipe.ps1 new file mode 100644 index 000000000..0c885d88d --- /dev/null +++ b/ci/appveyor_build_recipe.ps1 @@ -0,0 +1,6 @@ +if ($env:APPVEYOR_PULL_REQUEST_NUMBER) { + Invoke-Expression .\ci\install_miniconda.ps1 + &"$env:CONDA_BLD\Scripts\conda" build conda.recipe --dirty -q + $CONDA_PKG=(&"$env:CONDA_BLD\Scripts\conda" build conda.recipe --output -q) + Copy-Item $CONDA_PKG "$env:APPVEYOR_BUILD_FOLDER\dist\" +} diff --git a/conda.recipe/README.md b/conda.recipe/README.md new file mode 100644 index 000000000..42241999f --- /dev/null +++ b/conda.recipe/README.md @@ -0,0 +1,5 @@ +# Conda Recipe + +The files here are needed to build Python.Net with conda + +http://conda.pydata.org/docs/building/recipe.html From dee134c4939be63e1d4c9dbe407740c64e08f4bc Mon Sep 17 00:00:00 2001 From: Victor Uriarte Date: Fri, 27 Jan 2017 00:42:31 -0700 Subject: [PATCH 3/4] Add coverage --- .travis.yml | 12 +++++++++--- README.md | 3 +++ appveyor.yml | 22 ++++++++++++++-------- ci/appveyor_run_tests.ps1 | 33 +++++++++++++++++++++++++++++++++ src/embed_tests/packages.config | 1 + 5 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 ci/appveyor_run_tests.ps1 diff --git a/.travis.yml b/.travis.yml index 035a267af..418e50cfc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,14 +25,20 @@ addons: - nunit-console install: - - pip install six - - pip install pycparser - - python setup.py build_ext --inplace + - pip install pycparser coverage codecov six + - coverage run setup.py build_ext --inplace script: - export PYTHONPATH=`pwd`:$PYTHONPATH - python src/tests/runtests.py # - nunit-console src/embed_tests/bin/x64/ReleaseMono/Python.EmbeddingTest.dll +after_success: + # Uncomment if need to geninterop, ie. py37 final + # - python tools/geninterop/geninterop.py + + # Waiting on mono-cov support or SharpCover + - codecov + notifications: email: false diff --git a/README.md b/README.md index 0b6abe756..d4640a925 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![appveyor shield][]](https://ci.appveyor.com/project/pythonnet/pythonnet/branch/master) [![travis shield][]](https://travis-ci.org/pythonnet/pythonnet) +[![codecov shield][]](https://codecov.io/github/pythonnet/pythonnet) [![license shield][]](./LICENSE) [![pypi package version][]](https://pypi.python.org/pypi/pythonnet) [![python supported shield][]](https://pypi.python.org/pypi/pythonnet) @@ -80,6 +81,8 @@ int32 [appveyor shield]: https://img.shields.io/appveyor/ci/pythonnet/pythonnet/master.svg?label=AppVeyor +[codecov shield]: https://img.shields.io/codecov/c/github/pythonnet/pythonnet/pytest.svg?label=codecov + [license shield]: https://img.shields.io/badge/license-MIT-blue.svg [pypi package version]: https://img.shields.io/pypi/v/pythonnet.svg diff --git a/appveyor.yml b/appveyor.yml index 524e75969..a8827aee7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,7 +10,6 @@ environment: PYTHONUNBUFFERED: True PYTHONWARNINGS: 'ignore:::wheel.pep425tags:' PYTHONPATH: C:\testdir - NUNIT: nunit-console CONDA_BLD: C:\conda CONDA_BLD_VERSION: 3.5 @@ -35,7 +34,6 @@ init: - set CONDA_BLD_ARCH=%PLATFORM:x=% - set PYTHON=C:\PYTHON%PYTHON_VERSION:.=% - if %PLATFORM%==x86 (set CONDA_BLD_ARCH=32) - - if %PLATFORM%==x86 (set NUNIT=%NUNIT%-x86) - if %PLATFORM%==x64 (set PYTHON=%PYTHON%-x64) # Prepend newly installed Python to the PATH of this build @@ -47,21 +45,29 @@ init: - python -c "import ctypes; print(ctypes.sizeof(ctypes.c_wchar))" install: - # install for wheels - - pip install --upgrade pip wheel six + # install for wheels & coverage + - pip install --upgrade pip wheel coverage codecov six + + # Install OpenCover. Can't put on packages.config; not Linux/Mono compatible + - .\tools\nuget\nuget.exe install OpenCover -OutputDirectory packages build_script: - # build clean sdist & wheel - - python setup.py sdist bdist_wheel + # build clean sdist & wheel with coverage of setup.py, install local wheel + - coverage run setup.py sdist bdist_wheel test_script: - pip install --no-index --find-links=.\dist\ pythonnet - ps: Copy-Item (Resolve-Path .\build\*\Python.Test.dll) C:\testdir - - python src\tests\runtests.py - # - "%NUNIT% src/embed_tests/bin/%PLATFORM%/ReleaseWin/Python.EmbeddingTest.dll" + + # Test runner + - ps: .\ci\appveyor_run_tests.ps1 # Build conda-recipe on Pull Requests - ps: .\ci\appveyor_build_recipe.ps1 +on_finish: + # Upload coverage + - codecov + artifacts: - path: dist\* diff --git a/ci/appveyor_run_tests.ps1 b/ci/appveyor_run_tests.ps1 new file mode 100644 index 000000000..9f9a470bd --- /dev/null +++ b/ci/appveyor_run_tests.ps1 @@ -0,0 +1,33 @@ +# Script to simplify appveyor configuration and resolve path to tools + +# Executable paths for OpenCover +# Note if OpenCover fails, it won't affect the exit codes. +$OPENCOVER = Resolve-Path .\packages\OpenCover.*\tools\OpenCover.Console.exe +$NUNIT = Resolve-Path .\packages\NUnit.ConsoleRunner*\tools\nunit3-console.exe +$PY = Get-Command python + +# Can't use ".\build\*\Python.EmbeddingTest.dll". Missing framework files. +$CS_TESTS = Resolve-Path .\src\embed_tests\bin\*\*\Python.EmbeddingTest.dll +$RUNTIME_DIR = Resolve-Path .\src\runtime\bin\*\ReleaseWin\ + +# Run python tests with C# coverage +# why `2>&1 | %{ "$_" }`? see: http://stackoverflow.com/a/20950421/5208670 +.$OPENCOVER -register:user -searchdirs:"$RUNTIME_DIR" -output:py.coverage -target:"$PY" -targetargs:src\tests\runtests.py -returntargetcode 2>&1 | %{ "$_" } +$PYTHON_STATUS = $LastExitCode +if ($PYTHON_STATUS -ne 0) { + Write-Host "Python tests failed, continuing to embedded tests" -ForegroundColor "Red" +} + +# Run Embedded tests with C# coverage +# .$OPENCOVER -register:user -searchdirs:"$RUNTIME_DIR" -output:cs.coverage -target:"$NUNIT" -targetargs:"$CS_TESTS" -returntargetcode +# $NUNIT_STATUS = $LastExitCode +# if ($NUNIT_STATUS -ne 0) { +# Write-Host "Embedded tests failed" -ForegroundColor "Red" +# } + +# Embedded tests failing due to open issues, pass/fail only on Python exit code +# if ($PYTHON_STATUS -ne 0 -or $NUNIT_STATUS -ne 0) { +if ($PYTHON_STATUS -ne 0) { + Write-Host "Tests failed" -ForegroundColor "Red" + $host.SetShouldExit(1) +} diff --git a/src/embed_tests/packages.config b/src/embed_tests/packages.config index 53d73768d..8ab5202ce 100644 --- a/src/embed_tests/packages.config +++ b/src/embed_tests/packages.config @@ -1,4 +1,5 @@ + From 1145a4472c03dc4bdafed03f9b934c5f813b99fe Mon Sep 17 00:00:00 2001 From: Victor Uriarte Date: Fri, 27 Jan 2017 01:47:52 -0700 Subject: [PATCH 4/4] Add tox for quicker local testing --- tox.ini | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tox.ini diff --git a/tox.ini b/tox.ini new file mode 100644 index 000000000..1cc666ae3 --- /dev/null +++ b/tox.ini @@ -0,0 +1,42 @@ +[tox] +skipsdist=True +skip_missing_interpreters=True +envlist = + py27 + py33 + py34 + py35 + py36 + check + +[testenv] +recreate=True +basepython = + py27: {env:TOXPYTHON:python2.7} + py33: {env:TOXPYTHON:python3.3} + py34: {env:TOXPYTHON:python3.4} + py35: {env:TOXPYTHON:python3.5} + py36: {env:TOXPYTHON:python3.6} + check: python3.5 +setenv = + PYTHONUNBUFFERED=True + DISTUTILS_DEBUG= +passenv = + * +commands = + python --version + python -c "import struct; print('ARCH: %d' % (struct.calcsize('P') * 8))" + python -c "import ctypes; print('UCS%d' % ctypes.sizeof(ctypes.c_wchar))" + python setup.py bdist_wheel + pip install --no-index --find-links=dist/ pythonnet + {posargs:python src\tests\runtests.py} + +[testenv:check] +ignore_errors=True +deps = + check-manifest + flake8 +commands = + check-manifest {toxinidir} + flake8 src setup.py + python setup.py check --strict --metadata