Meson: raise FeatureNotPresent errors instead of Import errors when dependencies are not available#39412
Meson: raise FeatureNotPresent errors instead of Import errors when dependencies are not available#39412tobiasdiez wants to merge 1 commit intosagemath:developfrom
Conversation
…ependencies are not available
|
sounds like a good idea |
|
It is still possible to get |
|
Will the It's a pretty invasive change, so whether or not it's worth it ultimately depends on what is gained. For the error messages, it's not used consistently, but there is |
Currently, if a dependency of a Cython module is not available, then meson will simply ignore the Cython module. If then a user (or some other parts of sage) tries to import the Cython module, this will fail with a ModuleNotFound error. This is problematic, since there is no indication of the underlying reason (the missing dependency) why the import is not succesful.
This PR proposes to fix this by installing a small dummy python module in place of the original Cython module when the dependencies are not avaiable. This python module then raises a FeatureNotPresent error when one tries to use it.
(In the future, this error may even say what dependency is missing; but this is not yet implemented and needs a few small changes upstream in meson first.)
Instead of raising the FeatureNotPresent error directly upon import, the error is only raised once one actually tries to call the imported method or class. This is done so that the many imports in
.allare still "working" and don't raise exceptions. So in short:This added flexibilty should make it possible to react very dynamically and gracefully when dependencies are missing. This is especially important for Windows, where a bunch of dependencies are just not available (and this will also not change in the near future); see #38872 (comment).
📝 Checklist
⌛ Dependencies