-
Notifications
You must be signed in to change notification settings - Fork 72
/
setup.py
225 lines (200 loc) · 6.64 KB
/
setup.py
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/usr/bin/python -u
#
# Python Bindings for LZMA
#
# Copyright (c) 2004-2015 by Joachim Bauch, mail@joachim-bauch.de
# 7-Zip Copyright (C) 1999-2010 Igor Pavlov
# LZMA SDK Copyright (C) 1999-2010 Igor Pavlov
#
# 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; either
# version 2.1 of the License, or (at your option) any later version.
#
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id$
#
import sys, os
from warnings import warn
from distutils import log
from distutils.command.build_ext import build_ext as _build_ext
from version import get_git_version
try:
from setuptools import setup, Extension
except ImportError:
from ez_setup import use_setuptools
use_setuptools()
from setuptools import setup, Extension
class UnsupportedPlatformWarning(Warning):
pass
try:
unicode
except NameError:
# Python 3.x
class unicode(object):
def __new__(cls, s):
if isinstance(s, str):
return s
return s and s.decode('utf-8') or None
version = get_git_version()
if version and not isinstance(version, unicode):
version = unicode(version)
# set this to any true value to enable multithreaded compression
ENABLE_MULTITHREADING = True
# set this to any true value to add the compatibility decoder
# from version 0.0.3 to be able to decompress strings without
# the end of stream mark and you don't know their lengths
ENABLE_COMPATIBILITY = True
# compile including debug symbols on Windows?
COMPILE_DEBUG = False
# are we running on Windows?
IS_WINDOWS = sys.platform in ('win32', )
libraries = []
if IS_WINDOWS:
libraries += ['user32', 'oleaut32']
include_dirs = [
'src/sdk/C',
]
if sys.platform == 'darwin':
# additional include directories are required when compiling on Darwin platforms
include_dirs += [
"/var/include",
]
library_dirs = []
# platforms that multithreaded compression is supported on
mt_platforms = (
'win32',
)
if IS_WINDOWS:
# don't try to import MSVC compiler on non-windows platforms
# as this triggers unnecessary warnings
from distutils.msvccompiler import MSVCCompiler
else:
class MSVCCompiler(object):
# dummy marker class
pass
class build_ext(_build_ext):
def build_extension(self, ext):
self.with_mt = ENABLE_MULTITHREADING
if self.with_mt and not sys.platform in mt_platforms:
warn("""\
Multithreading is not supported on the platform "%s",
please contact mail@joachim-bauch.de for more informations.""" % (sys.platform), UnsupportedPlatformWarning)
self.with_mt = False
if self.with_mt:
log.info('adding support for multithreaded compression')
ext.define_macros.append(('COMPRESS_MF_MT', 1))
ext.sources += (
'src/sdk/C/LzFindMt.c',
'src/sdk/C/MtCoder.c',
'src/sdk/C/MtDec.c',
'src/sdk/C/Threads.c',
)
else:
ext.define_macros.append(('_7ZIP_ST', 1))
if isinstance(self.compiler, MSVCCompiler):
# set flags only available when using MSVC
ext.extra_link_args.append('/MANIFEST')
if COMPILE_DEBUG:
ext.extra_compile_args.append('/Zi')
ext.extra_compile_args.append('/MTd')
ext.extra_link_args.append('/DEBUG')
else:
ext.extra_compile_args.append('/MT')
_build_ext.build_extension(self, ext)
descr = "Python bindings for the LZMA library by Igor Pavlov."
long_descr = """PyLZMA provides a platform independent way to read and write data
that has been compressed or can be decompressed by the LZMA library by Igor Pavlov."""
modules = ['py7zlib']
c_files = [
'src/pylzma/pylzma.c',
'src/pylzma/pylzma_aes.c',
'src/pylzma/pylzma_compress.c',
'src/pylzma/pylzma_compressfile.c',
'src/pylzma/pylzma_decompress.c',
'src/pylzma/pylzma_decompressobj.c',
'src/pylzma/pylzma_streams.c',
]
compile_args = []
link_args = []
macros = [
('PY_SSIZE_T_CLEAN', 1),
]
lzma_files = (
'src/sdk/C/Aes.c',
'src/sdk/C/AesOpt.c',
'src/sdk/C/Bcj2.c',
'src/sdk/C/Bra.c',
'src/sdk/C/Bra86.c',
'src/sdk/C/BraIA64.c',
'src/sdk/C/CpuArch.c',
'src/sdk/C/Delta.c',
'src/sdk/C/LzFind.c',
'src/sdk/C/LzmaDec.c',
'src/sdk/C/LzmaEnc.c',
'src/sdk/C/Lzma2Dec.c',
'src/sdk/C/Lzma2Enc.c',
'src/sdk/C/Sha256.c',
'src/sdk/C/Ppmd7.c',
'src/sdk/C/Ppmd7Dec.c',
)
if ENABLE_COMPATIBILITY:
c_files += (
'src/pylzma/pylzma_decompress_compat.c',
'src/pylzma/pylzma_decompressobj_compat.c',
)
lzma_files += (
'src/compat/LzmaCompatDecode.c',
)
macros.append(('WITH_COMPAT', 1))
if version:
macros.append(('PYLZMA_VERSION', version))
c_files += [os.path.normpath(os.path.join('.', x)) for x in lzma_files]
extens = [
Extension('pylzma', c_files, include_dirs=include_dirs, libraries=libraries,
library_dirs=library_dirs, define_macros=macros, extra_compile_args=compile_args,
extra_link_args=link_args),
]
install_requires = []
tests_require = []
setup(
name = "pylzma",
version = version,
description = descr,
author = "Joachim Bauch",
author_email = "mail@joachim-bauch.de",
url = "http://www.joachim-bauch.de/projects/pylzma/",
download_url = "http://pypi.python.org/pypi/pylzma/",
license = 'LGPL',
keywords = "lzma compression",
long_description = long_descr,
classifiers = [
'Development Status :: 5 - Production/Stable',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Topic :: Software Development :: Libraries :: Python Modules',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)',
'Operating System :: OS Independent',
],
py_modules = modules,
ext_modules = extens,
cmdclass = {
'build_ext': build_ext,
},
install_requires = install_requires,
extras_require = {
'decrypt': [],
},
tests_require = tests_require,
test_suite = 'tests.suite',
zip_safe = False,
)