##// 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 533 if name in self.hotnames:
534 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 537 """ Make and start a new ipython instance.
538 538
539 539 This can be called even without having an already initialized
@@ -542,7 +542,7 b' def launch_new_instance(user_ns = None):'
542 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 546 ses.mainloop()
547 547
548 548
@@ -578,7 +578,7 b' def make_user_global_ns(ns = None):'
578 578 return ns
579 579
580 580
581 def make_session(user_ns = None):
581 def make_session(user_ns = None, shellclass = None):
582 582 """Makes, but does not launch an IPython session.
583 583
584 584 Later on you can call obj.mainloop() on the returned object.
@@ -591,6 +591,6 b' def make_session(user_ns = None):'
591 591 WARNING: This should *not* be run when a session exists already."""
592 592
593 593 import IPython.Shell
594 return IPython.Shell.start(user_ns)
595
596
594 if shellclass is None:
595 return IPython.Shell.start(user_ns)
596 return shellclass(user_ns = user_ns)
@@ -6,27 +6,37 b' user namespace.'
6 6 """
7 7
8 8 import sys
9 sys.path.append('..')
9 sys.path.insert(1,'..')
10 10
11 11 import IPython.ipapi
12 12
13 my_ns = dict(a=10)
14 13
15 ses = IPython.ipapi.make_session(my_ns)
16 14
17 # Now get the ipapi instance, to be stored somewhere in your program for manipulation of the running
18 # IPython session. See http://ipython.scipy.org/moin/IpythonExtensionApi
19
20 ip = ses.IP.getapi()
21
22 # let's play with the ipapi a bit, creating a magic function for a soon-to-be-started IPython
23 def mymagic_f(self,s):
24 print "mymagic says",s
25
26 ip.expose_magic("mymagic",mymagic_f)
27
28 # And finally, start the IPython interaction! This will block until you say Exit.
29
30 ses.mainloop()
31
32 print "IPython session finished! namespace content:",my_ns
15 def test_session(shellclass):
16 print "*****************\nLaunch shell for",shellclass
17 my_ns = dict(a=10)
18 ses = IPython.ipapi.make_session(my_ns)
19
20 # Now get the ipapi instance, to be stored somewhere in your program for manipulation of the running
21 # IPython session. See http://ipython.scipy.org/moin/IpythonExtensionApi
22
23 ip = ses.IP.getapi()
24
25 # let's play with the ipapi a bit, creating a magic function for a soon-to-be-started IPython
26 def mymagic_f(self,s):
27 print "mymagic says",s
28
29 ip.expose_magic("mymagic",mymagic_f)
30
31 # And finally, start the IPython interaction! This will block until you say Exit.
32
33 ses.mainloop()
34
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