@@ -256,38 +256,38 @@ def pkg_config_setup_extension(
256
256
ext .libraries .extend (default_libraries )
257
257
258
258
259
- class CheckFailed (Exception ):
259
+ class Skipped (Exception ):
260
260
"""
261
- Exception thrown when a `SetupPackage.check` method fails.
261
+ Exception thrown by `SetupPackage.check` to indicate that a package should
262
+ be skipped.
262
263
"""
263
- pass
264
264
265
265
266
266
class SetupPackage :
267
- optional = False
268
267
269
268
def check (self ):
270
269
"""
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`.
275
276
"""
276
- pass
277
277
278
278
def get_package_data (self ):
279
279
"""
280
280
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`.
283
283
"""
284
284
return {}
285
285
286
286
def get_extension (self ):
287
287
"""
288
288
Get a list of C extensions (`distutils.core.Extension`
289
289
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`.
291
291
"""
292
292
return None
293
293
@@ -297,43 +297,23 @@ def do_custom_build(self):
297
297
third-party library, before building an extension, it should
298
298
override this method.
299
299
"""
300
- pass
301
300
302
301
303
302
class OptionalPackage (SetupPackage ):
304
- optional = True
305
303
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
323
305
324
306
def check (self ):
325
307
"""
326
308
Check whether ``setup.cfg`` requests this package to be installed.
327
309
328
310
May be overridden by subclasses for additional checks.
329
311
"""
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 ):
334
314
return "installing"
335
315
else : # Configuration opt-out by user
336
- raise CheckFailed ("skipping due to configuration" )
316
+ raise Skipped ("skipping due to configuration" )
337
317
338
318
339
319
class Platform (SetupPackage ):
@@ -745,7 +725,7 @@ class BackendMacOSX(OptionalPackage):
745
725
746
726
def check (self ):
747
727
if sys .platform != 'darwin' :
748
- raise CheckFailed ("Mac OS-X only" )
728
+ raise Skipped ("Mac OS-X only" )
749
729
return super ().check ()
750
730
751
731
def get_extension (self ):
0 commit comments