Skip to content

Fix/import without plotnine - #547

Open
Wegatriespython wants to merge 3 commits into
mainfrom
fix/import-without-plotnine
Open

Fix/import without plotnine#547
Wegatriespython wants to merge 3 commits into
mainfrom
fix/import-without-plotnine

Conversation

@Wegatriespython

@Wegatriespython Wegatriespython commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

This PR addresses the plotnine import failure from the message-ix-models half of #540, and addresses #323 as well.

message_ix_models/report/plot.py needs plotnine at import time. This PR makes its eager imports lazy. There are two such sites:
the add_plots re-export in report/__init__.py, now resolved through a module __getattr__, and the third default callback in report/config.py, now a wrapper that imports .report.plot when the callback runs instead of when Config is constructed.

types.py imported ggplot solely to annotate PlotAddable.__radd__, so that import moves under TYPE_CHECKING

How to review

Read the diff, check CI passes. Try local plain install of this branch once ixmp is pointed at iiasa/ixmp#640

PR checklist

  • Continuous integration checks all ✅

- [ ] Add or expand tests; coverage checks both ✅ CI side change required if any.
- [ ] Add, expand, or update documentation.

  • Update doc/whatsnew.

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.
@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.3%. Comparing base (4f24a7e) to head (ac06785).

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           
Files with missing lines Coverage Δ
message_ix_models/report/__init__.py 87.8% <100.0%> (+0.3%) ⬆️
message_ix_models/report/config.py 100.0% <100.0%> (ø)
message_ix_models/types.py 87.5% <100.0%> (-0.5%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Wegatriespython
Wegatriespython requested a review from khaeru August 21, 2026 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant