10000 In the build, declare all (compulsory) extension modules together. · matplotlib/matplotlib@914cce5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 914cce5

Browse files
committed
In the build, declare all (compulsory) extension modules together.
... in a single function. Splitting them over multiple classes doesn't really buy much. Also convert the LibAgg and Qhull classes to toplevel functions, as they play a role similar to add_numpy_flags.
1 parent 146de7f commit 914cce5

File tree

2 files changed

+122
-180
lines changed

2 files changed

+122
-180
lines changed

setup.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,7 @@
5757
setupext.Matplotlib(),
5858
setupext.Python(),
5959
setupext.Platform(),
60-
setupext.LibAgg(),
6160
setupext.FreeType(),
62-
setupext.FT2Font(),
63-
setupext.Png(),
64-
setupext.Qhull(),
65-
setupext.Image(),
66-
setupext.TTConv(),
67-
setupext.Path(),
68-
setupext.Contour(),
69-
setupext.QhullWrap(),
70-
setupext.Tri(),
7161
'Optional subpackages',
7262
setupext.SampleData(),
7363
setupext.Tests(),
@@ -100,8 +90,8 @@ def __init__(self, dist):
10090

10191
class BuildExtraLibraries(BuildExtCommand):
10292
def finalize_options(self):
103-
self.distribution.ext_modules[:] = filter(
104-
None, (package.get_extension() for package in good_packages))
93+
for package in good_packages:
94+
self.distribution.ext_modules.extend(package.get_extensions())
10595
super().finalize_options()
10696

10797
def build_extensions(self):

setupext.py

Lines changed: 120 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -300,13 +300,13 @@ def get_package_data(self):
300300
"""
301301
return {}
302302

303-
def get_extension(self):
303+
def get_extensions(self):
304304
"""
305-
Get a list of C extensions (`distutils.core.Extension`
305+
Return or yield a list of C extensions (`distutils.core.Extension`
306306
objects) to add to the configuration. These are added to the
307307
`extensions` list passed to `distutils.setup`.
308308
"""
309-
return None
309+
return []
310310

311311
def do_custom_build(self):
312312
"""
@@ -404,6 +404,83 @@ def get_package_data(self):
404404
],
405405
}
406406

407+
def get_extensions(self):
408+
# contour
409+
ext = Extension('matplotlib._contour', [
410+
"src/_contour.cpp",
411+
"src/_contour_wrapper.cpp",
412+
'src/py_converters.cpp',
413+
])
414+
add_numpy_flags(ext)
415+
add_libagg_flags(ext)
416+
yield ext
417+
# ft2font
418+
ext = Extension('matplotlib.ft2font', [
419+
'src/ft2font.cpp',
420+
'src/ft2font_wrapper.cpp',
421+
'src/mplutils.cpp',
422+
'src/py_converters.cpp',
423+
])
424+
FreeType().add_flags(ext)
425+
add_numpy_flags(ext)
426+
add_libagg_flags(ext)
427+
yield ext
428+
# image
429+
ext = Extension('matplotlib._image', [
430+
'src/_image.cpp',
431+
'src/mplutils.cpp',
432+
'src/_image_wrapper.cpp',
433+
'src/py_converters.cpp'
434+
])
435+
add_numpy_flags(ext)
436+
add_libagg_flags_and_sources(ext)
437+
yield ext
438+
# path
439+
ext = Extension('matplotlib._path', [
440+
'src/py_converters.cpp',
441+
'src/_path_wrapper.cpp'
442+
])
443+
add_numpy_flags(ext)
444+
add_libagg_flags_and_sources(ext)
445+
yield ext
446+
# png
447+
ext = Extension('matplotlib._png', [
448+
'src/checkdep_libpng.c',
449+
'src/_png.cpp',
450+
'src/mplutils.cpp',
451+
])
452+
pkg_config_setup_extension(
453+
ext, 'libpng',
454+
atleast_version='1.2',
455+
alt_exec=['libpng-config', '--ldflags'],
456+
default_libraries=['png', 'z'])
457+
add_numpy_flags(ext)
458+
yield ext
459+
# qhull
460+
ext = Extension('matplotlib._qhull', ['src/qhull_wrap.c'],
461+
define_macros=[('MPL_DEVNULL', os.devnull)])
462+
add_numpy_flags(ext)
463+
add_qhull_flags(ext)
464+
yield ext
465+
# tri
466+
ext = Extension('matplotlib._tri', [
467+
"src/tri/_tri.cpp",
468+
"src/tri/_tri_wrapper.cpp",
469+
"src/mplutils.cpp"
470+
])
471+
add_numpy_flags(ext)
472+
yield ext
473+
# ttconv
474+
ext = Extension('matplotlib.ttconv', [
475+
'src/_ttconv.cpp',
476+
'extern/ttconv/pprdrv_tt.cpp',
477+
'extern/ttconv/pprdrv_tt2.cpp',
478+
'extern/ttconv/ttutil.cpp'
479+
])
480+
add_numpy_flags(ext)
481+
ext.include_dirs.insert(0, 'extern')
482+
yield ext
483+
407484

408485
class SampleData(OptionalPackage):
409486
"""
@@ -454,26 +531,38 @@ def add_numpy_flags(ext):
454531
])
455532

456533

457-
class LibAgg(SetupPackage):
458-
name = 'libagg'
459-
460-
def add_flags(self, ext, add_sources=True):
461-
# We need a patched Agg not available elsewhere, so always use the
462-
# vendored version.
463-
ext.include_dirs.insert(0, 'extern/agg24-svn/include')
464-
if add_sources:
465-
agg_sources = [
466-
'agg_bezier_arc.cpp',
467-
'agg_curves.cpp',
468-
'agg_image_filters.cpp',
469-
'agg_trans_affine.cpp',
470-
'agg_vcgen_contour.cpp',
471-
'agg_vcgen_dash.cpp',
472-
'agg_vcgen_stroke.cpp',
473-
'agg_vpgen_segmentator.cpp'
474-
]
475-
ext.sources.extend(os.path.join('extern', 'agg24-svn', 'src', x)
476-
for x in agg_sources)
534+
def add_libagg_flags(ext):
535+
# We need a patched Agg not available elsewhere, so always use the vendored
536+
# version.
537+
ext.include_dirs.insert(0, 'extern/agg24-svn/include')
538+
539+
540+
def add_libagg_flags_and_sources(ext):
541+
# We need a patched Agg not available elsewhere, so always use the vendored
542+
# version.
543+
ext.include_dirs.insert(0, 'extern/agg24-svn/include')
544+
agg_sources = [
545+
'agg_bezier_arc.cpp',
546+
'agg_curves.cpp',
547+
'agg_image_filters.cpp',
548+
'agg_trans_affine.cpp',
549+
'agg_vcgen_contour.cpp',
550+
'agg_vcgen_dash.cpp',
551+
'agg_vcgen_stroke.cpp',
552+
'agg_vpgen_segmentator.cpp',
553+
]
554+
ext.sources.extend(
555+
os.path.join('extern', 'agg24-svn', 'src', x) for x in agg_sources)
556+
557+
558+
def add_qhull_flags(ext):
559+
# Qhull doesn't distribute pkg-config info, so we have no way of knowing
560+
# whether a system install is recent enough. Thus, always use the vendored
561+
# version.
562+
ext.include_dirs.insert(0, 'extern')
563+
ext.sources.extend(sorted(glob.glob('extern/libqhull/*.c')))
564+
if sysconfig.get_config_var('LIBM') == '-lm':
565+
ext.libraries.extend('m')
477566

478567

479568
# For FreeType2 and libpng, we add a separate checkdep_foo.c source to at the
@@ -614,148 +703,11 @@ def do_custom_build(self):
614703
str(pathlib.Path(src_path, "objs/.libs/libfreetype.lib")))
615704

616705

617-
class FT2Font(SetupPackage):
618-
name = 'ft2font'
619-
620-
def get_extension(self):
621-
sources = [
622-
'src/ft2font.cpp',
623-
'src/ft2font_wrapper.cpp',
624-
'src/mplutils.cpp',
625-
'src/py_converters.cpp',
626-
]
627-
ext = Extension('matplotlib.ft2font', sources)
628-
FreeType().add_flags(ext)
629-
add_numpy_flags(ext)
630-
LibAgg().add_flags(ext, add_sources=False)
631-
return ext
632-
633-
634-
class Png(SetupPackage):
635-
name = "png"
636-
637-
def get_extension(self):
638-
sources = [
639-
'src/checkdep_libpng.c',
640-
'src/_png.cpp',
641-
'src/mplutils.cpp',
642-
]
643-
ext = Extension('matplotlib._png', sources)
644-
pkg_config_setup_extension(
645-
ext, 'libpng',
646-
atleast_version='1.2',
647-
alt_exec=['libpng-config', '--ldflags'],
648-
default_libraries=['png', 'z'])
649-
add_numpy_flags(ext)
650-
return ext
651-
652-
653-
class Qhull(SetupPackage):
654-
name = "qhull"
655-
656-
def add_flags(self, ext):
657-
# Qhull doesn't distribute pkg-config info, so we have no way of
658-
# knowing whether a system install is recent enough. Thus, always use
659-
# the vendored version.
660-
ext.include_dirs.insert(0, 'extern')
661-
ext.sources.extend(sorted(glob.glob('extern/libqhull/*.c')))
662-
if sysconfig.get_config_var('LIBM') == '-lm':
663-
ext.libraries.extend('m')
664-
665-
666-
class TTConv(SetupPackage):
667-
name = "ttconv"
668-
669-
def get_extension(self):
670-
sources = [
671-
'src/_ttconv.cpp',
672-
'extern/ttconv/pprdrv_tt.cpp',
673-
'extern/ttconv/pprdrv_tt2.cpp',
674-
'extern/ttconv/ttutil.cpp'
675-
]
676-
ext = Extension('matplotlib.ttconv', sources)
677-
add_numpy_flags(ext)
678-
ext.include_dirs.insert(0, 'extern')
679-
return ext
680-
681-
682-
class Path(SetupPackage):
683-
name = "path"
684-
685-
def get_extension(self):
686-
sources = [
687-
'src/py_converters.cpp',
688-
'src/_path_wrapper.cpp'
689-
]
690-
ext = Extension('matplotlib._path', sources)
691-
add_numpy_flags(ext)
692-
LibAgg().add_flags(ext)
693-
return ext
694-
695-
696-
class Image(SetupPackage):
697-
name = "image"
698-
699-
def get_extension(self):
700-
sources = [
701-
'src/_image.cpp',
702-
'src/mplutils.cpp',
703-
'src/_image_wrapper.cpp',
704-
'src/py_converters.cpp'
705-
]
706-
ext = Extension('matplotlib._image', sources)
707-
add_numpy_flags(ext)
708-
LibAgg().add_flags(ext)
709-
710-
return ext
711-
712-
713-
class Contour(SetupPackage):
714-
name = "contour"
715-
716-
def get_extension(self):
717-
sources = [
718-
"src/_contour.cpp",
719-
"src/_contour_wrapper.cpp",
720-
'src/py_converters.cpp',
721-
]
722-
ext = Extension('matplotlib._contour', sources)
723-
add_numpy_flags(ext)
724-
LibAgg().add_flags(ext, add_sources=False)
725-
return ext
726-
727-
728-
class QhullWrap(SetupPackage):
729-
name = "qhull_wrap"
730-
731-
def get_extension(self):
732-
sources = ['src/qhull_wrap.c']
733-
ext = Extension('matplotlib._qhull', sources,
734-
define_macros=[('MPL_DEVNULL', os.devnull)])
735-
add_numpy_flags(ext)
736-
Qhull().add_flags(ext)
737-
return ext
738-
739-
740-
class Tri(SetupPackage):
741-
name = "tri"
742-
743-
def get_extension(self):
744-
sources = [
745-
"src/tri/_tri.cpp",
746-
"src/tri/_tri_wrapper.cpp",
747-
"src/mplutils.cpp"
748-
]
749-
ext = Extension('matplotlib._tri', sources)
750-
add_numpy_flags(ext)
751-
return ext
752-
753-
754706
class BackendAgg(OptionalBackendPackage):
755707
name = "agg"
756708
force = True
757709

758-
def get_extension(self):
710+
def get_extensions(self):
759711
sources = [
760712
"src/mplutils.cpp",
761713
"src/py_converters.cpp",
@@ -764,9 +716,9 @@ def get_extension(self):
764716
]
765717
ext = Extension('matplotlib.backends._backend_agg', sources)
766718
add_numpy_flags(ext)
767-
LibAgg().add_flags(ext)
719+
add_libagg_flags_and_sources(ext)
768720
FreeType().add_flags(ext)
769-
return ext
721+
yield ext
770722

771723

772724
class BackendTkAgg(OptionalBackendPackage):
@@ -776,7 +728,7 @@ class BackendTkAgg(OptionalBackendPackage):
776728
def check(self):
777729
return "installing; run-time loading from Python Tcl/Tk"
778730

779-
def get_extension(self):
731+
def get_extensions(self):
780732
sources = [
781733
'src/_tkagg.cpp',
782734
'src/py_converters.cpp',
@@ -785,8 +737,8 @@ def get_extension(self):
785737
ext = Extension('matplotlib.backends._tkagg', sources)
786738
self.add_flags(ext)
787739
add_numpy_flags(ext)
788-
LibAgg().add_flags(ext, add_sources=False)
789-
return ext
740+
add_libagg_flags(ext)
741+
yield ext
790742

791743
def add_flags(self, ext):
792744
ext.include_dirs.insert(0, 'src')
@@ -807,15 +759,15 @@ def check(self):
807759
raise CheckFailed("Mac OS-X only")
808760
return super().check()
809761

810-
def get_extension(self):
762+
def get_extensions(self):
811763
sources = [
812764
'src/_macosx.m'
813765
]
814766
ext = Extension('matplotlib.backends._macosx', sources)
815767
ext.extra_link_args.extend(['-framework', 'Cocoa'])
816768
if platform.python_implementation().lower() == 'pypy':
817769
ext.extra_compile_args.append('-DPYPY=1')
818-
return ext
770+
yield ext
819771

820772

821773
class OptionalPackageData(OptionalPackage):

0 commit comments

Comments
 (0)
0