From 1d3334e31191d4b3767b2db704ec9b5d1d851df3 2008-08-14 04:38:50 From: Gael Varoquaux Date: 2008-08-14 04:38:50 Subject: [PATCH] Make the prefilterfrontend take an optional ipython0 instance as the constructor. --- diff --git a/IPython/Shell.py b/IPython/Shell.py index 0f65813..a8fe13a 100644 --- a/IPython/Shell.py +++ b/IPython/Shell.py @@ -634,7 +634,7 @@ class MatplotlibMTShell(MatplotlibShellBase,MTInteractiveShell): def __init__(self,name,usage=None,rc=Struct(opts=None,args=None), user_ns=None,user_global_ns=None, **kw): - user_ns,b2 = self._matplotlib_config(name,user_ns) + user_ns,user_global_ns,b2 = self._matplotlib_config(name,user_ns,user_global_ns) MTInteractiveShell.__init__(self,name,usage,rc,user_ns,user_global_ns, banner2=b2,**kw) diff --git a/IPython/frontend/prefilterfrontend.py b/IPython/frontend/prefilterfrontend.py index b495382..e09ed2b 100644 --- a/IPython/frontend/prefilterfrontend.py +++ b/IPython/frontend/prefilterfrontend.py @@ -58,14 +58,22 @@ class PrefilterFrontEnd(LineFrontEndBase): completion... """ - def __init__(self, *args, **kwargs): + def __init__(self, ipython0=None, *args, **kwargs): + """ Parameters: + ----------- + + ipython0: an optional ipython0 instance to use for command + prefiltering and completion. + """ self.save_output_hooks() - # Instanciate an IPython0 interpreter to be able to use the - # prefiltering. - self.ipython0 = make_IPython() + if ipython0 is None: + # Instanciate an IPython0 interpreter to be able to use the + # prefiltering. + ipython0 = make_IPython() + self.ipython0 = ipython0 # Set the pager: self.ipython0.set_hook('show_in_pager', - lambda s, string: self.write("\n"+string)) + lambda s, string: self.write("\n" + string)) self.ipython0.write = self.write self._ip = _ip = IPApi(self.ipython0) # Make sure the raw system call doesn't get called, as we don't diff --git a/IPython/frontend/tests/test_prefilterfrontend.py b/IPython/frontend/tests/test_prefilterfrontend.py index a48a10c..180cdc1 100644 --- a/IPython/frontend/tests/test_prefilterfrontend.py +++ b/IPython/frontend/tests/test_prefilterfrontend.py @@ -16,6 +16,7 @@ from IPython.frontend.prefilterfrontend import PrefilterFrontEnd from cStringIO import StringIO import string import sys +from IPython.ipapi import get as get_ipython0 class TestPrefilterFrontEnd(PrefilterFrontEnd): @@ -23,8 +24,9 @@ class TestPrefilterFrontEnd(PrefilterFrontEnd): output_prompt_template = string.Template('') def __init__(self): + ipython0 = get_ipython0() self.out = StringIO() - PrefilterFrontEnd.__init__(self) + PrefilterFrontEnd.__init__(self, ipython0=ipython0) def write(self, string): self.out.write(string) diff --git a/IPython/ipapi.py b/IPython/ipapi.py index 7026df3..81580cd 100644 --- a/IPython/ipapi.py +++ b/IPython/ipapi.py @@ -565,6 +565,19 @@ def make_user_ns(user_ns = None): This builds a dict with the minimal information needed to operate as a valid IPython user namespace, which you can pass to the various embedding classes in ipython. + + This API is currently deprecated. Use ipapi.make_user_namespaces() instead + to make both the local and global namespace objects simultaneously. + + :Parameters: + user_ns : dict-like, optional + The current user namespace. The items in this namespace should be + included in the output. If None, an appropriate blank namespace + should be created. + + :Returns: + A dictionary-like object to be used as the local namespace of the + interpreter. """ raise NotImplementedError @@ -575,7 +588,20 @@ def make_user_global_ns(ns = None): Similar to make_user_ns(), but global namespaces are really only needed in embedded applications, where there is a distinction between the user's - interactive namespace and the global one where ipython is running.""" + interactive namespace and the global one where ipython is running. + + This API is currently deprecated. Use ipapi.make_user_namespaces() instead + to make both the local and global namespace objects simultaneously. + + :Parameters: + ns : dict, optional + The current user global namespace. The items in this namespace + should be included in the output. If None, an appropriate blank + namespace should be created. + + :Returns: + A true dict to be used as the global namespace of the interpreter. + """ raise NotImplementedError @@ -599,6 +625,20 @@ def make_user_namespaces(user_ns = None,user_global_ns = None): namespace synchronize with the globals dict somehow. Raises TypeError if the provided globals namespace is not a true dict. + + :Parameters: + user_ns : dict-like, optional + The current user namespace. The items in this namespace should be + included in the output. If None, an appropriate blank namespace + should be created. + user_global_ns : dict, optional + The current user global namespace. The items in this namespace + should be included in the output. If None, an appropriate blank + namespace should be created. + + :Returns: + A tuple pair of dictionary-like object to be used as the local namespace + of the interpreter and a dict to be used as the global namespace. """ if user_ns is None: