Ejemplo n.º 1
0
 def load(env):
     msg = '..loading SmaSh user-config from: {0}'
     msg = msg.format(USER_CONFIG_PATH)
     smash_log.debug(msg)
     sandbox = env.copy()
     sandbox.update(__file__=USER_CONFIG_PATH)
     execfile(USER_CONFIG_PATH, sandbox)
     return sandbox
Ejemplo n.º 2
0
 def get_prompt(self):
     prompt = '\n'
     for component in self.prompt_components:
         smash_log.debug("calling prompt component: " + str(component))
         assert callable(component), str(
             "bad prompt component: " + str(component))
         prompt += component()
     prompt = prompt.replace('  ', ' ')
     return prompt
Ejemplo n.º 3
0
    def _activate(self, path):
        absfpath = abspath(expanduser(path))
        self.publish(C_PRE_ACTIVATE, name=absfpath)
        if True:
            vbin = to_vbin(absfpath)
            vlib = to_vlib(absfpath)

            # compute e.g. <venv>/lib/python2.6.
            # we call bullshit if they have a more than one dir;
            # it might be a chroot but i dont think it's a venv
            python_dir = glob.glob(opj(vlib, 'python*/'))
            if len(python_dir) == 0:
                raise RuntimeError('no python dir in {0}'.format(vlib))
            if len(python_dir) > 1:
                err = "multiple python dirs matching in {0}".format(vlib)
                raise RuntimeError(err)
            python_dir = python_dir[0]

            # this bit might enable switching between two venv's
            # that are be "no-global-site" vs "use-global-site"
            # .. tabling it for now
            # site_file = opj(python_dir, 'site.py')
            # assert ope(site_file)
            # tmp = dict(__file__=site_file)
            # execfile(site_file, tmp)
            #  tmp['main']()

            # some environment variable manipulation that would
            # normally be done by 'source bin/activate', but is
            # not handled by activate_this.py
            #path = get_path().split(':')
            os.environ['VIRTUAL_ENV'] = absfpath

            sandbox = dict(__file__=opj(vbin, 'activate_this.py'))
            execfile(opj(vbin, 'activate_this.py'), sandbox)
            self.reset_path = sandbox['prev_sys_path']

            # libraries like 'datetime' can very occasionally fail on import
            # if this isnt done, and i'm not sure why activate_this.py doesnt
            # accomplish it.  it might have something to do with venv's using
            # mixed pythons (different versions) or mixed --no-site-packages
            # tabling it for now
            # dynload = opj(python_dir, 'lib-dynload')
            # sys.path.append(dynload)

            # NB: this rehash will update bins but iirc kills aliases!
            msg = '$PATH was adjusted to {0}'.format(os.environ['PATH'])
            smash_log.debug(msg)
            self.report('Adjusting $PATH')
            msg = 'rehashing aliases'
            smash_log.info(msg)
            self.shell.magic('rehashx')
            self.publish(C_POST_ACTIVATE, absfpath)
Ejemplo n.º 4
0
    def deactivate(self):
        try:
            venv = get_venv()
        except KeyError:
            self.warning("no venv to deactivate")
            return False
        else:
            if not venv:
                return False
            self.report("venv_deactivate: " + venv)
            self.publish(C_PRE_DEACTIVATE, venv)

            if not ope(venv):
                self.warning('refusing to deactivate (relocated?) venv')
                return  # raise RuntimeError(err)

            del os.environ['VIRTUAL_ENV']
            path = get_path()
            path = path.split(':')

            # clean $PATH according to bash..
            # TODO: also rehash?
            vbin = to_vbin(venv)
            if vbin in path:
                msg = 'removing old venv bin from PATH: ' + \
                      summarize_fpath(str(vbin))
                self.report(msg)
                path.remove(vbin)
                os.environ['PATH'] = ':'.join(path)

            # clean sys.path according to python..
            # stupid, but this seems to work
            msg = 'clean sys.path'  # ,sys.path_changes)
            self.report(msg)
            smash_log.info(msg)
            reset_path = getattr(self, 'reset_path', None)
            if reset_path is not None:
                msg = str(set(sys.path) ^ set(reset_path))
                msg = 'sys.path difference: {0}'.format(msg)
                self.report(msg)
                smash_log.debug(msg)
                sys.path = reset_path
                self.reset_path = sys.path
            else:
                self.reset_path = sys.path
            self._clean_user_namespace(venv)
            self.publish(C_POST_DEACTIVATE, venv)
            return True
Ejemplo n.º 5
0
 def _load_macro(self, macro, name=None):
     smash_log.debug('[{0}]'.format(dict(macro=macro, name=name)))
     assert isinstance(macro, basestring)
     macro = 'get_ipython().run_cell("""{0}""")'.format(macro)
     macro = Macro(macro)
     get_smash().shell.user_ns[name] = macro
Ejemplo n.º 6
0
#
# SmaSh system configuration file
#
# Do not edit this file.
# The file in ~/.smash is reset from smashlib source on every run,
# and thus cannot be edited. To override these values, edit instead
# the user configuration file: ~/.smash/config.py (or inside smash
# type "ed_ed").
#
from smashlib.editor import get_editor
from smashlib._logging import smash_log

msg = "..loading system config: " + __file__
smash_log.debug(msg)

_ = get_config()  # NOQA

# set editor from $EDITOR if possible
_.TerminalInteractiveShell.editor = get_editor()

_.Smash.load_bash_aliases = True
_.Smash.load_bash_functions = True

# load toplevel extensions
##########################################################################
_.InteractiveShellApp.extensions.append("smashlib.ipy_smash")
# _.InteractiveShellApp.extensions.append('smashlib.plugins.prefilter_date')
# every smash component gets it's own verbosity setting.
# this mostly controls the printing of debugging info
##########################################################################
_.Smash.verbose = True
Ejemplo n.º 7
0
 def init(self):
     smash_log.debug('initializing')
     #self.smash.shell.Completer.matchers += [self.history_matcher]
     self.contribute_completer('.*', self.history_matcher)