Skip to content

Commit 52ad82e

Browse files
committed
add appveyor.yml
1 parent f024357 commit 52ad82e

File tree

3 files changed

+386
-0
lines changed

3 files changed

+386
-0
lines changed

appveyor.yml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
environment:
2+
global:
3+
# SDK v7.0 MSVC Express 2008's SetEnv.cmd script will fail if the
4+
# /E:ON and /V:ON options are not enabled in the batch script intepreter
5+
# See: http://stackoverflow.com/a/13751649/163740
6+
CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\appveyor\\run_with_env.cmd"
7+
8+
matrix:
9+
10+
# Pre-installed Python versions, which Appveyor may upgrade to
11+
# a later point release.
12+
# See: http://www.appveyor.com/docs/installed-software#python
13+
14+
- PYTHON: "C:\\Python27"
15+
PYTHON_VERSION: "2.7.x"
16+
PYTHON_ARCH: "32"
17+
18+
- PYTHON: "C:\\Python27-x64"
19+
PYTHON_VERSION: "2.7.x"
20+
PYTHON_ARCH: "64"
21+
22+
- PYTHON: "C:\\Python35"
23+
PYTHON_VERSION: "3.5.x"
24+
PYTHON_ARCH: "32"
25+
26+
- PYTHON: "C:\\Python35-x64"
27+
PYTHON_VERSION: "3.5.x"
28+
PYTHON_ARCH: "64"
29+
30+
install:
31+
# If there is a newer build queued for the same PR, cancel this one.
32+
# The AppVeyor 'rollout builds' option is supposed to serve the same
33+
# purpose but it is problematic because it tends to cancel builds pushed
34+
# directly to master instead of just PR builds (or the converse).
35+
# credits: JuliaLang developers.
36+
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
37+
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
38+
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
39+
throw "There are newer queued builds for this pull request, failing early." }
40+
- ECHO "Filesystem root:"
41+
- ps: "ls \"C:/\""
42+
43+
- ECHO "Installed SDKs:"
44+
- ps: "ls \"C:/Program Files/Microsoft SDKs/Windows\""
45+
46+
# Install Python (from the official .msi of http://python.org) and pip when
47+
# not already installed.
48+
- ps: if (-not(Test-Path($env:PYTHON))) { & appveyor\install.ps1 }
49+
50+
# Prepend newly installed Python to the PATH of this build (this cannot be
51+
# done from inside the powershell script as it would require to restart
52+
# the parent CMD process).
53+
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
54+
55+
# Check that we have the expected version and architecture for Python
56+
- "python --version"
57+
- "python -c \"import struct; print(struct.calcsize('P') * 8)\""
58+
59+
# Upgrade to the latest version of pip to avoid it displaying warnings
60+
# about it being out of date.
61+
- "pip install --disable-pip-version-check --user --upgrade pip"
62+
63+
build_script:
64+
# Build the compiled extension
65+
- "%CMD_IN_ENV% python setup.py"
66+
67+
artifacts:
68+
# Archive the generated packages in the ci.appveyor.com build report.
69+
- path: dist\*

appveyor/install.ps1

+229
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
# Sample script to install Python and pip under Windows
2+
# Authors: Olivier Grisel, Jonathan Helmus, Kyle Kastner, and Alex Willmer
3+
# License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/
4+
5+
$MINICONDA_URL = "http://repo.continuum.io/miniconda/"
6+
$BASE_URL = "https://www.python.org/ftp/python/"
7+
$GET_PIP_URL = "https://bootstrap.pypa.io/get-pip.py"
8+
$GET_PIP_PATH = "C:\get-pip.py"
9+
10+
$PYTHON_PRERELEASE_REGEX = @"
11+
(?x)
12+
(?<major>\d+)
13+
\.
14+
(?<minor>\d+)
15+
\.
16+
(?<micro>\d+)
17+
(?<prerelease>[a-z]{1,2}\d+)
18+
"@
19+
20+
21+
function Download ($filename, $url) {
22+
$webclient = New-Object System.Net.WebClient
23+
24+
$basedir = $pwd.Path + "\"
25+
$filepath = $basedir + $filename
26+
if (Test-Path $filename) {
27+
Write-Host "Reusing" $filepath
28+
return $filepath
29+
}
30+
31+
# Download and retry up to 3 times in case of network transient errors.
32+
Write-Host "Downloading" $filename "from" $url
33+
$retry_attempts = 2
34+
for ($i = 0; $i -lt $retry_attempts; $i++) {
35+
try {
36+
$webclient.DownloadFile($url, $filepath)
37+
break
38+
}
39+
Catch [Exception]{
40+
Start-Sleep 1
41+
}
42+
}
43+
if (Test-Path $filepath) {
44+
Write-Host "File saved at" $filepath
45+
} else {
46+
# Retry once to get the error message if any at the last try
47+
$webclient.DownloadFile($url, $filepath)
48+
}
49+
return $filepath
50+
}
51+
52+
53+
function ParsePythonVersion ($python_version) {
54+
if ($python_version -match $PYTHON_PRERELEASE_REGEX) {
55+
return ([int]$matches.major, [int]$matches.minor, [int]$matches.micro,
56+
$matches.prerelease)
57+
}
58+
$version_obj = [version]$python_version
59+
return ($version_obj.major, $version_obj.minor, $version_obj.build, "")
60+
}
61+
62+
63+
function DownloadPython ($python_version, $platform_suffix) {
64+
$major, $minor, $micro, $prerelease = ParsePythonVersion $python_version
65+
66+
if (($major -le 2 -and $micro -eq 0) `
67+
-or ($major -eq 3 -and $minor -le 2 -and $micro -eq 0) `
68+
) {
69+
$dir = "$major.$minor"
70+
$python_version = "$major.$minor$prerelease"
71+
} else {
72+
$dir = "$major.$minor.$micro"
73+
}
74+
75+
if ($prerelease) {
76+
if (($major -le 2) `
77+
-or ($major -eq 3 -and $minor -eq 1) `
78+
-or ($major -eq 3 -and $minor -eq 2) `
79+
-or ($major -eq 3 -and $minor -eq 3) `
80+
) {
81+
$dir = "$dir/prev"
82+
}
83+
}
84+
85+
if (($major -le 2) -or ($major -le 3 -and $minor -le 4)) {
86+
$ext = "msi"
87+
if ($platform_suffix) {
88+
$platform_suffix = ".$platform_suffix"
89+
}
90+
} else {
91+
$ext = "exe"
92+
if ($platform_suffix) {
93+
$platform_suffix = "-$platform_suffix"
94+
}
95+
}
96+
97+
$filename = "python-$python_version$platform_suffix.$ext"
98+
$url = "$BASE_URL$dir/$filename"
99+
$filepath = Download $filename $url
100+
return $filepath
101+
}
102+
103+
104+
function InstallPython ($python_version, $architecture, $python_home) {
105+
Write-Host "Installing Python" $python_version "for" $architecture "bit architecture to" $python_home
106+
if (Test-Path $python_home) {
107+
Write-Host $python_home "already exists, skipping."
108+
return $false
109+
}
110+
if ($architecture -eq "32") {
111+
$platform_suffix = ""
112+
} else {
113+
$platform_suffix = "amd64"
114+
}
115+
$installer_path = DownloadPython $python_version $platform_suffix
116+
$installer_ext = [System.IO.Path]::GetExtension($installer_path)
117+
Write-Host "Installing $installer_path to $python_home"
118+
$install_log = $python_home + ".log"
119+
if ($installer_ext -eq '.msi') {
120+
InstallPythonMSI $installer_path $python_home $install_log
121+
} else {
122+
InstallPythonEXE $installer_path $python_home $install_log
123+
}
124+
if (Test-Path $python_home) {
125+
Write-Host "Python $python_version ($architecture) installation complete"
126+
} else {
127+
Write-Host "Failed to install Python in $python_home"
128+
Get-Content -Path $install_log
129+
Exit 1
130+
}
131+
}
132+
133+
134+
function InstallPythonEXE ($exepath, $python_home, $install_log) {
135+
$install_args = "/quiet InstallAllUsers=1 TargetDir=$python_home"
136+
RunCommand $exepath $install_args
137+
}
138+
139+
140+
function InstallPythonMSI ($msipath, $python_home, $install_log) {
141+
$install_args = "/qn /log $install_log /i $msipath TARGETDIR=$python_home"
142+
$uninstall_args = "/qn /x $msipath"
143+
RunCommand "msiexec.exe" $install_args
144+
if (-not(Test-Path $python_home)) {
145+
Write-Host "Python seems to be installed else-where, reinstalling."
146+
RunCommand "msiexec.exe" $uninstall_args
147+
RunCommand "msiexec.exe" $install_args
148+
}
149+
}
150+
151+
function RunCommand ($command, $command_args) {
152+
Write-Host $command $command_args
153+
Start-Process -FilePath $command -ArgumentList $command_args -Wait -Passthru
154+
}
155+
156+
157+
function InstallPip ($python_home) {
158+
$pip_path = $python_home + "\Scripts\pip.exe"
159+
$python_path = $python_home + "\python.exe"
160+
if (-not(Test-Path $pip_path)) {
161+
Write-Host "Installing pip..."
162+
$webclient = New-Object System.Net.WebClient
163+
$webclient.DownloadFile($GET_PIP_URL, $GET_PIP_PATH)
164+
Write-Host "Executing:" $python_path $GET_PIP_PATH
165+
& $python_path $GET_PIP_PATH
166+
} else {
167+
Write-Host "pip already installed."
168+
}
169+
}
170+
171+
172+
function DownloadMiniconda ($python_version, $platform_suffix) {
173+
if ($python_version -eq "3.4") {
174+
$filename = "Miniconda3-3.5.5-Windows-" + $platform_suffix + ".exe"
175+
} else {
176+
$filename = "Miniconda-3.5.5-Windows-" + $platform_suffix + ".exe"
177+
}
178+
$url = $MINICONDA_URL + $filename
179+
$filepath = Download $filename $url
180+
return $filepath
181+
}
182+
183+
184+
function InstallMiniconda ($python_version, $architecture, $python_home) {
185+
Write-Host "Installing Python" $python_version "for" $architecture "bit architecture to" $python_home
186+
if (Test-Path $python_home) {
187+
Write-Host $python_home "already exists, skipping."
188+
return $false
189+
}
190+
if ($architecture -eq "32") {
191+
$platform_suffix = "x86"
192+
} else {
193+
$platform_suffix = "x86_64"
194+
}
195+
$filepath = DownloadMiniconda $python_version $platform_suffix
196+
Write-Host "Installing" $filepath "to" $python_home
197+
$install_log = $python_home + ".log"
198+
$args = "/S /D=$python_home"
199+
Write-Host $filepath $args
200+
Start-Process -FilePath $filepath -ArgumentList $args -Wait -Passthru
201+
if (Test-Path $python_home) {
202+
Write-Host "Python $python_version ($architecture) installation complete"
203+
} else {
204+
Write-Host "Failed to install Python in $python_home"
205+
Get-Content -Path $install_log
206+
Exit 1
207+
}
208+
}
209+
210+
211+
function InstallMinicondaPip ($python_home) {
212+
$pip_path = $python_home + "\Scripts\pip.exe"
213+
$conda_path = $python_home + "\Scripts\conda.exe"
214+
if (-not(Test-Path $pip_path)) {
215+
Write-Host "Installing pip..."
216+
$args = "install --yes pip"
217+
Write-Host $conda_path $args
218+
Start-Process -FilePath "$conda_path" -ArgumentList $args -Wait -Passthru
219+
} else {
220+
Write-Host "pip already installed."
221+
}
222+
}
223+
224+
function main () {
225+
InstallPython $env:PYTHON_VERSION $env:PYTHON_ARCH $env:PYTHON
226+
InstallPip $env:PYTHON
227+
}
228+
229+
main

appveyor/run_with_env.cmd

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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, and 64-bit builds for 3.5 and beyond, do not require specific
10+
:: environment configurations.
11+
::
12+
:: Note: this script needs to be run with the /E:ON and /V:ON flags for the
13+
:: cmd interpreter, at least for (SDK v7.0)
14+
::
15+
:: More details at:
16+
:: https://github.com/cython/cython/wiki/64BitCythonExtensionsOnWindows
17+
:: http://stackoverflow.com/a/13751649/163740
18+
::
19+
:: Author: Olivier Grisel
20+
:: License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/
21+
::
22+
:: Notes about batch files for Python people:
23+
::
24+
:: Quotes in values are literally part of the values:
25+
:: SET FOO="bar"
26+
:: FOO is now five characters long: " b a r "
27+
:: If you don't want quotes, don't include them on the right-hand side.
28+
::
29+
:: The CALL lines at the end of this file look redundant, but if you move them
30+
:: outside of the IF clauses, they do not run properly in the SET_SDK_64==Y
31+
:: case, I don't know why.
32+
@ECHO OFF
33+
34+
SET COMMAND_TO_RUN=%*
35+
SET WIN_SDK_ROOT=C:\Program Files\Microsoft SDKs\Windows
36+
SET WIN_WDK=c:\Program Files (x86)\Windows Kits\10\Include\wdf
37+
38+
:: Extract the major and minor versions, and allow for the minor version to be
39+
:: more than 9. This requires the version number to have two dots in it.
40+
SET MAJOR_PYTHON_VERSION=%PYTHON_VERSION:~0,1%
41+
IF "%PYTHON_VERSION:~3,1%" == "." (
42+
SET MINOR_PYTHON_VERSION=%PYTHON_VERSION:~2,1%
43+
) ELSE (
44+
SET MINOR_PYTHON_VERSION=%PYTHON_VERSION:~2,2%
45+
)
46+
47+
:: Based on the Python version, determine what SDK version to use, and whether
48+
:: to set the SDK for 64-bit.
49+
IF %MAJOR_PYTHON_VERSION% == 2 (
50+
SET WINDOWS_SDK_VERSION="v7.0"
51+
SET SET_SDK_64=Y
52+
) ELSE (
53+
IF %MAJOR_PYTHON_VERSION% == 3 (
54+
SET WINDOWS_SDK_VERSION="v7.1"
55+
IF %MINOR_PYTHON_VERSION% LEQ 4 (
56+
SET SET_SDK_64=Y
57+
) ELSE (
58+
SET SET_SDK_64=N
59+
IF EXIST "%WIN_WDK%" (
60+
:: See: https://connect.microsoft.com/VisualStudio/feedback/details/1610302/
61+
REN "%WIN_WDK%" 0wdf
62+
)
63+
)
64+
) ELSE (
65+
ECHO Unsupported Python version: "%MAJOR_PYTHON_VERSION%"
66+
EXIT 1
67+
)
68+
)
69+
70+
IF %PYTHON_ARCH% == 64 (
71+
IF %SET_SDK_64% == Y (
72+
ECHO Configuring Windows SDK %WINDOWS_SDK_VERSION% for Python %MAJOR_PYTHON_VERSION% on a 64 bit architecture
73+
SET DISTUTILS_USE_SDK=1
74+
SET MSSdk=1
75+
"%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Setup\WindowsSdkVer.exe" -q -version:%WINDOWS_SDK_VERSION%
76+
"%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Bin\SetEnv.cmd" /x64 /release
77+
ECHO Executing: %COMMAND_TO_RUN%
78+
call %COMMAND_TO_RUN% || EXIT 1
79+
) ELSE (
80+
ECHO Using default MSVC build environment for 64 bit architecture
81+
ECHO Executing: %COMMAND_TO_RUN%
82+
call %COMMAND_TO_RUN% || EXIT 1
83+
)
84+
) ELSE (
85+
ECHO Using default MSVC build environment for 32 bit architecture
86+
ECHO Executing: %COMMAND_TO_RUN%
87+
call %COMMAND_TO_RUN% || EXIT 1
88+
)

0 commit comments

Comments
 (0)