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

[PC4] 3.3 dependencies trigger ImportError: cannot import name events #1656

Closed
rchl opened this issue Oct 20, 2023 · 7 comments
Closed

[PC4] 3.3 dependencies trigger ImportError: cannot import name events #1656

rchl opened this issue Oct 20, 2023 · 7 comments
Labels

Comments

@rchl
Copy link
Contributor

rchl commented Oct 20, 2023

There are multiple reports in various repos (I can add links when I find them again) about lsp_utils throwing on trying to import events from package_control module.

For example here is one case: sublimelsp/LSP-ruff#38 (comment)

I saw that there was some related fix done in #1642 but it seems like some still have problems with that.

@deathaxe
Copy link
Collaborator

Any chance those having problems with it can check, they really have latest PC4.0-beta8 installed?

That's a known error of older releases.

events import used to fail for plugins which are loaded before Package Control.sublime-package. In that situation plugin host does not yet see Package Control and thus importing events into Lib\python3x\package_control.py fails.

Some action were taken to manually load that module from package file directly - bypassing ST's plugin loading mechanism.

I can't reproduce those imports to fail for any LSP-helper package, which uses lsp_utils since then on one of my test setups on Win/Linux. All those use latest Package Control.sublime-package in zipped form with all my over 100 packages installed for real world testing. Those include LSP and various helper packages.

I can't however test anything on MacOS.

To check for that issue, someone could just manipulate version number of an effected LSP-helper package while ST is closed. This triggers updater at start.

As ST's ZipImporter is used to manually load events module, I don't however see evidence for different behaviors on MacOS, than on Win/Linux.

@rchl
Copy link
Contributor Author

rchl commented Oct 21, 2023

The user in that specific issue I've linked had issue with lsp_utils dependency not being available for a while so maybe that caused bad state somehow that didn't resolve itself when dependency became available again. Just guessing.

Another user with this problem is at TerminalFi/LSP-copilot#123. As far as user's directory listing shows, the Package Control.sublime-package file has very recent updated date. That doesn't guarantee that it's the latest version but it's likely that is is.

@deathaxe
Copy link
Collaborator

With the technical reason for that issue in mind, lsp_utils could work around it by not importing the module globally, but by following https://packagecontrol.io/docs/events and import it locally in GenericClientHandler.cleanup() method. This would ensure import taking place not before all packages have been loaded.

@rchl
Copy link
Contributor Author

rchl commented Oct 21, 2023

I might do that but I feel that it would be better to address this issue first in PC4 anyway.

@deathaxe
Copy link
Collaborator

It's working on Win/Linux and I don't see what changes would needed beyond already taken actions to manually load events module.

If someone with a Mac wants to investigate and fix the importer, I'd however accept a PR.

A first step was to fix Libs\python33\package_control.py directly and once it's working changes would need to go into https://github.com/wbond/package_control/blob/four-point-oh/package_control/bootstrap.py

Note, that this module just forwards to Packages/Package Control/package_control at this point. Anything beyond that is not planned to be moved to Libs\ at this point. So moving events module or its code to Libs\ is out of scope.

@rchl
Copy link
Contributor Author

rchl commented Oct 22, 2023

I doubt it's a Mac-specific issue because it's only an issue for some Mac users and not all.

I can reproduce this issue with an old version of PC4 but not the new one.
And upgrading from beta 2 to beta 8 has correctly updated the bootstrapped lib and got rid of the issue for me.

I guess we need more info from users...

@deathaxe
Copy link
Collaborator

My hunch is that some users just installed beta2 as it is the version which was directly linked in some of my posts - stupid me.

That's also the build, which ships with a package-metadata.json with a 4.0.0-dev version, which is not updated to a 4.0.0-beta8 due to limitiations of how SemVer handles pre-releases.

All those users must either manually update once again or wait for a final release.

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

No branches or pull requests

2 participants