Skip to content

Commit 25715d2

Browse files
author
Pan
committed
Code changes for win32 build support.
Added appveyor CI config. Added conda CI recipe for Windows builds. Added appveyor and conda CI helper scripts. Updated readme.
1 parent 3eedf3d commit 25715d2

27 files changed

+1724
-1523
lines changed

.appveyor.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
environment:
2+
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
23+
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
38+
39+
test_script:
40+
- python ci\move-conda-package.py
41+
42+
platform:
43+
- x64
44+
45+
artifacts:
46+
- path: '*.tar.bz2'

README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Super fast SSH2 protocol library. ``ssh2-python`` provides Python bindings for `
1111
:alt: Latest Version
1212
.. image:: https://travis-ci.org/ParallelSSH/ssh2-python.svg?branch=master
1313
:target: https://travis-ci.org/ParallelSSH/ssh2-python
14-
14+
.. image:: https://ci.appveyor.com/api/projects/status/github/parallelssh/ssh2-python/branch/master?svg=true
15+
:target: https://ci.appveyor.com/project/pkittenis/ssh2-python
1516

1617
Installation
1718
______________

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/binstar-push.py

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

ci/move-conda-package.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import os
2+
import glob
3+
import shutil
4+
from conda_build.config import Config
5+
6+
binary_package_glob = os.path.join(Config().bldpkgs_dir, '*.tar.bz2')
7+
8+
try:
9+
binary_package = glob.glob(binary_package_glob)[0]
10+
except IndexError:
11+
pass
12+
else:
13+
shutil.move(binary_package, '.')

conda-recipe/meta.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{% set name = "ssh2-python" %}
2+
{% set version = GIT_DESCRIBE_TAG %}
3+
# {% set sha256 = "e5e77801a7a0d49799e288ecbd189b4d1c23eeadcf9c6f4ce80b31b7d397babe" %}
4+
5+
package:
6+
name: {{ name|lower }}
7+
version: {{ version }}
8+
9+
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 }}
14+
15+
build:
16+
features:
17+
- vc9 # [win and py27]
18+
- vc10 # [win and py34]
19+
- vc14 # [win and py35]
20+
# skip: true # [win]
21+
number: 0
22+
script:
23+
- python setup.py install --single-version-externally-managed --record record.txt # [unix]
24+
- rm -f ssh2/*.c # [win]
25+
- python setup.py build_ext --compiler=msvc # [win]
26+
- python setup.py install --single-version-externally-managed --record record.txt # [win]
27+
28+
requirements:
29+
build:
30+
- python
31+
- cython
32+
- setuptools
33+
- gcc # [unix]
34+
- libssh2
35+
- openssl 1.0.*
36+
run:
37+
- python
38+
- libssh2
39+
- gcc # [unix]
40+
- openssl 1.0.*
41+
42+
test:
43+
imports:
44+
- ssh2.session
45+
46+
about:
47+
home: http://github.com/ParallelSSH/ssh2-python
48+
license: LGPL-2.1
49+
license_family: LGPL
50+
license_file: LICENSE
51+
summary: 'Super fact SSH library. Based on libssh2.'
52+
53+
description: |
54+
Super fast SSH2 protocol library.
55+
56+
ssh2-python provides Python bindings for libssh2.
57+
58+
Its only dependency is the libssh2 library.
59+
dev_url: https://github.com/ParallelSSH/ssh2-python
60+
61+
extra:
62+
recipe-maintainers:
63+
- pkittenis

conda-recipe/run_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from ssh2.session import Session
2+
from ssh2.channel import Channel
3+
s = Session()
4+
c = Channel(s)

setup.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323

2424
ext = 'pyx' if USING_CYTHON else 'c'
2525
sources = glob('ssh2/*.%s' % (ext,))
26-
_libs = ['ssh2']
26+
_libs = ['ssh2'] if platform.system() != 'Windows' else [
27+
'libeay32', 'ssleay32', 'Ws2_32', 'libssh2', 'user32']
28+
2729
# _comp_args = ["-ggdb"]
28-
_comp_args = ["-O3"]
30+
_comp_args = ["-O3"] if platform.system() != 'Windows' else None
2931
_embedded_lib = bool(os.environ.get('EMBEDDED_LIB'))
3032
cython_directives = {'embedsignature': True,
3133
'boundscheck': False,
@@ -37,8 +39,10 @@
3739
'cython_compile_time_env': {'EMBEDDED_LIB': _embedded_lib}} \
3840
if USING_CYTHON else {}
3941

42+
print("Linking with %s and compiler arguments %s" % (_libs, _comp_args))
43+
4044
extensions = [
41-
Extension(sources[i].split('.')[0].replace('/', '.'),
45+
Extension(sources[i].split('.')[0].replace(os.path.sep, '.'),
4246
sources=[sources[i]],
4347
libraries=_libs,
4448
extra_compile_args=_comp_args,

ssh2/agent.c

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ssh2/c_sftp.pxd

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
# License along with this library; if not, write to the Free Software
1515
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1616

17-
from libc.stdint cimport uint64_t
18-
19-
from c_ssh2 cimport LIBSSH2_SESSION, LIBSSH2_CHANNEL
17+
from c_ssh2 cimport LIBSSH2_SESSION, LIBSSH2_CHANNEL, libssh2_uint64_t
2018

2119

2220
cdef extern from "libssh2_sftp.h" nogil:
@@ -26,7 +24,7 @@ cdef extern from "libssh2_sftp.h" nogil:
2624
pass
2725
ctypedef struct LIBSSH2_SFTP_ATTRIBUTES:
2826
unsigned long flags
29-
uint64_t filesize
27+
libssh2_uint64_t filesize
3028
unsigned long uid, gid
3129
unsigned long permissions
3230
unsigned long atime, mtime
@@ -35,17 +33,17 @@ cdef extern from "libssh2_sftp.h" nogil:
3533
LIBSSH2_SFTP_ST_RDONLY
3634
LIBSSH2_SFTP_ST_NOSUID
3735
ctypedef struct LIBSSH2_SFTP_STATVFS:
38-
uint64_t f_bsize # file system block size
39-
uint64_t f_frsize # fragment size
40-
uint64_t f_blocks # size of fs in f_frsize units
41-
uint64_t f_bfree # free blocks
42-
uint64_t f_bavail # free blocks for non-root
43-
uint64_t f_files # inodes
44-
uint64_t f_ffree # free inodes
45-
uint64_t f_favail # free inodes for non-root
46-
uint64_t f_fsid # file system ID
47-
uint64_t f_flag # mount flags
48-
uint64_t f_namemax # maximum filename length
36+
libssh2_uint64_t f_bsize # file system block size
37+
libssh2_uint64_t f_frsize # fragment size
38+
libssh2_uint64_t f_blocks # size of fs in f_frsize units
39+
libssh2_uint64_t f_bfree # free blocks
40+
libssh2_uint64_t f_bavail # free blocks for non-root
41+
libssh2_uint64_t f_files # inodes
42+
libssh2_uint64_t f_ffree # free inodes
43+
libssh2_uint64_t f_favail # free inodes for non-root
44+
libssh2_uint64_t f_fsid # file system ID
45+
libssh2_uint64_t f_flag # mount flags
46+
libssh2_uint64_t f_namemax # maximum filename length
4947
# SFTP File types
5048
enum:
5149
LIBSSH2_SFTP_S_IFMT # type of file mask
@@ -120,10 +118,10 @@ cdef extern from "libssh2_sftp.h" nogil:
120118
int libssh2_sftp_closedir(LIBSSH2_SFTP_HANDLE *handle)
121119
void libssh2_sftp_seek(LIBSSH2_SFTP_HANDLE *handle, size_t offset)
122120
void libssh2_sftp_seek64(LIBSSH2_SFTP_HANDLE *handle,
123-
uint64_t offset)
121+
libssh2_uint64_t offset)
124122
void libssh2_sftp_rewind(LIBSSH2_SFTP_HANDLE *handle)
125123
size_t libssh2_sftp_tell(LIBSSH2_SFTP_HANDLE *handle)
126-
uint64_t libssh2_sftp_tell64(LIBSSH2_SFTP_HANDLE *handle)
124+
libssh2_uint64_t libssh2_sftp_tell64(LIBSSH2_SFTP_HANDLE *handle)
127125
int libssh2_sftp_fstat_ex(LIBSSH2_SFTP_HANDLE *handle,
128126
LIBSSH2_SFTP_ATTRIBUTES *attrs,
129127
int setstat)

0 commit comments

Comments
 (0)