Beispiel #1
0
    def __init__(self, execer, ctx=None, shell_type=None, **kwargs):
        """
        Parameters
        ----------
        execer : Execer
            An execer instance capable of running xonsh code.
        ctx : Mapping, optional
            The execution context for the shell (e.g. the globals namespace).
            If none, this is computed by loading the rc files. If not None,
            this no additional context is computed and this is used
            directly.
        shell_type : str, optional
            The shell type to start, such as 'readline', 'prompt_toolkit',
            or 'random'.
        """
        self.execer = execer
        self.ctx = {} if ctx is None else ctx
        env = builtins.__xonsh_env__
        # build history backend before creating shell
        builtins.__xonsh_history__ = hist = xhm.construct_history(
            env=env.detype(), ts=[time.time(), None], locked=True)

        # pick a valid shell -- if no shell is specified by the user,
        # shell type is pulled from env
        if shell_type is None:
            shell_type = env.get('SHELL_TYPE')
            if shell_type == 'none':
                # This bricks interactive xonsh
                # Can happen from the use of .xinitrc, .xsession, etc
                shell_type = 'best'
        if shell_type == 'best' or shell_type is None:
            shell_type = best_shell_type()
        elif shell_type == 'random':
            shell_type = random.choice(('readline', 'prompt_toolkit'))
        if shell_type == 'prompt_toolkit':
            if not has_prompt_toolkit():
                warnings.warn('prompt_toolkit is not available, using '
                              'readline instead.')
                shell_type = 'readline'
            elif not ptk_version_is_supported():
                warnings.warn('prompt-toolkit version < v1.0.0 is not '
                              'supported. Please update prompt-toolkit. Using '
                              'readline instead.')
                shell_type = 'readline'
        self.shell_type = env['SHELL_TYPE'] = shell_type
        # actually make the shell
        if shell_type == 'none':
            from xonsh.base_shell import BaseShell as shell_class
        elif shell_type == 'prompt_toolkit':
            from xonsh.ptk.shell import PromptToolkitShell as shell_class
        elif shell_type == 'readline':
            from xonsh.readline_shell import ReadlineShell as shell_class
        else:
            raise XonshError('{} is not recognized as a shell type'.format(
                             shell_type))
        self.shell = shell_class(execer=self.execer,
                                 ctx=self.ctx, **kwargs)
        # allows history garbage collector to start running
        if hist.gc is not None:
            hist.gc.wait_for_shell = False
Beispiel #2
0
 def __init__(self,
              ctx=None,
              shell_type=None,
              config=None,
              rc=None,
              **kwargs):
     """
     Parameters
     ----------
     ctx : Mapping, optional
         The execution context for the shell (e.g. the globals namespace).
         If none, this is computed by loading the rc files. If not None,
         this no additional context is computed and this is used
         directly.
     shell_type : str, optional
         The shell type to start, such as 'readline', 'prompt_toolkit',
         or 'random'.
     config : str, optional
         Path to configuration file.
     rc : list of str, optional
         Sequence of paths to run control files.
     """
     self.login = kwargs.get('login', True)
     self.stype = shell_type
     self._init_environ(ctx, config, rc, kwargs.get('scriptcache', True),
                        kwargs.get('cacheall', False))
     env = builtins.__xonsh_env__
     # pick a valid shell
     if shell_type is not None:
         env['SHELL_TYPE'] = shell_type
     shell_type = env.get('SHELL_TYPE')
     if shell_type == 'best':
         shell_type = best_shell_type()
     elif shell_type == 'random':
         shell_type = random.choice(('readline', 'prompt_toolkit'))
     if shell_type == 'prompt_toolkit':
         if not is_prompt_toolkit_available():
             warn(
                 'prompt_toolkit is not available, using readline instead.')
             shell_type = env['SHELL_TYPE'] = 'readline'
     # actually make the shell
     if shell_type == 'none':
         from xonsh.base_shell import BaseShell as shell_class
     elif shell_type == 'prompt_toolkit':
         vptk = prompt_toolkit_version()
         major, minor = [int(x) for x in vptk.split('.')[:2]]
         if (major, minor) < (
                 0, 57) or vptk == '<0.57':  # TODO: remove in future
             msg = ('prompt-toolkit version < v0.57 and may not work as '
                    'expected. Please update.')
             warn(msg, RuntimeWarning)
         from xonsh.ptk.shell import PromptToolkitShell as shell_class
     elif shell_type == 'readline':
         from xonsh.readline_shell import ReadlineShell as shell_class
     else:
         raise XonshError(
             '{} is not recognized as a shell type'.format(shell_type))
     self.shell = shell_class(execer=self.execer, ctx=self.ctx, **kwargs)
     # allows history garbace colector to start running
     builtins.__xonsh_history__.gc.wait_for_shell = False
Beispiel #3
0
 def __init__(self,
              ctx=None,
              shell_type=None,
              config=None,
              rc=None,
              **kwargs):
     """
     Parameters
     ----------
     ctx : Mapping, optional
         The execution context for the shell (e.g. the globals namespace).
         If none, this is computed by loading the rc files. If not None,
         this no additional context is computed and this is used
         directly.
     shell_type : str, optional
         The shell type to start, such as 'readline', 'prompt_toolkit',
         or 'random'.
     config : str, optional
         Path to configuration file.
     rc : list of str, optional
         Sequence of paths to run control files.
     """
     self.login = kwargs.get('login', True)
     self.stype = shell_type
     self._init_environ(ctx, config, rc, kwargs.get('scriptcache', True),
                        kwargs.get('cacheall', False))
     env = builtins.__xonsh_env__
     # pick a valid shell -- if no shell is specified by the user,
     # shell type is pulled from env
     if shell_type is None:
         shell_type = env.get('SHELL_TYPE')
     if shell_type == 'best' or shell_type is None:
         shell_type = best_shell_type()
     elif shell_type == 'random':
         shell_type = random.choice(('readline', 'prompt_toolkit'))
     if shell_type == 'prompt_toolkit':
         if not has_prompt_toolkit():
             warnings.warn('prompt_toolkit is not available, using '
                           'readline instead.')
             shell_type = 'readline'
         elif not ptk_version_is_supported():
             warnings.warn('prompt-toolkit version < v1.0.0 is not '
                           'supported. Please update prompt-toolkit. Using '
                           'readline instead.')
             shell_type = 'readline'
     env['SHELL_TYPE'] = shell_type
     # actually make the shell
     if shell_type == 'none':
         from xonsh.base_shell import BaseShell as shell_class
     elif shell_type == 'prompt_toolkit':
         from xonsh.ptk.shell import PromptToolkitShell as shell_class
     elif shell_type == 'readline':
         from xonsh.readline_shell import ReadlineShell as shell_class
     else:
         raise XonshError(
             '{} is not recognized as a shell type'.format(shell_type))
     self.shell = shell_class(execer=self.execer, ctx=self.ctx, **kwargs)
     # allows history garbace colector to start running
     builtins.__xonsh_history__.gc.wait_for_shell = False
Beispiel #4
0
    def __init__(self, execer, ctx=None, shell_type=None, **kwargs):
        """
        Parameters
        ----------
        execer : Execer
            An execer instance capable of running xonsh code.
        ctx : Mapping, optional
            The execution context for the shell (e.g. the globals namespace).
            If none, this is computed by loading the rc files. If not None,
            this no additional context is computed and this is used
            directly.
        shell_type : str, optional
            The shell type to start, such as 'readline', 'prompt_toolkit',
            or 'random'.
        """
        self.execer = execer
        self.ctx = {} if ctx is None else ctx
        env = builtins.__xonsh_env__
        # build history backend before creating shell
        builtins.__xonsh_history__ = hist = xhm.construct_history(
            env=env.detype(), ts=[time.time(), None], locked=True)

        # pick a valid shell -- if no shell is specified by the user,
        # shell type is pulled from env
        if shell_type is None:
            shell_type = env.get('SHELL_TYPE')
            if shell_type == 'none':
                # This bricks interactive xonsh
                # Can happen from the use of .xinitrc, .xsession, etc
                shell_type = 'best'
        if shell_type == 'best' or shell_type is None:
            shell_type = best_shell_type()
        elif shell_type == 'random':
            shell_type = random.choice(('readline', 'prompt_toolkit'))
        if shell_type == 'prompt_toolkit':
            if not has_prompt_toolkit():
                warnings.warn('prompt_toolkit is not available, using '
                              'readline instead.')
                shell_type = 'readline'
            elif not ptk_version_is_supported():
                warnings.warn('prompt-toolkit version < v1.0.0 is not '
                              'supported. Please update prompt-toolkit. Using '
                              'readline instead.')
                shell_type = 'readline'
        self.shell_type = env['SHELL_TYPE'] = shell_type
        # actually make the shell
        if shell_type == 'none':
            from xonsh.base_shell import BaseShell as shell_class
        elif shell_type == 'prompt_toolkit':
            from xonsh.ptk.shell import PromptToolkitShell as shell_class
        elif shell_type == 'readline':
            from xonsh.readline_shell import ReadlineShell as shell_class
        else:
            raise XonshError(
                '{} is not recognized as a shell type'.format(shell_type))
        self.shell = shell_class(execer=self.execer, ctx=self.ctx, **kwargs)
        # allows history garbage collector to start running
        if hist.gc is not None:
            hist.gc.wait_for_shell = False
Beispiel #5
0
 def __init__(self, ctx=None, shell_type=None, config=None, rc=None,
              **kwargs):
     """
     Parameters
     ----------
     ctx : Mapping, optional
         The execution context for the shell (e.g. the globals namespace).
         If none, this is computed by loading the rc files. If not None,
         this no additional context is computed and this is used
         directly.
     shell_type : str, optional
         The shell type to start, such as 'readline', 'prompt_toolkit',
         or 'random'.
     config : str, optional
         Path to configuration file.
     rc : list of str, optional
         Sequence of paths to run control files.
     """
     self.login = kwargs.get('login', True)
     self.stype = shell_type
     self._init_environ(ctx, config, rc,
                        kwargs.get('scriptcache', True),
                        kwargs.get('cacheall', False))
     env = builtins.__xonsh_env__
     # pick a valid shell -- if no shell is specified by the user,
     # shell type is pulled from env
     if shell_type is None:
         shell_type = env.get('SHELL_TYPE')
     if shell_type == 'best' or shell_type is None:
         shell_type = best_shell_type()
     elif shell_type == 'random':
         shell_type = random.choice(('readline', 'prompt_toolkit'))
     if shell_type == 'prompt_toolkit':
         if not has_prompt_toolkit():
             warnings.warn('prompt_toolkit is not available, using '
                           'readline instead.')
             shell_type = 'readline'
         elif not ptk_version_is_supported():
             warnings.warn('prompt-toolkit version < v1.0.0 is not '
                           'supported. Please update prompt-toolkit. Using '
                           'readline instead.')
             shell_type = 'readline'
     env['SHELL_TYPE'] = shell_type
     # actually make the shell
     if shell_type == 'none':
         from xonsh.base_shell import BaseShell as shell_class
     elif shell_type == 'prompt_toolkit':
         from xonsh.ptk.shell import PromptToolkitShell as shell_class
     elif shell_type == 'readline':
         from xonsh.readline_shell import ReadlineShell as shell_class
     else:
         raise XonshError('{} is not recognized as a shell type'.format(
                          shell_type))
     self.shell = shell_class(execer=self.execer,
                              ctx=self.ctx, **kwargs)
     # allows history garbace colector to start running
     builtins.__xonsh_history__.gc.wait_for_shell = False
Beispiel #6
0
 def __init__(self, ctx=None, shell_type=None, config=None, rc=None,
              **kwargs):
     """
     Parameters
     ----------
     ctx : Mapping, optional
         The execution context for the shell (e.g. the globals namespace).
         If none, this is computed by loading the rc files. If not None,
         this no additional context is computed and this is used
         directly.
     shell_type : str, optional
         The shell type to start, such as 'readline', 'prompt_toolkit',
         or 'random'.
     config : str, optional
         Path to configuration file.
     rc : list of str, optional
         Sequence of paths to run control files.
     """
     self.login = kwargs.get('login', True)
     self.stype = shell_type
     self._init_environ(ctx, config, rc,
                        kwargs.get('scriptcache', True),
                        kwargs.get('cacheall', False))
     env = builtins.__xonsh_env__
     # pick a valid shell
     if shell_type is not None:
         env['SHELL_TYPE'] = shell_type
     shell_type = env.get('SHELL_TYPE')
     if shell_type == 'best':
         shell_type = best_shell_type()
     elif shell_type == 'random':
         shell_type = random.choice(('readline', 'prompt_toolkit'))
     if shell_type == 'prompt_toolkit':
         if not is_prompt_toolkit_available():
             warn('prompt_toolkit is not available, using readline instead.')
             shell_type = env['SHELL_TYPE'] = 'readline'
     # actually make the shell
     if shell_type == 'none':
         from xonsh.base_shell import BaseShell as shell_class
     elif shell_type == 'prompt_toolkit':
         vptk = prompt_toolkit_version()
         major,minor = [int(x) for x in vptk.split('.')[:2]]
         if (major,minor) < (0, 57) or vptk == '<0.57':  # TODO: remove in future
             msg = ('prompt-toolkit version < v0.57 and may not work as '
                    'expected. Please update.')
             warn(msg, RuntimeWarning)
         from xonsh.ptk.shell import PromptToolkitShell as shell_class
     elif shell_type == 'readline':
         from xonsh.readline_shell import ReadlineShell as shell_class
     else:
         raise XonshError('{} is not recognized as a shell type'.format(
                          shell_type))
     self.shell = shell_class(execer=self.execer,
                              ctx=self.ctx, **kwargs)
     # allows history garbace colector to start running
     builtins.__xonsh_history__.gc.wait_for_shell = False
Beispiel #7
0
    def __init__(self, execer, ctx=None, shell_type=None, **kwargs):
        """
        Parameters
        ----------
        execer : Execer
            An execer instance capable of running xonsh code.
        ctx : Mapping, optional
            The execution context for the shell (e.g. the globals namespace).
            If none, this is computed by loading the rc files. If not None,
            this no additional context is computed and this is used
            directly.
        shell_type : str, optional
            The shell type to start, such as 'readline', 'prompt_toolkit1',
            or 'random'.
        """
        self.execer = execer
        self.ctx = {} if ctx is None else ctx
        env = XSH.env

        # build history backend before creating shell
        if env.get("XONSH_INTERACTIVE"):
            XSH.history = hist = xhm.construct_history(
                env=env.detype(),
                ts=[time.time(), None],
                locked=True,
                filename=env.get("XONSH_HISTORY_FILE", None),
            )
            env["XONSH_HISTORY_FILE"] = hist.filename
        else:
            XSH.history = hist = DummyHistory()
            env["XONSH_HISTORY_FILE"] = None

        shell_type = self.choose_shell_type(shell_type, env)

        self.shell_type = env["SHELL_TYPE"] = shell_type

        # actually make the shell
        if shell_type == "none":
            from xonsh.base_shell import BaseShell as shell_class
        elif shell_type == "prompt_toolkit":
            from xonsh.ptk_shell.shell import PromptToolkitShell as shell_class
        elif shell_type == "readline":
            from xonsh.readline_shell import ReadlineShell as shell_class
        elif shell_type == "jupyter":
            from xonsh.jupyter_shell import JupyterShell as shell_class
        elif shell_type == "dumb":
            from xonsh.dumb_shell import DumbShell as shell_class
        else:
            raise XonshError(
                "{} is not recognized as a shell type".format(shell_type))
        self.shell = shell_class(execer=self.execer, ctx=self.ctx, **kwargs)
        # allows history garbage collector to start running
        if hist.gc is not None:
            hist.gc.wait_for_shell = False
Beispiel #8
0
 def __init__(self, ctx=None, shell_type=None, config=None, rc=None, **kwargs):
     """
     Parameters
     ----------
     ctx : Mapping, optional
         The execution context for the shell (e.g. the globals namespace).
         If none, this is computed by loading the rc files. If not None,
         this no additional context is computed and this is used
         directly.
     shell_type : str, optional
         The shell type to start, such as 'readline', 'prompt_toolkit',
         or 'random'.
     config : str, optional
         Path to configuration file.
     rc : list of str, optional
         Sequence of paths to run control files.
     """
     self.login = kwargs.get("login", True)
     self.stype = shell_type
     self._init_environ(ctx, config, rc, kwargs.get("scriptcache", True), kwargs.get("cacheall", False))
     env = builtins.__xonsh_env__
     # pick a valid shell -- if no shell is specified by the user,
     # shell type is pulled from env
     if shell_type is None:
         shell_type = env.get("SHELL_TYPE")
     if shell_type == "best" or shell_type is None:
         shell_type = best_shell_type()
     elif shell_type == "random":
         shell_type = random.choice(("readline", "prompt_toolkit"))
     if shell_type == "prompt_toolkit":
         if not has_prompt_toolkit():
             warn("prompt_toolkit is not available, using readline instead.")
             shell_type = "readline"
     env["SHELL_TYPE"] = shell_type
     # actually make the shell
     if shell_type == "none":
         from xonsh.base_shell import BaseShell as shell_class
     elif shell_type == "prompt_toolkit":
         if ptk_version_info()[:2] < (1, 0):
             msg = (
                 "prompt-toolkit version < v1.0.0 is not supported, "
                 "xonsh may not work as expected. Please update."
             )
             warn(msg, RuntimeWarning)
         from xonsh.ptk.shell import PromptToolkitShell as shell_class
     elif shell_type == "readline":
         from xonsh.readline_shell import ReadlineShell as shell_class
     else:
         raise XonshError("{} is not recognized as a shell type".format(shell_type))
     self.shell = shell_class(execer=self.execer, ctx=self.ctx, **kwargs)
     # allows history garbace colector to start running
     builtins.__xonsh_history__.gc.wait_for_shell = False
Beispiel #9
0
    def __init__(self, execer, ctx=None, shell_type=None, **kwargs):
        """
        Parameters
        ----------
        execer : Execer
            An execer instance capable of running xonsh code.
        ctx : Mapping, optional
            The execution context for the shell (e.g. the globals namespace).
            If none, this is computed by loading the rc files. If not None,
            this no additional context is computed and this is used
            directly.
        shell_type : str, optional
            The shell type to start, such as 'readline', 'prompt_toolkit1',
            or 'random'.
        """
        self.execer = execer
        self.ctx = {} if ctx is None else ctx
        env = builtins.__xonsh__.env
        # build history backend before creating shell
        builtins.__xonsh__.history = hist = xhm.construct_history(
            env=env.detype(), ts=[time.time(), None], locked=True)

        # pick a valid shell -- if no shell is specified by the user,
        # shell type is pulled from env
        if shell_type is None:
            shell_type = env.get("SHELL_TYPE")
            if shell_type == "none":
                # This bricks interactive xonsh
                # Can happen from the use of .xinitrc, .xsession, etc
                shell_type = "best"
        shell_type = self.shell_type_aliases.get(shell_type, shell_type)
        if shell_type == "best" or shell_type is None:
            shell_type = best_shell_type()
        elif env.get("TERM", "") == "dumb":
            shell_type = "dumb"
        elif shell_type == "random":
            shell_type = random.choice(("readline", "prompt_toolkit"))
        if shell_type == "prompt_toolkit":
            if not has_prompt_toolkit():
                warnings.warn("prompt_toolkit is not available, using "
                              "readline instead.")
                shell_type = "readline"
            elif not ptk_above_min_supported():
                warnings.warn("prompt-toolkit version < v1.0.0 is not "
                              "supported. Please update prompt-toolkit. Using "
                              "readline instead.")
                shell_type = "readline"
            else:
                shell_type = ptk_shell_type()
        self.shell_type = env["SHELL_TYPE"] = shell_type
        # actually make the shell
        if shell_type == "none":
            from xonsh.base_shell import BaseShell as shell_class
        elif shell_type == "prompt_toolkit2":
            from xonsh.ptk2.shell import PromptToolkit2Shell as shell_class
        elif shell_type == "prompt_toolkit1":
            from xonsh.ptk.shell import PromptToolkitShell as shell_class
        elif shell_type == "readline":
            from xonsh.readline_shell import ReadlineShell as shell_class
        elif shell_type == "jupyter":
            from xonsh.jupyter_shell import JupyterShell as shell_class
        elif shell_type == "dumb":
            from xonsh.dumb_shell import DumbShell as shell_class
        else:
            raise XonshError(
                "{} is not recognized as a shell type".format(shell_type))
        self.shell = shell_class(execer=self.execer, ctx=self.ctx, **kwargs)
        # allows history garbage collector to start running
        if hist.gc is not None:
            hist.gc.wait_for_shell = False
Beispiel #10
0
    def __init__(self, execer, ctx=None, shell_type=None, **kwargs):
        """
        Parameters
        ----------
        execer : Execer
            An execer instance capable of running xonsh code.
        ctx : Mapping, optional
            The execution context for the shell (e.g. the globals namespace).
            If none, this is computed by loading the rc files. If not None,
            this no additional context is computed and this is used
            directly.
        shell_type : str, optional
            The shell type to start, such as 'readline', 'prompt_toolkit1',
            or 'random'.
        """
        self.execer = execer
        self.ctx = {} if ctx is None else ctx
        env = builtins.__xonsh__.env
        # build history backend before creating shell
        builtins.__xonsh__.history = hist = xhm.construct_history(
            env=env.detype(), ts=[time.time(), None], locked=True
        )

        # pick a valid shell -- if no shell is specified by the user,
        # shell type is pulled from env
        if shell_type is None:
            shell_type = env.get("SHELL_TYPE")
            if shell_type == "none":
                # This bricks interactive xonsh
                # Can happen from the use of .xinitrc, .xsession, etc
                shell_type = "best"
        shell_type = self.shell_type_aliases.get(shell_type, shell_type)
        if shell_type == "best" or shell_type is None:
            shell_type = best_shell_type()
        elif env.get("TERM", "") == "dumb":
            shell_type = "dumb"
        elif shell_type == "random":
            shell_type = random.choice(("readline", "prompt_toolkit"))
        if shell_type == "prompt_toolkit":
            if not has_prompt_toolkit():
                warnings.warn(
                    "prompt_toolkit is not available, using " "readline instead."
                )
                shell_type = "readline"
            elif not ptk_above_min_supported():
                warnings.warn(
                    "prompt-toolkit version < v1.0.0 is not "
                    "supported. Please update prompt-toolkit. Using "
                    "readline instead."
                )
                shell_type = "readline"
            else:
                shell_type = ptk_shell_type()
        self.shell_type = env["SHELL_TYPE"] = shell_type
        # actually make the shell
        if shell_type == "none":
            from xonsh.base_shell import BaseShell as shell_class
        elif shell_type == "prompt_toolkit2":
            from xonsh.ptk2.shell import PromptToolkit2Shell as shell_class
        elif shell_type == "prompt_toolkit1":
            from xonsh.ptk.shell import PromptToolkitShell as shell_class
        elif shell_type == "readline":
            from xonsh.readline_shell import ReadlineShell as shell_class
        elif shell_type == "jupyter":
            from xonsh.jupyter_shell import JupyterShell as shell_class
        elif shell_type == "dumb":
            from xonsh.dumb_shell import DumbShell as shell_class
        else:
            raise XonshError("{} is not recognized as a shell type".format(shell_type))
        self.shell = shell_class(execer=self.execer, ctx=self.ctx, **kwargs)
        # allows history garbage collector to start running
        if hist.gc is not None:
            hist.gc.wait_for_shell = False