Skip to content

Commit a9dc566

Browse files
committed
Don't bother with checking backends at setup time.
We can just default to trying all backends in order until one loads. Only backends actually requiring a compiled component need to be handled in setupext.py now. Move the `mpl-data/*.glade` entry into a recursive glob for the Matplotlib SetupPackage (as there are no more entries for Gtk3). As a side benefit, we don't need any multiprocessing craziness in setupext.py anymore...
1 parent 5afd3bd commit a9dc566

File tree

6 files changed

+19
-414
lines changed

6 files changed

+19
-414
lines changed

.gitignore

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ ehthumbs.db
5050
Icon?
5151
Thumbs.db
5252

53-
# Things specific to this project #
54-
###################################
55-
lib/matplotlib/mpl-data/matplotlib.conf
56-
lib/matplotlib/mpl-data/matplotlibrc
57-
5853
# Documentation generated files #
5954
#################################
6055
# sphinx build directory

lib/matplotlib/mpl-data/matplotlibrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

lib/matplotlib/rcsetup.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -955,9 +955,13 @@ def _validate_linestyle(ls):
955955

956956
# a map from key -> value, converter
957957
defaultParams = {
958-
'backend': ['Agg', validate_backend], # agg is certainly
959-
# present
960-
'backend_fallback': [True, validate_bool], # agg is certainly present
958+
'backend': [["macosx",
959+
"qt5agg", "qt4agg",
960+
"gtk3agg", "gtk3cairo", "gtkagg",
961+
"tkagg",
962+
"wxagg",
963+
"agg", "cairo"], validate_backend],
964+
'backend_fallback': [True, validate_bool],
961965
'backend.qt4': ['PyQt4', validate_qt4],
962966
'backend.qt5': ['PyQt5', validate_qt5],
963967
'webagg.port': [8988, validate_int],

matplotlibrc.template

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@
3636
# referring to the module name (which must be in the PYTHONPATH) as
3737
# 'module://my_backend'.
3838
#
39-
# If you omit this parameter, it will always default to "Agg", which is a
40-
# non-interactive backend.
41-
backend : $TEMPLATE_BACKEND
39+
# Try the backends in the given order until one successfully loads.
40+
# backend : macosx, qt5agg, qt4agg, gtk3agg, gtk3cairo, gtkagg, tkagg, wxagg, agg, cairo
4241

4342
# If you are using the Qt4Agg backend, you can choose here
4443
# to use the PyQt4 bindings or the newer PySide bindings to

setup.py

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,11 @@
7676
setupext.Tests(),
7777
setupext.Toolkits_Tests(),
7878
'Optional backend extensions',
79-
# These backends are listed in order of preference, the first
80-
# being the most preferred. The first one that looks like it will
81-
# work will be selected as the default backend.
8279
setupext.BackendMacOSX(),
83-
setupext.BackendQt5(),
84-
setupext.BackendQt4(),
85-
setupext.BackendGtk3Agg(),
86-
setupext.BackendGtk3Cairo(),
8780
setupext.BackendGtkAgg(),
8881
setupext.BackendTkAgg(),
89-
setupext.BackendWxAgg(),
9082
setupext.BackendGtk(),
9183
setupext.BackendAgg(),
92-
setupext.BackendCairo(),
9384
setupext.Windowing(),
9485
'Optional LaTeX dependencies',
9586
setupext.DviPng(),
@@ -133,9 +124,7 @@ def run(self):
133124
cmdclass['test'] = NoopTestCommand
134125
cmdclass['build_ext'] = BuildExtraLibraries
135126

136-
# One doesn't normally see `if __name__ == '__main__'` blocks in a setup.py,
137-
# however, this is needed on Windows to avoid creating infinite subprocesses
138-
# when using multiprocessing.
127+
139128
if __name__ == '__main__':
140129
# These are distutils.setup parameters that the various packages add
141130
# things to.
@@ -147,7 +136,6 @@ def run(self):
147136
package_dir = {'': 'lib'}
148137
install_requires = []
149138
setup_requires = []
150-
default_backend = None
151139

152140
# If the user just queries for information, don't bother figuring out which
153141
# packages to build or install.
@@ -183,10 +171,6 @@ def run(self):
183171
required_failed.append(package)
184172
else:
185173
good_packages.append(package)
186-
if (isinstance(package, setupext.OptionalBackendPackage) and
187-
package.runtime_check() and
188-
default_backend is None):
189-
default_backend = package.name
190174
print_raw('')
191175

192176
# Abort if any of the required packages can not be built.
@@ -216,17 +200,6 @@ def run(self):
216200
install_requires.extend(package.get_install_requires())
217201
setup_requires.extend(package.get_setup_requires())
218202

219-
# Write the default matplotlibrc file
220-
if default_backend is None:
221-
default_backend = 'svg'
222-
if setupext.options['backend']:
223-
default_backend = setupext.options['backend']
224-
with open('matplotlibrc.template') as fd:
225-
template = fd.read()
226-
template = Template(template)
227-
with open('lib/matplotlib/mpl-data/matplotlibrc', 'w') as fd:
228-
fd.write(template.safe_substitute(TEMPLATE_BACKEND=default_backend))
229-
230203
# Build in verbose mode if requested
231204
if setupext.options['verbose']:
232205
for mod in ext_modules:
@@ -237,10 +210,8 @@ def run(self):
237210
for mod in ext_modules:
238211
mod.finalize()
239212

240-
extra_args = {}
241-
242213
# Finally, pass this all along to distutils to do the heavy lifting.
243-
distrib = setup(
214+
setup(
244215
name="matplotlib",
245216
version=__version__,
246217
description="Python plotting package",
@@ -274,5 +245,4 @@ def run(self):
274245
# check for zip safety.
275246
zip_safe=False,
276247
cmdclass=cmdclass,
277-
**extra_args
278248
)

0 commit comments

Comments
 (0)