Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ae19a6e

Browse files
committed
Refactor distutils script to display information about the extensions
being built. Use pkg-config to find freetype if possible. svn path=/trunk/matplotlib/; revision=3646
1 parent d151038 commit ae19a6e

3 files changed

Lines changed: 451 additions & 279 deletions

File tree

setup.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
[egg_info]
22
tag_svn_revision = 1
3+
4+
[status]
5+
# To suppress display of the dependencies and their versions
6+
# at the top of the build log, uncomment the following line:
7+
# suppress = 1

setup.py

Lines changed: 103 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

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

4040

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

74+
if major==2 and minor1<3 or major<2:
75+
raise SystemExit("""matplotlib requires Python 2.3 or later.""")
76+
7477
import glob
7578
from distutils.core import setup
7679
from setupext import build_agg, build_gtkagg, build_tkagg, build_wxagg,\
7780
build_ft2font, build_image, build_windowing, build_transforms, \
7881
build_contour, build_nxutils, build_enthought, build_swigagg, build_gdk, \
79-
build_subprocess, build_ttconv
82+
build_subprocess, build_ttconv, print_line, print_status, print_message, \
83+
print_raw, check_for_freetype, check_for_libpng, check_for_gtk, check_for_tk, \
84+
check_for_wx, check_for_numpy, check_for_qt, check_for_qt4, check_for_cairo
8085
#import distutils.sysconfig
8186

87+
# jdh
88+
packages = [
89+
'matplotlib',
90+
'matplotlib.backends',
91+
'matplotlib.toolkits',
92+
'matplotlib.numerix',
93+
'matplotlib.numerix.mlab',
94+
'matplotlib.numerix.ma',
95+
'matplotlib.numerix.npyma',
96+
'matplotlib.numerix.linear_algebra',
97+
'matplotlib.numerix.random_array',
98+
'matplotlib.numerix.fft',
99+
'matplotlib.config'
100+
]
101+
102+
ext_modules = []
103+
104+
# these are not optional
105+
BUILD_FT2FONT = 1
106+
BUILD_TTCONV = 1
107+
BUILD_CONTOUR = 1
108+
BUILD_NXUTILS = 1
109+
82110
for line in file('lib/matplotlib/__init__.py').readlines():
83-
if line[:11] == '__version__':
111+
if (line.startswith('__version__') or
112+
line.startswith('__revision__') or
113+
line.startswith('__date__')):
84114
exec(line.strip())
85115

116+
print_line()
117+
print_raw("BUILDING MATPLOTLIB")
118+
print_status('matplotlib', '%s (r%s)' % (__version__, __revision__.split()[-2]))
119+
print_status('platform', sys.platform)
120+
if sys.platform == 'win32':
121+
print_status('Windows version', sys.getwindowsversion())
122+
print_raw("")
123+
print_raw("REQUIRED DEPENDENCIES")
124+
86125
# Specify all the required mpl data
87126
package_data = {'matplotlib':['mpl-data/fonts/afm/*.afm',
88127
'mpl-data/fonts/pdfcorefonts/*.afm',
@@ -98,43 +137,19 @@
98137
'backends/Matplotlib.nib/*',
99138
]}
100139

140+
if not check_for_numpy():
141+
sys.exit()
142+
101143
# The NUMERIX variable (a list) is left over from the days when it had
102144
# a string for each of the supported backends. Now there is only one
103145
# supported backend, so this approach could (should?) get changed for
104146
# simplicity.
105147

106-
try:
107-
import numpy
108-
NUMERIX = ['numpy']
109-
except ImportError:
110-
raise RuntimeError("You must install numpy to build matplotlib")
148+
import numpy
149+
NUMERIX = ['numpy']
111150

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

114-
ext_modules = []
115-
116-
# these are not optional
117-
BUILD_FT2FONT = 1
118-
BUILD_TTCONV = 1
119-
BUILD_CONTOUR = 1
120-
BUILD_NXUTILS = 1
121-
122-
# jdh
123-
packages = [
124-
'matplotlib',
125-
'matplotlib.backends',
126-
'matplotlib.toolkits',
127-
'matplotlib.numerix',
128-
'matplotlib.numerix.mlab',
129-
'matplotlib.numerix.ma',
130-
'matplotlib.numerix.npyma',
131-
'matplotlib.numerix.linear_algebra',
132-
'matplotlib.numerix.random_array',
133-
'matplotlib.numerix.fft',
134-
'matplotlib.config'
135-
]
136-
137-
138153
try: import subprocess
139154
except ImportError: havesubprocess = False
140155
else: havesubprocess = True
@@ -146,12 +161,28 @@
146161
subprocess_dir = os.path.dirname(subprocess.__file__)
147162
if subprocess_dir.endswith('.egg/subprocess'):
148163
havesubprocess = False
149-
164+
150165
if not havesubprocess:
151166
packages.append('subprocess')
152167
if sys.platform == 'win32':
153168
build_subprocess(ext_modules, packages)
154169

170+
if not check_for_freetype():
171+
sys.exit(1)
172+
173+
if BUILD_FT2FONT:
174+
build_ft2font(ext_modules, packages)
175+
176+
if BUILD_TTCONV:
177+
build_ttconv(ext_modules, packages)
178+
179+
if 1: # I don't think we need to make these optional
180+
build_contour(ext_modules, packages)
181+
build_nxutils(ext_modules, packages)
182+
183+
print_raw("")
184+
print_raw("OPTIONAL DEPENDENCIES")
185+
155186
try: import datetime
156187
except ImportError: havedate = False
157188
else: havedate = True
@@ -174,114 +205,69 @@ def add_dateutil():
174205
add_dateutil()
175206
else:
176207
# only add them if we need them
177-
try: import dateutil
178-
except ImportError:
179-
add_dateutil()
180208

181-
try: import pytz
209+
try:
210+
import pytz
182211
except ImportError:
183212
add_pytz()
184213

214+
try:
215+
import dateutil
216+
except ImportError:
217+
add_dateutil()
218+
185219
build_swigagg(ext_modules, packages)
186220
build_transforms(ext_modules, packages)
187221
build_enthought(ext_modules, packages)
188222

189-
def havegtk():
190-
'check for the presence of pygtk'
191-
if havegtk.gotit is not None: return havegtk.gotit
192-
try:
193-
import gtk
194-
except ImportError:
195-
print 'building for GTK requires pygtk; you must be able to "import gtk" in your build/install environment'
196-
havegtk.gotit = False
197-
except RuntimeError:
198-
print 'pygtk present but import failed'
199-
havegtk.gotit = False
200-
else:
201-
version = (2,2,0)
202-
if gtk.pygtk_version < version:
203-
print "Error: GTK backend requires PyGTK %d.%d.%d (or later), " \
204-
"%d.%d.%d was detected." % (
205-
version + gtk.pygtk_version)
206-
havegtk.gotit = False
207-
else:
208-
havegtk.gotit = True
209-
return havegtk.gotit
210-
211-
havegtk.gotit = None
212-
213-
if BUILD_GTK and havegtk():
214-
build_gdk(ext_modules, packages)
215-
rc['backend'] = 'GTK'
216-
217-
if BUILD_GTKAGG and havegtk():
223+
if check_for_gtk() and (BUILD_GTK or BUILD_GTKAGG):
224+
if BUILD_GTK:
225+
build_gdk(ext_modules, packages)
226+
rc['backend'] = 'GTK'
227+
if BUILD_GTKAGG:
228+
BUILD_AGG = 1
229+
build_gtkagg(ext_modules, packages)
230+
rc['backend'] = 'GTKAgg'
231+
232+
if check_for_tk() and BUILD_TKAGG:
218233
BUILD_AGG = 1
219-
build_gtkagg(ext_modules, packages)
220-
rc['backend'] = 'GTKAgg'
234+
build_tkagg(ext_modules, packages)
235+
rc['backend'] = 'TkAgg'
221236

222-
if BUILD_TKAGG:
223-
try:
224-
import Tkinter
225-
except ImportError:
226-
print 'TKAgg requires TkInter'
227-
BUILD_TKAGG = 0
228-
except RuntimeError:
229-
print 'Tkinter present but import failed'
230-
BUILD_TKAGG = 0
231-
else:
232-
try:
233-
tk = Tkinter.Tk()
234-
tk.withdraw()
235-
except Tkinter.TclError:
236-
print 'Tkinter present, but window failed to open'
237-
BUILD_TKAGG = 0
238-
else:
239-
BUILD_AGG = 1
240-
build_tkagg(ext_modules, packages)
241-
rc['backend'] = 'TkAgg'
242-
243-
if BUILD_WXAGG:
244-
try:
245-
import wx
246-
except ImportError:
247-
if BUILD_WXAGG != 'auto':
248-
print 'WXAgg\'s accelerator requires wxPython'
249-
BUILD_WXAGG = 0
237+
explanation = None
238+
if check_for_wx() and BUILD_WXAGG:
239+
BUILD_AGG = 1
240+
import wx
241+
if wx.__version__ < (2.8):
242+
build_wxagg(ext_modules, packages)
243+
wxagg_backend_status = "yes"
250244
else:
251-
if getattr(wx, '__version__', '0.0')[0:3] < '2.8':
252-
BUILD_AGG = 1
253-
build_wxagg(ext_modules, packages,
254-
not (isinstance(BUILD_WXAGG, str) # don't abort if BUILD_WXAGG
255-
and BUILD_WXAGG.lower() == 'auto')) # is "auto"
256-
rc['backend'] = 'WXAgg'
257-
258-
if BUILD_AGG:
245+
print_message("WxAgg extension not required for wxPython < 2.8")
246+
rc['backend'] = 'WXAgg'
247+
248+
# These are informational only. We don't build
249+
# any extensions for them.
250+
check_for_qt()
251+
check_for_qt4()
252+
check_for_cairo()
253+
254+
if check_for_libpng() and BUILD_AGG:
259255
build_agg(ext_modules, packages)
260256
if rc['backend'] == 'PS': rc['backend'] = 'Agg'
261257

262-
263-
264-
if BUILD_FT2FONT:
265-
build_ft2font(ext_modules, packages)
266-
267-
if BUILD_TTCONV:
268-
build_ttconv(ext_modules, packages)
269-
270258
if BUILD_WINDOWING and sys.platform=='win32':
271259
build_windowing(ext_modules, packages)
272260

273261
if BUILD_IMAGE:
274262
build_image(ext_modules, packages)
275263

276-
if 1: # I don't think we need to make these optional
277-
build_contour(ext_modules, packages)
278-
build_nxutils(ext_modules, packages)
279-
280264
for mod in ext_modules:
281265
if VERBOSE:
282266
mod.extra_compile_args.append('-DVERBOSE')
283267

284-
268+
print_raw("")
269+
print_raw("[Edit setup.cfg to suppress the above messages]")
270+
print_line()
285271

286272
# packagers: set rc['numerix'] and rc['backend'] here to override the auto
287273
# defaults, eg

0 commit comments

Comments
 (0)