Debian Codegraph @

setup.py

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