Commits

Haim Ashkenazi  committed 835d844

A proof of concept for enabling bpython support in pylons.

This is just a proof of concept. Still need to:
- find out what everything does (e.g, locals,
paste.registry.restorer.restoration_end(), etc) :)
- decide on the workflow of selecting shell
- tests?

  • Participants
  • Parent commits 169245b

Comments (0)

Files changed (1)

File pylons/commands.py

     group_name = 'pylons'
 
     parser = Command.standard_parser(simulate=True)
+    parser.add_option('-b', '--bpython',
+                      action='store_true',
+                      dest='use_bpython',
+                      help="Try to use bpython (instead of ipython)")
+
     parser.add_option('-d', '--disable-ipython',
                       action='store_true',
                       dest='disable_ipython',
             'paste.fixture wrapped around wsgiapp')
 
         try:
-            if self.options.disable_ipython:
-                raise ImportError()
+            # first choice to bpython if it was requested
+            if self.options.use_bpython:
+                # in bpython 0.9.6.2 bpython.embed doesn't pass 
+                # the banner to the shell.
+                from bpython import cli
+                try:
+                    cli.main(locals_=locs, args=['-i', '-q'], banner=banner)
+                finally:
+                    paste.registry.restorer.restoration_end()
+            else:
+                if self.options.disable_ipython:
+                    raise ImportError()
 
-            # try to use IPython if possible
-            from IPython.Shell import IPShellEmbed
+                # try to use IPython if possible
+                from IPython.Shell import IPShellEmbed
 
-            shell = IPShellEmbed(argv=self.args)
-            shell.set_banner(shell.IP.BANNER + '\n\n' + banner)
-            try:
-                shell(local_ns=locs, global_ns={})
-            finally:
-                paste.registry.restorer.restoration_end()
+                shell = IPShellEmbed(argv=self.args)
+                shell.set_banner(shell.IP.BANNER + '\n\n' + banner)
+                try:
+                    shell(local_ns=locs, global_ns={})
+                finally:
+                    paste.registry.restorer.restoration_end()
         except ImportError:
             import code
             py_prefix = sys.platform.startswith('java') and 'J' or 'P'