Fix/import without plotnine - #547
Open
Wegatriespython wants to merge 3 commits into
Open
Conversation
plotnine is provided by the "report" extra, but .types is reached on import of message_ix_models. Its only use of ggplot is the annotation on PlotAddable.__radd__.
message_ix_models/__init__.py creates a Context, which populates Context.report by importing .report.Config. That ran .report/__init__.py and .report.config._default_callbacks(), both of which imported .report.plot and so required plotnine, from the "report" extra. Resolve add_plots through a module __getattr__, and call .report.plot.callback through a wrapper that imports it when the reporter is prepared.
Wegatriespython
force-pushed
the
fix/import-without-plotnine
branch
from
August 21, 2026 11:38
34d9869 to
ac06785
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #547 +/- ##
=====================================
Coverage 74.3% 74.3%
=====================================
Files 323 323
Lines 25850 25855 +5
=====================================
+ Hits 19207 19212 +5
Misses 6643 6643
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses the
plotnineimport failure from themessage-ix-modelshalf of #540, and addresses #323 as well.message_ix_models/report/plot.pyneeds plotnine at import time. This PR makes its eager imports lazy. There are two such sites:the
add_plotsre-export inreport/__init__.py, now resolved through a module__getattr__, and the third default callback inreport/config.py, now a wrapper that imports.report.plotwhen the callback runs instead of whenConfigis constructed.types.pyimportedggplotsolely to annotatePlotAddable.__radd__, so that import moves underTYPE_CHECKINGHow to review
Read the diff, check CI passes. Try local plain install of this branch once
ixmpis pointed at iiasa/ixmp#640PR checklist
- [ ] Add or expand tests; coverage checks both ✅CI side change required if any.- [ ] Add, expand, or update documentation.