Skip to content

Commit cea330e

Browse files
authored
Appveyor wheel (#4)
Add binary wheel building on Windows for all Python versions and PyPi upload on tags.
1 parent 3304910 commit cea330e

12 files changed

+308
-88
lines changed

.appveyor.yml

Lines changed: 112 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,120 @@
11
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_BUILD_FOLDER%\\ci\\appveyor\\run_with_env.cmd"
7+
PYTHONUNBUFFERED: 1
8+
EMBEDDED_LIB: 1
9+
PYPI_USER:
10+
secure: 2m0jy6JD/R9RExIosOT6YA==
11+
PYPI_PASS:
12+
secure: x+dF0A8BZUf2IrPNRN1O0w==
213
matrix:
3-
- TARGET_ARCH: "x64"
4-
CONDA_PY: "27"
5-
PY_CONDITION: "python >=2.7,<3"
6-
CONDA_INSTALL_LOCN: "C:\\Miniconda-x64"
7-
- TARGET_ARCH: "x64"
8-
CONDA_PY: "35"
9-
PY_CONDITION: "python >=3.5,<3.6"
10-
CONDA_INSTALL_LOCN: "C:\\Miniconda35-x64"
11-
- TARGET_ARCH: "x64"
12-
CONDA_PY: "36"
13-
PY_CONDITION: "python >=3.6"
14-
CONDA_INSTALL_LOCN: "C:\\Miniconda36-x64"
15-
16-
matrix:
17-
fast_finish: true
18-
19-
cache:
20-
- "%TMP%\\py\\"
21-
22-
build: false
14+
- PYTHON: "C:\\Python27"
15+
PYTHON_VERSION: "2.7"
16+
PYTHON_ARCH: "32"
17+
MSVC: "Visual Studio 9"
18+
19+
- PYTHON: "C:\\Python27-x64"
20+
PYTHON_VERSION: "2.7"
21+
PYTHON_ARCH: "64"
22+
MSVC: "Visual Studio 9"
23+
24+
- PYTHON: "C:\\Python34"
25+
PYTHON_VERSION: "3.4"
26+
PYTHON_ARCH: "32"
27+
MSVC: "Visual Studio 10"
28+
29+
- PYTHON: "C:\\Python34-x64"
30+
PYTHON_VERSION: "3.4"
31+
PYTHON_ARCH: "64"
32+
MSVC: "Visual Studio 10 Win64"
33+
34+
- PYTHON: "C:\\Python35"
35+
PYTHON_VERSION: "3.5"
36+
PYTHON_ARCH: "32"
37+
MSVC: "Visual Studio 14"
38+
39+
- PYTHON: "C:\\Python35-x64"
40+
PYTHON_VERSION: "3.5"
41+
PYTHON_ARCH: "64"
42+
MSVC: "Visual Studio 14 Win64"
43+
44+
- PYTHON: "C:\\Python36"
45+
PYTHON_VERSION: "3.6"
46+
PYTHON_ARCH: "32"
47+
MSVC: "Visual Studio 14"
48+
49+
- PYTHON: "C:\\Python36-x64"
50+
PYTHON_VERSION: "3.6"
51+
PYTHON_ARCH: "64"
52+
MSVC: "Visual Studio 14 Win64"
53+
2354
install:
24-
- set CONDA_NPY=19
25-
# Remove cygwin (and therefore the git that comes with it).
26-
- rmdir C:\cygwin /s /q
27-
# Use the pre-installed Miniconda for the desired arch
28-
- set PATH=%CONDA_INSTALL_LOCN%/Library/bin;%CONDA_INSTALL_LOCN%/Scripts;%PATH%
29-
- conda update --yes --quiet conda
30-
- call %CONDA_INSTALL_LOCN%\Scripts\activate.bat
31-
- conda config --add channels conda-forge
32-
- conda config --set show_channel_urls true
33-
- conda install --yes --quiet conda-build-all
34-
- conda update --yes conda-build
35-
- conda install --yes --quiet conda-forge-build-setup
36-
- run_conda_forge_build_setup
37-
- conda build conda-recipe
55+
# If there is a newer build queued for the same PR, cancel this one.
56+
# The AppVeyor 'rollout builds' option is supposed to serve the same
57+
# purpose but it is problematic because it tends to cancel builds pushed
58+
# directly to master instead of just PR builds (or the converse).
59+
# credits: JuliaLang developers.
60+
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
61+
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
62+
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
63+
throw "There are newer queued builds for this pull request, failing early." }
64+
- ECHO "Installed SDKs:"
65+
- ps: "ls \"C:/Program Files/Microsoft SDKs/Windows\""
66+
67+
# Prepend newly installed Python to the PATH of this build (this cannot be
68+
# done from inside the powershell script as it would require to restart
69+
# the parent CMD process).
70+
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
71+
72+
# Check that we have the expected version and architecture for Python
73+
- "python --version"
74+
- "python -c \"import struct; print(struct.calcsize('P') * 8)\""
75+
76+
# Upgrade to the latest version of pip to avoid it displaying warnings
77+
# about it being out of date.
78+
- "pip install --disable-pip-version-check --user --upgrade pip"
79+
80+
# Install the build dependencies of the project. If some dependencies contain
81+
# compiled extensions and are not provided as pre-built wheel packages,
82+
# pip will build them from source using the MSVC compiler matching the
83+
# target Python version and architecture
84+
- "%CMD_IN_ENV% pip install -r requirements_dev.txt"
85+
- "%CMD_IN_ENV% pip install -U wheel setuptools twine"
86+
- git submodule update --init --recursive
87+
88+
# .c files need to be generated on Windows to handle platform
89+
# specific code.
90+
# Fix version used by versioneer to current git tag so the generated .c files
91+
# do not cause a version change.
92+
- python ci/appveyor/fix_version.py .
93+
- mv -f .git .git.bak
94+
95+
build_script:
96+
# Build the compiled extension
97+
- "%CMD_IN_ENV% ci\\appveyor\\build_ssh2.bat"
98+
- rm -f ssh2/*.c
99+
- "%CMD_IN_ENV% python setup.py build"
100+
- "%CMD_IN_ENV% python setup.py build_ext -i"
38101

39102
test_script:
40-
- python ci\move-conda-package.py
103+
- python -c "from ssh2.session import Session; Session()"
41104

42-
platform:
43-
- x64
105+
after_test:
106+
# If tests are successful, create binary packages for the project.
107+
- "%CMD_IN_ENV% python setup.py bdist_wheel"
108+
- "%CMD_IN_ENV% python setup.py bdist_wininst"
109+
- mv dist/* .
110+
# Create 'none' ABI dist packages for use by older pip/wheel versions
111+
- python ci/copy_abi_dist.py *.whl
44112

45113
artifacts:
46-
- path: '*.tar.bz2'
114+
# Archive the generated packages in the ci.appveyor.com build report.
115+
- path: "*.whl"
116+
- path: "*.exe"
117+
118+
deploy_script:
119+
- python ci/appveyor/pypi_upload.py *.whl
120+
- python ci/appveyor/pypi_upload.py *.exe

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "libssh2"]
2+
path = libssh2
3+
url = https://github.com/libssh2/libssh2.git

ci/appveyor/anaconda_upload.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import sys
2+
import os
3+
from glob import glob
4+
import subprocess
5+
import traceback
6+
7+
8+
cmd = ['anaconda', '-t', os.environ['ANACONDA_TOKEN'], 'upload']
9+
cmd.extend(glob('*.tar.bz2'))
10+
try:
11+
subprocess.check_call(cmd)
12+
except subprocess.CalledProcessError:
13+
sys.exit(1)

ci/appveyor/build_ssh2.bat

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
mkdir src && cd src
2+
3+
IF "%MSVC%" == "Visual Studio 9" (
4+
ECHO "Building without platform set"
5+
cmake ..\libssh2 -G "NMake Makefiles" ^
6+
-DCMAKE_BUILD_TYPE=Release ^
7+
-DCRYPTO_BACKEND=WinCNG ^
8+
-DBUILD_SHARED_LIBS=OFF
9+
) ELSE (
10+
ECHO "Building with platform %MSVC%"
11+
cmake ..\libssh2 -G "NMake Makefiles" ^
12+
-DCMAKE_BUILD_TYPE=Release ^
13+
-DCRYPTO_BACKEND=WinCNG ^
14+
-G"%MSVC%" ^
15+
-DBUILD_SHARED_LIBS=OFF
16+
)
17+
18+
cmake --build . --config Release
19+
cd ..
20+
ls src/src
21+
cp src/src/libssh2.lib %PYTHON%/libs/ || cp src/src/Release/libssh2.lib %PYTHON%/libs/
22+
ls %PYTHON%/libs/

ci/appveyor/fix_version.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import os
2+
from datetime import datetime
3+
import subprocess
4+
import json
5+
import sys
6+
7+
def get_describe_tag():
8+
return subprocess.check_output(['git', 'describe', '--tags']).strip().decode('utf-8')
9+
10+
def make_version_file(basedir):
11+
# import ipdb; ipdb.set_trace()
12+
rev = os.environ['APPVEYOR_REPO_COMMIT']
13+
basedir = os.path.abspath(basedir)
14+
git_desc = get_describe_tag()
15+
version_json = {'date': datetime.now().isoformat(),
16+
'dirty': False,
17+
'error': None,
18+
'full-revisionid': rev,
19+
'version': git_desc}
20+
data = """
21+
import json
22+
23+
version_json = '''
24+
%s''' # END VERSION_JSON
25+
26+
27+
def get_versions():
28+
return json.loads(version_json)
29+
30+
""" % (json.dumps(version_json))
31+
with open(os.path.join(basedir, 'ssh2', '_version.py'), 'w') as fh:
32+
fh.write(data)
33+
34+
35+
if __name__ == "__main__":
36+
if not len(sys.argv) > 1:
37+
sys.stderr.write("Need basedir of repo" + os.linesep)
38+
sys.exit(1)
39+
make_version_file(sys.argv[1])

ci/appveyor/pypi_upload.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from __future__ import print_function
2+
3+
import sys
4+
import subprocess
5+
import os
6+
7+
8+
def upload_pypi(files):
9+
_user, _pass = os.environ['PYPI_USER'], os.environ['PYPI_PASS']
10+
try:
11+
subprocess.check_call(['twine', 'upload', '-u', _user,
12+
'-p', _pass, files])
13+
except Exception:
14+
sys.stderr.write("Error uploading to PyPi" + os.linesep)
15+
16+
17+
if __name__ == "__main__":
18+
if not len(sys.argv) > 1:
19+
sys.stderr.write("Need files to upload argument" + os.linesep)
20+
sys.exit(1)
21+
upload_pypi(os.path.abspath(sys.argv[1]))

ci/appveyor/run_with_env.cmd

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
:: To build extensions for 64 bit Python 3, we need to configure environment
1+
:: To build extensions for 64 bit Python 3.5 or later no special environment needs
2+
:: to be configured for the Python extension code alone, however, all dependent
3+
:: libraries also need to be compiled with the same SDK in order to be able to
4+
:: link them together.
5+
::
6+
:: This script sets SDK version and environment for all commands.
7+
::
8+
:: To build extensions for 64 bit Python 3.4 or earlier, we need to configure environment
29
:: variables to use the MSVC 2010 C++ compilers from GRMSDKX_EN_DVD.iso of:
310
:: MS Windows SDK for Windows 7 and .NET Framework 4 (SDK v7.1)
411
::
@@ -13,35 +20,52 @@
1320
::
1421
:: More details at:
1522
:: https://github.com/cython/cython/wiki/64BitCythonExtensionsOnWindows
16-
:: http://stackoverflow.com/a/13751649/163740
23+
:: https://stackoverflow.com/a/13751649/163740
1724
::
18-
:: Author: Olivier Grisel
19-
:: License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/
25+
:: Original Author: Olivier Grisel
26+
:: License: CC0 1.0 Universal: https://creativecommons.org/publicdomain/zero/1.0/
27+
:: This version based on updates for python 3.5 by Phil Elson at:
28+
:: https://github.com/pelson/Obvious-CI/tree/master/scripts
29+
:: Further updates to always correctly set SDK version and environment so
30+
:: that compiled library dependencies use same SDK as Python extension.
31+
2032
@ECHO OFF
2133

2234
SET COMMAND_TO_RUN=%*
2335
SET WIN_SDK_ROOT=C:\Program Files\Microsoft SDKs\Windows
2436

2537
SET MAJOR_PYTHON_VERSION="%PYTHON_VERSION:~0,1%"
38+
SET MINOR_PYTHON_VERSION=%PYTHON_VERSION:~2,1%
2639
IF %MAJOR_PYTHON_VERSION% == "2" (
2740
SET WINDOWS_SDK_VERSION="v7.0"
41+
SET SET_SDK_64=Y
2842
) ELSE IF %MAJOR_PYTHON_VERSION% == "3" (
2943
SET WINDOWS_SDK_VERSION="v7.1"
44+
IF %MINOR_PYTHON_VERSION% LEQ 4 (
45+
SET SET_SDK_64=Y
46+
) ELSE (
47+
SET SET_SDK_64=N
48+
)
3049
) ELSE (
3150
ECHO Unsupported Python version: "%MAJOR_PYTHON_VERSION%"
3251
EXIT 1
3352
)
3453

54+
"%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Setup\WindowsSdkVer.exe" -q -version:%WINDOWS_SDK_VERSION%
55+
3556
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%
57+
IF %SET_SDK_64% == Y (
58+
ECHO Configuring Windows SDK %WINDOWS_SDK_VERSION% for Python %MAJOR_PYTHON_VERSION% on a 64 bit architecture
59+
SET DISTUTILS_USE_SDK=1
60+
SET MSSdk=1
61+
)
62+
ECHO Setting MSVC %WINDOWS_SDK_VERSION% build environment for 64 bit architecture
4063
"%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Bin\SetEnv.cmd" /x64 /release
4164
ECHO Executing: %COMMAND_TO_RUN%
4265
call %COMMAND_TO_RUN% || EXIT 1
4366
) ELSE (
44-
ECHO Using default MSVC build environment for 32 bit architecture
67+
ECHO Setting MSVC %WINDOWS_SDK_VERSION% build environment for 32 bit architecture
68+
"%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Bin\SetEnv.cmd" /x86 /release
4569
ECHO Executing: %COMMAND_TO_RUN%
4670
call %COMMAND_TO_RUN% || EXIT 1
4771
)

ci/copy_abi_dist.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from __future__ import print_function
2+
3+
import os
4+
from glob import glob
5+
import re
6+
import sys
7+
import shutil
8+
9+
10+
re_c = re.compile(r'.+-.+-.+-(.+)-.+\.')
11+
12+
13+
def rename_dist_files(files):
14+
for _file in glob(files):
15+
match = re_c.match(_file)
16+
abi = match.group(1)
17+
new_file = _file.replace(abi, 'none')
18+
print("Copying %s to new file %s" % (_file, new_file))
19+
shutil.copy2(_file, new_file)
20+
21+
if __name__ == "__main__":
22+
if len(sys.argv) < 2:
23+
sys.stderr.write("Need files argument" + os.linesep)
24+
sys.exit(1)
25+
rename_dist_files(os.path.abspath(sys.argv[1]))

conda-recipe/meta.yaml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
{% set name = "ssh2-python" %}
22
{% set version = GIT_DESCRIBE_TAG %}
3-
# {% set sha256 = "e5e77801a7a0d49799e288ecbd189b4d1c23eeadcf9c6f4ce80b31b7d397babe" %}
43

54
package:
65
name: {{ name|lower }}
76
version: {{ version }}
87

98
source:
10-
path: ../
11-
# fn: {{ name }}-{{ version }}.tar.gz
12-
# url: https://pypi.io/packages/source/{{ name[0] }}/{{ name }}/{{ name }}-{{ version }}.tar.gz
13-
# sha256: {{ sha256 }}
9+
git_url: https://github.com/ParallelSSH/ssh2-python.git
1410

1511
build:
1612
features:
1713
- vc9 # [win and py27]
1814
- vc10 # [win and py34]
1915
- vc14 # [win and py35]
20-
# skip: true # [win]
2116
number: 0
2217
script:
23-
- python setup.py install --single-version-externally-managed --record record.txt # [unix]
24-
- rm -f ssh2/*.c # [win]
18+
- rm -f ssh2/*.c
19+
- EMBEDDED_LIB=1 python setup.py install --single-version-externally-managed --record record.txt # [unix]
2520
- python setup.py build_ext --compiler=msvc # [win]
2621
- python setup.py install --single-version-externally-managed --record record.txt # [win]
2722

libssh2

Submodule libssh2 added at 30e9c13

0 commit comments

Comments
 (0)