Skip to content

Commit

Permalink
Code changes for win32 build support.
Browse files Browse the repository at this point in the history
Added appveyor CI config.
Added conda CI recipe for Windows builds.
Added appveyor and conda CI helper scripts.
Updated readme.
  • Loading branch information
pkittenis committed Aug 16, 2017
1 parent 3eedf3d commit 25715d2
Show file tree
Hide file tree
Showing 27 changed files with 1,724 additions and 1,523 deletions.
46 changes: 46 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
environment:
matrix:
- TARGET_ARCH: "x64"
CONDA_PY: "27"
PY_CONDITION: "python >=2.7,<3"
CONDA_INSTALL_LOCN: "C:\\Miniconda-x64"
- TARGET_ARCH: "x64"
CONDA_PY: "35"
PY_CONDITION: "python >=3.5,<3.6"
CONDA_INSTALL_LOCN: "C:\\Miniconda35-x64"
- TARGET_ARCH: "x64"
CONDA_PY: "36"
PY_CONDITION: "python >=3.6"
CONDA_INSTALL_LOCN: "C:\\Miniconda36-x64"

matrix:
fast_finish: true

cache:
- "%TMP%\\py\\"

build: false
install:
- set CONDA_NPY=19
# Remove cygwin (and therefore the git that comes with it).
- rmdir C:\cygwin /s /q
# Use the pre-installed Miniconda for the desired arch
- set PATH=%CONDA_INSTALL_LOCN%/Library/bin;%CONDA_INSTALL_LOCN%/Scripts;%PATH%
- conda update --yes --quiet conda
- call %CONDA_INSTALL_LOCN%\Scripts\activate.bat
- conda config --add channels conda-forge
- conda config --set show_channel_urls true
- conda install --yes --quiet conda-build-all
- conda update --yes conda-build
- conda install --yes --quiet conda-forge-build-setup
- run_conda_forge_build_setup
- conda build conda-recipe

test_script:
- python ci\move-conda-package.py

platform:
- x64

artifacts:
- path: '*.tar.bz2'
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Super fast SSH2 protocol library. ``ssh2-python`` provides Python bindings for `
:alt: Latest Version
.. image:: https://travis-ci.org/ParallelSSH/ssh2-python.svg?branch=master
:target: https://travis-ci.org/ParallelSSH/ssh2-python

.. image:: https://ci.appveyor.com/api/projects/status/github/parallelssh/ssh2-python/branch/master?svg=true
:target: https://ci.appveyor.com/project/pkittenis/ssh2-python

Installation
______________
Expand Down
47 changes: 47 additions & 0 deletions ci/appveyor/run_with_env.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
:: To build extensions for 64 bit Python 3, we need to configure environment
:: variables to use the MSVC 2010 C++ compilers from GRMSDKX_EN_DVD.iso of:
:: MS Windows SDK for Windows 7 and .NET Framework 4 (SDK v7.1)
::
:: To build extensions for 64 bit Python 2, we need to configure environment
:: variables to use the MSVC 2008 C++ compilers from GRMSDKX_EN_DVD.iso of:
:: MS Windows SDK for Windows 7 and .NET Framework 3.5 (SDK v7.0)
::
:: 32 bit builds do not require specific environment configurations.
::
:: Note: this script needs to be run with the /E:ON and /V:ON flags for the
:: cmd interpreter, at least for (SDK v7.0)
::
:: More details at:
:: https://github.com/cython/cython/wiki/64BitCythonExtensionsOnWindows
:: http://stackoverflow.com/a/13751649/163740
::
:: Author: Olivier Grisel
:: License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/
@ECHO OFF

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

SET MAJOR_PYTHON_VERSION="%PYTHON_VERSION:~0,1%"
IF %MAJOR_PYTHON_VERSION% == "2" (
SET WINDOWS_SDK_VERSION="v7.0"
) ELSE IF %MAJOR_PYTHON_VERSION% == "3" (
SET WINDOWS_SDK_VERSION="v7.1"
) ELSE (
ECHO Unsupported Python version: "%MAJOR_PYTHON_VERSION%"
EXIT 1
)

IF "%PYTHON_ARCH%"=="64" (
ECHO Configuring Windows SDK %WINDOWS_SDK_VERSION% for Python %MAJOR_PYTHON_VERSION% on a 64 bit architecture
SET DISTUTILS_USE_SDK=1
SET MSSdk=1
"%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Setup\WindowsSdkVer.exe" -q -version:%WINDOWS_SDK_VERSION%
"%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Bin\SetEnv.cmd" /x64 /release
ECHO Executing: %COMMAND_TO_RUN%
call %COMMAND_TO_RUN% || EXIT 1
) ELSE (
ECHO Using default MSVC build environment for 32 bit architecture
ECHO Executing: %COMMAND_TO_RUN%
call %COMMAND_TO_RUN% || EXIT 1
)
12 changes: 12 additions & 0 deletions ci/binstar-push.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os
import glob
import subprocess
import traceback

token = os.environ['BINSTAR_TOKEN']
cmd = ['binstar', '-t', token, 'upload', '--force']
cmd.extend(glob.glob('*.tar.bz2'))
try:
subprocess.check_call(cmd)
except subprocess.CalledProcessError:
traceback.print_exc()
13 changes: 13 additions & 0 deletions ci/move-conda-package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import os
import glob
import shutil
from conda_build.config import Config

binary_package_glob = os.path.join(Config().bldpkgs_dir, '*.tar.bz2')

try:
binary_package = glob.glob(binary_package_glob)[0]
except IndexError:
pass
else:
shutil.move(binary_package, '.')
63 changes: 63 additions & 0 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{% set name = "ssh2-python" %}
{% set version = GIT_DESCRIBE_TAG %}
# {% set sha256 = "e5e77801a7a0d49799e288ecbd189b4d1c23eeadcf9c6f4ce80b31b7d397babe" %}

package:
name: {{ name|lower }}
version: {{ version }}

source:
path: ../
# fn: {{ name }}-{{ version }}.tar.gz
# url: https://pypi.io/packages/source/{{ name[0] }}/{{ name }}/{{ name }}-{{ version }}.tar.gz
# sha256: {{ sha256 }}

build:
features:
- vc9 # [win and py27]
- vc10 # [win and py34]
- vc14 # [win and py35]
# skip: true # [win]
number: 0
script:
- python setup.py install --single-version-externally-managed --record record.txt # [unix]
- rm -f ssh2/*.c # [win]
- python setup.py build_ext --compiler=msvc # [win]
- python setup.py install --single-version-externally-managed --record record.txt # [win]

requirements:
build:
- python
- cython
- setuptools
- gcc # [unix]
- libssh2
- openssl 1.0.*
run:
- python
- libssh2
- gcc # [unix]
- openssl 1.0.*

test:
imports:
- ssh2.session

about:
home: http://github.com/ParallelSSH/ssh2-python
license: LGPL-2.1
license_family: LGPL
license_file: LICENSE
summary: 'Super fact SSH library. Based on libssh2.'

description: |
Super fast SSH2 protocol library.
ssh2-python provides Python bindings for libssh2.
Its only dependency is the libssh2 library.
dev_url: https://github.com/ParallelSSH/ssh2-python

extra:
recipe-maintainers:
- pkittenis
4 changes: 4 additions & 0 deletions conda-recipe/run_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from ssh2.session import Session
from ssh2.channel import Channel
s = Session()
c = Channel(s)
10 changes: 7 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@

ext = 'pyx' if USING_CYTHON else 'c'
sources = glob('ssh2/*.%s' % (ext,))
_libs = ['ssh2']
_libs = ['ssh2'] if platform.system() != 'Windows' else [
'libeay32', 'ssleay32', 'Ws2_32', 'libssh2', 'user32']

# _comp_args = ["-ggdb"]
_comp_args = ["-O3"]
_comp_args = ["-O3"] if platform.system() != 'Windows' else None
_embedded_lib = bool(os.environ.get('EMBEDDED_LIB'))
cython_directives = {'embedsignature': True,
'boundscheck': False,
Expand All @@ -37,8 +39,10 @@
'cython_compile_time_env': {'EMBEDDED_LIB': _embedded_lib}} \
if USING_CYTHON else {}

print("Linking with %s and compiler arguments %s" % (_libs, _comp_args))

extensions = [
Extension(sources[i].split('.')[0].replace('/', '.'),
Extension(sources[i].split('.')[0].replace(os.path.sep, '.'),
sources=[sources[i]],
libraries=_libs,
extra_compile_args=_comp_args,
Expand Down
6 changes: 1 addition & 5 deletions ssh2/agent.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 15 additions & 17 deletions ssh2/c_sftp.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

from libc.stdint cimport uint64_t

from c_ssh2 cimport LIBSSH2_SESSION, LIBSSH2_CHANNEL
from c_ssh2 cimport LIBSSH2_SESSION, LIBSSH2_CHANNEL, libssh2_uint64_t


cdef extern from "libssh2_sftp.h" nogil:
Expand All @@ -26,7 +24,7 @@ cdef extern from "libssh2_sftp.h" nogil:
pass
ctypedef struct LIBSSH2_SFTP_ATTRIBUTES:
unsigned long flags
uint64_t filesize
libssh2_uint64_t filesize
unsigned long uid, gid
unsigned long permissions
unsigned long atime, mtime
Expand All @@ -35,17 +33,17 @@ cdef extern from "libssh2_sftp.h" nogil:
LIBSSH2_SFTP_ST_RDONLY
LIBSSH2_SFTP_ST_NOSUID
ctypedef struct LIBSSH2_SFTP_STATVFS:
uint64_t f_bsize # file system block size
uint64_t f_frsize # fragment size
uint64_t f_blocks # size of fs in f_frsize units
uint64_t f_bfree # free blocks
uint64_t f_bavail # free blocks for non-root
uint64_t f_files # inodes
uint64_t f_ffree # free inodes
uint64_t f_favail # free inodes for non-root
uint64_t f_fsid # file system ID
uint64_t f_flag # mount flags
uint64_t f_namemax # maximum filename length
libssh2_uint64_t f_bsize # file system block size
libssh2_uint64_t f_frsize # fragment size
libssh2_uint64_t f_blocks # size of fs in f_frsize units
libssh2_uint64_t f_bfree # free blocks
libssh2_uint64_t f_bavail # free blocks for non-root
libssh2_uint64_t f_files # inodes
libssh2_uint64_t f_ffree # free inodes
libssh2_uint64_t f_favail # free inodes for non-root
libssh2_uint64_t f_fsid # file system ID
libssh2_uint64_t f_flag # mount flags
libssh2_uint64_t f_namemax # maximum filename length
# SFTP File types
enum:
LIBSSH2_SFTP_S_IFMT # type of file mask
Expand Down Expand Up @@ -120,10 +118,10 @@ cdef extern from "libssh2_sftp.h" nogil:
int libssh2_sftp_closedir(LIBSSH2_SFTP_HANDLE *handle)
void libssh2_sftp_seek(LIBSSH2_SFTP_HANDLE *handle, size_t offset)
void libssh2_sftp_seek64(LIBSSH2_SFTP_HANDLE *handle,
uint64_t offset)
libssh2_uint64_t offset)
void libssh2_sftp_rewind(LIBSSH2_SFTP_HANDLE *handle)
size_t libssh2_sftp_tell(LIBSSH2_SFTP_HANDLE *handle)
uint64_t libssh2_sftp_tell64(LIBSSH2_SFTP_HANDLE *handle)
libssh2_uint64_t libssh2_sftp_tell64(LIBSSH2_SFTP_HANDLE *handle)
int libssh2_sftp_fstat_ex(LIBSSH2_SFTP_HANDLE *handle,
LIBSSH2_SFTP_ATTRIBUTES *attrs,
int setstat)
Expand Down
13 changes: 7 additions & 6 deletions ssh2/c_ssh2.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

from libc.stdint cimport uint64_t
from libc.time cimport time_t
from posix.types cimport blkcnt_t, blksize_t, dev_t, gid_t, ino_t, \
nlink_t, off_t, time_t, uid_t
from posix.stat cimport struct_stat
nlink_t, time_t, uid_t

from c_stat cimport struct_stat


cdef extern from "libssh2.h" nogil:
ctypedef long long libssh2_int64_t
ctypedef int libssh2_socket_t
ctypedef unsigned long long libssh2_uint64_t
int libssh2_init(int flags)
enum:
LIBSSH2_SESSION_BLOCK_INBOUND
Expand All @@ -32,8 +34,7 @@ cdef extern from "libssh2.h" nogil:
LIBSSH2_VERSION_PATCH
LIBSSH2_CHANNEL_FLUSH_EXTENDED_DATA
LIBSSH2_CHANNEL_FLUSH_ALL
ctypedef long long libssh2_int64_t
ctypedef uint64_t libssh2_struct_stat_size
# ctypedef libssh2_uint64_t libssh2_struct_stat_size
ctypedef struct libssh2_struct_stat:
dev_t st_dev
ino_t st_ino
Expand All @@ -42,7 +43,7 @@ cdef extern from "libssh2.h" nogil:
uid_t st_uid
gid_t st_gid
dev_t st_rdev
uint64_t st_size
libssh2_uint64_t st_size
blksize_t st_blksize
blkcnt_t st_blocks
time_t st_atime
Expand Down
36 changes: 36 additions & 0 deletions ssh2/c_stat.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This file is part of ssh2-python.
# Copyright (C) 2017 Panos Kittenis

# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation, version 2.1.

# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

from libc.time cimport time_t
from posix.types cimport blkcnt_t, blksize_t, dev_t, gid_t, ino_t, \
nlink_t, off_t, time_t, uid_t, mode_t


cdef extern from "<sys/stat.h>" nogil:
cdef struct struct_stat "stat":
dev_t st_dev
ino_t st_ino
mode_t st_mode
nlink_t st_nlink
uid_t st_uid
gid_t st_gid
dev_t st_rdev
off_t st_size
blksize_t st_blksize
blkcnt_t st_blocks
time_t st_atime
time_t st_mtime
time_t st_ctime

0 comments on commit 25715d2

Please sign in to comment.