@@ -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
266266class 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
303302class 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
339319class 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