Closed rgommers closed 1 year ago
Pythran should behave correctly is scipy is not importable - that's a bug. We should just skip trying to model scipy.special builtins if they are not importable.
Mmmh looks like we already have a try-except catch here, but it doesn't catch the expected exception...
I don't think any try-except will do the right thing unfortunately, since import scipy
will hit an import hook from the importlib
machinery (https://github.com/mesonbuild/meson-python/blob/main/mesonpy/_editable.py#L297) and that will not be happy. I really need to avoid calling import scipy
during the build of scipy itself. Supporting editable (in-place) builds with an out-of-place build system is inherently a little obscure unfortunate.
That said, I've seen Cython crash before with Pythran installed but not requested for use, so the problem isn't limited to SciPy's editable builds. Calling this much code on a plain import pythran
is not very robust - an import cycle is bad even within a try-except.
oh, thanks for explaining. I'm convinced and as you offered to provide a PR for lazy loading, I cannot say no ;-)
Thanks! I'll work on this soon.
@rgommers : the definition of soon as expired :-) Do you want me to give it a try?
Sorry, it took me way longer than expected to finally finish the build system stuff for Python 3.12 - we only got a numpy beta release out yesterday.
I should still be able to do this, but probably not this week - if you're in a hurry maybe you want to give it a try?
I'm definitively in a hurry, and if you're not either, let's take our time :-)
@rgommers I'll do a release once you've fixed this one, that should help with main
numpy / scipy builds
Thanks. I'll have a go at this today.
We're hitting a recursive import error when building SciPy twice with
pip install -e . --no-build-isolation
. The error happens only for editable installs of SciPy, however the recursion is also there with normal builds. The SciPy build has to do:in its build script to obtain Pythran's include directory. However, that import statement basically pulls in all of the Pythran code base, and this errors out at:
What is happening there is that that code fails when
module_name
equals'scipy.special'
, creating an import loop.Full traceback (from https://github.com/scipy/scipy/issues/18900):
To make matters worse, it's not so easy to work around it, because disabling pythran in the scipy build is not helping - Cython contains an
import pythan
statement too in a try-except loop.My suggested solution here is to make the imports in
pythran/__init__.py
lazy via the use of__getattr__
. That will solve both of the above issues at once, and I suspect it may also help with robustness for Cython in general (it only accessespythran.__version__
if--np-pythran
isn't explicitly used). If that sounds fine to you @serge-sans-paille, then I'd be happy to submit a PR.