Debian Codegraph @

setup.py

raw ◀ ▶
Source reconstructed at patch state 0 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 else: # Linux and other unices
127 macros = dict(
128 HAVE_SEM_OPEN=1,
129 HAVE_SEM_TIMEDWAIT=1,
130 HAVE_FD_TRANSFER=1,
131 )
132 libraries = ['rt']
133
134 if sys.platform == 'win32':
135 multiprocessing_srcs = [
136 'Modules/_billiard/multiprocessing.c',
137 'Modules/_billiard/semaphore.c',
138 'Modules/_billiard/win32_functions.c',
139 ]
140 else:
141 multiprocessing_srcs = [
142 'Modules/_billiard/multiprocessing.c',
143 ]
144
145 if macros.get('HAVE_SEM_OPEN', False):
146 multiprocessing_srcs.append('Modules/_billiard/semaphore.c')
147
148 long_description = open(os.path.join(HERE, 'README.rst')).read()
149
150 # -*- Installation Requires -*-
151
152 py_version = sys.version_info
153 is_pypy = hasattr(sys, 'pypy_version_info')
154
155
156 def _is_build_command(argv=sys.argv, cmds=('install', 'build', 'bdist')):
157 for arg in argv:
158 if arg.startswith(cmds):
159 return arg
160
161
162 def run_setup(with_extensions=True):
163 extensions = []
164 if with_extensions:
165 extensions = [
166 setuptools.Extension(
167 '_billiard',
168 sources=multiprocessing_srcs,
169 define_macros=macros.items(),
170 libraries=libraries,
171 include_dirs=['Modules/_billiard'],
172 depends=glob.glob('Modules/_billiard/*.h') + ['setup.py'],
173 ),
174 ]
175 if sys.platform == 'win32':
176 extensions.append(
177 setuptools.Extension(
178 '_winapi',
179 sources=multiprocessing_srcs,
180 define_macros=macros.items(),
181 libraries=libraries,
182 include_dirs=['Modules/_billiard'],
183 depends=glob.glob('Modules/_billiard/*.h') + ['setup.py'],
184 ),
185 )
186 packages = setuptools.find_packages(exclude=['ez_setup', 't', 't.*'])
187 setuptools.setup(
188 name='billiard',
189 version=meta['version'],
190 description=meta['doc'],
191 long_description=long_description,
192 packages=packages,
193 ext_modules=extensions,
194 author=meta['author'],
195 author_email=meta['author_email'],
196 keywords='multiprocessing pool process',
197 maintainer=meta['maintainer'],
198 maintainer_email=meta['contact'],
199 url=meta['homepage'],
200 zip_safe=False,
201 license='BSD',
202 python_requires='>=3.10',
203 classifiers=[
204 'Development Status :: 5 - Production/Stable',
205 'Intended Audience :: Developers',
206 'Programming Language :: Python',
207 'Programming Language :: C',
208 'Programming Language :: Python :: 3',
209 'Programming Language :: Python :: 3.10',
210 'Programming Language :: Python :: 3.11',
211 'Programming Language :: Python :: 3.12',
212 'Programming Language :: Python :: 3.13',
213 'Programming Language :: Python :: 3.14',
214 'Programming Language :: Python :: Implementation :: CPython',
215 'Programming Language :: Python :: Implementation :: PyPy',
216 'Operating System :: Microsoft :: Windows',
217 'Operating System :: POSIX',
218 'License :: OSI Approved :: BSD License',
219 'Topic :: Software Development :: Libraries :: Python Modules',
220 'Topic :: System :: Distributed Computing',
221 ],
222 **extras
223 )
224
225 try:
226 run_setup(not (is_pypy or is_py3k))
227 except BaseException:
228 if _is_build_command(sys.argv):
229 import traceback
230 print(BUILD_WARNING % '\n'.join(traceback.format_stack()),
231 file=sys.stderr)
232 run_setup(False)
233 else:
234 raise