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

Fix dispatcher when no plugins are given #332

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion dotbot/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ def __init__(
):
self._log = Messenger()
self._setup_context(base_directory, options)
plugins = plugins or []
if plugins == None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please always use identity, not equality, comparisons with None:

Suggested change
if plugins == None:
if plugins is None:

plugins = Plugin.__subclasses__()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will circumvent the configuration option --disable-built-in-plugins. It will re-enable plugins that the user may have requested be disabled.

else:
plugins = plugins or []
self._plugins = [plugin(self._context) for plugin in plugins]
self._only = only
self._skip = skip
Expand Down
17 changes: 17 additions & 0 deletions tests/dotbot_plugin_dispatch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Test that a plugin can call dispatcher for subtasks.

The plugin calls dispatch with his data.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The plugin calls dispatch with his data.
The plugin calls dispatch with its data.

"""

import os.path

import dotbot


class Dispatch(dotbot.Plugin):
def can_handle(self, directive):
return directive == "dispatch"

def handle(self, directive, data):
dispatcher = dotbot.dispatcher.Dispatcher(self._context.base_directory())
return dispatcher.dispatch(data)
22 changes: 22 additions & 0 deletions tests/test_dispatcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os
import shutil

import pytest


def test_plugin_dispatcher(capfd, home, dotfiles, run_dotbot):
"""Verify that plugins can call dispatcher without explicitly specifying plugins."""

dotfiles.makedirs("plugins")
plugin_file = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "dotbot_plugin_dispatch.py"
)
shutil.copy(plugin_file, os.path.join(dotfiles.directory, "plugins", "dispatch.py"))
dotfiles.write_config(
[
{"dispatch": [{"create": ["~/a"]}]},
]
)
run_dotbot("--plugin-dir", os.path.join(dotfiles.directory, "plugins"))

assert os.path.exists(os.path.join(home, "a"))