Skip to content

Commit

Permalink
Merge pull request #2 from johnlettman/feature/user-plugins
Browse files Browse the repository at this point in the history
Implement `ifplatform` user plugin handling method
  • Loading branch information
wonderbeyond authored Aug 20, 2023
2 parents 2b4dc56 + 82c2e79 commit 28b2fc6
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion if.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import glob
import os
import subprocess

import dotbot
from dotbot.dispatcher import Dispatcher
from dotbot.util import module
from dotbot.plugins import Clean, Create, Link, Shell


class If(dotbot.Plugin):
Expand All @@ -19,7 +23,6 @@ def handle(self, directive, data):

return self._handle_single_if(data)


def _handle_single_if(self, data):
cond = data.get('cond')

Expand All @@ -36,12 +39,25 @@ def _handle_single_if(self, data):

return self._run_internal(data['met'] if is_met else data['unmet'])

def _load_plugins(self):
plugin_paths = self._context.options().plugins
plugins = []
for dir in self._context.options().plugin_dirs:
for path in glob.glob(os.path.join(dir, '*.py')):
plugin_paths.append(path)
for path in plugin_paths:
abspath = os.path.abspath(path)
plugins.extend(module.load(abspath))
if not self._context.options().disable_built_in_plugins:
plugins.extend([Clean, Create, Link, Shell])
return plugins

def _run_internal(self, data):
dispatcher = Dispatcher(
self._context.base_directory(),
only=self._context.options().only,
skip=self._context.options().skip,
options=self._context.options(),
plugins=self._load_plugins(),
)
return dispatcher.dispatch(data)

0 comments on commit 28b2fc6

Please sign in to comment.