Exemple #1
0
def _info(ns):
    env = builtins.__xonsh_env__
    try:
        ply.__version__ = ply.__version__
    except AttributeError:
        ply.__version__ = '3.8'
    data = [('xonsh', XONSH_VERSION), ('Git SHA', githash()),
            ('Python', '{}.{}.{}'.format(*PYTHON_VERSION_INFO)),
            ('PLY', ply.__version__),
            ('have readline', is_readline_available()),
            ('prompt toolkit', ptk_version() or None),
            ('shell type', env.get('SHELL_TYPE')),
            ('pygments', pygments_version()), ('on posix', bool(ON_POSIX)),
            ('on linux', ON_LINUX)]
    if ON_LINUX:
        data.append(('distro', linux_distro()))
    data.extend([
        ('on darwin', ON_DARWIN),
        ('on windows', ON_WINDOWS),
        ('on cygwin', ON_CYGWIN),
        ('is superuser', is_superuser()),
        ('default encoding', DEFAULT_ENCODING),
        ('xonsh encoding', env.get('XONSH_ENCODING')),
        ('encoding errors', env.get('XONSH_ENCODING_ERRORS')),
    ])
    formatter = _xonfig_format_json if ns.json else _xonfig_format_human
    s = formatter(data)
    return s
Exemple #2
0
def _info(ns):
    env = builtins.__xonsh_env__
    try:
        ply.__version__ = ply.__version__
    except AttributeError:
        ply.__version__ = '3.8'
    data = [
        ('xonsh', XONSH_VERSION),
        ('Git SHA', githash()),
        ('Python', '{}.{}.{}'.format(*PYTHON_VERSION_INFO)),
        ('PLY', ply.__version__),
        ('have readline', is_readline_available()),
        ('prompt toolkit', ptk_version() or None),
        ('shell type', env.get('SHELL_TYPE')),
        ('pygments', pygments_version()),
        ('on posix', bool(ON_POSIX)),
        ('on linux', ON_LINUX)]
    if ON_LINUX:
        data.append(('distro', linux_distro()))
    data.extend([
        ('on darwin', ON_DARWIN),
        ('on windows', ON_WINDOWS),
        ('on cygwin', ON_CYGWIN),
        ('is superuser', is_superuser()),
        ('default encoding', DEFAULT_ENCODING),
        ('xonsh encoding', env.get('XONSH_ENCODING')),
        ('encoding errors', env.get('XONSH_ENCODING_ERRORS')),
    ])
    formatter = _xonfig_format_json if ns.json else _xonfig_format_human
    s = formatter(data)
    return s
Exemple #3
0
def _info(ns):
    env = builtins.__xonsh__.env
    data = [("xonsh", XONSH_VERSION)]
    hash_, date_ = githash()
    if hash_:
        data.append(("Git SHA", hash_))
        data.append(("Commit Date", date_))
    data.extend([
        ("Python", "{}.{}.{}".format(*PYTHON_VERSION_INFO)),
        ("PLY", ply.__version__),
        ("have readline", is_readline_available()),
        ("prompt toolkit", ptk_version() or None),
        ("shell type", env.get("SHELL_TYPE")),
        ("pygments", pygments_version()),
        ("on posix", bool(ON_POSIX)),
        ("on linux", bool(ON_LINUX)),
    ])
    if ON_LINUX:
        data.append(("distro", linux_distro()))
    data.extend([
        ("on darwin", ON_DARWIN),
        ("on windows", ON_WINDOWS),
        ("on cygwin", ON_CYGWIN),
        ("on msys2", ON_MSYS),
        ("is superuser", is_superuser()),
        ("default encoding", DEFAULT_ENCODING),
        ("xonsh encoding", env.get("XONSH_ENCODING")),
        ("encoding errors", env.get("XONSH_ENCODING_ERRORS")),
    ])
    formatter = _xonfig_format_json if ns.json else _xonfig_format_human
    s = formatter(data)
    return s
Exemple #4
0
    def reserve_space(self):
        cli = builtins.__xonsh_shell__.shell.prompter.cli
        if ptk_version().startswith("1.0"):
            # This is the layout for ptk 1.0
            window = cli.application.layout.children[0].content.children[1]
        else:
            #TODO remove after next prompt_toolkit release
            try:
                #old layout to be removed at next ptk release
                window = cli.application.layout.children[1].children[1].content
            except AttributeError:
                #new layout to become default
                window = cli.application.layout.children[1].content

        if window and window.render_info:
            h = window.render_info.content_height
            r = builtins.__xonsh_env__.get('COMPLETIONS_MENU_ROWS')
            size = h + r

            def comp_height(cli):
                # If there is an autocompletion menu to be shown, make sure that o
                # layout has at least a minimal height in order to display it.
                if not cli.is_done:
                    return LayoutDimension(min=size)
                else:
                    return LayoutDimension()

            window._height = comp_height
Exemple #5
0
def _info(ns):
    env = builtins.__xonsh_env__
    try:
        ply.__version__ = ply.__version__
    except AttributeError:
        ply.__version__ = "3.8"
    data = [
        ("xonsh", XONSH_VERSION),
        ("Git SHA", githash()),
        ("Python", "{}.{}.{}".format(*PYTHON_VERSION_INFO)),
        ("PLY", ply.__version__),
        ("have readline", is_readline_available()),
        ("prompt toolkit", ptk_version() or None),
        ("shell type", env.get("SHELL_TYPE")),
        ("pygments", pygments_version()),
        ("on posix", bool(ON_POSIX)),
        ("on linux", ON_LINUX),
    ]
    if ON_LINUX:
        data.append(("distro", linux_distro()))
    data.extend(
        [
            ("on darwin", ON_DARWIN),
            ("on windows", ON_WINDOWS),
            ("on cygwin", ON_CYGWIN),
            ("is superuser", is_superuser()),
            ("default encoding", DEFAULT_ENCODING),
            ("xonsh encoding", env.get("XONSH_ENCODING")),
            ("encoding errors", env.get("XONSH_ENCODING_ERRORS")),
        ]
    )
    formatter = _xonfig_format_json if ns.json else _xonfig_format_human
    s = formatter(data)
    return s
Exemple #6
0
    def reserve_space(self):
        cli = builtins.__xonsh_shell__.shell.prompter.cli
        if ptk_version().startswith("1.0"):
            # This is the layout for ptk 1.0
            window = cli.application.layout.children[0].content.children[1]
        else:
            #TODO remove after next prompt_toolkit release
            try:
                #old layout to be removed at next ptk release
                window = cli.application.layout.children[1].children[1].content
            except AttributeError:
                #new layout to become default
                window = cli.application.layout.children[1].content

        if window and window.render_info:
            h = window.render_info.content_height
            r = builtins.__xonsh_env__.get('COMPLETIONS_MENU_ROWS')
            size = h + r
            def comp_height(cli):
                # If there is an autocompletion menu to be shown, make sure that o
                # layout has at least a minimal height in order to display it.
                if not cli.is_done:
                    return LayoutDimension(min=size)
                else:
                    return LayoutDimension()
            window._height = comp_height
Exemple #7
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' 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 = 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':
         if ptk_version_info()[:2] < (0, 57) or \
                 ptk_version() == '<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
Exemple #8
0
def _info(to_json=False, ) -> str:
    """Displays configuration information

    Parameters
    ----------
    to_json : -j, --json
        reports results as json
    """
    env = XSH.env
    data: tp.List[tp.Any] = [("xonsh", XONSH_VERSION)]
    hash_, date_ = githash()
    if hash_:
        data.append(("Git SHA", hash_))
        data.append(("Commit Date", date_))
    data.extend([
        ("Python", "{}.{}.{}".format(*PYTHON_VERSION_INFO)),
        ("PLY", ply.__version__),
        ("have readline", is_readline_available()),
        ("prompt toolkit", ptk_version() or None),
        ("shell type", env.get("SHELL_TYPE")),
        ("history backend", env.get("XONSH_HISTORY_BACKEND")),
        ("pygments", pygments_version()),
        ("on posix", bool(ON_POSIX)),
        ("on linux", bool(ON_LINUX)),
    ])
    if ON_LINUX:
        data.append(("distro", linux_distro()))
        data.append(("on wsl", bool(ON_WSL)))
        if ON_WSL:
            data.append(("wsl version", 1 if ON_WSL1 else 2))
    data.extend([
        ("on darwin", bool(ON_DARWIN)),
        ("on windows", bool(ON_WINDOWS)),
        ("on cygwin", bool(ON_CYGWIN)),
        ("on msys2", bool(ON_MSYS)),
        ("is superuser", is_superuser()),
        ("default encoding", DEFAULT_ENCODING),
        ("xonsh encoding", env.get("XONSH_ENCODING")),
        ("encoding errors", env.get("XONSH_ENCODING_ERRORS")),
    ])
    jup_ksm = jup_kernel = None
    try:
        from jupyter_client.kernelspec import KernelSpecManager

        jup_ksm = KernelSpecManager()
        jup_kernel = jup_ksm.find_kernel_specs().get(XONSH_JUPYTER_KERNEL)
    except Exception:
        pass
    data.extend([("on jupyter", jup_ksm is not None),
                 ("jupyter kernel", jup_kernel)])

    data.extend([("xontrib", xontribs_loaded())])
    data.extend([("RC file", XSH.rc_files)])

    formatter = _xonfig_format_json if to_json else _xonfig_format_human
    s = formatter(data)
    return s
Exemple #9
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' 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 = 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':
         if ptk_version_info()[:2] < (0, 57) or \
                 ptk_version() == '<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
Exemple #10
0
def _info(ns):
    env = builtins.__xonsh__.env
    data = [("xonsh", XONSH_VERSION)]
    hash_, date_ = githash()
    if hash_:
        data.append(("Git SHA", hash_))
        data.append(("Commit Date", date_))
    data.extend(
        [
            ("Python", "{}.{}.{}".format(*PYTHON_VERSION_INFO)),
            ("PLY", ply.__version__),
            ("have readline", is_readline_available()),
            ("prompt toolkit", ptk_version() or None),
            ("shell type", env.get("SHELL_TYPE")),
            ("pygments", pygments_version()),
            ("on posix", bool(ON_POSIX)),
            ("on linux", bool(ON_LINUX)),
        ]
    )
    if ON_LINUX:
        data.append(("distro", linux_distro()))
    data.extend(
        [
            ("on darwin", bool(ON_DARWIN)),
            ("on windows", bool(ON_WINDOWS)),
            ("on cygwin", bool(ON_CYGWIN)),
            ("on msys2", bool(ON_MSYS)),
            ("is superuser", is_superuser()),
            ("default encoding", DEFAULT_ENCODING),
            ("xonsh encoding", env.get("XONSH_ENCODING")),
            ("encoding errors", env.get("XONSH_ENCODING_ERRORS")),
        ]
    )
    jup_ksm = jup_kernel = None
    try:
        from jupyter_client.kernelspec import KernelSpecManager

        jup_ksm = KernelSpecManager()
        jup_kernel = jup_ksm.find_kernel_specs().get(XONSH_JUPYTER_KERNEL)
    except Exception:
        pass
    data.extend([("on jupyter", jup_ksm is not None), ("jupyter kernel", jup_kernel)])

    data.extend([("xontrib", xontribs_loaded())])

    formatter = _xonfig_format_json if ns.json else _xonfig_format_human
    s = formatter(data)
    return s
Exemple #11
0
def _info(ns):
    data = [('xonsh', XONSH_VERSION),
            ('Python', '{}.{}.{}'.format(*platform.PYTHON_VERSION_INFO)),
            ('PLY', ply.__version__),
            ('have readline', is_readline_available()),
            ('prompt toolkit', ptk_version() or None),
            ('pygments', platform.PYGMENTS_VERSION),
            ('on posix', platform.ON_POSIX), ('on linux', platform.ON_LINUX)]
    if platform.ON_LINUX:
        data.append(('distro', platform.LINUX_DISTRO))
    data.extend([
        ('on darwin', platform.ON_DARWIN),
        ('on windows', platform.ON_WINDOWS),
        ('is superuser', tools.IS_SUPERUSER),
        ('default encoding', platform.DEFAULT_ENCODING),
    ])
    formatter = _format_json if ns.json else _format_human
    s = formatter(data)
    return s
Exemple #12
0
def _info(ns):
    data = [
        ('xonsh', XONSH_VERSION),
        ('Python', '{}.{}.{}'.format(*platform.PYTHON_VERSION_INFO)),
        ('PLY', ply.__version__),
        ('have readline', is_readline_available()),
        ('prompt toolkit', ptk_version() or None),
        ('pygments', platform.PYGMENTS_VERSION),
        ('on posix', platform.ON_POSIX),
        ('on linux', platform.ON_LINUX)]
    if platform.ON_LINUX:
        data.append(('distro', platform.LINUX_DISTRO))
    data.extend([
        ('on darwin', platform.ON_DARWIN),
        ('on windows', platform.ON_WINDOWS),
        ('is superuser', tools.IS_SUPERUSER),
        ('default encoding', platform.DEFAULT_ENCODING),
        ])
    formatter = _format_json if ns.json else _format_human
    s = formatter(data)
    return s
Exemple #13
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.prompter = Prompter()
        self.history = PromptToolkitHistory()
        self.pt_completer = PromptToolkitCompleter(self.completer, self.ctx)

        key_bindings_manager_args = {
            'enable_auto_suggest_bindings': True,
            'enable_search': True,
            'enable_abort_and_exit_bindings': True,
            'enable_open_in_editor': True,
        }
        major, minor = ptk_version_info()[:2]
        self.new_vi_mode_flag = (major, minor) >= (1, 0) \
                                and ptk_version() != '<0.57'
        if not self.new_vi_mode_flag:
            # enable_vi_mode is deprecated acoording to prompt_toolset 1.0 document.
            key_bindings_manager_args['enable_vi_mode'] = Condition(
                lambda cli: builtins.__xonsh_env__.get('VI_MODE'))

        self.key_bindings_manager = KeyBindingManager(
            **key_bindings_manager_args)
        load_xonsh_bindings(self.key_bindings_manager)