10000 Make using an external PyCXX possible on != Python 2.7 · matplotlib/matplotlib@5f41835 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5f41835

Browse files
committed
Make using an external PyCXX possible on != Python 2.7
1 parent d93226e commit 5f41835

File tree

1 file changed

+51
-17
lines changed

1 file changed

+51
-17
lines changed

setupext.py

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from distutils import version
55
from distutils.core import Extension
66
import glob
7+
import io
78
import multiprocessing
89
import os
910
import re
@@ -634,17 +635,48 @@ class CXX(SetupPackage):
634635
name = 'pycxx'
635636

636637
def check(self):
638+
if sys.version_info[:2] == (2, 7):
639+
# There is no version of PyCXX in the wild that will work
640+
# with Python 2.7
641+
self.__class__.found_external = False
642+
return ("Official version of PyCXX are not compatible with "
643+
"Python 2.7. Using local copy")
644+
645+
self.__class__.found_external = True
646+
old_stdout = sys.stdout
647+
sys.stdout = io.BytesIO()
648+
try:
649+
import CXX
650+
except ImportError:
651+
self.__class__.found_external = False
652+
return "Couldn't import. Using local copy."
653+
finally:
654+
sys.stdout = old_stdout
655+
637656
try:
638657
return self._check_for_pkg_config(
639-
'PyCXX', 'CXX/Extensions.hxx', min_version='PATCH')
658+
'PyCXX', 'CXX/Extensions.hxx', min_version='6.2.4')
640659
except CheckFailed as e:
641660
self.__class__.found_external = False
642661
return str(e) + ' Using local copy.'
643-
else:
644-
self.__class__.found_external = True
645662

646663
def add_flags(self, ext):
647664
if self.found_external:
665+
support_dir = os.path.normpath(
666+
os.path.join(
667+
sys.prefix,
668+
'share',
669+
'python%d.%d' % (
670+
sys.version_info[0], sys.version_info[1]),
671+
'CXX'))
672+
if not os.path.exists(support_dir):
673+
# On Fedora 17, these files are installed in /usr/share/CXX
674+
support_dir = '/usr/src/CXX'
675+
ext.sources.extend([
676+
os.path.join(support_dir, x) for x in
677+
['cxxsupport.cxx', 'cxx_extensions.cxx',
678+
'IndirectPythonInterface.cxx',
679+
'cxxextensions.c']])
648680
pkg_config.setup_extension(ext, 'PyCXX')
649681
else:
650682
ext.sources.extend(glob.glob('CXX/*.cxx'))
@@ -661,28 +693,30 @@ class LibAgg(SetupPackage):
661693
name = 'libagg'
662694

663695
def check(self):
696+
self.__class__.found_external = True
664697
try:
665698
return self._check_for_pkg_config(
666699
'libagg', 'agg2/agg_basics.h', min_version='PATCH')
667700
except CheckFailed as e:
668701
self.__class__.found_external = False
669702
return str(e) + ' Using local copy.'
670-
finally:
671-
self.__class__.found_external = True
672703

673704
def add_flags(self, ext):
674-
ext.include_dirs.append('agg24/include')
675-
agg_sources = [
676-
'agg_bezier_arc.cpp',
677-
'agg_curves.cpp',
678-
'agg_image_filters.cpp',
679-
'agg_trans_affine.cpp',
680-
'agg_vcgen_contour.cpp',
681-
'agg_vcgen_dash.cpp',
682-
'agg_vcgen_stroke.cpp',
683-
]
684-
ext.sources.extend(
685-
os.path.join('agg24', 'src', x) for x in agg_sources)
705+
if self.found_external:
706+
pkg_config.setup_extension(ext, 'libagg')
707+
else:
708+
ext.include_dirs.append('agg24/include')
709+
agg_sources = [
710+
'agg_bezier_arc.cpp',
711+
'agg_curves.cpp',
712+
'agg_image_filters.cpp',
713+
'agg_trans_affine.cpp',
714+
'agg_vcgen_contour.cpp',
715+
'agg_vcgen_dash.cpp',
716+
'agg_vcgen_stroke.cpp',
717+
]
718+
ext.sources.extend(
719+
os.path.join('agg24', 'src', x) for x in agg_sources)
686720

687721

688722
class FreeType(SetupPackage):

0 commit comments

Comments
 (0)
0