Skip to content

Instantly share code, notes, and snippets.

@gdugas
Last active May 27, 2016 12:55
Show Gist options
  • Save gdugas/46f18710a5fd43898d2f5ad843543fac to your computer and use it in GitHub Desktop.
Save gdugas/46f18710a5fd43898d2f5ad843543fac to your computer and use it in GitHub Desktop.
from importlib.machinery import PathFinder
import os
import sys
class PrefixedPathFinder:
pathes = {
"modload.plugins" : os.path.join(os.path.abspath(os.path.dirname(__file__)))
}
@classmethod
def find_spec(cls, name, import_path, target=None):
for prefix in cls.pathes:
if name.startswith(prefix):
print(name)
if name == prefix:
import_path = [cls.pathes[prefix]]
return PathFinder.find_spec(name, import_path, target=target)
return None
sys.meta_path.append(PrefixedPathFinder)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment