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

Allow for local, per-project plugins #35

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
35 changes: 31 additions & 4 deletions pman/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,46 @@ def _get_all_plugins():
import pkg_resources

def load_plugin(entrypoint):
plugin_class = entrypoint.load()
try:
plugin_class = entrypoint.load()
except ModuleNotFoundError:
return None
if not hasattr(plugin_class, 'name'):
plugin_class.name = entrypoint.name
return plugin_class()

return [
return [plugin for plugin in [
load_plugin(entrypoint)
for entrypoint in pkg_resources.iter_entry_points('pman.plugins')
]
] if plugin is not None]


def _get_project_plugins():
import glob
import importlib
import os
import sys

plugins = []
sys.path = [os.getcwd()] + sys.path

plugins_path = os.path.join(os.getcwd(), "plugins")
for python_file in glob.glob(plugins_path + "/*.py"):
plugin_name = os.path.splitext(os.path.basename(python_file))[0]
if plugin_name == "__init__":
continue
module = importlib.import_module("plugins." + plugin_name)
for attrib in dir(module):
if attrib.endswith("Plugin"):
project_plugin = getattr(module, attrib)()
project_plugin.name = plugin_name
plugins.append(project_plugin)

return plugins


def get_plugins(*, filter_names=None, has_attr=None):
plugins = _get_all_plugins()
plugins = _get_all_plugins() + _get_project_plugins()

def use_plugin(plugin):
return (
Expand Down