Created
June 22, 2013 15:45
-
-
Save ionelmc/5841339 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| import os | |
| import imp | |
| class OverlayImporter(object): | |
| def __init__(self, path): | |
| self.path = path | |
| def find_module(self, name, _path=None): | |
| names = name.split('.') | |
| try: | |
| file, filename, description = imp.find_module( | |
| names[-1], | |
| [os.path.join(self.path, *names[:-1])] | |
| ) | |
| suffix, mode, type_ = description | |
| if type_ == imp.PKG_DIRECTORY: | |
| return | |
| return OverlayLoader(file, filename, description) | |
| except ImportError: | |
| return | |
| class OverlayLoader(object): | |
| def __init__(self, file, filename, description): | |
| self.file = file | |
| self.filename = filename | |
| self.description = description | |
| def load_module(self, name): | |
| mod = imp.load_module(name, self.file, self.filename, self.description) | |
| if self.file: | |
| self.file.close() | |
| return mod | |
| sys.path.append(os.path.abspath('normal')) | |
| sys.meta_path.append(OverlayImporter(os.path.abspath('overlay'))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment