[Distutils] Correct way to allow C extension building to fail?
Andrew Straw
strawman at astraw.com
Wed Jul 2 21:54:53 CEST 2008
I'm not sure if this will work, but it might:
class NotPlatformDependentDistribution(Distribution):
# Force platform-independent build.
def has_ext_modules(self):
return False
setup(
distclass = NotPlatformDependentDistribution,
)
Andreas Klöckner wrote:
> 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
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Distutils-SIG maillist - Distutils-SIG at python.org
> http://mail.python.org/mailman/listinfo/distutils-sig
More information about the Distutils-SIG
mailing list