Example #1
0
def _initialize_python_shell():
    try:
        from jedi.utils import setup_readline
        setup_readline()
    except ImportError:
        import readline
        readline.parse_and_bind("tab: complete")
    finally:
        import readline
        import os.path
        history_file = os.path.join(os.environ['HOME'], '.python_history')
        readline.set_history_length(1000)
        readline.read_history_file(history_file)
Example #2
0
 def configureCompletion(self) -> None:
     try:
         from jedi.utils import setup_readline
         setup_readline()
     except ImportError:
         # Fallback to the stdlib readline completer if it is installed.
         # Taken from http://docs.python.org/2/library/rlcompleter.html
         runtime.ui.info("jedi is not installed, falling back to readline"
                         " for completion")
         try:
             import readline
             import rlcompleter
             readline.parse_and_bind("tab: complete")
         except ImportError:
             runtime.ui.info("readline is not installed either."
                             " No tab completion is enabled.")
Example #3
0
 def configureCompletion(self) -> None:
     try:
         from jedi.utils import setup_readline
         setup_readline()
     except ImportError:
         # Fallback to the stdlib readline completer if it is installed.
         # Taken from http://docs.python.org/2/library/rlcompleter.html
         runtime.ui.info("jedi is not installed, falling back to readline"
             " for completion")
         try:
             import readline
             import rlcompleter
             readline.parse_and_bind("tab: complete")
         except ImportError:
             runtime.ui.info("readline is not installed either."
                 " No tab completion is enabled.")
Example #4
0
# http://sontek.net/blog/detail/tips-and-tricks-for-the-python-interpreter
from __future__ import print_function
import os
import sys

try:
    import readline
    import rlcompleter
    import atexit
except ImportError:
    print("You need readline, rlcompleter, and atexit")


try:
    from jedi.utils import setup_readline
    setup_readline()
except ImportError:
    # Fallback to the stdlib readline completer if it is installed.
    # Taken from http://docs.python.org/2/library/rlcompleter.html
    print("Jedi is not installed, falling back to readline")
    try:
        readline.parse_and_bind("tab: complete")
    except ImportError:
        print("Readline is not installed either.\
         No tab completion is enabled.")

class Completer(object):
    def __init__(self):
        # Enable a History
        self.HISTFILE = os.path.join(os.environ['HOME'], '.pythonhist')
Example #5
0
import readline
import pathlib

# Modules additionnels potentiellement présents
# try:
# import requests
# except ImportError:
# pass

histfile_name = '.python_history'

# Enable completion in the standard python shell if jedi is installed
# http://jedi.readthedocs.io/en/latest/docs/usage.html#tab-completion-in-the-python-shell
try:
    from jedi.utils import setup_readline
    setup_readline()
except ImportError:
    # Fallback to the stdlib readline completer if it is installed.
    # Taken from http://docs.python.org/2/library/rlcompleter.html
    print("Jedi is not installed, falling back to readline")
    try:
        # import readline
        import rlcompleter
        readline.parse_and_bind("tab: complete")
    except ImportError:
        print(
            "Readline is not installed either. No tab completion is enabled.")

# Environnement virtuel ?
env = os.environ.get('VIRTUAL_ENV')
Example #6
0
    def __init__(self, *args, **kwargs):
        super(type(self), self).__init__(*args, **kwargs)

        self.namespace = self.NameSpace()
        utils.setup_readline(self.namespace)
Example #7
0
    def __init__(self, *args, **kwargs):
        super(type(self), self).__init__(*args, **kwargs)

        self.namespace = self.NameSpace()
        utils.setup_readline(self.namespace)
Example #8
0
def shell(config, **kwargs):
    import atexit
    import code
    import readline
    import sys
    from jedi.utils import setup_readline

    histfile_name = ".python_history"

    config.init()
    # launch a development server for testing
    graph_ents = config.store.graph.values()
    graphs = []
    for graph in graph_ents:
        graphs.append(
            graph_manager.plan(
                graph,
                store=config.store,
                environment=config.environment,
            ))

    output = render_impl.FileRenderer("-")

    def renderer(x):
        runtime_impl.render_graph(x, output)
        output.write()

    ns = {
        "graphs": graphs,
        "store": config.store,
        "config": config,
        "dump": lambda x: print(utils.dump(x)),
        "render": renderer,
        "output": output,
        "utils": utils,
    }
    if graphs:
        ns["g"] = graphs[0]

    class O:
        def __init__(self, ns):
            self.__dict__ = ns

    setup_readline(O(ns))

    env = os.environ.get("VIRTUAL_ENV")

    if env:
        env_name = os.path.basename(env)
        histfile_name = "{}_{}".format(histfile_name, env_name)
        name = graphs[0].name if graphs else "default"
        sys.ps1 = f"model ({name}) >>> "

    # set history file
    try:
        histfile = os.path.join(os.environ["XDG_CACHE_HOME"], "python",
                                histfile_name)
    except KeyError:
        histfile = os.path.join(os.environ["HOME"], ".cache", "python",
                                histfile_name)

    Path(os.path.dirname(histfile)).mkdir(parents=True, exist_ok=True)

    try:
        readline.read_history_file(histfile)
        # default history len is -1 (infinite), which may grow unruly
        readline.set_history_length(1000)
    except FileNotFoundError:
        pass

    atexit.register(readline.write_history_file, histfile)
    banner = f"""model interactive shell
{sorted(ns.keys())}
    """
    code.interact(banner, local=ns)