summaryrefslogtreecommitdiff
path: root/setupinfo.py
diff options
context:
space:
mode:
authorMarc Abramowitz <marc@marc-abramowitz.com>2015-03-05 10:36:36 -0800
committerMarc Abramowitz <marc@marc-abramowitz.com>2015-03-05 15:47:37 -0800
commit738d3584530ffdb32952dda079749f6715438df1 (patch)
treeb773a5895e4184e900b8f9abde16a17f58b97ddb /setupinfo.py
parented6af05991ca39910c575e7177a8389244a2cc4f (diff)
downloadpython-lxml-738d3584530ffdb32952dda079749f6715438df1.tar.gz
Friendlier error when libxml2 not installed
Use distutils.ccompiler.has_function to detect whether libxml2 is installed in setupinfo.py. This allows failing earlier with a somewhat more helpful error message if libxml2 is not installed. On OS X, I display a tip about `xcode-select --install`. Normally I wouldn't put platform-specific stuff in here (i.e.: I don't advise using apt-get on Debian/Ubuntu or yum on Fedora/RedHat/CentOS) because it's a pain to enumerate all the special cases and usually most people on Linux platforms know their platform well enough to know how to install packages. I made an exception for OS X and `xcode-select --install`, because I am pretty savvy with Linux and OS X and getting things to build, but the `xcode-select --install` thing was not obvious to me at all. At one point, I had concluded that libxml2 must've been removed from OS X and I would have to `brew install` it and specify environment variables to make the compiler find it, because it's a keg-only formula, but then I found a post on Stack Overflow, which illustrated that `xcode-select --install` might be all it takes to get Xcode to put the files in the proper places so that command-line tools can find them. Since this was not obvious and a good tip, I decided to add it here.
Diffstat (limited to 'setupinfo.py')
-rw-r--r--setupinfo.py28
1 files changed, 26 insertions, 2 deletions
diff --git a/setupinfo.py b/setupinfo.py
index c6c5ae1e..1ac6f3ba 100644
--- a/setupinfo.py
+++ b/setupinfo.py
@@ -1,6 +1,6 @@
import sys, os, os.path
from distutils.core import Extension
-from distutils.errors import DistutilsOptionError
+from distutils.errors import CompileError, DistutilsOptionError
from versioninfo import get_base_dir
try:
@@ -200,9 +200,33 @@ def find_dependencies(module):
def extra_setup_args():
result = {}
if CYTHON_INSTALLED:
- result['cmdclass'] = {'build_ext': build_pyx}
+ class CheckLibxml2BuildExt(build_pyx):
+ """Subclass to check whether libxml2 is available"""
+
+ def run(self):
+ try:
+ build_pyx.run(self)
+ except CompileError as e:
+ print('Compile failed: %s' % e)
+ if not has_libxml2():
+ sys.stderr.write('*********************************************************************************\n')
+ sys.stderr.write('Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?\n')
+ if sys.platform in ('darwin',):
+ sys.stderr.write('Perhaps try: xcode-select --install\n')
+ sys.stderr.write('*********************************************************************************\n')
+ raise
+
+ result['cmdclass'] = {'build_ext': CheckLibxml2BuildExt}
return result
+def has_libxml2():
+ from distutils import ccompiler
+ compiler = ccompiler.new_compiler()
+ return compiler.has_function(
+ 'xmlXPathInit',
+ include_dirs=['/usr/include/libxml2'], includes=['libxml/xpath.h'],
+ libraries=['xml2'])
+
def libraries():
if sys.platform in ('win32',):
libs = ['libxslt', 'libexslt', 'libxml2', 'iconv']