diff options
| author | 2019-02-05 15:53:11 +0000 | |
|---|---|---|
| committer | 2019-02-05 15:53:11 +0000 | |
| commit | c311521a319e6252799efa76c6b2d7309eaa6604 (patch) | |
| tree | 260c5578b9169cac2a02c301ec7455e67ec53172 /src/ModuleManager.py | |
| parent | Switch to a non-deprecated method of loading files by filename (diff) | |
| signature | ||
Switch to using __init__.py as main file of directory modules, so they behave
like a package (also put the modules manually in sys.modules
Diffstat (limited to 'src/ModuleManager.py')
| -rw-r--r-- | src/ModuleManager.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/ModuleManager.py b/src/ModuleManager.py index 8dd6a465..f0cb8580 100644 --- a/src/ModuleManager.py +++ b/src/ModuleManager.py @@ -75,7 +75,7 @@ class ModuleManager(object): modules.append((ModuleType.FILE, file_module)) for directory_module in glob.glob(os.path.join( - self.directory, "*", "module.py")): + self.directory, "*", "__init__.py")): directory = os.path.dirname(directory_module) modules.append((ModuleType.DIRECTORY, directory)) return sorted(modules, key=lambda module: module[1]) @@ -94,8 +94,8 @@ class ModuleManager(object): def _load_module(self, bot: "IRCBot.Bot", name: str) -> LoadedModule: path = self._module_path(name) if os.path.isdir(path) and os.path.isfile(os.path.join( - path, "module.py")): - path = os.path.join(path, "module.py") + path, "__init__.py")): + path = os.path.join(path, "__init__.py") else: path = "%s.py" % path @@ -120,6 +120,7 @@ class ModuleManager(object): import_name = self._import_name(name) import_spec = importlib.util.spec_from_file_location(import_name, path) module = importlib.util.module_from_spec(import_spec) + sys.modules[import_name] = module import_spec.loader.exec_module(module) module_object_pointer = getattr(module, "Module", None) |
