The Wayback Machine - https://web.archive.org/web/20240106070624/https://github.com/matplotlib/matplotlib/pull/20990/
Skip to content
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

Explicit registration of canvas-specific tool subclasses. #20990

Merged
merged 1 commit into from Sep 14, 2021

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Sep 3, 2021

Don't mess up with overwriting backend_tools globals, which would fail if multiple backend modules are imported.

This proposes an API to fix #17986 (and therefore unblock #20273 (comment)). I had tried another approach back in #9941, but that PR did many more cleanups at the same time and therefore got bogged down in side discussions; this one solely implements canvas-specific tool subclass registration. That registration mechanism is private for now, but we can always consider making it public if there's demand for it. (I actually guess there would not be that much demand for third-party tool implementers because even if the tool really required some backend-specific logic, it could just use a plain old if-switch instead (https://github.com/anntzer/mplinorm/blob/dbd0b34ab4b2ad3799410565ec6ad31f992b7576/lib/mplinorm.py#L162) because a single module/package would provide the tools; the dispatch problem on Matplotlib's side mostly comes from the fact that each backend implements its own tools in its own module. The only case where this would really be necessary for third parties is for integration into a new event loop.)

(See the linked PRs and issues for more details about the problem this is solving.)

attn @fariza, I guess.

PR Summary

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@fariza
Copy link
Member

fariza commented Sep 8, 2021

@anntzer
Copy link
Contributor Author

anntzer commented Sep 8, 2021

Yes, it works.

_tool_registry = set()


def _register_tool_class(canvas_cls, tool_cls=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how to do it easily, but I still need to ask, is it possible to add test to these two functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fariza
Copy link
Member

fariza commented Sep 13, 2021

@anntzer does it need a rebase?

Don't mess up with overwriting backend_tools globals, which would fail
if multiple backend modules are imported.
@anntzer
Copy link
Contributor Author

anntzer commented Sep 14, 2021

rebased

@anntzer
Copy link
Contributor Author

anntzer commented Sep 14, 2021

Please note that the standard policy is two positive reviews before merging.

@anntzer anntzer deleted the tsr branch September 14, 2021 22:42
@fariza
Copy link
Member

fariza commented Sep 15, 2021

Sorry, I saw Github requesting only one review, and I saw this as kind of small well contained change

@tacaswell tacaswell added this to the v3.6.0 milestone Sep 16, 2021
tacaswell pushed a commit that referenced this pull request Oct 20, 2021
Explicit registration of canvas-specific tool subclasses.
This was referenced Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MEP: MEP22 tool manager
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MEP22 per-backend tool registration
3 participants