@@ -228,38 +228,38 @@ def pkg_config_setup_extension(
228228 ext .libraries .extend (default_libraries )
229229
230230
231- class CheckFailed (Exception ):
231+ class Skipped (Exception ):
232232 """
233- Exception thrown when a `SetupPackage.check` method fails.
233+ Exception thrown by `SetupPackage.check` to indicate that a package should
234+ be skipped.
234235 """
235- pass
236236
237237
238238class SetupPackage :
239- optional = False
240239
241240 def check (self ):
242241 """
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`.
247248 """
248- pass
249249
250250 def get_package_data (self ):
251251 """
252252 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`.
255255 """
256256 return {}
257257
258258 def get_extension (self ):
259259 """
260260 Get a list of C extensions (`distutils.core.Extension`
261261 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`.
263263 """
264264 return None
265265
@@ -269,43 +269,23 @@ def do_custom_build(self):
269269 third-party library, before building an extension, it should
270270 override this method.
271271 """
272- pass
273272
274273
275274class OptionalPackage (SetupPackage ):
276- optional = True
277275 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
295277
296278 def check (self ):
297279 """
298280 Check whether ``setup.cfg`` requests this package to be installed.
299281
300282 May be overridden by subclasses for additional checks.
301283 """
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 ):
306286 return "installing"
307287 else : # Configuration opt-out by user
308- raise CheckFailed ("skipping due to configuration" )
288+ raise Skipped ("skipping due to configuration" )
309289
310290
311291class Platform (SetupPackage ):
@@ -722,7 +702,7 @@ class BackendMacOSX(OptionalPackage):
722702
723703 def check (self ):
724704 if sys .platform != 'darwin' :
725- raise CheckFailed ("Mac OS-X only" )
705+ raise Skipped ("Mac OS-X only" )
726706 return super ().check ()
727707
728708 def get_extension (self ):
0 commit comments