Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: plugins system allows __init__.py for relative imports #20

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions cutekit/plugins.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import logging
import os
import sys

from . import shell, model, const

Expand All @@ -17,6 +18,7 @@ def load(path: str):
return None

module = importlib.module_from_spec(spec)
sys.modules["plugin"] = module
spec.loader.exec_module(module)


Expand All @@ -33,11 +35,11 @@ def loadAll():

for dirname in paths:
pluginDir = os.path.join(project.dirname(), dirname, const.META_DIR, "plugins")

for files in shell.readdir(pluginDir):
if files.endswith(".py"):
plugin = load(os.path.join(pluginDir, files))

if plugin:
_logger.info(f"Loaded plugin {plugin.name}")
plugin.init()
initFile = os.path.join(pluginDir, "__init__.py")

if os.path.isfile(initFile):
load(initFile)
else:
for files in shell.readdir(pluginDir):
if files.endswith(".py"):
load(os.path.join(pluginDir, files))
Loading