How to use the bpython.args function in bpython

To help you get started, we’ve selected a few bpython 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 bpython / bpython / bpython / gtk_.py View on Github external
True)

    interpreter = repl.Interpreter(None, getpreferredencoding())
    repl_widget = ReplWidget(interpreter, config)
    repl_widget.connect('exit-event', gtk.main_quit)

    gobject.idle_add(init_import_completion)

    if not exec_args:
        sys.path.insert(0, '')
        gobject.idle_add(repl_widget.startup)
    else:
        if options.interactive:
            gobject.idle_add(bpython.args.exec_code, interpreter, exec_args)
        else:
            bpython.args.exec_code(interpreter, exec_args)
            return 0

    sys.stderr = repl_widget
    sys.stdout = repl_widget

    if not options.socket_id:
        parent = gtk.Window()
        parent.connect('delete-event', lambda widget, event: gtk.main_quit())

        # branding
        # fix icon to be distributed and loaded from the correct path
        icon = gtk.gdk.pixbuf_new_from_file(os.path.join(os.path.dirname(__file__),
                                                         'logo.png'))

        parent.set_title('bpython')
        parent.set_icon(icon)
github bpython / bpython / bpython / gtk_.py View on Github external
def main(args=None):
    translations.init()

    gtk_options = (_('gtk-specific options'),
                   _("Options specific to bpython's Gtk+ front end"),
                   [optparse.Option('--socket-id', dest='socket_id',
                                    type='int', help=_('Embed bpython'))])
    config, options, exec_args = bpython.args.parse(args, gtk_options,
                                                    True)

    interpreter = repl.Interpreter(None, getpreferredencoding())
    repl_widget = ReplWidget(interpreter, config)
    repl_widget.connect('exit-event', gtk.main_quit)

    gobject.idle_add(init_import_completion)

    if not exec_args:
        sys.path.insert(0, '')
        gobject.idle_add(repl_widget.startup)
    else:
        if options.interactive:
            gobject.idle_add(bpython.args.exec_code, interpreter, exec_args)
        else:
            bpython.args.exec_code(interpreter, exec_args)
github bpython / bpython / bpython / curtsies.py View on Github external
def main(args=None, locals_=None, banner=None, welcome_message=None):
    """
    banner is displayed directly after the version information.
    welcome_message is passed on to Repl and displayed in the statusbar.
    """
    translations.init()

    config, options, exec_args = bpargs.parse(
        args,
        (
            "curtsies options",
            None,
            [
                Option(
                    "--log",
                    "-L",
                    action="count",
                    help=_("log debug messages to bpython.log"),
                ),
                Option(
                    "--paste",
                    "-p",
                    action="store_true",
                    help=_("start by pasting lines of a file into session"),
github bpython / bpython / bpython / curtsies.py View on Github external
interp = None
    paste = None
    if exec_args:
        if not options:
            raise ValueError("don't pass in exec_args without options")
        exit_value = ()
        if options.paste:
            paste = curtsies.events.PasteEvent()
            encoding = inspection.get_encoding_file(exec_args[0])
            with io.open(exec_args[0], encoding=encoding) as f:
                sourcecode = f.read()
            paste.events.extend(sourcecode)
        else:
            try:
                interp = Interp(locals=locals_)
                bpargs.exec_code(interp, exec_args)
            except SystemExit as e:
                exit_value = e.args
            if not options.interactive:
                return extract_exit_value(exit_value)
    else:
        # expected for interactive sessions (vanilla python does it)
        sys.path.insert(0, "")

    if not options.quiet:
        print(bpargs.version_banner())
    if banner is not None:
        print(banner)
    global repl
    repl = FullCurtsiesRepl(config, locals_, welcome_message, interp)
    try:
        with repl.input_generator:
github bpython / bpython / bpython / cli.py View on Github external
main_win, statusbar = init_wins(scr, cols, config)

    if locals_ is None:
        sys.modules['__main__'] = ModuleType('__main__')
        locals_ = sys.modules['__main__'].__dict__
    interpreter = Interpreter(locals_, getpreferredencoding())

    repl = CLIRepl(main_win, interpreter, statusbar, config, idle)
    repl._C = cols

    sys.stdin = FakeStdin(repl)
    sys.stdout = repl
    sys.stderr = repl

    if args:
        bpython.args.exec_code(interpreter, args)
        if not interactive:
            curses.raw(False)
            return repl.getstdout()

    repl.repl()
    if config.hist_length:
        histfilename = os.path.expanduser(config.hist_file)
        repl.rl_history.save(histfilename, getpreferredencoding())

    main_win.erase()
    main_win.refresh()
    statusbar.win.clear()
    statusbar.win.refresh()
    curses.raw(False)

    # Restore SIGWINCH handler
github bpython / bpython / bpython / cli.py View on Github external
curses.raw(True)
    main_win, statusbar = init_wins(scr, config)

    interpreter = repl.Interpreter(locals_, getpreferredencoding())

    clirepl = CLIRepl(main_win, interpreter, statusbar, config, idle)
    clirepl._C = cols

    sys.stdin = FakeStdin(clirepl)
    sys.stdout = FakeStream(clirepl, lambda: sys.stdout)
    sys.stderr = FakeStream(clirepl, lambda: sys.stderr)

    if args:
        exit_value = ()
        try:
            bpargs.exec_code(interpreter, args)
        except SystemExit as e:
            # The documentation of code.InteractiveInterpreter.runcode claims
            # that it reraises SystemExit. However, I can't manage to trigger
            # that. To be one the safe side let's catch SystemExit here anyway.
            exit_value = e.args
        if not interactive:
            curses.raw(False)
            return (exit_value, clirepl.getstdout())
    else:
        sys.path.insert(0, "")
        try:
            clirepl.startup()
        except OSError as e:
            # Handle this with a proper error message.
            if e.errno != errno.ENOENT:
                raise
github ivanov / bipython / bipython / __init__.py View on Github external
def start(main_loop, user_data):
        if exec_args:
            bpargs.exec_code(interpreter, exec_args)
            if not options.interactive:
                raise urwid.ExitMainLoop()
        if not exec_args:
            sys.path.insert(0, '')
            # this is CLIRepl.startup inlined.
            filename = os.environ.get('PYTHONSTARTUP')
            if filename and os.path.isfile(filename):
                with open(filename, 'r') as f:
                    if py3:
                        interpreter.runsource(f.read(), filename, 'exec')
                    else:
                        interpreter.runsource(f.read(), filename, 'exec',
                                              encode=False)

        if banner is not None:
            repl.write(banner)
github bpython / bpython / bpython / curtsies.py View on Github external
def main(args=None, locals_=None, banner=None):
    config, options, exec_args = bpargs.parse(args, (
        'scroll options', None, [
            Option('--log', '-L', action='store_true',
                help=_("log debug messages to bpython-curtsies.log")),
            Option('--type', '-t', action='store_true',
                help=_("enter lines of file as though interactively typed")),
            ]))
    if options.log:
        import logging
        logging.basicConfig(filename='scroll.log', level=logging.DEBUG)

    interp = None
    paste = None
    if exec_args:
        assert options, "don't pass in exec_args without options"
        exit_value = 0
        if options.type:
github bpython / bpython / bpython / cli.py View on Github external
def main(args=None, locals_=None):
    global stdscr

    setlocale(LC_ALL, '')

    config, options, exec_args = bpython.args.parse(args)

    # Save stdin, stdout and stderr for later restoration
    orig_stdin = sys.stdin
    orig_stdout = sys.stdout
    orig_stderr = sys.stderr

    try:
        o = curses_wrapper(main_curses, exec_args, config,
                           options.interactive, locals_)
    finally:
        sys.stdin = orig_stdin
        sys.stderr = orig_stderr
        sys.stdout = orig_stdout

# Fake stdout data so everything's still visible after exiting
    if config.flush_output and not options.quiet: