Skip to content

Commit

Permalink
Refactor distutils script to display information about the extensions
Browse files Browse the repository at this point in the history
being built.  Use pkg-config to find freetype if possible.

svn path=/trunk/matplotlib/; revision=3646
  • Loading branch information
mdboom committed Jul 31, 2007
1 parent d151038 commit ae19a6e
Show file tree
Hide file tree
Showing 3 changed files with 451 additions and 279 deletions.
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
[egg_info]
tag_svn_revision = 1

[status]
# To suppress display of the dependencies and their versions
# at the top of the build log, uncomment the following line:
# suppress = 1
220 changes: 103 additions & 117 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

# build wxPython extension code to efficiently blit agg into wx. Only
# needed for wxpython <2.8 if you plan on doing animations
BUILD_WXAGG = 0
BUILD_WXAGG = 1


# build a small extension to manage the focus on win32 platforms.
Expand Down Expand Up @@ -71,18 +71,57 @@
setuptools requirement, you must delete the old matplotlib install
directory.""")

if major==2 and minor1<3 or major<2:
raise SystemExit("""matplotlib requires Python 2.3 or later.""")

import glob
from distutils.core import setup
from setupext import build_agg, build_gtkagg, build_tkagg, build_wxagg,\
build_ft2font, build_image, build_windowing, build_transforms, \
build_contour, build_nxutils, build_enthought, build_swigagg, build_gdk, \
build_subprocess, build_ttconv
build_subprocess, build_ttconv, print_line, print_status, print_message, \
print_raw, check_for_freetype, check_for_libpng, check_for_gtk, check_for_tk, \
check_for_wx, check_for_numpy, check_for_qt, check_for_qt4, check_for_cairo
#import distutils.sysconfig

# jdh
packages = [
'matplotlib',
'matplotlib.backends',
'matplotlib.toolkits',
'matplotlib.numerix',
'matplotlib.numerix.mlab',
'matplotlib.numerix.ma',
'matplotlib.numerix.npyma',
'matplotlib.numerix.linear_algebra',
'matplotlib.numerix.random_array',
'matplotlib.numerix.fft',
'matplotlib.config'
]

ext_modules = []

# these are not optional
BUILD_FT2FONT = 1
BUILD_TTCONV = 1
BUILD_CONTOUR = 1
BUILD_NXUTILS = 1

for line in file('lib/matplotlib/__init__.py').readlines():
if line[:11] == '__version__':
if (line.startswith('__version__') or
line.startswith('__revision__') or
line.startswith('__date__')):
exec(line.strip())

print_line()
print_raw("BUILDING MATPLOTLIB")
print_status('matplotlib', '%s (r%s)' % (__version__, __revision__.split()[-2]))
print_status('platform', sys.platform)
if sys.platform == 'win32':
print_status('Windows version', sys.getwindowsversion())
print_raw("")
print_raw("REQUIRED DEPENDENCIES")

# Specify all the required mpl data
package_data = {'matplotlib':['mpl-data/fonts/afm/*.afm',
'mpl-data/fonts/pdfcorefonts/*.afm',
Expand All @@ -98,43 +137,19 @@
'backends/Matplotlib.nib/*',
]}

if not check_for_numpy():
sys.exit()

# The NUMERIX variable (a list) is left over from the days when it had
# a string for each of the supported backends. Now there is only one
# supported backend, so this approach could (should?) get changed for
# simplicity.

try:
import numpy
NUMERIX = ['numpy']
except ImportError:
raise RuntimeError("You must install numpy to build matplotlib")
import numpy
NUMERIX = ['numpy']

rc['numerix'] = NUMERIX[-1]

ext_modules = []

# these are not optional
BUILD_FT2FONT = 1
BUILD_TTCONV = 1
BUILD_CONTOUR = 1
BUILD_NXUTILS = 1

# jdh
packages = [
'matplotlib',
'matplotlib.backends',
'matplotlib.toolkits',
'matplotlib.numerix',
'matplotlib.numerix.mlab',
'matplotlib.numerix.ma',
'matplotlib.numerix.npyma',
'matplotlib.numerix.linear_algebra',
'matplotlib.numerix.random_array',
'matplotlib.numerix.fft',
'matplotlib.config'
]


try: import subprocess
except ImportError: havesubprocess = False
else: havesubprocess = True
Expand All @@ -146,12 +161,28 @@
subprocess_dir = os.path.dirname(subprocess.__file__)
if subprocess_dir.endswith('.egg/subprocess'):
havesubprocess = False

if not havesubprocess:
packages.append('subprocess')
if sys.platform == 'win32':
build_subprocess(ext_modules, packages)

if not check_for_freetype():
sys.exit(1)

if BUILD_FT2FONT:
build_ft2font(ext_modules, packages)

if BUILD_TTCONV:
build_ttconv(ext_modules, packages)

if 1: # I don't think we need to make these optional
build_contour(ext_modules, packages)
build_nxutils(ext_modules, packages)

print_raw("")
print_raw("OPTIONAL DEPENDENCIES")

try: import datetime
except ImportError: havedate = False
else: havedate = True
Expand All @@ -174,114 +205,69 @@ def add_dateutil():
add_dateutil()
else:
# only add them if we need them
try: import dateutil
except ImportError:
add_dateutil()

try: import pytz
try:
import pytz
except ImportError:
add_pytz()

try:
import dateutil
except ImportError:
add_dateutil()

build_swigagg(ext_modules, packages)
build_transforms(ext_modules, packages)
build_enthought(ext_modules, packages)

def havegtk():
'check for the presence of pygtk'
if havegtk.gotit is not None: return havegtk.gotit
try:
import gtk
except ImportError:
print 'building for GTK requires pygtk; you must be able to "import gtk" in your build/install environment'
havegtk.gotit = False
except RuntimeError:
print 'pygtk present but import failed'
havegtk.gotit = False
else:
version = (2,2,0)
if gtk.pygtk_version < version:
print "Error: GTK backend requires PyGTK %d.%d.%d (or later), " \
"%d.%d.%d was detected." % (
version + gtk.pygtk_version)
havegtk.gotit = False
else:
havegtk.gotit = True
return havegtk.gotit

havegtk.gotit = None

if BUILD_GTK and havegtk():
build_gdk(ext_modules, packages)
rc['backend'] = 'GTK'

if BUILD_GTKAGG and havegtk():
if check_for_gtk() and (BUILD_GTK or BUILD_GTKAGG):
if BUILD_GTK:
build_gdk(ext_modules, packages)
rc['backend'] = 'GTK'
if BUILD_GTKAGG:
BUILD_AGG = 1
build_gtkagg(ext_modules, packages)
rc['backend'] = 'GTKAgg'

if check_for_tk() and BUILD_TKAGG:
BUILD_AGG = 1
build_gtkagg(ext_modules, packages)
rc['backend'] = 'GTKAgg'
build_tkagg(ext_modules, packages)
rc['backend'] = 'TkAgg'

if BUILD_TKAGG:
try:
import Tkinter
except ImportError:
print 'TKAgg requires TkInter'
BUILD_TKAGG = 0
except RuntimeError:
print 'Tkinter present but import failed'
BUILD_TKAGG = 0
else:
try:
tk = Tkinter.Tk()
tk.withdraw()
except Tkinter.TclError:
print 'Tkinter present, but window failed to open'
BUILD_TKAGG = 0
else:
BUILD_AGG = 1
build_tkagg(ext_modules, packages)
rc['backend'] = 'TkAgg'

if BUILD_WXAGG:
try:
import wx
except ImportError:
if BUILD_WXAGG != 'auto':
print 'WXAgg\'s accelerator requires wxPython'
BUILD_WXAGG = 0
explanation = None
if check_for_wx() and BUILD_WXAGG:
BUILD_AGG = 1
import wx
if wx.__version__ < (2.8):
build_wxagg(ext_modules, packages)
wxagg_backend_status = "yes"
else:
if getattr(wx, '__version__', '0.0')[0:3] < '2.8':
BUILD_AGG = 1
build_wxagg(ext_modules, packages,
not (isinstance(BUILD_WXAGG, str) # don't abort if BUILD_WXAGG
and BUILD_WXAGG.lower() == 'auto')) # is "auto"
rc['backend'] = 'WXAgg'

if BUILD_AGG:
print_message("WxAgg extension not required for wxPython < 2.8")
rc['backend'] = 'WXAgg'

# These are informational only. We don't build
# any extensions for them.
check_for_qt()
check_for_qt4()
check_for_cairo()

if check_for_libpng() and BUILD_AGG:
build_agg(ext_modules, packages)
if rc['backend'] == 'PS': rc['backend'] = 'Agg'



if BUILD_FT2FONT:
build_ft2font(ext_modules, packages)

if BUILD_TTCONV:
build_ttconv(ext_modules, packages)

if BUILD_WINDOWING and sys.platform=='win32':
build_windowing(ext_modules, packages)

if BUILD_IMAGE:
build_image(ext_modules, packages)

if 1: # I don't think we need to make these optional
build_contour(ext_modules, packages)
build_nxutils(ext_modules, packages)

for mod in ext_modules:
if VERBOSE:
mod.extra_compile_args.append('-DVERBOSE')


print_raw("")
print_raw("[Edit setup.cfg to suppress the above messages]")
print_line()

# packagers: set rc['numerix'] and rc['backend'] here to override the auto
# defaults, eg
Expand Down
Loading

0 comments on commit ae19a6e

Please sign in to comment.