[Distutils] Correct way to allow C extension building to fail?

Andreas Klöckner lists at informa.tiker.net
Wed Jul 2 20:59:25 CEST 2008


Hi there,

I'm working on a Python module (simplejson) that comes with a C extension that 
can optionally speed up some of its operations. It is however ok for this 
extension to fail to build, in which case the module will use Python 
fallbacks.

How can I allow for this failure? Bob Ippolito, the original author, has this 
implemented as follows:

8< ------------------------------------------------------
class ve_build_ext(build_ext):
    # This class allows C extension building to fail.

    def run(self):
        try:
            build_ext.run(self)
        except DistutilsPlatformError, x:
            self._unavailable(x)

    def build_extension(self, ext):
        try:
            build_ext.build_extension(self, ext)
        except (CCompilerError, DistutilsExecError), x:
           self._unavailable(x)

    def _unavailable(self, exc):
         print '*'*70
         print BUILD_EXT_WARNING
         print exc
         print '*'*70

...

   setup(cmdclass={'build_ext': ve_build_ext},)
8< ------------------------------------------------------

On current setuptools, this fails with

** error: Setup script exited with error: can't 
copy 'simplejson.egg-info\native_libs.txt': doesn't exist or not a regular 
file

How can I fix this?

Andreas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.python.org/pipermail/distutils-sig/attachments/20080702/82e1718a/attachment.pgp>


More information about the Distutils-SIG mailing list