@@ -228,38 +228,38 @@ def pkg_config_setup_extension(
228
228
ext .libraries .extend (default_libraries )
229
229
230
230
231
- class CheckFailed (Exception ):
231
+ class Skipped (Exception ):
232
232
"""
233
- Exception thrown when a `SetupPackage.check` method fails.
233
+ Exception thrown by `SetupPackage.check` to indicate that a package should
234
+ be skipped.
234
235
"""
235
- pass
236
236
237
237
238
238
class SetupPackage :
239
- optional = False
240
239
241
240
def check (self ):
242
241
"""
243
- Checks whether the build dependencies are met. Should raise a
244
- `CheckFailed` exception if the dependency could not be met, otherwise
245
- return a string indicating a version number or some other message
246
- indicating what was found.
242
+ If the package should be installed, return an informative string, or
243
+ None if no information should be displayed at all.
244
+
245
+ If the package should be skipped, raise a `Skipped` exception.
246
+
247
+ If a missing build dependency is fatal, call `sys.exit`.
247
248
"""
248
- pass
249
249
250
250
def get_package_data (self ):
251
251
"""
252
252
Get a package data dictionary to add to the configuration.
253
- These are merged into to the ` package_data` list passed to
254
- `distutils .setup`.
253
+ These are merged into to the * package_data* list passed to
254
+ `setuptools .setup`.
255
255
"""
256
256
return {}
257
257
258
258
def get_extension (self ):
259
259
"""
260
260
Get a list of C extensions (`distutils.core.Extension`
261
261
objects) to add to the configuration. These are added to the
262
- ` extensions` list passed to `distutils .setup`.
262
+ * extensions* list passed to `setuptools .setup`.
263
263
"""
264
264
return None
265
265
@@ -269,43 +269,23 @@ def do_custom_build(self):
269
269
third-party library, before building an extension, it should
270
270
override this method.
271
271
"""
272
- pass
273
272
274
273
275
274
class OptionalPackage (SetupPackage ):
276
- optional = True
277
275
config_category = "packages"
278
- default_config = "auto"
279
-
280
- @classmethod
281
- def get_config (cls ):
282
- """
283
- Look at `setup.cfg` and return one of ["auto", True, False] indicating
284
- if the package is at default state ("auto"), forced by the user (case
285
- insensitively defined as 1, true, yes, on for True) or opted-out (case
286
- insensitively defined as 0, false, no, off for False).
287
- """
288
- conf = cls .default_config
289
- if config .has_option (cls .config_category , cls .name ):
290
- try :
291
- conf = config .getboolean (cls .config_category , cls .name )
292
- except ValueError :
293
- conf = config .get (cls .config_category , cls .name )
294
- return conf
276
+ default_config = True
295
277
296
278
def check (self ):
297
279
"""
298
280
Check whether ``setup.cfg`` requests this package to be installed.
299
281
300
282
May be overridden by subclasses for additional checks.
301
283
"""
302
- conf = self .get_config () # Check configuration file
303
- if conf in [True , 'auto' ]: # Default "auto", or install forced by user
304
- if conf is True : # Set non-optional if user sets `True` in config
305
- self .optional = False
284
+ if config .getboolean (self .config_category , self .name ,
285
+ fallback = self .default_config ):
306
286
return "installing"
307
287
else : # Configuration opt-out by user
308
- raise CheckFailed ("skipping due to configuration" )
288
+ raise Skipped ("skipping due to configuration" )
309
289
310
290
311
291
class Platform (SetupPackage ):
@@ -722,7 +702,7 @@ class BackendMacOSX(OptionalPackage):
722
702
723
703
def check (self ):
724
704
if sys .platform != 'darwin' :
725
- raise CheckFailed ("Mac OS-X only" )
705
+ raise Skipped ("Mac OS-X only" )
726
706
return super ().check ()
727
707
728
708
def get_extension (self ):
0 commit comments