wbond / package_control

The Sublime Text package manager
https://packagecontrol.io
4.79k stars 815 forks source link

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

Closed rchl closed 10 months ago

rchl commented 11 months ago

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: https://github.com/sublimelsp/LSP-ruff/issues/38#issuecomment-1766392360

I saw that there was some related fix done in https://github.com/wbond/package_control/issues/1642 but it seems like some still have problems with that.

deathaxe commented 11 months ago

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 commented 11 months ago

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 https://github.com/TerminalFi/LSP-copilot/issues/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 commented 11 months ago

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 commented 11 months ago

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

deathaxe commented 11 months ago

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/packagecontrol 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 commented 11 months ago

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 commented 11 months ago

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.