-
Notifications
You must be signed in to change notification settings - Fork 18
Lazy-load top-level imports and defer setup #439
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
base: main
Are you sure you want to change the base?
Conversation
|
This change set reworks ultraplot’s import path to be lazy by default: |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Refactored the lazy loading mechanism in ultraplot/__init__.py to be automated and convention-based. This simplifies the process of adding new modules and makes the system more maintainable. Fixed a documentation build error caused by the previous lazy loading implementation. Added documentation for the new lazy loading system in docs/lazy_loading.rst.
b0a06d5 to
8120900
Compare
|
In my effors I made the situation worse -- putting this to draft temporarily. |
8120900 to
ebb37ab
Compare
beckermr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is very very complex. Is there a simpler way to do this?
|
|
||
| .. _contrib_lazy_loading: | ||
|
|
||
| Lazy Loading and Adding New Modules |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This documentation appears to be wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure I follow -- could you clarify what is wrong?
| "rc": "ultraplot.axes.base", | ||
| } | ||
|
|
||
| def __missing__(self, key): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this method called?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is called when a key is missing and attempts to lazy load it
There are simpler ways to do this, but they’re either less future‑proof or they change the public API. UltraPlot currently pulls many internal modules into the top level, and those imports drag in heavy dependencies, which stack up in import time. This PR keeps the API unchanged while making imports lazy. It (a) auto‑discovers new modules as the package evolves and (b) defers internal/external imports until they’re actually accessed, rather than at import time. I did try to untangle the eager imports, but they’re too intertwined to cleanly separate. The alternatives are either (a) drop top‑level symbols, which would break user expectations (e.g., Proposed review route: start with |
This PR rewires ultraplot’s import path to lazy‑load modules/registries and defer setup/registration work until first access, moves docstring snippet setup into
ultraplot.internals.docstringwith lazy snippet resolution, and defers optional dependency imports (IPython/pyplot/cartopy/basemap) while preserving the public API.Import time report (python -X importtime -c "import ultraplot", Python 3.13.11):
Top ultraplot modules (before):
Top external modules (before):
Top ultraplot modules (after):
Top external modules (after):
Closes #395