Commit 462eb4aa authored by adam j hartz's avatar adam j hartz

lay some groundwork for plugins

parent c9f004d9
# This file is part of tako
# Copyright (c) 2015-2017 Adam Hartz <> and contributors
# This program is free software: you can redistribute it and/or modify it under
# the terms of the Soopycat License, version 2.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the Soopycat License for more details.
# You should have received a copy of the Soopycat License along with this
# program. If not, see <>.
# tako is a fork of xonsh (
# xonsh is Copyright (c) 2015-2016 the xonsh developers and is licensed under
# the 2-Clause BSD license.
class PluginEnv(dict):
def __init__(self, *args, parent=None, **kwargs):
dict.__init__(self, *args, **kwargs)
self.parent = parent
def __getitem__(self, key):
if dict.__contains__(self, key):
return dict.__getitem__(self, key)
if self.parent is None:
raise KeyError
return self.parent[key]
def __contains__(self, key):
if dict.__contains__(self, key):
return True
return self.parent.__contains__(self, key)
......@@ -131,6 +131,7 @@ defaults = {
'SHELL_TYPE': 'readline',
'PLUGINS': {},
defaults['HISTORY_FILE'] = os.path.join(defaults['DATA_DIR'], 'history')
......@@ -18,8 +18,14 @@
# -*- coding: utf-8 -*-
"""The tako shell"""
from takoshell.environ import takorc_context
import os
import builtins
from import display_error_message
from takoshell.execer import Execer
from takoshell.plugins import PluginEnv
from takoshell.environ import takorc_context
from takoshell.settings import Settings
class Shell(object):
......@@ -46,6 +52,8 @@ class Shell(object):
kwargs.get('scriptcache', True),
kwargs.get('cacheall', False))
if not self.headless:
def __getattr__(self, attr):
"""Delegates calls to appropriate shell instance."""
......@@ -71,3 +79,26 @@ class Shell(object):
from takoshell.base_shell import BaseShell as shell_class = shell_class(execer=self.execer,
ctx=self.ctx, **self.kwargs)
def _init_plugins(self, ctx):
env = builtins.__tako_env__
settings = env['TAKO_SETTINGS']
plugin_dir = os.path.join(settings.config_dir, 'plugins')
if not os.path.isdir(plugin_dir):
all_plugins = os.listdir(plugin_dir)
for p in all_plugins:
if not p.endswith('.tako'):
name = p.rsplit('.', 1)[0]
full_path = os.path.join(plugin_dir, p)
if not os.path.isfile(full_path):
env_contents = {'PLUGIN_SETTINGS': Settings({'ALIASES': {}})}
new_env = PluginEnv(env_contents, parent=ctx)
self.execer.exec(open(full_path).read(), glbs=new_env)
settings.plugins[name] = new_env
print('Error loading plugin %s' % name)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment