Debian Codegraph @

setup.py

raw symbols SCIP
1 #!/usr/bin/env python
2 import os
3 from setuptools import setup, find_packages, Extension
4 from setuptools.command.build_ext import new_compiler
5 import sys
6
7
8 # Note: if updating LZ4_REQUIRED_VERSION you need to update docs/install.rst as
9 # well.
10 LZ4_REQUIRED_VERSION = '>= 1.7.5'
11
12 # Check to see if we have a suitable lz4 library installed on the system and
13 # use if so. If not, we'll use the bundled libraries.
14 liblz4_found = False
15
16 try:
17 from pkgconfig import installed as pkgconfig_installed
18 from pkgconfig import parse as pkgconfig_parse
19 except ImportError:
20 # pkgconfig is not installed. It will be installed by setup_requires.
21 pass
22 else:
23 def pkgconfig_installed_check(lib, required_version, default):
24 installed = default
25 try:
26 installed = pkgconfig_installed(lib, required_version)
27 except EnvironmentError:
28 # Windows, no pkg-config present
29 pass
30 except ValueError:
31 # pkgconfig was unable to determine if
32 # required version of liblz4 is available
33 # Bundled version of liblz4 will be used
34 pass
35 return installed
36 liblz4_found = pkgconfig_installed_check('liblz4', LZ4_REQUIRED_VERSION, default=False)
37
38 # Establish if we want to build experimental functionality or not.
39 experimental_env = os.environ.get("PYLZ4_EXPERIMENTAL", "False")
40 if experimental_env.upper() in ("1", "TRUE"):
41 experimental = True
42 else:
43 experimental = False
44
45 # Set up the extension modules. If a system wide lz4 library is found, and is
46 # recent enough, we'll use that. Otherwise we'll build with the bundled one. If
47 # we're building against the system lz4 library we don't set the compiler
48 # flags, so they'll be picked up from the environment. If we're building
49 # against the bundled lz4 files, we'll set the compiler flags to be consistent
50 # with what upstream lz4 recommends.
51
52 extension_kwargs = {}
53
54 lz4version_sources = [
55 'lz4/_version.c'
56 ]
57
58 lz4block_sources = [
59 'lz4/block/_block.c'
60 ]
61
62 lz4frame_sources = [
63 'lz4/frame/_frame.c'
64 ]
65
66 lz4stream_sources = [
67 'lz4/stream/_stream.c'
68 ]
69
70 use_system_liblz4_env = os.environ.get("PYLZ4_USE_SYSTEM_LZ4", "True")
71 if use_system_liblz4_env.upper() in ("1", "TRUE"):
72 use_system_liblz4 = True
73 else:
74 use_system_liblz4 = False
75
76 if liblz4_found is True and use_system_liblz4 is True:
77 extension_kwargs['libraries'] = ['lz4']
78 else:
79 extension_kwargs['include_dirs'] = ['lz4libs']
80 lz4version_sources.extend(
81 [
82 'lz4libs/lz4.c',
83 ]
84 )
85 lz4block_sources.extend(
86 [
87 'lz4libs/lz4.c',
88 'lz4libs/lz4hc.c',
89 ]
90 )
91 lz4frame_sources.extend(
92 [
93 'lz4libs/lz4.c',
94 'lz4libs/lz4hc.c',
95 'lz4libs/lz4frame.c',
96 'lz4libs/xxhash.c',
97 ]
98 )
99 lz4stream_sources.extend(
100 [
101 'lz4libs/lz4.c',
102 'lz4libs/lz4hc.c',
103 ]
104 )
105
106 compiler = new_compiler().compiler_type
107
108 if compiler == 'msvc':
109 extension_kwargs['extra_compile_args'] = [
110 '/Ot',
111 '/Wall',
112 '/wd4711',
113 '/wd4820',
114 ]
115 elif compiler in ('unix', 'mingw32'):
116 if liblz4_found is True and use_system_liblz4 is True:
117 extension_kwargs = pkgconfig_parse('liblz4')
118 else:
119 extension_kwargs['extra_compile_args'] = [
120 '-O3',
121 '-Wall',
122 '-Wundef'
123 ]
124 else:
125 print('Unrecognized compiler: {0}'.format(compiler))
126 sys.exit(1)
127
128 lz4version = Extension('lz4._version',
129 lz4version_sources,
130 **extension_kwargs)
131
132 lz4block = Extension('lz4.block._block',
133 lz4block_sources,
134 **extension_kwargs)
135
136 lz4frame = Extension('lz4.frame._frame',
137 lz4frame_sources,
138 **extension_kwargs)
139
140 lz4stream = Extension('lz4.stream._stream',
141 lz4stream_sources,
142 **extension_kwargs)
143
144 ext_modules = [lz4version, lz4block, lz4frame]
145
146 if experimental is True:
147 ext_modules.append(lz4stream)
148 packages = find_packages()
149 else:
150 packages = find_packages(exclude=("lz4.stream",))
151
152 # Dependencies for testing. We define a list here, so that we can
153 # refer to it for the tests_require and the extras_require arguments
154 # to setup below. The latter enables us to use pip install .[tests] to
155 # install testing dependencies.
156 # Note: pytest 3.3.0 contains a bug with null bytes in parameter IDs:
157 # https://github.com/pytest-dev/pytest/issues/2957
158 tests_require = [
159 'pytest!=3.3.0',
160 'psutil',
161 'pytest-cov',
162 ],
163
164 # Only require pytest-runner if actually running the tests
165 needs_pytest = {'pytest', 'test', 'ptr'}.intersection(sys.argv)
166 pytest_runner = ['pytest-runner'] if needs_pytest else []
167
168 # Finally call setup with the extension modules as defined above.
169 setup(
170 name='lz4',
171 use_scm_version={
172 'write_to': "lz4/version.py",
173 },
174 python_requires=">=3.9",
175 setup_requires=[
176 'setuptools_scm',
177 'pkgconfig',
178 ] + pytest_runner,
179 description="LZ4 Bindings for Python",
180 long_description=open('README.rst', 'r').read(),
181 author='Jonathan Underwood',
182 author_email='[email protected]',
183 url='https://github.com/python-lz4/python-lz4',
184 packages=packages,
185 ext_modules=ext_modules,
186 tests_require=tests_require,
187 extras_require={
188 'tests': tests_require,
189 'docs': [
190 'sphinx >= 1.6.0',
191 'sphinx_bootstrap_theme',
192 ],
193 'flake8': [
194 'flake8',
195 ]
196 },
197 classifiers=[
198 'Development Status :: 5 - Production/Stable',
199 'License :: OSI Approved :: BSD License',
200 'Intended Audience :: Developers',
201 'Programming Language :: C',
202 'Programming Language :: Python',
203 'Programming Language :: Python :: 3.9',
204 'Programming Language :: Python :: 3.10',
205 'Programming Language :: Python :: 3.11',
206 'Programming Language :: Python :: 3.12',
207 'Programming Language :: Python :: 3.13',
208 ],
209 )