Debian Codegraph @

setup.py

raw ◀ ▶
Source reconstructed at patch state 1 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 import os
2 import sys
3 import glob
4
5 import setuptools
6
7 from distutils import sysconfig
8 from distutils.errors import (
9 CCompilerError,
10 DistutilsExecError,
11 DistutilsPlatformError
12 )
13 HERE = os.path.dirname(os.path.abspath(__file__))
14
15 ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
16 if sys.platform == 'win32':
17 # distutils.msvc9compiler can raise IOError if the compiler is missing
18 ext_errors += (IOError, )
19
20 is_pypy = hasattr(sys, 'pypy_version_info')
21 is_py3k = sys.version_info[0] == 3
22
23 BUILD_WARNING = """
24
25 -----------------------------------------------------------------------
26 WARNING: The C extensions could not be compiled
27 -----------------------------------------------------------------------
28
29 Maybe you do not have a C compiler installed on this system?
30 The reason was:
31 %s
32
33 This is just a warning as most of the functionality will work even
34 without the updated C extension. It will simply fallback to the
35 built-in _multiprocessing module. Most notably you will not be able to use
36 FORCE_EXECV on POSIX systems. If this is a problem for you then please
37 install a C compiler or fix the error(s) above.
38 -----------------------------------------------------------------------
39
40 """
41
42 # -*- py3k -*-
43 extras = {}
44
45 # -*- Distribution Meta -*-
46
47 import re
48 re_meta = re.compile(r'__(\w+?)__\s*=\s*(.*)')
49 re_doc = re.compile(r'^"""(.+?)"""')
50 rq = lambda s: s.strip("\"'")
51
52
53 def add_default(m):
54 attr_name, attr_value = m.groups()
55 return ((attr_name, rq(attr_value)), )
56
57
58 def add_doc(m):
59 return (('doc', m.groups()[0]), )
60
61 pats = {re_meta: add_default,
62 re_doc: add_doc}
63 here = os.path.abspath(os.path.dirname(__file__))
64 meta_fh = open(os.path.join(here, 'billiard/__init__.py'))
65 try:
66 meta = {}
67 for line in meta_fh:
68 if line.strip() == '# -eof meta-':
69 break
70 for pattern, handler in pats.items():
71 m = pattern.match(line.strip())
72 if m:
73 meta.update(handler(m))
74 finally:
75 meta_fh.close()
76
77
78 if sys.version_info < (3, 10):
79 raise ValueError('Versions of Python before 3.10 are not supported')
80
81 if sys.platform == 'win32': # Windows
82 macros = dict()
83 libraries = ['ws2_32']
84 elif sys.platform.startswith('darwin'): # macOS
85 macros = dict(
86 HAVE_SEM_OPEN=1,
87 HAVE_SEM_TIMEDWAIT=0,
88 HAVE_FD_TRANSFER=1,
89 HAVE_BROKEN_SEM_GETVALUE=1
90 )
91 libraries = []
92 elif sys.platform.startswith('cygwin'): # Cygwin
93 macros = dict(
94 HAVE_SEM_OPEN=1,
95 HAVE_SEM_TIMEDWAIT=1,
96 HAVE_FD_TRANSFER=0,
97 HAVE_BROKEN_SEM_UNLINK=1
98 )
99 libraries = []
100 elif sys.platform in ('freebsd4', 'freebsd5', 'freebsd6'):
101 # FreeBSD's P1003.1b semaphore support is very experimental
102 # and has many known problems. (as of June 2008)
103 macros = dict( # FreeBSD 4-6
104 HAVE_SEM_OPEN=0,
105 HAVE_SEM_TIMEDWAIT=0,
106 HAVE_FD_TRANSFER=1,
107 )
108 libraries = []
109 elif re.match('^(gnukfreebsd(8|9|10|11)|freebsd(7|8|9|0))', sys.platform):
110 macros = dict( # FreeBSD 7+ and GNU/kFreeBSD 8+
111 HAVE_SEM_OPEN=bool(
112 sysconfig.get_config_var('HAVE_SEM_OPEN') and not
113 bool(sysconfig.get_config_var('POSIX_SEMAPHORES_NOT_ENABLED'))
114 ),
115 HAVE_SEM_TIMEDWAIT=1,
116 HAVE_FD_TRANSFER=1,
117 )
118 libraries = []
119 elif sys.platform.startswith('openbsd'):
120 macros = dict( # OpenBSD
121 HAVE_SEM_OPEN=0, # Not implemented
122 HAVE_SEM_TIMEDWAIT=0,
123 HAVE_FD_TRANSFER=1,
124 )
125 libraries = []
126 elif sys.platform.startswith('gnu'):
127 macros = dict( # GNU/Hurd
128 HAVE_SEM_OPEN=0, # Not implemented
129 HAVE_SEM_TIMEDWAIT=0,
130 HAVE_FD_TRANSFER=1,
131 )
132 libraries = []
133 else: # Linux and other unices
134 macros = dict(
135 HAVE_SEM_OPEN=1,
136 HAVE_SEM_TIMEDWAIT=1,
137 HAVE_FD_TRANSFER=1,
138 )
139 libraries = ['rt']
140
141 if sys.platform == 'win32':
142 multiprocessing_srcs = [
143 'Modules/_billiard/multiprocessing.c',
144 'Modules/_billiard/semaphore.c',
145 'Modules/_billiard/win32_functions.c',
146 ]
147 else:
148 multiprocessing_srcs = [
149 'Modules/_billiard/multiprocessing.c',
150 ]
151
152 if macros.get('HAVE_SEM_OPEN', False):
153 multiprocessing_srcs.append('Modules/_billiard/semaphore.c')
154
155 long_description = open(os.path.join(HERE, 'README.rst')).read()
156
157 # -*- Installation Requires -*-
158
159 py_version = sys.version_info
160 is_pypy = hasattr(sys, 'pypy_version_info')
161
162
163 def _is_build_command(argv=sys.argv, cmds=('install', 'build', 'bdist')):
164 for arg in argv:
165 if arg.startswith(cmds):
166 return arg
167
168
169 def run_setup(with_extensions=True):
170 extensions = []
171 if with_extensions:
172 extensions = [
173 setuptools.Extension(
174 '_billiard',
175 sources=multiprocessing_srcs,
176 define_macros=macros.items(),
177 libraries=libraries,
178 include_dirs=['Modules/_billiard'],
179 depends=glob.glob('Modules/_billiard/*.h') + ['setup.py'],
180 ),
181 ]
182 if sys.platform == 'win32':
183 extensions.append(
184 setuptools.Extension(
185 '_winapi',
186 sources=multiprocessing_srcs,
187 define_macros=macros.items(),
188 libraries=libraries,
189 include_dirs=['Modules/_billiard'],
190 depends=glob.glob('Modules/_billiard/*.h') + ['setup.py'],
191 ),
192 )
193 packages = setuptools.find_packages(exclude=['ez_setup', 't', 't.*'])
194 setuptools.setup(
195 name='billiard',
196 version=meta['version'],
197 description=meta['doc'],
198 long_description=long_description,
199 packages=packages,
200 ext_modules=extensions,
201 author=meta['author'],
202 author_email=meta['author_email'],
203 keywords='multiprocessing pool process',
204 maintainer=meta['maintainer'],
205 maintainer_email=meta['contact'],
206 url=meta['homepage'],
207 zip_safe=False,
208 license='BSD',
209 python_requires='>=3.10',
210 classifiers=[
211 'Development Status :: 5 - Production/Stable',
212 'Intended Audience :: Developers',
213 'Programming Language :: Python',
214 'Programming Language :: C',
215 'Programming Language :: Python :: 3',
216 'Programming Language :: Python :: 3.10',
217 'Programming Language :: Python :: 3.11',
218 'Programming Language :: Python :: 3.12',
219 'Programming Language :: Python :: 3.13',
220 'Programming Language :: Python :: 3.14',
221 'Programming Language :: Python :: Implementation :: CPython',
222 'Programming Language :: Python :: Implementation :: PyPy',
223 'Operating System :: Microsoft :: Windows',
224 'Operating System :: POSIX',
225 'License :: OSI Approved :: BSD License',
226 'Topic :: Software Development :: Libraries :: Python Modules',
227 'Topic :: System :: Distributed Computing',
228 ],
229 **extras
230 )
231
232 try:
233 run_setup(not (is_pypy or is_py3k))
234 except BaseException:
235 if _is_build_command(sys.argv):
236 import traceback
237 print(BUILD_WARNING % '\n'.join(traceback.format_stack()),
238 file=sys.stderr)
239 run_setup(False)
240 else:
241 raise