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

Skip to content

Commit 8e6808e

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 38fd0c2 commit 8e6808e

File tree

2 files changed

+130
-185
lines changed

2 files changed

+130
-185
lines changed

setup.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,7 @@
5555
setupext.Matplotlib(),
5656
setupext.Python(),
5757
setupext.Platform(),
58-
setupext.LibAgg(),
5958
setupext.FreeType(),
60-
setupext.FT2Font(),
61-
setupext.Png(),
62-
setupext.Qhull(),
63-
setupext.Image(),
64-
setupext.TTConv(),
65-
setupext.Path(),
66-
setupext.Contour(),
67-
setupext.QhullWrap(),
68-
setupext.Tri(),
6959
setupext.SampleData(),
7060
setupext.Tests(),
7161
setupext.BackendAgg(),
@@ -94,8 +84,11 @@ def __init__(self, dist):
9484

9585
class BuildExtraLibraries(BuildExtCommand):
9686
def finalize_options(self):
97-
self.distribution.ext_modules[:] = filter(
98-
None, (package.get_extension() for package in good_packages))
87+
self.distribution.ext_modules[:] = [
88+
ext
89+
for package in good_packages
90+
for ext in package.get_extensions()
91+
]
9992
super().finalize_options()
10093

10194
def build_extensions(self):

setupext.py

Lines changed: 125 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,13 @@ def get_package_data(self):
316316
"""
317317
return {}
318318

319-
def get_extension(self):
319+
def get_extensions(self):
320320
"""
321-
Get a list of C extensions (`distutils.core.Extension`
321+
Return or yield a list of C extensions (`distutils.core.Extension`
322322
objects) to add to the configuration. These are added to the
323323
`extensions` list passed to `distutils.setup`.
324324
"""
325-
return None
325+
return []
326326

327327
def do_custom_build(self):
328328
"""
@@ -422,6 +422,88 @@ def get_package_data(self):
422422
],
423423
}
424424

425+
def get_extensions(self):
426+
# contour
427+
ext = Extension('matplotlib._contour', [
428+
"src/_contour.cpp",
429+
"src/_contour_wrapper.cpp",
430+
'src/py_converters.cpp',
431+
])
432+
add_numpy_flags(ext)
433+
add_libagg_flags(ext)
434+
yield ext
435+
# ft2font
436+
ext = Extension('matplotlib.ft2font', [
437+
'src/ft2font.cpp',
438+
'src/ft2font_wrapper.cpp',
439+
'src/mplutils.cpp',
440+
'src/py_converters.cpp',
441+
])
442+
FreeType().add_flags(ext)
443+
add_numpy_flags(ext)
444+
add_libagg_flags(ext)
445+
yield ext
446+
# image
447+
ext = Extension('matplotlib._image', [
448+
'src/_image.cpp',
449+
'src/mplutils.cpp',
450+
'src/_image_wrapper.cpp',
451+
'src/py_converters.cpp'
452+
])
453+
add_numpy_flags(ext)
454+
add_libagg_flags_and_sources(ext)
455+
yield ext
456+
# path
457+
ext = Extension('matplotlib._path', [
458+
'src/py_converters.cpp',
459+
'src/_path_wrapper.cpp'
460+
])
461+
add_numpy_flags(ext)
462+
add_libagg_flags_and_sources(ext)
463+
yield ext
464+
# png
465+
ext = Extension('matplotlib._png', [
466+
'src/checkdep_libpng.c',
467+
'src/_png.cpp',
468+
'src/mplutils.cpp',
469+
])
470+
pkg_config_setup_extension(
471+
ext, 'libpng',
472+
atleast_version='1.2',
473+
alt_exec=['libpng-config', '--ldflags'],
474+
default_libraries=(
475+
['png', 'z'] if os.name == 'posix' else
476+
# libpng upstream names their lib libpng16.lib, not png.lib.
477+
# zlib upstream names their lib zlib.lib, not z.lib.
478+
[deplib('libpng16'), deplib('z')] if os.name == 'nt' else
479+
[]))
480+
add_numpy_flags(ext)
481+
yield ext
482+
# qhull
483+
ext = Extension('matplotlib._qhull', ['src/qhull_wrap.c'],
484+
define_macros=[('MPL_DEVNULL', os.devnull)])
485+
add_numpy_flags(ext)
486+
add_qhull_flags(ext)
487+
yield ext
488+
# tri
489+
ext = Extension('matplotlib._tri', [
490+
"src/tri/_tri.cpp",
491+
"src/tri/_tri_wrapper.cpp",
492+
"src/mplutils.cpp"
493+
])
494+
add_numpy_flags(ext)
495+
yield ext
496+
# ttconv
497+
ext = Extension('matplotlib.ttconv', [
498+
'src/_ttconv.cpp',
499+
'extern/ttconv/pprdrv_tt.cpp',
500+
'extern/ttconv/pprdrv_tt2.cpp',
501+
'extern/ttconv/ttutil.cpp'
502+
])
503+
add_numpy_flags(ext)
504+
ext.include_dirs.insert(0, 'extern')
505+
yield ext
506+
425507

426508
class SampleData(OptionalPackage):
427509
"""
@@ -470,26 +552,38 @@ def add_numpy_flags(ext):
470552
])
471553

472554

473-
class LibAgg(SetupPackage):
474-
name = 'libagg'
475-
476-
def add_flags(self, ext, add_sources=True):
477-
# We need a patched Agg not available elsewhere, so always use the
478-
# vendored version.
479-
ext.include_dirs.insert(0, 'extern/agg24-svn/include')
480-
if add_sources:
481-
agg_sources = [
482-
'agg_bezier_arc.cpp',
483-
'agg_curves.cpp',
484-
'agg_image_filters.cpp',
485-
'agg_trans_affine.cpp',
486-
'agg_vcgen_contour.cpp',
487-
'agg_vcgen_dash.cpp',
488-
'agg_vcgen_stroke.cpp',
489-
'agg_vpgen_segmentator.cpp'
490-
]
491-
ext.sources.extend(os.path.join('extern', 'agg24-svn', 'src', x)
492-
for x in agg_sources)
555+
def add_libagg_flags(ext):
556+
# We need a patched Agg not available elsewhere, so always use the vendored
557+
# version.
558+
ext.include_dirs.insert(0, 'extern/agg24-svn/include')
559+
560+
561+
def add_libagg_flags_and_sources(ext):
562+
# We need a patched Agg not available elsewhere, so always use the vendored
563+
# version.
564+
ext.include_dirs.insert(0, 'extern/agg24-svn/include')
565+
agg_sources = [
566+
'agg_bezier_arc.cpp',
567+
'agg_curves.cpp',
568+
'agg_image_filters.cpp',
569+
'agg_trans_affine.cpp',
570+
'agg_vcgen_contour.cpp',
571+
'agg_vcgen_dash.cpp',
572+
'agg_vcgen_stroke.cpp',
573+
'agg_vpgen_segmentator.cpp',
574+
]
575+
ext.sources.extend(
576+
os.path.join('extern', 'agg24-svn', 'src', x) for x in agg_sources)
577+
578+
579+
def add_qhull_flags(ext):
580+
# Qhull doesn't distribute pkg-config info, so we have no way of knowing
581+
# whether a system install is recent enough. Thus, always use the vendored
582+
# version.
583+
ext.include_dirs.insert(0, 'extern')
584+
ext.sources.extend(sorted(glob.glob('extern/libqhull/*.c')))
585+
if sysconfig.get_config_var('LIBM') == '-lm':
586+
ext.libraries.extend('m')
493587

494588

495589
# For FreeType2 and libpng, we add a separate checkdep_foo.c source to at the
@@ -625,153 +719,11 @@ def do_custom_build(self):
625719
shutil.copy2(lib_path, src_path / "objs/.libs/libfreetype.lib")
626720

627721

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

774-
def get_extension(self):
726+
def get_extensions(self):
775727
sources = [
776728
"src/mplutils.cpp",
777729
"src/py_converters.cpp",
@@ -780,9 +732,9 @@ def get_extension(self):
780732
]
781733
ext = Extension('matplotlib.backends._backend_agg', sources)
782734
add_numpy_flags(ext)
783-
LibAgg().add_flags(ext)
735+
add_libagg_flags_and_sources(ext)
784736
FreeType().add_flags(ext)
785-
return ext
737+
yield ext
786738

787739

788740
class BackendTkAgg(OptionalBackendPackage):
@@ -792,7 +744,7 @@ class BackendTkAgg(OptionalBackendPackage):
792744
def check(self):
793745
return "installing; run-time loading from Python Tcl/Tk"
794746

795-
def get_extension(self):
747+
def get_extensions(self):
796748
sources = [
797749
'src/_tkagg.cpp',
798750
'src/py_converters.cpp',
@@ -801,8 +753,8 @@ def get_extension(self):
801753
ext = Extension('matplotlib.backends._tkagg', sources)
802754
self.add_flags(ext)
803755
add_numpy_flags(ext)
804-
LibAgg().add_flags(ext, add_sources=False)
805-
return ext
756+
add_libagg_flags(ext)
757+
yield ext
806758

807759
def add_flags(self, ext):
808760
ext.include_dirs.insert(0, 'src')
@@ -823,12 +775,12 @@ def check(self):
823775
raise CheckFailed("Mac OS-X only")
824776
73C0 return super().check()
825777

826-
def get_extension(self):
778+
def get_extensions(self):
827779
sources = [
828780
'src/_macosx.m'
829781
]
830782
ext = Extension('matplotlib.backends._macosx', sources)
831783
ext.extra_link_args.extend(['-framework', 'Cocoa'])
832784
if platform.python_implementation().lower() == 'pypy':
833785
ext.extra_compile_args.append('-DPYPY=1')
834-
return ext
786+
yield ext

0 commit comments

Comments
 (0)
0