Skip to content

Commit f56520e

Browse files
committed
Further simplify setupext.
Remove `config = "auto"` and `SetupPackage.optional`, which were effectively unused.
1 parent 860803d commit f56520e

File tree

3 files changed

+27
-56
lines changed

3 files changed

+27
-56
lines changed

setup.cfg.template

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,11 @@
1818

1919
[gui_support]
2020
# Matplotlib supports multiple GUI toolkits, known as backends.
21-
# The Mac OSX backend requires the Cocoa headers included with XCode.
21+
# The MacOSX backend requires the Cocoa headers included with XCode.
2222
# You can select whether to build it by uncommenting the following line.
23-
# Acceptable values are:
23+
# It is never built on Linux or Windows, regardless of the config value.
2424
#
25-
# True: build the extension. Exits with a warning if the
26-
# required dependencies are not available
27-
# False: do not build the extension
28-
# auto: build if the required dependencies are available,
29-
# otherwise skip silently. This is the default
30-
# behavior
31-
#
32-
#macosx = auto
25+
#macosx = True
3326

3427
[rc_options]
3528
# User-configurable options

setup.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,13 @@ def run(self):
187187
good_packages = []
188188
for package in mpl_packages:
189189
try:
190-
result = package.check()
191-
if result is not None:
192-
print_status(package.name, 'yes [%s]' % result)
193-
except setupext.CheckFailed as e:
194-
print_status(package.name, 'no [%s]' % str(e))
195-
if not package.optional:
196-
sys.exit("Failed to build %s" % package.name)
197-
else:
198-
good_packages.append(package)
190+
message = package.check()
191+
except setupext.Skipped as e:
192+
print_status(package.name, f"no [{e}]")
193+
continue
194+
if message is not None:
195+
print_status(package.name, f"yes [{message}]")
196+
good_packages.append(package)
199197

200198
print_raw()
201199

setupext.py

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -256,38 +256,38 @@ def pkg_config_setup_extension(
256256
ext.libraries.extend(default_libraries)
257257

258258

259-
class CheckFailed(Exception):
259+
class Skipped(Exception):
260260
"""
261-
Exception thrown when a `SetupPackage.check` method fails.
261+
Exception thrown by `SetupPackage.check` to indicate that a package should
262+
be skipped.
262263
"""
263-
pass
264264

265265

266266
class SetupPackage:
267-
optional = False
268267

269268
def check(self):
270269
"""
271-
Checks whether the build dependencies are met. Should raise a
272-
`CheckFailed` exception if the dependency could not be met, otherwise
273-
return a string indicating a version number or some other message
274-
indicating what was found.
270+
If the package should be installed, return an informative string, or
271+
None if no information should be displayed at all.
272+
273+
If the package should be skipped, raise a `Skipped` exception.
274+
275+
If a missing build dependency is fatal, call `sys.exit`.
275276
"""
276-
pass
277277

278278
def get_package_data(self):
279279
"""
280280
Get a package data dictionary to add to the configuration.
281-
These are merged into to the `package_data` list passed to
282-
`distutils.setup`.
281+
These are merged into to the *package_data* list passed to
282+
`setuptools.setup`.
283283
"""
284284
return {}
285285

286286
def get_extension(self):
287287
"""
288288
Get a list of C extensions (`distutils.core.Extension`
289289
objects) to add to the configuration. These are added to the
290-
`extensions` list passed to `distutils.setup`.
290+
*extensions* list passed to `setuptools.setup`.
291291
"""
292292
return None
293293

@@ -297,43 +297,23 @@ def do_custom_build(self):
297297
third-party library, before building an extension, it should
298298
override this method.
299299
"""
300-
pass
301300

302301

303302
class OptionalPackage(SetupPackage):
304-
optional = True
305303
config_category = "packages"
306-
default_config = "auto"
307-
308-
@classmethod
309-
def get_config(cls):
310-
"""
311-
Look at `setup.cfg` and return one of ["auto", True, False] indicating
312-
if the package is at default state ("auto"), forced by the user (case
313-
insensitively defined as 1, true, yes, on for True) or opted-out (case
314-
insensitively defined as 0, false, no, off for False).
315-
"""
316-
conf = cls.default_config
317-
if config.has_option(cls.config_category, cls.name):
318-
try:
319-
conf = config.getboolean(cls.config_category, cls.name)
320-
except ValueError:
321-
conf = config.get(cls.config_category, cls.name)
322-
return conf
304+
default_config = True
323305

324306
def check(self):
325307
"""
326308
Check whether ``setup.cfg`` requests this package to be installed.
327309
328310
May be overridden by subclasses for additional checks.
329311
"""
330-
conf = self.get_config() # Check configuration file
331-
if conf in [True, 'auto']: # Default "auto", or install forced by user
332-
if conf is True: # Set non-optional if user sets `True` in config
333-
self.optional = False
312+
if config.getboolean(self.config_category, self.name,
313+
fallback=self.default_config):
334314
return "installing"
335315
else: # Configuration opt-out by user
336-
raise CheckFailed("skipping due to configuration")
316+
raise Skipped("skipping due to configuration")
337317

338318

339319
class Platform(SetupPackage):
@@ -745,7 +725,7 @@ class BackendMacOSX(OptionalPackage):
745725

746726
def check(self):
747727
if sys.platform != 'darwin':
748-
raise CheckFailed("Mac OS-X only")
728+
raise Skipped("Mac OS-X only")
749729
return super().check()
750730

751731
def get_extension(self):

0 commit comments

Comments
 (0)