##// END OF EJS Templates
ipapi: allow specifying shell class in launch_new_instance & make_new instance. Use this in test_embed.py
Ville M. Vainio -
Show More
@@ -533,7 +533,7 b' class DebugTools:'
533 if name in self.hotnames:
533 if name in self.hotnames:
534 self.debug_stack( "HotName '%s' caught" % name)
534 self.debug_stack( "HotName '%s' caught" % name)
535
535
536 def launch_new_instance(user_ns = None):
536 def launch_new_instance(user_ns = None,shellclass = None):
537 """ Make and start a new ipython instance.
537 """ Make and start a new ipython instance.
538
538
539 This can be called even without having an already initialized
539 This can be called even without having an already initialized
@@ -542,7 +542,7 b' def launch_new_instance(user_ns = None):'
542 This is also used as the egg entry point for the 'ipython' script.
542 This is also used as the egg entry point for the 'ipython' script.
543
543
544 """
544 """
545 ses = make_session(user_ns)
545 ses = make_session(user_ns,shellclass)
546 ses.mainloop()
546 ses.mainloop()
547
547
548
548
@@ -578,7 +578,7 b' def make_user_global_ns(ns = None):'
578 return ns
578 return ns
579
579
580
580
581 def make_session(user_ns = None):
581 def make_session(user_ns = None, shellclass = None):
582 """Makes, but does not launch an IPython session.
582 """Makes, but does not launch an IPython session.
583
583
584 Later on you can call obj.mainloop() on the returned object.
584 Later on you can call obj.mainloop() on the returned object.
@@ -591,6 +591,6 b' def make_session(user_ns = None):'
591 WARNING: This should *not* be run when a session exists already."""
591 WARNING: This should *not* be run when a session exists already."""
592
592
593 import IPython.Shell
593 import IPython.Shell
594 if shellclass is None:
594 return IPython.Shell.start(user_ns)
595 return IPython.Shell.start(user_ns)
595
596 return shellclass(user_ns = user_ns)
596
@@ -6,12 +6,15 b' user namespace.'
6 """
6 """
7
7
8 import sys
8 import sys
9 sys.path.append('..')
9 sys.path.insert(1,'..')
10
10
11 import IPython.ipapi
11 import IPython.ipapi
12
12
13 my_ns = dict(a=10)
14
13
14
15 def test_session(shellclass):
16 print "*****************\nLaunch shell for",shellclass
17 my_ns = dict(a=10)
15 ses = IPython.ipapi.make_session(my_ns)
18 ses = IPython.ipapi.make_session(my_ns)
16
19
17 # Now get the ipapi instance, to be stored somewhere in your program for manipulation of the running
20 # Now get the ipapi instance, to be stored somewhere in your program for manipulation of the running
@@ -29,4 +32,11 b' ip.expose_magic("mymagic",mymagic_f)'
29
32
30 ses.mainloop()
33 ses.mainloop()
31
34
32 print "IPython session finished! namespace content:",my_ns
35 print "IPython session for shell ",shellclass," finished! namespace content:"
36 for k,v in my_ns.items():
37 print k,':',str(v)[:80].rstrip()
38
39 import IPython.Shell
40
41 test_session(shellclass = None)
42 test_session(IPython.Shell._select_shell(['ipython', '-q4thread']))
General Comments 0
You need to be logged in to leave comments. Login now