Пример #1
0
 def run_ipython():            
     import IPython
     from IPython.frontend.terminal.embed import InteractiveShellEmbed
     from django.conf import settings
     try:
         imported_objects = import_objects(options, self.style)
         cfgfile = "%s/.config/ipython/profile_default/ipython_config.py" % os.environ['HOME']
         cfg = IPython.config.loader.PyFileConfigLoader(cfgfile).load_config()
         appname = "Welcome to the %s Shell.\n" % getattr(settings, "APPLICATION_NAME", "")
         ipshell = InteractiveShellEmbed(config=cfg, banner1=appname, user_ns=imported_objects)
         # An example how to define magics
         # the function _toggle_logging has to be provided by the PYTHONSTARTUP script,
         # see django_extensions/management/shells.py
         try:
             ipshell.define_magic('toggle_logging', imported_objects['_toggle_logging'])
         except:
             pass
         ipshell()
     except ImportError:
         # IPython < 0.11
         # Explicitly pass an empty list as arguments, because otherwise
         # IPython would use sys.argv from this script.
         # Notebook not supported for IPython < 0.11.
         from IPython.Shell import IPShell
         imported_objects = import_objects(options, self.style)
         shell = IPShell(argv=[], user_ns=imported_objects)
         shell.mainloop()
Пример #2
0
 def run_ipython():
     try:
         from IPython import embed
         imported_objects = import_objects(options, self.style)
         embed(user_ns=imported_objects)
     except ImportError:
         # IPython < 0.11
         # Explicitly pass an empty list as arguments, because otherwise
         # IPython would use sys.argv from this script.
         # Notebook not supported for IPython < 0.11.
         from IPython.Shell import IPShell
         imported_objects = import_objects(options, self.style)
         shell = IPShell(argv=[], user_ns=imported_objects)
         shell.mainloop()
Пример #3
0
 def run_ipython():
     try:
         from IPython import embed
         imported_objects = import_objects(options, self.style)
         embed(user_ns=imported_objects)
     except ImportError:
         # IPython < 0.11
         # Explicitly pass an empty list as arguments, because otherwise
         # IPython would use sys.argv from this script.
         # Notebook not supported for IPython < 0.11.
         from IPython.Shell import IPShell
         imported_objects = import_objects(options, self.style)
         shell = IPShell(argv=[], user_ns=imported_objects)
         shell.mainloop()
 def run_kernel():
     imported_objects = import_objects(options, self.style)
     kwargs = dict(argv=[], user_ns=imported_objects)
     connection_file = options.get("connection_file")
     if connection_file:
         kwargs["connection_file"] = connection_file
     start_kernel(**kwargs)
Пример #5
0
        def run_plain():
            # Using normal Python shell
            import code
            imported_objects = import_objects(options, self.style)
            try:
                # Try activating rlcompleter, because it's handy.
                import readline
            except ImportError:
                pass
            else:
                # We don't have to wrap the following import in a 'try', because
                # we already know 'readline' was imported successfully.
                import rlcompleter
                readline.set_completer(
                    rlcompleter.Completer(imported_objects).complete)
                readline.parse_and_bind("tab:complete")

            # We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system
            # conventions and get $PYTHONSTARTUP first then import user.
            if use_pythonrc:
                pythonrc = os.environ.get("PYTHONSTARTUP")
                if pythonrc and os.path.isfile(pythonrc):
                    try:
                        execfile(pythonrc)
                    except NameError:
                        pass
                # This will import .pythonrc.py as a side-effect
                import user  # NOQA
            code.interact(local=imported_objects)
Пример #6
0
        def run_plain():
            # Using normal Python shell
            import code
            imported_objects = import_objects(options, self.style)
            try:
                # Try activating rlcompleter, because it's handy.
                import readline
            except ImportError:
                pass
            else:
                # We don't have to wrap the following import in a 'try', because
                # we already know 'readline' was imported successfully.
                import rlcompleter
                readline.set_completer(rlcompleter.Completer(imported_objects).complete)
                readline.parse_and_bind("tab:complete")

            # We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system
            # conventions and get $PYTHONSTARTUP first then import user.
            if use_pythonrc:
                pythonrc = os.environ.get("PYTHONSTARTUP")
                if pythonrc and os.path.isfile(pythonrc):
                    global_ns = {}
                    with open(pythonrc) as rcfile:
                        try:
                            six.exec_(compile(rcfile.read(), pythonrc, 'exec'), global_ns)
                            imported_objects.update(global_ns)
                        except NameError:
                            pass
                # This will import .pythonrc.py as a side-effect
                try:
                    import user  # NOQA
                except ImportError:
                    pass
            code.interact(local=imported_objects)
Пример #7
0
 def run_ptipython():
     imported_objects = import_objects(options, self.style)
     history_filename = os.path.expanduser('~/.ptpython_history')
     embed(user_ns=imported_objects,
           history_filename=history_filename,
           vi_mode=options.get('vi_mode', False),
           configure=run_config)
Пример #8
0
def start_django(reloader, main_func, *args, **kwargs):
    ensure_echo_on()

    main_func = check_errors(main_func)
    django_main_thread = threading.Thread(target=main_func,
                                          args=args,
                                          kwargs=kwargs,
                                          name='django-main-thread')
    reloader_thread = ReloaderThread(reloader=reloader,
                                     django_main_thread=django_main_thread)

    try:
        from django_extensions.management.shells import import_objects
    except ImportError:
        kernel_user_ns = {}
    else:
        kernel_user_ns = import_objects({'quiet_load': True}, style=None)

    django_main_thread.setDaemon(True)
    reloader_thread.setDaemon(True)
    django_main_thread.start()
    reloader_thread.start()
    kernelapp.launch_new_instance(argv=[],
                                  user_ns=kernel_user_ns,
                                  quiet=False,
                                  use_experimental_completions=False)
 def run_kernel():
     from IPython import release
     if release.version_info[0] < 2:
         print(self.style.ERROR("--kernel requires at least IPython version 2.0"))
         return
     from IPython import embed_kernel
     imported_objects = import_objects(options, self.style)
     embed_kernel(local_ns=imported_objects)
Пример #10
0
def load_ipython_extension(ipython):
    from django.core.management.color import no_style
    from django_extensions.management.shells import import_objects

    imported_objects = import_objects(
        options={'dont_load': []},
        style=no_style(),
    )
    ipython.push(imported_objects)
 def run_ptipython():
     imported_objects = import_objects(options, self.style)
     history_filename = os.path.expanduser("~/.ptpython_history")
     embed(
         user_ns=imported_objects,
         history_filename=history_filename,
         vi_mode=options.get("vi_mode", False),
         configure=run_config,
     )
Пример #12
0
 def run_kernel():
     from IPython import release
     if release.version_info[0] < 2:
         print(
             self.style.ERROR(
                 "--kernel requires at least IPython version 2.0"))
         return
     from IPython import embed_kernel
     imported_objects = import_objects(options, self.style)
     embed_kernel(local_ns=imported_objects)
Пример #13
0
 def run_kernel():
     imported_objects = import_objects(options, self.style)
     kwargs = dict(
         argv=[],
         user_ns=imported_objects,
     )
     connection_file = options.get('connection_file')
     if connection_file:
         kwargs['connection_file'] = connection_file
     start_kernel(**kwargs)
Пример #14
0
def load_ipython_extension(ipython):
    import sys
    sys.path[0:0] = [
        '/home/jsmits/Development/repos/delfland',
        '/home/jsmits/.buildout/eggs/djangorecipe-1.3-py2.7.egg',
        '/home/jsmits/.buildout/eggs/Django-1.4.3-py2.7.egg',
        '/home/jsmits/.buildout/eggs/zc.recipe.egg-1.2.2-py2.7.egg',
        '/home/jsmits/.buildout/eggs/zc.buildout-1.4.4-py2.7.egg',
        '/usr/lib/python2.7/dist-packages',
        '/home/jsmits/.buildout/eggs/simplejson-2.4.0-py2.7-linux-x86_64.egg',
        '/home/jsmits/.buildout/eggs/Werkzeug-0.8.3-py2.7.egg',
        '/home/jsmits/.buildout/eggs/python_memcached-1.48-py2.7.egg',
        '/home/jsmits/.buildout/eggs/lizard_ui-4.16-py2.7.egg',
        '/home/jsmits/.buildout/eggs/lizard_map-4.16-py2.7.egg',
        '/home/jsmits/Development/repos/delfland/src/controlnext',
        '/home/jsmits/.buildout/eggs/gunicorn-0.13.4-py2.7.egg',
        '/home/jsmits/.buildout/eggs/django_nose-1.1-py2.7.egg',
        '/home/jsmits/.buildout/eggs/django_extensions-1.0.1-py2.7.egg',
        '/home/jsmits/.buildout/eggs/django_celery-3.0.11-py2.7.egg',
        '/home/jsmits/.buildout/eggs/South-0.7.6-py2.7.egg',
        '/home/jsmits/.buildout/eggs/raven-2.0.3-py2.7.egg',
        '/home/jsmits/.buildout/eggs/lizard_security-0.5-py2.7.egg',
        '/home/jsmits/.buildout/eggs/docutils-0.8-py2.7.egg',
        '/home/jsmits/.buildout/eggs/django_compressor-1.2-py2.7.egg',
        '/home/jsmits/.buildout/eggs/django_staticfiles-1.2.1-py2.7.egg',
        '/home/jsmits/.buildout/eggs/BeautifulSoup-3.2.1-py2.7.egg',
        '/home/jsmits/.buildout/eggs/pkginfo-0.8-py2.7.egg',
        '/home/jsmits/.buildout/eggs/mock-0.8.0-py2.7.egg',
        '/home/jsmits/.buildout/eggs/lizard_help-0.4-py2.7.egg',
        '/home/jsmits/.buildout/eggs/iso8601-0.1.4-py2.7.egg',
        '/home/jsmits/.buildout/eggs/djangorestframework-2.1.12-py2.7.egg',
        '/home/jsmits/.buildout/eggs/django_piston-0.2.2-py2.7.egg',
        '/home/jsmits/.buildout/eggs/django_jsonfield-0.8.11-py2.7.egg',
        '/home/jsmits/.buildout/eggs/Pillow-1.7.7-py2.7-linux-x86_64.egg',
        '/home/jsmits/.buildout/eggs/factory_boy-1.2.0-py2.7.egg',
        '/home/jsmits/.buildout/eggs/pandas-0.10.1-py2.7-linux-x86_64.egg',
        '/home/jsmits/.buildout/eggs/lizard_fewsjdbc-2.14-py2.7.egg',
        '/home/jsmits/.buildout/eggs/celery-3.0.11-py2.7.egg',
        '/home/jsmits/.buildout/eggs/django_tls-0.0.2-py2.7.egg',
        '/home/jsmits/.buildout/eggs/django_appconf-0.5-py2.7.egg',
        '/home/jsmits/.buildout/eggs/lizard_task-0.15-py2.7.egg',
        '/home/jsmits/.buildout/eggs/kombu-2.4.7-py2.7.egg',
        '/home/jsmits/.buildout/eggs/billiard-2.7.3.18-py2.7-linux-x86_64.egg',
        '/home/jsmits/.buildout/eggs/amqplib-1.0.2-py2.7.egg',
        '/home/jsmits/.buildout/eggs/anyjson-0.3.3-py2.7.egg',
        '/home/jsmits/Development/repos/delfland',
    ]

    from django.core.management.color import no_style
    from django_extensions.management.shells import import_objects
    imported_objects = import_objects(options={'dont_load': []},
        style=no_style())
    print imported_objects
    ipython.push(imported_objects)
Пример #15
0
        def run_plain():
            # Using normal Python shell
            import code
            imported_objects = import_objects(options, self.style)
            try:
                # Try activating rlcompleter, because it's handy.
                import readline
            except ImportError:
                pass
            else:
                # We don't have to wrap the following import in a 'try', because
                # we already know 'readline' was imported successfully.
                import rlcompleter
                readline.set_completer(
                    rlcompleter.Completer(imported_objects).complete)
                readline.parse_and_bind("tab:complete")

            # We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system
            # conventions and get $PYTHONSTARTUP first then import user.
            if use_pythonrc:
                pythonrc = os.environ.get("PYTHONSTARTUP")
                if pythonrc and os.path.isfile(pythonrc):
                    global_ns = {}
                    with open(pythonrc) as rcfile:
                        try:
                            six.exec_(compile(rcfile.read(), pythonrc, 'exec'),
                                      global_ns)
                            imported_objects.update(global_ns)
                        except NameError:
                            pass
                # This will import .pythonrc.py as a side-effect
                try:
                    import user  # NOQA
                except ImportError:
                    pass
            shellplus_imports = {}
            spfile = 'apps/rss_feeds/management/shellplus_imports.py'
            with open(spfile) as rcfile:
                six.exec_(compile(rcfile.read(), spfile, 'exec'),
                          shellplus_imports)
                imported_objects.update(shellplus_imports)
            code.interact(local=imported_objects)
Пример #16
0
 def get_imported_objects(self, options):
     imported_objects = import_objects(options, self.style)
     if self.tests_mode:
         # save imported objects so we can run tests against it later
         self.tests_imported_objects = imported_objects
     return imported_objects
Пример #17
0
    def handle_noargs(self, **options):
        use_notebook = options.get('notebook', False)
        use_ipython = options.get('ipython', use_notebook)
        use_plain = options.get('plain', False)
        use_pythonrc = not options.get('no_pythonrc', True)

        if options.get("print_sql", False):
            # Code from http://gist.github.com/118990
            from django.db.backends import util
            try:
                import sqlparse
            except ImportError:
                sqlparse = None

            class PrintQueryWrapper(util.CursorDebugWrapper):
                def execute(self, sql, params=()):
                    starttime = time.time()
                    try:
                        return self.cursor.execute(sql, params)
                    finally:
                        raw_sql = self.db.ops.last_executed_query(self.cursor, sql, params)
                        execution_time = time.time() - starttime
                        if sqlparse:
                            print sqlparse.format(raw_sql, reindent=True)
                        else:
                            print raw_sql
                        print
                        print 'Execution time: %.6fs [Database: %s]' % (execution_time, self.db.alias)
                        print

            util.CursorDebugWrapper = PrintQueryWrapper

        # Set up a dictionary to serve as the environment for the shell, so
        # that tab completion works on objects that are imported at runtime.
        # See ticket 5082.
        try:
            if use_plain:
                # Don't bother loading B/IPython, because the user wants plain Python.
                raise ImportError
            try:
                if use_ipython:
                    # User wants IPython
                    raise ImportError
                from bpython import embed
                imported_objects = import_objects(options, self.style)
                embed(imported_objects)
            except ImportError:
                try:
                    if use_notebook:
                        from django.conf import settings
                        from IPython.frontend.html.notebook import notebookapp
                        app = notebookapp.NotebookApp.instance()
                        ipython_arguments = getattr(
                            settings,
                            'IPYTHON_ARGUMENTS',
                            ['--ext',
                             'django_extensions.management.notebook_extension'])
                        app.initialize(ipython_arguments)
                        app.start()
                    else:
                        from IPython import embed
                        imported_objects = import_objects(options, self.style)
                        embed(user_ns=imported_objects)
                except ImportError:
                    # IPython < 0.11
                    # Explicitly pass an empty list as arguments, because otherwise
                    # IPython would use sys.argv from this script.
                    # Notebook not supported for IPython < 0.11.
                    try:
                        from IPython.Shell import IPShell
                        imported_objects = import_objects(options, self.style)
                        shell = IPShell(argv=[], user_ns=imported_objects)
                        shell.mainloop()
                    except ImportError:
                        # IPython not found at all, raise ImportError
                        raise
        except ImportError:
            # Using normal Python shell
            import code
            imported_objects = import_objects(options, self.style)
            try:
                # Try activating rlcompleter, because it's handy.
                import readline
            except ImportError:
                pass
            else:
                # We don't have to wrap the following import in a 'try', because
                # we already know 'readline' was imported successfully.
                import rlcompleter
                readline.set_completer(rlcompleter.Completer(imported_objects).complete)
                readline.parse_and_bind("tab:complete")

            # We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system
            # conventions and get $PYTHONSTARTUP first then import user.
            if use_pythonrc:
                pythonrc = os.environ.get("PYTHONSTARTUP")
                if pythonrc and os.path.isfile(pythonrc):
                    try:
                        execfile(pythonrc)
                    except NameError:
                        pass
                # This will import .pythonrc.py as a side-effect
                import user
            code.interact(local=imported_objects)
Пример #18
0
    def handle_noargs(self, **options):
        use_notebook = options.get('notebook', False)
        use_ipython = options.get('ipython', False)
        use_bpython = options.get('bpython', False)
        use_plain = options.get('plain', False)
        use_pythonrc = not options.get('no_pythonrc', True)
        auto_reload = options.get('autoreload') or getattr(
            settings, 'AUTO_RELOAD_SHELL', False)
        if auto_reload:
            # Transparently reload modules on filesystem changes via threading
            if not _listener_enabled:
                raise CommandError(
                    "Watchdog is required to use auto reload shell_plus.  Install via pip. (pip install watchdog)"
                )

            autoreload_path = os.environ.get(
                'VIRTUAL_ENV', getattr(settings, 'PROJECT_ROOT', False))
            if not autoreload_path:
                raise CommandError("""To reload shell_plus automatically,
                                    you must either work in an activated
                                    Python VIRTUALENV or specify a path in your filesystem
                                    as 'PROJECT_ROOT' in your Django settings"""
                                   )

            def listen_for_changes(shell_globals, project_root, model_globals):
                # Begin thread which listens for file system changes via Watchdog library
                event_handler = ReloaderEventHandler(
                    project_root=project_root,
                    model_globals=model_globals,
                    shell_globals=shell_globals)
                observer_thread.schedule(event_handler,
                                         path=project_root,
                                         recursive=True)
                observer_thread.start()

        if options.get("print_sql", False):
            # Code from http://gist.github.com/118990
            from django.db.backends import util
            sqlparse = None
            try:
                import sqlparse
            except ImportError:
                pass

            class PrintQueryWrapper(util.CursorDebugWrapper):
                def execute(self, sql, params=()):
                    starttime = time.time()
                    try:
                        return self.cursor.execute(sql, params)
                    finally:
                        execution_time = time.time() - starttime
                        raw_sql = self.db.ops.last_executed_query(
                            self.cursor, sql, params)
                        if sqlparse:
                            print sqlparse.format(raw_sql, reindent=True)
                        else:
                            print raw_sql
                        print
                        print 'Execution time: %.6fs [Database: %s]' % (
                            execution_time, self.db.alias)
                        print

            util.CursorDebugWrapper = PrintQueryWrapper

        global_model_scope = defaultdict(list)
        imported_objects = import_objects(
            options, self.style, global_model_scope=global_model_scope)

        def run_notebook():
            from django.conf import settings
            from IPython.frontend.html.notebook import notebookapp
            app = notebookapp.NotebookApp.instance()
            ipython_arguments = getattr(
                settings, 'IPYTHON_ARGUMENTS',
                ['--ext', 'django_extensions.management.notebook_extension'])
            app.initialize(ipython_arguments)
            app.start()

        def run_plain():
            # Using normal Python shell
            import code
            try:
                # Try activating rlcompleter, because it's handy.
                import readline
            except ImportError:
                pass
            else:
                # We don't have to wrap the following import in a 'try', because
                # we already know 'readline' was imported successfully.
                import rlcompleter
                readline.set_completer(
                    rlcompleter.Completer(imported_objects).complete)
                readline.parse_and_bind("tab:complete")

            # We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system
            # conventions and get $PYTHONSTARTUP first then import user.
            if use_pythonrc:
                pythonrc = os.environ.get("PYTHONSTARTUP")
                if pythonrc and os.path.isfile(pythonrc):
                    try:
                        execfile(pythonrc)
                    except NameError:
                        pass
                # This will import .pythonrc.py as a side-effect
                import user  # NOQA
            code.interact(local=imported_objects)

        def run_bpython():
            from bpython import embed
            embed(imported_objects)

        def run_ipython():
            try:
                from IPython import embed
                embed(user_ns=imported_objects)
            except ImportError:
                # IPython < 0.11
                # Explicitly pass an empty list as arguments, because otherwise
                # IPython would use sys.argv from this script.
                # Notebook not supported for IPython < 0.11.
                from IPython.Shell import IPShell
                shell = IPShell(argv=[], user_ns=imported_objects)
                shell.mainloop()

        if use_notebook:
            run_notebook()
        else:
            if auto_reload:
                listen_for_changes(imported_objects, autoreload_path,
                                   global_model_scope)

            if use_plain:
                run_plain()
            elif use_ipython:
                run_ipython()
            elif use_bpython:
                run_bpython()
            else:
                for func in (run_ipython, run_bpython, run_plain):
                    try:
                        func()
                    except ImportError:
                        continue
                    else:
                        break
                else:
                    import traceback
                    traceback.print_exc()
                    print self.style.ERROR(
                        "Could not load any interactive Python environment.")
Пример #19
0
 def get_imported_objects(self, options):
     imported_objects = import_objects(options, self.style)
     if self.tests_mode:
         # save imported objects so we can run tests against it later
         self.tests_imported_objects = imported_objects
     return imported_objects
Пример #20
0
 def run_bpython():
     from bpython import embed
     imported_objects = import_objects(options, self.style)
     embed(imported_objects)
Пример #21
0
 def run_ipython():
     imported_objects = import_objects(options, self.style)
     shell = IPShell(argv=[], user_ns=imported_objects)
     shell.mainloop()
Пример #22
0
 def run_ipython():
     imported_objects = import_objects(options, self.style)
     embed(user_ns=imported_objects)
Пример #23
0
    def handle_noargs(self, **options):
        use_notebook = options.get('notebook', False)
        use_ipython = options.get('ipython', False)
        use_bpython = options.get('bpython', False)
        use_plain = options.get('plain', False)
        use_pythonrc = not options.get('no_pythonrc', True)
        auto_reload = options.get('autoreload') or getattr(settings, 'AUTO_RELOAD_SHELL', False)
        if auto_reload:
            # Transparently reload modules on filesystem changes via threading
            if not _listener_enabled:
                raise CommandError("Watchdog is required to use auto reload shell_plus.  Install via pip. (pip install watchdog)")

            autoreload_path = os.environ.get('VIRTUAL_ENV', getattr(settings, 'PROJECT_ROOT', False))
            if not autoreload_path:
                raise CommandError("""To reload shell_plus automatically,
                                    you must either work in an activated
                                    Python VIRTUALENV or specify a path in your filesystem
                                    as 'PROJECT_ROOT' in your Django settings""")

            def listen_for_changes(shell_globals, project_root, model_globals):
                # Begin thread which listens for file system changes via Watchdog library
                event_handler = ReloaderEventHandler(project_root=project_root, model_globals=model_globals, shell_globals=shell_globals)
                observer_thread.schedule(event_handler, path=project_root, recursive=True)
                observer_thread.start()

        if options.get("print_sql", False):
            # Code from http://gist.github.com/118990
            from django.db.backends import util
            sqlparse = None
            try:
                import sqlparse
            except ImportError:
                pass

            class PrintQueryWrapper(util.CursorDebugWrapper):
                def execute(self, sql, params=()):
                    starttime = time.time()
                    try:
                        return self.cursor.execute(sql, params)
                    finally:
                        execution_time = time.time() - starttime
                        raw_sql = self.db.ops.last_executed_query(self.cursor, sql, params)
                        if sqlparse:
                            print sqlparse.format(raw_sql, reindent=True)
                        else:
                            print raw_sql
                        print
                        print 'Execution time: %.6fs [Database: %s]' % (execution_time, self.db.alias)
                        print

            util.CursorDebugWrapper = PrintQueryWrapper

        global_model_scope = defaultdict(list)
        imported_objects = import_objects(options, self.style, global_model_scope=global_model_scope)

        def run_notebook():
            from django.conf import settings
            from IPython.frontend.html.notebook import notebookapp
            app = notebookapp.NotebookApp.instance()
            ipython_arguments = getattr(settings, 'IPYTHON_ARGUMENTS', ['--ext', 'django_extensions.management.notebook_extension'])
            app.initialize(ipython_arguments)
            app.start()

        def run_plain():
            # Using normal Python shell
            import code
            try:
                # Try activating rlcompleter, because it's handy.
                import readline
            except ImportError:
                pass
            else:
                # We don't have to wrap the following import in a 'try', because
                # we already know 'readline' was imported successfully.
                import rlcompleter
                readline.set_completer(rlcompleter.Completer(imported_objects).complete)
                readline.parse_and_bind("tab:complete")

            # We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system
            # conventions and get $PYTHONSTARTUP first then import user.
            if use_pythonrc:
                pythonrc = os.environ.get("PYTHONSTARTUP")
                if pythonrc and os.path.isfile(pythonrc):
                    try:
                        execfile(pythonrc)
                    except NameError:
                        pass
                # This will import .pythonrc.py as a side-effect
                import user  # NOQA
            code.interact(local=imported_objects)

        def run_bpython():
            from bpython import embed
            embed(imported_objects)

        def run_ipython():
            try:
                from IPython import embed
                embed(user_ns=imported_objects)
            except ImportError:
                # IPython < 0.11
                # Explicitly pass an empty list as arguments, because otherwise
                # IPython would use sys.argv from this script.
                # Notebook not supported for IPython < 0.11.
                from IPython.Shell import IPShell
                shell = IPShell(argv=[], user_ns=imported_objects)
                shell.mainloop()

        if use_notebook:
            run_notebook()
        else:
            if auto_reload:
                listen_for_changes(imported_objects, autoreload_path, global_model_scope)

            if use_plain:
                run_plain()
            elif use_ipython:
                run_ipython()
            elif use_bpython:
                run_bpython()
            else:
                for func in (run_ipython, run_bpython, run_plain):
                    try:
                        func()
                    except ImportError:
                        continue
                    else:
                        break
                else:
                    import traceback
                    traceback.print_exc()
                    print self.style.ERROR("Could not load any interactive Python environment.")
Пример #24
0
 def run_ptpython():
     imported_objects = import_objects(options, self.style)
     history_filename = os.path.expanduser('~/.ptpython_history')
     embed(globals=imported_objects, history_filename=history_filename,
           vi_mode=options.get('vi_mode', False))
 def run_ipython():
     imported_objects = import_objects(options, self.style)
     ipython_arguments = getattr(settings, 'IPYTHON_ARGUMENTS', [])
     start_ipython(argv=ipython_arguments, user_ns=imported_objects)
 def run_ipython():
     imported_objects = import_objects(options, self.style)
     ipython_arguments = self.get_ipython_arguments(options)
     start_ipython(argv=ipython_arguments, user_ns=imported_objects)
Пример #27
0
 def run_ipython():
     imported_objects = import_objects(options, self.style)
     ipython_arguments = getattr(settings, 'IPYTHON_ARGUMENTS', [])
     start_ipython(argv=ipython_arguments, user_ns=imported_objects)
 def run_ipython():
     imported_objects = import_objects(options, self.style)
     ipython_arguments = self.get_ipython_arguments(options)
     start_ipython(argv=ipython_arguments,
                   user_ns=imported_objects)
Пример #29
0
 def run_bpython():
     from bpython import embed
     imported_objects = import_objects(options, self.style)
     embed(imported_objects)
Пример #30
0
 def run_kernel():
     imported_objects = import_objects(options, self.style)
     if options.get('connection_file'):
         start_kernel(argv=[], user_ns=imported_objects, connection_file=options.get('connection_file'))
     else:
         start_kernel(argv=[], user_ns=imported_objects)
Пример #31
0
 def get_imported_objects(self, options):
     return import_objects(options, self.style)
 def run_kernel():
     imported_objects = import_objects(options, self.style)
     embed_kernel(local_ns=imported_objects)
 def run_ipython():
     imported_objects = import_objects(options, self.style)
     embed(user_ns=imported_objects)
Пример #34
0
 def get_imported_objects(self, options):
     return import_objects(options, self.style)
Пример #35
0
 def run_kernel():
     imported_objects = import_objects(options, self.style)
     embed_kernel(local_ns=imported_objects)
 def run_ipython():
     imported_objects = import_objects(options, self.style)
     shell = IPShell(argv=[], user_ns=imported_objects)
     shell.mainloop()