Uh oh!
There was an error while loading. Please reload this page.
forked from MagicStack/uvloop
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
Latest commit
126 lines (99 loc) · 4 KB
/
Copy pathsetup.py
File metadata and controls
126 lines (99 loc) · 4 KB
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
importos
importre
importsubprocess
importsys
importunittest
ifsys.platformin ('win32', 'cygwin', 'cli'):
raiseRuntimeError('uvloop does not support Windows at the moment')
ifsys.version_info< (3, 5):
raiseRuntimeError('uvloop requires Python 3.5 or greater')
fromsetuptoolsimportsetup, Extension
fromsetuptools.command.build_extimportbuild_ext
LIBUV_DIR=os.path.join(os.path.dirname(__file__), 'vendor', 'libuv')
defdiscover_tests():
test_loader=unittest.TestLoader()
test_suite=test_loader.discover('tests', pattern='test_*.py')
returntest_suite
classlibuv_build_ext(build_ext):
build_ext.user_options.extend([
("use-system-libuv", None,
"Use the system provided libuv, instead of the bundled one")
])
build_ext.boolean_options.extend(["use-system-libuv"])
definitialize_options(self):
build_ext.initialize_options(self)
ifgetattr(self, 'use_system_libuv', None) isNone:
self.use_system_libuv=0
defbuild_libuv(self):
env=os.environ.copy()
cur_cflags=env.get('CFLAGS', '')
ifnotre.search('-O\d', cur_cflags):
cur_cflags+=' -O2'
env['CFLAGS'] = (cur_cflags+' -fPIC '+env.get('ARCHFLAGS', ''))
j_flag='-j{}'.format(os.cpu_count() or1)
ifnotos.path.exists(os.path.join(LIBUV_DIR, 'configure')):
subprocess.run(['/bin/sh', 'autogen.sh'], cwd=LIBUV_DIR, env=env,
check=True)
# Sometimes pip fails to preserve the timestamps correctly,
# in which case, make will try to run autotools again.
subprocess.run(['touch', 'configure.ac', 'aclocal.m4',
'configure', 'Makefile.am', 'Makefile.in'],
cwd=LIBUV_DIR, env=env, check=True)
subprocess.run(['./configure'], cwd=LIBUV_DIR, env=env, check=True)
c_flag="CFLAGS={}".format(env['CFLAGS'])
subprocess.run(['make', j_flag, c_flag],
cwd=LIBUV_DIR, env=env, check=True)
defbuild_extensions(self):
ifself.use_system_libuv:
self.compiler.add_library('uv')
ifsys.platform=='darwin'and \
os.path.exists('/opt/local/include'):
# Support macports on Mac OS X.
self.compiler.add_include_dir('/opt/local/include')
else:
libuv_lib=os.path.join(LIBUV_DIR, '.libs', 'libuv.a')
ifnotos.path.exists(libuv_lib):
self.build_libuv()
ifnotos.path.exists(libuv_lib):
raiseRuntimeError('failed to build libuv')
self.extensions[-1].extra_objects.extend([libuv_lib])
self.compiler.add_include_dir(os.path.join(LIBUV_DIR, 'include'))
ifsys.platform.startswith('linux'):
self.compiler.add_library('rt')
elifsys.platform.startswith('freebsd'):
self.compiler.add_library('kvm')
elifsys.platform.startswith('sunos'):
self.compiler.add_library('kstat')
super().build_extensions()
setup(
name='uvloop',
description='Fast implementation of asyncio event loop on top of libuv',
url='http://github.com/MagicStack/uvloop',
license='MIT',
author='Yury Selivanov',
author_email='yury@magic.io',
platforms=['*nix'],
version='0.5.4',
packages=['uvloop'],
cmdclass={'build_ext': libuv_build_ext},
ext_modules=[
Extension(
"uvloop.loop",
sources=[
"uvloop/loop.c",
],
extra_compile_args=['-O2']
),
],
classifiers=[
'Development Status :: 4 - Beta',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.5',
'License :: OSI Approved :: Apache Software License',
'License :: OSI Approved :: MIT License',
'Intended Audience :: Developers',
],
provides=['uvloop'],
include_package_data=True,
test_suite='setup.discover_tests'
)