Test more things before trying to build our stringprep module.
This commit is contained in:
parent
fb3ac78bf9
commit
829c8b27b6
1 changed files with 18 additions and 5 deletions
23
setup.py
23
setup.py
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from subprocess import call, DEVNULL
|
from subprocess import call, DEVNULL, check_output, CalledProcessError
|
||||||
from tempfile import TemporaryFile
|
from tempfile import TemporaryFile
|
||||||
try:
|
try:
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
@ -35,18 +35,31 @@ 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):
|
def check_include(library_name, header):
|
||||||
command = [os.environ.get('CC', 'cc'), '-E', '-']
|
command = [os.environ.get('PKG_CONFIG', 'pkg-config'), '--cflags', library_name]
|
||||||
|
try:
|
||||||
|
cflags = check_output(command).decode('utf-8').split()
|
||||||
|
except FileNotFoundError:
|
||||||
|
print('pkg-config not found.')
|
||||||
|
return False
|
||||||
|
except CalledProcessError:
|
||||||
|
# pkg-config already prints the missing libraries on stderr.
|
||||||
|
return False
|
||||||
|
command = [os.environ.get('CC', 'cc')] + cflags + ['-E', '-']
|
||||||
with TemporaryFile('w+') as c_file:
|
with TemporaryFile('w+') as c_file:
|
||||||
c_file.write('#include <%s>' % header)
|
c_file.write('#include <%s>' % header)
|
||||||
c_file.seek(0)
|
c_file.seek(0)
|
||||||
try:
|
try:
|
||||||
return call(command, stdin=c_file, stdout=DEVNULL, stderr=DEVNULL) == 0
|
return call(command, stdin=c_file, stdout=DEVNULL, stderr=DEVNULL) == 0
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
|
print('%s headers not found.' % library_name)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
HAS_PYTHON_HEADERS = check_include('python3', 'Python.h')
|
||||||
|
HAS_STRINGPREP_HEADERS = check_include('libidn', 'stringprep.h')
|
||||||
|
|
||||||
ext_modules = None
|
ext_modules = None
|
||||||
if check_include('stringprep.h'):
|
if HAS_PYTHON_HEADERS and HAS_STRINGPREP_HEADERS:
|
||||||
try:
|
try:
|
||||||
from Cython.Build import cythonize
|
from Cython.Build import cythonize
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -54,7 +67,7 @@ if check_include('stringprep.h'):
|
||||||
else:
|
else:
|
||||||
ext_modules = cythonize('slixmpp/stringprep.pyx')
|
ext_modules = cythonize('slixmpp/stringprep.pyx')
|
||||||
else:
|
else:
|
||||||
print('libidn-dev not found, falling back to the slow stringprep module.')
|
print('Falling back to the slow stringprep module.')
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="slixmpp",
|
name="slixmpp",
|
||||||
|
|
Loading…
Reference in a new issue