-
-
Notifications
You must be signed in to change notification settings - Fork 781
implement Lazy Loading for Cocoa core imports #3599
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
base: main
Are you sure you want to change the base?
Conversation
I'm not sure if you're aware of how to run the testbed on your own machine, but there are instructions here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My two cents is that the tests_backend
stuff aren't being run as tests -- they just support the test files in the tests directory in the testbed, so this file isn't been ran at all. Not sure if this is right, but I think you'd need to generalize this to not write toga_cocoa
but to work out a name to change the tested import depending on backend in the testbed tests directory, and then skip the test on everything besides Cocoa for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My immediate impression is that I don't think this PR is doing what you think it is doing.
The giveaway is that the toga_cocoa/__init__.py
module is importing everything from factory. At present, import toga_cocoa
doesn't import all the parts of the factory module into the toga_cocoa
namespace. So - this PR adds a bunch of lazy symbols to the toga_cocoa
namespace... where they will never be used.
If we're going to use lazy loading on backends, it needs to be on the factory
module itself. That's the API that toga-core
uses to load platform implementations (see all the impl = factory.WidgetName()
calls in toga-core
.
Also - as @johnzhou721 has noted, the test_import
that you've added won't ever be executed. That said - if the lazy import is done right, it won't need any additional tests - because the existing codebase is testing every valid import. All this change would do is modify how that import is implemented, making it (hopefully) faster.
Agreed. But I think we should have an explicict test about failed imports. Cocoa has now achieved 100% functionality coverage, so there's no |
Sure - but that's more of a "filling a testing gap that is currently hidden", rather than anything directly related to this PR. I've added #3632 to track this as an idea. |
Wow... didn't realize it wasn't covered now!!! My eyes tend to ignore gray things (comments in Xcode as I don't even have a proper IDE just random apps that happens to open Python files), I guess. |
As we discussed in the toga-core lazy import PR, we should still have a test if possible, otherwise it would be easy to reintroduce an eager import by accident and not notice for years. The same approach can be used in this PR. |
Fixes (partly) #2547
PR Checklist: