How to use the ptpython.repl.embed function in ptpython

To help you get started, we’ve selected a few ptpython examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github python-manage / manage / manage / cli.py View on Github external
exec_init(manage_dict, _vars)
    exec_init_script(manage_dict, _vars)

    atexit_functions = [
        import_module(func_name)
        for func_name in manage_dict["shell"].get("exit_hooks", [])
    ]
    atexit_functions += exit_hooks or []
    for atexit_function in atexit_functions:
        atexit.register(atexit_function)

    if console == "ptpython":
        try:
            from ptpython.repl import embed

            embed({}, _vars)
        except ImportError:
            click.echo("ptpython is not installed!")
        return

    if console == "bpython":
        try:
            from bpython import embed

            embed(locals_=_vars, banner=banner_msg)
        except ImportError:
            click.echo("bpython is not installed!")
        return

    try:
        if console == "ipython":
            from IPython import start_ipython
github jacquerie / flask-shell-ptpython / flask_shell_ptpython.py View on Github external
from flask.globals import _app_ctx_stack
    from ptpython.repl import embed

    app = _app_ctx_stack.top.app
    ctx = {}

    # Support the regular Python interpreter startup script if someone
    # is using it.
    startup = os.environ.get('PYTHONSTARTUP')
    if startup and os.path.isfile(startup):
        with open(startup, 'r') as f:
            eval(compile(f.read(), startup, 'exec'), ctx)

    ctx.update(app.make_shell_context())

    embed(globals=ctx)
github acsone / click-odoo / click_odoo / console.py View on Github external
def ptpython(cls, local_vars):
        from ptpython.repl import embed

        embed({}, local_vars)
github lordmauve / pgzero / pgzero / runner.py View on Github external
"""
    try:
        game = PGZeroGame(mod)
        if repl:
            import asyncio
            from ptpython.repl import embed
            loop = asyncio.get_event_loop()

            # Make sure the game runs
            # NB. if the game exits, the REPL will keep running, which allows
            # inspecting final state
            game_task = loop.create_task(game.run_as_coroutine())

            # Wait for the REPL to exit
            loop.run_until_complete(embed(
                globals=vars(mod),
                return_asyncio_coroutine=True,
                patch_stdout=True,
                title="Pygame Zero REPL",
                configure=configure_repl,
            ))

            # Ask game loop to shut down (if it has not) and wait for it
            if game.running:
                pygame.event.post(pygame.event.Event(pygame.QUIT))
                loop.run_until_complete(game_task)
        else:
            game.run()
    finally:
        storage.Storage.save_all()
github prompt-toolkit / ptpython / examples / python-embed.py View on Github external
def main():
    embed(globals(), locals(), vi_mode=False)
github flectra-hq / flectra / flectra / cli / shell.py View on Github external
def ptpython(self, local_vars):
        from ptpython.repl import embed
        embed({}, local_vars)
github nekoyume / nekoyume / nekoyume / shell.py View on Github external
def run():
    from .app import app

    parser = argparse.ArgumentParser(description='Nekoyume shell')
    args = parser.parse_args()

    app.app_context().push()
    embed(globals(), locals())
github prompt-toolkit / ptpython / examples / python-embed-with-custom-prompt.py View on Github external
def main():
    embed(globals(), locals(), configure=configure)