8000 Drop pgi support for the GTK3 backend by lazka · Pull Request #13014 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Drop pgi support for the GTK3 backend #13014

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

Merged
merged 1 commit into from
Dec 23, 2018

Conversation

lazka
Copy link
Contributor
@lazka lazka commented Dec 18, 2018

PR Summary

It's incomplete and unmaintained and PyGObject is pip installable now
and supports Ubuntu xenial which is used on travis-ci.

matplotlib should preferably test with things that are actually used by end users.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@@ -11,8 +11,7 @@

import numpy as np

# cairocffi is more widely compatible than pycairo (in particular pgi only
# works with cairocffi) so try it first.
# cairocffi is more widely compatible than pycairo so try it first.
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps it makes sense to prefer pycairo now? (as pygobject will go through pycairo regardless).
In fact, does pygobject even work (in this use case) without pycairo?

Copy link
Contributor Author
@lazka lazka Dec 18, 2018

Choose a reason for hiding this comment

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

I saw that there is code to convert pycairo objects to cairocffi ones for some fastpath implementations, so I assumed it is still preferred.

If there is anything I can do in pycairo to make it the preferred one I'm happy to help.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact, does pygobject even work (in this use case) without pycairo?

No, it can be build without pycairo but then any function using cairo types will not work.

Copy link
Contributor

Choose a reason for hiding this comment

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

Which means in particular on_draw_event (connected to the "draw" event), no?
IOW, can we just assume that gtk3 is built with cairo support and that cairo is a dependency, and error out early if not?

I don't think keeping the cairocffi optional dependency just for the sake of a not-even-twofold speedup is worth it (but if you want to make expose something similar in pycairo's side what would be needed is a way to create a cairo Path from a list of cairo_path_data_t (or better, from a buffer (in the memoryview sense), so that no copy at all is done). (Effectively, this runs afoul of the last paragraph of https://cairographics.org/manual/bindings-path.html ("You should not present an API for mutating or for creating new cairo_path_t objects. In the future, these guidelines may be extended to present an API for creating a cairo_path_t from scratch for use with cairo_append_path() but the current expectation is that cairo_append_path() will mostly be used with paths from cairo_copy_path()."), but performance wise it does make some difference.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which means in particular on_draw_event (connected to the "draw" event), no?

yeah

IOW, can we just assume that gtk3 is built with cairo support and that cairo is a dependency, and error out early if not?

We have https://pygobject.readthedocs.io/en/latest/guide/api/api.html?highlight=require_foreign#gi.require_foreign to check for this.

I don't think keeping the cairocffi optional dependency just for the sake of a not-even-twofold speedup is worth it [...]

Thanks, I'll have a look.


Either way I think any changes to the cairo part should be another PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

It was originally done to support py3 but I guess yeah I don't know the situation with pypy right now either, @lazka?

Copy link
Contributor Author
@lazka lazka Dec 18, 2018

Choose a reason for hiding this comment

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

It was originally done to support py3

Yeah, the pycairo in Ubuntu 16.04 for example (the distro provided package) is lacking various API compared to the Python 2 version, and also has a few bugs/crashers.

I don't know the situation with pypy right now either,

PyGObject and Pycairo do work with PyPy now: https://lazka.github.io/posts/2018-04_pypy-pygobject/index.html but pycairo is probably slower than cairocffi with PyPy.

Copy link
Contributor

Choose a reason for hiding this comment

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

xenial has pycairo 1.10 but we require 1.11 indeed.

Copy link
Contributor Author
@lazka lazka Dec 20, 2018

Choose a reason for hiding this comment

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

@anntzer if I just take the code in _append_paths_fast() that computes codes/vertices and loop over them and call the path functions I get the same FPS boost as with the buffer passing approach (unless I'm missing something). So I think the whole cairo_path_data_t thing is not needed and the fast path would also works with pycairo as is.

(tested with wire3d_animation_sgskip)

Copy link
Contributor Author
@lazka lazka Dec 20, 2018

Choose a reason for hiding this comment

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

ah, the "fast path" cleans up the path first, so they aren't doing the same thing. The main speedup comes from removing the curve segments. So assuming that shortcut is OK this would be faster than the current fast path for both libraries: (turned out to be wrong, see my PRs)

# Mapping from Matplotlib Path codes to cairo path functions.
_MPL_TO_CAIRO_PATH_TYPE = [lambda ctx, *args: None] * (Path.CLOSEPOLY + 1)
_MPL_TO_CAIRO_PATH_TYPE[Path.MOVETO] = cairo.Context.move_to
_MPL_TO_CAIRO_PATH_TYPE[Path.LINETO] = cairo.Context.line_to
_MPL_TO_CAIRO_PATH_TYPE[Path.CLOSEPOLY] = \
    lambda ctx, *args: cairo.Context.close_path(ctx)

def _append_path(ctx, path, transform, clip=None):
    cleaned = path.cleaned(transform, remove_nans=True, clip=clip)
    for points, code in zip(cleaned.vertices, cleaned.codes):
        _MPL_TO_CAIRO_PATH_TYPE[code](ctx, *points)

@anntzer
Copy link
Contributor
anntzer commented Dec 18, 2018

A note in the changelog would be nice.

@tacaswell tacaswell added this to the v3.1 milestone Dec 18, 2018
@lazka
Copy link
Contributor Author
lazka commented Dec 18, 2018

@anntzer do you mean in doc/users/next_whats_new? Or somewhere else?

@tacaswell
Copy link
Member

I would put it in https://github.com/matplotlib/matplotlib/tree/master/doc/api/next_api_changes as dropping support for pgi is an API change (but hopefully one that impacts 0 users!).

@lazka
< 10000 div class="ml-n3 timeline-comment unminimized-comment comment previewable-edit js-task-list-container js-comment timeline-comment--caret" data-body-version="8cef4f0573b16811ddd765f09a3b27ec3a59fc4e816d1f31869a69c59b203b23">
Copy link
Contributor Author
lazka commented Dec 19, 2018

I would put it in https://github.com/matplotlib/matplotlib/tree/master/doc/api/next_api_changes as dropping support for pgi is an API change (but hopefully one that impacts 0 users!).

done

.travis.yml Outdated
echo 'pgi is available' ||
echo 'pgi is not available'
python -mpip install --upgrade pycairo cairocffi>=0.8
python -mpip install --upgrade PyGObject==3.30.4 &&
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason PyGObject is pinned to this specific version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just the latest stable release to keep the CI environment stable and in case PyGObject drops Ubuntu 16.04 support, even though there are no plans to do so right now.

I can remove it if you want.

Copy link
Member

Choose a reason for hiding this comment

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

Not quite sure on our version policy for CI. Keeping it stable and always testing the mos recent one both have their benefits. Nevertheless, I would go with the most recent.

@tacaswell Do you have an opinion on version pinning here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed the pinning now.

Copy link
Member

Choose a reason for hiding this comment

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

a belated 👍 to removing the pinning. Would rather deal with broken CI than finding out after things are released.

It's incomplete and unmaintained and PyGObject is pip installable now
and supports Ubuntu Xenial which is used on Travis-CI.

matplotlib should preferably test with things that are actually used by end users.
@timhoffm timhoffm merged commit 3221c94 into matplotlib:master Dec 23, 2018
@timhoffm
Copy link
Member
timhoffm commented Dec 23, 2018

Thanks, and congratulations on your first contribution to Matplotlib!

Usually, I‘d say: Hope to see you back some time. But I know, you‘ve already some quite good PRs in the pipeline. So I‘m quite sure about that 😃 .

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.

4 participants
0