ManderaGeneral / generalimport

Handle all your optional dependencies with a single call!
https://pypi.org/project/generalimport/
Apache License 2.0
15 stars 1 forks source link

Handle namespace packages #3

Closed Mandera closed 2 years ago

Mandera commented 2 years ago

Pip uninstall sometimes leaves behind empty folders which will return in namespace packages indicated by their lack of __path__. These can be imported like normal meaning our custom importer will never be asked.

Solution I'm trying is to insert an importer at index 0 of sys.meta_path and only put namespace packages there. I'm creating a function to check if a module is a namespace package, had some trouble because I forgot to remove it from sys.modules meaning it bypassed all importers

Mandera commented 2 years ago

https://github.com/ManderaGeneral/generalimport/commit/ce29a7b8479c095344d30243f6d8c524eca75d5e