From 1e3200269cda3ec0763dddc6f9442242265fd4f9 2008-03-13 15:18:25 From: Ville M. Vainio Date: 2008-03-13 15:18:25 Subject: [PATCH] merge from trunk --- diff --git a/IPython/Extensions/ipy_completers.py b/IPython/Extensions/ipy_completers.py index f1b3f78..e5644cb 100644 --- a/IPython/Extensions/ipy_completers.py +++ b/IPython/Extensions/ipy_completers.py @@ -211,15 +211,10 @@ def hg_completer(self,event): -bzr_commands = """ -add annotate bind branch break-lock bundle-revisions cat check -checkout commit conflicts deleted diff export gannotate gbranch -gcommit gdiff help ignore ignored info init init-repository inventory -log merge missing mkdir mv nick pull push reconcile register-branch -remerge remove renames resolve revert revno root serve sign-my-commits -status testament unbind uncommit unknowns update upgrade version -version-info visualise whoami -""" +def bzr_commands(): + out = os.popen('bzr help commands') + return [l.split()[0] for l in out] + def bzr_completer(self,event): """ Completer for bazaar commands """ @@ -232,7 +227,7 @@ def bzr_completer(self,event): param = cmd_param[-1] output_file = (param == '--output=') if cmd == 'help': - return bzr_commands.split() + return bzr_commands() elif cmd in ['bundle-revisions','conflicts', 'deleted','nick','register-branch', 'serve','unbind','upgrade','version', @@ -242,7 +237,7 @@ def bzr_completer(self,event): # the rest are probably file names return ip.IP.Completer.file_matches(event.symbol) - return bzr_commands.split() + return bzr_commands() def shlex_split(x): diff --git a/IPython/ipapi.py b/IPython/ipapi.py index 57c8960..99f2fc1 100644 --- a/IPython/ipapi.py +++ b/IPython/ipapi.py @@ -533,7 +533,7 @@ class DebugTools: if name in self.hotnames: self.debug_stack( "HotName '%s' caught" % name) -def launch_new_instance(user_ns = None): +def launch_new_instance(user_ns = None,shellclass = None): """ Make and start a new ipython instance. This can be called even without having an already initialized @@ -542,7 +542,7 @@ def launch_new_instance(user_ns = None): This is also used as the egg entry point for the 'ipython' script. """ - ses = make_session(user_ns) + ses = make_session(user_ns,shellclass) ses.mainloop() @@ -578,7 +578,7 @@ def make_user_global_ns(ns = None): return ns -def make_session(user_ns = None): +def make_session(user_ns = None, shellclass = None): """Makes, but does not launch an IPython session. Later on you can call obj.mainloop() on the returned object. @@ -591,6 +591,6 @@ def make_session(user_ns = None): WARNING: This should *not* be run when a session exists already.""" import IPython.Shell - return IPython.Shell.start(user_ns) - - + if shellclass is None: + return IPython.Shell.start(user_ns) + return shellclass(user_ns = user_ns) diff --git a/IPython/ipmaker.py b/IPython/ipmaker.py index d281077..14c084a 100644 --- a/IPython/ipmaker.py +++ b/IPython/ipmaker.py @@ -58,6 +58,14 @@ from IPython.iplib import InteractiveShell from IPython.usage import cmd_line_usage,interactive_usage from IPython.genutils import * +def force_import(modname): + if modname in sys.modules: + print "reload",modname + reload(sys.modules[modname]) + else: + __import__(modname) + + #----------------------------------------------------------------------------- def make_IPython(argv=None,user_ns=None,user_global_ns=None,debug=1, rc_override=None,shell_class=InteractiveShell, @@ -633,15 +641,17 @@ object? -> Details about 'object'. ?object also works, ?? prints more. if opts_all.profile and not profile_handled_by_legacy: profmodname = 'ipy_profile_' + opts_all.profile try: - __import__(profmodname) + + force_import(profmodname) except: IP.InteractiveTB() print "Error importing",profmodname,"- perhaps you should run %upgrade?" import_fail_info(profmodname) else: - import ipy_profile_none - try: - import ipy_user_conf + force_import('ipy_profile_none') + try: + + force_import('ipy_user_conf') except: conf = opts_all.ipythondir + "/ipy_user_conf.py" diff --git a/test/test_embed.py b/test/test_embed.py index 876548c..ad88343 100644 --- a/test/test_embed.py +++ b/test/test_embed.py @@ -6,27 +6,43 @@ user namespace. """ import sys -sys.path.append('..') +sys.path.insert(1,'..') import IPython.ipapi -my_ns = dict(a=10) -ses = IPython.ipapi.make_session(my_ns) -# Now get the ipapi instance, to be stored somewhere in your program for manipulation of the running -# IPython session. See http://ipython.scipy.org/moin/IpythonExtensionApi - -ip = ses.IP.getapi() - -# let's play with the ipapi a bit, creating a magic function for a soon-to-be-started IPython -def mymagic_f(self,s): - print "mymagic says",s - -ip.expose_magic("mymagic",mymagic_f) - -# And finally, start the IPython interaction! This will block until you say Exit. - -ses.mainloop() - -print "IPython session finished! namespace content:",my_ns +def test_session(shellclass): + print "*****************\nLaunch shell for",shellclass + my_ns = dict(a=10) + ses = IPython.ipapi.make_session(my_ns, shellclass=shellclass) + + # Now get the ipapi instance, to be stored somewhere in your program for manipulation of the running + # IPython session. See http://ipython.scipy.org/moin/IpythonExtensionApi + + ip = ses.IP.getapi() + + # let's play with the ipapi a bit, creating a magic function for a soon-to-be-started IPython + def mymagic_f(self,s): + print "mymagic says",s + + ip.expose_magic("mymagic",mymagic_f) + + # And finally, start the IPython interaction! This will block until you say Exit. + + ses.mainloop() + + print "IPython session for shell ",shellclass," finished! namespace content:" + for k,v in my_ns.items(): + print k,':',str(v)[:80].rstrip() + +import IPython.Shell + +def do_test(arg_line): + test_session(IPython.Shell._select_shell(arg_line.split())) + +do_test('') +do_test('ipython -gthread') +do_test('ipython -q4thread') +do_test('ipython -pylab') +do_test('ipython -pylab -gthread') \ No newline at end of file