Repository navigation
Expand file tree
/
Copy pathsetup.py
More file actions
115 lines (96 loc) · 3.65 KB
/
Copy pathsetup.py
File metadata and controls
115 lines (96 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# This file is part of ssh-python.
# Copyright (C) 2018-2025 Panos Kittenis.
# Copyright (C) 2018-2025 ssh-python Contributors.
#
# 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-130
import os
import platform
import sys
from glob import glob
from setuptools import setup
# Make the local libssh build helper importable in PEP 517 builds.
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import versioneer
from _setup_libssh import build_ssh
cpython = platform.python_implementation() == 'CPython'
try:
from Cython.Distutils.extension import Extension
from Cython.Distutils import build_ext
except ImportError:
from setuptools import Extension
USING_CYTHON = False
else:
USING_CYTHON = True
ON_WINDOWS = platform.system() == 'Windows'
SYSTEM_LIBSSH = bool(os.environ.get('SYSTEM_LIBSSH', 0)) or ON_WINDOWS
# Only build libssh if SYSTEM_LIBSSH is not set and running a build
if not SYSTEM_LIBSSH and (len(sys.argv) >= 2 and not (
'--help' in sys.argv[1:] or
sys.argv[1] in (
'--help-commands', 'egg_info', '--version', 'clean',
'sdist', '--long-description')) and
__name__ == '__main__'):
sys.stdout.write("SYSTEM_LIBSSH is unset, starting embedded libssh build%s" % (os.linesep,))
build_ssh()
ext = 'pyx' if USING_CYTHON else 'c'
sources = glob('ssh/*.%s' % (ext,))
_arch = platform.architecture()[0][0:2]
_libs = ['ssh'] if not ON_WINDOWS else [
'ssh', 'Ws2_32', 'user32',
'libcrypto%sMD' % _arch, 'libssl%sMD' % _arch,
'zlibstatic',
]
# _comp_args = ["-ggdb"]
_comp_args = ['-O2', '-g0', '-s'] if not ON_WINDOWS else None
cython_directives = {
'embedsignature': True,
'boundscheck': False,
'optimize.use_switch': True,
'wraparound': False,
'language_level': 3,
}
cython_args = {
'cython_directives': cython_directives,
'cython_compile_time_env': {
'ON_WINDOWS': ON_WINDOWS,
}} \
if USING_CYTHON else {}
runtime_library_dirs = ["$ORIGIN/."] if not SYSTEM_LIBSSH else None
lib_dirs = [os.path.abspath("./local/lib")] if not SYSTEM_LIBSSH else ["/usr/local/lib"]
include_dirs = ["./local/include", "./libssh/include"] \
if ON_WINDOWS or not SYSTEM_LIBSSH else ["/usr/local/include"]
sys.stdout.write("Library dirs: %s, runtime dirs: %s, include: %s%s" %
(lib_dirs, runtime_library_dirs, include_dirs, os.linesep))
extensions = [
Extension(
sources[i].split('.')[0].replace(os.path.sep, '.'),
sources=[sources[i]],
include_dirs=include_dirs,
libraries=_libs,
library_dirs=lib_dirs,
runtime_library_dirs=runtime_library_dirs,
extra_compile_args=_comp_args,
**cython_args
)
for i in range(len(sources))]
cmdclass = versioneer.get_cmdclass()
if USING_CYTHON:
cmdclass['build_ext'] = build_ext
sys.stdout.write("Cython arguments: %s%s" % (cython_args, os.linesep))
sys.stdout.write("Windows platform: %s%s" % (ON_WINDOWS, os.linesep))
setup(
version=versioneer.get_version(),
cmdclass=cmdclass,
ext_modules=extensions,
)