-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure plugins are loaded during dispatch
- Loading branch information
Showing
7 changed files
with
81 additions
and
58 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from .clean import Clean | ||
from .create import Create | ||
from .link import Link | ||
from .shell import Shell | ||
from .plugins import Plugins | ||
from .shell import Shell |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,46 @@ | ||
import os | ||
import glob | ||
import dotbot | ||
import os | ||
|
||
from ..plugin import Plugin | ||
from ..util import module | ||
|
||
|
||
class Plugins(dotbot.Plugin): | ||
''' | ||
class Plugins(Plugin): | ||
""" | ||
Load plugins from a list of paths. | ||
''' | ||
""" | ||
|
||
_directive = 'plugins' | ||
_directive = "plugins" | ||
_has_shown_override_message = False | ||
|
||
def can_handle(self, directive): | ||
return directive == self._directive | ||
|
||
def handle(self, directive, data): | ||
if directive != self._directive: | ||
raise ValueError('plugins cannot handle directive %s' % | ||
directive) | ||
raise ValueError("plugins cannot handle directive %s" % directive) | ||
return self._process_plugins(data) | ||
|
||
def _process_plugins(self, data): | ||
success = True | ||
plugin_paths = [] | ||
for item in data: | ||
self._log.lowinfo('Loading plugin from %s' % item) | ||
self._log.lowinfo("Loading plugin from %s" % item) | ||
|
||
plugin_path_globs = glob.glob(os.path.join(item, '*.py')) | ||
plugin_path_globs = glob.glob(os.path.join(item, "*.py")) | ||
if not plugin_path_globs: | ||
success = False | ||
self._log.warning('Failed to load plugin from %s' % item) | ||
self._log.warning("Failed to load plugin from %s" % item) | ||
else: | ||
for plugin_path in plugin_path_globs: | ||
plugin_paths.append(plugin_path) | ||
|
||
for plugin_path in plugin_paths: | ||
abspath = os.path.abspath(plugin_path) | ||
dotbot.util.module.load(abspath) | ||
module.load(abspath) | ||
|
||
if success: | ||
self._log.info('All commands have been executed') | ||
self._log.info("All commands have been executed") | ||
else: | ||
self._log.error('Some commands were not successfully executed') | ||
self._log.error("Some commands were not successfully executed") | ||
return success |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"""Test that a plugin can be loaded by config file. | ||
This file is copied to a location with the name "config_file.py", | ||
and is then loaded from within the `test_cli.py` code. | ||
""" | ||
|
||
import os.path | ||
|
||
import dotbot | ||
|
||
|
||
class ConfigFile(dotbot.Plugin): | ||
def can_handle(self, directive): | ||
return directive == "plugin_config_file" | ||
|
||
def handle(self, directive, data): | ||
with open(os.path.abspath(os.path.expanduser("~/flag")), "w") as file: | ||
file.write("config file plugin loading works") | ||
return True |
This file contains 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