-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check which attributes have been loaded without triggering imports #51
Comments
Inspecting |
You could also just attach that dict to the function itself.
Question is, who will be looking at that. Perhap it can be done only when a debug flag is present in the environment. |
Hmm, Good point about the debug flag. I guess the bigger question is how to reliably and automatically test that accidental imports don't invalidate lazy loading. Basically I'd like something to turn red and notice if a PR triggers an import in scikit-image. |
If that's all you want to do, then you can just add a check to getattr that raises if a certain env variable is set, or if you're inside a certain context manager. |
I'm closing for now, since there's no obvious action to take. |
Could we re-open since there's your suggestion
which I'd be happy to take on some time? |
@lagru I'm getting back to this issue; could you help me understand what kind of debugging you need to do? Is it sufficient to raise on getattr? That will only catch the first instance. Would logging be better? |
Basically, I'd like to be able to test the assumption that nothing is loaded for a given import. I like your environment variable idea. What do you think about an API like this? LAZY_LOADER_RAISE_ON=".*" python -c "import skimage"
LAZY_LOADER_RAISE_ON="skimage.restoration" python -c "import skimage.restoration"
Ideally, I'd like to have an approach that could be called from within Python, but that would require a clean import slate for the current Python process. Could be done with |
Being able to check in the current console has "X" been imported would be a bonus that might help with debugging. |
Is there a mechanism to check which objects have been loaded and which ones are still in the "lazy" state? Looking through the code and inspecting the objects returned by
lazy.attach_stub
it didn't see an obvious way to do so.Maybe this could be addressed by making
attach
not return simple functions but objects. E.g.I think this would be very helpful in debugging and testing that lazy loading actually works as intended.
I'd be happy to work on this if there is interest!
The text was updated successfully, but these errors were encountered: