Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5a7e3b4

Browse files
committed
CI: test in windows and build packages
This builds windows conda packages and wheels for some python versions and runs the tests on these python versions on windows. It uses the AppVeyor CI servive and the packages are available as artefacts to download. Appveyor based on http://tjelvarolsson.com/blog/how-to-continuously-test-your-python-code-on-windows-using-appveyor/ https://packaging.python.org/en/latest/appveyor/ https://github.com/rmcgibbo/python-appveyor-conda-example Conda stuff based on https://github.com/conda/conda-recipes/tree/master/matplotlib ...and a lot of trial and error...
1 parent 659ce45 commit 5a7e3b4

File tree

14 files changed

+536
-0
lines changed

14 files changed

+536
-0
lines changed

appveyor.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# With infos from
2+
# http://tjelvarolsson.com/blog/how-to-continuously-test-your-python-code-on-windows-using-appveyor/
3+
# https://packaging.python.org/en/latest/appveyor/
4+
# https://github.com/rmcgibbo/python-appveyor-conda-example
5+
6+
# Backslashes in quotes need to be escaped: \ -> "\\"
7+
8+
environment:
9+
10+
global:
11+
# SDK v7.0 MSVC Express 2008's SetEnv.cmd script will fail if the
12+
# /E:ON and /V:ON options are not enabled in the batch script intepreter
13+
# See: http://stackoverflow.com/a/13751649/163740
14+
CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\ci\\appveyor\\run_with_env.cmd"
15+
16+
matrix:
17+
- PYTHON: "C:\\Python34_64"
18+
PYTHON_VERSION: "3.4"
19+
PYTHON_ARCH: "64"
20+
CONDA_PY: "34"
21+
CONDA_NPY: "18"
22+
23+
- PYTHON: "C:\\Python27_64"
24+
PYTHON_VERSION: "2.7"
25+
PYTHON_ARCH: "64"
26+
CONDA_PY: "27"
27+
CONDA_NPY: "18"
28+
29+
- PYTHON: "C:\\Python27_32"
30+
PYTHON_VERSION: "2.7"
31+
PYTHON_ARCH: "32"
32+
CONDA_PY: "27"
33+
CONDA_NPY: "18"
34+
35+
# We always use a 64-bit machine, but can build x86 distributions
36+
# with the PYTHON_ARCH variable (which is used by CMD_IN_ENV).
37+
platform:
38+
- x64
39+
40+
# all our python builds have to happen in tests_script...
41+
build: false
42+
43+
init:
44+
- "ECHO %PYTHON_VERSION% %PYTHON%"
45+
46+
install:
47+
- powershell .\ci\appveyor\install.ps1
48+
- SET PATH=%PYTHON%;%PYTHON%\Scripts;%PATH%
49+
- cmd: conda config --set show_channel_urls yes
50+
# for msinttypes
51+
- cmd: conda config --add channels conda-forge
52+
# this is now the downloaded conda...
53+
- conda info -a
54+
# same things as in tools/conda_recipe
55+
- cmd: conda create -y -q -n test-environment python=%PYTHON_VERSION% pip setuptools numpy python-dateutil freetype=2.5 msinttypes pyparsing pytz tornado libpng zlib pyqt cycler nose mock
56+
- activate test-environment
57+
# This is needed for the installer to find the dlls...
58+
- set LIBRARY_LIB=%CONDA_DEFAULT_ENV%\Library\lib
59+
- dir %LIBRARY_LIB%
60+
- cmd: 'mkdir lib || cmd /c "exit /b 0"'
61+
- copy %LIBRARY_LIB%\zlibstatic.lib lib\z.lib
62+
- copy %LIBRARY_LIB%\libpng_static.lib lib\png.lib
63+
- set LIB=%LIBRARY_LIB%;.\lib
64+
- set LIBPATH=%LIBRARY_LIB%;.\lib
65+
- set LIB_INC=%CONDA_DEFAULT_ENV%\Library\include
66+
- set INCLUDE=%LIB_INC%;%LIB_INC%\freetype2;WhateverInclude
67+
- set CPLUS_INCLUDE_PATH=%LIB_INC%\freetype2;%LIB_INC%;WhateverCPLUS
68+
- dir %LIB_INC%
69+
- dir %LIB_INC%\freetype2
70+
# Show the installed packages + versions
71+
- conda list
72+
73+
test_script:
74+
# Now build the thing..
75+
- '%CMD_IN_ENV% python setup.py develop'
76+
# tests
77+
# for now, just let them pass to get the after_test parts...
78+
- python tests.py || cmd /c "exit /b 0"
79+
80+
after_test:
81+
# After the tests were a success, build packages (wheels and conda)
82+
83+
# There is a bug in wheels which prevents building wheels when the package uses namespaces
84+
- cmd: '%CMD_IN_ENV% python setup.py bdist_wheel'
85+
# Note also that our setup.py script, which is called by conda-build, writes
86+
# a __conda_version__.txt file, so the version number on the binary package
87+
# is set dynamically. This unfortunately mean that conda build --output
88+
# doesn't really work.
89+
- cmd: '%CMD_IN_ENV% conda config --get channels'
90+
# These vars get included in the conda env, so cleanup out current conda env
91+
- set LIB=
92+
- set LIBPATH=
93+
- set INCLUDE=
94+
- set LIB_INC=
95+
- set
96+
# we can't build conda packages on 27 due to missing functools32, which is a recent
97+
# additional dependency for matplotlib
98+
- cmd: if [%CONDA_PY%] NEQ [27] %CMD_IN_ENV% conda build .\ci\conda_recipe
99+
# Move the conda package into the dist directory, to register it
100+
# as an "artifact" for Appveyor.
101+
- cmd: 'copy /Y %PYTHON%\conda-bld\win-32\*.bz2 dist || cmd /c "exit /b 0"'
102+
- cmd: 'copy /Y %PYTHON%\conda-bld\win-64\*.bz2 dist || cmd /c "exit /b 0"'
103+
- cmd: dir .\dist\
104+
105+
artifacts:
106+
- path: dist\*
107+
name: packages

ci/appveyor/install.ps1

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Sample script to install Miniconda under Windows
2+
# Authors: Olivier Grisel, Jonathan Helmus and Kyle Kastner, Robert McGibbon
3+
# License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/
4+
5+
$MINICONDA_URL = "http://repo.continuum.io/miniconda/"
6+
7+
8+
function DownloadMiniconda ($python_version, $platform_suffix) {
9+
$webclient = New-Object System.Net.WebClient
10+
if ($python_version -match "3.4") {
11+
$filename = "Miniconda3-latest-Windows-" + $platform_suffix + ".exe"
12+
} else {
13+
$filename = "Miniconda-latest-Windows-" + $platform_suffix + ".exe"
14+
}
15+
$url = $MINICONDA_URL + $filename
16+
17+
$basedir = $pwd.Path + "\"
18+
$filepath = $basedir + $filename
19+
if (Test-Path $filename) {
20+
Write-Host "Reusing" $filepath
21+
return $filepath
22+
}
23+
24+
# Download and retry up to 3 times in case of network transient errors.
25+
Write-Host "Downloading" $filename "from" $url
26+
$retry_attempts = 2
27+
for($i=0; $i -lt $retry_attempts; $i++){
28+
try {
29+
$webclient.DownloadFile($url, $filepath)
30+
break
31+
}
32+
Catch [Exception]{
33+
Start-Sleep 1
34+
}
35+
}
36+
if (Test-Path $filepath) {
37+
Write-Host "File saved at" $filepath
38+
} else {
39+
# Retry once to get the error message if any at the last try
40+
$webclient.DownloadFile($url, $filepath)
41+
}
42+
return $filepath
43+
}
44+
45+
46+
function InstallMiniconda ($python_version, $architecture, $python_home) {
47+
Write-Host "Installing Python" $python_version "for" $architecture "bit architecture to" $python_home
48+
if (Test-Path $python_home) {
49+
Write-Host $python_home "already exists, skipping."
50+
return $false
51+
}
52+
if ($architecture -match "32") {
53+
$platform_suffix = "x86"
54+
} else {
55+
$platform_suffix = "x86_64"
56+
}
57+
58+
$filepath = DownloadMiniconda $python_version $platform_suffix
59+
Write-Host "Installing" $filepath "to" $python_home
60+
$install_log = $python_home + ".log"
61+
$args = "/S /D=$python_home"
62+
Write-Host $filepath $args
63+
Start-Process -FilePath $filepath -ArgumentList $args -Wait -Passthru
64+
if (Test-Path $python_home) {
65+
Write-Host "Python $python_version ($architecture) installation complete"
66+
} else {
67+
Write-Host "Failed to install Python in $python_home"
68+
Get-Content -Path $install_log
69+
Exit 1
70+
}
71+
}
72+
73+
74+
function InstallCondaPackages ($python_home, $spec) {
75+
$conda_path = $python_home + "\Scripts\conda.exe"
76+
$args = "install --yes " + $spec
77+
Write-Host ("conda " + $args)
78+
Start-Process -FilePath "$conda_path" -ArgumentList $args -Wait -Passthru
79+
}
80+
81+
function UpdateConda ($python_home) {
82+
$conda_path = $python_home + "\Scripts\conda.exe"
83+
Write-Host "Updating conda..."
84+
$args = "update --yes conda"
85+
Write-Host $conda_path $args
86+
Start-Process -FilePath "$conda_path" -ArgumentList $args -Wait -Passthru
87+
}
88+
89+
90+
function main () {
91+
InstallMiniconda $env:PYTHON_VERSION $env:PYTHON_ARCH $env:PYTHON
92+
UpdateConda $env:PYTHON
93+
InstallCondaPackages $env:PYTHON "conda-build jinja2 anaconda-client"
94+
}
95+
96+
main

ci/appveyor/run_with_env.cmd

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
:: To build extensions for 64 bit Python 3, we need to configure environment
2+
:: variables to use the MSVC 2010 C++ compilers from GRMSDKX_EN_DVD.iso of:
3+
:: MS Windows SDK for Windows 7 and .NET Framework 4 (SDK v7.1)
4+
::
5+
:: To build extensions for 64 bit Python 2, we need to configure environment
6+
:: variables to use the MSVC 2008 C++ compilers from GRMSDKX_EN_DVD.iso of:
7+
:: MS Windows SDK for Windows 7 and .NET Framework 3.5 (SDK v7.0)
8+
::
9+
:: 32 bit builds do not require specific environment configurations.
10+
::
11+
:: Note: this script needs to be run with the /E:ON and /V:ON flags for the
12+
:: cmd interpreter, at least for (SDK v7.0)
13+
::
14+
:: More details at:
15+
:: https://github.com/cython/cython/wiki/64BitCythonExtensionsOnWindows
16+
:: http://stackoverflow.com/a/13751649/163740
17+
::
18+
:: Author: Olivier Grisel
19+
:: License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/
20+
@ECHO OFF
21+
22+
SET COMMAND_TO_RUN=%*
23+
SET WIN_SDK_ROOT=C:\Program Files\Microsoft SDKs\Windows
24+
25+
SET MAJOR_PYTHON_VERSION="%PYTHON_VERSION:~0,1%"
26+
IF %MAJOR_PYTHON_VERSION% == "2" (
27+
SET WINDOWS_SDK_VERSION="v7.0"
28+
) ELSE IF %MAJOR_PYTHON_VERSION% == "3" (
29+
SET WINDOWS_SDK_VERSION="v7.1"
30+
) ELSE (
31+
ECHO Unsupported Python version: "%MAJOR_PYTHON_VERSION%"
32+
EXIT 1
33+
)
34+
35+
IF "%PYTHON_ARCH%"=="64" (
36+
ECHO Configuring Windows SDK %WINDOWS_SDK_VERSION% for Python %MAJOR_PYTHON_VERSION% on a 64 bit architecture
37+
SET DISTUTILS_USE_SDK=1
38+
SET MSSdk=1
39+
"%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Setup\WindowsSdkVer.exe" -q -version:%WINDOWS_SDK_VERSION%
40+
"%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Bin\SetEnv.cmd" /x64 /release
41+
ECHO Executing: %COMMAND_TO_RUN%
42+
call %COMMAND_TO_RUN% || EXIT 1
43+
) ELSE (
44+
ECHO Using default MSVC build environment for 32 bit architecture
45+
ECHO Executing: %COMMAND_TO_RUN%
46+
call %COMMAND_TO_RUN% || EXIT 1
47+
)

ci/conda_recipe/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# conda package
2+
3+
Up to now, this is mainly used to build a test conda package on windows on appveyor.

ci/conda_recipe/bld.bat

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
mkdir lib
2+
copy %LIBRARY_LIB%\zlibstatic.lib lib\z.lib
3+
if errorlevel 1 exit 1
4+
copy %LIBRARY_LIB%\libpng_static.lib lib\png.lib
5+
if errorlevel 1 exit 1
6+
7+
set LIB=%LIB%;.\lib
8+
set LIBPATH=%LIBPATH%;.\lib
9+
set INCLUDE=%LIBRARY_INC%;%LIBRARY_INC%\freetype2;%INCLUDE%
10+
11+
:: debug...
12+
set
13+
14+
copy setup.cfg.template setup.cfg
15+
if errorlevel 1 exit 1
16+
17+
python setup.py install
18+
if errorlevel 1 exit 1
19+
20+
rd /s /q %SP_DIR%\dateutil
21+
rd /s /q %SP_DIR%\numpy
22+
23+
if "%ARCH%"=="64" (
24+
set PLAT=win-amd64
25+
) else (
26+
set PLAT=win32
27+
)
28+
29+
::copy C:\Tcl%ARCH%\bin\t*.dll %SP_DIR%\matplotlib-%PKG_VERSION%-py%PY_VER%-%PLAT%.egg\matplotlib\backends

ci/conda_recipe/build.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
if [ `uname` == Linux ]; then
4+
pushd $PREFIX/lib
5+
ln -s libtcl8.5.so libtcl.so
6+
ln -s libtk8.5.so libtk.so
7+
popd
8+
fi
9+
10+
if [ `uname` == Darwin ]; then
11+
sed s:'#ifdef WITH_NEXT_FRAMEWORK':'#if 1':g -i src/_macosx.m
12+
fi
13+
14+
cp setup.cfg.template setup.cfg || exit 1
15+
16+
sed s:/usr/local:$PREFIX:g -i setupext.py
17+
18+
$PYTHON setup.py install
19+
20+
rm -rf $SP_DIR/PySide
21+
rm -rf $SP_DIR/__pycache__
22+
rm -rf $PREFIX/bin/nose*
23+

ci/conda_recipe/cfg.patch

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git setup.cfg.template setup.cfg.template
2+
index ba4cde3..8d8b7c5 100644
3+
--- setup.cfg.template
4+
+++ setup.cfg.template
5+
@@ -63,7 +63,7 @@
6+
#macosx = auto
7+
#pyside = auto
8+
#qt4agg = auto
9+
-#tkagg = auto
10+
+tkagg = True
11+
#windowing = auto
12+
#wxagg = auto
13+

ci/conda_recipe/cfg_notests.patch

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git setup.cfg.template setup.cfg.template
2+
index 09fd92f..2085832 100644
3+
--- setup.cfg.template
4+
+++ setup.cfg.template
5+
@@ -18,7 +18,7 @@
6+
# optional. They are all installed by default, but they may be turned
7+
# off here.
8+
#
9+
-#tests = True
10+
+tests = False
11+
#sample_data = True
12+
#toolkits = True
13+
# Tests for the toolkits are only automatically installed

ci/conda_recipe/cfg_qt4agg.patch

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
diff --git setup.cfg.template setup.cfg.template
2+
index 8af8b6d..4e4f9d2 100644
3+
--- setup.cfg.template
4+
+++ setup.cfg.template
5+
@@ -78,5 +78,5 @@
6+
# if you have disabled the relevent extension modules. Agg will be used
7+
# by default.
8+
#
9+
-#backend = Agg
10+
+backend = Qt4Agg
11+
#

0 commit comments

Comments
 (0)