4040 'sunos5' : [os .getenv ('MPLIB_BASE' ) or '/usr/local' ,],
4141}
4242
43- import sys , os
43+ import sys , os , stat
4444from distutils .core import Extension
4545import glob
4646
5959BUILT_TKAGG = False
6060BUILT_WINDOWING = False
6161
62+ class CleanUpFile :
63+ """CleanUpFile deletes the specified filename when self is destroyed."""
64+ def __init__ (self , name ):
65+ self .name = name
66+ def __del__ (self ):
67+ os .remove (self .name )
68+
69+ def temp_copy (_from , _to ):
70+ """temp_copy copies a named file into a named temporary file.
71+ The temporary will be deleted when the setupext module is destructed.
72+ """
73+ # Copy the file data from _from to _to
74+ s = open (_from ).read ()
75+ open (_to ,"w+" ).write (s )
76+ # Suppress object rebuild by preserving time stamps.
77+ stats = os .stat (_from )
78+ os .utime (_to , (stats .st_atime , stats .st_mtime ))
79+ # Make an object to eliminate the temporary file at exit time.
80+ globals ()["_cleanup_" + _to ] = CleanUpFile (_to )
81+
6282def add_base_flags (module ):
6383 incdirs = [os .path .join (p , 'include' ) for p in basedir [sys .platform ]
6484 if os .path .exists (p )]
@@ -343,17 +363,13 @@ def build_tkagg(ext_modules, packages):
343363 # add agg flags before pygtk because agg only supports freetype1
344364 # and pygtk includes freetype2. This is a bit fragile.
345365
346-
347366 add_tk_flags (module ) # do this first
348367 add_agg_flags (module )
349- add_ft2font_flags (module )
350-
351-
368+ add_ft2font_flags (module )
352369 ext_modules .append (module )
353370 BUILT_TKAGG = True
354371
355372
356-
357373def build_agg (ext_modules , packages ):
358374 global BUILT_AGG
359375 if BUILT_AGG : return # only build it if you you haven't already
@@ -377,20 +393,64 @@ def build_agg(ext_modules, packages):
377393def build_image (ext_modules , packages , numerix ):
378394 global BUILT_IMAGE
379395 if BUILT_IMAGE : return # only build it if you you haven't already
380-
381- deps = ['src/_image.cpp' , 'src/mplutils.cpp' ]
382- deps .extend (glob .glob ('agg2/src/*.cpp' ))
383- deps .extend (glob .glob ('CXX/*.cxx' ))
384- deps .extend (glob .glob ('CXX/*.c' ))
385396
386- module = Extension (
387- 'matplotlib._image' ,
388- deps
389- ,
390- )
391- if numerix .lower ().find ('numarray' )>= 0 :
392- module .extra_compile_args .append ('-DNUMARRAY' )
393- add_agg_flags (module )
394- ext_modules .append (module )
397+ if numerix in ["numarray" ,"both" ]: # Build for numarray
398+ temp_copy ('src/_image.cpp' , 'src/_na_image.cpp' )
399+ deps = ['src/_na_image.cpp' , 'src/mplutils.cpp' ]
400+ deps .extend (glob .glob ('agg2/src/*.cpp' ))
401+ deps .extend (glob .glob ('CXX/*.cxx' ))
402+ deps .extend (glob .glob ('CXX/*.c' ))
403+ module = Extension (
404+ 'matplotlib._na_image' ,
405+ deps
406+ ,
407+ )
408+ module .extra_compile_args .append ('-DNUMARRAY=1' )
409+ add_agg_flags (module )
410+ ext_modules .append (module )
411+
412+ if numerix in ["Numeric" ,"both" ]: # Build for Numeric
413+ temp_copy ('src/_image.cpp' , 'src/_nc_image.cpp' )
414+ deps = ['src/_nc_image.cpp' , 'src/mplutils.cpp' ]
415+ deps .extend (glob .glob ('agg2/src/*.cpp' ))
416+ deps .extend (glob .glob ('CXX/*.cxx' ))
417+ deps .extend (glob .glob ('CXX/*.c' ))
418+ module = Extension (
419+ 'matplotlib._nc_image' ,
420+ deps
421+ ,
422+ )
423+ module .extra_compile_args .append ('-DNUMERIC=1' )
424+ add_agg_flags (module )
425+ ext_modules .append (module )
426+
395427 BUILT_IMAGE = True
396428
429+ def build_transforms (ext_modules , packages , numerix ):
430+ if numerix in ["numarray" ,"both" ]: # Build for numarray
431+ cxx = glob .glob ('CXX/*.cxx' )
432+ cxx .extend (glob .glob ('CXX/*.c' ))
433+ temp_copy ("src/_transforms.cpp" ,"src/_na_transforms.cpp" )
434+ module = Extension ('matplotlib._na_transforms' ,
435+ ['src/_na_transforms.cpp' ,
436+ 'src/mplutils.cpp' ] + cxx ,
437+ libraries = ['stdc++' , 'm' ],
438+ include_dirs = ['src' , '.' ],
439+ )
440+ module .extra_compile_args .append ("-DNUMARRAY=1" )
441+ ext_modules .append (module )
442+
443+ if numerix in ["Numeric" ,"both" ]: # Build for Numeric
444+ cxx = glob .glob ('CXX/*.cxx' )
445+ cxx .extend (glob .glob ('CXX/*.c' ))
446+ temp_copy ("src/_transforms.cpp" ,"src/_nc_transforms.cpp" )
447+ module = Extension ('matplotlib._nc_transforms' ,
448+ ['src/_nc_transforms.cpp' ,
449+ 'src/mplutils.cpp' ] + cxx ,
450+ libraries = ['stdc++' , 'm' ],
451+ include_dirs = ['src' , '.' ],
452+ )
453+ module .extra_compile_args .append ("-DNUMERIC=1" )
454+ ext_modules .append (module )
455+
456+
0 commit comments