Pip fallback in case of failed extension build

Hello,

I have a package that contains a small C-extension module that is used to accelerate a few functions. The C-extension functions are also implemented in pure python inside the package, if the C-extension is not available it fallbacks to the pure python code (see asammdf/mdf_v4.py at 7465baa09dc00ed79d99271bbd35e10303810f71 · danielhrisca/asammdf (github.com))

Is there a way at install time to just copy the python files even if the C-extension build fails?

If you distribute wheels, you can distribute them with the compiled extension where it works, and a pure python wheel that will be used as a fallback when there’s no platform-specific wheel available.

1 Like

The main problem comes when installing from the github development branch. This happens often when an user attempts to test a fix

If your user is installing from source, then it’s more a setuptools issue than a pip issue so I’ll let setuptools experts comment.

Not “by default”, no.

Since you’re using setuptools, it is possible for you to override the build_ext command, such that if there’s a failure, it is ignored. I’m not a 100% sure if that’s a good fit for what you want to do here.

See cmdclass in setuptools.setup and/or read Python: customize setup actions.

MarkupSafe is a good example of this automatic fallback: GitHub - pallets/markupsafe: Safely add untrusted strings to HTML/XML markup.

Thanks I will try to adapt the markupsafe solution