Skip to content

Commit d6259e1

Browse files
committed
Update setup.py to allow optional compilation of C accellerators modules
1 parent 0d63f7a commit d6259e1

File tree

3 files changed

+62
-22
lines changed

3 files changed

+62
-22
lines changed

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ graft docs
88
graft examples
99
graft tests
1010
global-exclude *.pyc
11+
exclude aiohttp/_multidict.html
12+
exclude aiohttp/_multidict.*.so

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ clean:
3737
rm -rf cover
3838
make -C docs clean
3939
python setup.py clean
40+
rm -f aiohttp/_multidict.html
41+
rm -f aiohttp/_multidict.c
42+
rm -f aiohttp/_multidict.*.so
43+
rm -f aiohttp/_multidict.*.pyd
4044

4145
doc:
4246
make -C docs html

setup.py

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import re
44
import sys
55
from setuptools import setup, find_packages, Extension
6+
from distutils.errors import (CCompilerError, DistutilsExecError,
7+
DistutilsPlatformError)
8+
from distutils.command.build_ext import build_ext
69

710

811
try:
@@ -21,6 +24,26 @@
2124
extensions = cythonize(extensions)
2225

2326

27+
class BuildFailed(Exception):
28+
pass
29+
30+
31+
class ve_build_ext(build_ext):
32+
# This class allows C extension building to fail.
33+
34+
def run(self):
35+
try:
36+
build_ext.run(self)
37+
except DistutilsPlatformError:
38+
raise BuildFailed()
39+
40+
def build_extension(self, ext):
41+
try:
42+
build_ext.build_extension(self, ext)
43+
except (CCompilerError, DistutilsExecError, DistutilsPlatformError):
44+
raise BuildFailed()
45+
46+
2447
with codecs.open(os.path.join(os.path.abspath(os.path.dirname(
2548
__file__)), 'aiohttp', '__init__.py'), 'r', 'latin1') as fp:
2649
try:
@@ -40,26 +63,37 @@
4063
def read(f):
4164
return open(os.path.join(os.path.dirname(__file__), f)).read().strip()
4265

66+
args = dict(
67+
name='aiohttp',
68+
version=version,
69+
description=('http client/server for asyncio'),
70+
long_description='\n\n'.join((read('README.rst'), read('CHANGES.txt'))),
71+
classifiers=[
72+
'License :: OSI Approved :: Apache Software License',
73+
'Intended Audience :: Developers',
74+
'Programming Language :: Python',
75+
'Programming Language :: Python :: 3',
76+
'Programming Language :: Python :: 3.3',
77+
'Programming Language :: Python :: 3.4',
78+
'Topic :: Internet :: WWW/HTTP'],
79+
author='Nikolay Kim',
80+
author_email='[email protected]',
81+
url='https://github.com/KeepSafe/aiohttp/',
82+
license='Apache 2',
83+
packages=find_packages(),
84+
install_requires=install_requires,
85+
tests_require=tests_require,
86+
test_suite='nose.collector',
87+
include_package_data=True,
88+
ext_modules=extensions,
89+
cmdclass=dict(build_ext=ve_build_ext))
4390

44-
setup(name='aiohttp',
45-
version=version,
46-
description=('http client/server for asyncio'),
47-
long_description='\n\n'.join((read('README.rst'), read('CHANGES.txt'))),
48-
classifiers=[
49-
'License :: OSI Approved :: Apache Software License',
50-
'Intended Audience :: Developers',
51-
'Programming Language :: Python',
52-
'Programming Language :: Python :: 3',
53-
'Programming Language :: Python :: 3.3',
54-
'Programming Language :: Python :: 3.4',
55-
'Topic :: Internet :: WWW/HTTP'],
56-
author='Nikolay Kim',
57-
author_email='[email protected]',
58-
url='https://github.com/KeepSafe/aiohttp/',
59-
license='Apache 2',
60-
packages=find_packages(),
61-
install_requires=install_requires,
62-
tests_require=tests_require,
63-
test_suite='nose.collector',
64-
include_package_data=True,
65-
ext_modules=extensions)
91+
try:
92+
setup(**args)
93+
except BuildFailed:
94+
print("*************************************************************")
95+
print("Cannot compile C accellerator module, use pure python version")
96+
print("*************************************************************")
97+
del args['ext_modules']
98+
del args['cmdclass']
99+
setup(**args)

0 commit comments

Comments
 (0)