forked from travcunn/python-libarchive
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsetup.py
129 lines (109 loc) · 4.69 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
#!/usr/bin/env python
#
# Copyright (c) 2015, SmartFile <[email protected]>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the organization nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from os import environ
try:
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
except ImportError:
from distutils.core import setup, Extension
from distutils.command.build_ext import build_ext
# Use a provided libarchive else default to hard-coded path.
libarchivePrefix = environ.get('LIBARCHIVE_PREFIX')
if libarchivePrefix is None:
import pathlib
for i in [ '/usr', '/usr/local', '/opt/local' ]:
libdir = pathlib.Path(i) / 'lib'
if any(libdir.glob('**/libarchive.*')):
libarchivePrefix = i
break
if libarchivePrefix:
includePath = libarchivePrefix + '/include'
else:
includePath = '/usr/local/include'
name = 'python-libarchive'
version = '4.2.1'
readme = 'README.rst'
repourl = 'https://github.com/smartfile/python-libarchive'
long_description = open(readme).read()
class build_ext_extra(build_ext, object):
"""
Extend build_ext allowing extra_compile_args and extra_link_args to be set
on the command-line.
"""
user_options = build_ext.user_options
user_options.append(('extra-compile-args=', None, 'Extra arguments passed directly to the compiler'))
user_options.append(('extra-link-args=', None, 'Extra arguments passed directly to the linker'))
def initialize_options(self):
build_ext.initialize_options(self)
self.extra_compile_args = None
self.extra_link_args = None
def build_extension(self, ext):
if self.extra_compile_args:
ext.extra_compile_args.append(self.extra_compile_args)
if self.extra_link_args:
ext.extra_link_args.append(self.extra_link_args)
super(build_ext_extra, self).build_extension(ext)
if libarchivePrefix:
extra_compile_args = ['-I{0}/include'.format(libarchivePrefix)]
extra_link_args = ['-Wl,-rpath,{0}/lib'.format(libarchivePrefix)]
environ['LDFLAGS'] = '-L{0}/lib {1}'.format(libarchivePrefix, environ.get('LDFLAGS', ''))
else:
extra_compile_args = []
extra_link_args = ['-l:libarchive.so']
__libarchive = Extension(
name='libarchive.__libarchive',
sources=['libarchive/_libarchive_wrap.c'],
libraries=['archive'],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
include_dirs=[includePath, 'libarchive'],
)
setup(
name=name,
version=version,
description='A libarchive wrapper for Python supporting password protection.',
long_description=long_description,
license='BSD-style license',
platforms=['any'],
author='Vadim Lebedev, Ben Timby, Travis Cunningham, Ryan Johnston, SmartFile',
author_email='[email protected]',
url=repourl,
packages=['libarchive'],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Operating System :: OS Independent',
'Programming Language :: C',
'Programming Language :: Python',
'Topic :: System :: Archiving :: Compression',
'Topic :: Software Development :: Libraries :: Python Modules',
],
cmdclass={
'build_ext': build_ext_extra,
},
ext_modules=[__libarchive],
)