I\'m working on creating a Python module that maps API provided by a different language/framework into Python. Ideally, I would like this to be presented as a single root pa
In general, I think your approach looks fine. I wouldn't worry about it being "global", since the whole point is to specify which paths should be handled by you. Moving this test inside the import logic would just needlessly complicate it, so it's left to the implementer of the hook to decide.
Just one small concern, maybe you could use sys.path_hooks
? It appears to be a bit less "powerful" than sys.meta_path
sys.path_hooks
is a list of callables, which will be checked in sequence to determine if they can handle a given path item. The callable is called with one argument, the path item. The callable must raiseImportError
if it is unable to handle the path item, and return an importer object if it can handle the path item.