setup.py: Check for libidn before trying to use Cython.

This commit is contained in:
Emmanuel Gil Peyrot 2016-10-05 20:28:11 +01:00
parent 36824379c3
commit 3c7236fe73

View file

@ -7,20 +7,15 @@
# This software is licensed as described in the README.rst and LICENSE # This software is licensed as described in the README.rst and LICENSE
# file, which you should have received as part of this distribution. # file, which you should have received as part of this distribution.
import os
from pathlib import Path from pathlib import Path
from subprocess import call, DEVNULL
from tempfile import TemporaryFile
try: try:
from setuptools import setup from setuptools import setup
except ImportError: except ImportError:
from distutils.core import setup from distutils.core import setup
try:
from Cython.Build import cythonize
except ImportError:
print('Cython not found, falling back to the slow stringprep module.')
ext_modules = None
else:
ext_modules = cythonize('slixmpp/stringprep.pyx')
from run_tests import TestCommand from run_tests import TestCommand
from slixmpp.version import __version__ from slixmpp.version import __version__
@ -40,6 +35,27 @@ CLASSIFIERS = [
packages = [str(mod.parent) for mod in Path('slixmpp').rglob('__init__.py')] packages = [str(mod.parent) for mod in Path('slixmpp').rglob('__init__.py')]
def check_include(header):
command = [os.environ.get('CC', 'cc'), '-E', '-']
with TemporaryFile('w+') as c_file:
c_file.write('#include <%s>' % header)
c_file.seek(0)
try:
return call(command, stdin=c_file, stdout=DEVNULL, stderr=DEVNULL) == 0
except FileNotFoundError:
return False
ext_modules = None
if check_include('stringprep.h'):
try:
from Cython.Build import cythonize
except ImportError:
print('Cython not found, falling back to the slow stringprep module.')
else:
ext_modules = cythonize('slixmpp/stringprep.pyx')
else:
print('libidn-dev not found, falling back to the slow stringprep module.')
setup( setup(
name="slixmpp", name="slixmpp",
version=VERSION, version=VERSION,