Skip to content

Added support for MacOSX backend for PyPy #12633

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 2 commits into from
Nov 15, 2018

Conversation

Mottl
Copy link
Contributor

@Mottl Mottl commented Oct 26, 2018

This PR adds support for MacOSX backend for PyPy and fixes an issue with the buggy/inactive/background/hidden windows in non-framework Python setups.

PR Checklist

  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)

@Mottl
Copy link
Contributor Author

Mottl commented Oct 26, 2018

I've tested on PyPy 6.0.0 (3.5.3), CPython 3.6.6 and macOS High Sierra 10.13.6
@jklymak, please review

@jklymak
Copy link
Member

jklymak commented Oct 26, 2018

OK< that's interesting - not claiming to be a mac-app expert at all.

The verify_framework() check was to verify that we are using a framework python on OSX. If we are going to allow non-framework pythons, then we can just get rid of that whole subroutine, in which case your new code would go in lazy_init().

The reason for the check was weird interactions between the REPL and the GUI, as in #665. If I don't include your new line, then I still get those errors. If I do include your new line I can't reproduce the errors noted in #665. I'm not sure if there aren't other errors, but my quick testing indicates your change works.

I'm not an expert on Mac GUIs and don't even use the macosx backend, so I'm happy to defer to others as to whether this suggested change is an issue or not. I just got involved to try and fix the backend choosing issues. If we could get rid of the framework/non-framwork issues it'd sure make our lives a lot easier.

But I suggest the change go in lazy_init() and we get rid of verify_framework if there is agreement that this is the right thing to do.

ping @jenshnielsen who is the most recent active dev who seems to grok this stuff.

@jenshnielsen
Copy link
Member

@jklymak Unfortunately I am not much more of an expert and at the moment not even a mac user. We did indeed disable it due to the issues in #665, If this makes it possible to work without being a framework build we should go for it.

@Mottl
Copy link
Contributor Author

Mottl commented Oct 26, 2018

@jklymak Unfortunately I am not much more of an expert and at the moment not even a mac user. We did indeed disable it due to the issues in #665, If this makes it possible to work without being a framework build we should go for it.

I can't reproduce loosing plot window focus (#665) on CPython 3.6 and PyPy 6.0.0 with this PR.

Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

This change nullifies the point of verify_framework (it always returns true!) so that function should be removed, and this change should be put into lazy_init.

@Mottl
Copy link
Contributor Author

Mottl commented Oct 26, 2018

Seems like we need to leave verify_framework cause this fix is only for the newer macOS (>=10.6)

@jklymak
Copy link
Member

jklymak commented Oct 26, 2018

Fair enough, but maybe only invoke verify_framework in that case...

The point being that we don't have to start the event loop as early if we don't do this until lazy_init (for OSX >= 10.6)

Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

Works great for me on my conda python and pythonw. Seem to have proper control of GUI elements etc. I think we should go w/ this change...

@Mottl
Copy link
Contributor Author

Mottl commented Oct 26, 2018

The point being that we don't have to start the event loop as early if we don't do this until lazy_init (for OSX >= 10.6)

Make sense... Done.

@jklymak
Copy link
Member

jklymak commented Oct 26, 2018

This is kind of a game-changer if we don't have to steer OS X users to the framework build all the time. Thanks a lot, I dont' really understand what the Activation Policy flags mean, so justr assumed it was the way it was because.

It would be good if someone who knows how to embed Matplotlib in a Mac GUI would write a small test GUI and make sure this doesn't break it somehow.

@Mottl
Copy link
Contributor Author

Mottl commented Oct 26, 2018

This is kind of a game-changer if we don't have to steer OS X users to the framework build all the time. Thanks a lot, I dont' really understand what the Activation Policy flags mean, so justr assumed it was the way it was because.

It just tells OS how to display the App.
From Apple Developer documentation:
https://developer.apple.com/documentation/appkit/nsapplicationactivationpolicy/nsapplicationactivationpolicyregular

From stackoverflow:
https://stackoverflow.com/questions/16125371/setactivationpolicy-to-regular-and-openwindow#20388602

If you want you can try NSApplicationActivationPolicyAccessory instead of NSApplicationActivationPolicyRegular — it works the same except it has no dock icon (which is somewhat less comfortable to me).

I'm not an Apple developer in any sense (it actually was the first time I have to look at the Objective C code). But I'm really want to make the Matplotlib working with PyPy :)

@Mottl
Copy link
Contributor Author

Mottl commented Oct 26, 2018

Tested on CPython 3.6.6 and PyPy 6.0.0 (3.5.3) both from MacPorts. Both work.

@Mottl
Copy link
Contributor Author

Mottl commented Oct 26, 2018

@jenshnielsen, please approve

@jklymak
Copy link
Member

jklymak commented Oct 28, 2018

@dopplershift or @dstansby : do either of you know of any bad interactions this might have?

@dopplershift
Copy link
Contributor

Tread very carefully here. I seem to remember once upon a time I was convinced things worked without a framework Python, but that hard check was added for a reason.

One thing I do remember was that when I wasn't using a framework build, things like closing figure windows no longer work.

@jklymak
Copy link
Member

jklymak commented Oct 29, 2018

I tested the bad behaviour I knew of

  • windows don’t respond to cmd-w
  • GUI would never accept keyboard input

And those are both OK

I’m not sure it’s the end of the world to change this. Worst case scenario folks start using the non-framework build and we get some bug reports and ask them to use the framework build. I don’t think we will actually break anyone’s code.

OTOH if anyone remembers other bad interactions we should definitely check.

@jklymak
Copy link
Member

jklymak commented Oct 29, 2018

Ping @mdehoon as you seem to have some expertise.

@tacaswell tacaswell modified the milestones: v3.0.x, v3.1 Oct 29, 2018
@tacaswell
Copy link
Member

This seems reasonable, but pushing to 3.1 (targeted for early next year).

@Mottl
Copy link
Contributor Author

Mottl commented Nov 14, 2018

@tacaswell, @jklymak, @jenshnielsen
Hi, everybody! Didn't we forget to merge it?

@jklymak
Copy link
Member

jklymak commented Nov 14, 2018

No, it needs a second review (we do two reviews to merge)...

@Mottl
Copy link
Contributor Author

Mottl commented Nov 14, 2018

Could you invite here those, that can make the second approvement?

Copy link
Contributor

@dopplershift dopplershift left a comment

Choose a reason for hiding this comment

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

Behavior both with and without a framework build of Python seem fine with this PR. The only difference I can see is the icon in the dock, otherwise they seem identical from a usage standpoint.

@dopplershift
Copy link
Contributor

For the record, that was with Python 3.6.6 (conda-forge) and MacOS 10.14.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants