##// END OF EJS Templates
wildcard.py => utils/wildcard.py and updated imports.
Brian Granger -
Show More

The requested changes are too big and content was truncated. Show full diff

1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
@@ -1,607 +1,607 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Tools for inspecting Python objects.
2 """Tools for inspecting Python objects.
3
3
4 Uses syntax highlighting for presenting the various information elements.
4 Uses syntax highlighting for presenting the various information elements.
5
5
6 Similar in spirit to the inspect module, but all calls take a name argument to
6 Similar in spirit to the inspect module, but all calls take a name argument to
7 reference the name under which an object is being read.
7 reference the name under which an object is being read.
8 """
8 """
9
9
10 #*****************************************************************************
10 #*****************************************************************************
11 # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu>
11 # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu>
12 #
12 #
13 # Distributed under the terms of the BSD License. The full license is in
13 # Distributed under the terms of the BSD License. The full license is in
14 # the file COPYING, distributed as part of this software.
14 # the file COPYING, distributed as part of this software.
15 #*****************************************************************************
15 #*****************************************************************************
16
16
17 __all__ = ['Inspector','InspectColors']
17 __all__ = ['Inspector','InspectColors']
18
18
19 # stdlib modules
19 # stdlib modules
20 import __builtin__
20 import __builtin__
21 import StringIO
21 import StringIO
22 import inspect
22 import inspect
23 import linecache
23 import linecache
24 import os
24 import os
25 import string
25 import string
26 import sys
26 import sys
27 import types
27 import types
28
28
29 # IPython's own
29 # IPython's own
30 from IPython.utils import PyColorize
30 from IPython.utils import PyColorize
31 from IPython.utils.genutils import page,indent,Term
31 from IPython.utils.genutils import page,indent,Term
32 from IPython.external.Itpl import itpl
32 from IPython.external.Itpl import itpl
33 from IPython.wildcard import list_namespace
33 from IPython.utils.wildcard import list_namespace
34 from IPython.utils.coloransi import *
34 from IPython.utils.coloransi import *
35
35
36 #****************************************************************************
36 #****************************************************************************
37 # HACK!!! This is a crude fix for bugs in python 2.3's inspect module. We
37 # HACK!!! This is a crude fix for bugs in python 2.3's inspect module. We
38 # simply monkeypatch inspect with code copied from python 2.4.
38 # simply monkeypatch inspect with code copied from python 2.4.
39 if sys.version_info[:2] == (2,3):
39 if sys.version_info[:2] == (2,3):
40 from inspect import ismodule, getabsfile, modulesbyfile
40 from inspect import ismodule, getabsfile, modulesbyfile
41 def getmodule(object):
41 def getmodule(object):
42 """Return the module an object was defined in, or None if not found."""
42 """Return the module an object was defined in, or None if not found."""
43 if ismodule(object):
43 if ismodule(object):
44 return object
44 return object
45 if hasattr(object, '__module__'):
45 if hasattr(object, '__module__'):
46 return sys.modules.get(object.__module__)
46 return sys.modules.get(object.__module__)
47 try:
47 try:
48 file = getabsfile(object)
48 file = getabsfile(object)
49 except TypeError:
49 except TypeError:
50 return None
50 return None
51 if file in modulesbyfile:
51 if file in modulesbyfile:
52 return sys.modules.get(modulesbyfile[file])
52 return sys.modules.get(modulesbyfile[file])
53 for module in sys.modules.values():
53 for module in sys.modules.values():
54 if hasattr(module, '__file__'):
54 if hasattr(module, '__file__'):
55 modulesbyfile[
55 modulesbyfile[
56 os.path.realpath(
56 os.path.realpath(
57 getabsfile(module))] = module.__name__
57 getabsfile(module))] = module.__name__
58 if file in modulesbyfile:
58 if file in modulesbyfile:
59 return sys.modules.get(modulesbyfile[file])
59 return sys.modules.get(modulesbyfile[file])
60 main = sys.modules['__main__']
60 main = sys.modules['__main__']
61 if not hasattr(object, '__name__'):
61 if not hasattr(object, '__name__'):
62 return None
62 return None
63 if hasattr(main, object.__name__):
63 if hasattr(main, object.__name__):
64 mainobject = getattr(main, object.__name__)
64 mainobject = getattr(main, object.__name__)
65 if mainobject is object:
65 if mainobject is object:
66 return main
66 return main
67 builtin = sys.modules['__builtin__']
67 builtin = sys.modules['__builtin__']
68 if hasattr(builtin, object.__name__):
68 if hasattr(builtin, object.__name__):
69 builtinobject = getattr(builtin, object.__name__)
69 builtinobject = getattr(builtin, object.__name__)
70 if builtinobject is object:
70 if builtinobject is object:
71 return builtin
71 return builtin
72
72
73 inspect.getmodule = getmodule
73 inspect.getmodule = getmodule
74
74
75 #****************************************************************************
75 #****************************************************************************
76 # Builtin color schemes
76 # Builtin color schemes
77
77
78 Colors = TermColors # just a shorthand
78 Colors = TermColors # just a shorthand
79
79
80 # Build a few color schemes
80 # Build a few color schemes
81 NoColor = ColorScheme(
81 NoColor = ColorScheme(
82 'NoColor',{
82 'NoColor',{
83 'header' : Colors.NoColor,
83 'header' : Colors.NoColor,
84 'normal' : Colors.NoColor # color off (usu. Colors.Normal)
84 'normal' : Colors.NoColor # color off (usu. Colors.Normal)
85 } )
85 } )
86
86
87 LinuxColors = ColorScheme(
87 LinuxColors = ColorScheme(
88 'Linux',{
88 'Linux',{
89 'header' : Colors.LightRed,
89 'header' : Colors.LightRed,
90 'normal' : Colors.Normal # color off (usu. Colors.Normal)
90 'normal' : Colors.Normal # color off (usu. Colors.Normal)
91 } )
91 } )
92
92
93 LightBGColors = ColorScheme(
93 LightBGColors = ColorScheme(
94 'LightBG',{
94 'LightBG',{
95 'header' : Colors.Red,
95 'header' : Colors.Red,
96 'normal' : Colors.Normal # color off (usu. Colors.Normal)
96 'normal' : Colors.Normal # color off (usu. Colors.Normal)
97 } )
97 } )
98
98
99 # Build table of color schemes (needed by the parser)
99 # Build table of color schemes (needed by the parser)
100 InspectColors = ColorSchemeTable([NoColor,LinuxColors,LightBGColors],
100 InspectColors = ColorSchemeTable([NoColor,LinuxColors,LightBGColors],
101 'Linux')
101 'Linux')
102
102
103 #****************************************************************************
103 #****************************************************************************
104 # Auxiliary functions
104 # Auxiliary functions
105 def getdoc(obj):
105 def getdoc(obj):
106 """Stable wrapper around inspect.getdoc.
106 """Stable wrapper around inspect.getdoc.
107
107
108 This can't crash because of attribute problems.
108 This can't crash because of attribute problems.
109
109
110 It also attempts to call a getdoc() method on the given object. This
110 It also attempts to call a getdoc() method on the given object. This
111 allows objects which provide their docstrings via non-standard mechanisms
111 allows objects which provide their docstrings via non-standard mechanisms
112 (like Pyro proxies) to still be inspected by ipython's ? system."""
112 (like Pyro proxies) to still be inspected by ipython's ? system."""
113
113
114 ds = None # default return value
114 ds = None # default return value
115 try:
115 try:
116 ds = inspect.getdoc(obj)
116 ds = inspect.getdoc(obj)
117 except:
117 except:
118 # Harden against an inspect failure, which can occur with
118 # Harden against an inspect failure, which can occur with
119 # SWIG-wrapped extensions.
119 # SWIG-wrapped extensions.
120 pass
120 pass
121 # Allow objects to offer customized documentation via a getdoc method:
121 # Allow objects to offer customized documentation via a getdoc method:
122 try:
122 try:
123 ds2 = obj.getdoc()
123 ds2 = obj.getdoc()
124 except:
124 except:
125 pass
125 pass
126 else:
126 else:
127 # if we get extra info, we add it to the normal docstring.
127 # if we get extra info, we add it to the normal docstring.
128 if ds is None:
128 if ds is None:
129 ds = ds2
129 ds = ds2
130 else:
130 else:
131 ds = '%s\n%s' % (ds,ds2)
131 ds = '%s\n%s' % (ds,ds2)
132 return ds
132 return ds
133
133
134
134
135 def getsource(obj,is_binary=False):
135 def getsource(obj,is_binary=False):
136 """Wrapper around inspect.getsource.
136 """Wrapper around inspect.getsource.
137
137
138 This can be modified by other projects to provide customized source
138 This can be modified by other projects to provide customized source
139 extraction.
139 extraction.
140
140
141 Inputs:
141 Inputs:
142
142
143 - obj: an object whose source code we will attempt to extract.
143 - obj: an object whose source code we will attempt to extract.
144
144
145 Optional inputs:
145 Optional inputs:
146
146
147 - is_binary: whether the object is known to come from a binary source.
147 - is_binary: whether the object is known to come from a binary source.
148 This implementation will skip returning any output for binary objects, but
148 This implementation will skip returning any output for binary objects, but
149 custom extractors may know how to meaningfully process them."""
149 custom extractors may know how to meaningfully process them."""
150
150
151 if is_binary:
151 if is_binary:
152 return None
152 return None
153 else:
153 else:
154 try:
154 try:
155 src = inspect.getsource(obj)
155 src = inspect.getsource(obj)
156 except TypeError:
156 except TypeError:
157 if hasattr(obj,'__class__'):
157 if hasattr(obj,'__class__'):
158 src = inspect.getsource(obj.__class__)
158 src = inspect.getsource(obj.__class__)
159 return src
159 return src
160
160
161 def getargspec(obj):
161 def getargspec(obj):
162 """Get the names and default values of a function's arguments.
162 """Get the names and default values of a function's arguments.
163
163
164 A tuple of four things is returned: (args, varargs, varkw, defaults).
164 A tuple of four things is returned: (args, varargs, varkw, defaults).
165 'args' is a list of the argument names (it may contain nested lists).
165 'args' is a list of the argument names (it may contain nested lists).
166 'varargs' and 'varkw' are the names of the * and ** arguments or None.
166 'varargs' and 'varkw' are the names of the * and ** arguments or None.
167 'defaults' is an n-tuple of the default values of the last n arguments.
167 'defaults' is an n-tuple of the default values of the last n arguments.
168
168
169 Modified version of inspect.getargspec from the Python Standard
169 Modified version of inspect.getargspec from the Python Standard
170 Library."""
170 Library."""
171
171
172 if inspect.isfunction(obj):
172 if inspect.isfunction(obj):
173 func_obj = obj
173 func_obj = obj
174 elif inspect.ismethod(obj):
174 elif inspect.ismethod(obj):
175 func_obj = obj.im_func
175 func_obj = obj.im_func
176 else:
176 else:
177 raise TypeError, 'arg is not a Python function'
177 raise TypeError, 'arg is not a Python function'
178 args, varargs, varkw = inspect.getargs(func_obj.func_code)
178 args, varargs, varkw = inspect.getargs(func_obj.func_code)
179 return args, varargs, varkw, func_obj.func_defaults
179 return args, varargs, varkw, func_obj.func_defaults
180
180
181 #****************************************************************************
181 #****************************************************************************
182 # Class definitions
182 # Class definitions
183
183
184 class myStringIO(StringIO.StringIO):
184 class myStringIO(StringIO.StringIO):
185 """Adds a writeln method to normal StringIO."""
185 """Adds a writeln method to normal StringIO."""
186 def writeln(self,*arg,**kw):
186 def writeln(self,*arg,**kw):
187 """Does a write() and then a write('\n')"""
187 """Does a write() and then a write('\n')"""
188 self.write(*arg,**kw)
188 self.write(*arg,**kw)
189 self.write('\n')
189 self.write('\n')
190
190
191
191
192 class Inspector:
192 class Inspector:
193 def __init__(self,color_table,code_color_table,scheme,
193 def __init__(self,color_table,code_color_table,scheme,
194 str_detail_level=0):
194 str_detail_level=0):
195 self.color_table = color_table
195 self.color_table = color_table
196 self.parser = PyColorize.Parser(code_color_table,out='str')
196 self.parser = PyColorize.Parser(code_color_table,out='str')
197 self.format = self.parser.format
197 self.format = self.parser.format
198 self.str_detail_level = str_detail_level
198 self.str_detail_level = str_detail_level
199 self.set_active_scheme(scheme)
199 self.set_active_scheme(scheme)
200
200
201 def __getdef(self,obj,oname=''):
201 def __getdef(self,obj,oname=''):
202 """Return the definition header for any callable object.
202 """Return the definition header for any callable object.
203
203
204 If any exception is generated, None is returned instead and the
204 If any exception is generated, None is returned instead and the
205 exception is suppressed."""
205 exception is suppressed."""
206
206
207 try:
207 try:
208 return oname + inspect.formatargspec(*getargspec(obj))
208 return oname + inspect.formatargspec(*getargspec(obj))
209 except:
209 except:
210 return None
210 return None
211
211
212 def __head(self,h):
212 def __head(self,h):
213 """Return a header string with proper colors."""
213 """Return a header string with proper colors."""
214 return '%s%s%s' % (self.color_table.active_colors.header,h,
214 return '%s%s%s' % (self.color_table.active_colors.header,h,
215 self.color_table.active_colors.normal)
215 self.color_table.active_colors.normal)
216
216
217 def set_active_scheme(self,scheme):
217 def set_active_scheme(self,scheme):
218 self.color_table.set_active_scheme(scheme)
218 self.color_table.set_active_scheme(scheme)
219 self.parser.color_table.set_active_scheme(scheme)
219 self.parser.color_table.set_active_scheme(scheme)
220
220
221 def noinfo(self,msg,oname):
221 def noinfo(self,msg,oname):
222 """Generic message when no information is found."""
222 """Generic message when no information is found."""
223 print 'No %s found' % msg,
223 print 'No %s found' % msg,
224 if oname:
224 if oname:
225 print 'for %s' % oname
225 print 'for %s' % oname
226 else:
226 else:
227 print
227 print
228
228
229 def pdef(self,obj,oname=''):
229 def pdef(self,obj,oname=''):
230 """Print the definition header for any callable object.
230 """Print the definition header for any callable object.
231
231
232 If the object is a class, print the constructor information."""
232 If the object is a class, print the constructor information."""
233
233
234 if not callable(obj):
234 if not callable(obj):
235 print 'Object is not callable.'
235 print 'Object is not callable.'
236 return
236 return
237
237
238 header = ''
238 header = ''
239
239
240 if inspect.isclass(obj):
240 if inspect.isclass(obj):
241 header = self.__head('Class constructor information:\n')
241 header = self.__head('Class constructor information:\n')
242 obj = obj.__init__
242 obj = obj.__init__
243 elif type(obj) is types.InstanceType:
243 elif type(obj) is types.InstanceType:
244 obj = obj.__call__
244 obj = obj.__call__
245
245
246 output = self.__getdef(obj,oname)
246 output = self.__getdef(obj,oname)
247 if output is None:
247 if output is None:
248 self.noinfo('definition header',oname)
248 self.noinfo('definition header',oname)
249 else:
249 else:
250 print >>Term.cout, header,self.format(output),
250 print >>Term.cout, header,self.format(output),
251
251
252 def pdoc(self,obj,oname='',formatter = None):
252 def pdoc(self,obj,oname='',formatter = None):
253 """Print the docstring for any object.
253 """Print the docstring for any object.
254
254
255 Optional:
255 Optional:
256 -formatter: a function to run the docstring through for specially
256 -formatter: a function to run the docstring through for specially
257 formatted docstrings."""
257 formatted docstrings."""
258
258
259 head = self.__head # so that itpl can find it even if private
259 head = self.__head # so that itpl can find it even if private
260 ds = getdoc(obj)
260 ds = getdoc(obj)
261 if formatter:
261 if formatter:
262 ds = formatter(ds)
262 ds = formatter(ds)
263 if inspect.isclass(obj):
263 if inspect.isclass(obj):
264 init_ds = getdoc(obj.__init__)
264 init_ds = getdoc(obj.__init__)
265 output = itpl('$head("Class Docstring:")\n'
265 output = itpl('$head("Class Docstring:")\n'
266 '$indent(ds)\n'
266 '$indent(ds)\n'
267 '$head("Constructor Docstring"):\n'
267 '$head("Constructor Docstring"):\n'
268 '$indent(init_ds)')
268 '$indent(init_ds)')
269 elif (type(obj) is types.InstanceType or isinstance(obj,object)) \
269 elif (type(obj) is types.InstanceType or isinstance(obj,object)) \
270 and hasattr(obj,'__call__'):
270 and hasattr(obj,'__call__'):
271 call_ds = getdoc(obj.__call__)
271 call_ds = getdoc(obj.__call__)
272 if call_ds:
272 if call_ds:
273 output = itpl('$head("Class Docstring:")\n$indent(ds)\n'
273 output = itpl('$head("Class Docstring:")\n$indent(ds)\n'
274 '$head("Calling Docstring:")\n$indent(call_ds)')
274 '$head("Calling Docstring:")\n$indent(call_ds)')
275 else:
275 else:
276 output = ds
276 output = ds
277 else:
277 else:
278 output = ds
278 output = ds
279 if output is None:
279 if output is None:
280 self.noinfo('documentation',oname)
280 self.noinfo('documentation',oname)
281 return
281 return
282 page(output)
282 page(output)
283
283
284 def psource(self,obj,oname=''):
284 def psource(self,obj,oname=''):
285 """Print the source code for an object."""
285 """Print the source code for an object."""
286
286
287 # Flush the source cache because inspect can return out-of-date source
287 # Flush the source cache because inspect can return out-of-date source
288 linecache.checkcache()
288 linecache.checkcache()
289 try:
289 try:
290 src = getsource(obj)
290 src = getsource(obj)
291 except:
291 except:
292 self.noinfo('source',oname)
292 self.noinfo('source',oname)
293 else:
293 else:
294 page(self.format(src))
294 page(self.format(src))
295
295
296 def pfile(self,obj,oname=''):
296 def pfile(self,obj,oname=''):
297 """Show the whole file where an object was defined."""
297 """Show the whole file where an object was defined."""
298
298
299 try:
299 try:
300 try:
300 try:
301 lineno = inspect.getsourcelines(obj)[1]
301 lineno = inspect.getsourcelines(obj)[1]
302 except TypeError:
302 except TypeError:
303 # For instances, try the class object like getsource() does
303 # For instances, try the class object like getsource() does
304 if hasattr(obj,'__class__'):
304 if hasattr(obj,'__class__'):
305 lineno = inspect.getsourcelines(obj.__class__)[1]
305 lineno = inspect.getsourcelines(obj.__class__)[1]
306 # Adjust the inspected object so getabsfile() below works
306 # Adjust the inspected object so getabsfile() below works
307 obj = obj.__class__
307 obj = obj.__class__
308 except:
308 except:
309 self.noinfo('file',oname)
309 self.noinfo('file',oname)
310 return
310 return
311
311
312 # We only reach this point if object was successfully queried
312 # We only reach this point if object was successfully queried
313
313
314 # run contents of file through pager starting at line
314 # run contents of file through pager starting at line
315 # where the object is defined
315 # where the object is defined
316 ofile = inspect.getabsfile(obj)
316 ofile = inspect.getabsfile(obj)
317
317
318 if (ofile.endswith('.so') or ofile.endswith('.dll')):
318 if (ofile.endswith('.so') or ofile.endswith('.dll')):
319 print 'File %r is binary, not printing.' % ofile
319 print 'File %r is binary, not printing.' % ofile
320 elif not os.path.isfile(ofile):
320 elif not os.path.isfile(ofile):
321 print 'File %r does not exist, not printing.' % ofile
321 print 'File %r does not exist, not printing.' % ofile
322 else:
322 else:
323 # Print only text files, not extension binaries. Note that
323 # Print only text files, not extension binaries. Note that
324 # getsourcelines returns lineno with 1-offset and page() uses
324 # getsourcelines returns lineno with 1-offset and page() uses
325 # 0-offset, so we must adjust.
325 # 0-offset, so we must adjust.
326 page(self.format(open(ofile).read()),lineno-1)
326 page(self.format(open(ofile).read()),lineno-1)
327
327
328 def pinfo(self,obj,oname='',formatter=None,info=None,detail_level=0):
328 def pinfo(self,obj,oname='',formatter=None,info=None,detail_level=0):
329 """Show detailed information about an object.
329 """Show detailed information about an object.
330
330
331 Optional arguments:
331 Optional arguments:
332
332
333 - oname: name of the variable pointing to the object.
333 - oname: name of the variable pointing to the object.
334
334
335 - formatter: special formatter for docstrings (see pdoc)
335 - formatter: special formatter for docstrings (see pdoc)
336
336
337 - info: a structure with some information fields which may have been
337 - info: a structure with some information fields which may have been
338 precomputed already.
338 precomputed already.
339
339
340 - detail_level: if set to 1, more information is given.
340 - detail_level: if set to 1, more information is given.
341 """
341 """
342
342
343 obj_type = type(obj)
343 obj_type = type(obj)
344
344
345 header = self.__head
345 header = self.__head
346 if info is None:
346 if info is None:
347 ismagic = 0
347 ismagic = 0
348 isalias = 0
348 isalias = 0
349 ospace = ''
349 ospace = ''
350 else:
350 else:
351 ismagic = info.ismagic
351 ismagic = info.ismagic
352 isalias = info.isalias
352 isalias = info.isalias
353 ospace = info.namespace
353 ospace = info.namespace
354 # Get docstring, special-casing aliases:
354 # Get docstring, special-casing aliases:
355 if isalias:
355 if isalias:
356 if not callable(obj):
356 if not callable(obj):
357 try:
357 try:
358 ds = "Alias to the system command:\n %s" % obj[1]
358 ds = "Alias to the system command:\n %s" % obj[1]
359 except:
359 except:
360 ds = "Alias: " + str(obj)
360 ds = "Alias: " + str(obj)
361 else:
361 else:
362 ds = "Alias to " + str(obj)
362 ds = "Alias to " + str(obj)
363 if obj.__doc__:
363 if obj.__doc__:
364 ds += "\nDocstring:\n" + obj.__doc__
364 ds += "\nDocstring:\n" + obj.__doc__
365 else:
365 else:
366 ds = getdoc(obj)
366 ds = getdoc(obj)
367 if ds is None:
367 if ds is None:
368 ds = '<no docstring>'
368 ds = '<no docstring>'
369 if formatter is not None:
369 if formatter is not None:
370 ds = formatter(ds)
370 ds = formatter(ds)
371
371
372 # store output in a list which gets joined with \n at the end.
372 # store output in a list which gets joined with \n at the end.
373 out = myStringIO()
373 out = myStringIO()
374
374
375 string_max = 200 # max size of strings to show (snipped if longer)
375 string_max = 200 # max size of strings to show (snipped if longer)
376 shalf = int((string_max -5)/2)
376 shalf = int((string_max -5)/2)
377
377
378 if ismagic:
378 if ismagic:
379 obj_type_name = 'Magic function'
379 obj_type_name = 'Magic function'
380 elif isalias:
380 elif isalias:
381 obj_type_name = 'System alias'
381 obj_type_name = 'System alias'
382 else:
382 else:
383 obj_type_name = obj_type.__name__
383 obj_type_name = obj_type.__name__
384 out.writeln(header('Type:\t\t')+obj_type_name)
384 out.writeln(header('Type:\t\t')+obj_type_name)
385
385
386 try:
386 try:
387 bclass = obj.__class__
387 bclass = obj.__class__
388 out.writeln(header('Base Class:\t')+str(bclass))
388 out.writeln(header('Base Class:\t')+str(bclass))
389 except: pass
389 except: pass
390
390
391 # String form, but snip if too long in ? form (full in ??)
391 # String form, but snip if too long in ? form (full in ??)
392 if detail_level >= self.str_detail_level:
392 if detail_level >= self.str_detail_level:
393 try:
393 try:
394 ostr = str(obj)
394 ostr = str(obj)
395 str_head = 'String Form:'
395 str_head = 'String Form:'
396 if not detail_level and len(ostr)>string_max:
396 if not detail_level and len(ostr)>string_max:
397 ostr = ostr[:shalf] + ' <...> ' + ostr[-shalf:]
397 ostr = ostr[:shalf] + ' <...> ' + ostr[-shalf:]
398 ostr = ("\n" + " " * len(str_head.expandtabs())).\
398 ostr = ("\n" + " " * len(str_head.expandtabs())).\
399 join(map(string.strip,ostr.split("\n")))
399 join(map(string.strip,ostr.split("\n")))
400 if ostr.find('\n') > -1:
400 if ostr.find('\n') > -1:
401 # Print multi-line strings starting at the next line.
401 # Print multi-line strings starting at the next line.
402 str_sep = '\n'
402 str_sep = '\n'
403 else:
403 else:
404 str_sep = '\t'
404 str_sep = '\t'
405 out.writeln("%s%s%s" % (header(str_head),str_sep,ostr))
405 out.writeln("%s%s%s" % (header(str_head),str_sep,ostr))
406 except:
406 except:
407 pass
407 pass
408
408
409 if ospace:
409 if ospace:
410 out.writeln(header('Namespace:\t')+ospace)
410 out.writeln(header('Namespace:\t')+ospace)
411
411
412 # Length (for strings and lists)
412 # Length (for strings and lists)
413 try:
413 try:
414 length = str(len(obj))
414 length = str(len(obj))
415 out.writeln(header('Length:\t\t')+length)
415 out.writeln(header('Length:\t\t')+length)
416 except: pass
416 except: pass
417
417
418 # Filename where object was defined
418 # Filename where object was defined
419 binary_file = False
419 binary_file = False
420 try:
420 try:
421 try:
421 try:
422 fname = inspect.getabsfile(obj)
422 fname = inspect.getabsfile(obj)
423 except TypeError:
423 except TypeError:
424 # For an instance, the file that matters is where its class was
424 # For an instance, the file that matters is where its class was
425 # declared.
425 # declared.
426 if hasattr(obj,'__class__'):
426 if hasattr(obj,'__class__'):
427 fname = inspect.getabsfile(obj.__class__)
427 fname = inspect.getabsfile(obj.__class__)
428 if fname.endswith('<string>'):
428 if fname.endswith('<string>'):
429 fname = 'Dynamically generated function. No source code available.'
429 fname = 'Dynamically generated function. No source code available.'
430 if (fname.endswith('.so') or fname.endswith('.dll')):
430 if (fname.endswith('.so') or fname.endswith('.dll')):
431 binary_file = True
431 binary_file = True
432 out.writeln(header('File:\t\t')+fname)
432 out.writeln(header('File:\t\t')+fname)
433 except:
433 except:
434 # if anything goes wrong, we don't want to show source, so it's as
434 # if anything goes wrong, we don't want to show source, so it's as
435 # if the file was binary
435 # if the file was binary
436 binary_file = True
436 binary_file = True
437
437
438 # reconstruct the function definition and print it:
438 # reconstruct the function definition and print it:
439 defln = self.__getdef(obj,oname)
439 defln = self.__getdef(obj,oname)
440 if defln:
440 if defln:
441 out.write(header('Definition:\t')+self.format(defln))
441 out.write(header('Definition:\t')+self.format(defln))
442
442
443 # Docstrings only in detail 0 mode, since source contains them (we
443 # Docstrings only in detail 0 mode, since source contains them (we
444 # avoid repetitions). If source fails, we add them back, see below.
444 # avoid repetitions). If source fails, we add them back, see below.
445 if ds and detail_level == 0:
445 if ds and detail_level == 0:
446 out.writeln(header('Docstring:\n') + indent(ds))
446 out.writeln(header('Docstring:\n') + indent(ds))
447
447
448 # Original source code for any callable
448 # Original source code for any callable
449 if detail_level:
449 if detail_level:
450 # Flush the source cache because inspect can return out-of-date
450 # Flush the source cache because inspect can return out-of-date
451 # source
451 # source
452 linecache.checkcache()
452 linecache.checkcache()
453 source_success = False
453 source_success = False
454 try:
454 try:
455 try:
455 try:
456 src = getsource(obj,binary_file)
456 src = getsource(obj,binary_file)
457 except TypeError:
457 except TypeError:
458 if hasattr(obj,'__class__'):
458 if hasattr(obj,'__class__'):
459 src = getsource(obj.__class__,binary_file)
459 src = getsource(obj.__class__,binary_file)
460 if src is not None:
460 if src is not None:
461 source = self.format(src)
461 source = self.format(src)
462 out.write(header('Source:\n')+source.rstrip())
462 out.write(header('Source:\n')+source.rstrip())
463 source_success = True
463 source_success = True
464 except Exception, msg:
464 except Exception, msg:
465 pass
465 pass
466
466
467 if ds and not source_success:
467 if ds and not source_success:
468 out.writeln(header('Docstring [source file open failed]:\n')
468 out.writeln(header('Docstring [source file open failed]:\n')
469 + indent(ds))
469 + indent(ds))
470
470
471 # Constructor docstring for classes
471 # Constructor docstring for classes
472 if inspect.isclass(obj):
472 if inspect.isclass(obj):
473 # reconstruct the function definition and print it:
473 # reconstruct the function definition and print it:
474 try:
474 try:
475 obj_init = obj.__init__
475 obj_init = obj.__init__
476 except AttributeError:
476 except AttributeError:
477 init_def = init_ds = None
477 init_def = init_ds = None
478 else:
478 else:
479 init_def = self.__getdef(obj_init,oname)
479 init_def = self.__getdef(obj_init,oname)
480 init_ds = getdoc(obj_init)
480 init_ds = getdoc(obj_init)
481 # Skip Python's auto-generated docstrings
481 # Skip Python's auto-generated docstrings
482 if init_ds and \
482 if init_ds and \
483 init_ds.startswith('x.__init__(...) initializes'):
483 init_ds.startswith('x.__init__(...) initializes'):
484 init_ds = None
484 init_ds = None
485
485
486 if init_def or init_ds:
486 if init_def or init_ds:
487 out.writeln(header('\nConstructor information:'))
487 out.writeln(header('\nConstructor information:'))
488 if init_def:
488 if init_def:
489 out.write(header('Definition:\t')+ self.format(init_def))
489 out.write(header('Definition:\t')+ self.format(init_def))
490 if init_ds:
490 if init_ds:
491 out.writeln(header('Docstring:\n') + indent(init_ds))
491 out.writeln(header('Docstring:\n') + indent(init_ds))
492 # and class docstring for instances:
492 # and class docstring for instances:
493 elif obj_type is types.InstanceType or \
493 elif obj_type is types.InstanceType or \
494 isinstance(obj,object):
494 isinstance(obj,object):
495
495
496 # First, check whether the instance docstring is identical to the
496 # First, check whether the instance docstring is identical to the
497 # class one, and print it separately if they don't coincide. In
497 # class one, and print it separately if they don't coincide. In
498 # most cases they will, but it's nice to print all the info for
498 # most cases they will, but it's nice to print all the info for
499 # objects which use instance-customized docstrings.
499 # objects which use instance-customized docstrings.
500 if ds:
500 if ds:
501 try:
501 try:
502 cls = getattr(obj,'__class__')
502 cls = getattr(obj,'__class__')
503 except:
503 except:
504 class_ds = None
504 class_ds = None
505 else:
505 else:
506 class_ds = getdoc(cls)
506 class_ds = getdoc(cls)
507 # Skip Python's auto-generated docstrings
507 # Skip Python's auto-generated docstrings
508 if class_ds and \
508 if class_ds and \
509 (class_ds.startswith('function(code, globals[,') or \
509 (class_ds.startswith('function(code, globals[,') or \
510 class_ds.startswith('instancemethod(function, instance,') or \
510 class_ds.startswith('instancemethod(function, instance,') or \
511 class_ds.startswith('module(name[,') ):
511 class_ds.startswith('module(name[,') ):
512 class_ds = None
512 class_ds = None
513 if class_ds and ds != class_ds:
513 if class_ds and ds != class_ds:
514 out.writeln(header('Class Docstring:\n') +
514 out.writeln(header('Class Docstring:\n') +
515 indent(class_ds))
515 indent(class_ds))
516
516
517 # Next, try to show constructor docstrings
517 # Next, try to show constructor docstrings
518 try:
518 try:
519 init_ds = getdoc(obj.__init__)
519 init_ds = getdoc(obj.__init__)
520 # Skip Python's auto-generated docstrings
520 # Skip Python's auto-generated docstrings
521 if init_ds and \
521 if init_ds and \
522 init_ds.startswith('x.__init__(...) initializes'):
522 init_ds.startswith('x.__init__(...) initializes'):
523 init_ds = None
523 init_ds = None
524 except AttributeError:
524 except AttributeError:
525 init_ds = None
525 init_ds = None
526 if init_ds:
526 if init_ds:
527 out.writeln(header('Constructor Docstring:\n') +
527 out.writeln(header('Constructor Docstring:\n') +
528 indent(init_ds))
528 indent(init_ds))
529
529
530 # Call form docstring for callable instances
530 # Call form docstring for callable instances
531 if hasattr(obj,'__call__'):
531 if hasattr(obj,'__call__'):
532 #out.writeln(header('Callable:\t')+'Yes')
532 #out.writeln(header('Callable:\t')+'Yes')
533 call_def = self.__getdef(obj.__call__,oname)
533 call_def = self.__getdef(obj.__call__,oname)
534 #if call_def is None:
534 #if call_def is None:
535 # out.writeln(header('Call def:\t')+
535 # out.writeln(header('Call def:\t')+
536 # 'Calling definition not available.')
536 # 'Calling definition not available.')
537 if call_def is not None:
537 if call_def is not None:
538 out.writeln(header('Call def:\t')+self.format(call_def))
538 out.writeln(header('Call def:\t')+self.format(call_def))
539 call_ds = getdoc(obj.__call__)
539 call_ds = getdoc(obj.__call__)
540 # Skip Python's auto-generated docstrings
540 # Skip Python's auto-generated docstrings
541 if call_ds and call_ds.startswith('x.__call__(...) <==> x(...)'):
541 if call_ds and call_ds.startswith('x.__call__(...) <==> x(...)'):
542 call_ds = None
542 call_ds = None
543 if call_ds:
543 if call_ds:
544 out.writeln(header('Call docstring:\n') + indent(call_ds))
544 out.writeln(header('Call docstring:\n') + indent(call_ds))
545
545
546 # Finally send to printer/pager
546 # Finally send to printer/pager
547 output = out.getvalue()
547 output = out.getvalue()
548 if output:
548 if output:
549 page(output)
549 page(output)
550 # end pinfo
550 # end pinfo
551
551
552 def psearch(self,pattern,ns_table,ns_search=[],
552 def psearch(self,pattern,ns_table,ns_search=[],
553 ignore_case=False,show_all=False):
553 ignore_case=False,show_all=False):
554 """Search namespaces with wildcards for objects.
554 """Search namespaces with wildcards for objects.
555
555
556 Arguments:
556 Arguments:
557
557
558 - pattern: string containing shell-like wildcards to use in namespace
558 - pattern: string containing shell-like wildcards to use in namespace
559 searches and optionally a type specification to narrow the search to
559 searches and optionally a type specification to narrow the search to
560 objects of that type.
560 objects of that type.
561
561
562 - ns_table: dict of name->namespaces for search.
562 - ns_table: dict of name->namespaces for search.
563
563
564 Optional arguments:
564 Optional arguments:
565
565
566 - ns_search: list of namespace names to include in search.
566 - ns_search: list of namespace names to include in search.
567
567
568 - ignore_case(False): make the search case-insensitive.
568 - ignore_case(False): make the search case-insensitive.
569
569
570 - show_all(False): show all names, including those starting with
570 - show_all(False): show all names, including those starting with
571 underscores.
571 underscores.
572 """
572 """
573 #print 'ps pattern:<%r>' % pattern # dbg
573 #print 'ps pattern:<%r>' % pattern # dbg
574
574
575 # defaults
575 # defaults
576 type_pattern = 'all'
576 type_pattern = 'all'
577 filter = ''
577 filter = ''
578
578
579 cmds = pattern.split()
579 cmds = pattern.split()
580 len_cmds = len(cmds)
580 len_cmds = len(cmds)
581 if len_cmds == 1:
581 if len_cmds == 1:
582 # Only filter pattern given
582 # Only filter pattern given
583 filter = cmds[0]
583 filter = cmds[0]
584 elif len_cmds == 2:
584 elif len_cmds == 2:
585 # Both filter and type specified
585 # Both filter and type specified
586 filter,type_pattern = cmds
586 filter,type_pattern = cmds
587 else:
587 else:
588 raise ValueError('invalid argument string for psearch: <%s>' %
588 raise ValueError('invalid argument string for psearch: <%s>' %
589 pattern)
589 pattern)
590
590
591 # filter search namespaces
591 # filter search namespaces
592 for name in ns_search:
592 for name in ns_search:
593 if name not in ns_table:
593 if name not in ns_table:
594 raise ValueError('invalid namespace <%s>. Valid names: %s' %
594 raise ValueError('invalid namespace <%s>. Valid names: %s' %
595 (name,ns_table.keys()))
595 (name,ns_table.keys()))
596
596
597 #print 'type_pattern:',type_pattern # dbg
597 #print 'type_pattern:',type_pattern # dbg
598 search_result = []
598 search_result = []
599 for ns_name in ns_search:
599 for ns_name in ns_search:
600 ns = ns_table[ns_name]
600 ns = ns_table[ns_name]
601 tmp_res = list(list_namespace(ns,type_pattern,filter,
601 tmp_res = list(list_namespace(ns,type_pattern,filter,
602 ignore_case=ignore_case,
602 ignore_case=ignore_case,
603 show_all=show_all))
603 show_all=show_all))
604 search_result.extend(tmp_res)
604 search_result.extend(tmp_res)
605 search_result.sort()
605 search_result.sort()
606
606
607 page('\n'.join(search_result))
607 page('\n'.join(search_result))
@@ -1,32 +1,35 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 # encoding: utf-8
2 # encoding: utf-8
3
3
4 def test_import_coloransi():
4 def test_import_coloransi():
5 from IPython.utils import coloransi
5 from IPython.utils import coloransi
6
6
7 def test_import_DPyGetOpt():
7 def test_import_DPyGetOpt():
8 from IPython.utils import DPyGetOpt
8 from IPython.utils import DPyGetOpt
9
9
10 def test_import_generics():
10 def test_import_generics():
11 from IPython.utils import generics
11 from IPython.utils import generics
12
12
13 def test_import_genutils():
13 def test_import_genutils():
14 from IPython.utils import genutils
14 from IPython.utils import genutils
15
15
16 def test_import_ipstruct():
16 def test_import_ipstruct():
17 from IPython.utils import ipstruct
17 from IPython.utils import ipstruct
18
18
19 def test_import_platutils():
19 def test_import_platutils():
20 from IPython.utils import platutils
20 from IPython.utils import platutils
21
21
22 def test_import_PyColorize():
22 def test_import_PyColorize():
23 from IPython.utils import PyColorize
23 from IPython.utils import PyColorize
24
24
25 def test_import_rlineimpl():
25 def test_import_rlineimpl():
26 from IPython.utils import rlineimpl
26 from IPython.utils import rlineimpl
27
27
28 def test_import_strdispatch():
28 def test_import_strdispatch():
29 from IPython.utils import strdispatch
29 from IPython.utils import strdispatch
30
30
31 def test_import_upgradedir():
31 def test_import_upgradedir():
32 from IPython.utils import upgradedir
32 from IPython.utils import upgradedir
33
34 def test_import_wildcard():
35 from IPython.utils import wildcard
1 NO CONTENT: file renamed from IPython/wildcard.py to IPython/utils/wildcard.py
NO CONTENT: file renamed from IPython/wildcard.py to IPython/utils/wildcard.py
@@ -1,270 +1,270 b''
1 =============================
1 =============================
2 IPython module reorganization
2 IPython module reorganization
3 =============================
3 =============================
4
4
5 Currently, IPython has many top-level modules that serve many different purposes.
5 Currently, IPython has many top-level modules that serve many different purposes.
6 The lack of organization make it very difficult for developers to work on IPython
6 The lack of organization make it very difficult for developers to work on IPython
7 and understand its design. This document contains notes about how we will reorganize
7 and understand its design. This document contains notes about how we will reorganize
8 the modules into sub-packages.
8 the modules into sub-packages.
9
9
10 .. warning::
10 .. warning::
11
11
12 This effort will possibly break third party packages that use IPython as
12 This effort will possibly break third party packages that use IPython as
13 a library or hack on the IPython internals.
13 a library or hack on the IPython internals.
14
14
15 .. warning::
15 .. warning::
16
16
17 This effort will result in the removal from IPython of certain modules
17 This effort will result in the removal from IPython of certain modules
18 that are not used anymore, don't currently work, are unmaintained, etc.
18 that are not used anymore, don't currently work, are unmaintained, etc.
19
19
20
20
21 Current subpackges
21 Current subpackges
22 ==================
22 ==================
23
23
24 IPython currently has the following sub-packages:
24 IPython currently has the following sub-packages:
25
25
26 * :mod:`IPython.config`
26 * :mod:`IPython.config`
27
27
28 * :mod:`IPython.Extensions`
28 * :mod:`IPython.Extensions`
29
29
30 * :mod:`IPython.external`
30 * :mod:`IPython.external`
31
31
32 * :mod:`IPython.frontend`
32 * :mod:`IPython.frontend`
33
33
34 * :mod:`IPython.gui`
34 * :mod:`IPython.gui`
35
35
36 * :mod:`IPython.kernel`
36 * :mod:`IPython.kernel`
37
37
38 * :mod:`IPython.testing`
38 * :mod:`IPython.testing`
39
39
40 * :mod:`IPython.tests`
40 * :mod:`IPython.tests`
41
41
42 * :mod:`IPython.tools`
42 * :mod:`IPython.tools`
43
43
44 * :mod:`IPython.UserConfig`
44 * :mod:`IPython.UserConfig`
45
45
46 New Subpackages to be created
46 New Subpackages to be created
47 =============================
47 =============================
48
48
49 We propose to create the following new sub-packages:
49 We propose to create the following new sub-packages:
50
50
51 * :mod:`IPython.core`. This sub-package will contain the core of the IPython
51 * :mod:`IPython.core`. This sub-package will contain the core of the IPython
52 interpreter, but none of its extended capabilities.
52 interpreter, but none of its extended capabilities.
53
53
54 * :mod:`IPython.lib`. IPython has many extended capabilities that are not part
54 * :mod:`IPython.lib`. IPython has many extended capabilities that are not part
55 of the IPython core. These things will go here. Any better names than
55 of the IPython core. These things will go here. Any better names than
56 :mod:`IPython.lib`?
56 :mod:`IPython.lib`?
57
57
58 * :mod:`IPython.utils`. This sub-package will contain anything that might
58 * :mod:`IPython.utils`. This sub-package will contain anything that might
59 eventually be found in the Python standard library, like things in
59 eventually be found in the Python standard library, like things in
60 :mod:`genutils`. Each sub-module in this sub-package should contain
60 :mod:`genutils`. Each sub-module in this sub-package should contain
61 functions and classes that serve a single purpose.
61 functions and classes that serve a single purpose.
62
62
63 * :mod:`IPython.deathrow`. This is for code that is untested and/or rotting
63 * :mod:`IPython.deathrow`. This is for code that is untested and/or rotting
64 and needs to be removed from IPython. Eventually all this code will either
64 and needs to be removed from IPython. Eventually all this code will either
65 i) be revived by someone willing to maintain it with tests and docs and
65 i) be revived by someone willing to maintain it with tests and docs and
66 re-included into IPython or 2) be removed from IPython proper, but put into
66 re-included into IPython or 2) be removed from IPython proper, but put into
67 a separate top-level (not IPython) package that we keep around. No new code
67 a separate top-level (not IPython) package that we keep around. No new code
68 will be allowed here.
68 will be allowed here.
69
69
70 * :mod:`IPython.quarantine`. This is for code that doesn't meet IPython's
70 * :mod:`IPython.quarantine`. This is for code that doesn't meet IPython's
71 standards, but that we plan on keeping. To be moved out of this sub-package
71 standards, but that we plan on keeping. To be moved out of this sub-package
72 a module needs to have a maintainer, tests and documentation.
72 a module needs to have a maintainer, tests and documentation.
73
73
74 Prodecure
74 Prodecure
75 =========
75 =========
76
76
77 1. Move the file to its new location with its new name.
77 1. Move the file to its new location with its new name.
78 2. Rename all import statements to reflect the change.
78 2. Rename all import statements to reflect the change.
79 3. Run PyFlakes on each changes module.
79 3. Run PyFlakes on each changes module.
80 3. Add tests/test_imports.py to test it.
80 3. Add tests/test_imports.py to test it.
81
81
82 Need to modify iptests to properly skip modules that are no longer top
82 Need to modify iptests to properly skip modules that are no longer top
83 level modules.
83 level modules.
84
84
85 Need to update the top level IPython/__init__.py file.
85 Need to update the top level IPython/__init__.py file.
86
86
87 Where things will be moved
87 Where things will be moved
88 ==========================
88 ==========================
89
89
90 * :file:`background_jobs.py`. Move to :file:`IPython/lib/backgroundjobs.py`.
90 * :file:`background_jobs.py`. Move to :file:`IPython/lib/backgroundjobs.py`.
91
91
92 * :file:`ColorANSI.py`. Move to :file:`IPython/utils/coloransi.py`.
92 * :file:`ColorANSI.py`. Move to :file:`IPython/utils/coloransi.py`.
93
93
94 * :file:`completer.py`. Move to :file:`IPython/core/completer.py`.
94 * :file:`completer.py`. Move to :file:`IPython/core/completer.py`.
95
95
96 * :file:`ConfigLoader.py`. Move to :file:`IPython/config/configloader.py`.
96 * :file:`ConfigLoader.py`. Move to :file:`IPython/config/configloader.py`.
97
97
98 * :file:`CrashHandler.py`. Move to :file:`IPython/core/crashhandler`.
98 * :file:`CrashHandler.py`. Move to :file:`IPython/core/crashhandler`.
99
99
100 * :file:`Debugger.py`. Move to :file:`IPython/core/debugger.py`.
100 * :file:`Debugger.py`. Move to :file:`IPython/core/debugger.py`.
101
101
102 * :file:`deep_reload.py`. Move to :file:`IPython/lib/deepreload.py`.
102 * :file:`deep_reload.py`. Move to :file:`IPython/lib/deepreload.py`.
103
103
104 * :file:`demo.py`. Move to :file:`IPython/lib/demo.py`.
104 * :file:`demo.py`. Move to :file:`IPython/lib/demo.py`.
105
105
106 * :file:`DPyGetOpt.py`. Move to :mod:`IPython.utils` and replace with newer options parser.
106 * :file:`DPyGetOpt.py`. Move to :mod:`IPython.utils` and replace with newer options parser.
107
107
108 * :file:`dtutils.py`. Move to :file:`IPython.deathrow`.
108 * :file:`dtutils.py`. Move to :file:`IPython.deathrow`.
109
109
110 * :file:`excolors.py`. Move to :file:`IPython.core` or :file:`IPython.config`.
110 * :file:`excolors.py`. Move to :file:`IPython.core` or :file:`IPython.config`.
111 Maybe move to :mod:`IPython.lib` or :mod:`IPython.python`?
111 Maybe move to :mod:`IPython.lib` or :mod:`IPython.python`?
112
112
113 * :file:`FakeModule.py`. Move to :file:`IPython/core/fakemodule.py`.
113 * :file:`FakeModule.py`. Move to :file:`IPython/core/fakemodule.py`.
114
114
115 * :file:`generics.py`. Move to :file:`IPython.python`.
115 * :file:`generics.py`. Move to :file:`IPython.python`.
116
116
117 * :file:`genutils.py`. Move to :file:`IPython.utils`.
117 * :file:`genutils.py`. Move to :file:`IPython.utils`.
118
118
119 * :file:`Gnuplot2.py`. Move to :file:`IPython.sandbox`.
119 * :file:`Gnuplot2.py`. Move to :file:`IPython.sandbox`.
120
120
121 * :file:`GnuplotInteractive.py`. Move to :file:`IPython.sandbox`.
121 * :file:`GnuplotInteractive.py`. Move to :file:`IPython.sandbox`.
122
122
123 * :file:`GnuplotRuntime.py`. Move to :file:`IPython.sandbox`.
123 * :file:`GnuplotRuntime.py`. Move to :file:`IPython.sandbox`.
124
124
125 * :file:`numutils.py`. Move to :file:`IPython.sandbox`.
125 * :file:`numutils.py`. Move to :file:`IPython.sandbox`.
126
126
127 * :file:`twshell.py`. Move to :file:`IPython.sandbox`.
127 * :file:`twshell.py`. Move to :file:`IPython.sandbox`.
128
128
129 * :file:`Extensions`. This needs to be gone through separately. Minimally,
129 * :file:`Extensions`. This needs to be gone through separately. Minimally,
130 the package should be renamed to :file:`extensions`.
130 the package should be renamed to :file:`extensions`.
131
131
132 * :file:`history.py`. Move to :file:`IPython.core`.
132 * :file:`history.py`. Move to :file:`IPython.core`.
133
133
134 * :file:`hooks.py`. Move to :file:`IPython.core`.
134 * :file:`hooks.py`. Move to :file:`IPython.core`.
135
135
136 * :file:`ipapi.py`. Move to :file:`IPython.core`.
136 * :file:`ipapi.py`. Move to :file:`IPython.core`.
137
137
138 * :file:`iplib.py`. Move to :file:`IPython.core`.
138 * :file:`iplib.py`. Move to :file:`IPython.core`.
139
139
140 * :file:`ipmaker.py`: Move to :file:`IPython.core`.
140 * :file:`ipmaker.py`: Move to :file:`IPython.core`.
141
141
142 * :file:`ipstruct.py`. Move to :file:`IPython.python`.
142 * :file:`ipstruct.py`. Move to :file:`IPython.python`.
143
143
144 * :file:`irunner.py`. Move to :file:`IPython.scripts`. ???
144 * :file:`irunner.py`. Move to :file:`IPython.scripts`. ???
145
145
146 * :file:`Itpl.py`. Move to :file:`deathrow/Itpl.py`. Copy already in
146 * :file:`Itpl.py`. Move to :file:`deathrow/Itpl.py`. Copy already in
147 :file:`IPython.external`.
147 :file:`IPython.external`.
148
148
149 * :file:`Logger.py`. Move to :file:`IPython/core/logger.py`.
149 * :file:`Logger.py`. Move to :file:`IPython/core/logger.py`.
150
150
151 * :file:`macro.py`. Move to :file:`IPython.core`.
151 * :file:`macro.py`. Move to :file:`IPython.core`.
152
152
153 * :file:`Magic.py`. Move to :file:`IPython/core/magic.py`.
153 * :file:`Magic.py`. Move to :file:`IPython/core/magic.py`.
154
154
155 * :file:`OInspect.py`. Move to :file:`IPython/core/oinspect.py`.
155 * :file:`OInspect.py`. Move to :file:`IPython/core/oinspect.py`.
156
156
157 * :file:`OutputTrap.py`. Move to :file:`IPython/core/outputtrap.py`.
157 * :file:`OutputTrap.py`. Move to :file:`IPython/core/outputtrap.py`.
158
158
159 * :file:`platutils.py`. Move to :file:`IPython.python`.
159 * :file:`platutils.py`. Move to :file:`IPython.python`.
160
160
161 * :file:`platutils_dummy.py`. Move to :file:`IPython.python`.
161 * :file:`platutils_dummy.py`. Move to :file:`IPython.python`.
162
162
163 * :file:`platutils_posix.py`. Move to :file:`IPython.python`.
163 * :file:`platutils_posix.py`. Move to :file:`IPython.python`.
164
164
165 * :file:`platutils_win32.py`. Move to :file:`IPython.python`.
165 * :file:`platutils_win32.py`. Move to :file:`IPython.python`.
166
166
167 * :file:`prefilter.py`: Move to :file:`IPython.core`.
167 * :file:`prefilter.py`: Move to :file:`IPython.core`.
168
168
169 * :file:`Prompts.py`. Move to :file:`IPython/core/prompts.py` or
169 * :file:`Prompts.py`. Move to :file:`IPython/core/prompts.py` or
170 :file:`IPython/frontend/prompts.py`.
170 :file:`IPython/frontend/prompts.py`.
171
171
172 * :file:`PyColorize.py`. Replace with pygments? If not, move to
172 * :file:`PyColorize.py`. Replace with pygments? If not, move to
173 :file:`IPython/core/pycolorize.py`. Maybe move to :mod:`IPython.lib` or
173 :file:`IPython/core/pycolorize.py`. Maybe move to :mod:`IPython.lib` or
174 :mod:`IPython.python`?
174 :mod:`IPython.python`?
175
175
176 * :file:`Release.py`. Move to ??? or remove?
176 * :file:`Release.py`. Move to ??? or remove?
177
177
178 * :file:`rlineimpl.py`. Move to :file:`IPython.core`.
178 * :file:`rlineimpl.py`. Move to :file:`IPython.core`.
179
179
180 * :file:`shadowns.py`. Move to :file:`IPython.core`.
180 * :file:`shadowns.py`. Move to :file:`IPython.core`.
181
181
182 * :file:`Shell.py`. Move to :file:`IPython.core.shell.py` or
182 * :file:`Shell.py`. Move to :file:`IPython.core.shell.py` or
183 :file:`IPython/frontend/shell.py`.
183 :file:`IPython/frontend/shell.py`.
184
184
185 * :file:`shellglobals.py`. Move to :file:`IPython.core`.
185 * :file:`shellglobals.py`. Move to :file:`IPython.core`.
186
186
187 * :file:`strdispatch.py`. Move to :file:`IPython.python`.
187 * :file:`strdispatch.py`. Move to :file:`IPython.python`.
188
188
189 * :file:`testing`. Good where it is.
189 * :file:`testing`. Good where it is.
190
190
191 * :file:`tests`. Good where it is.
191 * :file:`tests`. Good where it is.
192
192
193 * :file:`tools`. Things in here need to be looked at and moved elsewhere like
193 * :file:`tools`. Things in here need to be looked at and moved elsewhere like
194 :file:`IPython.python`.
194 :file:`IPython.python`.
195
195
196 * :file:`UserConfig`. Move to a subdirectory of :file:`IPython.config`.
196 * :file:`UserConfig`. Move to a subdirectory of :file:`IPython.config`.
197
197
198
198
199
199
200
200
201 * :file:`config`. Good where it is!
201 * :file:`config`. Good where it is!
202
202
203 * :file:`external`. Good where it is!
203 * :file:`external`. Good where it is!
204
204
205 * :file:`frontend`. Good where it is!
205 * :file:`frontend`. Good where it is!
206
206
207
207
208
208
209 * :file:`gui`. Eventually this should be moved to a subdir of
209 * :file:`gui`. Eventually this should be moved to a subdir of
210 :file:`IPython.frontend`.
210 :file:`IPython.frontend`.
211
211
212
212
213
213
214
214
215
215
216
216
217
217
218
218
219
219
220
220
221
221
222 * :file:`kernel`. Good where it is.
222 * :file:`kernel`. Good where it is.
223
223
224
224
225
225
226
226
227
227
228
228
229
229
230
230
231
231
232
232
233
233
234
234
235
235
236
236
237
237
238 * :file:`twshell.py`. Move to :file:`IPython.sandbox`.
238 * :file:`twshell.py`. Move to :file:`IPython.sandbox`.
239
239
240 * :file:`ultraTB.py`. Move to :file:`IPython/core/ultratb.py`.
240 * :file:`ultraTB.py`. Move to :file:`IPython/core/ultratb.py`.
241
241
242 * :file:`upgrade_dir.py`. Move to :file:`IPython/python/upgradedir.py`.
242 * :file:`upgrade_dir.py`. Move to :file:`IPython/utils/upgradedir.py`.
243
243
244 * :file:`usage.py`. Move to :file:`IPython.core`.
244 * :file:`usage.py`. Move to :file:`IPython.core`.
245
245
246 * :file:`wildcard.py`. Move to :file:`IPython.python` or :file:`IPython.core`.
246 * :file:`wildcard.py`. Move to :file:`IPython.utils`.
247
247
248 * :file:`winconsole.py`. Move to :file:`IPython.lib`.
248 * :file:`winconsole.py`. Move to :file:`IPython.lib`.
249
249
250 Other things
250 Other things
251 ============
251 ============
252
252
253 When these files are moved around, a number of other things will happen at the same time:
253 When these files are moved around, a number of other things will happen at the same time:
254
254
255 1. Test files will be created for each module in IPython. Minimally, all
255 1. Test files will be created for each module in IPython. Minimally, all
256 modules will be imported as a part of the test. This will serve as a
256 modules will be imported as a part of the test. This will serve as a
257 test of the module reorganization. These tests will be put into new
257 test of the module reorganization. These tests will be put into new
258 :file:`tests` subdirectories that each package will have.
258 :file:`tests` subdirectories that each package will have.
259
259
260 2. PyFlakes and other code checkers will be run to look for problems.
260 2. PyFlakes and other code checkers will be run to look for problems.
261
261
262 3. Modules will be renamed to comply with PEP 8 naming conventions: all
262 3. Modules will be renamed to comply with PEP 8 naming conventions: all
263 lowercase and no special characters like ``-`` or ``_``.
263 lowercase and no special characters like ``-`` or ``_``.
264
264
265 4. Existing tests will be moved to the appropriate :file:`tests`
265 4. Existing tests will be moved to the appropriate :file:`tests`
266 subdirectories.
266 subdirectories.
267
267
268
268
269
269
270
270
General Comments 0
You need to be logged in to leave comments. Login now