Title: [MNT]: Cleanup internal import dependencies and initialization logic · Issue #29813 · matplotlib/matplotlib · GitHub
Open Graph Title: [MNT]: Cleanup internal import dependencies and initialization logic · Issue #29813 · matplotlib/matplotlib
X Title: [MNT]: Cleanup internal import dependencies and initialization logic · Issue #29813 · matplotlib/matplotlib
Description: Summary There's a delicate dependency on who goes first in the import order because we couple module dependencies (imports) and intialization (code execution at import). See e.g. #29808 (comment) Proposed fix I think we can make this sim...
Open Graph Description: Summary There's a delicate dependency on who goes first in the import order because we couple module dependencies (imports) and intialization (code execution at import). See e.g. #29808 (comment) P...
X Description: Summary There's a delicate dependency on who goes first in the import order because we couple module dependencies (imports) and intialization (code execution at import). See e.g. #29808 (commen...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/29813
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[MNT]: Cleanup internal import dependencies and initialization logic","articleBody":"### Summary\n\nThere's a delicate dependency on who goes first in the import order because we couple module dependencies (imports) and intialization (code execution at import).\n\nSee e.g. https://github.com/matplotlib/matplotlib/pull/29808#discussion_r2013917048\n\n### Proposed fix\n\nI think we can make this simpler by applying the following rules\n\n- no submodule is allowed to run intialization code (e.g. loading the colormaps) as part of their import\n- initialization should be lazy if possible\n- if lazy initialization is not possible, the initalization code must be placed in a `_mpl_init()` function in that module. ( (e.g. it's tricky for colormaps because the colormaps are injected as globals into the cm module)\n- only the top-level `matplotlib` module is allowed to call `._mpl_init()` of the submodules.\n\nThis way, we can decouple initialization from import and have one central place that orchestrates the initialization.\n\nWhat do you think?","author":{"url":"https://github.com/timhoffm","@type":"Person","name":"timhoffm"},"datePublished":"2025-03-26T23:35:03.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/29813/matplotlib/issues/29813"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:20dc14d4-1d77-d9dc-0d12-0fcff2349dc3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C324:2FB335:188740C:20BED8F:6A52C511 |
| html-safe-nonce | 6a7e07365c01cae38c54cdc3c26b622694d699f2dfe26621141b4f5b2c6e0900 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMzI0OjJGQjMzNToxODg3NDBDOjIwQkVEOEY6NkE1MkM1MTEiLCJ2aXNpdG9yX2lkIjoiMjUwODA1ODYxODI3ODEwMjI4OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 23a5e1669fd71ca93b9610f7a17e1fb9307d2d9d75295b869bb29d7c0640b81d |
| hovercard-subject-tag | issue:2950994613 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/29813/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8d456bef343897b0da2e5a42ab73a107617eaee70e34d0f21b763ff23f1d9bb4/matplotlib/matplotlib/issues/29813 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8d456bef343897b0da2e5a42ab73a107617eaee70e34d0f21b763ff23f1d9bb4/matplotlib/matplotlib/issues/29813 |
| og:image:alt | Summary There's a delicate dependency on who goes first in the import order because we couple module dependencies (imports) and intialization (code execution at import). See e.g. #29808 (comment) P... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | timhoffm |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width