Merge lp:~fdo.perez/ipython/trunk-dev into lp:ipython/0.11
- trunk-dev
- Merge into trunk
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Brian Granger | Needs Fixing | ||
Review via email: mp+4450@code.launchpad.net |
Commit message
Description of the change
Fernando Perez (fdo.perez) wrote : | # |
- 1172. By Fernando Perez
-
Close https:/
/bugs.launchpad .net/ipython/ +bug/341726 Apply patch submitted by Alexander Clausen <alex-AT-
gc-web. de>. Fixes
incorrect bug reporting URL for IPython and stale SVN references. - 1173. By Fernando Perez
-
Fix https:/
/bugs.launchpad .net/ipython/ +bug/239054 - Made a more robust reset method to fully flush internal state and restore
the system to a clean state. We'll need to see later if %reset should just
call this. For now it's used to release resources. - 1174. By Fernando Perez
-
Fix https:/
/bugs.launchpad .net/ipython/ +bug/284660 Since we now require python 2.4, I applied a simpler version of the patch
mentioned there, simply using the set() builtin everywhere. - 1175. By Fernando Perez
-
Merging from upstream (with a few local cleanups when resolving conflicts).
- 1176. By Fernando Perez
-
Add a note about the conflict winpdb causes with PyTables.
- 1177. By Fernando Perez
-
Fix problems with multiline doctests and add docs about testing.
Also enabled some more testings that were blacklisted, now that the testing
machinery is more robust.
Brian Granger (ellisonbg) wrote : | # |
I just had fun doing this code review. Launchpad has really improved its code review interface. I really like how you can look through the diffs for each file now!
One general comment: I know you like to code in a single branch, but it makes it more difficult to review a branch when there are many revisions on a wide range of topics. I don't think each revision should go in its own branch, but when there is a larger set of revisions addressing a single issue, having all of those revisions in a single topic branch would be nice and make review easier. Also, smaller branches allow code that *is* finished to get into trunk faster without waiting for unrelated code to be finished and reviewed. I am guilty of the "big branch" workflow myself though.
r1168:
As you go through file and clean up the copyright info, please convert the copyright header to our standard one that references the ipython development team. Any specific mention of module authors or maintainers should go into the module docstring.
r1169:
Are the numpy helper scripts for converting docstrings in place and working with our IPython?
How do we want to handle references in our docs. Sphinx can now create a nice references section in the pdf files, but you have to use a particular format for the references. The current form of the references you have put in::
.. _PEP 257: http://
I don't think will end up in the references section. How does numpy handle such things. Have a look at how references are handled in the kernel documentation to see how I have been handling this. My way may not be the best. Let's figure out how all of us should handle this and then document it in our docs.
r1171:
In ipy_profile_
All other revisions are great.
- 1178. By Fernando Perez
-
Merging upstream changes from trunk (after fixing small conflicts).
Fernando Perez (fdo.perez) wrote : | # |
Hey,
I know we talked offline about most of this, but I'll leave things
here for recording purposes.
On Mon, Mar 16, 2009 at 9:39 AM, Brian Granger <email address hidden> wrote:
> Review: Needs Fixing
> I just had fun doing this code review. Launchpad has really improved its code review interface. I really like how you can look through the diffs for each file now!
Yes, it's gotten much better. Launchpad is slowly but surely improving.
>
> One general comment: I know you like to code in a single branch, but it makes it more difficult to review a branch when there are many revisions on a wide range of topics. I don't think each revision should go in its own branch, but when there is a larger set of revisions addressing a single issue, having all of those revisions in a single topic branch would be nice and make review easier. Also, smaller branches allow code that *is* finished to get into trunk faster without waiting for unrelated code to be finished and reviewed. I am guilty of the "big branch" workflow myself though.
Me too, it's certainly a bad habit. As we spoke about, we could
probably settle on a workflow with:
- per-person permanent 'trunk-dev' branches, on which we do easy,
incremental reviewing and merging.
- short-lived 'feature branches' for standalone ideas, more like a
patch in other workflows, just a patch that keeps evolving and that's
easy to track as it changes.
I'll try to do better in the future on this, and I really appreciate
that you took the time to go over this much code. Many thanks.
>
> r1168:
>
> As you go through file and clean up the copyright info, please convert the copyright header to our standard one that references the ipython development team. Any specific mention of module authors or maintainers should go into the module docstring.
As I mentioned, I was really going after the 'import Release'
statements, not after the authorship notices. But from now on, I'll
try to cleanup the copyright notices as I work on files.
> r1169:
>
> Are the numpy helper scripts for converting docstrings in place and working with our IPython?
>
> How do we want to handle references in our docs. Sphinx can now create a nice references section in the pdf files, but you have to use a particular format for the references. The current form of the references you have put in::
>
> .. _PEP 257: http://
>
> I don't think will end up in the references section. How does numpy handle such things. Have a look at how references are handled in the kernel documentation to see how I have been handling this. My way may not be the best. Let's figure out how all of us should handle this and then document it in our docs.
This one, I don't know. I'm going to look into what Matthew Brett did
for Nipy to see if I can find a good overall solution.
> r1171:
>
> In ipy_profile_
I'll do what we discussed: put the authorship notes I find in the
top-level docstring. This has the added benefit of putting them in
the generated API docs.
> All other revisions are great.
Thanks again for reviewing such a monster!
I'l...
- 1179. By Fernando Perez
-
Merging from upstream trunk
- 1180. By Fernando Perez
-
Update copyright/author statements.
- Updated copyright statements to use the new form:
# Copyright (C) 2008-2009 The IPython Development Team
I left the old notices in place (just updating the year in some cases),
because as far as I know, old copyright statements are not meant to be
retroactively modified.- Also, on most files, replaced __author__ marks with an 'Authors' section
in the module docstring. This reduces top-level code in the module, while
ensuring that the Author(s) get properly acknowledged in auto-generated API
docs (sphinx doesn't read __author__ marks, but it will include the module
docstring).I only left a few in place for very old files that we ship externally, and
for those by Laurent: he had his authorship mark both in the docstring and
in __author__ variables, so I think out of courtesy it would be better to
ask him about it on the list. All the others were I found regular
__author__ variables, I moved them to the main docstring.
Fernando Perez (fdo.perez) wrote : | # |
"""
> r1168:
>
> As you go through file and clean up the copyright info, please convert the copyright header to our standard one that references the ipython development team. Any specific mention of module authors or maintainers should go into the module docstring.
As I mentioned, I was really going after the 'import Release'
statements, not after the authorship notices. But from now on, I'll
try to cleanup the copyright notices as I work on files.
"""
I did try to update at least those where I went fixing __author__ marks, as per your other comment. See the log comment in
http://
for more details on the logic I used. I took the 'team' 2008 statement and pushed to 09, and just closed the year gap on the old statements but otherwise left them as they were. I think that's how copyright statements are supposed to be updated, but I'm not sure. Feel free to let me know if it should be done otherwise.
> r1169:
>
> Are the numpy helper scripts for converting docstrings in place and working with our IPython?
Yes, they are. I've started using numpy docstrings in all new functions, and they work fine. I haven't gone updating old ones though... I did add mention of this in the dev docs.
"""
> How do we want to handle references in our docs. Sphinx can now create a nice references section in the pdf files, but you have to use a particular format for the references. The current form of the references you have put in::
>
> .. _PEP 257: http://
>
> I don't think will end up in the references section. How does numpy handle such things. Have a look at how references are handled in the kernel documentation to see how I have been handling this. My way may not be the best. Let's figure out how all of us should handle this and then document it in our docs.
This one, I don't know. I'm going to look into what Matthew Brett did
for Nipy to see if I can find a good overall solution.
"""
I have to admit that I'm stumped on how to handle this one. Since it's not anything new in this branch per se, are you OK with merging and working on it together on trunk? I'm happy to make any local changes to the branch before merging, but I don't have a full solution for the references problem.
"""
> r1171:
>
> In ipy_profile_
I'll do what we discussed: put the authorship notes I find in the
top-level docstring. This has the added benefit of putting them in
the generated API docs.
"""
I did go through most, as noted in the changelog. There's only a few left of very old external files, and Laurent's, which we should ask him about on list.
Thanks for the review!
- 1181. By Fernando Perez
-
Add information about our testing system, test writing tips, etc.
Brian Granger (ellisonbg) wrote : | # |
> I did try to update at least those where I went fixing __author__ marks, as per your other comment. See the log comment in
> http://
> for more details on the logic I used. I took the 'team' 2008 statement and pushed to 09, and just closed the year gap on the old statements but otherwise left them as they were. I think that's how copyright statements are supposed to be updated, but I'm not sure. Feel free to let me know if it should be done otherwise.
Sounds fine by me.
>> r1169:
>>
>> Are the numpy helper scripts for converting docstrings in place and working with our IPython?
>
> Yes, they are. I've started using numpy docstrings in all new functions, and they work fine. I haven't gone updating old ones though... I did add mention of this in the dev docs.
Great, I will start to write my docstring to this format.
>> How do we want to handle references in our docs. Sphinx can now create a nice references section in the pdf files, but you have to use a particular format for the references. The current form of the references you have put in::
>>
>> .. _PEP 257: http://
>>
>> I don't think will end up in the references section. How does numpy handle such things. Have a look at how references are handled in the kernel documentation to see how I have been handling this. My way may not be the best. Let's figure out how all of us should handle this and then document it in our docs.
>
>
> This one, I don't know. I'm going to look into what Matthew Brett did
> for Nipy to see if I can find a good overall solution.
> """
>
> I have to admit that I'm stumped on how to handle this one. Since it's not anything new in this branch per se, are you OK with merging and working on it together on trunk? I'm happy to make any local changes to the branch before merging, but I don't have a full solution for the references problem.
That is fine. Just do the merge and we can slowly figure this one out.
It is not a big deal because our existing refs don't do anything in
particular in this area, so we will have to change things anyway.
> Thanks for the review!
No problem.
Brian
--
Brian E. Granger, Ph.D.
Assistant Professor of Physics
Cal Poly State University, San Luis Obispo
<email address hidden>
<email address hidden>
- 1182. By Fernando Perez
-
Add a .bzrignore file for cleaner 'bzr status' output
Fernando Perez (fdo.perez) wrote : | # |
On Tue, Mar 17, 2009 at 7:15 AM, Brian Granger <email address hidden> wrote:
> That is fine. Just do the merge and we can slowly figure this one out.
> It is not a big deal because our existing refs don't do anything in
> particular in this area, so we will have to change things anyway.
OK. I just did the merge, this is large enough that I'll put a
message on the list so everyone can test it.
Thanks again for the review work, this one was a lot to look at :)
Cheers,
f
Preview Diff
1 | === modified file 'IPython/ColorANSI.py' | |||
2 | --- IPython/ColorANSI.py 2008-08-28 22:00:22 +0000 | |||
3 | +++ IPython/ColorANSI.py 2009-03-11 06:53:19 +0000 | |||
4 | @@ -1,7 +1,6 @@ | |||
5 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
6 | 2 | """Tools for coloring text in ANSI terminals. | 2 | """Tools for coloring text in ANSI terminals. |
9 | 3 | 3 | """ | |
8 | 4 | $Id: ColorANSI.py 2167 2007-03-21 06:57:50Z fperez $""" | ||
10 | 5 | 4 | ||
11 | 6 | #***************************************************************************** | 5 | #***************************************************************************** |
12 | 7 | # Copyright (C) 2002-2006 Fernando Perez. <fperez@colorado.edu> | 6 | # Copyright (C) 2002-2006 Fernando Perez. <fperez@colorado.edu> |
13 | @@ -10,10 +9,6 @@ | |||
14 | 10 | # the file COPYING, distributed as part of this software. | 9 | # the file COPYING, distributed as part of this software. |
15 | 11 | #***************************************************************************** | 10 | #***************************************************************************** |
16 | 12 | 11 | ||
17 | 13 | from IPython import Release | ||
18 | 14 | __author__ = '%s <%s>' % Release.authors['Fernando'] | ||
19 | 15 | __license__ = Release.license | ||
20 | 16 | |||
21 | 17 | __all__ = ['TermColors','InputTermColors','ColorScheme','ColorSchemeTable'] | 12 | __all__ = ['TermColors','InputTermColors','ColorScheme','ColorSchemeTable'] |
22 | 18 | 13 | ||
23 | 19 | import os | 14 | import os |
24 | 20 | 15 | ||
25 | === modified file 'IPython/ConfigLoader.py' | |||
26 | --- IPython/ConfigLoader.py 2008-02-28 18:21:11 +0000 | |||
27 | +++ IPython/ConfigLoader.py 2009-03-11 06:53:19 +0000 | |||
28 | @@ -1,7 +1,6 @@ | |||
29 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
30 | 2 | """Configuration loader | 2 | """Configuration loader |
33 | 3 | 3 | """ | |
32 | 4 | $Id: ConfigLoader.py 1005 2006-01-12 08:39:26Z fperez $""" | ||
34 | 5 | 4 | ||
35 | 6 | #***************************************************************************** | 5 | #***************************************************************************** |
36 | 7 | # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu> | 6 | # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu> |
37 | @@ -10,10 +9,6 @@ | |||
38 | 10 | # the file COPYING, distributed as part of this software. | 9 | # the file COPYING, distributed as part of this software. |
39 | 11 | #***************************************************************************** | 10 | #***************************************************************************** |
40 | 12 | 11 | ||
41 | 13 | from IPython import Release | ||
42 | 14 | __author__ = '%s <%s>' % Release.authors['Fernando'] | ||
43 | 15 | __license__ = Release.license | ||
44 | 16 | |||
45 | 17 | import exceptions | 12 | import exceptions |
46 | 18 | import os | 13 | import os |
47 | 19 | from pprint import pprint | 14 | from pprint import pprint |
48 | @@ -73,14 +68,14 @@ | |||
49 | 73 | # avoid including the same file more than once | 68 | # avoid including the same file more than once |
50 | 74 | if fname in self.included: | 69 | if fname in self.included: |
51 | 75 | return data | 70 | return data |
53 | 76 | Xinfo = ultraTB.AutoFormattedTB() | 71 | Xinfo = ultraTB.AutoFormattedTB(color_scheme='NoColor') |
54 | 77 | if convert==None and recurse_key : convert = {qwflat:recurse_key} | 72 | if convert==None and recurse_key : convert = {qwflat:recurse_key} |
55 | 78 | # for production, change warn to 0: | 73 | # for production, change warn to 0: |
56 | 79 | data.merge(read_dict(fname,convert,fs=self.field_sep,strip=1, | 74 | data.merge(read_dict(fname,convert,fs=self.field_sep,strip=1, |
57 | 80 | warn=0,no_empty=0,**kw)) | 75 | warn=0,no_empty=0,**kw)) |
58 | 81 | # keep track of successfully loaded files | 76 | # keep track of successfully loaded files |
59 | 82 | self.included.append(fname) | 77 | self.included.append(fname) |
61 | 83 | if recurse_key in data.keys(): | 78 | if recurse_key in data: |
62 | 84 | for incfilename in data[recurse_key]: | 79 | for incfilename in data[recurse_key]: |
63 | 85 | found=0 | 80 | found=0 |
64 | 86 | try: | 81 | try: |
65 | 87 | 82 | ||
66 | === modified file 'IPython/CrashHandler.py' | |||
67 | --- IPython/CrashHandler.py 2008-02-28 18:21:11 +0000 | |||
68 | +++ IPython/CrashHandler.py 2009-03-11 06:53:19 +0000 | |||
69 | @@ -1,7 +1,6 @@ | |||
70 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
71 | 2 | """sys.excepthook for IPython itself, leaves a detailed report on disk. | 2 | """sys.excepthook for IPython itself, leaves a detailed report on disk. |
74 | 3 | 3 | """ | |
73 | 4 | $Id: CrashHandler.py 2908 2007-12-30 21:07:46Z vivainio $""" | ||
75 | 5 | 4 | ||
76 | 6 | #***************************************************************************** | 5 | #***************************************************************************** |
77 | 7 | # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu> | 6 | # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu> |
78 | 8 | 7 | ||
79 | === modified file 'IPython/DPyGetOpt.py' | |||
80 | --- IPython/DPyGetOpt.py 2008-02-28 18:21:11 +0000 | |||
81 | +++ IPython/DPyGetOpt.py 2009-03-11 06:53:19 +0000 | |||
82 | @@ -1,8 +1,6 @@ | |||
83 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
84 | 2 | """DPyGetOpt -- Demiurge Python GetOptions Module | 2 | """DPyGetOpt -- Demiurge Python GetOptions Module |
85 | 3 | 3 | ||
86 | 4 | $Id: DPyGetOpt.py 2872 2007-11-25 17:58:05Z fperez $ | ||
87 | 5 | |||
88 | 6 | This module is modeled after perl's Getopt::Long module-- which | 4 | This module is modeled after perl's Getopt::Long module-- which |
89 | 7 | is, in turn, modeled after GNU's extended getopt() function. | 5 | is, in turn, modeled after GNU's extended getopt() function. |
90 | 8 | 6 | ||
91 | @@ -32,8 +30,7 @@ | |||
92 | 32 | and -baz options that appear on within the parsed argument list | 30 | and -baz options that appear on within the parsed argument list |
93 | 33 | must have a real number argument and that the accumulated list | 31 | must have a real number argument and that the accumulated list |
94 | 34 | of values will be available under the name 'foo' | 32 | of values will be available under the name 'foo' |
97 | 35 | 33 | """ | |
96 | 36 | $Id: DPyGetOpt.py 2872 2007-11-25 17:58:05Z fperez $""" | ||
98 | 37 | 34 | ||
99 | 38 | #***************************************************************************** | 35 | #***************************************************************************** |
100 | 39 | # | 36 | # |
101 | 40 | 37 | ||
102 | === modified file 'IPython/Debugger.py' | |||
103 | --- IPython/Debugger.py 2008-06-07 06:50:18 +0000 | |||
104 | +++ IPython/Debugger.py 2009-03-11 06:53:19 +0000 | |||
105 | @@ -13,9 +13,7 @@ | |||
106 | 13 | changes. Licensing should therefore be under the standard Python terms. For | 13 | changes. Licensing should therefore be under the standard Python terms. For |
107 | 14 | details on the PSF (Python Software Foundation) standard license, see: | 14 | details on the PSF (Python Software Foundation) standard license, see: |
108 | 15 | 15 | ||
112 | 16 | http://www.python.org/2.2.3/license.html | 16 | http://www.python.org/2.2.3/license.html""" |
110 | 17 | |||
111 | 18 | $Id: Debugger.py 2913 2007-12-31 12:42:14Z vivainio $""" | ||
113 | 19 | 17 | ||
114 | 20 | #***************************************************************************** | 18 | #***************************************************************************** |
115 | 21 | # | 19 | # |
116 | @@ -27,10 +25,6 @@ | |||
117 | 27 | # | 25 | # |
118 | 28 | #***************************************************************************** | 26 | #***************************************************************************** |
119 | 29 | 27 | ||
120 | 30 | from IPython import Release | ||
121 | 31 | __author__ = '%s <%s>' % Release.authors['Fernando'] | ||
122 | 32 | __license__ = 'Python' | ||
123 | 33 | |||
124 | 34 | import bdb | 28 | import bdb |
125 | 35 | import cmd | 29 | import cmd |
126 | 36 | import linecache | 30 | import linecache |
127 | @@ -39,7 +33,7 @@ | |||
128 | 39 | 33 | ||
129 | 40 | from IPython import PyColorize, ColorANSI, ipapi | 34 | from IPython import PyColorize, ColorANSI, ipapi |
130 | 41 | from IPython.genutils import Term | 35 | from IPython.genutils import Term |
132 | 42 | from IPython.excolors import ExceptionColors | 36 | from IPython.excolors import exception_colors |
133 | 43 | 37 | ||
134 | 44 | # See if we can use pydb. | 38 | # See if we can use pydb. |
135 | 45 | has_pydb = False | 39 | has_pydb = False |
136 | @@ -210,7 +204,7 @@ | |||
137 | 210 | 204 | ||
138 | 211 | # Create color table: we copy the default one from the traceback | 205 | # Create color table: we copy the default one from the traceback |
139 | 212 | # module and add a few attributes needed for debugging | 206 | # module and add a few attributes needed for debugging |
141 | 213 | self.color_scheme_table = ExceptionColors.copy() | 207 | self.color_scheme_table = exception_colors() |
142 | 214 | 208 | ||
143 | 215 | # shorthands | 209 | # shorthands |
144 | 216 | C = ColorANSI.TermColors | 210 | C = ColorANSI.TermColors |
145 | @@ -257,8 +251,7 @@ | |||
146 | 257 | 251 | ||
147 | 258 | # Create color table: we copy the default one from the traceback | 252 | # Create color table: we copy the default one from the traceback |
148 | 259 | # module and add a few attributes needed for debugging | 253 | # module and add a few attributes needed for debugging |
151 | 260 | ExceptionColors.set_active_scheme(color_scheme) | 254 | self.color_scheme_table = exception_colors() |
150 | 261 | self.color_scheme_table = ExceptionColors.copy() | ||
152 | 262 | 255 | ||
153 | 263 | # shorthands | 256 | # shorthands |
154 | 264 | C = ColorANSI.TermColors | 257 | C = ColorANSI.TermColors |
155 | 265 | 258 | ||
156 | === modified file 'IPython/Extensions/InterpreterExec.py' | |||
157 | --- IPython/Extensions/InterpreterExec.py 2008-02-28 18:21:11 +0000 | |||
158 | +++ IPython/Extensions/InterpreterExec.py 2009-03-11 06:53:19 +0000 | |||
159 | @@ -4,8 +4,7 @@ | |||
160 | 4 | We define a special input line filter to allow typing lines which begin with | 4 | We define a special input line filter to allow typing lines which begin with |
161 | 5 | '~', '/' or '.'. If one of those strings is encountered, it is automatically | 5 | '~', '/' or '.'. If one of those strings is encountered, it is automatically |
162 | 6 | executed. | 6 | executed. |
165 | 7 | 7 | """ | |
164 | 8 | $Id: InterpreterExec.py 2724 2007-09-07 08:05:38Z fperez $""" | ||
166 | 9 | 8 | ||
167 | 10 | #***************************************************************************** | 9 | #***************************************************************************** |
168 | 11 | # Copyright (C) 2004 W.J. van der Laan <gnufnork@hetdigitalegat.nl> | 10 | # Copyright (C) 2004 W.J. van der Laan <gnufnork@hetdigitalegat.nl> |
169 | @@ -15,11 +14,6 @@ | |||
170 | 15 | # the file COPYING, distributed as part of this software. | 14 | # the file COPYING, distributed as part of this software. |
171 | 16 | #***************************************************************************** | 15 | #***************************************************************************** |
172 | 17 | 16 | ||
173 | 18 | from IPython import Release | ||
174 | 19 | __author__ = 'W.J. van der Laan <gnufnork@hetdigitalegat.nl>, '\ | ||
175 | 20 | '%s <%s>' % Release.authors['Fernando'] | ||
176 | 21 | __license__ = Release.license | ||
177 | 22 | |||
178 | 23 | # TODO: deprecated | 17 | # TODO: deprecated |
179 | 24 | def prefilter_shell(self,line,continuation): | 18 | def prefilter_shell(self,line,continuation): |
180 | 25 | """Alternate prefilter, modified for shell-like functionality. | 19 | """Alternate prefilter, modified for shell-like functionality. |
181 | 26 | 20 | ||
182 | === modified file 'IPython/Extensions/clearcmd.py' | |||
183 | --- IPython/Extensions/clearcmd.py 2008-02-16 09:50:47 +0000 | |||
184 | +++ IPython/Extensions/clearcmd.py 2009-03-10 19:39:05 +0000 | |||
185 | @@ -5,43 +5,65 @@ | |||
186 | 5 | import gc | 5 | import gc |
187 | 6 | ip = IPython.ipapi.get() | 6 | ip = IPython.ipapi.get() |
188 | 7 | 7 | ||
189 | 8 | |||
190 | 9 | def clear_f(self,arg): | 8 | def clear_f(self,arg): |
191 | 10 | """ Clear various data (e.g. stored history data) | 9 | """ Clear various data (e.g. stored history data) |
192 | 11 | 10 | ||
193 | 11 | %clear in - clear input history | ||
194 | 12 | %clear out - clear output history | 12 | %clear out - clear output history |
195 | 13 | %clear in - clear input history | ||
196 | 14 | %clear shadow_compress - Compresses shadow history (to speed up ipython) | 13 | %clear shadow_compress - Compresses shadow history (to speed up ipython) |
197 | 15 | %clear shadow_nuke - permanently erase all entries in shadow history | 14 | %clear shadow_nuke - permanently erase all entries in shadow history |
198 | 16 | %clear dhist - clear dir history | 15 | %clear dhist - clear dir history |
199 | 16 | %clear array - clear only variables that are NumPy arrays | ||
200 | 17 | |||
201 | 18 | Examples: | ||
202 | 19 | |||
203 | 20 | In [1]: clear in | ||
204 | 21 | Flushing input history | ||
205 | 22 | |||
206 | 23 | In [2]: clear shadow_compress | ||
207 | 24 | Compressing shadow history | ||
208 | 25 | |||
209 | 26 | In [3]: clear shadow_nuke | ||
210 | 27 | Erased all keys from shadow history | ||
211 | 28 | |||
212 | 29 | In [4]: clear dhist | ||
213 | 30 | Clearing directory history | ||
214 | 17 | """ | 31 | """ |
215 | 18 | 32 | ||
216 | 19 | api = self.getapi() | 33 | api = self.getapi() |
217 | 34 | user_ns = self.user_ns # local lookup, heavily used | ||
218 | 35 | |||
219 | 36 | |||
220 | 20 | for target in arg.split(): | 37 | for target in arg.split(): |
221 | 38 | |||
222 | 21 | if target == 'out': | 39 | if target == 'out': |
224 | 22 | print "Flushing output cache (%d entries)" % len(api.user_ns['_oh']) | 40 | print "Flushing output cache (%d entries)" % len(user_ns['_oh']) |
225 | 23 | self.outputcache.flush() | 41 | self.outputcache.flush() |
226 | 42 | |||
227 | 24 | elif target == 'in': | 43 | elif target == 'in': |
228 | 25 | print "Flushing input history" | 44 | print "Flushing input history" |
229 | 26 | from IPython import iplib | ||
230 | 27 | pc = self.outputcache.prompt_count + 1 | 45 | pc = self.outputcache.prompt_count + 1 |
231 | 28 | for n in range(1, pc): | 46 | for n in range(1, pc): |
232 | 29 | key = '_i'+`n` | 47 | key = '_i'+`n` |
233 | 48 | user_ns.pop(key,None) | ||
234 | 30 | try: | 49 | try: |
236 | 31 | del self.user_ns[key] | 50 | del user_ns[key] |
237 | 32 | except: pass | 51 | except: pass |
238 | 33 | # must be done in-place | 52 | # must be done in-place |
239 | 34 | self.input_hist[:] = ['\n'] * pc | 53 | self.input_hist[:] = ['\n'] * pc |
240 | 35 | self.input_hist_raw[:] = ['\n'] * pc | 54 | self.input_hist_raw[:] = ['\n'] * pc |
241 | 55 | |||
242 | 36 | elif target == 'array': | 56 | elif target == 'array': |
243 | 57 | # Support cleaning up numpy arrays | ||
244 | 37 | try: | 58 | try: |
249 | 38 | pylab=ip.IP.pylab | 59 | from numpy import ndarray |
250 | 39 | for x in self.user_ns.keys(): | 60 | # This must be done with items and not iteritems because we're |
251 | 40 | if isinstance(self.user_ns[x],pylab.arraytype): | 61 | # going to modify the dict in-place. |
252 | 41 | del self.user_ns[x] | 62 | for x,val in user_ns.items(): |
253 | 63 | if isinstance(val,ndarray): | ||
254 | 64 | del user_ns[x] | ||
255 | 42 | except AttributeError: | 65 | except AttributeError: |
258 | 43 | print "Clear array only available in -pylab mode" | 66 | print "Clear array only works if Numpy is available." |
257 | 44 | gc.collect() | ||
259 | 45 | 67 | ||
260 | 46 | elif target == 'shadow_compress': | 68 | elif target == 'shadow_compress': |
261 | 47 | print "Compressing shadow history" | 69 | print "Compressing shadow history" |
262 | @@ -51,16 +73,15 @@ | |||
263 | 51 | print "Erased all keys from shadow history " | 73 | print "Erased all keys from shadow history " |
264 | 52 | for k in ip.db.keys('shadowhist/*'): | 74 | for k in ip.db.keys('shadowhist/*'): |
265 | 53 | del ip.db[k] | 75 | del ip.db[k] |
266 | 76 | |||
267 | 54 | elif target == 'dhist': | 77 | elif target == 'dhist': |
268 | 55 | print "Clearing directory history" | 78 | print "Clearing directory history" |
272 | 56 | del ip.user_ns['_dh'][:] | 79 | del user_ns['_dh'][:] |
273 | 57 | 80 | ||
274 | 58 | 81 | gc.collect() | |
275 | 82 | |||
276 | 83 | # Activate the extension | ||
277 | 59 | ip.expose_magic("clear",clear_f) | 84 | ip.expose_magic("clear",clear_f) |
278 | 60 | import ipy_completers | 85 | import ipy_completers |
279 | 61 | ipy_completers.quick_completer( | 86 | ipy_completers.quick_completer( |
285 | 62 | '%clear','in out shadow_nuke shadow_compress dhist') | 87 | '%clear','in out shadow_nuke shadow_compress dhist') |
281 | 63 | |||
282 | 64 | |||
283 | 65 | |||
284 | 66 | |||
286 | 67 | 88 | ||
287 | === modified file 'IPython/Extensions/ext_rescapture.py' | |||
288 | --- IPython/Extensions/ext_rescapture.py 2008-02-16 09:50:47 +0000 | |||
289 | +++ IPython/Extensions/ext_rescapture.py 2009-03-11 06:53:19 +0000 | |||
290 | @@ -6,9 +6,6 @@ | |||
291 | 6 | var = %magic blah blah | 6 | var = %magic blah blah |
292 | 7 | 7 | ||
293 | 8 | var = !ls | 8 | var = !ls |
294 | 9 | |||
295 | 10 | $Id: genutils.py 1077 2006-01-24 18:15:27Z vivainio $ | ||
296 | 11 | |||
297 | 12 | """ | 9 | """ |
298 | 13 | 10 | ||
299 | 14 | import IPython.ipapi | 11 | import IPython.ipapi |
300 | 15 | 12 | ||
301 | === modified file 'IPython/Extensions/ipy_profile_zope.py' | |||
302 | --- IPython/Extensions/ipy_profile_zope.py 2008-02-16 09:50:47 +0000 | |||
303 | +++ IPython/Extensions/ipy_profile_zope.py 2009-03-13 17:56:47 +0000 | |||
304 | @@ -12,7 +12,6 @@ | |||
305 | 12 | 12 | ||
306 | 13 | __author__ = """Stefan Eletzhofer <stefan.eletzhofer@inquant.de>""" | 13 | __author__ = """Stefan Eletzhofer <stefan.eletzhofer@inquant.de>""" |
307 | 14 | __docformat__ = 'plaintext' | 14 | __docformat__ = 'plaintext' |
308 | 15 | __revision__ = "$Revision$" | ||
309 | 16 | 15 | ||
310 | 17 | from IPython import ipapi | 16 | from IPython import ipapi |
311 | 18 | from IPython import Release | 17 | from IPython import Release |
312 | 19 | 18 | ||
313 | === modified file 'IPython/Extensions/pspersistence.py' | |||
314 | --- IPython/Extensions/pspersistence.py 2008-06-03 20:03:02 +0000 | |||
315 | +++ IPython/Extensions/pspersistence.py 2009-03-11 06:53:19 +0000 | |||
316 | @@ -3,8 +3,6 @@ | |||
317 | 3 | %store magic for lightweight persistence. | 3 | %store magic for lightweight persistence. |
318 | 4 | 4 | ||
319 | 5 | Stores variables, aliases etc. in PickleShare database. | 5 | Stores variables, aliases etc. in PickleShare database. |
320 | 6 | |||
321 | 7 | $Id: iplib.py 1107 2006-01-30 19:02:20Z vivainio $ | ||
322 | 8 | """ | 6 | """ |
323 | 9 | 7 | ||
324 | 10 | import IPython.ipapi | 8 | import IPython.ipapi |
325 | 11 | 9 | ||
326 | === modified file 'IPython/FakeModule.py' | |||
327 | --- IPython/FakeModule.py 2008-02-28 18:21:11 +0000 | |||
328 | +++ IPython/FakeModule.py 2009-03-11 06:53:19 +0000 | |||
329 | @@ -4,8 +4,7 @@ | |||
330 | 4 | 4 | ||
331 | 5 | Needed to allow pickle to correctly resolve namespaces during IPython | 5 | Needed to allow pickle to correctly resolve namespaces during IPython |
332 | 6 | sessions. | 6 | sessions. |
335 | 7 | 7 | """ | |
334 | 8 | $Id: FakeModule.py 2754 2007-09-09 10:16:59Z fperez $""" | ||
336 | 9 | 8 | ||
337 | 10 | #***************************************************************************** | 9 | #***************************************************************************** |
338 | 11 | # Copyright (C) 2002-2004 Fernando Perez. <fperez@colorado.edu> | 10 | # Copyright (C) 2002-2004 Fernando Perez. <fperez@colorado.edu> |
339 | 12 | 11 | ||
340 | === modified file 'IPython/Gnuplot2.py' | |||
341 | --- IPython/Gnuplot2.py 2008-02-28 18:21:11 +0000 | |||
342 | +++ IPython/Gnuplot2.py 2009-03-11 06:53:19 +0000 | |||
343 | @@ -12,8 +12,7 @@ | |||
344 | 12 | Gnuplot, so it should be safe to do: | 12 | Gnuplot, so it should be safe to do: |
345 | 13 | 13 | ||
346 | 14 | import IPython.Gnuplot2 as Gnuplot | 14 | import IPython.Gnuplot2 as Gnuplot |
349 | 15 | 15 | """ | |
348 | 16 | $Id: Gnuplot2.py 1210 2006-03-13 01:19:31Z fperez $""" | ||
350 | 17 | 16 | ||
351 | 18 | import cStringIO | 17 | import cStringIO |
352 | 19 | import os | 18 | import os |
353 | 20 | 19 | ||
354 | === modified file 'IPython/GnuplotInteractive.py' | |||
355 | --- IPython/GnuplotInteractive.py 2008-02-28 18:21:11 +0000 | |||
356 | +++ IPython/GnuplotInteractive.py 2009-03-11 06:53:19 +0000 | |||
357 | @@ -9,8 +9,7 @@ | |||
358 | 9 | See gphelp() below for details on the services offered by this module. | 9 | See gphelp() below for details on the services offered by this module. |
359 | 10 | 10 | ||
360 | 11 | Inspired by a suggestion/request from Arnd Baecker. | 11 | Inspired by a suggestion/request from Arnd Baecker. |
363 | 12 | 12 | """ | |
362 | 13 | $Id: GnuplotInteractive.py 389 2004-10-09 07:59:30Z fperez $""" | ||
364 | 14 | 13 | ||
365 | 15 | __all__ = ['Gnuplot','gp','gp_new','plot','plot2','splot','replot', | 14 | __all__ = ['Gnuplot','gp','gp_new','plot','plot2','splot','replot', |
366 | 16 | 'hardcopy','gpdata','gpfile','gpstring','gpfunc','gpgrid', | 15 | 'hardcopy','gpdata','gpfile','gpstring','gpfunc','gpgrid', |
367 | 17 | 16 | ||
368 | === modified file 'IPython/GnuplotRuntime.py' | |||
369 | --- IPython/GnuplotRuntime.py 2008-02-28 18:21:11 +0000 | |||
370 | +++ IPython/GnuplotRuntime.py 2009-03-11 06:53:19 +0000 | |||
371 | @@ -47,8 +47,7 @@ | |||
372 | 47 | http://gnuplot-py.sourceforge.net/ | 47 | http://gnuplot-py.sourceforge.net/ |
373 | 48 | 48 | ||
374 | 49 | Inspired by a suggestion/request from Arnd Baecker. | 49 | Inspired by a suggestion/request from Arnd Baecker. |
377 | 50 | 50 | """ | |
376 | 51 | $Id: GnuplotRuntime.py 389 2004-10-09 07:59:30Z fperez $""" | ||
378 | 52 | 51 | ||
379 | 53 | __all__ = ['Gnuplot','gp','gp_new','Data','File','Func','GridData', | 52 | __all__ = ['Gnuplot','gp','gp_new','Data','File','Func','GridData', |
380 | 54 | 'pm3d_config','eps_fix_bbox'] | 53 | 'pm3d_config','eps_fix_bbox'] |
381 | 55 | 54 | ||
382 | === modified file 'IPython/Itpl.py' | |||
383 | --- IPython/Itpl.py 2008-05-15 05:05:58 +0000 | |||
384 | +++ IPython/Itpl.py 2009-03-11 06:53:19 +0000 | |||
385 | @@ -27,7 +27,7 @@ | |||
386 | 27 | import Itpl | 27 | import Itpl |
387 | 28 | sys.stdout = Itpl.filter() | 28 | sys.stdout = Itpl.filter() |
388 | 29 | f = "fancy" | 29 | f = "fancy" |
390 | 30 | print "Isn't this $f?" | 30 | print "Is this not $f?" |
391 | 31 | print "Standard output has been replaced with a $sys.stdout object." | 31 | print "Standard output has been replaced with a $sys.stdout object." |
392 | 32 | sys.stdout = Itpl.unfilter() | 32 | sys.stdout = Itpl.unfilter() |
393 | 33 | print "Okay, back $to $normal." | 33 | print "Okay, back $to $normal." |
394 | @@ -43,9 +43,7 @@ | |||
395 | 43 | print str(s) | 43 | print str(s) |
396 | 44 | foo = "bar" | 44 | foo = "bar" |
397 | 45 | print str(s) | 45 | print str(s) |
401 | 46 | 46 | """ | |
399 | 47 | $Id: Itpl.py 2918 2007-12-31 14:34:47Z vivainio $ | ||
400 | 48 | """ # ' -> close an open quote for stupid emacs | ||
402 | 49 | 47 | ||
403 | 50 | #***************************************************************************** | 48 | #***************************************************************************** |
404 | 51 | # | 49 | # |
405 | 52 | 50 | ||
406 | === modified file 'IPython/Logger.py' | |||
407 | --- IPython/Logger.py 2008-08-14 12:48:09 +0000 | |||
408 | +++ IPython/Logger.py 2009-03-11 06:53:19 +0000 | |||
409 | @@ -1,8 +1,6 @@ | |||
410 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
411 | 2 | """ | 2 | """ |
412 | 3 | Logger class for IPython's logging facilities. | 3 | Logger class for IPython's logging facilities. |
413 | 4 | |||
414 | 5 | $Id: Logger.py 2875 2007-11-26 08:37:39Z fperez $ | ||
415 | 6 | """ | 4 | """ |
416 | 7 | 5 | ||
417 | 8 | #***************************************************************************** | 6 | #***************************************************************************** |
418 | @@ -16,11 +14,6 @@ | |||
419 | 16 | #**************************************************************************** | 14 | #**************************************************************************** |
420 | 17 | # Modules and globals | 15 | # Modules and globals |
421 | 18 | 16 | ||
422 | 19 | from IPython import Release | ||
423 | 20 | __author__ = '%s <%s>\n%s <%s>' % \ | ||
424 | 21 | ( Release.authors['Janko'] + Release.authors['Fernando'] ) | ||
425 | 22 | __license__ = Release.license | ||
426 | 23 | |||
427 | 24 | # Python standard modules | 17 | # Python standard modules |
428 | 25 | import glob | 18 | import glob |
429 | 26 | import os | 19 | import os |
430 | 27 | 20 | ||
431 | === modified file 'IPython/Magic.py' | |||
432 | --- IPython/Magic.py 2008-09-17 19:07:48 +0000 | |||
433 | +++ IPython/Magic.py 2009-03-13 17:56:19 +0000 | |||
434 | @@ -1,7 +1,6 @@ | |||
435 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
436 | 2 | """Magic functions for InteractiveShell. | 2 | """Magic functions for InteractiveShell. |
439 | 3 | 3 | """ | |
438 | 4 | $Id: Magic.py 2996 2008-01-30 06:31:39Z fperez $""" | ||
440 | 5 | 4 | ||
441 | 6 | #***************************************************************************** | 5 | #***************************************************************************** |
442 | 7 | # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and | 6 | # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and |
443 | @@ -14,11 +13,6 @@ | |||
444 | 14 | #**************************************************************************** | 13 | #**************************************************************************** |
445 | 15 | # Modules and globals | 14 | # Modules and globals |
446 | 16 | 15 | ||
447 | 17 | from IPython import Release | ||
448 | 18 | __author__ = '%s <%s>\n%s <%s>' % \ | ||
449 | 19 | ( Release.authors['Janko'] + Release.authors['Fernando'] ) | ||
450 | 20 | __license__ = Release.license | ||
451 | 21 | |||
452 | 22 | # Python standard modules | 16 | # Python standard modules |
453 | 23 | import __builtin__ | 17 | import __builtin__ |
454 | 24 | import bdb | 18 | import bdb |
455 | @@ -1050,10 +1044,33 @@ | |||
456 | 1050 | def magic_reset(self, parameter_s=''): | 1044 | def magic_reset(self, parameter_s=''): |
457 | 1051 | """Resets the namespace by removing all names defined by the user. | 1045 | """Resets the namespace by removing all names defined by the user. |
458 | 1052 | 1046 | ||
463 | 1053 | Input/Output history are left around in case you need them.""" | 1047 | Input/Output history are left around in case you need them. |
464 | 1054 | 1048 | ||
465 | 1055 | ans = self.shell.ask_yes_no( | 1049 | Parameters |
466 | 1056 | "Once deleted, variables cannot be recovered. Proceed (y/[n])? ") | 1050 | ---------- |
467 | 1051 | -y : force reset without asking for confirmation. | ||
468 | 1052 | |||
469 | 1053 | Examples | ||
470 | 1054 | -------- | ||
471 | 1055 | In [6]: a = 1 | ||
472 | 1056 | |||
473 | 1057 | In [7]: a | ||
474 | 1058 | Out[7]: 1 | ||
475 | 1059 | |||
476 | 1060 | In [8]: 'a' in _ip.user_ns | ||
477 | 1061 | Out[8]: True | ||
478 | 1062 | |||
479 | 1063 | In [9]: %reset -f | ||
480 | 1064 | |||
481 | 1065 | In [10]: 'a' in _ip.user_ns | ||
482 | 1066 | Out[10]: False | ||
483 | 1067 | """ | ||
484 | 1068 | |||
485 | 1069 | if parameter_s == '-f': | ||
486 | 1070 | ans = True | ||
487 | 1071 | else: | ||
488 | 1072 | ans = self.shell.ask_yes_no( | ||
489 | 1073 | "Once deleted, variables cannot be recovered. Proceed (y/[n])? ") | ||
490 | 1057 | if not ans: | 1074 | if not ans: |
491 | 1058 | print 'Nothing done.' | 1075 | print 'Nothing done.' |
492 | 1059 | return | 1076 | return |
493 | @@ -1063,7 +1080,7 @@ | |||
494 | 1063 | 1080 | ||
495 | 1064 | # Also flush the private list of module references kept for script | 1081 | # Also flush the private list of module references kept for script |
496 | 1065 | # execution protection | 1082 | # execution protection |
498 | 1066 | self.shell._user_main_modules[:] = [] | 1083 | self.shell.clear_main_mod_cache() |
499 | 1067 | 1084 | ||
500 | 1068 | def magic_logstart(self,parameter_s=''): | 1085 | def magic_logstart(self,parameter_s=''): |
501 | 1069 | """Start logging anywhere in a session. | 1086 | """Start logging anywhere in a session. |
502 | @@ -1422,7 +1439,8 @@ | |||
503 | 1422 | return None | 1439 | return None |
504 | 1423 | 1440 | ||
505 | 1424 | @testdec.skip_doctest | 1441 | @testdec.skip_doctest |
507 | 1425 | def magic_run(self, parameter_s ='',runner=None): | 1442 | def magic_run(self, parameter_s ='',runner=None, |
508 | 1443 | file_finder=get_py_filename): | ||
509 | 1426 | """Run the named file inside IPython as a program. | 1444 | """Run the named file inside IPython as a program. |
510 | 1427 | 1445 | ||
511 | 1428 | Usage:\\ | 1446 | Usage:\\ |
512 | @@ -1537,7 +1555,7 @@ | |||
513 | 1537 | mode='list',list_all=1) | 1555 | mode='list',list_all=1) |
514 | 1538 | 1556 | ||
515 | 1539 | try: | 1557 | try: |
517 | 1540 | filename = get_py_filename(arg_lst[0]) | 1558 | filename = file_finder(arg_lst[0]) |
518 | 1541 | except IndexError: | 1559 | except IndexError: |
519 | 1542 | warn('you must provide at least a filename.') | 1560 | warn('you must provide at least a filename.') |
520 | 1543 | print '\n%run:\n',OInspect.getdoc(self.magic_run) | 1561 | print '\n%run:\n',OInspect.getdoc(self.magic_run) |
521 | @@ -1573,10 +1591,13 @@ | |||
522 | 1573 | main_mod = FakeModule() | 1591 | main_mod = FakeModule() |
523 | 1574 | prog_ns = main_mod.__dict__ | 1592 | prog_ns = main_mod.__dict__ |
524 | 1575 | prog_ns['__name__'] = name | 1593 | prog_ns['__name__'] = name |
525 | 1594 | |||
526 | 1576 | # The shell MUST hold a reference to main_mod so after %run exits, | 1595 | # The shell MUST hold a reference to main_mod so after %run exits, |
527 | 1577 | # the python deletion mechanism doesn't zero it out (leaving | 1596 | # the python deletion mechanism doesn't zero it out (leaving |
530 | 1578 | # dangling references) | 1597 | # dangling references). However, we should drop old versions of |
531 | 1579 | self.shell._user_main_modules.append(main_mod) | 1598 | # main_mod. There is now a proper API to manage this caching in |
532 | 1599 | # the main shell object, we use that. | ||
533 | 1600 | self.shell.cache_main_mod(main_mod) | ||
534 | 1580 | 1601 | ||
535 | 1581 | # Since '%run foo' emulates 'python foo.py' at the cmd line, we must | 1602 | # Since '%run foo' emulates 'python foo.py' at the cmd line, we must |
536 | 1582 | # set the __file__ global in the script's namespace | 1603 | # set the __file__ global in the script's namespace |
537 | 1583 | 1604 | ||
538 | === modified file 'IPython/OInspect.py' | |||
539 | --- IPython/OInspect.py 2008-07-29 22:57:51 +0000 | |||
540 | +++ IPython/OInspect.py 2009-03-11 06:53:19 +0000 | |||
541 | @@ -5,8 +5,6 @@ | |||
542 | 5 | 5 | ||
543 | 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 |
544 | 7 | reference the name under which an object is being read. | 7 | reference the name under which an object is being read. |
545 | 8 | |||
546 | 9 | $Id: OInspect.py 2843 2007-10-15 21:22:32Z fperez $ | ||
547 | 10 | """ | 8 | """ |
548 | 11 | 9 | ||
549 | 12 | #***************************************************************************** | 10 | #***************************************************************************** |
550 | @@ -16,10 +14,6 @@ | |||
551 | 16 | # the file COPYING, distributed as part of this software. | 14 | # the file COPYING, distributed as part of this software. |
552 | 17 | #***************************************************************************** | 15 | #***************************************************************************** |
553 | 18 | 16 | ||
554 | 19 | from IPython import Release | ||
555 | 20 | __author__ = '%s <%s>' % Release.authors['Fernando'] | ||
556 | 21 | __license__ = Release.license | ||
557 | 22 | |||
558 | 23 | __all__ = ['Inspector','InspectColors'] | 17 | __all__ = ['Inspector','InspectColors'] |
559 | 24 | 18 | ||
560 | 25 | # stdlib modules | 19 | # stdlib modules |
561 | 26 | 20 | ||
562 | === modified file 'IPython/OutputTrap.py' | |||
563 | --- IPython/OutputTrap.py 2008-02-28 18:21:11 +0000 | |||
564 | +++ IPython/OutputTrap.py 2009-03-11 06:53:19 +0000 | |||
565 | @@ -1,7 +1,6 @@ | |||
566 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
567 | 2 | """Class to trap stdout and stderr and log them separately. | 2 | """Class to trap stdout and stderr and log them separately. |
570 | 3 | 3 | """ | |
569 | 4 | $Id: OutputTrap.py 958 2005-12-27 23:17:51Z fperez $""" | ||
571 | 5 | 4 | ||
572 | 6 | #***************************************************************************** | 5 | #***************************************************************************** |
573 | 7 | # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu> | 6 | # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu> |
574 | @@ -10,10 +9,6 @@ | |||
575 | 10 | # the file COPYING, distributed as part of this software. | 9 | # the file COPYING, distributed as part of this software. |
576 | 11 | #***************************************************************************** | 10 | #***************************************************************************** |
577 | 12 | 11 | ||
578 | 13 | from IPython import Release | ||
579 | 14 | __author__ = '%s <%s>' % Release.authors['Fernando'] | ||
580 | 15 | __license__ = Release.license | ||
581 | 16 | |||
582 | 17 | import exceptions | 12 | import exceptions |
583 | 18 | import sys | 13 | import sys |
584 | 19 | from cStringIO import StringIO | 14 | from cStringIO import StringIO |
585 | 20 | 15 | ||
586 | === modified file 'IPython/Prompts.py' | |||
587 | --- IPython/Prompts.py 2008-02-28 18:21:11 +0000 | |||
588 | +++ IPython/Prompts.py 2009-03-11 06:53:19 +0000 | |||
589 | @@ -1,8 +1,7 @@ | |||
590 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
591 | 2 | """ | 2 | """ |
592 | 3 | Classes for handling input/output prompts. | 3 | Classes for handling input/output prompts. |
595 | 4 | 4 | """ | |
594 | 5 | $Id: Prompts.py 3026 2008-02-07 16:03:16Z vivainio $""" | ||
596 | 6 | 5 | ||
597 | 7 | #***************************************************************************** | 6 | #***************************************************************************** |
598 | 8 | # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu> | 7 | # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu> |
599 | 9 | 8 | ||
600 | === modified file 'IPython/PyColorize.py' | |||
601 | --- IPython/PyColorize.py 2008-08-23 22:34:55 +0000 | |||
602 | +++ IPython/PyColorize.py 2009-03-11 06:53:19 +0000 | |||
603 | @@ -1,34 +1,33 @@ | |||
604 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
605 | 2 | """ | 2 | """ |
635 | 3 | Class and program to colorize python source code for ANSI terminals. | 3 | Class and program to colorize python source code for ANSI terminals. |
636 | 4 | 4 | ||
637 | 5 | Based on an HTML code highlighter by Jurgen Hermann found at: | 5 | Based on an HTML code highlighter by Jurgen Hermann found at: |
638 | 6 | http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52298 | 6 | http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52298 |
639 | 7 | 7 | ||
640 | 8 | Modifications by Fernando Perez (fperez@colorado.edu). | 8 | Modifications by Fernando Perez (fperez@colorado.edu). |
641 | 9 | 9 | ||
642 | 10 | Information on the original HTML highlighter follows: | 10 | Information on the original HTML highlighter follows: |
643 | 11 | 11 | ||
644 | 12 | MoinMoin - Python Source Parser | 12 | MoinMoin - Python Source Parser |
645 | 13 | 13 | ||
646 | 14 | Title: Colorize Python source using the built-in tokenizer | 14 | Title: Colorize Python source using the built-in tokenizer |
647 | 15 | 15 | ||
648 | 16 | Submitter: Jurgen Hermann | 16 | Submitter: Jurgen Hermann |
649 | 17 | Last Updated:2001/04/06 | 17 | Last Updated:2001/04/06 |
650 | 18 | 18 | ||
651 | 19 | Version no:1.2 | 19 | Version no:1.2 |
652 | 20 | 20 | ||
653 | 21 | Description: | 21 | Description: |
654 | 22 | 22 | ||
655 | 23 | This code is part of MoinMoin (http://moin.sourceforge.net/) and converts | 23 | This code is part of MoinMoin (http://moin.sourceforge.net/) and converts |
656 | 24 | Python source code to HTML markup, rendering comments, keywords, | 24 | Python source code to HTML markup, rendering comments, keywords, |
657 | 25 | operators, numeric and string literals in different colors. | 25 | operators, numeric and string literals in different colors. |
658 | 26 | 26 | ||
659 | 27 | It shows how to use the built-in keyword, token and tokenize modules to | 27 | It shows how to use the built-in keyword, token and tokenize modules to |
660 | 28 | scan Python source code and re-emit it with no changes to its original | 28 | scan Python source code and re-emit it with no changes to its original |
661 | 29 | formatting (which is the hard part). | 29 | formatting (which is the hard part). |
662 | 30 | 30 | """ | |
634 | 31 | $Id: PyColorize.py 2586 2007-08-06 19:30:09Z vivainio $""" | ||
663 | 32 | 31 | ||
664 | 33 | __all__ = ['ANSICodeColors','Parser'] | 32 | __all__ = ['ANSICodeColors','Parser'] |
665 | 34 | 33 | ||
666 | 35 | 34 | ||
667 | === modified file 'IPython/Shell.py' | |||
668 | --- IPython/Shell.py 2008-08-24 06:10:55 +0000 | |||
669 | +++ IPython/Shell.py 2009-03-11 06:53:19 +0000 | |||
670 | @@ -3,8 +3,7 @@ | |||
671 | 3 | 3 | ||
672 | 4 | All the matplotlib support code was co-developed with John Hunter, | 4 | All the matplotlib support code was co-developed with John Hunter, |
673 | 5 | matplotlib's author. | 5 | matplotlib's author. |
676 | 6 | 6 | """ | |
675 | 7 | $Id: Shell.py 3024 2008-02-07 15:34:42Z darren.dale $""" | ||
677 | 8 | 7 | ||
678 | 9 | #***************************************************************************** | 8 | #***************************************************************************** |
679 | 10 | # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu> | 9 | # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu> |
680 | @@ -13,10 +12,6 @@ | |||
681 | 13 | # the file COPYING, distributed as part of this software. | 12 | # the file COPYING, distributed as part of this software. |
682 | 14 | #***************************************************************************** | 13 | #***************************************************************************** |
683 | 15 | 14 | ||
684 | 16 | from IPython import Release | ||
685 | 17 | __author__ = '%s <%s>' % Release.authors['Fernando'] | ||
686 | 18 | __license__ = Release.license | ||
687 | 19 | |||
688 | 20 | # Code begins | 15 | # Code begins |
689 | 21 | # Stdlib imports | 16 | # Stdlib imports |
690 | 22 | import __builtin__ | 17 | import __builtin__ |
691 | 23 | 18 | ||
692 | === modified file 'IPython/UserConfig/ipythonrc' | |||
693 | --- IPython/UserConfig/ipythonrc 2008-02-28 18:21:11 +0000 | |||
694 | +++ IPython/UserConfig/ipythonrc 2009-03-13 17:56:47 +0000 | |||
695 | @@ -1,5 +1,4 @@ | |||
696 | 1 | # -*- Mode: Shell-Script -*- Not really, but shows comments correctly | 1 | # -*- Mode: Shell-Script -*- Not really, but shows comments correctly |
697 | 2 | # $Id: ipythonrc 2156 2007-03-19 02:32:19Z fperez $ | ||
698 | 3 | 2 | ||
699 | 4 | #*************************************************************************** | 3 | #*************************************************************************** |
700 | 5 | # | 4 | # |
701 | 6 | 5 | ||
702 | === modified file 'IPython/__init__.py' | |||
703 | --- IPython/__init__.py 2008-08-02 09:05:40 +0000 | |||
704 | +++ IPython/__init__.py 2009-03-11 06:53:19 +0000 | |||
705 | @@ -25,9 +25,8 @@ | |||
706 | 25 | 25 | ||
707 | 26 | iii - serve as an embeddable, ready to go interpreter for your own programs. | 26 | iii - serve as an embeddable, ready to go interpreter for your own programs. |
708 | 27 | 27 | ||
712 | 28 | IPython requires Python 2.3 or newer. | 28 | IPython requires Python 2.4 or newer. |
713 | 29 | 29 | """ | |
711 | 30 | $Id: __init__.py 2399 2007-05-26 10:23:10Z vivainio $""" | ||
714 | 31 | 30 | ||
715 | 32 | #***************************************************************************** | 31 | #***************************************************************************** |
716 | 33 | # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu> | 32 | # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu> |
717 | 34 | 33 | ||
718 | === modified file 'IPython/background_jobs.py' | |||
719 | --- IPython/background_jobs.py 2008-02-28 18:21:11 +0000 | |||
720 | +++ IPython/background_jobs.py 2009-03-11 06:53:19 +0000 | |||
721 | @@ -17,8 +17,6 @@ | |||
722 | 17 | 17 | ||
723 | 18 | (although ultimately no code from this text was used, as IPython's system is a | 18 | (although ultimately no code from this text was used, as IPython's system is a |
724 | 19 | separate implementation). | 19 | separate implementation). |
725 | 20 | |||
726 | 21 | $Id: background_jobs.py 994 2006-01-08 08:29:44Z fperez $ | ||
727 | 22 | """ | 20 | """ |
728 | 23 | 21 | ||
729 | 24 | #***************************************************************************** | 22 | #***************************************************************************** |
730 | @@ -28,10 +26,6 @@ | |||
731 | 28 | # the file COPYING, distributed as part of this software. | 26 | # the file COPYING, distributed as part of this software. |
732 | 29 | #***************************************************************************** | 27 | #***************************************************************************** |
733 | 30 | 28 | ||
734 | 31 | from IPython import Release | ||
735 | 32 | __author__ = '%s <%s>' % Release.authors['Fernando'] | ||
736 | 33 | __license__ = Release.license | ||
737 | 34 | |||
738 | 35 | # Code begins | 29 | # Code begins |
739 | 36 | import sys | 30 | import sys |
740 | 37 | import threading | 31 | import threading |
741 | 38 | 32 | ||
742 | === modified file 'IPython/completer.py' | |||
743 | --- IPython/completer.py 2008-08-21 09:42:55 +0000 | |||
744 | +++ IPython/completer.py 2009-03-11 01:24:53 +0000 | |||
745 | @@ -6,7 +6,6 @@ | |||
746 | 6 | functionality specific to IPython, so this module will continue to live as an | 6 | functionality specific to IPython, so this module will continue to live as an |
747 | 7 | IPython-specific utility. | 7 | IPython-specific utility. |
748 | 8 | 8 | ||
749 | 9 | --------------------------------------------------------------------------- | ||
750 | 10 | Original rlcompleter documentation: | 9 | Original rlcompleter documentation: |
751 | 11 | 10 | ||
752 | 12 | This requires the latest extension to the readline module (the | 11 | This requires the latest extension to the readline module (the |
753 | 13 | 12 | ||
754 | === modified file 'IPython/deep_reload.py' | |||
755 | --- IPython/deep_reload.py 2008-07-17 06:37:49 +0000 | |||
756 | +++ IPython/deep_reload.py 2009-03-11 06:53:19 +0000 | |||
757 | @@ -12,8 +12,7 @@ | |||
758 | 12 | >>> __builtin__.dreload = deep_reload.reload | 12 | >>> __builtin__.dreload = deep_reload.reload |
759 | 13 | 13 | ||
760 | 14 | This code is almost entirely based on knee.py from the standard library. | 14 | This code is almost entirely based on knee.py from the standard library. |
763 | 15 | 15 | """ | |
762 | 16 | $Id: deep_reload.py 958 2005-12-27 23:17:51Z fperez $""" | ||
764 | 17 | 16 | ||
765 | 18 | #***************************************************************************** | 17 | #***************************************************************************** |
766 | 19 | # Copyright (C) 2001 Nathaniel Gray <n8gray@caltech.edu> | 18 | # Copyright (C) 2001 Nathaniel Gray <n8gray@caltech.edu> |
767 | @@ -22,12 +21,6 @@ | |||
768 | 22 | # the file COPYING, distributed as part of this software. | 21 | # the file COPYING, distributed as part of this software. |
769 | 23 | #***************************************************************************** | 22 | #***************************************************************************** |
770 | 24 | 23 | ||
771 | 25 | from IPython import Release # do it explicitly so pydoc can see it - pydoc bug | ||
772 | 26 | __author__ = '%s <%s>' % Release.authors['Nathan'] | ||
773 | 27 | __license__ = Release.license | ||
774 | 28 | __version__ = "0.5" | ||
775 | 29 | __date__ = "21 August 2001" | ||
776 | 30 | |||
777 | 31 | import __builtin__ | 24 | import __builtin__ |
778 | 32 | import imp | 25 | import imp |
779 | 33 | import sys | 26 | import sys |
780 | 34 | 27 | ||
781 | === modified file 'IPython/excolors.py' | |||
782 | --- IPython/excolors.py 2008-02-16 09:50:47 +0000 | |||
783 | +++ IPython/excolors.py 2009-03-13 17:56:47 +0000 | |||
784 | @@ -1,8 +1,7 @@ | |||
785 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
786 | 2 | """ | 2 | """ |
787 | 3 | Color schemes for exception handling code in IPython. | 3 | Color schemes for exception handling code in IPython. |
790 | 4 | 4 | """ | |
789 | 5 | $Id: Prompts.py 638 2005-07-18 03:01:41Z fperez $""" | ||
791 | 6 | 5 | ||
792 | 7 | #***************************************************************************** | 6 | #***************************************************************************** |
793 | 8 | # Copyright (C) 2005-2006 Fernando Perez <fperez@colorado.edu> | 7 | # Copyright (C) 2005-2006 Fernando Perez <fperez@colorado.edu> |
794 | @@ -11,99 +10,128 @@ | |||
795 | 11 | # the file COPYING, distributed as part of this software. | 10 | # the file COPYING, distributed as part of this software. |
796 | 12 | #***************************************************************************** | 11 | #***************************************************************************** |
797 | 13 | 12 | ||
798 | 14 | from IPython import Release | ||
799 | 15 | __author__ = '%s <%s>' % Release.authors['Fernando'] | ||
800 | 16 | __license__ = Release.license | ||
801 | 17 | __version__ = Release.version | ||
802 | 18 | |||
803 | 19 | #**************************************************************************** | 13 | #**************************************************************************** |
804 | 20 | # Required modules | 14 | # Required modules |
805 | 21 | from IPython.ColorANSI import ColorSchemeTable, TermColors, ColorScheme | 15 | from IPython.ColorANSI import ColorSchemeTable, TermColors, ColorScheme |
806 | 22 | 16 | ||
894 | 23 | ExceptionColors = ColorSchemeTable() | 17 | def exception_colors(): |
895 | 24 | 18 | """Return a color table with fields for exception reporting. | |
896 | 25 | # Populate it with color schemes | 19 | |
897 | 26 | C = TermColors # shorthand and local lookup | 20 | The table is an instance of ColorSchemeTable with schemes added for |
898 | 27 | ExceptionColors.add_scheme(ColorScheme( | 21 | 'Linux', 'LightBG' and 'NoColor' and fields for exception handling filled |
899 | 28 | 'NoColor', | 22 | in. |
900 | 29 | # The color to be used for the top line | 23 | |
901 | 30 | topline = C.NoColor, | 24 | Examples: |
902 | 31 | 25 | ||
903 | 32 | # The colors to be used in the traceback | 26 | >>> ec = exception_colors() |
904 | 33 | filename = C.NoColor, | 27 | >>> ec.active_scheme_name |
905 | 34 | lineno = C.NoColor, | 28 | '' |
906 | 35 | name = C.NoColor, | 29 | >>> print ec.active_colors |
907 | 36 | vName = C.NoColor, | 30 | None |
908 | 37 | val = C.NoColor, | 31 | |
909 | 38 | em = C.NoColor, | 32 | Now we activate a color scheme: |
910 | 39 | 33 | >>> ec.set_active_scheme('NoColor') | |
911 | 40 | # Emphasized colors for the last frame of the traceback | 34 | >>> ec.active_scheme_name |
912 | 41 | normalEm = C.NoColor, | 35 | 'NoColor' |
913 | 42 | filenameEm = C.NoColor, | 36 | >>> ec.active_colors.keys() |
914 | 43 | linenoEm = C.NoColor, | 37 | ['em', 'caret', '__allownew', 'name', 'val', 'vName', 'Normal', 'normalEm', |
915 | 44 | nameEm = C.NoColor, | 38 | 'filename', 'linenoEm', 'excName', 'lineno', 'valEm', 'filenameEm', |
916 | 45 | valEm = C.NoColor, | 39 | 'nameEm', 'line', 'topline'] |
917 | 46 | 40 | """ | |
918 | 47 | # Colors for printing the exception | 41 | |
919 | 48 | excName = C.NoColor, | 42 | ex_colors = ColorSchemeTable() |
920 | 49 | line = C.NoColor, | 43 | |
921 | 50 | caret = C.NoColor, | 44 | # Populate it with color schemes |
922 | 51 | Normal = C.NoColor | 45 | C = TermColors # shorthand and local lookup |
923 | 52 | )) | 46 | ex_colors.add_scheme(ColorScheme( |
924 | 53 | 47 | 'NoColor', | |
925 | 54 | # make some schemes as instances so we can copy them for modification easily | 48 | # The color to be used for the top line |
926 | 55 | ExceptionColors.add_scheme(ColorScheme( | 49 | topline = C.NoColor, |
927 | 56 | 'Linux', | 50 | |
928 | 57 | # The color to be used for the top line | 51 | # The colors to be used in the traceback |
929 | 58 | topline = C.LightRed, | 52 | filename = C.NoColor, |
930 | 59 | 53 | lineno = C.NoColor, | |
931 | 60 | # The colors to be used in the traceback | 54 | name = C.NoColor, |
932 | 61 | filename = C.Green, | 55 | vName = C.NoColor, |
933 | 62 | lineno = C.Green, | 56 | val = C.NoColor, |
934 | 63 | name = C.Purple, | 57 | em = C.NoColor, |
935 | 64 | vName = C.Cyan, | 58 | |
936 | 65 | val = C.Green, | 59 | # Emphasized colors for the last frame of the traceback |
937 | 66 | em = C.LightCyan, | 60 | normalEm = C.NoColor, |
938 | 67 | 61 | filenameEm = C.NoColor, | |
939 | 68 | # Emphasized colors for the last frame of the traceback | 62 | linenoEm = C.NoColor, |
940 | 69 | normalEm = C.LightCyan, | 63 | nameEm = C.NoColor, |
941 | 70 | filenameEm = C.LightGreen, | 64 | valEm = C.NoColor, |
942 | 71 | linenoEm = C.LightGreen, | 65 | |
943 | 72 | nameEm = C.LightPurple, | 66 | # Colors for printing the exception |
944 | 73 | valEm = C.LightBlue, | 67 | excName = C.NoColor, |
945 | 74 | 68 | line = C.NoColor, | |
946 | 75 | # Colors for printing the exception | 69 | caret = C.NoColor, |
947 | 76 | excName = C.LightRed, | 70 | Normal = C.NoColor |
948 | 77 | line = C.Yellow, | 71 | )) |
949 | 78 | caret = C.White, | 72 | |
950 | 79 | Normal = C.Normal | 73 | # make some schemes as instances so we can copy them for modification easily |
951 | 80 | )) | 74 | ex_colors.add_scheme(ColorScheme( |
952 | 81 | 75 | 'Linux', | |
953 | 82 | # For light backgrounds, swap dark/light colors | 76 | # The color to be used for the top line |
954 | 83 | ExceptionColors.add_scheme(ColorScheme( | 77 | topline = C.LightRed, |
955 | 84 | 'LightBG', | 78 | |
956 | 85 | # The color to be used for the top line | 79 | # The colors to be used in the traceback |
957 | 86 | topline = C.Red, | 80 | filename = C.Green, |
958 | 87 | 81 | lineno = C.Green, | |
959 | 88 | # The colors to be used in the traceback | 82 | name = C.Purple, |
960 | 89 | filename = C.LightGreen, | 83 | vName = C.Cyan, |
961 | 90 | lineno = C.LightGreen, | 84 | val = C.Green, |
962 | 91 | name = C.LightPurple, | 85 | em = C.LightCyan, |
963 | 92 | vName = C.Cyan, | 86 | |
964 | 93 | val = C.LightGreen, | 87 | # Emphasized colors for the last frame of the traceback |
965 | 94 | em = C.Cyan, | 88 | normalEm = C.LightCyan, |
966 | 95 | 89 | filenameEm = C.LightGreen, | |
967 | 96 | # Emphasized colors for the last frame of the traceback | 90 | linenoEm = C.LightGreen, |
968 | 97 | normalEm = C.Cyan, | 91 | nameEm = C.LightPurple, |
969 | 98 | filenameEm = C.Green, | 92 | valEm = C.LightBlue, |
970 | 99 | linenoEm = C.Green, | 93 | |
971 | 100 | nameEm = C.Purple, | 94 | # Colors for printing the exception |
972 | 101 | valEm = C.Blue, | 95 | excName = C.LightRed, |
973 | 102 | 96 | line = C.Yellow, | |
974 | 103 | # Colors for printing the exception | 97 | caret = C.White, |
975 | 104 | excName = C.Red, | 98 | Normal = C.Normal |
976 | 105 | #line = C.Brown, # brown often is displayed as yellow | 99 | )) |
977 | 106 | line = C.Red, | 100 | |
978 | 107 | caret = C.Normal, | 101 | # For light backgrounds, swap dark/light colors |
979 | 108 | Normal = C.Normal | 102 | ex_colors.add_scheme(ColorScheme( |
980 | 109 | )) | 103 | 'LightBG', |
981 | 104 | # The color to be used for the top line | ||
982 | 105 | topline = C.Red, | ||
983 | 106 | |||
984 | 107 | # The colors to be used in the traceback | ||
985 | 108 | filename = C.LightGreen, | ||
986 | 109 | lineno = C.LightGreen, | ||
987 | 110 | name = C.LightPurple, | ||
988 | 111 | vName = C.Cyan, | ||
989 | 112 | val = C.LightGreen, | ||
990 | 113 | em = C.Cyan, | ||
991 | 114 | |||
992 | 115 | # Emphasized colors for the last frame of the traceback | ||
993 | 116 | normalEm = C.Cyan, | ||
994 | 117 | filenameEm = C.Green, | ||
995 | 118 | linenoEm = C.Green, | ||
996 | 119 | nameEm = C.Purple, | ||
997 | 120 | valEm = C.Blue, | ||
998 | 121 | |||
999 | 122 | # Colors for printing the exception | ||
1000 | 123 | excName = C.Red, | ||
1001 | 124 | #line = C.Brown, # brown often is displayed as yellow | ||
1002 | 125 | line = C.Red, | ||
1003 | 126 | caret = C.Normal, | ||
1004 | 127 | Normal = C.Normal, | ||
1005 | 128 | )) | ||
1006 | 129 | |||
1007 | 130 | return ex_colors | ||
1008 | 131 | |||
1009 | 132 | |||
1010 | 133 | # For backwards compatibility, keep around a single global object. Note that | ||
1011 | 134 | # this should NOT be used, the factory function should be used instead, since | ||
1012 | 135 | # these objects are stateful and it's very easy to get strange bugs if any code | ||
1013 | 136 | # modifies the module-level object's state. | ||
1014 | 137 | ExceptionColors = exception_colors() | ||
1015 | 110 | 138 | ||
1016 | === modified file 'IPython/external/Itpl.py' | |||
1017 | --- IPython/external/Itpl.py 2008-06-06 19:58:56 +0000 | |||
1018 | +++ IPython/external/Itpl.py 2009-03-11 06:53:19 +0000 | |||
1019 | @@ -27,7 +27,7 @@ | |||
1020 | 27 | import Itpl | 27 | import Itpl |
1021 | 28 | sys.stdout = Itpl.filter() | 28 | sys.stdout = Itpl.filter() |
1022 | 29 | f = "fancy" | 29 | f = "fancy" |
1024 | 30 | print "Isn't this $f?" | 30 | print "Is this not $f?" |
1025 | 31 | print "Standard output has been replaced with a $sys.stdout object." | 31 | print "Standard output has been replaced with a $sys.stdout object." |
1026 | 32 | sys.stdout = Itpl.unfilter() | 32 | sys.stdout = Itpl.unfilter() |
1027 | 33 | print "Okay, back $to $normal." | 33 | print "Okay, back $to $normal." |
1028 | @@ -43,9 +43,7 @@ | |||
1029 | 43 | print str(s) | 43 | print str(s) |
1030 | 44 | foo = "bar" | 44 | foo = "bar" |
1031 | 45 | print str(s) | 45 | print str(s) |
1035 | 46 | 46 | """ | |
1033 | 47 | $Id: Itpl.py 2305 2007-05-04 05:34:42Z bgranger $ | ||
1034 | 48 | """ # ' -> close an open quote for stupid emacs | ||
1036 | 49 | 47 | ||
1037 | 50 | #***************************************************************************** | 48 | #***************************************************************************** |
1038 | 51 | # | 49 | # |
1039 | 52 | 50 | ||
1040 | === modified file 'IPython/genutils.py' | |||
1041 | --- IPython/genutils.py 2008-09-03 23:31:20 +0000 | |||
1042 | +++ IPython/genutils.py 2009-03-11 06:53:19 +0000 | |||
1043 | @@ -1,11 +1,9 @@ | |||
1044 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
1047 | 2 | """ | 2 | """General purpose utilities. |
1046 | 3 | General purpose utilities. | ||
1048 | 4 | 3 | ||
1049 | 5 | This is a grab-bag of stuff I find useful in most programs I write. Some of | 4 | This is a grab-bag of stuff I find useful in most programs I write. Some of |
1050 | 6 | these things are also convenient when working at the command line. | 5 | these things are also convenient when working at the command line. |
1053 | 7 | 6 | """ | |
1052 | 8 | $Id: genutils.py 2998 2008-01-31 10:06:04Z vivainio $""" | ||
1054 | 9 | 7 | ||
1055 | 10 | #***************************************************************************** | 8 | #***************************************************************************** |
1056 | 11 | # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu> | 9 | # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu> |
1057 | @@ -14,10 +12,6 @@ | |||
1058 | 14 | # the file COPYING, distributed as part of this software. | 12 | # the file COPYING, distributed as part of this software. |
1059 | 15 | #***************************************************************************** | 13 | #***************************************************************************** |
1060 | 16 | 14 | ||
1061 | 17 | from IPython import Release | ||
1062 | 18 | __author__ = '%s <%s>' % Release.authors['Fernando'] | ||
1063 | 19 | __license__ = Release.license | ||
1064 | 20 | |||
1065 | 21 | #**************************************************************************** | 15 | #**************************************************************************** |
1066 | 22 | # required modules from the Python standard library | 16 | # required modules from the Python standard library |
1067 | 23 | import __main__ | 17 | import __main__ |
1068 | @@ -1234,11 +1228,11 @@ | |||
1069 | 1234 | def make_quoted_expr(s): | 1228 | def make_quoted_expr(s): |
1070 | 1235 | """Return string s in appropriate quotes, using raw string if possible. | 1229 | """Return string s in appropriate quotes, using raw string if possible. |
1071 | 1236 | 1230 | ||
1077 | 1237 | Effectively this turns string: cd \ao\ao\ | 1231 | XXX - example removed because it caused encoding errors in documentation |
1078 | 1238 | to: r"cd \ao\ao\_"[:-1] | 1232 | generation. We need a new example that doesn't contain invalid chars. |
1079 | 1239 | 1233 | ||
1080 | 1240 | Note the use of raw string and padding at the end to allow trailing backslash. | 1234 | Note the use of raw string and padding at the end to allow trailing |
1081 | 1241 | 1235 | backslash. | |
1082 | 1242 | """ | 1236 | """ |
1083 | 1243 | 1237 | ||
1084 | 1244 | tail = '' | 1238 | tail = '' |
1085 | 1245 | 1239 | ||
1086 | === modified file 'IPython/history.py' | |||
1087 | --- IPython/history.py 2008-09-13 08:39:54 +0000 | |||
1088 | +++ IPython/history.py 2008-11-10 00:15:00 +0000 | |||
1089 | @@ -1,5 +1,4 @@ | |||
1090 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
1091 | 2 | |||
1092 | 3 | """ History related magics and functionality """ | 2 | """ History related magics and functionality """ |
1093 | 4 | 3 | ||
1094 | 5 | # Stdlib imports | 4 | # Stdlib imports |
1095 | @@ -7,7 +6,7 @@ | |||
1096 | 7 | import os | 6 | import os |
1097 | 8 | 7 | ||
1098 | 9 | # IPython imports | 8 | # IPython imports |
1100 | 10 | from IPython.genutils import Term, ask_yes_no | 9 | from IPython.genutils import Term, ask_yes_no, warn |
1101 | 11 | import IPython.ipapi | 10 | import IPython.ipapi |
1102 | 12 | 11 | ||
1103 | 13 | def magic_history(self, parameter_s = ''): | 12 | def magic_history(self, parameter_s = ''): |
1104 | @@ -47,8 +46,6 @@ | |||
1105 | 47 | -f FILENAME: instead of printing the output to the screen, redirect it to | 46 | -f FILENAME: instead of printing the output to the screen, redirect it to |
1106 | 48 | the given file. The file is always overwritten, though IPython asks for | 47 | the given file. The file is always overwritten, though IPython asks for |
1107 | 49 | confirmation first if it already exists. | 48 | confirmation first if it already exists. |
1108 | 50 | |||
1109 | 51 | |||
1110 | 52 | """ | 49 | """ |
1111 | 53 | 50 | ||
1112 | 54 | ip = self.api | 51 | ip = self.api |
1113 | @@ -62,31 +59,28 @@ | |||
1114 | 62 | try: | 59 | try: |
1115 | 63 | outfname = opts['f'] | 60 | outfname = opts['f'] |
1116 | 64 | except KeyError: | 61 | except KeyError: |
1118 | 65 | outfile = Term.cout | 62 | outfile = Term.cout # default |
1119 | 66 | # We don't want to close stdout at the end! | 63 | # We don't want to close stdout at the end! |
1120 | 67 | close_at_end = False | 64 | close_at_end = False |
1121 | 68 | else: | 65 | else: |
1122 | 69 | if os.path.exists(outfname): | 66 | if os.path.exists(outfname): |
1125 | 70 | ans = ask_yes_no("File %r exists. Overwrite?" % outfname) | 67 | if not ask_yes_no("File %r exists. Overwrite?" % outfname): |
1124 | 71 | if not ans: | ||
1126 | 72 | print 'Aborting.' | 68 | print 'Aborting.' |
1127 | 73 | return | 69 | return |
1134 | 74 | else: | 70 | |
1135 | 75 | outfile = open(outfname,'w') | 71 | outfile = open(outfname,'w') |
1136 | 76 | close_at_end = True | 72 | close_at_end = True |
1137 | 77 | 73 | ||
1138 | 78 | 74 | if 't' in opts: | |
1133 | 79 | if opts.has_key('t'): | ||
1139 | 80 | input_hist = shell.input_hist | 75 | input_hist = shell.input_hist |
1141 | 81 | elif opts.has_key('r'): | 76 | elif 'r' in opts: |
1142 | 82 | input_hist = shell.input_hist_raw | 77 | input_hist = shell.input_hist_raw |
1143 | 83 | else: | 78 | else: |
1144 | 84 | input_hist = shell.input_hist | 79 | input_hist = shell.input_hist |
1147 | 85 | 80 | ||
1146 | 86 | |||
1148 | 87 | default_length = 40 | 81 | default_length = 40 |
1149 | 88 | pattern = None | 82 | pattern = None |
1151 | 89 | if opts.has_key('g'): | 83 | if 'g' in opts: |
1152 | 90 | init = 1 | 84 | init = 1 |
1153 | 91 | final = len(input_hist) | 85 | final = len(input_hist) |
1154 | 92 | parts = parameter_s.split(None,1) | 86 | parts = parameter_s.split(None,1) |
1155 | @@ -138,13 +132,11 @@ | |||
1156 | 138 | outfile.close() | 132 | outfile.close() |
1157 | 139 | 133 | ||
1158 | 140 | 134 | ||
1159 | 141 | |||
1160 | 142 | def magic_hist(self, parameter_s=''): | 135 | def magic_hist(self, parameter_s=''): |
1161 | 143 | """Alternate name for %history.""" | 136 | """Alternate name for %history.""" |
1162 | 144 | return self.magic_history(parameter_s) | 137 | return self.magic_history(parameter_s) |
1163 | 145 | 138 | ||
1164 | 146 | 139 | ||
1165 | 147 | |||
1166 | 148 | def rep_f(self, arg): | 140 | def rep_f(self, arg): |
1167 | 149 | r""" Repeat a command, or get command to input line for editing | 141 | r""" Repeat a command, or get command to input line for editing |
1168 | 150 | 142 | ||
1169 | @@ -173,11 +165,9 @@ | |||
1170 | 173 | %rep foo | 165 | %rep foo |
1171 | 174 | 166 | ||
1172 | 175 | Place the most recent line that has the substring "foo" to next input. | 167 | Place the most recent line that has the substring "foo" to next input. |
1175 | 176 | (e.g. 'svn ci -m foobar'). | 168 | (e.g. 'svn ci -m foobar'). |
1174 | 177 | |||
1176 | 178 | """ | 169 | """ |
1177 | 179 | 170 | ||
1178 | 180 | |||
1179 | 181 | opts,args = self.parse_options(arg,'',mode='list') | 171 | opts,args = self.parse_options(arg,'',mode='list') |
1180 | 182 | ip = self.api | 172 | ip = self.api |
1181 | 183 | if not args: | 173 | if not args: |
1182 | @@ -206,7 +196,6 @@ | |||
1183 | 206 | ip.set_next_input(str(h).rstrip()) | 196 | ip.set_next_input(str(h).rstrip()) |
1184 | 207 | return | 197 | return |
1185 | 208 | 198 | ||
1186 | 209 | |||
1187 | 210 | try: | 199 | try: |
1188 | 211 | lines = self.extract_input_slices(args, True) | 200 | lines = self.extract_input_slices(args, True) |
1189 | 212 | print "lines",lines | 201 | print "lines",lines |
1190 | @@ -215,7 +204,6 @@ | |||
1191 | 215 | print "Not found in recent history:", args | 204 | print "Not found in recent history:", args |
1192 | 216 | 205 | ||
1193 | 217 | 206 | ||
1194 | 218 | |||
1195 | 219 | _sentinel = object() | 207 | _sentinel = object() |
1196 | 220 | 208 | ||
1197 | 221 | class ShadowHist: | 209 | class ShadowHist: |
1198 | @@ -259,23 +247,12 @@ | |||
1199 | 259 | if k == idx: | 247 | if k == idx: |
1200 | 260 | return v | 248 | return v |
1201 | 261 | 249 | ||
1202 | 262 | def test_shist(): | ||
1203 | 263 | from IPython.Extensions import pickleshare | ||
1204 | 264 | db = pickleshare.PickleShareDB('~/shist') | ||
1205 | 265 | s = ShadowHist(db) | ||
1206 | 266 | s.add('hello') | ||
1207 | 267 | s.add('world') | ||
1208 | 268 | s.add('hello') | ||
1209 | 269 | s.add('hello') | ||
1210 | 270 | s.add('karhu') | ||
1211 | 271 | print "all",s.all() | ||
1212 | 272 | print s.get(2) | ||
1213 | 273 | 250 | ||
1214 | 274 | def init_ipython(ip): | 251 | def init_ipython(ip): |
1215 | 252 | import ipy_completers | ||
1216 | 253 | |||
1217 | 275 | ip.expose_magic("rep",rep_f) | 254 | ip.expose_magic("rep",rep_f) |
1218 | 276 | ip.expose_magic("hist",magic_hist) | 255 | ip.expose_magic("hist",magic_hist) |
1219 | 277 | ip.expose_magic("history",magic_history) | 256 | ip.expose_magic("history",magic_history) |
1220 | 278 | 257 | ||
1221 | 279 | import ipy_completers | ||
1222 | 280 | ipy_completers.quick_completer('%hist' ,'-g -t -r -n') | 258 | ipy_completers.quick_completer('%hist' ,'-g -t -r -n') |
1223 | 281 | #test_shist() | ||
1224 | 282 | 259 | ||
1225 | === modified file 'IPython/hooks.py' | |||
1226 | --- IPython/hooks.py 2008-06-07 06:50:18 +0000 | |||
1227 | +++ IPython/hooks.py 2009-03-11 06:53:19 +0000 | |||
1228 | @@ -31,8 +31,7 @@ | |||
1229 | 31 | 31 | ||
1230 | 32 | You can then enable the functionality by doing 'import myiphooks' | 32 | You can then enable the functionality by doing 'import myiphooks' |
1231 | 33 | somewhere in your configuration files or ipython command line. | 33 | somewhere in your configuration files or ipython command line. |
1234 | 34 | 34 | """ | |
1233 | 35 | $Id: hooks.py 2998 2008-01-31 10:06:04Z vivainio $""" | ||
1235 | 36 | 35 | ||
1236 | 37 | #***************************************************************************** | 36 | #***************************************************************************** |
1237 | 38 | # Copyright (C) 2005 Fernando Perez. <fperez@colorado.edu> | 37 | # Copyright (C) 2005 Fernando Perez. <fperez@colorado.edu> |
1238 | @@ -41,11 +40,7 @@ | |||
1239 | 41 | # the file COPYING, distributed as part of this software. | 40 | # the file COPYING, distributed as part of this software. |
1240 | 42 | #***************************************************************************** | 41 | #***************************************************************************** |
1241 | 43 | 42 | ||
1242 | 44 | from IPython import Release | ||
1243 | 45 | from IPython import ipapi | 43 | from IPython import ipapi |
1244 | 46 | __author__ = '%s <%s>' % Release.authors['Fernando'] | ||
1245 | 47 | __license__ = Release.license | ||
1246 | 48 | __version__ = Release.version | ||
1247 | 49 | 44 | ||
1248 | 50 | import os,bisect | 45 | import os,bisect |
1249 | 51 | from genutils import Term,shell | 46 | from genutils import Term,shell |
1250 | 52 | 47 | ||
1251 | === modified file 'IPython/ipapi.py' | |||
1252 | --- IPython/ipapi.py 2008-08-13 06:05:45 +0000 | |||
1253 | +++ IPython/ipapi.py 2009-03-11 01:24:53 +0000 | |||
1254 | @@ -24,7 +24,6 @@ | |||
1255 | 24 | personal configuration (as opposed to boilerplate ipythonrc-PROFILENAME | 24 | personal configuration (as opposed to boilerplate ipythonrc-PROFILENAME |
1256 | 25 | stuff) in there. | 25 | stuff) in there. |
1257 | 26 | 26 | ||
1258 | 27 | ----------------------------------------------- | ||
1259 | 28 | import IPython.ipapi | 27 | import IPython.ipapi |
1260 | 29 | ip = IPython.ipapi.get() | 28 | ip = IPython.ipapi.get() |
1261 | 30 | 29 | ||
1262 | 31 | 30 | ||
1263 | === modified file 'IPython/iplib.py' | |||
1264 | --- IPython/iplib.py 2008-08-14 12:50:55 +0000 | |||
1265 | +++ IPython/iplib.py 2009-03-13 17:56:19 +0000 | |||
1266 | @@ -2,10 +2,9 @@ | |||
1267 | 2 | """ | 2 | """ |
1268 | 3 | IPython -- An enhanced Interactive Python | 3 | IPython -- An enhanced Interactive Python |
1269 | 4 | 4 | ||
1271 | 5 | Requires Python 2.3 or newer. | 5 | Requires Python 2.4 or newer. |
1272 | 6 | 6 | ||
1273 | 7 | This file contains all the classes and helper functions specific to IPython. | 7 | This file contains all the classes and helper functions specific to IPython. |
1274 | 8 | |||
1275 | 9 | """ | 8 | """ |
1276 | 10 | 9 | ||
1277 | 11 | #***************************************************************************** | 10 | #***************************************************************************** |
1278 | @@ -27,12 +26,6 @@ | |||
1279 | 27 | #**************************************************************************** | 26 | #**************************************************************************** |
1280 | 28 | # Modules and globals | 27 | # Modules and globals |
1281 | 29 | 28 | ||
1282 | 30 | from IPython import Release | ||
1283 | 31 | __author__ = '%s <%s>\n%s <%s>' % \ | ||
1284 | 32 | ( Release.authors['Janko'] + Release.authors['Fernando'] ) | ||
1285 | 33 | __license__ = Release.license | ||
1286 | 34 | __version__ = Release.version | ||
1287 | 35 | |||
1288 | 36 | # Python standard modules | 29 | # Python standard modules |
1289 | 37 | import __main__ | 30 | import __main__ |
1290 | 38 | import __builtin__ | 31 | import __builtin__ |
1291 | @@ -342,15 +335,19 @@ | |||
1292 | 342 | # code ran is deleted. Now that this object is a true module (needed | 335 | # code ran is deleted. Now that this object is a true module (needed |
1293 | 343 | # so docetst and other tools work correctly), the Python module | 336 | # so docetst and other tools work correctly), the Python module |
1294 | 344 | # teardown mechanism runs over it, and sets to None every variable | 337 | # teardown mechanism runs over it, and sets to None every variable |
1304 | 345 | # present in that module. This means that later calls to functions | 338 | # present in that module. Top-level references to objects from the |
1305 | 346 | # defined in the script (which have become interactively visible after | 339 | # script survive, because the user_ns is updated with them. However, |
1306 | 347 | # script exit) fail, because they hold references to objects that have | 340 | # calling functions defined in the script that use other things from |
1307 | 348 | # become overwritten into None. The only solution I see right now is | 341 | # the script will fail, because the function's closure had references |
1308 | 349 | # to protect every FakeModule used by %run by holding an internal | 342 | # to the original objects, which are now all None. So we must protect |
1309 | 350 | # reference to it. This private list will be used for that. The | 343 | # these modules from deletion by keeping a cache. To avoid keeping |
1310 | 351 | # %reset command will flush it as well. | 344 | # stale modules around (we only need the one from the last run), we use |
1311 | 352 | self._user_main_modules = [] | 345 | # a dict keyed with the full path to the script, so only the last |
1312 | 353 | 346 | # version of the module is held in the cache. The %reset command will | |
1313 | 347 | # flush this cache. See the cache_main_mod() and clear_main_mod_cache() | ||
1314 | 348 | # methods for details on use. | ||
1315 | 349 | self._user_main_modules = {} | ||
1316 | 350 | |||
1317 | 354 | # List of input with multi-line handling. | 351 | # List of input with multi-line handling. |
1318 | 355 | # Fill its zero entry, user counter starts at 1 | 352 | # Fill its zero entry, user counter starts at 1 |
1319 | 356 | self.input_hist = InputList(['\n']) | 353 | self.input_hist = InputList(['\n']) |
1320 | @@ -601,10 +598,6 @@ | |||
1321 | 601 | 598 | ||
1322 | 602 | #TODO: remove this, redundant | 599 | #TODO: remove this, redundant |
1323 | 603 | self.add_builtins() | 600 | self.add_builtins() |
1324 | 604 | |||
1325 | 605 | |||
1326 | 606 | |||
1327 | 607 | |||
1328 | 608 | # end __init__ | 601 | # end __init__ |
1329 | 609 | 602 | ||
1330 | 610 | def var_expand(self,cmd,depth=0): | 603 | def var_expand(self,cmd,depth=0): |
1331 | @@ -633,16 +626,15 @@ | |||
1332 | 633 | """ | 626 | """ |
1333 | 634 | rc = self.rc | 627 | rc = self.rc |
1334 | 635 | try: | 628 | try: |
1336 | 636 | self.db = pickleshare.PickleShareDB(rc.ipythondir + "/db") | 629 | self.db = pickleshare.PickleShareDB(rc.ipythondir + "/db") |
1337 | 637 | except exceptions.UnicodeDecodeError: | 630 | except exceptions.UnicodeDecodeError: |
1338 | 638 | print "Your ipythondir can't be decoded to unicode!" | 631 | print "Your ipythondir can't be decoded to unicode!" |
1339 | 639 | print "Please set HOME environment variable to something that" | 632 | print "Please set HOME environment variable to something that" |
1340 | 640 | print r"only has ASCII characters, e.g. c:\home" | 633 | print r"only has ASCII characters, e.g. c:\home" |
1341 | 641 | print "Now it is",rc.ipythondir | 634 | print "Now it is",rc.ipythondir |
1342 | 642 | sys.exit() | 635 | sys.exit() |
1346 | 643 | self.shadowhist = IPython.history.ShadowHist(self.db) | 636 | self.shadowhist = IPython.history.ShadowHist(self.db) |
1347 | 644 | 637 | ||
1345 | 645 | |||
1348 | 646 | def post_config_initialization(self): | 638 | def post_config_initialization(self): |
1349 | 647 | """Post configuration init method | 639 | """Post configuration init method |
1350 | 648 | 640 | ||
1351 | @@ -909,7 +901,6 @@ | |||
1352 | 909 | call_pdb = property(_get_call_pdb,_set_call_pdb,None, | 901 | call_pdb = property(_get_call_pdb,_set_call_pdb,None, |
1353 | 910 | 'Control auto-activation of pdb at exceptions') | 902 | 'Control auto-activation of pdb at exceptions') |
1354 | 911 | 903 | ||
1355 | 912 | |||
1356 | 913 | # These special functions get installed in the builtin namespace, to | 904 | # These special functions get installed in the builtin namespace, to |
1357 | 914 | # provide programmatic (pure python) access to magics, aliases and system | 905 | # provide programmatic (pure python) access to magics, aliases and system |
1358 | 915 | # calls. This is important for logging, user scripting, and more. | 906 | # calls. This is important for logging, user scripting, and more. |
1359 | @@ -1139,7 +1130,8 @@ | |||
1360 | 1139 | inif = 'ipythonrc.ini' | 1130 | inif = 'ipythonrc.ini' |
1361 | 1140 | else: | 1131 | else: |
1362 | 1141 | inif = 'ipythonrc' | 1132 | inif = 'ipythonrc' |
1364 | 1142 | minimal_setup = {'ipy_user_conf.py' : 'import ipy_defaults', inif : '# intentionally left blank' } | 1133 | minimal_setup = {'ipy_user_conf.py' : 'import ipy_defaults', |
1365 | 1134 | inif : '# intentionally left blank' } | ||
1366 | 1143 | os.makedirs(ipythondir, mode = 0777) | 1135 | os.makedirs(ipythondir, mode = 0777) |
1367 | 1144 | for f, cont in minimal_setup.items(): | 1136 | for f, cont in minimal_setup.items(): |
1368 | 1145 | open(ipythondir + '/' + f,'w').write(cont) | 1137 | open(ipythondir + '/' + f,'w').write(cont) |
1369 | @@ -1298,7 +1290,6 @@ | |||
1370 | 1298 | finally: | 1290 | finally: |
1371 | 1299 | readline.read_history_file(self.histfile) | 1291 | readline.read_history_file(self.histfile) |
1372 | 1300 | return wrapper | 1292 | return wrapper |
1373 | 1301 | |||
1374 | 1302 | 1293 | ||
1375 | 1303 | def pre_readline(self): | 1294 | def pre_readline(self): |
1376 | 1304 | """readline hook to be used at the start of each line. | 1295 | """readline hook to be used at the start of each line. |
1377 | @@ -1396,7 +1387,59 @@ | |||
1378 | 1396 | if self.rc.quiet: | 1387 | if self.rc.quiet: |
1379 | 1397 | return True | 1388 | return True |
1380 | 1398 | return ask_yes_no(prompt,default) | 1389 | return ask_yes_no(prompt,default) |
1382 | 1399 | 1390 | ||
1383 | 1391 | def cache_main_mod(self,mod): | ||
1384 | 1392 | """Cache a main module. | ||
1385 | 1393 | |||
1386 | 1394 | When scripts are executed via %run, we must keep a reference to their | ||
1387 | 1395 | __main__ module (a FakeModule instance) around so that Python doesn't | ||
1388 | 1396 | clear it, rendering objects defined therein useless. | ||
1389 | 1397 | |||
1390 | 1398 | This method keeps said reference in a private dict, keyed by the | ||
1391 | 1399 | absolute path of the module object (which corresponds to the script | ||
1392 | 1400 | path). This way, for multiple executions of the same script we only | ||
1393 | 1401 | keep one copy of __main__ (the last one), thus preventing memory leaks | ||
1394 | 1402 | from old references while allowing the objects from the last execution | ||
1395 | 1403 | to be accessible. | ||
1396 | 1404 | |||
1397 | 1405 | Parameters | ||
1398 | 1406 | ---------- | ||
1399 | 1407 | mod : a module object | ||
1400 | 1408 | |||
1401 | 1409 | Examples | ||
1402 | 1410 | -------- | ||
1403 | 1411 | |||
1404 | 1412 | In [10]: import IPython | ||
1405 | 1413 | |||
1406 | 1414 | In [11]: _ip.IP.cache_main_mod(IPython) | ||
1407 | 1415 | |||
1408 | 1416 | In [12]: IPython.__file__ in _ip.IP._user_main_modules | ||
1409 | 1417 | Out[12]: True | ||
1410 | 1418 | """ | ||
1411 | 1419 | self._user_main_modules[os.path.abspath(mod.__file__) ] = mod | ||
1412 | 1420 | |||
1413 | 1421 | def clear_main_mod_cache(self): | ||
1414 | 1422 | """Clear the cache of main modules. | ||
1415 | 1423 | |||
1416 | 1424 | Mainly for use by utilities like %reset. | ||
1417 | 1425 | |||
1418 | 1426 | Examples | ||
1419 | 1427 | -------- | ||
1420 | 1428 | |||
1421 | 1429 | In [15]: import IPython | ||
1422 | 1430 | |||
1423 | 1431 | In [16]: _ip.IP.cache_main_mod(IPython) | ||
1424 | 1432 | |||
1425 | 1433 | In [17]: len(_ip.IP._user_main_modules) > 0 | ||
1426 | 1434 | Out[17]: True | ||
1427 | 1435 | |||
1428 | 1436 | In [18]: _ip.IP.clear_main_mod_cache() | ||
1429 | 1437 | |||
1430 | 1438 | In [19]: len(_ip.IP._user_main_modules) == 0 | ||
1431 | 1439 | Out[19]: True | ||
1432 | 1440 | """ | ||
1433 | 1441 | self._user_main_modules.clear() | ||
1434 | 1442 | |||
1435 | 1400 | def _should_recompile(self,e): | 1443 | def _should_recompile(self,e): |
1436 | 1401 | """Utility routine for edit_syntax_error""" | 1444 | """Utility routine for edit_syntax_error""" |
1437 | 1402 | 1445 | ||
1438 | @@ -1552,8 +1595,6 @@ | |||
1439 | 1552 | self.set_completer() | 1595 | self.set_completer() |
1440 | 1553 | except KeyboardInterrupt: | 1596 | except KeyboardInterrupt: |
1441 | 1554 | self.write("\nKeyboardInterrupt\n") | 1597 | self.write("\nKeyboardInterrupt\n") |
1442 | 1555 | |||
1443 | 1556 | |||
1444 | 1557 | 1598 | ||
1445 | 1558 | def mainloop(self,banner=None): | 1599 | def mainloop(self,banner=None): |
1446 | 1559 | """Creates the local namespace and starts the mainloop. | 1600 | """Creates the local namespace and starts the mainloop. |
1447 | @@ -1576,7 +1617,9 @@ | |||
1448 | 1576 | try: | 1617 | try: |
1449 | 1577 | self.interact(banner) | 1618 | self.interact(banner) |
1450 | 1578 | #self.interact_with_readline() | 1619 | #self.interact_with_readline() |
1452 | 1579 | # XXX for testing of a readline-decoupled repl loop, call interact_with_readline above | 1620 | |
1453 | 1621 | # XXX for testing of a readline-decoupled repl loop, call | ||
1454 | 1622 | # interact_with_readline above | ||
1455 | 1580 | 1623 | ||
1456 | 1581 | break | 1624 | break |
1457 | 1582 | except KeyboardInterrupt: | 1625 | except KeyboardInterrupt: |
1458 | 1583 | 1626 | ||
1459 | === modified file 'IPython/ipmaker.py' | |||
1460 | --- IPython/ipmaker.py 2008-06-04 08:15:46 +0000 | |||
1461 | +++ IPython/ipmaker.py 2009-03-11 06:53:19 +0000 | |||
1462 | @@ -5,8 +5,7 @@ | |||
1463 | 5 | Requires Python 2.1 or better. | 5 | Requires Python 2.1 or better. |
1464 | 6 | 6 | ||
1465 | 7 | This file contains the main make_IPython() starter function. | 7 | This file contains the main make_IPython() starter function. |
1468 | 8 | 8 | """ | |
1467 | 9 | $Id: ipmaker.py 2930 2008-01-11 07:03:11Z vivainio $""" | ||
1469 | 10 | 9 | ||
1470 | 11 | #***************************************************************************** | 10 | #***************************************************************************** |
1471 | 12 | # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu> | 11 | # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu> |
1472 | 13 | 12 | ||
1473 | === modified file 'IPython/ipstruct.py' | |||
1474 | --- IPython/ipstruct.py 2008-08-02 09:07:37 +0000 | |||
1475 | +++ IPython/ipstruct.py 2009-03-11 06:53:19 +0000 | |||
1476 | @@ -1,7 +1,6 @@ | |||
1477 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
1478 | 2 | """Mimic C structs with lots of extra functionality. | 2 | """Mimic C structs with lots of extra functionality. |
1481 | 3 | 3 | """ | |
1480 | 4 | $Id: ipstruct.py 1950 2006-11-28 19:15:35Z vivainio $""" | ||
1482 | 5 | 4 | ||
1483 | 6 | #***************************************************************************** | 5 | #***************************************************************************** |
1484 | 7 | # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu> | 6 | # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu> |
1485 | @@ -10,10 +9,6 @@ | |||
1486 | 10 | # the file COPYING, distributed as part of this software. | 9 | # the file COPYING, distributed as part of this software. |
1487 | 11 | #***************************************************************************** | 10 | #***************************************************************************** |
1488 | 12 | 11 | ||
1489 | 13 | from IPython import Release | ||
1490 | 14 | __author__ = '%s <%s>' % Release.authors['Fernando'] | ||
1491 | 15 | __license__ = Release.license | ||
1492 | 16 | |||
1493 | 17 | __all__ = ['Struct'] | 12 | __all__ = ['Struct'] |
1494 | 18 | 13 | ||
1495 | 19 | import types | 14 | import types |
1496 | @@ -163,8 +158,22 @@ | |||
1497 | 163 | return self.__dict__[key] | 158 | return self.__dict__[key] |
1498 | 164 | 159 | ||
1499 | 165 | def __contains__(self,key): | 160 | def __contains__(self,key): |
1502 | 166 | """Allows use of the 'in' operator.""" | 161 | """Allows use of the 'in' operator. |
1503 | 167 | return self.__dict__.has_key(key) | 162 | |
1504 | 163 | Examples: | ||
1505 | 164 | >>> s = Struct(x=1) | ||
1506 | 165 | >>> 'x' in s | ||
1507 | 166 | True | ||
1508 | 167 | >>> 'y' in s | ||
1509 | 168 | False | ||
1510 | 169 | >>> s[4] = None | ||
1511 | 170 | >>> 4 in s | ||
1512 | 171 | True | ||
1513 | 172 | >>> s.z = None | ||
1514 | 173 | >>> 'z' in s | ||
1515 | 174 | True | ||
1516 | 175 | """ | ||
1517 | 176 | return key in self.__dict__ | ||
1518 | 168 | 177 | ||
1519 | 169 | def __iadd__(self,other): | 178 | def __iadd__(self,other): |
1520 | 170 | """S += S2 is a shorthand for S.merge(S2).""" | 179 | """S += S2 is a shorthand for S.merge(S2).""" |
1521 | @@ -246,12 +255,13 @@ | |||
1522 | 246 | Optionally, one or more key=value pairs can be given at the end for | 255 | Optionally, one or more key=value pairs can be given at the end for |
1523 | 247 | direct update.""" | 256 | direct update.""" |
1524 | 248 | 257 | ||
1529 | 249 | # The funny name __loc_data__ is to prevent a common variable name which | 258 | # The funny name __loc_data__ is to prevent a common variable name |
1530 | 250 | # could be a fieled of a Struct to collide with this parameter. The problem | 259 | # which could be a fieled of a Struct to collide with this |
1531 | 251 | # would arise if the function is called with a keyword with this same name | 260 | # parameter. The problem would arise if the function is called with a |
1532 | 252 | # that a user means to add as a Struct field. | 261 | # keyword with this same name that a user means to add as a Struct |
1533 | 262 | # field. | ||
1534 | 253 | newdict = Struct.__make_dict(self,__loc_data__,**kw) | 263 | newdict = Struct.__make_dict(self,__loc_data__,**kw) |
1536 | 254 | for k,v in newdict.items(): | 264 | for k,v in newdict.iteritems(): |
1537 | 255 | self[k] = v | 265 | self[k] = v |
1538 | 256 | 266 | ||
1539 | 257 | def merge(self,__loc_data__=None,__conflict_solve=None,**kw): | 267 | def merge(self,__loc_data__=None,__conflict_solve=None,**kw): |
1540 | 258 | 268 | ||
1541 | === modified file 'IPython/kernel/core/ultraTB.py' | |||
1542 | --- IPython/kernel/core/ultraTB.py 2008-06-06 19:41:55 +0000 | |||
1543 | +++ IPython/kernel/core/ultraTB.py 2009-03-11 06:53:19 +0000 | |||
1544 | @@ -1,5 +1,4 @@ | |||
1547 | 1 | # encoding: utf-8 | 1 | # -*- coding: utf-8 -*- |
1546 | 2 | |||
1548 | 3 | """ | 2 | """ |
1549 | 4 | ultraTB.py -- Spice up your tracebacks! | 3 | ultraTB.py -- Spice up your tracebacks! |
1550 | 5 | 4 | ||
1551 | @@ -60,26 +59,15 @@ | |||
1552 | 60 | You can implement other color schemes easily, the syntax is fairly | 59 | You can implement other color schemes easily, the syntax is fairly |
1553 | 61 | self-explanatory. Please send back new schemes you develop to the author for | 60 | self-explanatory. Please send back new schemes you develop to the author for |
1554 | 62 | possible inclusion in future releases. | 61 | possible inclusion in future releases. |
1562 | 63 | 62 | """ | |
1563 | 64 | $Id: ultraTB.py 2480 2007-07-06 19:33:43Z fperez $""" | 63 | |
1564 | 65 | 64 | #***************************************************************************** | |
1565 | 66 | __docformat__ = "restructuredtext en" | 65 | # Copyright (C) 2001 Nathaniel Gray <n8gray@caltech.edu> |
1566 | 67 | 66 | # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu> | |
1560 | 68 | #------------------------------------------------------------------------------- | ||
1561 | 69 | # Copyright (C) 2008 The IPython Development Team | ||
1567 | 70 | # | 67 | # |
1568 | 71 | # Distributed under the terms of the BSD License. The full license is in | 68 | # Distributed under the terms of the BSD License. The full license is in |
1569 | 72 | # the file COPYING, distributed as part of this software. | 69 | # the file COPYING, distributed as part of this software. |
1580 | 73 | #------------------------------------------------------------------------------- | 70 | #***************************************************************************** |
1571 | 74 | |||
1572 | 75 | #------------------------------------------------------------------------------- | ||
1573 | 76 | # Imports | ||
1574 | 77 | #------------------------------------------------------------------------------- | ||
1575 | 78 | |||
1576 | 79 | from IPython import Release | ||
1577 | 80 | __author__ = '%s <%s>\n%s <%s>' % (Release.authors['Nathan']+ | ||
1578 | 81 | Release.authors['Fernando']) | ||
1579 | 82 | __license__ = Release.license | ||
1581 | 83 | 71 | ||
1582 | 84 | # Required modules | 72 | # Required modules |
1583 | 85 | import inspect | 73 | import inspect |
1584 | @@ -104,7 +92,7 @@ | |||
1585 | 104 | # Modified pdb which doesn't damage IPython's readline handling | 92 | # Modified pdb which doesn't damage IPython's readline handling |
1586 | 105 | from IPython import Debugger, PyColorize | 93 | from IPython import Debugger, PyColorize |
1587 | 106 | from IPython.ipstruct import Struct | 94 | from IPython.ipstruct import Struct |
1589 | 107 | from IPython.excolors import ExceptionColors | 95 | from IPython.excolors import exception_colors |
1590 | 108 | from IPython.genutils import Term,uniq_stable,error,info | 96 | from IPython.genutils import Term,uniq_stable,error,info |
1591 | 109 | 97 | ||
1592 | 110 | # Globals | 98 | # Globals |
1593 | @@ -141,11 +129,18 @@ | |||
1594 | 141 | FIXED version with which we monkeypatch the stdlib to work around a bug.""" | 129 | FIXED version with which we monkeypatch the stdlib to work around a bug.""" |
1595 | 142 | 130 | ||
1596 | 143 | file = getsourcefile(object) or getfile(object) | 131 | file = getsourcefile(object) or getfile(object) |
1600 | 144 | module = getmodule(object, file) | 132 | # If the object is a frame, then trying to get the globals dict from its |
1601 | 145 | if module: | 133 | # module won't work. Instead, the frame object itself has the globals |
1602 | 146 | lines = linecache.getlines(file, module.__dict__) | 134 | # dictionary. |
1603 | 135 | globals_dict = None | ||
1604 | 136 | if inspect.isframe(object): | ||
1605 | 137 | # XXX: can this ever be false? | ||
1606 | 138 | globals_dict = object.f_globals | ||
1607 | 147 | else: | 139 | else: |
1609 | 148 | lines = linecache.getlines(file) | 140 | module = getmodule(object, file) |
1610 | 141 | if module: | ||
1611 | 142 | globals_dict = module.__dict__ | ||
1612 | 143 | lines = linecache.getlines(file, globals_dict) | ||
1613 | 149 | if not lines: | 144 | if not lines: |
1614 | 150 | raise IOError('could not get source code') | 145 | raise IOError('could not get source code') |
1615 | 151 | 146 | ||
1616 | @@ -202,11 +197,31 @@ | |||
1617 | 202 | if sys.version_info[:2] >= (2,5): | 197 | if sys.version_info[:2] >= (2,5): |
1618 | 203 | inspect.findsource = findsource | 198 | inspect.findsource = findsource |
1619 | 204 | 199 | ||
1620 | 200 | def fix_frame_records_filenames(records): | ||
1621 | 201 | """Try to fix the filenames in each record from inspect.getinnerframes(). | ||
1622 | 202 | |||
1623 | 203 | Particularly, modules loaded from within zip files have useless filenames | ||
1624 | 204 | attached to their code object, and inspect.getinnerframes() just uses it. | ||
1625 | 205 | """ | ||
1626 | 206 | fixed_records = [] | ||
1627 | 207 | for frame, filename, line_no, func_name, lines, index in records: | ||
1628 | 208 | # Look inside the frame's globals dictionary for __file__, which should | ||
1629 | 209 | # be better. | ||
1630 | 210 | better_fn = frame.f_globals.get('__file__', None) | ||
1631 | 211 | if isinstance(better_fn, str): | ||
1632 | 212 | # Check the type just in case someone did something weird with | ||
1633 | 213 | # __file__. It might also be None if the error occurred during | ||
1634 | 214 | # import. | ||
1635 | 215 | filename = better_fn | ||
1636 | 216 | fixed_records.append((frame, filename, line_no, func_name, lines, index)) | ||
1637 | 217 | return fixed_records | ||
1638 | 218 | |||
1639 | 219 | |||
1640 | 205 | def _fixed_getinnerframes(etb, context=1,tb_offset=0): | 220 | def _fixed_getinnerframes(etb, context=1,tb_offset=0): |
1641 | 206 | import linecache | 221 | import linecache |
1642 | 207 | LNUM_POS, LINES_POS, INDEX_POS = 2, 4, 5 | 222 | LNUM_POS, LINES_POS, INDEX_POS = 2, 4, 5 |
1643 | 208 | 223 | ||
1645 | 209 | records = inspect.getinnerframes(etb, context) | 224 | records = fix_frame_records_filenames(inspect.getinnerframes(etb, context)) |
1646 | 210 | 225 | ||
1647 | 211 | # If the error is at the console, don't build any context, since it would | 226 | # If the error is at the console, don't build any context, since it would |
1648 | 212 | # otherwise produce 5 blank lines printed out (there is no file at the | 227 | # otherwise produce 5 blank lines printed out (there is no file at the |
1649 | @@ -299,7 +314,7 @@ | |||
1650 | 299 | self.call_pdb = call_pdb | 314 | self.call_pdb = call_pdb |
1651 | 300 | 315 | ||
1652 | 301 | # Create color table | 316 | # Create color table |
1654 | 302 | self.color_scheme_table = ExceptionColors | 317 | self.color_scheme_table = exception_colors() |
1655 | 303 | 318 | ||
1656 | 304 | self.set_colors(color_scheme) | 319 | self.set_colors(color_scheme) |
1657 | 305 | self.old_scheme = color_scheme # save initial value for toggles | 320 | self.old_scheme = color_scheme # save initial value for toggles |
1658 | @@ -356,8 +371,8 @@ | |||
1659 | 356 | 371 | ||
1660 | 357 | def __call__(self, etype, value, elist): | 372 | def __call__(self, etype, value, elist): |
1661 | 358 | Term.cout.flush() | 373 | Term.cout.flush() |
1662 | 359 | Term.cerr.flush() | ||
1663 | 360 | print >> Term.cerr, self.text(etype,value,elist) | 374 | print >> Term.cerr, self.text(etype,value,elist) |
1664 | 375 | Term.cerr.flush() | ||
1665 | 361 | 376 | ||
1666 | 362 | def text(self,etype, value, elist,context=5): | 377 | def text(self,etype, value, elist,context=5): |
1667 | 363 | """Return a color formatted string with the traceback info.""" | 378 | """Return a color formatted string with the traceback info.""" |
1668 | @@ -424,7 +439,8 @@ | |||
1669 | 424 | 439 | ||
1670 | 425 | Also lifted nearly verbatim from traceback.py | 440 | Also lifted nearly verbatim from traceback.py |
1671 | 426 | """ | 441 | """ |
1673 | 427 | 442 | ||
1674 | 443 | have_filedata = False | ||
1675 | 428 | Colors = self.Colors | 444 | Colors = self.Colors |
1676 | 429 | list = [] | 445 | list = [] |
1677 | 430 | try: | 446 | try: |
1678 | @@ -438,8 +454,9 @@ | |||
1679 | 438 | try: | 454 | try: |
1680 | 439 | msg, (filename, lineno, offset, line) = value | 455 | msg, (filename, lineno, offset, line) = value |
1681 | 440 | except: | 456 | except: |
1683 | 441 | pass | 457 | have_filedata = False |
1684 | 442 | else: | 458 | else: |
1685 | 459 | have_filedata = True | ||
1686 | 443 | #print 'filename is',filename # dbg | 460 | #print 'filename is',filename # dbg |
1687 | 444 | if not filename: filename = "<string>" | 461 | if not filename: filename = "<string>" |
1688 | 445 | list.append('%s File %s"%s"%s, line %s%d%s\n' % \ | 462 | list.append('%s File %s"%s"%s, line %s%d%s\n' % \ |
1689 | @@ -469,6 +486,12 @@ | |||
1690 | 469 | Colors.Normal, s)) | 486 | Colors.Normal, s)) |
1691 | 470 | else: | 487 | else: |
1692 | 471 | list.append('%s\n' % str(stype)) | 488 | list.append('%s\n' % str(stype)) |
1693 | 489 | |||
1694 | 490 | # vds:>> | ||
1695 | 491 | if have_filedata: | ||
1696 | 492 | __IPYTHON__.hooks.synchronize_with_editor(filename, lineno, 0) | ||
1697 | 493 | # vds:<< | ||
1698 | 494 | |||
1699 | 472 | return list | 495 | return list |
1700 | 473 | 496 | ||
1701 | 474 | def _some_str(self, value): | 497 | def _some_str(self, value): |
1702 | @@ -780,6 +803,15 @@ | |||
1703 | 780 | for name in names: | 803 | for name in names: |
1704 | 781 | value = text_repr(getattr(evalue, name)) | 804 | value = text_repr(getattr(evalue, name)) |
1705 | 782 | exception.append('\n%s%s = %s' % (indent, name, value)) | 805 | exception.append('\n%s%s = %s' % (indent, name, value)) |
1706 | 806 | |||
1707 | 807 | # vds: >> | ||
1708 | 808 | if records: | ||
1709 | 809 | filepath, lnum = records[-1][1:3] | ||
1710 | 810 | #print "file:", str(file), "linenb", str(lnum) # dbg | ||
1711 | 811 | filepath = os.path.abspath(filepath) | ||
1712 | 812 | __IPYTHON__.hooks.synchronize_with_editor(filepath, lnum, 0) | ||
1713 | 813 | # vds: << | ||
1714 | 814 | |||
1715 | 783 | # return all our info assembled as a single string | 815 | # return all our info assembled as a single string |
1716 | 784 | return '%s\n\n%s\n%s' % (head,'\n'.join(frames),''.join(exception[0]) ) | 816 | return '%s\n\n%s\n%s' % (head,'\n'.join(frames),''.join(exception[0]) ) |
1717 | 785 | 817 | ||
1718 | @@ -834,8 +866,8 @@ | |||
1719 | 834 | (etype, evalue, etb) = info or sys.exc_info() | 866 | (etype, evalue, etb) = info or sys.exc_info() |
1720 | 835 | self.tb = etb | 867 | self.tb = etb |
1721 | 836 | Term.cout.flush() | 868 | Term.cout.flush() |
1722 | 837 | Term.cerr.flush() | ||
1723 | 838 | print >> Term.cerr, self.text(etype, evalue, etb) | 869 | print >> Term.cerr, self.text(etype, evalue, etb) |
1724 | 870 | Term.cerr.flush() | ||
1725 | 839 | 871 | ||
1726 | 840 | # Changed so an instance can just be called as VerboseTB_inst() and print | 872 | # Changed so an instance can just be called as VerboseTB_inst() and print |
1727 | 841 | # out the right info on its own. | 873 | # out the right info on its own. |
1728 | @@ -845,7 +877,10 @@ | |||
1729 | 845 | self.handler() | 877 | self.handler() |
1730 | 846 | else: | 878 | else: |
1731 | 847 | self.handler((etype, evalue, etb)) | 879 | self.handler((etype, evalue, etb)) |
1733 | 848 | self.debugger() | 880 | try: |
1734 | 881 | self.debugger() | ||
1735 | 882 | except KeyboardInterrupt: | ||
1736 | 883 | print "\nKeyboardInterrupt" | ||
1737 | 849 | 884 | ||
1738 | 850 | #---------------------------------------------------------------------------- | 885 | #---------------------------------------------------------------------------- |
1739 | 851 | class FormattedTB(VerboseTB,ListTB): | 886 | class FormattedTB(VerboseTB,ListTB): |
1740 | @@ -953,14 +988,17 @@ | |||
1741 | 953 | if out is None: | 988 | if out is None: |
1742 | 954 | out = Term.cerr | 989 | out = Term.cerr |
1743 | 955 | Term.cout.flush() | 990 | Term.cout.flush() |
1744 | 956 | out.flush() | ||
1745 | 957 | if tb_offset is not None: | 991 | if tb_offset is not None: |
1746 | 958 | tb_offset, self.tb_offset = self.tb_offset, tb_offset | 992 | tb_offset, self.tb_offset = self.tb_offset, tb_offset |
1747 | 959 | print >> out, self.text(etype, evalue, etb) | 993 | print >> out, self.text(etype, evalue, etb) |
1748 | 960 | self.tb_offset = tb_offset | 994 | self.tb_offset = tb_offset |
1749 | 961 | else: | 995 | else: |
1750 | 962 | print >> out, self.text(etype, evalue, etb) | 996 | print >> out, self.text(etype, evalue, etb) |
1752 | 963 | self.debugger() | 997 | out.flush() |
1753 | 998 | try: | ||
1754 | 999 | self.debugger() | ||
1755 | 1000 | except KeyboardInterrupt: | ||
1756 | 1001 | print "\nKeyboardInterrupt" | ||
1757 | 964 | 1002 | ||
1758 | 965 | def text(self,etype=None,value=None,tb=None,context=5,mode=None): | 1003 | def text(self,etype=None,value=None,tb=None,context=5,mode=None): |
1759 | 966 | if etype is None: | 1004 | if etype is None: |
1760 | 967 | 1005 | ||
1761 | === modified file 'IPython/kernel/core/util.py' | |||
1762 | --- IPython/kernel/core/util.py 2008-06-06 19:41:55 +0000 | |||
1763 | +++ IPython/kernel/core/util.py 2009-03-11 01:24:53 +0000 | |||
1764 | @@ -70,8 +70,8 @@ | |||
1765 | 70 | def make_quoted_expr(s): | 70 | def make_quoted_expr(s): |
1766 | 71 | """Return string s in appropriate quotes, using raw string if possible. | 71 | """Return string s in appropriate quotes, using raw string if possible. |
1767 | 72 | 72 | ||
1770 | 73 | Effectively this turns string: cd \ao\ao\ | 73 | XXX - example removed because it caused encoding errors in documentation |
1771 | 74 | to: r"cd \ao\ao\_"[:-1] | 74 | generation. We need a new example that doesn't contain invalid chars. |
1772 | 75 | 75 | ||
1773 | 76 | Note the use of raw string and padding at the end to allow trailing | 76 | Note the use of raw string and padding at the end to allow trailing |
1774 | 77 | backslash. | 77 | backslash. |
1775 | 78 | 78 | ||
1776 | === modified file 'IPython/kernel/scripts/ipcluster' (properties changed: -x to +x) | |||
1777 | === modified file 'IPython/kernel/scripts/ipcluster.py' (properties changed: -x to +x) | |||
1778 | === modified file 'IPython/kernel/scripts/ipcontroller' (properties changed: -x to +x) | |||
1779 | === modified file 'IPython/kernel/scripts/ipcontroller.py' (properties changed: -x to +x) | |||
1780 | === modified file 'IPython/kernel/scripts/ipengine' (properties changed: -x to +x) | |||
1781 | === modified file 'IPython/kernel/scripts/ipengine.py' (properties changed: -x to +x) | |||
1782 | === modified file 'IPython/macro.py' | |||
1783 | --- IPython/macro.py 2008-02-16 09:50:47 +0000 | |||
1784 | +++ IPython/macro.py 2009-03-11 06:53:19 +0000 | |||
1785 | @@ -9,7 +9,6 @@ | |||
1786 | 9 | 9 | ||
1787 | 10 | import IPython.ipapi | 10 | import IPython.ipapi |
1788 | 11 | 11 | ||
1789 | 12 | |||
1790 | 13 | from IPython.genutils import Term | 12 | from IPython.genutils import Term |
1791 | 14 | from IPython.ipapi import IPyAutocall | 13 | from IPython.ipapi import IPyAutocall |
1792 | 15 | 14 | ||
1793 | @@ -41,4 +40,4 @@ | |||
1794 | 41 | 40 | ||
1795 | 42 | def __getstate__(self): | 41 | def __getstate__(self): |
1796 | 43 | """ needed for safe pickling via %store """ | 42 | """ needed for safe pickling via %store """ |
1797 | 44 | return {'value': self.value} | ||
1798 | 45 | \ No newline at end of file | 43 | \ No newline at end of file |
1799 | 44 | return {'value': self.value} | ||
1800 | 46 | 45 | ||
1801 | === modified file 'IPython/numutils.py' | |||
1802 | --- IPython/numutils.py 2008-02-28 18:21:11 +0000 | |||
1803 | +++ IPython/numutils.py 2009-03-11 06:53:19 +0000 | |||
1804 | @@ -4,8 +4,7 @@ | |||
1805 | 4 | 4 | ||
1806 | 5 | Most of this module requires Numerical Python or is meant to be used with it. | 5 | Most of this module requires Numerical Python or is meant to be used with it. |
1807 | 6 | See http://www.pfdubois.com/numpy for details. | 6 | See http://www.pfdubois.com/numpy for details. |
1810 | 7 | 7 | """ | |
1809 | 8 | $Id: numutils.py 958 2005-12-27 23:17:51Z fperez $""" | ||
1811 | 9 | 8 | ||
1812 | 10 | #***************************************************************************** | 9 | #***************************************************************************** |
1813 | 11 | # Copyright (C) 2001-2005 Fernando Perez <fperez@colorado.edu> | 10 | # Copyright (C) 2001-2005 Fernando Perez <fperez@colorado.edu> |
1814 | @@ -14,10 +13,6 @@ | |||
1815 | 14 | # the file COPYING, distributed as part of this software. | 13 | # the file COPYING, distributed as part of this software. |
1816 | 15 | #***************************************************************************** | 14 | #***************************************************************************** |
1817 | 16 | 15 | ||
1818 | 17 | from IPython import Release | ||
1819 | 18 | __author__ = '%s <%s>' % Release.authors['Fernando'] | ||
1820 | 19 | __license__ = Release.license | ||
1821 | 20 | |||
1822 | 21 | __all__ = ['sum_flat','mean_flat','rms_flat','base_repr','binary_repr', | 16 | __all__ = ['sum_flat','mean_flat','rms_flat','base_repr','binary_repr', |
1823 | 22 | 'amin','amax','amap','zeros_like','empty_like', | 17 | 'amin','amax','amap','zeros_like','empty_like', |
1824 | 23 | 'frange','diagonal_matrix','identity', | 18 | 'frange','diagonal_matrix','identity', |
1825 | 24 | 19 | ||
1826 | === modified file 'IPython/platutils.py' | |||
1827 | --- IPython/platutils.py 2008-07-06 16:54:20 +0000 | |||
1828 | +++ IPython/platutils.py 2009-03-11 06:27:38 +0000 | |||
1829 | @@ -12,10 +12,6 @@ | |||
1830 | 12 | # the file COPYING, distributed as part of this software. | 12 | # the file COPYING, distributed as part of this software. |
1831 | 13 | #***************************************************************************** | 13 | #***************************************************************************** |
1832 | 14 | 14 | ||
1833 | 15 | from IPython import Release | ||
1834 | 16 | __author__ = '%s <%s>' % Release.authors['Ville'] | ||
1835 | 17 | __license__ = Release.license | ||
1836 | 18 | |||
1837 | 19 | import os | 15 | import os |
1838 | 20 | import sys | 16 | import sys |
1839 | 21 | 17 | ||
1840 | @@ -35,8 +31,26 @@ | |||
1841 | 35 | # Functionality that's logically common to all platforms goes here, each | 31 | # Functionality that's logically common to all platforms goes here, each |
1842 | 36 | # platform-specific module only provides the bits that are OS-dependent. | 32 | # platform-specific module only provides the bits that are OS-dependent. |
1843 | 37 | 33 | ||
1846 | 38 | def freeze_term_title(): | 34 | # XXX - I'm still not happy with a module global for this, but at least now |
1847 | 39 | _platutils.ignore_termtitle = True | 35 | # there is a public, cross-platform way of toggling the term title control on |
1848 | 36 | # and off. We should make this a stateful object later on so that each user | ||
1849 | 37 | # can have its own instance if needed. | ||
1850 | 38 | def toggle_set_term_title(val): | ||
1851 | 39 | """Control whether set_term_title is active or not. | ||
1852 | 40 | |||
1853 | 41 | set_term_title() allows writing to the console titlebar. In embedded | ||
1854 | 42 | widgets this can cause problems, so this call can be used to toggle it on | ||
1855 | 43 | or off as needed. | ||
1856 | 44 | |||
1857 | 45 | The default state of the module is for the function to be disabled. | ||
1858 | 46 | |||
1859 | 47 | Parameters | ||
1860 | 48 | ---------- | ||
1861 | 49 | val : bool | ||
1862 | 50 | If True, set_term_title() actually writes to the terminal (using the | ||
1863 | 51 | appropriate platform-specific module). If False, it is a no-op. | ||
1864 | 52 | """ | ||
1865 | 53 | _platutils.ignore_termtitle = not(val) | ||
1866 | 40 | 54 | ||
1867 | 41 | 55 | ||
1868 | 42 | def set_term_title(title): | 56 | def set_term_title(title): |
1869 | @@ -45,3 +59,12 @@ | |||
1870 | 45 | if _platutils.ignore_termtitle: | 59 | if _platutils.ignore_termtitle: |
1871 | 46 | return | 60 | return |
1872 | 47 | _platutils.set_term_title(title) | 61 | _platutils.set_term_title(title) |
1873 | 62 | |||
1874 | 63 | |||
1875 | 64 | #----------------------------------------------------------------------------- | ||
1876 | 65 | # Deprecated functions | ||
1877 | 66 | #----------------------------------------------------------------------------- | ||
1878 | 67 | def freeze_term_title(): | ||
1879 | 68 | warnings.warn("This function is deprecated, use toggle_set_term_title()") | ||
1880 | 69 | _platutils.ignore_termtitle = True | ||
1881 | 70 | |||
1882 | 48 | 71 | ||
1883 | === modified file 'IPython/platutils_posix.py' | |||
1884 | --- IPython/platutils_posix.py 2008-07-06 16:54:20 +0000 | |||
1885 | +++ IPython/platutils_posix.py 2009-03-11 06:27:38 +0000 | |||
1886 | @@ -12,14 +12,10 @@ | |||
1887 | 12 | # the file COPYING, distributed as part of this software. | 12 | # the file COPYING, distributed as part of this software. |
1888 | 13 | #***************************************************************************** | 13 | #***************************************************************************** |
1889 | 14 | 14 | ||
1890 | 15 | from IPython import Release | ||
1891 | 16 | __author__ = '%s <%s>' % Release.authors['Ville'] | ||
1892 | 17 | __license__ = Release.license | ||
1893 | 18 | |||
1894 | 19 | import sys | 15 | import sys |
1895 | 20 | import os | 16 | import os |
1896 | 21 | 17 | ||
1898 | 22 | ignore_termtitle = False | 18 | ignore_termtitle = True |
1899 | 23 | 19 | ||
1900 | 24 | def _dummy_op(*a, **b): | 20 | def _dummy_op(*a, **b): |
1901 | 25 | """ A no-op function """ | 21 | """ A no-op function """ |
1902 | @@ -27,7 +23,7 @@ | |||
1903 | 27 | def _set_term_title_xterm(title): | 23 | def _set_term_title_xterm(title): |
1904 | 28 | """ Change virtual terminal title in xterm-workalikes """ | 24 | """ Change virtual terminal title in xterm-workalikes """ |
1905 | 29 | 25 | ||
1907 | 30 | sys.stdout.write('\033]%d;%s\007' % (0,title)) | 26 | sys.stdout.write('\033]0;%s\007' % title) |
1908 | 31 | 27 | ||
1909 | 32 | 28 | ||
1910 | 33 | if os.environ.get('TERM','') == 'xterm': | 29 | if os.environ.get('TERM','') == 'xterm': |
1911 | 34 | 30 | ||
1912 | === modified file 'IPython/platutils_win32.py' | |||
1913 | --- IPython/platutils_win32.py 2008-07-06 16:54:20 +0000 | |||
1914 | +++ IPython/platutils_win32.py 2009-03-11 06:53:19 +0000 | |||
1915 | @@ -12,13 +12,9 @@ | |||
1916 | 12 | # the file COPYING, distributed as part of this software. | 12 | # the file COPYING, distributed as part of this software. |
1917 | 13 | #***************************************************************************** | 13 | #***************************************************************************** |
1918 | 14 | 14 | ||
1919 | 15 | from IPython import Release | ||
1920 | 16 | __author__ = '%s <%s>' % Release.authors['Ville'] | ||
1921 | 17 | __license__ = Release.license | ||
1922 | 18 | |||
1923 | 19 | import os | 15 | import os |
1924 | 20 | 16 | ||
1926 | 21 | ignore_termtitle = False | 17 | ignore_termtitle = True |
1927 | 22 | 18 | ||
1928 | 23 | try: | 19 | try: |
1929 | 24 | import ctypes | 20 | import ctypes |
1930 | 25 | 21 | ||
1931 | === modified file 'IPython/rlineimpl.py' | |||
1932 | --- IPython/rlineimpl.py 2008-02-16 09:50:47 +0000 | |||
1933 | +++ IPython/rlineimpl.py 2009-03-11 06:53:19 +0000 | |||
1934 | @@ -5,8 +5,7 @@ | |||
1935 | 5 | 5 | ||
1936 | 6 | In addition to normal readline stuff, this module provides have_readline | 6 | In addition to normal readline stuff, this module provides have_readline |
1937 | 7 | boolean and _outputfile variable used in genutils. | 7 | boolean and _outputfile variable used in genutils. |
1940 | 8 | 8 | """ | |
1939 | 9 | $Id: Magic.py 1096 2006-01-28 20:08:02Z vivainio $""" | ||
1941 | 10 | 9 | ||
1942 | 11 | import sys | 10 | import sys |
1943 | 12 | 11 | ||
1944 | @@ -53,4 +52,4 @@ | |||
1945 | 53 | _rl.clear_history | 52 | _rl.clear_history |
1946 | 54 | except AttributeError: | 53 | except AttributeError: |
1947 | 55 | def clear_history(): pass | 54 | def clear_history(): pass |
1948 | 56 | _rl.clear_history = clear_history | ||
1949 | 57 | \ No newline at end of file | 55 | \ No newline at end of file |
1950 | 56 | _rl.clear_history = clear_history | ||
1951 | 58 | 57 | ||
1952 | === modified file 'IPython/shellglobals.py' | |||
1953 | --- IPython/shellglobals.py 2008-03-22 15:03:36 +0000 | |||
1954 | +++ IPython/shellglobals.py 2009-03-11 06:53:19 +0000 | |||
1955 | @@ -1,6 +1,13 @@ | |||
1959 | 1 | from IPython.genutils import Term,warn,error,flag_calls, ask_yes_no | 1 | """Some globals used by the main Shell classes. |
1960 | 2 | 2 | """ | |
1961 | 3 | import thread,inspect | 3 | |
1962 | 4 | #----------------------------------------------------------------------------- | ||
1963 | 5 | # Module imports | ||
1964 | 6 | #----------------------------------------------------------------------------- | ||
1965 | 7 | |||
1966 | 8 | # stdlib | ||
1967 | 9 | import inspect | ||
1968 | 10 | import thread | ||
1969 | 4 | 11 | ||
1970 | 5 | try: | 12 | try: |
1971 | 6 | import ctypes | 13 | import ctypes |
1972 | @@ -8,8 +15,12 @@ | |||
1973 | 8 | except ImportError: | 15 | except ImportError: |
1974 | 9 | HAS_CTYPES = False | 16 | HAS_CTYPES = False |
1975 | 10 | 17 | ||
1976 | 18 | # our own | ||
1977 | 19 | from IPython.genutils import Term,warn,error,flag_calls, ask_yes_no | ||
1978 | 11 | 20 | ||
1979 | 21 | #----------------------------------------------------------------------------- | ||
1980 | 12 | # Globals | 22 | # Globals |
1981 | 23 | #----------------------------------------------------------------------------- | ||
1982 | 13 | # global flag to pass around information about Ctrl-C without exceptions | 24 | # global flag to pass around information about Ctrl-C without exceptions |
1983 | 14 | KBINT = False | 25 | KBINT = False |
1984 | 15 | 26 | ||
1985 | @@ -22,13 +33,11 @@ | |||
1986 | 22 | # Tag when runcode() is active, for exception handling | 33 | # Tag when runcode() is active, for exception handling |
1987 | 23 | CODE_RUN = None | 34 | CODE_RUN = None |
1988 | 24 | 35 | ||
1989 | 25 | |||
1990 | 26 | #----------------------------------------------------------------------------- | 36 | #----------------------------------------------------------------------------- |
1991 | 27 | # This class is trivial now, but I want to have it in to publish a clean | 37 | # This class is trivial now, but I want to have it in to publish a clean |
1992 | 28 | # interface. Later when the internals are reorganized, code that uses this | 38 | # interface. Later when the internals are reorganized, code that uses this |
1993 | 29 | # shouldn't have to change. | 39 | # shouldn't have to change. |
1994 | 30 | 40 | ||
1995 | 31 | |||
1996 | 32 | if HAS_CTYPES: | 41 | if HAS_CTYPES: |
1997 | 33 | # Add async exception support. Trick taken from: | 42 | # Add async exception support. Trick taken from: |
1998 | 34 | # http://sebulba.wikispaces.com/recipe+thread2 | 43 | # http://sebulba.wikispaces.com/recipe+thread2 |
1999 | @@ -81,16 +90,12 @@ | |||
2000 | 81 | # Set global flag so that runsource can know that Ctrl-C was hit | 90 | # Set global flag so that runsource can know that Ctrl-C was hit |
2001 | 82 | KBINT = True | 91 | KBINT = True |
2002 | 83 | 92 | ||
2003 | 93 | |||
2004 | 84 | def run_in_frontend(src): | 94 | def run_in_frontend(src): |
2009 | 85 | """ Check if source snippet can be run in the REPL thread, as opposed to GUI mainloop | 95 | """ Check if source snippet can be run in the REPL thread, as opposed to |
2010 | 86 | 96 | GUI mainloop (to prevent unnecessary hanging of mainloop). | |
2007 | 87 | (to prevent unnecessary hanging of mainloop). | ||
2008 | 88 | |||
2011 | 89 | """ | 97 | """ |
2012 | 90 | 98 | ||
2013 | 91 | if src.startswith('_ip.system(') and not '\n' in src: | 99 | if src.startswith('_ip.system(') and not '\n' in src: |
2014 | 92 | return True | 100 | return True |
2015 | 93 | return False | 101 | return False |
2016 | 94 | |||
2017 | 95 | |||
2018 | 96 | |||
2019 | 97 | 102 | ||
2020 | === modified file 'IPython/strdispatch.py' | |||
2021 | --- IPython/strdispatch.py 2008-07-30 20:08:19 +0000 | |||
2022 | +++ IPython/strdispatch.py 2009-03-11 06:53:19 +0000 | |||
2023 | @@ -8,7 +8,6 @@ | |||
2024 | 8 | from IPython.hooks import CommandChainDispatcher | 8 | from IPython.hooks import CommandChainDispatcher |
2025 | 9 | import IPython.hooks | 9 | import IPython.hooks |
2026 | 10 | 10 | ||
2027 | 11 | |||
2028 | 12 | # Code begins | 11 | # Code begins |
2029 | 13 | class StrDispatch(object): | 12 | class StrDispatch(object): |
2030 | 14 | """Dispatch (lookup) a set of strings / regexps for match. | 13 | """Dispatch (lookup) a set of strings / regexps for match. |
2031 | 15 | 14 | ||
2032 | === modified file 'IPython/testing/decorators.py' | |||
2033 | --- IPython/testing/decorators.py 2008-09-15 02:07:52 +0000 | |||
2034 | +++ IPython/testing/decorators.py 2009-03-11 01:24:53 +0000 | |||
2035 | @@ -1,12 +1,10 @@ | |||
2036 | 1 | """Decorators for labeling test objects. | 1 | """Decorators for labeling test objects. |
2037 | 2 | 2 | ||
2045 | 3 | Decorators that merely return a modified version of the original | 3 | Decorators that merely return a modified version of the original function |
2046 | 4 | function object are straightforward. Decorators that return a new | 4 | object are straightforward. Decorators that return a new function object need |
2047 | 5 | function object need to use | 5 | to use nose.tools.make_decorator(original_function)(decorator) in returning the |
2048 | 6 | nose.tools.make_decorator(original_function)(decorator) in returning | 6 | decorator, in order to preserve metadata such as function name, setup and |
2049 | 7 | the decorator, in order to preserve metadata such as function name, | 7 | teardown functions and so on - see nose.tools for more information. |
2043 | 8 | setup and teardown functions and so on - see nose.tools for more | ||
2044 | 9 | information. | ||
2050 | 10 | 8 | ||
2051 | 11 | This module provides a set of useful decorators meant to be ready to use in | 9 | This module provides a set of useful decorators meant to be ready to use in |
2052 | 12 | your own tests. See the bottom of the file for the ready-made ones, and if you | 10 | your own tests. See the bottom of the file for the ready-made ones, and if you |
2053 | @@ -115,6 +113,115 @@ | |||
2054 | 115 | 113 | ||
2055 | 116 | return decor | 114 | return decor |
2056 | 117 | 115 | ||
2057 | 116 | |||
2058 | 117 | # Inspired by numpy's skipif, but uses the full apply_wrapper utility to | ||
2059 | 118 | # preserve function metadata better and allows the skip condition to be a | ||
2060 | 119 | # callable. | ||
2061 | 120 | def skipif(skip_condition, msg=None): | ||
2062 | 121 | ''' Make function raise SkipTest exception if skip_condition is true | ||
2063 | 122 | |||
2064 | 123 | Parameters | ||
2065 | 124 | ---------- | ||
2066 | 125 | skip_condition : bool or callable. | ||
2067 | 126 | Flag to determine whether to skip test. If the condition is a | ||
2068 | 127 | callable, it is used at runtime to dynamically make the decision. This | ||
2069 | 128 | is useful for tests that may require costly imports, to delay the cost | ||
2070 | 129 | until the test suite is actually executed. | ||
2071 | 130 | msg : string | ||
2072 | 131 | Message to give on raising a SkipTest exception | ||
2073 | 132 | |||
2074 | 133 | Returns | ||
2075 | 134 | ------- | ||
2076 | 135 | decorator : function | ||
2077 | 136 | Decorator, which, when applied to a function, causes SkipTest | ||
2078 | 137 | to be raised when the skip_condition was True, and the function | ||
2079 | 138 | to be called normally otherwise. | ||
2080 | 139 | |||
2081 | 140 | Notes | ||
2082 | 141 | ----- | ||
2083 | 142 | You will see from the code that we had to further decorate the | ||
2084 | 143 | decorator with the nose.tools.make_decorator function in order to | ||
2085 | 144 | transmit function name, and various other metadata. | ||
2086 | 145 | ''' | ||
2087 | 146 | |||
2088 | 147 | def skip_decorator(f): | ||
2089 | 148 | # Local import to avoid a hard nose dependency and only incur the | ||
2090 | 149 | # import time overhead at actual test-time. | ||
2091 | 150 | import nose | ||
2092 | 151 | |||
2093 | 152 | # Allow for both boolean or callable skip conditions. | ||
2094 | 153 | if callable(skip_condition): | ||
2095 | 154 | skip_val = lambda : skip_condition() | ||
2096 | 155 | else: | ||
2097 | 156 | skip_val = lambda : skip_condition | ||
2098 | 157 | |||
2099 | 158 | def get_msg(func,msg=None): | ||
2100 | 159 | """Skip message with information about function being skipped.""" | ||
2101 | 160 | if msg is None: out = 'Test skipped due to test condition.' | ||
2102 | 161 | else: out = msg | ||
2103 | 162 | return "Skipping test: %s. %s" % (func.__name__,out) | ||
2104 | 163 | |||
2105 | 164 | # We need to define *two* skippers because Python doesn't allow both | ||
2106 | 165 | # return with value and yield inside the same function. | ||
2107 | 166 | def skipper_func(*args, **kwargs): | ||
2108 | 167 | """Skipper for normal test functions.""" | ||
2109 | 168 | if skip_val(): | ||
2110 | 169 | raise nose.SkipTest(get_msg(f,msg)) | ||
2111 | 170 | else: | ||
2112 | 171 | return f(*args, **kwargs) | ||
2113 | 172 | |||
2114 | 173 | def skipper_gen(*args, **kwargs): | ||
2115 | 174 | """Skipper for test generators.""" | ||
2116 | 175 | if skip_val(): | ||
2117 | 176 | raise nose.SkipTest(get_msg(f,msg)) | ||
2118 | 177 | else: | ||
2119 | 178 | for x in f(*args, **kwargs): | ||
2120 | 179 | yield x | ||
2121 | 180 | |||
2122 | 181 | # Choose the right skipper to use when building the actual generator. | ||
2123 | 182 | if nose.util.isgenerator(f): | ||
2124 | 183 | skipper = skipper_gen | ||
2125 | 184 | else: | ||
2126 | 185 | skipper = skipper_func | ||
2127 | 186 | |||
2128 | 187 | return nose.tools.make_decorator(f)(skipper) | ||
2129 | 188 | |||
2130 | 189 | return skip_decorator | ||
2131 | 190 | |||
2132 | 191 | # A version with the condition set to true, common case just to attacha message | ||
2133 | 192 | # to a skip decorator | ||
2134 | 193 | def skip(msg=None): | ||
2135 | 194 | """Decorator factory - mark a test function for skipping from test suite. | ||
2136 | 195 | |||
2137 | 196 | :Parameters: | ||
2138 | 197 | msg : string | ||
2139 | 198 | Optional message to be added. | ||
2140 | 199 | |||
2141 | 200 | :Returns: | ||
2142 | 201 | decorator : function | ||
2143 | 202 | Decorator, which, when applied to a function, causes SkipTest | ||
2144 | 203 | to be raised, with the optional message added. | ||
2145 | 204 | """ | ||
2146 | 205 | |||
2147 | 206 | return skipif(True,msg) | ||
2148 | 207 | |||
2149 | 208 | |||
2150 | 209 | #----------------------------------------------------------------------------- | ||
2151 | 210 | # Utility functions for decorators | ||
2152 | 211 | def numpy_not_available(): | ||
2153 | 212 | """Can numpy be imported? Returns true if numpy does NOT import. | ||
2154 | 213 | |||
2155 | 214 | This is used to make a decorator to skip tests that require numpy to be | ||
2156 | 215 | available, but delay the 'import numpy' to test execution time. | ||
2157 | 216 | """ | ||
2158 | 217 | try: | ||
2159 | 218 | import numpy | ||
2160 | 219 | np_not_avail = False | ||
2161 | 220 | except ImportError: | ||
2162 | 221 | np_not_avail = True | ||
2163 | 222 | |||
2164 | 223 | return np_not_avail | ||
2165 | 224 | |||
2166 | 118 | #----------------------------------------------------------------------------- | 225 | #----------------------------------------------------------------------------- |
2167 | 119 | # Decorators for public use | 226 | # Decorators for public use |
2168 | 120 | 227 | ||
2169 | @@ -125,36 +232,13 @@ | |||
2170 | 125 | omit from testing, while preserving the docstring for introspection, help, | 232 | omit from testing, while preserving the docstring for introspection, help, |
2171 | 126 | etc.""") | 233 | etc.""") |
2172 | 127 | 234 | ||
2173 | 128 | def skip(msg=''): | ||
2174 | 129 | """Decorator - mark a test function for skipping from test suite. | ||
2175 | 130 | |||
2176 | 131 | This function *is* already a decorator, it is not a factory like | ||
2177 | 132 | make_label_dec or some of those in decorators_numpy. | ||
2178 | 133 | |||
2179 | 134 | :Parameters: | ||
2180 | 135 | |||
2181 | 136 | func : function | ||
2182 | 137 | Test function to be skipped | ||
2183 | 138 | |||
2184 | 139 | msg : string | ||
2185 | 140 | Optional message to be added. | ||
2186 | 141 | """ | ||
2187 | 142 | |||
2188 | 143 | import nose | ||
2189 | 144 | |||
2190 | 145 | def inner(func): | ||
2191 | 146 | |||
2192 | 147 | def wrapper(*a,**k): | ||
2193 | 148 | if msg: out = '\n'+msg | ||
2194 | 149 | else: out = '' | ||
2195 | 150 | raise nose.SkipTest("Skipping test for function: %s%s" % | ||
2196 | 151 | (func.__name__,out)) | ||
2197 | 152 | |||
2198 | 153 | return apply_wrapper(wrapper,func) | ||
2199 | 154 | |||
2200 | 155 | return inner | ||
2201 | 156 | |||
2202 | 157 | # Decorators to skip certain tests on specific platforms. | 235 | # Decorators to skip certain tests on specific platforms. |
2204 | 158 | skip_win32 = skipif(sys.platform=='win32',"This test does not run under Windows") | 236 | skip_win32 = skipif(sys.platform=='win32', |
2205 | 237 | "This test does not run under Windows") | ||
2206 | 159 | skip_linux = skipif(sys.platform=='linux2',"This test does not run under Linux") | 238 | skip_linux = skipif(sys.platform=='linux2',"This test does not run under Linux") |
2208 | 160 | skip_osx = skipif(sys.platform=='darwin',"This test does not run under OSX") | 239 | skip_osx = skipif(sys.platform=='darwin',"This test does not run under OS X") |
2209 | 240 | |||
2210 | 241 | |||
2211 | 242 | skipif_not_numpy = skipif(numpy_not_available,"This test requires numpy") | ||
2212 | 243 | |||
2213 | 244 | skipknownfailure = skip('This test is known to fail') | ||
2214 | 161 | 245 | ||
2215 | === modified file 'IPython/testing/decorators_numpy.py' | |||
2216 | --- IPython/testing/decorators_numpy.py 2008-08-02 09:07:37 +0000 | |||
2217 | +++ IPython/testing/decorators_numpy.py 2009-03-11 01:24:53 +0000 | |||
2218 | @@ -46,13 +46,16 @@ | |||
2219 | 46 | return t | 46 | return t |
2220 | 47 | return set_test | 47 | return set_test |
2221 | 48 | 48 | ||
2223 | 49 | def skipif(skip_condition, msg=None): | 49 | def skipif(skip_condition=True, msg=None): |
2224 | 50 | ''' Make function raise SkipTest exception if skip_condition is true | 50 | ''' Make function raise SkipTest exception if skip_condition is true |
2225 | 51 | 51 | ||
2226 | 52 | Parameters | 52 | Parameters |
2230 | 53 | --------- | 53 | ---------- |
2231 | 54 | skip_condition : bool | 54 | skip_condition : bool or callable. |
2232 | 55 | Flag to determine whether to skip test (True) or not (False) | 55 | Flag to determine whether to skip test. If the condition is a |
2233 | 56 | callable, it is used at runtime to dynamically make the decision. This | ||
2234 | 57 | is useful for tests that may require costly imports, to delay the cost | ||
2235 | 58 | until the test suite is actually executed. | ||
2236 | 56 | msg : string | 59 | msg : string |
2237 | 57 | Message to give on raising a SkipTest exception | 60 | Message to give on raising a SkipTest exception |
2238 | 58 | 61 | ||
2239 | 59 | 62 | ||
2240 | === modified file 'IPython/testing/iptest.py' | |||
2241 | --- IPython/testing/iptest.py 2008-08-24 06:37:40 +0000 | |||
2242 | +++ IPython/testing/iptest.py 2009-03-11 05:49:08 +0000 | |||
2243 | @@ -1,16 +1,53 @@ | |||
2244 | 1 | #!/usr/bin/env python | ||
2245 | 2 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
2246 | 3 | """IPython Test Suite Runner. | 2 | """IPython Test Suite Runner. |
2247 | 3 | |||
2248 | 4 | This module provides a main entry point to a user script to test IPython itself | ||
2249 | 5 | from the command line. The main() routine can be used in a similar manner to | ||
2250 | 6 | the ``nosetests`` script, and it takes similar arguments, but if no arguments | ||
2251 | 7 | are given it defaults to testing all of IPython. This should be preferred to | ||
2252 | 8 | using plain ``nosetests`` because a number of nose plugins necessary to test | ||
2253 | 9 | IPython correctly are automatically configured by this code. | ||
2254 | 4 | """ | 10 | """ |
2255 | 5 | 11 | ||
2256 | 12 | #----------------------------------------------------------------------------- | ||
2257 | 13 | # Module imports | ||
2258 | 14 | #----------------------------------------------------------------------------- | ||
2259 | 15 | |||
2260 | 16 | # stdlib | ||
2261 | 6 | import sys | 17 | import sys |
2262 | 7 | import warnings | 18 | import warnings |
2263 | 8 | 19 | ||
2264 | 20 | # third-party | ||
2265 | 21 | import nose.plugins.builtin | ||
2266 | 9 | from nose.core import TestProgram | 22 | from nose.core import TestProgram |
2267 | 10 | import nose.plugins.builtin | ||
2268 | 11 | 23 | ||
2269 | 24 | # Our own imports | ||
2270 | 12 | from IPython.testing.plugin.ipdoctest import IPythonDoctest | 25 | from IPython.testing.plugin.ipdoctest import IPythonDoctest |
2271 | 13 | 26 | ||
2272 | 27 | #----------------------------------------------------------------------------- | ||
2273 | 28 | # Constants and globals | ||
2274 | 29 | #----------------------------------------------------------------------------- | ||
2275 | 30 | |||
2276 | 31 | # For the IPythonDoctest plugin, we need to exclude certain patterns that cause | ||
2277 | 32 | # testing problems. We should strive to minimize the number of skipped | ||
2278 | 33 | # modules, since this means untested code. As the testing machinery | ||
2279 | 34 | # solidifies, this list should eventually become empty. | ||
2280 | 35 | EXCLUDE = ['IPython/external/', | ||
2281 | 36 | 'IPython/platutils_win32', | ||
2282 | 37 | 'IPython/frontend/cocoa', | ||
2283 | 38 | 'IPython_doctest_plugin', | ||
2284 | 39 | 'IPython/Gnuplot', | ||
2285 | 40 | 'IPython/Extensions/ipy_', | ||
2286 | 41 | 'IPython/Extensions/clearcmd', | ||
2287 | 42 | 'IPython/Extensions/PhysicalQIn', | ||
2288 | 43 | 'IPython/Extensions/scitedirector', | ||
2289 | 44 | 'IPython/testing/plugin', | ||
2290 | 45 | ] | ||
2291 | 46 | |||
2292 | 47 | #----------------------------------------------------------------------------- | ||
2293 | 48 | # Functions and classes | ||
2294 | 49 | #----------------------------------------------------------------------------- | ||
2295 | 50 | |||
2296 | 14 | def main(): | 51 | def main(): |
2297 | 15 | """Run the IPython test suite. | 52 | """Run the IPython test suite. |
2298 | 16 | """ | 53 | """ |
2299 | @@ -18,36 +55,39 @@ | |||
2300 | 18 | warnings.filterwarnings('ignore', | 55 | warnings.filterwarnings('ignore', |
2301 | 19 | 'This will be removed soon. Use IPython.testing.util instead') | 56 | 'This will be removed soon. Use IPython.testing.util instead') |
2302 | 20 | 57 | ||
2306 | 21 | 58 | argv = sys.argv + [ '--with-ipdoctest', | |
2307 | 22 | # construct list of plugins, omitting the existing doctest plugin | 59 | '--doctest-tests','--doctest-extension=txt', |
2308 | 23 | plugins = [IPythonDoctest()] | 60 | '--detailed-errors', |
2309 | 61 | |||
2310 | 62 | # We add --exe because of setuptools' imbecility (it | ||
2311 | 63 | # blindly does chmod +x on ALL files). Nose does the | ||
2312 | 64 | # right thing and it tries to avoid executables, | ||
2313 | 65 | # setuptools unfortunately forces our hand here. This | ||
2314 | 66 | # has been discussed on the distutils list and the | ||
2315 | 67 | # setuptools devs refuse to fix this problem! | ||
2316 | 68 | '--exe', | ||
2317 | 69 | ] | ||
2318 | 70 | |||
2319 | 71 | # Detect if any tests were required by explicitly calling an IPython | ||
2320 | 72 | # submodule or giving a specific path | ||
2321 | 73 | has_tests = False | ||
2322 | 74 | for arg in sys.argv: | ||
2323 | 75 | if 'IPython' in arg or arg.endswith('.py') or \ | ||
2324 | 76 | (':' in arg and '.py' in arg): | ||
2325 | 77 | has_tests = True | ||
2326 | 78 | break | ||
2327 | 79 | # If nothing was specifically requested, test full IPython | ||
2328 | 80 | if not has_tests: | ||
2329 | 81 | argv.append('IPython') | ||
2330 | 82 | |||
2331 | 83 | # Construct list of plugins, omitting the existing doctest plugin. | ||
2332 | 84 | plugins = [IPythonDoctest(EXCLUDE)] | ||
2333 | 24 | for p in nose.plugins.builtin.plugins: | 85 | for p in nose.plugins.builtin.plugins: |
2334 | 25 | plug = p() | 86 | plug = p() |
2335 | 26 | if plug.name == 'doctest': | 87 | if plug.name == 'doctest': |
2336 | 27 | continue | 88 | continue |
2337 | 28 | 89 | ||
2339 | 29 | #print 'adding plugin:',plug.name # dbg | 90 | #print '*** adding plugin:',plug.name # dbg |
2340 | 30 | plugins.append(plug) | 91 | plugins.append(plug) |
2341 | 31 | 92 | ||
2342 | 32 | argv = sys.argv + ['--doctest-tests','--doctest-extension=txt', | ||
2343 | 33 | '--detailed-errors', | ||
2344 | 34 | |||
2345 | 35 | # We add --exe because of setuptools' imbecility (it | ||
2346 | 36 | # blindly does chmod +x on ALL files). Nose does the | ||
2347 | 37 | # right thing and it tries to avoid executables, | ||
2348 | 38 | # setuptools unfortunately forces our hand here. This | ||
2349 | 39 | # has been discussed on the distutils list and the | ||
2350 | 40 | # setuptools devs refuse to fix this problem! | ||
2351 | 41 | '--exe', | ||
2352 | 42 | ] | ||
2353 | 43 | |||
2354 | 44 | has_ip = False | ||
2355 | 45 | for arg in sys.argv: | ||
2356 | 46 | if 'IPython' in arg: | ||
2357 | 47 | has_ip = True | ||
2358 | 48 | break | ||
2359 | 49 | |||
2360 | 50 | if not has_ip: | ||
2361 | 51 | argv.append('IPython') | ||
2362 | 52 | |||
2363 | 53 | TestProgram(argv=argv,plugins=plugins) | 93 | TestProgram(argv=argv,plugins=plugins) |
2364 | 54 | 94 | ||
2365 | === modified file 'IPython/testing/plugin/Makefile' | |||
2366 | --- IPython/testing/plugin/Makefile 2008-09-03 15:54:03 +0000 | |||
2367 | +++ IPython/testing/plugin/Makefile 2008-11-09 05:54:34 +0000 | |||
2368 | @@ -36,8 +36,8 @@ | |||
2369 | 36 | magic: plugin | 36 | magic: plugin |
2370 | 37 | $(NOSE) IPython.Magic | 37 | $(NOSE) IPython.Magic |
2371 | 38 | 38 | ||
2374 | 39 | ipipe: plugin | 39 | excolors: plugin |
2375 | 40 | $(NOSE) IPython.Extensions.ipipe | 40 | $(NOSE) IPython.excolors |
2376 | 41 | 41 | ||
2377 | 42 | iplib: plugin | 42 | iplib: plugin |
2378 | 43 | $(NOSE) IPython.iplib | 43 | $(NOSE) IPython.iplib |
2379 | 44 | 44 | ||
2380 | === modified file 'IPython/testing/plugin/ipdoctest.py' | |||
2381 | --- IPython/testing/plugin/ipdoctest.py 2008-08-24 06:10:55 +0000 | |||
2382 | +++ IPython/testing/plugin/ipdoctest.py 2009-03-11 05:49:08 +0000 | |||
2383 | @@ -65,13 +65,28 @@ | |||
2384 | 65 | # test globals. Once we move over to a clean magic system, this will be done | 65 | # test globals. Once we move over to a clean magic system, this will be done |
2385 | 66 | # with much less ugliness. | 66 | # with much less ugliness. |
2386 | 67 | 67 | ||
2387 | 68 | class py_file_finder(object): | ||
2388 | 69 | def __init__(self,test_filename): | ||
2389 | 70 | self.test_filename = test_filename | ||
2390 | 71 | |||
2391 | 72 | def __call__(self,name): | ||
2392 | 73 | from IPython.genutils import get_py_filename | ||
2393 | 74 | try: | ||
2394 | 75 | get_py_filename(name) | ||
2395 | 76 | except IOError: | ||
2396 | 77 | test_dir = os.path.dirname(self.test_filename) | ||
2397 | 78 | new_path = os.path.join(test_dir,name) | ||
2398 | 79 | return get_py_filename(new_path) | ||
2399 | 80 | |||
2400 | 81 | |||
2401 | 68 | def _run_ns_sync(self,arg_s,runner=None): | 82 | def _run_ns_sync(self,arg_s,runner=None): |
2402 | 69 | """Modified version of %run that syncs testing namespaces. | 83 | """Modified version of %run that syncs testing namespaces. |
2403 | 70 | 84 | ||
2404 | 71 | This is strictly needed for running doctests that call %run. | 85 | This is strictly needed for running doctests that call %run. |
2405 | 72 | """ | 86 | """ |
2406 | 73 | 87 | ||
2408 | 74 | out = _ip.IP.magic_run_ori(arg_s,runner) | 88 | finder = py_file_finder(_run_ns_sync.test_filename) |
2409 | 89 | out = _ip.IP.magic_run_ori(arg_s,runner,finder) | ||
2410 | 75 | _run_ns_sync.test_globs.update(_ip.user_ns) | 90 | _run_ns_sync.test_globs.update(_ip.user_ns) |
2411 | 76 | return out | 91 | return out |
2412 | 77 | 92 | ||
2413 | @@ -129,8 +144,7 @@ | |||
2414 | 129 | 144 | ||
2415 | 130 | # Start IPython instance. We customize it to start with minimal frills. | 145 | # Start IPython instance. We customize it to start with minimal frills. |
2416 | 131 | user_ns,global_ns = IPython.ipapi.make_user_namespaces(ipnsdict(),dict()) | 146 | user_ns,global_ns = IPython.ipapi.make_user_namespaces(ipnsdict(),dict()) |
2419 | 132 | 147 | IPython.Shell.IPShell(['--colors=NoColor','--noterm_title'], | |
2418 | 133 | IPython.Shell.IPShell(['--classic','--noterm_title'], | ||
2420 | 134 | user_ns,global_ns) | 148 | user_ns,global_ns) |
2421 | 135 | 149 | ||
2422 | 136 | # Deactivate the various python system hooks added by ipython for | 150 | # Deactivate the various python system hooks added by ipython for |
2423 | @@ -172,13 +186,19 @@ | |||
2424 | 172 | return os.path.splitext(filename)[1].lower() in ('.so','.pyd') | 186 | return os.path.splitext(filename)[1].lower() in ('.so','.pyd') |
2425 | 173 | 187 | ||
2426 | 174 | 188 | ||
2428 | 175 | class nodoc(object): | 189 | class DocTestSkip(object): |
2429 | 190 | """Object wrapper for doctests to be skipped.""" | ||
2430 | 191 | |||
2431 | 192 | ds_skip = """Doctest to skip. | ||
2432 | 193 | >>> 1 #doctest: +SKIP | ||
2433 | 194 | """ | ||
2434 | 195 | |||
2435 | 176 | def __init__(self,obj): | 196 | def __init__(self,obj): |
2436 | 177 | self.obj = obj | 197 | self.obj = obj |
2437 | 178 | 198 | ||
2438 | 179 | def __getattribute__(self,key): | 199 | def __getattribute__(self,key): |
2439 | 180 | if key == '__doc__': | 200 | if key == '__doc__': |
2441 | 181 | return None | 201 | return DocTestSkip.ds_skip |
2442 | 182 | else: | 202 | else: |
2443 | 183 | return getattr(object.__getattribute__(self,'obj'),key) | 203 | return getattr(object.__getattribute__(self,'obj'),key) |
2444 | 184 | 204 | ||
2445 | @@ -222,7 +242,7 @@ | |||
2446 | 222 | 242 | ||
2447 | 223 | if hasattr(obj,"skip_doctest"): | 243 | if hasattr(obj,"skip_doctest"): |
2448 | 224 | #print 'SKIPPING DOCTEST FOR:',obj # dbg | 244 | #print 'SKIPPING DOCTEST FOR:',obj # dbg |
2450 | 225 | obj = nodoc(obj) | 245 | obj = DocTestSkip(obj) |
2451 | 226 | 246 | ||
2452 | 227 | doctest.DocTestFinder._find(self,tests, obj, name, module, | 247 | doctest.DocTestFinder._find(self,tests, obj, name, module, |
2453 | 228 | source_lines, globs, seen) | 248 | source_lines, globs, seen) |
2454 | @@ -638,7 +658,8 @@ | |||
2455 | 638 | # when called (rather than unconconditionally updating test.globs here | 658 | # when called (rather than unconconditionally updating test.globs here |
2456 | 639 | # for all examples, most of which won't be calling %run anyway). | 659 | # for all examples, most of which won't be calling %run anyway). |
2457 | 640 | _run_ns_sync.test_globs = test.globs | 660 | _run_ns_sync.test_globs = test.globs |
2459 | 641 | 661 | _run_ns_sync.test_filename = test.filename | |
2460 | 662 | |||
2461 | 642 | return super(IPDocTestRunner,self).run(test, | 663 | return super(IPDocTestRunner,self).run(test, |
2462 | 643 | compileflags,out,clear_globs) | 664 | compileflags,out,clear_globs) |
2463 | 644 | 665 | ||
2464 | @@ -656,6 +677,22 @@ | |||
2465 | 656 | name = 'extdoctest' # call nosetests with --with-extdoctest | 677 | name = 'extdoctest' # call nosetests with --with-extdoctest |
2466 | 657 | enabled = True | 678 | enabled = True |
2467 | 658 | 679 | ||
2468 | 680 | def __init__(self,exclude_patterns=None): | ||
2469 | 681 | """Create a new ExtensionDoctest plugin. | ||
2470 | 682 | |||
2471 | 683 | Parameters | ||
2472 | 684 | ---------- | ||
2473 | 685 | |||
2474 | 686 | exclude_patterns : sequence of strings, optional | ||
2475 | 687 | These patterns are compiled as regular expressions, subsequently used | ||
2476 | 688 | to exclude any filename which matches them from inclusion in the test | ||
2477 | 689 | suite (using pattern.search(), NOT pattern.match() ). | ||
2478 | 690 | """ | ||
2479 | 691 | if exclude_patterns is None: | ||
2480 | 692 | exclude_patterns = [] | ||
2481 | 693 | self.exclude_patterns = map(re.compile,exclude_patterns) | ||
2482 | 694 | doctests.Doctest.__init__(self) | ||
2483 | 695 | |||
2484 | 659 | def options(self, parser, env=os.environ): | 696 | def options(self, parser, env=os.environ): |
2485 | 660 | Plugin.options(self, parser, env) | 697 | Plugin.options(self, parser, env) |
2486 | 661 | parser.add_option('--doctest-tests', action='store_true', | 698 | parser.add_option('--doctest-tests', action='store_true', |
2487 | @@ -688,6 +725,7 @@ | |||
2488 | 688 | self.globs = None | 725 | self.globs = None |
2489 | 689 | self.extraglobs = None | 726 | self.extraglobs = None |
2490 | 690 | 727 | ||
2491 | 728 | |||
2492 | 691 | def loadTestsFromExtensionModule(self,filename): | 729 | def loadTestsFromExtensionModule(self,filename): |
2493 | 692 | bpath,mod = os.path.split(filename) | 730 | bpath,mod = os.path.split(filename) |
2494 | 693 | modname = os.path.splitext(mod)[0] | 731 | modname = os.path.splitext(mod)[0] |
2495 | @@ -703,8 +741,8 @@ | |||
2496 | 703 | # a few modifications to control output checking. | 741 | # a few modifications to control output checking. |
2497 | 704 | 742 | ||
2498 | 705 | def loadTestsFromModule(self, module): | 743 | def loadTestsFromModule(self, module): |
2501 | 706 | #print 'lTM',module # dbg | 744 | #print '*** ipdoctest - lTM',module # dbg |
2502 | 707 | 745 | ||
2503 | 708 | if not self.matches(module.__name__): | 746 | if not self.matches(module.__name__): |
2504 | 709 | log.debug("Doctest doesn't want module %s", module) | 747 | log.debug("Doctest doesn't want module %s", module) |
2505 | 710 | return | 748 | return |
2506 | @@ -733,8 +771,6 @@ | |||
2507 | 733 | 771 | ||
2508 | 734 | 772 | ||
2509 | 735 | def loadTestsFromFile(self, filename): | 773 | def loadTestsFromFile(self, filename): |
2510 | 736 | #print 'lTF',filename # dbg | ||
2511 | 737 | |||
2512 | 738 | if is_extension_module(filename): | 774 | if is_extension_module(filename): |
2513 | 739 | for t in self.loadTestsFromExtensionModule(filename): | 775 | for t in self.loadTestsFromExtensionModule(filename): |
2514 | 740 | yield t | 776 | yield t |
2515 | @@ -761,22 +797,10 @@ | |||
2516 | 761 | Modified version that accepts extension modules as valid containers for | 797 | Modified version that accepts extension modules as valid containers for |
2517 | 762 | doctests. | 798 | doctests. |
2518 | 763 | """ | 799 | """ |
2535 | 764 | print 'Filename:',filename # dbg | 800 | #print '*** ipdoctest- wantFile:',filename # dbg |
2536 | 765 | 801 | ||
2537 | 766 | # XXX - temporarily hardcoded list, will move to driver later | 802 | for pat in self.exclude_patterns: |
2538 | 767 | exclude = ['IPython/external/', | 803 | if pat.search(filename): |
2523 | 768 | 'IPython/platutils_win32', | ||
2524 | 769 | 'IPython/frontend/cocoa', | ||
2525 | 770 | 'IPython_doctest_plugin', | ||
2526 | 771 | 'IPython/Gnuplot', | ||
2527 | 772 | 'IPython/Extensions/ipy_', | ||
2528 | 773 | 'IPython/Extensions/PhysicalQIn', | ||
2529 | 774 | 'IPython/Extensions/scitedirector', | ||
2530 | 775 | 'IPython/testing/plugin', | ||
2531 | 776 | ] | ||
2532 | 777 | |||
2533 | 778 | for fex in exclude: | ||
2534 | 779 | if fex in filename: # substring | ||
2539 | 780 | #print '###>>> SKIP:',filename # dbg | 804 | #print '###>>> SKIP:',filename # dbg |
2540 | 781 | return False | 805 | return False |
2541 | 782 | 806 | ||
2542 | @@ -791,6 +815,23 @@ | |||
2543 | 791 | """ | 815 | """ |
2544 | 792 | name = 'ipdoctest' # call nosetests with --with-ipdoctest | 816 | name = 'ipdoctest' # call nosetests with --with-ipdoctest |
2545 | 793 | enabled = True | 817 | enabled = True |
2546 | 818 | |||
2547 | 819 | def makeTest(self, obj, parent): | ||
2548 | 820 | """Look for doctests in the given object, which will be a | ||
2549 | 821 | function, method or class. | ||
2550 | 822 | """ | ||
2551 | 823 | # always use whitespace and ellipsis options | ||
2552 | 824 | optionflags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS | ||
2553 | 825 | |||
2554 | 826 | doctests = self.finder.find(obj, module=getmodule(parent)) | ||
2555 | 827 | if doctests: | ||
2556 | 828 | for test in doctests: | ||
2557 | 829 | if len(test.examples) == 0: | ||
2558 | 830 | continue | ||
2559 | 831 | |||
2560 | 832 | yield DocTestCase(test, obj=obj, | ||
2561 | 833 | optionflags=optionflags, | ||
2562 | 834 | checker=self.checker) | ||
2563 | 794 | 835 | ||
2564 | 795 | def configure(self, options, config): | 836 | def configure(self, options, config): |
2565 | 796 | 837 | ||
2566 | 797 | 838 | ||
2567 | === added file 'IPython/tests/tclass.py' | |||
2568 | --- IPython/tests/tclass.py 1970-01-01 00:00:00 +0000 | |||
2569 | +++ IPython/tests/tclass.py 2009-03-13 17:56:19 +0000 | |||
2570 | @@ -0,0 +1,26 @@ | |||
2571 | 1 | """Simple script to instantiate a class for testing %run""" | ||
2572 | 2 | |||
2573 | 3 | import sys | ||
2574 | 4 | |||
2575 | 5 | # An external test will check that calls to f() work after %run | ||
2576 | 6 | class foo: pass | ||
2577 | 7 | |||
2578 | 8 | def f(): | ||
2579 | 9 | return foo() | ||
2580 | 10 | |||
2581 | 11 | # We also want to ensure that while objects remain available for immediate | ||
2582 | 12 | # access, objects from *previous* runs of the same script get collected, to | ||
2583 | 13 | # avoid accumulating massive amounts of old references. | ||
2584 | 14 | class C(object): | ||
2585 | 15 | def __init__(self,name): | ||
2586 | 16 | self.name = name | ||
2587 | 17 | |||
2588 | 18 | def __del__(self): | ||
2589 | 19 | print 'Deleting object:',self.name | ||
2590 | 20 | |||
2591 | 21 | try: | ||
2592 | 22 | name = sys.argv[1] | ||
2593 | 23 | except IndexError: | ||
2594 | 24 | pass | ||
2595 | 25 | else: | ||
2596 | 26 | c = C(name) | ||
2597 | 0 | 27 | ||
2598 | === modified file 'IPython/tests/test_magic.py' | |||
2599 | --- IPython/tests/test_magic.py 2008-09-17 19:01:11 +0000 | |||
2600 | +++ IPython/tests/test_magic.py 2009-03-13 17:56:19 +0000 | |||
2601 | @@ -1,8 +1,21 @@ | |||
2606 | 1 | """ Tests for various magic functions | 1 | """Tests for various magic functions. |
2607 | 2 | 2 | ||
2608 | 3 | Needs to be run by nose (to make ipython session available) | 3 | Needs to be run by nose (to make ipython session available). |
2605 | 4 | |||
2609 | 5 | """ | 4 | """ |
2610 | 5 | |||
2611 | 6 | # Standard library imports | ||
2612 | 7 | import os | ||
2613 | 8 | import sys | ||
2614 | 9 | |||
2615 | 10 | # Third-party imports | ||
2616 | 11 | import nose.tools as nt | ||
2617 | 12 | |||
2618 | 13 | # From our own code | ||
2619 | 14 | from IPython.testing import decorators as dec | ||
2620 | 15 | |||
2621 | 16 | #----------------------------------------------------------------------------- | ||
2622 | 17 | # Test functions begin | ||
2623 | 18 | |||
2624 | 6 | def test_rehashx(): | 19 | def test_rehashx(): |
2625 | 7 | # clear up everything | 20 | # clear up everything |
2626 | 8 | _ip.IP.alias_table.clear() | 21 | _ip.IP.alias_table.clear() |
2627 | @@ -19,3 +32,96 @@ | |||
2628 | 19 | # rehashx must fill up syscmdlist | 32 | # rehashx must fill up syscmdlist |
2629 | 20 | scoms = _ip.db['syscmdlist'] | 33 | scoms = _ip.db['syscmdlist'] |
2630 | 21 | assert len(scoms) > 10 | 34 | assert len(scoms) > 10 |
2631 | 35 | |||
2632 | 36 | |||
2633 | 37 | def doctest_run_ns(): | ||
2634 | 38 | """Classes declared %run scripts must be instantiable afterwards. | ||
2635 | 39 | |||
2636 | 40 | In [11]: run tclass | ||
2637 | 41 | |||
2638 | 42 | In [12]: isinstance(f(),foo) | ||
2639 | 43 | Out[12]: True | ||
2640 | 44 | """ | ||
2641 | 45 | |||
2642 | 46 | |||
2643 | 47 | def doctest_run_ns2(): | ||
2644 | 48 | """Classes declared %run scripts must be instantiable afterwards. | ||
2645 | 49 | |||
2646 | 50 | In [3]: run tclass.py | ||
2647 | 51 | |||
2648 | 52 | In [4]: run tclass first_pass | ||
2649 | 53 | |||
2650 | 54 | In [5]: run tclass second_pass | ||
2651 | 55 | Deleting object: first_pass | ||
2652 | 56 | """ | ||
2653 | 57 | |||
2654 | 58 | |||
2655 | 59 | def doctest_hist_f(): | ||
2656 | 60 | """Test %hist -f with temporary filename. | ||
2657 | 61 | |||
2658 | 62 | In [9]: import tempfile | ||
2659 | 63 | |||
2660 | 64 | In [10]: tfile = tempfile.mktemp('.py','tmp-ipython-') | ||
2661 | 65 | |||
2662 | 66 | In [11]: %history -n -f $tfile 3 | ||
2663 | 67 | """ | ||
2664 | 68 | |||
2665 | 69 | |||
2666 | 70 | def doctest_hist_r(): | ||
2667 | 71 | """Test %hist -r | ||
2668 | 72 | |||
2669 | 73 | XXX - This test is not recording the output correctly. Not sure why... | ||
2670 | 74 | |||
2671 | 75 | In [6]: x=1 | ||
2672 | 76 | |||
2673 | 77 | In [7]: hist -n -r 2 | ||
2674 | 78 | x=1 # random | ||
2675 | 79 | hist -n -r 2 # random | ||
2676 | 80 | """ | ||
2677 | 81 | |||
2678 | 82 | |||
2679 | 83 | def test_shist(): | ||
2680 | 84 | # Simple tests of ShadowHist class - test generator. | ||
2681 | 85 | import os, shutil, tempfile | ||
2682 | 86 | |||
2683 | 87 | from IPython.Extensions import pickleshare | ||
2684 | 88 | from IPython.history import ShadowHist | ||
2685 | 89 | |||
2686 | 90 | tfile = tempfile.mktemp('','tmp-ipython-') | ||
2687 | 91 | |||
2688 | 92 | db = pickleshare.PickleShareDB(tfile) | ||
2689 | 93 | s = ShadowHist(db) | ||
2690 | 94 | s.add('hello') | ||
2691 | 95 | s.add('world') | ||
2692 | 96 | s.add('hello') | ||
2693 | 97 | s.add('hello') | ||
2694 | 98 | s.add('karhu') | ||
2695 | 99 | |||
2696 | 100 | yield nt.assert_equals,s.all(),[(1, 'hello'), (2, 'world'), (3, 'karhu')] | ||
2697 | 101 | |||
2698 | 102 | yield nt.assert_equal,s.get(2),'world' | ||
2699 | 103 | |||
2700 | 104 | shutil.rmtree(tfile) | ||
2701 | 105 | |||
2702 | 106 | @dec.skipif_not_numpy | ||
2703 | 107 | def test_numpy_clear_array_undec(): | ||
2704 | 108 | _ip.ex('import numpy as np') | ||
2705 | 109 | _ip.ex('a = np.empty(2)') | ||
2706 | 110 | |||
2707 | 111 | yield nt.assert_true,'a' in _ip.user_ns | ||
2708 | 112 | _ip.magic('clear array') | ||
2709 | 113 | yield nt.assert_false,'a' in _ip.user_ns | ||
2710 | 114 | |||
2711 | 115 | |||
2712 | 116 | @dec.skip() | ||
2713 | 117 | def test_fail_dec(*a,**k): | ||
2714 | 118 | yield nt.assert_true, False | ||
2715 | 119 | |||
2716 | 120 | @dec.skip('This one shouldn not run') | ||
2717 | 121 | def test_fail_dec2(*a,**k): | ||
2718 | 122 | yield nt.assert_true, False | ||
2719 | 123 | |||
2720 | 124 | @dec.skipknownfailure | ||
2721 | 125 | def test_fail_dec3(*a,**k): | ||
2722 | 126 | yield nt.assert_true, False | ||
2723 | 127 | |||
2724 | 22 | 128 | ||
2725 | === modified file 'IPython/twshell.py' | |||
2726 | --- IPython/twshell.py 2008-04-26 07:17:18 +0000 | |||
2727 | +++ IPython/twshell.py 2009-03-11 06:53:19 +0000 | |||
2728 | @@ -1,3 +1,7 @@ | |||
2729 | 1 | """Twisted shell support. | ||
2730 | 2 | |||
2731 | 3 | XXX - This module is missing proper docs. | ||
2732 | 4 | """ | ||
2733 | 1 | import sys | 5 | import sys |
2734 | 2 | 6 | ||
2735 | 3 | from twisted.internet import reactor, threads | 7 | from twisted.internet import reactor, threads |
2736 | 4 | 8 | ||
2737 | === modified file 'IPython/ultraTB.py' | |||
2738 | --- IPython/ultraTB.py 2008-08-24 06:10:55 +0000 | |||
2739 | +++ IPython/ultraTB.py 2009-03-11 06:53:19 +0000 | |||
2740 | @@ -59,8 +59,7 @@ | |||
2741 | 59 | You can implement other color schemes easily, the syntax is fairly | 59 | You can implement other color schemes easily, the syntax is fairly |
2742 | 60 | self-explanatory. Please send back new schemes you develop to the author for | 60 | self-explanatory. Please send back new schemes you develop to the author for |
2743 | 61 | possible inclusion in future releases. | 61 | possible inclusion in future releases. |
2746 | 62 | 62 | """ | |
2745 | 63 | $Id: ultraTB.py 2908 2007-12-30 21:07:46Z vivainio $""" | ||
2747 | 64 | 63 | ||
2748 | 65 | #***************************************************************************** | 64 | #***************************************************************************** |
2749 | 66 | # Copyright (C) 2001 Nathaniel Gray <n8gray@caltech.edu> | 65 | # Copyright (C) 2001 Nathaniel Gray <n8gray@caltech.edu> |
2750 | @@ -70,11 +69,6 @@ | |||
2751 | 70 | # the file COPYING, distributed as part of this software. | 69 | # the file COPYING, distributed as part of this software. |
2752 | 71 | #***************************************************************************** | 70 | #***************************************************************************** |
2753 | 72 | 71 | ||
2754 | 73 | from IPython import Release | ||
2755 | 74 | __author__ = '%s <%s>\n%s <%s>' % (Release.authors['Nathan']+ | ||
2756 | 75 | Release.authors['Fernando']) | ||
2757 | 76 | __license__ = Release.license | ||
2758 | 77 | |||
2759 | 78 | # Required modules | 72 | # Required modules |
2760 | 79 | import inspect | 73 | import inspect |
2761 | 80 | import keyword | 74 | import keyword |
2762 | @@ -98,7 +92,7 @@ | |||
2763 | 98 | # Modified pdb which doesn't damage IPython's readline handling | 92 | # Modified pdb which doesn't damage IPython's readline handling |
2764 | 99 | from IPython import Debugger, PyColorize | 93 | from IPython import Debugger, PyColorize |
2765 | 100 | from IPython.ipstruct import Struct | 94 | from IPython.ipstruct import Struct |
2767 | 101 | from IPython.excolors import ExceptionColors | 95 | from IPython.excolors import exception_colors |
2768 | 102 | from IPython.genutils import Term,uniq_stable,error,info | 96 | from IPython.genutils import Term,uniq_stable,error,info |
2769 | 103 | 97 | ||
2770 | 104 | # Globals | 98 | # Globals |
2771 | @@ -320,7 +314,7 @@ | |||
2772 | 320 | self.call_pdb = call_pdb | 314 | self.call_pdb = call_pdb |
2773 | 321 | 315 | ||
2774 | 322 | # Create color table | 316 | # Create color table |
2776 | 323 | self.color_scheme_table = ExceptionColors | 317 | self.color_scheme_table = exception_colors() |
2777 | 324 | 318 | ||
2778 | 325 | self.set_colors(color_scheme) | 319 | self.set_colors(color_scheme) |
2779 | 326 | self.old_scheme = color_scheme # save initial value for toggles | 320 | self.old_scheme = color_scheme # save initial value for toggles |
2780 | 327 | 321 | ||
2781 | === modified file 'IPython/usage.py' | |||
2782 | --- IPython/usage.py 2008-02-28 18:21:11 +0000 | |||
2783 | +++ IPython/usage.py 2009-03-11 06:53:19 +0000 | |||
2784 | @@ -6,13 +6,6 @@ | |||
2785 | 6 | # the file COPYING, distributed as part of this software. | 6 | # the file COPYING, distributed as part of this software. |
2786 | 7 | #***************************************************************************** | 7 | #***************************************************************************** |
2787 | 8 | 8 | ||
2788 | 9 | # $Id: usage.py 2723 2007-09-07 07:44:16Z fperez $ | ||
2789 | 10 | |||
2790 | 11 | from IPython import Release | ||
2791 | 12 | __author__ = '%s <%s>' % Release.authors['Fernando'] | ||
2792 | 13 | __license__ = Release.license | ||
2793 | 14 | __version__ = Release.version | ||
2794 | 15 | |||
2795 | 16 | __doc__ = """ | 9 | __doc__ = """ |
2796 | 17 | IPython -- An enhanced Interactive Python | 10 | IPython -- An enhanced Interactive Python |
2797 | 18 | ========================================= | 11 | ========================================= |
2798 | @@ -650,5 +643,3 @@ | |||
2799 | 650 | The following magic functions are currently available: | 643 | The following magic functions are currently available: |
2800 | 651 | 644 | ||
2801 | 652 | """ | 645 | """ |
2802 | 653 | |||
2803 | 654 | |||
2804 | 655 | 646 | ||
2805 | === modified file 'IPython/wildcard.py' | |||
2806 | --- IPython/wildcard.py 2008-02-16 09:50:47 +0000 | |||
2807 | +++ IPython/wildcard.py 2009-03-11 06:53:19 +0000 | |||
2808 | @@ -1,7 +1,5 @@ | |||
2809 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
2810 | 2 | """Support for wildcard pattern matching in object inspection. | 2 | """Support for wildcard pattern matching in object inspection. |
2811 | 3 | |||
2812 | 4 | $Id: OInspect.py 608 2005-07-06 17:52:32Z fperez $ | ||
2813 | 5 | """ | 3 | """ |
2814 | 6 | 4 | ||
2815 | 7 | #***************************************************************************** | 5 | #***************************************************************************** |
2816 | 8 | 6 | ||
2817 | === modified file 'docs/Makefile' | |||
2818 | --- docs/Makefile 2008-08-28 23:34:53 +0000 | |||
2819 | +++ docs/Makefile 2009-03-11 01:24:53 +0000 | |||
2820 | @@ -5,13 +5,14 @@ | |||
2821 | 5 | SPHINXOPTS = | 5 | SPHINXOPTS = |
2822 | 6 | SPHINXBUILD = sphinx-build | 6 | SPHINXBUILD = sphinx-build |
2823 | 7 | PAPER = | 7 | PAPER = |
2824 | 8 | SRCDIR = source | ||
2825 | 8 | 9 | ||
2826 | 9 | # Internal variables. | 10 | # Internal variables. |
2827 | 10 | PAPEROPT_a4 = -D latex_paper_size=a4 | 11 | PAPEROPT_a4 = -D latex_paper_size=a4 |
2828 | 11 | PAPEROPT_letter = -D latex_paper_size=letter | 12 | PAPEROPT_letter = -D latex_paper_size=letter |
2830 | 12 | ALLSPHINXOPTS = -d build/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source | 13 | ALLSPHINXOPTS = -d build/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) $(SRCDIR) |
2831 | 13 | 14 | ||
2833 | 14 | .PHONY: help clean html web pickle htmlhelp latex changes linkcheck | 15 | .PHONY: help clean html web pickle htmlhelp latex changes linkcheck api |
2834 | 15 | 16 | ||
2835 | 16 | help: | 17 | help: |
2836 | 17 | @echo "Please use \`make <target>' where <target> is one of" | 18 | @echo "Please use \`make <target>' where <target> is one of" |
2837 | @@ -28,7 +29,7 @@ | |||
2838 | 28 | @echo "dist all, and then puts the results in dist/" | 29 | @echo "dist all, and then puts the results in dist/" |
2839 | 29 | 30 | ||
2840 | 30 | clean: | 31 | clean: |
2842 | 31 | -rm -rf build/* dist/* | 32 | -rm -rf build/* dist/* $(SRCDIR)/api/generated |
2843 | 32 | 33 | ||
2844 | 33 | pdf: latex | 34 | pdf: latex |
2845 | 34 | cd build/latex && make all-pdf | 35 | cd build/latex && make all-pdf |
2846 | @@ -41,12 +42,16 @@ | |||
2847 | 41 | cp -al build/html dist/ | 42 | cp -al build/html dist/ |
2848 | 42 | @echo "Build finished. Final docs are in dist/" | 43 | @echo "Build finished. Final docs are in dist/" |
2849 | 43 | 44 | ||
2851 | 44 | html: | 45 | html: api |
2852 | 45 | mkdir -p build/html build/doctrees | 46 | mkdir -p build/html build/doctrees |
2853 | 46 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) build/html | 47 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) build/html |
2854 | 47 | @echo | 48 | @echo |
2855 | 48 | @echo "Build finished. The HTML pages are in build/html." | 49 | @echo "Build finished. The HTML pages are in build/html." |
2856 | 49 | 50 | ||
2857 | 51 | api: | ||
2858 | 52 | python autogen_api.py | ||
2859 | 53 | @echo "Build API docs finished." | ||
2860 | 54 | |||
2861 | 50 | pickle: | 55 | pickle: |
2862 | 51 | mkdir -p build/pickle build/doctrees | 56 | mkdir -p build/pickle build/doctrees |
2863 | 52 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) build/pickle | 57 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) build/pickle |
2864 | 53 | 58 | ||
2865 | === added file 'docs/autogen_api.py' | |||
2866 | --- docs/autogen_api.py 1970-01-01 00:00:00 +0000 | |||
2867 | +++ docs/autogen_api.py 2009-03-11 01:24:53 +0000 | |||
2868 | @@ -0,0 +1,33 @@ | |||
2869 | 1 | #!/usr/bin/env python | ||
2870 | 2 | """Script to auto-generate our API docs. | ||
2871 | 3 | """ | ||
2872 | 4 | # stdlib imports | ||
2873 | 5 | import os | ||
2874 | 6 | import sys | ||
2875 | 7 | |||
2876 | 8 | # local imports | ||
2877 | 9 | sys.path.append(os.path.abspath('sphinxext')) | ||
2878 | 10 | from apigen import ApiDocWriter | ||
2879 | 11 | |||
2880 | 12 | #***************************************************************************** | ||
2881 | 13 | if __name__ == '__main__': | ||
2882 | 14 | pjoin = os.path.join | ||
2883 | 15 | package = 'IPython' | ||
2884 | 16 | outdir = pjoin('source','api','generated') | ||
2885 | 17 | docwriter = ApiDocWriter(package,rst_extension='.txt') | ||
2886 | 18 | docwriter.package_skip_patterns += [r'\.fixes$', | ||
2887 | 19 | r'\.externals$', | ||
2888 | 20 | r'\.Extensions', | ||
2889 | 21 | r'\.kernel.config', | ||
2890 | 22 | r'\.attic', | ||
2891 | 23 | ] | ||
2892 | 24 | docwriter.module_skip_patterns += [ r'\.FakeModule', | ||
2893 | 25 | r'\.cocoa', | ||
2894 | 26 | r'\.ipdoctest', | ||
2895 | 27 | r'\.Gnuplot', | ||
2896 | 28 | ] | ||
2897 | 29 | docwriter.write_api_docs(outdir) | ||
2898 | 30 | docwriter.write_index(outdir, 'gen', | ||
2899 | 31 | relative_to = pjoin('source','api') | ||
2900 | 32 | ) | ||
2901 | 33 | print '%d files written' % len(docwriter.written_modules) | ||
2902 | 0 | 34 | ||
2903 | === added directory 'docs/source/api' | |||
2904 | === added file 'docs/source/api/index.txt' | |||
2905 | --- docs/source/api/index.txt 1970-01-01 00:00:00 +0000 | |||
2906 | +++ docs/source/api/index.txt 2009-03-11 01:24:53 +0000 | |||
2907 | @@ -0,0 +1,12 @@ | |||
2908 | 1 | .. _api-index: | ||
2909 | 2 | |||
2910 | 3 | ################### | ||
2911 | 4 | The IPython API | ||
2912 | 5 | ################### | ||
2913 | 6 | |||
2914 | 7 | .. htmlonly:: | ||
2915 | 8 | |||
2916 | 9 | :Release: |version| | ||
2917 | 10 | :Date: |today| | ||
2918 | 11 | |||
2919 | 12 | .. include:: generated/gen.txt | ||
2920 | 0 | 13 | ||
2921 | === modified file 'docs/source/conf.py' | |||
2922 | --- docs/source/conf.py 2008-09-14 07:58:49 +0000 | |||
2923 | +++ docs/source/conf.py 2009-03-11 01:24:53 +0000 | |||
2924 | @@ -36,9 +36,13 @@ | |||
2925 | 36 | # Add any Sphinx extension module names here, as strings. They can be extensions | 36 | # Add any Sphinx extension module names here, as strings. They can be extensions |
2926 | 37 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. | 37 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. |
2927 | 38 | extensions = ['sphinx.ext.autodoc', | 38 | extensions = ['sphinx.ext.autodoc', |
2929 | 39 | 'inheritance_diagram', 'only_directives', | 39 | 'sphinx.ext.doctest', |
2930 | 40 | |||
2931 | 41 | 'only_directives', | ||
2932 | 42 | 'inheritance_diagram', | ||
2933 | 40 | 'ipython_console_highlighting', | 43 | 'ipython_console_highlighting', |
2934 | 41 | # 'plot_directive', # disabled for now, needs matplotlib | 44 | # 'plot_directive', # disabled for now, needs matplotlib |
2935 | 45 | 'numpydoc', # to preprocess docstrings | ||
2936 | 42 | ] | 46 | ] |
2937 | 43 | 47 | ||
2938 | 44 | # Add any paths that contain templates here, relative to this directory. | 48 | # Add any paths that contain templates here, relative to this directory. |
2939 | 45 | 49 | ||
2940 | === added file 'docs/source/development/coding_guide.txt' | |||
2941 | --- docs/source/development/coding_guide.txt 1970-01-01 00:00:00 +0000 | |||
2942 | +++ docs/source/development/coding_guide.txt 2008-10-04 07:47:34 +0000 | |||
2943 | @@ -0,0 +1,141 @@ | |||
2944 | 1 | ============== | ||
2945 | 2 | Coding guide | ||
2946 | 3 | ============== | ||
2947 | 4 | |||
2948 | 5 | |||
2949 | 6 | Coding conventions | ||
2950 | 7 | ================== | ||
2951 | 8 | |||
2952 | 9 | In general, we'll try to follow the standard Python style conventions as | ||
2953 | 10 | described in Python's `PEP 8`_, the official Python Style Guide. | ||
2954 | 11 | |||
2955 | 12 | .. _PEP 8: http://www.python.org/peps/pep-0008.html | ||
2956 | 13 | |||
2957 | 14 | Other comments: | ||
2958 | 15 | |||
2959 | 16 | - In a large file, top level classes and functions should be separated by 2-3 | ||
2960 | 17 | lines to make it easier to separate them visually. | ||
2961 | 18 | |||
2962 | 19 | - Use 4 spaces for indentation, *never* use hard tabs. | ||
2963 | 20 | |||
2964 | 21 | - Keep the ordering of methods the same in classes that have the same methods. | ||
2965 | 22 | This is particularly true for classes that implement similar interfaces and | ||
2966 | 23 | for interfaces that are similar. | ||
2967 | 24 | |||
2968 | 25 | Naming conventions | ||
2969 | 26 | ------------------ | ||
2970 | 27 | |||
2971 | 28 | In terms of naming conventions, we'll follow the guidelines of PEP 8. Some of | ||
2972 | 29 | the existing code doesn't honor this perfectly, but for all new IPython code | ||
2973 | 30 | (and much existing code is being refactored), we'll use: | ||
2974 | 31 | |||
2975 | 32 | - All ``lowercase`` module names. | ||
2976 | 33 | |||
2977 | 34 | - ``CamelCase`` for class names. | ||
2978 | 35 | |||
2979 | 36 | - ``lowercase_with_underscores`` for methods, functions, variables and | ||
2980 | 37 | attributes. | ||
2981 | 38 | |||
2982 | 39 | This may be confusing as some of the existing codebase uses a different | ||
2983 | 40 | convention (``lowerCamelCase`` for methods and attributes). Slowly, we will | ||
2984 | 41 | move IPython over to the new convention, providing shadow names for backward | ||
2985 | 42 | compatibility in public interfaces. | ||
2986 | 43 | |||
2987 | 44 | There are, however, some important exceptions to these rules. In some cases, | ||
2988 | 45 | IPython code will interface with packages (Twisted, Wx, Qt) that use other | ||
2989 | 46 | conventions. At some level this makes it impossible to adhere to our own | ||
2990 | 47 | standards at all times. In particular, when subclassing classes that use other | ||
2991 | 48 | naming conventions, you must follow their naming conventions. To deal with | ||
2992 | 49 | cases like this, we propose the following policy: | ||
2993 | 50 | |||
2994 | 51 | - If you are subclassing a class that uses different conventions, use its | ||
2995 | 52 | naming conventions throughout your subclass. Thus, if you are creating a | ||
2996 | 53 | Twisted Protocol class, used Twisted's | ||
2997 | 54 | ``namingSchemeForMethodsAndAttributes.`` | ||
2998 | 55 | |||
2999 | 56 | - All IPython's official interfaces should use our conventions. In some cases | ||
3000 | 57 | this will mean that you need to provide shadow names (first implement | ||
3001 | 58 | ``fooBar`` and then ``foo_bar = fooBar``). We want to avoid this at all | ||
3002 | 59 | costs, but it will probably be necessary at times. But, please use this | ||
3003 | 60 | sparingly! | ||
3004 | 61 | |||
3005 | 62 | Implementation-specific *private* methods will use | ||
3006 | 63 | ``_single_underscore_prefix``. Names with a leading double underscore will | ||
3007 | 64 | *only* be used in special cases, as they makes subclassing difficult (such | ||
3008 | 65 | names are not easily seen by child classes). | ||
3009 | 66 | |||
3010 | 67 | Occasionally some run-in lowercase names are used, but mostly for very short | ||
3011 | 68 | names or where we are implementing methods very similar to existing ones in a | ||
3012 | 69 | base class (like ``runlines()`` where ``runsource()`` and ``runcode()`` had | ||
3013 | 70 | established precedent). | ||
3014 | 71 | |||
3015 | 72 | The old IPython codebase has a big mix of classes and modules prefixed with an | ||
3016 | 73 | explicit ``IP``. In Python this is mostly unnecessary, redundant and frowned | ||
3017 | 74 | upon, as namespaces offer cleaner prefixing. The only case where this approach | ||
3018 | 75 | is justified is for classes which are expected to be imported into external | ||
3019 | 76 | namespaces and a very generic name (like Shell) is too likely to clash with | ||
3020 | 77 | something else. We'll need to revisit this issue as we clean up and refactor | ||
3021 | 78 | the code, but in general we should remove as many unnecessary ``IP``/``ip`` | ||
3022 | 79 | prefixes as possible. However, if a prefix seems absolutely necessary the more | ||
3023 | 80 | specific ``IPY`` or ``ipy`` are preferred. | ||
3024 | 81 | |||
3025 | 82 | |||
3026 | 83 | .. _devel-testing: | ||
3027 | 84 | |||
3028 | 85 | Testing system | ||
3029 | 86 | ============== | ||
3030 | 87 | |||
3031 | 88 | It is extremely important that all code contributed to IPython has tests. Tests | ||
3032 | 89 | should be written as unittests, doctests or as entities that the `Nose`_ | ||
3033 | 90 | testing package will find. Regardless of how the tests are written, we will use | ||
3034 | 91 | `Nose`_ for discovering and running the tests. `Nose`_ will be required to run | ||
3035 | 92 | the IPython test suite, but will not be required to simply use IPython. | ||
3036 | 93 | |||
3037 | 94 | .. _Nose: http://code.google.com/p/python-nose/ | ||
3038 | 95 | |||
3039 | 96 | Tests of `Twisted`__ using code should be written by subclassing the | ||
3040 | 97 | ``TestCase`` class that comes with ``twisted.trial.unittest``. When this is | ||
3041 | 98 | done, `Nose`_ will be able to run the tests and the twisted reactor will be | ||
3042 | 99 | handled correctly. | ||
3043 | 100 | |||
3044 | 101 | .. __: http://www.twistedmatrix.com | ||
3045 | 102 | |||
3046 | 103 | Each subpackage in IPython should have its own ``tests`` directory that | ||
3047 | 104 | contains all of the tests for that subpackage. This allows each subpackage to | ||
3048 | 105 | be self-contained. If a subpackage has any dependencies beyond the Python | ||
3049 | 106 | standard library, the tests for that subpackage should be skipped if the | ||
3050 | 107 | dependencies are not found. This is very important so users don't get tests | ||
3051 | 108 | failing simply because they don't have dependencies. | ||
3052 | 109 | |||
3053 | 110 | We also need to look into use Noses ability to tag tests to allow a more | ||
3054 | 111 | modular approach of running tests. | ||
3055 | 112 | |||
3056 | 113 | .. _devel-config: | ||
3057 | 114 | |||
3058 | 115 | Configuration system | ||
3059 | 116 | ==================== | ||
3060 | 117 | |||
3061 | 118 | IPython uses `.ini`_ files for configuration purposes. This represents a huge | ||
3062 | 119 | improvement over the configuration system used in IPython. IPython works with | ||
3063 | 120 | these files using the `ConfigObj`_ package, which IPython includes as | ||
3064 | 121 | ``ipython1/external/configobj.py``. | ||
3065 | 122 | |||
3066 | 123 | Currently, we are using raw `ConfigObj`_ objects themselves. Each subpackage of | ||
3067 | 124 | IPython should contain a ``config`` subdirectory that contains all of the | ||
3068 | 125 | configuration information for the subpackage. To see how configuration | ||
3069 | 126 | information is defined (along with defaults) see at the examples in | ||
3070 | 127 | ``ipython1/kernel/config`` and ``ipython1/core/config``. Likewise, to see how | ||
3071 | 128 | the configuration information is used, see examples in | ||
3072 | 129 | ``ipython1/kernel/scripts/ipengine.py``. | ||
3073 | 130 | |||
3074 | 131 | Eventually, we will add a new layer on top of the raw `ConfigObj`_ objects. We | ||
3075 | 132 | are calling this new layer, ``tconfig``, as it will use a `Traits`_-like | ||
3076 | 133 | validation model. We won't actually use `Traits`_, but will implement | ||
3077 | 134 | something similar in pure Python. But, even in this new system, we will still | ||
3078 | 135 | use `ConfigObj`_ and `.ini`_ files underneath the hood. Talk to Fernando if you | ||
3079 | 136 | are interested in working on this part of IPython. The current prototype of | ||
3080 | 137 | ``tconfig`` is located in the IPython sandbox. | ||
3081 | 138 | |||
3082 | 139 | .. _.ini: http://docs.python.org/lib/module-ConfigParser.html | ||
3083 | 140 | .. _ConfigObj: http://www.voidspace.org.uk/python/configobj.html | ||
3084 | 141 | .. _Traits: http://code.enthought.com/traits/ | ||
3085 | 0 | 142 | ||
3086 | === added file 'docs/source/development/doc_guide.txt' | |||
3087 | --- docs/source/development/doc_guide.txt 1970-01-01 00:00:00 +0000 | |||
3088 | +++ docs/source/development/doc_guide.txt 2009-03-11 06:58:43 +0000 | |||
3089 | @@ -0,0 +1,103 @@ | |||
3090 | 1 | .. _documenting-ipython: | ||
3091 | 2 | |||
3092 | 3 | ===================== | ||
3093 | 4 | Documenting IPython | ||
3094 | 5 | ===================== | ||
3095 | 6 | |||
3096 | 7 | Standalone documentation | ||
3097 | 8 | ======================== | ||
3098 | 9 | |||
3099 | 10 | All standalone documentation should be written in plain text (``.txt``) files | ||
3100 | 11 | using `reStructuredText`_ for markup and formatting. All such documentation | ||
3101 | 12 | should be placed in the top level directory ``docs`` of the IPython source | ||
3102 | 13 | tree. Or, when appropriate, a suitably named subdirectory should be used. The | ||
3103 | 14 | documentation in this location will serve as the main source for IPython | ||
3104 | 15 | documentation and all existing documentation should be converted to this | ||
3105 | 16 | format. | ||
3106 | 17 | |||
3107 | 18 | The actual HTML and PDF docs are built using the Sphinx_ documentation | ||
3108 | 19 | generation tool. Sphinx has been adopted as the default documentation tool for | ||
3109 | 20 | Python itself as of version 2.6, as well as by a number of projects that | ||
3110 | 21 | IPython is related with, such as numpy, scipy, matplotlib, sage and nipy. | ||
3111 | 22 | |||
3112 | 23 | .. _reStructuredText: http://docutils.sourceforge.net/rst.html | ||
3113 | 24 | .. _Sphinx: http://sphinx.pocoo.org/ | ||
3114 | 25 | |||
3115 | 26 | |||
3116 | 27 | The rest of this document is mostly taken from the `matploblib | ||
3117 | 28 | documentation`__; we are using a number of Sphinx tools and extensions written | ||
3118 | 29 | by the matplotlib team and will mostly follow their conventions, which are | ||
3119 | 30 | nicely spelled out in their guide. What follows is thus a lightly adapted | ||
3120 | 31 | version of the matplotlib documentation guide, taken with permission from the | ||
3121 | 32 | MPL team. | ||
3122 | 33 | |||
3123 | 34 | .. __: http://matplotlib.sourceforge.net/devel/documenting_mpl.html | ||
3124 | 35 | |||
3125 | 36 | |||
3126 | 37 | A bit of Python code:: | ||
3127 | 38 | |||
3128 | 39 | for i in range(10): | ||
3129 | 40 | print i, | ||
3130 | 41 | print "A big number:",2**34 | ||
3131 | 42 | |||
3132 | 43 | An interactive Python session:: | ||
3133 | 44 | |||
3134 | 45 | >>> from IPython import genutils | ||
3135 | 46 | >>> genutils.get_ipython_dir() | ||
3136 | 47 | '/home/fperez/.ipython' | ||
3137 | 48 | |||
3138 | 49 | |||
3139 | 50 | An IPython session: | ||
3140 | 51 | |||
3141 | 52 | .. code-block:: ipython | ||
3142 | 53 | |||
3143 | 54 | In [7]: import IPython | ||
3144 | 55 | |||
3145 | 56 | In [8]: print "This IPython is version:",IPython.__version__ | ||
3146 | 57 | This IPython is version: 0.9.1 | ||
3147 | 58 | |||
3148 | 59 | In [9]: 2+4 | ||
3149 | 60 | Out[9]: 6 | ||
3150 | 61 | |||
3151 | 62 | |||
3152 | 63 | A bit of shell code: | ||
3153 | 64 | |||
3154 | 65 | .. code-block:: bash | ||
3155 | 66 | |||
3156 | 67 | cd /tmp | ||
3157 | 68 | echo "My home directory is: $HOME" | ||
3158 | 69 | ls | ||
3159 | 70 | |||
3160 | 71 | |||
3161 | 72 | Docstring format | ||
3162 | 73 | ================ | ||
3163 | 74 | |||
3164 | 75 | Good docstrings are very important. Unfortunately, Python itself only provides | ||
3165 | 76 | a rather loose standard for docstrings (`PEP 257`_), and there is no universally | ||
3166 | 77 | accepted convention for all the different parts of a complete docstring. | ||
3167 | 78 | However, the NumPy project has established a very reasonable standard, and has | ||
3168 | 79 | developed some tools to support the smooth inclusion of such docstrings in | ||
3169 | 80 | Sphinx-generated manuals. Rather than inventing yet another pseudo-standard, | ||
3170 | 81 | IPython will be henceforth documented using the NumPy conventions; we carry | ||
3171 | 82 | copies of some of the NumPy support tools to remain self-contained, but share | ||
3172 | 83 | back upstream with NumPy any improvements or fixes we may make to the tools. | ||
3173 | 84 | |||
3174 | 85 | The `NumPy documentation guidelines`_ contain detailed information on this | ||
3175 | 86 | standard, and for a quick overview, the NumPy `example docstring`_ is a useful | ||
3176 | 87 | read. | ||
3177 | 88 | |||
3178 | 89 | As in the past IPython used epydoc, currently many docstrings still use epydoc | ||
3179 | 90 | conventions. We will update them as we go, but all new code should be fully | ||
3180 | 91 | documented using the NumPy standard. | ||
3181 | 92 | |||
3182 | 93 | .. _PEP 257: http://www.python.org/peps/pep-0257.html | ||
3183 | 94 | .. _NumPy documentation guidelines: http://projects.scipy.org/numpy/wiki/CodingStyleGuidelines | ||
3184 | 95 | |||
3185 | 96 | .. _example docstring: http://projects.scipy.org/numpy/browser/trunk/doc/EXAMPLE_DOCSTRING.txt | ||
3186 | 97 | |||
3187 | 98 | Additional PEPs of interest regarding documentation of code. While both of | ||
3188 | 99 | these were rejected, the ideas therein form much of the basis of docutils (the | ||
3189 | 100 | machinery to process reStructuredText): | ||
3190 | 101 | |||
3191 | 102 | - `Docstring Processing System Framework <http://www.python.org/peps/pep-0256.html>`_ | ||
3192 | 103 | - `Docutils Design Specification <http://www.python.org/peps/pep-0258.html>`_ | ||
3193 | 0 | 104 | ||
3194 | === modified file 'docs/source/development/index.txt' | |||
3195 | --- docs/source/development/index.txt 2008-09-11 23:58:46 +0000 | |||
3196 | +++ docs/source/development/index.txt 2008-10-04 07:47:34 +0000 | |||
3197 | @@ -1,10 +1,13 @@ | |||
3201 | 1 | ================== | 1 | =========================== |
3202 | 2 | Development | 2 | IPython Developer's Guide |
3203 | 3 | ================== | 3 | =========================== |
3204 | 4 | 4 | ||
3205 | 5 | .. toctree:: | 5 | .. toctree:: |
3206 | 6 | :maxdepth: 2 | 6 | :maxdepth: 2 |
3207 | 7 | 7 | ||
3209 | 8 | development.txt | 8 | overview.txt |
3210 | 9 | coding_guide.txt | ||
3211 | 10 | doc_guide.txt | ||
3212 | 9 | roadmap.txt | 11 | roadmap.txt |
3213 | 12 | |||
3214 | 10 | notification_blueprint.txt | 13 | notification_blueprint.txt |
3215 | 11 | 14 | ||
3216 | === renamed file 'docs/source/development/development.txt' => 'docs/source/development/overview.txt' | |||
3217 | --- docs/source/development/development.txt 2008-09-15 03:37:13 +0000 | |||
3218 | +++ docs/source/development/overview.txt 2008-10-04 07:47:34 +0000 | |||
3219 | @@ -1,32 +1,35 @@ | |||
3220 | 1 | .. This file has a lot of bash but little python, set default role | ||
3221 | 2 | |||
3222 | 3 | .. highlight:: bash | ||
3223 | 4 | |||
3224 | 1 | .. _development: | 5 | .. _development: |
3225 | 2 | 6 | ||
3226 | 3 | ============================== | 7 | ============================== |
3228 | 4 | IPython development guidelines | 8 | IPython development overview |
3229 | 5 | ============================== | 9 | ============================== |
3230 | 6 | 10 | ||
3243 | 7 | 11 | Currently, IPython's development tree contains all of the code that used to be | |
3244 | 8 | Overview | 12 | part of IPython since the project's inception in 2001, plus all of the effort |
3245 | 9 | ======== | 13 | that was known for a while (roughly 2004-2008) as ``IPython1``. The IPyhton1 |
3246 | 10 | 14 | development was meant to be an effort to: | |
3235 | 11 | IPython is the next generation of IPython. It is named such for two reasons: | ||
3236 | 12 | |||
3237 | 13 | - Eventually, IPython will become IPython version 1.0. | ||
3238 | 14 | - This new code base needs to be able to co-exist with the existing IPython until | ||
3239 | 15 | it is a full replacement for it. Thus we needed a different name. We couldn't | ||
3240 | 16 | use ``ipython`` (lowercase) as some files systems are case insensitive. | ||
3241 | 17 | |||
3242 | 18 | There are two, no three, main goals of the IPython effort: | ||
3247 | 19 | 15 | ||
3248 | 20 | 1. Clean up the existing codebase and write lots of tests. | 16 | 1. Clean up the existing codebase and write lots of tests. |
3251 | 21 | 2. Separate the core functionality of IPython from the terminal to enable IPython | 17 | |
3252 | 22 | to be used from within a variety of GUI applications. | 18 | 2. Separate the core functionality of IPython from the terminal to enable |
3253 | 19 | IPython to be used from within a variety of GUI applications. | ||
3254 | 20 | |||
3255 | 23 | 3. Implement a system for interactive parallel computing. | 21 | 3. Implement a system for interactive parallel computing. |
3256 | 24 | 22 | ||
3257 | 25 | While the third goal may seem a bit unrelated to the main focus of IPython, it | 23 | While the third goal may seem a bit unrelated to the main focus of IPython, it |
3258 | 26 | turns out that the technologies required for this goal are nearly identical | 24 | turns out that the technologies required for this goal are nearly identical |
3259 | 27 | with those required for goal two. This is the main reason the interactive | 25 | with those required for goal two. This is the main reason the interactive |
3262 | 28 | parallel computing capabilities are being put into IPython proper. Currently | 26 | parallel computing capabilities are being put into IPython proper. |
3263 | 29 | the third of these goals is furthest along. | 27 | |
3264 | 28 | In the summer of 2008, the IPython1 code was merged back into the mainline, and | ||
3265 | 29 | now there is a unified codebase. While the above goals aren't completely | ||
3266 | 30 | implemented for the older code, we do have a proper :ref:`testing system | ||
3267 | 31 | <devel-testing>` in place (though this is still evolving), unified | ||
3268 | 32 | documentation and partial implementations of the more separated components. | ||
3269 | 30 | 33 | ||
3270 | 31 | This document describes IPython from the perspective of developers. | 34 | This document describes IPython from the perspective of developers. |
3271 | 32 | 35 | ||
3272 | @@ -46,16 +49,19 @@ | |||
3273 | 46 | 49 | ||
3274 | 47 | - **Tests**. Each subpackage shoud have its own ``tests`` subdirectory that | 50 | - **Tests**. Each subpackage shoud have its own ``tests`` subdirectory that |
3275 | 48 | contains all of the tests for that package. For information about writing | 51 | contains all of the tests for that package. For information about writing |
3277 | 49 | tests for IPython, see the `Testing System`_ section of this document. | 52 | tests for IPython, see the :ref:`Testing System <devel-testing>` section of |
3278 | 53 | this document. | ||
3279 | 50 | 54 | ||
3280 | 51 | - **Configuration**. Each subpackage should have its own ``config`` | 55 | - **Configuration**. Each subpackage should have its own ``config`` |
3281 | 52 | subdirectory that contains the configuration information for the components | 56 | subdirectory that contains the configuration information for the components |
3282 | 53 | of the subpackage. For information about how the IPython configuration | 57 | of the subpackage. For information about how the IPython configuration |
3284 | 54 | system works, see the `Configuration System`_ section of this document. | 58 | system works, see the :ref:`Configuration System <devel-config>` section of |
3285 | 59 | this document. | ||
3286 | 55 | 60 | ||
3287 | 56 | - **Scripts**. Each subpackage should have its own ``scripts`` subdirectory | 61 | - **Scripts**. Each subpackage should have its own ``scripts`` subdirectory |
3288 | 57 | that contains all of the command line scripts associated with the subpackage. | 62 | that contains all of the command line scripts associated with the subpackage. |
3289 | 58 | 63 | ||
3290 | 64 | |||
3291 | 59 | Installation and dependencies | 65 | Installation and dependencies |
3292 | 60 | ----------------------------- | 66 | ----------------------------- |
3293 | 61 | 67 | ||
3294 | @@ -117,266 +123,132 @@ | |||
3295 | 117 | today 's IPython. Other frontends will likely be more powerful and based | 123 | today 's IPython. Other frontends will likely be more powerful and based |
3296 | 118 | on GUI toolkits. | 124 | on GUI toolkits. |
3297 | 119 | 125 | ||
3298 | 120 | ``notebook`` | ||
3299 | 121 | An application that allows users to work with IPython notebooks. | ||
3300 | 122 | |||
3301 | 123 | ``tools`` | 126 | ``tools`` |
3302 | 124 | This is where general utilities go. | 127 | This is where general utilities go. |
3303 | 125 | 128 | ||
3304 | 126 | 129 | ||
3326 | 127 | Version control | 130 | Version control workflow |
3327 | 128 | =============== | 131 | ======================== |
3328 | 129 | 132 | ||
3329 | 130 | In the past, IPython development has been done using `Subversion`__. Recently, | 133 | All IPython development today is done using the `Bazaar`__ system for |
3330 | 131 | we made the transition to using `Bazaar`__ and `Launchpad`__. This makes it | 134 | distributed version control and the `Launchpad`__ site for code hosting and bug |
3331 | 132 | much easier for people to contribute code to IPython. Here is a sketch of how | 135 | tracking. This makes it very easy for anyone to contribute code to IPython. |
3332 | 133 | to use Bazaar for IPython development. First, you should install Bazaar. | 136 | |
3333 | 134 | After you have done that, make sure that it is working by getting the latest | 137 | .. __: http://bazaar-vcs.org |
3334 | 135 | main branch of IPython:: | 138 | .. __: http://launchpad.net/ipython |
3335 | 136 | 139 | ||
3336 | 137 | $ bzr branch lp:ipython | 140 | If you are interested in contributing to IPython, you should familiarize a bit |
3337 | 138 | 141 | with how to use bazaar, but this document gives you a concise set of steps to | |
3338 | 139 | Now you can create a new branch for you to do your work in:: | 142 | get started. If you are going to become heavily involved with creating code |
3339 | 140 | 143 | for IPython you'll eventually want to have a Launchpad account (free) so you | |
3340 | 141 | $ bzr branch ipython ipython-mybranch | 144 | can publish your own code on the site for review and merging, but small |
3341 | 142 | 145 | contributions can be simply sent via email to the IPython list as patches. | |
3342 | 143 | The typical work cycle in this branch will be to make changes in | 146 | |
3343 | 144 | ``ipython-mybranch`` and then commit those changes using the commit command:: | 147 | Start by creating what Bazaar calls a `shared repository`_:: |
3344 | 145 | 148 | ||
3345 | 146 | $ ...do work in ipython-mybranch... | 149 | # You can choose any name you want instead of "ipython-repo" |
3346 | 147 | $ bzr ci -m "the commit message goes here" | 150 | bzr init-repo ipython-repo |
3347 | 151 | |||
3348 | 152 | .. _shared repository: http://bazaar-vcs.org/SharedRepositoryTutorial | ||
3349 | 153 | |||
3350 | 154 | This creates an empty repository where a lot of related branches can be kept, | ||
3351 | 155 | and they all reuse common storage. This way, many operations are very fast and | ||
3352 | 156 | take up less space. Now, go to the newly created repository and make a local | ||
3353 | 157 | branch of the public trunk:: | ||
3354 | 158 | |||
3355 | 159 | cd ipython-repo | ||
3356 | 160 | # This makes a local copy of the public trunk called "trunk-lp" | ||
3357 | 161 | bzr branch lp:ipython trunk-lp | ||
3358 | 162 | |||
3359 | 163 | The ``trunk-lp`` branch is meant to always be a pristine copy of the public | ||
3360 | 164 | trunk. From here, make a personal development copy of the public trunk, where | ||
3361 | 165 | you'll make your changes:: | ||
3362 | 166 | |||
3363 | 167 | bzr branch trunk-lp trunk-dev | ||
3364 | 168 | |||
3365 | 169 | Now, your working area looks like this:: | ||
3366 | 170 | |||
3367 | 171 | maqroll[ipython-repo]> ls -a | ||
3368 | 172 | ./ ../ .bzr/ trunk-dev/ trunk-lp/ | ||
3369 | 173 | |||
3370 | 174 | The ``.bzr`` directory is the Bazaar storage area, and you now have both the | ||
3371 | 175 | reference copy of the public trunk and one working copy for your own | ||
3372 | 176 | development. You can later make further branches as needed (a common workflow | ||
3373 | 177 | is to make branches to contain specific feature implementations until they are | ||
3374 | 178 | ready to be merged). | ||
3375 | 179 | |||
3376 | 180 | The typical work cycle will be to make changes in ``trunk-dev`` and then commit | ||
3377 | 181 | those changes as often as needed:: | ||
3378 | 182 | |||
3379 | 183 | cd trunk-dev | ||
3380 | 184 | # ... implement cool new feature... | ||
3381 | 185 | bzr commit -m "Commit message goes here." | ||
3382 | 148 | 186 | ||
3383 | 149 | Please note that since we now don't use an old-style linear ChangeLog (that | 187 | Please note that since we now don't use an old-style linear ChangeLog (that |
3384 | 150 | tends to cause problems with distributed version control systems), you should | 188 | tends to cause problems with distributed version control systems), you should |
3394 | 151 | ensure that your log messages are reasonably detailed. Use a docstring-like | 189 | ensure that your log messages are reasonably detailed. For non-trivial |
3395 | 152 | approach in the commit messages (including the second line being left | 190 | changes, use a docstring-like approach in the commit messages (including the |
3396 | 153 | *blank*):: | 191 | second line being left *blank*). Type ``bzr commit`` *without* the ``-m`` |
3397 | 154 | 192 | switch, and Bazaar will open an editor where you can type a more detailed | |
3398 | 155 | Single line summary of changes being committed. | 193 | message:: |
3399 | 156 | 194 | ||
3400 | 157 | - more details when warranted ... | 195 | Single line summary of changes being committed. |
3401 | 158 | - including crediting outside contributors if they sent the | 196 | |
3402 | 159 | code/bug/idea! | 197 | - more details when warranted ... |
3403 | 198 | - including crediting outside contributors if they sent the | ||
3404 | 199 | code/bug/idea! | ||
3405 | 160 | 200 | ||
3406 | 161 | If we couple this with a policy of making single commits for each reasonably | 201 | If we couple this with a policy of making single commits for each reasonably |
3407 | 162 | atomic change, the bzr log should give an excellent view of the project, and | 202 | atomic change, the bzr log should give an excellent view of the project, and |
3414 | 163 | the `--short` log option becomes a nice summary. | 203 | the ``--short`` log option becomes a nice summary. |
3415 | 164 | 204 | ||
3416 | 165 | While working with this branch, it is a good idea to merge in changes that have | 205 | As you work on the branch, it's a good idea to frequently keep your copy of the |
3417 | 166 | been made upstream in the parent branch. This can be done by doing:: | 206 | trunk updated with respect to Launchpad. This is done via:: |
3418 | 167 | 207 | ||
3419 | 168 | $ bzr pull | 208 | cd trunk-lp |
3420 | 209 | bzr pull | ||
3421 | 210 | |||
3422 | 211 | Bazaar can then merge any changes that were done to the public trunk into your | ||
3423 | 212 | local branch via:: | ||
3424 | 213 | |||
3425 | 214 | cd trunk-dev | ||
3426 | 215 | bzr merge ../trunk-lp | ||
3427 | 216 | bzr commit -m"Merged upstream changes" | ||
3428 | 217 | |||
3429 | 218 | This workflow ensures that a local copy stays in sync with the public trunk, | ||
3430 | 219 | while allowing for local development to be pushed back for public review. | ||
3431 | 220 | |||
3432 | 221 | Once your changes are ready for review, you can push them to Launchpad where | ||
3433 | 222 | the IPython team can review them and give you feedback. The first time, use:: | ||
3434 | 223 | |||
3435 | 224 | bzr push --remember \ | ||
3436 | 225 | bzr+ssh://<you>@bazaar.launchpad.net/~<you>/ipython/trunk-dev | ||
3437 | 226 | |||
3438 | 227 | where ``<you>`` is your Launchpad user name. This will make this branch | ||
3439 | 228 | publicly visible to all. In subsequent uses you can simply run in the branch:: | ||
3440 | 229 | |||
3441 | 230 | bzr push | ||
3442 | 231 | |||
3443 | 232 | .. note:: | ||
3444 | 233 | |||
3445 | 234 | Before you can push your code to Launchpad, you need to configure your SSH | ||
3446 | 235 | keys. You can do this by clicking on ``Change details`` for your profile | ||
3447 | 236 | and then clicking on the ``SSH Keys`` tab. This should take you to a URL | ||
3448 | 237 | of the form ``https://launchpad.net/~<you>/+editsshkeys`` with instructions | ||
3449 | 238 | on how to upload your keys. | ||
3450 | 169 | 239 | ||
3661 | 170 | If this command shows that the branches have diverged, then you should do a | 240 | Once the branch is publicly visible, using the launchpad interface it can be |
3662 | 171 | merge instead:: | 241 | marked for merging with the link marked *"Propose for merging into another |
3663 | 172 | 242 | branch"*, leaving the default choice of trunk as its target. This way, | |
3664 | 173 | $ bzr merge lp:ipython | 243 | Launchpad tracks what changes of this branch are new with respect to the trunk, |
3665 | 174 | 244 | others in the team can review it, and merge the changes into the trunk. | |
3666 | 175 | If you want others to be able to see your branch, you can create an account | 245 | |
3667 | 176 | with launchpad and push the branch to your own workspace:: | 246 | The IPython team has a policy of reviewing all code (both from core members of |
3668 | 177 | 247 | the team and from external contributors) before merging it. Code should be | |
3669 | 178 | $ bzr push bzr+ssh://<me>@bazaar.launchpad.net/~<me>/+junk/ipython-mybranch | 248 | clearly documented (as explained further in this guide), clear and well tested. |
3670 | 179 | 249 | We will be happy to provide you with feedback for your code to be a great | |
3671 | 180 | Finally, once the work in your branch is done, you can merge your changes back | 250 | contribution to the project, and we've found that peer review of code is an |
3672 | 181 | into the `ipython` branch by using merge:: | 251 | excellent way to improve the quality of everyone's work. |
3463 | 182 | |||
3464 | 183 | $ cd ipython | ||
3465 | 184 | $ merge ../ipython-mybranch | ||
3466 | 185 | [resolve any conflicts] | ||
3467 | 186 | $ bzr ci -m "Fixing that bug" | ||
3468 | 187 | $ bzr push | ||
3469 | 188 | |||
3470 | 189 | But this will require you to have write permissions to the `ipython` branch. | ||
3471 | 190 | It you don't you can tell one of the IPython devs about your branch and they | ||
3472 | 191 | can do the merge for you. | ||
3473 | 192 | |||
3474 | 193 | More information about Bazaar workflows can be found `here`__. | ||
3475 | 194 | |||
3476 | 195 | .. __: http://subversion.tigris.org/ | ||
3477 | 196 | .. __: http://bazaar-vcs.org/ | ||
3478 | 197 | .. __: http://www.launchpad.net/ipython | ||
3479 | 198 | .. __: http://doc.bazaar-vcs.org/bzr.dev/en/user-guide/index.html | ||
3480 | 199 | |||
3481 | 200 | Documentation | ||
3482 | 201 | ============= | ||
3483 | 202 | |||
3484 | 203 | Standalone documentation | ||
3485 | 204 | ------------------------ | ||
3486 | 205 | |||
3487 | 206 | All standalone documentation should be written in plain text (``.txt``) files | ||
3488 | 207 | using `reStructuredText`_ for markup and formatting. All such documentation | ||
3489 | 208 | should be placed in the top level directory ``docs`` of the IPython source | ||
3490 | 209 | tree. Or, when appropriate, a suitably named subdirectory should be used. The | ||
3491 | 210 | documentation in this location will serve as the main source for IPython | ||
3492 | 211 | documentation and all existing documentation should be converted to this | ||
3493 | 212 | format. | ||
3494 | 213 | |||
3495 | 214 | In the future, the text files in the ``docs`` directory will be used to | ||
3496 | 215 | generate all forms of documentation for IPython. This include documentation on | ||
3497 | 216 | the IPython website as well as *pdf* documentation. | ||
3498 | 217 | |||
3499 | 218 | .. _reStructuredText: http://docutils.sourceforge.net/rst.html | ||
3500 | 219 | |||
3501 | 220 | Docstring format | ||
3502 | 221 | ---------------- | ||
3503 | 222 | |||
3504 | 223 | Good docstrings are very important. All new code will use `Epydoc`_ for | ||
3505 | 224 | generating API docs, so we will follow the `Epydoc`_ conventions. More | ||
3506 | 225 | specifically, we will use `reStructuredText`_ for markup and formatting, since | ||
3507 | 226 | it is understood by a wide variety of tools. This means that if in the future | ||
3508 | 227 | we have any reason to change from `Epydoc`_ to something else, we'll have fewer | ||
3509 | 228 | transition pains. | ||
3510 | 229 | |||
3511 | 230 | Details about using `reStructuredText`_ for docstrings can be found `here | ||
3512 | 231 | <http://epydoc.sourceforge.net/manual-othermarkup.html>`_. | ||
3513 | 232 | |||
3514 | 233 | .. _Epydoc: http://epydoc.sourceforge.net/ | ||
3515 | 234 | |||
3516 | 235 | Additional PEPs of interest regarding documentation of code: | ||
3517 | 236 | |||
3518 | 237 | - `Docstring Conventions <http://www.python.org/peps/pep-0257.html>`_ | ||
3519 | 238 | - `Docstring Processing System Framework <http://www.python.org/peps/pep-0256.html>`_ | ||
3520 | 239 | - `Docutils Design Specification <http://www.python.org/peps/pep-0258.html>`_ | ||
3521 | 240 | |||
3522 | 241 | |||
3523 | 242 | Coding conventions | ||
3524 | 243 | ================== | ||
3525 | 244 | |||
3526 | 245 | General | ||
3527 | 246 | ------- | ||
3528 | 247 | |||
3529 | 248 | In general, we'll try to follow the standard Python style conventions as | ||
3530 | 249 | described here: | ||
3531 | 250 | |||
3532 | 251 | - `Style Guide for Python Code <http://www.python.org/peps/pep-0008.html>`_ | ||
3533 | 252 | |||
3534 | 253 | |||
3535 | 254 | Other comments: | ||
3536 | 255 | |||
3537 | 256 | - In a large file, top level classes and functions should be | ||
3538 | 257 | separated by 2-3 lines to make it easier to separate them visually. | ||
3539 | 258 | - Use 4 spaces for indentation. | ||
3540 | 259 | - Keep the ordering of methods the same in classes that have the same | ||
3541 | 260 | methods. This is particularly true for classes that implement | ||
3542 | 261 | similar interfaces and for interfaces that are similar. | ||
3543 | 262 | |||
3544 | 263 | Naming conventions | ||
3545 | 264 | ------------------ | ||
3546 | 265 | |||
3547 | 266 | In terms of naming conventions, we'll follow the guidelines from the `Style | ||
3548 | 267 | Guide for Python Code`_. | ||
3549 | 268 | |||
3550 | 269 | For all new IPython code (and much existing code is being refactored), we'll use: | ||
3551 | 270 | |||
3552 | 271 | - All ``lowercase`` module names. | ||
3553 | 272 | |||
3554 | 273 | - ``CamelCase`` for class names. | ||
3555 | 274 | |||
3556 | 275 | - ``lowercase_with_underscores`` for methods, functions, variables and | ||
3557 | 276 | attributes. | ||
3558 | 277 | |||
3559 | 278 | This may be confusing as most of the existing IPython codebase uses a different | ||
3560 | 279 | convention (``lowerCamelCase`` for methods and attributes). Slowly, we will | ||
3561 | 280 | move IPython over to the new convention, providing shadow names for backward | ||
3562 | 281 | compatibility in public interfaces. | ||
3563 | 282 | |||
3564 | 283 | There are, however, some important exceptions to these rules. In some cases, | ||
3565 | 284 | IPython code will interface with packages (Twisted, Wx, Qt) that use other | ||
3566 | 285 | conventions. At some level this makes it impossible to adhere to our own | ||
3567 | 286 | standards at all times. In particular, when subclassing classes that use other | ||
3568 | 287 | naming conventions, you must follow their naming conventions. To deal with | ||
3569 | 288 | cases like this, we propose the following policy: | ||
3570 | 289 | |||
3571 | 290 | - If you are subclassing a class that uses different conventions, use its | ||
3572 | 291 | naming conventions throughout your subclass. Thus, if you are creating a | ||
3573 | 292 | Twisted Protocol class, used Twisted's | ||
3574 | 293 | ``namingSchemeForMethodsAndAttributes.`` | ||
3575 | 294 | |||
3576 | 295 | - All IPython's official interfaces should use our conventions. In some cases | ||
3577 | 296 | this will mean that you need to provide shadow names (first implement | ||
3578 | 297 | ``fooBar`` and then ``foo_bar = fooBar``). We want to avoid this at all | ||
3579 | 298 | costs, but it will probably be necessary at times. But, please use this | ||
3580 | 299 | sparingly! | ||
3581 | 300 | |||
3582 | 301 | Implementation-specific *private* methods will use | ||
3583 | 302 | ``_single_underscore_prefix``. Names with a leading double underscore will | ||
3584 | 303 | *only* be used in special cases, as they makes subclassing difficult (such | ||
3585 | 304 | names are not easily seen by child classes). | ||
3586 | 305 | |||
3587 | 306 | Occasionally some run-in lowercase names are used, but mostly for very short | ||
3588 | 307 | names or where we are implementing methods very similar to existing ones in a | ||
3589 | 308 | base class (like ``runlines()`` where ``runsource()`` and ``runcode()`` had | ||
3590 | 309 | established precedent). | ||
3591 | 310 | |||
3592 | 311 | The old IPython codebase has a big mix of classes and modules prefixed with an | ||
3593 | 312 | explicit ``IP``. In Python this is mostly unnecessary, redundant and frowned | ||
3594 | 313 | upon, as namespaces offer cleaner prefixing. The only case where this approach | ||
3595 | 314 | is justified is for classes which are expected to be imported into external | ||
3596 | 315 | namespaces and a very generic name (like Shell) is too likely to clash with | ||
3597 | 316 | something else. We'll need to revisit this issue as we clean up and refactor | ||
3598 | 317 | the code, but in general we should remove as many unnecessary ``IP``/``ip`` | ||
3599 | 318 | prefixes as possible. However, if a prefix seems absolutely necessary the more | ||
3600 | 319 | specific ``IPY`` or ``ipy`` are preferred. | ||
3601 | 320 | |||
3602 | 321 | .. _devel_testing: | ||
3603 | 322 | |||
3604 | 323 | Testing system | ||
3605 | 324 | ============== | ||
3606 | 325 | |||
3607 | 326 | It is extremely important that all code contributed to IPython has tests. Tests | ||
3608 | 327 | should be written as unittests, doctests or as entities that the `Nose`_ | ||
3609 | 328 | testing package will find. Regardless of how the tests are written, we will use | ||
3610 | 329 | `Nose`_ for discovering and running the tests. `Nose`_ will be required to run | ||
3611 | 330 | the IPython test suite, but will not be required to simply use IPython. | ||
3612 | 331 | |||
3613 | 332 | .. _Nose: http://code.google.com/p/python-nose/ | ||
3614 | 333 | |||
3615 | 334 | Tests of `Twisted`__ using code should be written by subclassing the | ||
3616 | 335 | ``TestCase`` class that comes with ``twisted.trial.unittest``. When this is | ||
3617 | 336 | done, `Nose`_ will be able to run the tests and the twisted reactor will be | ||
3618 | 337 | handled correctly. | ||
3619 | 338 | |||
3620 | 339 | .. __: http://www.twistedmatrix.com | ||
3621 | 340 | |||
3622 | 341 | Each subpackage in IPython should have its own ``tests`` directory that | ||
3623 | 342 | contains all of the tests for that subpackage. This allows each subpackage to | ||
3624 | 343 | be self-contained. If a subpackage has any dependencies beyond the Python | ||
3625 | 344 | standard library, the tests for that subpackage should be skipped if the | ||
3626 | 345 | dependencies are not found. This is very important so users don't get tests | ||
3627 | 346 | failing simply because they don't have dependencies. | ||
3628 | 347 | |||
3629 | 348 | We also need to look into use Noses ability to tag tests to allow a more | ||
3630 | 349 | modular approach of running tests. | ||
3631 | 350 | |||
3632 | 351 | .. _devel_config: | ||
3633 | 352 | |||
3634 | 353 | Configuration system | ||
3635 | 354 | ==================== | ||
3636 | 355 | |||
3637 | 356 | IPython uses `.ini`_ files for configuration purposes. This represents a huge | ||
3638 | 357 | improvement over the configuration system used in IPython. IPython works with | ||
3639 | 358 | these files using the `ConfigObj`_ package, which IPython includes as | ||
3640 | 359 | ``ipython1/external/configobj.py``. | ||
3641 | 360 | |||
3642 | 361 | Currently, we are using raw `ConfigObj`_ objects themselves. Each subpackage of | ||
3643 | 362 | IPython should contain a ``config`` subdirectory that contains all of the | ||
3644 | 363 | configuration information for the subpackage. To see how configuration | ||
3645 | 364 | information is defined (along with defaults) see at the examples in | ||
3646 | 365 | ``ipython1/kernel/config`` and ``ipython1/core/config``. Likewise, to see how | ||
3647 | 366 | the configuration information is used, see examples in | ||
3648 | 367 | ``ipython1/kernel/scripts/ipengine.py``. | ||
3649 | 368 | |||
3650 | 369 | Eventually, we will add a new layer on top of the raw `ConfigObj`_ objects. We | ||
3651 | 370 | are calling this new layer, ``tconfig``, as it will use a `Traits`_-like | ||
3652 | 371 | validation model. We won't actually use `Traits`_, but will implement | ||
3653 | 372 | something similar in pure Python. But, even in this new system, we will still | ||
3654 | 373 | use `ConfigObj`_ and `.ini`_ files underneath the hood. Talk to Fernando if you | ||
3655 | 374 | are interested in working on this part of IPython. The current prototype of | ||
3656 | 375 | ``tconfig`` is located in the IPython sandbox. | ||
3657 | 376 | |||
3658 | 377 | .. _.ini: http://docs.python.org/lib/module-ConfigParser.html | ||
3659 | 378 | .. _ConfigObj: http://www.voidspace.org.uk/python/configobj.html | ||
3660 | 379 | .. _Traits: http://code.enthought.com/traits/ | ||
3673 | 380 | 252 | ||
3674 | 381 | 253 | ||
3675 | 382 | Installation and testing scenarios | 254 | Installation and testing scenarios |
3676 | @@ -386,43 +258,54 @@ | |||
3677 | 386 | release an IPython version. These scenarios represent different ways of | 258 | release an IPython version. These scenarios represent different ways of |
3678 | 387 | installing IPython and its dependencies. | 259 | installing IPython and its dependencies. |
3679 | 388 | 260 | ||
3680 | 261 | |||
3681 | 389 | Installation scenarios under Linux and OS X | 262 | Installation scenarios under Linux and OS X |
3682 | 390 | ------------------------------------------- | 263 | ------------------------------------------- |
3683 | 391 | 264 | ||
3696 | 392 | 1. Install from tarball using ``python setup.py install``. | 265 | 1. Install from tarball using ``python setup.py install``. |
3697 | 393 | a. With only readline+nose dependencies installed. | 266 | |
3698 | 394 | b. With all dependencies installed (readline, zope.interface, Twisted, | 267 | * With only readline+nose dependencies installed. |
3699 | 395 | foolscap, Sphinx, nose, pyOpenSSL). | 268 | |
3700 | 396 | 269 | * With all dependencies installed (readline, zope.interface, Twisted, | |
3701 | 397 | 2. Install using easy_install. | 270 | foolscap, Sphinx, nose, pyOpenSSL). |
3702 | 398 | 271 | ||
3703 | 399 | a. With only readline+nose dependencies installed. | 272 | 2. Install using easy_install. |
3704 | 400 | i. Default dependencies: ``easy_install ipython-0.9.beta3-py2.5.egg`` | 273 | |
3705 | 401 | ii. Optional dependency sets: ``easy_install -f ipython-0.9.beta3-py2.5.egg IPython[kernel,doc,test,security]`` | 274 | * With only readline+nose dependencies installed. |
3706 | 402 | 275 | ||
3707 | 403 | b. With all dependencies already installed. | 276 | * Default dependencies: ``easy_install ipython-0.9.beta3-py2.5.egg`` |
3708 | 277 | |||
3709 | 278 | * Optional dependency sets: | ||
3710 | 279 | ``easy_install -f ipython-0.9.beta3-py2.5.egg IPython[kernel,doc,test,security]`` | ||
3711 | 280 | |||
3712 | 281 | * With all dependencies already installed. | ||
3713 | 404 | 282 | ||
3714 | 405 | 283 | ||
3715 | 406 | Installation scenarios under Win32 | 284 | Installation scenarios under Win32 |
3716 | 407 | ---------------------------------- | 285 | ---------------------------------- |
3717 | 408 | 286 | ||
3720 | 409 | 1. Install everything from .exe installers | 287 | #. Install everything from .exe installers |
3721 | 410 | 2. easy_install? | 288 | #. easy_install? |
3722 | 411 | 289 | ||
3723 | 412 | 290 | ||
3724 | 413 | Tests to run for these scenarios | 291 | Tests to run for these scenarios |
3725 | 414 | -------------------------------- | 292 | -------------------------------- |
3726 | 415 | 293 | ||
3737 | 416 | 1. Run the full test suite. | 294 | #. Run the full test suite. |
3738 | 417 | 2. Start a controller and engines and try a few things by hand. | 295 | |
3739 | 418 | a. Using ipcluster. | 296 | #. Start a controller and engines and try a few things by hand. |
3740 | 419 | b. Using ipcontroller/ipengine by hand. | 297 | |
3741 | 420 | 298 | * Using ipcluster. | |
3742 | 421 | 3. Run a few of the parallel examples. | 299 | * Using ipcontroller/ipengine by hand. |
3743 | 422 | 4. Try the kernel with and without security with and without PyOpenSSL | 300 | |
3744 | 423 | installed. | 301 | #. Run a few of the parallel examples. |
3745 | 424 | 5. Beat on the IPython terminal a bunch. | 302 | |
3746 | 425 | 6. Make sure that furl files are being put in proper locations. | 303 | #. Try the kernel with and without security with and without PyOpenSSL |
3747 | 304 | installed. | ||
3748 | 305 | |||
3749 | 306 | #. Beat on the IPython terminal a bunch. | ||
3750 | 307 | |||
3751 | 308 | #. Make sure that furl files are being put in proper locations. | ||
3752 | 426 | 309 | ||
3753 | 427 | 310 | ||
3754 | 428 | Release checklist | 311 | Release checklist |
3755 | 429 | 312 | ||
3756 | === modified file 'docs/source/index.txt' | |||
3757 | --- docs/source/index.txt 2008-09-15 03:37:13 +0000 | |||
3758 | +++ docs/source/index.txt 2009-03-11 01:24:53 +0000 | |||
3759 | @@ -17,10 +17,11 @@ | |||
3760 | 17 | interactive/index.txt | 17 | interactive/index.txt |
3761 | 18 | parallel/index.txt | 18 | parallel/index.txt |
3762 | 19 | config/index.txt | 19 | config/index.txt |
3763 | 20 | faq.txt | ||
3764 | 21 | history.txt | ||
3765 | 20 | changes.txt | 22 | changes.txt |
3766 | 21 | development/index.txt | 23 | development/index.txt |
3769 | 22 | faq.txt | 24 | api/index.txt |
3768 | 23 | history.txt | ||
3770 | 24 | license_and_copyright.txt | 25 | license_and_copyright.txt |
3771 | 25 | credits.txt | 26 | credits.txt |
3772 | 26 | 27 | ||
3773 | 27 | 28 | ||
3774 | === modified file 'docs/source/install/index.txt' | |||
3775 | --- docs/source/install/index.txt 2008-09-11 23:49:58 +0000 | |||
3776 | +++ docs/source/install/index.txt 2008-10-04 05:37:23 +0000 | |||
3777 | @@ -1,8 +1,8 @@ | |||
3778 | 1 | .. _install_index: | 1 | .. _install_index: |
3779 | 2 | 2 | ||
3781 | 3 | ================== | 3 | ============ |
3782 | 4 | Installation | 4 | Installation |
3784 | 5 | ================== | 5 | ============ |
3785 | 6 | 6 | ||
3786 | 7 | .. toctree:: | 7 | .. toctree:: |
3787 | 8 | :maxdepth: 2 | 8 | :maxdepth: 2 |
3788 | 9 | 9 | ||
3789 | === modified file 'docs/source/install/install.txt' | |||
3790 | --- docs/source/install/install.txt 2008-09-13 15:14:14 +0000 | |||
3791 | +++ docs/source/install/install.txt 2008-10-04 07:47:34 +0000 | |||
3792 | @@ -1,77 +1,126 @@ | |||
3793 | 1 | .. There's little Python in this file, so make the default language bash. | ||
3794 | 2 | |||
3795 | 3 | .. highlight:: bash | ||
3796 | 4 | |||
3797 | 1 | Overview | 5 | Overview |
3798 | 2 | ======== | 6 | ======== |
3799 | 3 | 7 | ||
3801 | 4 | This document describes the steps required to install IPython. IPython is organized into a number of subpackages, each of which has its own dependencies. All of the subpackages come with IPython, so you don't need to download and install them separately. However, to use a given subpackage, you will need to install all of its dependencies. | 8 | This document describes the steps required to install IPython. IPython is |
3802 | 9 | organized into a number of subpackages, each of which has its own dependencies. | ||
3803 | 10 | All of the subpackages come with IPython, so you don't need to download and | ||
3804 | 11 | install them separately. However, to use a given subpackage, you will need to | ||
3805 | 12 | install all of its dependencies. | ||
3806 | 5 | 13 | ||
3807 | 6 | 14 | ||
3808 | 7 | Please let us know if you have problems installing IPython or any of its | 15 | Please let us know if you have problems installing IPython or any of its |
3811 | 8 | dependencies. IPython requires Python version 2.4 or greater. We have not tested | 16 | dependencies. IPython requires Python version 2.4 or greater. We have not |
3812 | 9 | IPython with the upcoming 2.6 or 3.0 versions. | 17 | tested IPython with the upcoming 2.6 or 3.0 versions, though preliminary |
3813 | 18 | reports of 2.6 usage are encouraging. 3.0 porting will take longer, however. | ||
3814 | 10 | 19 | ||
3815 | 11 | .. warning:: | 20 | .. warning:: |
3816 | 12 | 21 | ||
3822 | 13 | IPython will not work with Python 2.3 or below. | 22 | IPython will not work with Python 2.3 or below. |
3823 | 14 | 23 | ||
3824 | 15 | Some of the installation approaches use the :mod:`setuptools` package and its :command:`easy_install` command line program. In many scenarios, this provides the most simple method of installing IPython and its dependencies. It is not required though. More information about :mod:`setuptools` can be found on its website. | 24 | Some of the installation approaches use the :mod:`setuptools` package and its |
3825 | 16 | 25 | :command:`easy_install` command line program. In many scenarios, this provides | |
3826 | 17 | More general information about installing Python packages can be found in Python's documentation at http://www.python.org/doc/. | 26 | the most simple method of installing IPython and its dependencies. It is not |
3827 | 27 | required though. More information about :mod:`setuptools` can be found on its | ||
3828 | 28 | website. | ||
3829 | 29 | |||
3830 | 30 | More general information about installing Python packages can be found in | ||
3831 | 31 | Python's documentation at http://www.python.org/doc/. | ||
3832 | 32 | |||
3833 | 18 | 33 | ||
3834 | 19 | Installing IPython itself | 34 | Installing IPython itself |
3835 | 20 | ========================= | 35 | ========================= |
3836 | 21 | 36 | ||
3838 | 22 | Given a properly built Python, the basic interactive IPython shell will work with no external dependencies. However, some Python distributions (particularly on Windows and OS X), don't come with a working :mod:`readline` module. The IPython shell will work without :mod:`readline`, but will lack many features that users depend on, such as tab completion and command line editing. See below for details of how to make sure you have a working :mod:`readline`. | 37 | Given a properly built Python, the basic interactive IPython shell will work |
3839 | 38 | with no external dependencies. However, some Python distributions | ||
3840 | 39 | (particularly on Windows and OS X), don't come with a working :mod:`readline` | ||
3841 | 40 | module. The IPython shell will work without :mod:`readline`, but will lack | ||
3842 | 41 | many features that users depend on, such as tab completion and command line | ||
3843 | 42 | editing. See below for details of how to make sure you have a working | ||
3844 | 43 | :mod:`readline`. | ||
3845 | 23 | 44 | ||
3846 | 24 | Installation using easy_install | 45 | Installation using easy_install |
3847 | 25 | ------------------------------- | 46 | ------------------------------- |
3848 | 26 | 47 | ||
3854 | 27 | If you have :mod:`setuptools` installed, the easiest way of getting IPython is to simple use :command:`easy_install`:: | 48 | If you have :mod:`setuptools` installed, the easiest way of getting IPython is |
3855 | 28 | 49 | to use :command:`easy_install`:: | |
3856 | 29 | $ easy_install IPython | 50 | |
3857 | 30 | 51 | easy_install IPython | |
3858 | 31 | That's it. | 52 | |
3859 | 53 | Unless you've written a custom distutils script as explained `here`__, that will | ||
3860 | 54 | try to install either in a default system-wide location, which may require | ||
3861 | 55 | administrator access. If that is the case, you can either run the command with | ||
3862 | 56 | root privileges:: | ||
3863 | 57 | |||
3864 | 58 | sudo easy_install IPython | ||
3865 | 59 | |||
3866 | 60 | or you can specify an alternate location, for example:: | ||
3867 | 61 | |||
3868 | 62 | easy_install --prefix=~/usr/local IPython | ||
3869 | 63 | |||
3870 | 64 | where this assumes that ``~/usr/local`` is a valid prefix for you to install | ||
3871 | 65 | packages to in your user account. | ||
3872 | 66 | |||
3873 | 67 | .. __: http://docs.python.org/install/index.html#inst-config-files | ||
3874 | 68 | |||
3875 | 32 | 69 | ||
3876 | 33 | Installation from source | 70 | Installation from source |
3877 | 34 | ------------------------ | 71 | ------------------------ |
3878 | 35 | 72 | ||
3886 | 36 | If you don't want to use :command:`easy_install`, or don't have it installed, just grab the latest stable build of IPython from `here <http://ipython.scipy.org/dist/>`_. Then do the following:: | 73 | If you don't want to use :command:`easy_install`, or don't have it installed, |
3887 | 37 | 74 | just grab the latest stable build of IPython from `here | |
3888 | 38 | $ tar -xzf ipython.tar.gz | 75 | <http://ipython.scipy.org/dist/>`_. Then do the following (using the |
3889 | 39 | $ cd ipython | 76 | appropriate version number):: |
3890 | 40 | $ python setup.py install | 77 | |
3891 | 41 | 78 | tar -xzf ipython.tar.gz | |
3892 | 42 | If you are installing to a location (like ``/usr/local``) that requires higher permissions, you may need to run the last command with :command:`sudo`. | 79 | cd ipython |
3893 | 80 | python setup.py install | ||
3894 | 81 | |||
3895 | 82 | If you are installing to a location (like ``/usr/local``) that requires higher | ||
3896 | 83 | permissions, you may need to run the last command with :command:`sudo`. | ||
3897 | 43 | 84 | ||
3898 | 44 | Windows | 85 | Windows |
3899 | 45 | ------- | 86 | ------- |
3900 | 46 | 87 | ||
3901 | 47 | There are a few caveats for Windows users. The main issue is that a basic ``python setup.py install`` approach won't create ``.bat`` file or Start Menu shortcuts, which most users want. To get an installation with these, there are two choices: | 88 | There are a few caveats for Windows users. The main issue is that a basic ``python setup.py install`` approach won't create ``.bat`` file or Start Menu shortcuts, which most users want. To get an installation with these, there are two choices: |
3902 | 48 | 89 | ||
3908 | 49 | 1. Install using :command:`easy_install`. | 90 | #. Install using :command:`easy_install`. |
3909 | 50 | 91 | ||
3910 | 51 | 2. Install using our binary ``.exe`` Windows installer, which can be found at `here <http://ipython.scipy.org/dist/>`_ | 92 | #. Install using our binary ``.exe`` Windows installer, which can be found at |
3911 | 52 | 93 | `here <http://ipython.scipy.org/dist/>`_ | |
3912 | 53 | 3. Install from source, but using :mod:`setuptools` (``python setupegg.py install``). | 94 | |
3913 | 95 | #. Install from source, but using :mod:`setuptools` (``python setupegg.py | ||
3914 | 96 | install``). | ||
3915 | 54 | 97 | ||
3916 | 55 | Installing the development version | 98 | Installing the development version |
3917 | 56 | ---------------------------------- | 99 | ---------------------------------- |
3918 | 57 | 100 | ||
3921 | 58 | It is also possible to install the development version of IPython from our `Bazaar <http://bazaar-vcs.org/>`_ source code | 101 | It is also possible to install the development version of IPython from our |
3922 | 59 | repository. To do this you will need to have Bazaar installed on your system. Then just do:: | 102 | `Bazaar <http://bazaar-vcs.org/>`_ source code repository. To do this you will |
3923 | 103 | need to have Bazaar installed on your system. Then just do:: | ||
3924 | 60 | 104 | ||
3928 | 61 | $ bzr branch lp:ipython | 105 | bzr branch lp:ipython |
3929 | 62 | $ cd ipython | 106 | cd ipython |
3930 | 63 | $ python setup.py install | 107 | python setup.py install |
3931 | 64 | 108 | ||
3932 | 65 | Again, this last step on Windows won't create ``.bat`` files or Start Menu shortcuts, so you will have to use one of the other approaches listed above. | 109 | Again, this last step on Windows won't create ``.bat`` files or Start Menu shortcuts, so you will have to use one of the other approaches listed above. |
3933 | 66 | 110 | ||
3942 | 67 | Some users want to be able to follow the development branch as it changes. If you have :mod:`setuptools` installed, this is easy. Simply replace the last step by:: | 111 | Some users want to be able to follow the development branch as it changes. If |
3943 | 68 | 112 | you have :mod:`setuptools` installed, this is easy. Simply replace the last | |
3944 | 69 | $ python setupegg.py develop | 113 | step by:: |
3945 | 70 | 114 | ||
3946 | 71 | This creates links in the right places and installs the command line script to the appropriate places. Then, if you want to update your IPython at any time, just do:: | 115 | python setupegg.py develop |
3947 | 72 | 116 | ||
3948 | 73 | $ bzr pull | 117 | This creates links in the right places and installs the command line script to |
3949 | 74 | 118 | the appropriate places. Then, if you want to update your IPython at any time, | |
3950 | 119 | just do:: | ||
3951 | 120 | |||
3952 | 121 | bzr pull | ||
3953 | 122 | |||
3954 | 123 | |||
3955 | 75 | Basic optional dependencies | 124 | Basic optional dependencies |
3956 | 76 | =========================== | 125 | =========================== |
3957 | 77 | 126 | ||
3958 | @@ -86,17 +135,24 @@ | |||
3959 | 86 | readline | 135 | readline |
3960 | 87 | -------- | 136 | -------- |
3961 | 88 | 137 | ||
3963 | 89 | In principle, all Python distributions should come with a working :mod:`readline` module. But, reality is not quite that simple. There are two common situations where you won't have a working :mod:`readline` module: | 138 | In principle, all Python distributions should come with a working |
3964 | 139 | :mod:`readline` module. But, reality is not quite that simple. There are two | ||
3965 | 140 | common situations where you won't have a working :mod:`readline` module: | ||
3966 | 90 | 141 | ||
3967 | 91 | * If you are using the built-in Python on Mac OS X. | 142 | * If you are using the built-in Python on Mac OS X. |
3968 | 92 | 143 | ||
3969 | 93 | * If you are running Windows, which doesn't have a :mod:`readline` module. | 144 | * If you are running Windows, which doesn't have a :mod:`readline` module. |
3970 | 94 | 145 | ||
3976 | 95 | On OS X, the built-in Python doesn't not have :mod:`readline` because of license issues. Starting with OS X 10.5 (Leopard), Apple's built-in Python has a BSD-licensed not-quite-compatible readline replacement. As of IPython 0.9, many of the issues related to the differences between readline and libedit have been resolved. For many users, libedit may be sufficient. | 146 | On OS X, the built-in Python doesn't not have :mod:`readline` because of |
3977 | 96 | 147 | license issues. Starting with OS X 10.5 (Leopard), Apple's built-in Python has | |
3978 | 97 | Most users on OS X will want to get the full :mod:`readline` module. To get a working :mod:`readline` module, just do (with :mod:`setuptools` installed):: | 148 | a BSD-licensed not-quite-compatible readline replacement. As of IPython 0.9, |
3979 | 98 | 149 | many of the issues related to the differences between readline and libedit have | |
3980 | 99 | $ easy_install readline | 150 | been resolved. For many users, libedit may be sufficient. |
3981 | 151 | |||
3982 | 152 | Most users on OS X will want to get the full :mod:`readline` module. To get a | ||
3983 | 153 | working :mod:`readline` module, just do (with :mod:`setuptools` installed):: | ||
3984 | 154 | |||
3985 | 155 | easy_install readline | ||
3986 | 100 | 156 | ||
3987 | 101 | .. note: | 157 | .. note: |
3988 | 102 | 158 | ||
3989 | @@ -104,83 +160,112 @@ | |||
3990 | 104 | official python.org binaries) already have readline installed so | 160 | official python.org binaries) already have readline installed so |
3991 | 105 | you don't have to do this step. | 161 | you don't have to do this step. |
3992 | 106 | 162 | ||
3994 | 107 | If needed, the readline egg can be build and installed from source (see the wiki page at http://ipython.scipy.org/moin/InstallationOSXLeopard). | 163 | If needed, the readline egg can be build and installed from source (see the |
3995 | 164 | wiki page at http://ipython.scipy.org/moin/InstallationOSXLeopard). | ||
3996 | 108 | 165 | ||
3998 | 109 | On Windows, you will need the PyReadline module. PyReadline is a separate, Windows only implementation of readline that uses native Windows calls through :mod:`ctypes`. The easiest way of installing PyReadline is you use the binary installer available `here <http://ipython.scipy.org/dist/>`_. The :mod:`ctypes` module, which comes with Python 2.5 and greater, is required by PyReadline. It is available for Python 2.4 at http://python.net/crew/theller/ctypes. | 166 | On Windows, you will need the PyReadline module. PyReadline is a separate, |
3999 | 167 | Windows only implementation of readline that uses native Windows calls through | ||
4000 | 168 | :mod:`ctypes`. The easiest way of installing PyReadline is you use the binary | ||
4001 | 169 | installer available `here <http://ipython.scipy.org/dist/>`_. The | ||
4002 | 170 | :mod:`ctypes` module, which comes with Python 2.5 and greater, is required by | ||
4003 | 171 | PyReadline. It is available for Python 2.4 at | ||
4004 | 172 | http://python.net/crew/theller/ctypes. | ||
4005 | 110 | 173 | ||
4006 | 111 | nose | 174 | nose |
4007 | 112 | ---- | 175 | ---- |
4008 | 113 | 176 | ||
4010 | 114 | To run the IPython test suite you will need the :mod:`nose` package. Nose provides a great way of sniffing out and running all of the IPython tests. The simplest way of getting nose, is to use :command:`easy_install`:: | 177 | To run the IPython test suite you will need the :mod:`nose` package. Nose |
4011 | 178 | provides a great way of sniffing out and running all of the IPython tests. The | ||
4012 | 179 | simplest way of getting nose, is to use :command:`easy_install`:: | ||
4013 | 115 | 180 | ||
4015 | 116 | $ easy_install nose | 181 | easy_install nose |
4016 | 117 | 182 | ||
4017 | 118 | Another way of getting this is to do:: | 183 | Another way of getting this is to do:: |
4018 | 119 | 184 | ||
4024 | 120 | $ easy_install IPython[test] | 185 | easy_install IPython[test] |
4025 | 121 | 186 | ||
4026 | 122 | For more installation options, see the `nose website <http://somethingaboutorange.com/mrl/projects/nose/>`_. Once you have nose installed, you can run IPython's test suite using the iptest command:: | 187 | For more installation options, see the `nose website |
4027 | 123 | 188 | <http://somethingaboutorange.com/mrl/projects/nose/>`_. Once you have nose | |
4028 | 124 | $ iptest | 189 | installed, you can run IPython's test suite using the iptest command:: |
4029 | 190 | |||
4030 | 191 | iptest | ||
4031 | 125 | 192 | ||
4032 | 126 | 193 | ||
4033 | 127 | pexpect | 194 | pexpect |
4034 | 128 | ------- | 195 | ------- |
4035 | 129 | 196 | ||
4037 | 130 | The `pexpect <http://www.noah.org/wiki/Pexpect>`_ package is used in IPython's :command:`irunner` script. On Unix platforms (including OS X), just do:: | 197 | The `pexpect <http://www.noah.org/wiki/Pexpect>`_ package is used in IPython's |
4038 | 198 | :command:`irunner` script. On Unix platforms (including OS X), just do:: | ||
4039 | 131 | 199 | ||
4041 | 132 | $ easy_install pexpect | 200 | easy_install pexpect |
4042 | 133 | 201 | ||
4043 | 134 | Windows users are out of luck as pexpect does not run there. | 202 | Windows users are out of luck as pexpect does not run there. |
4044 | 135 | 203 | ||
4045 | 136 | Dependencies for IPython.kernel (parallel computing) | 204 | Dependencies for IPython.kernel (parallel computing) |
4046 | 137 | ==================================================== | 205 | ==================================================== |
4047 | 138 | 206 | ||
4049 | 139 | The IPython kernel provides a nice architecture for parallel computing. The main focus of this architecture is on interactive parallel computing. These features require a number of additional packages: | 207 | The IPython kernel provides a nice architecture for parallel computing. The |
4050 | 208 | main focus of this architecture is on interactive parallel computing. These | ||
4051 | 209 | features require a number of additional packages: | ||
4052 | 140 | 210 | ||
4053 | 141 | * zope.interface (yep, we use interfaces) | 211 | * zope.interface (yep, we use interfaces) |
4054 | 142 | * Twisted (asynchronous networking framework) | 212 | * Twisted (asynchronous networking framework) |
4055 | 143 | * Foolscap (a nice, secure network protocol) | 213 | * Foolscap (a nice, secure network protocol) |
4056 | 144 | * pyOpenSSL (security for network connections) | 214 | * pyOpenSSL (security for network connections) |
4057 | 145 | 215 | ||
4059 | 146 | On a Unix style platform (including OS X), if you want to use :mod:`setuptools`, you can just do:: | 216 | On a Unix style platform (including OS X), if you want to use |
4060 | 217 | :mod:`setuptools`, you can just do:: | ||
4061 | 147 | 218 | ||
4064 | 148 | $ easy_install IPython[kernel] # the first three | 219 | easy_install IPython[kernel] # the first three |
4065 | 149 | $ easy_install IPython[security] # pyOpenSSL | 220 | easy_install IPython[security] # pyOpenSSL |
4066 | 150 | 221 | ||
4067 | 151 | zope.interface and Twisted | 222 | zope.interface and Twisted |
4068 | 152 | -------------------------- | 223 | -------------------------- |
4069 | 153 | 224 | ||
4078 | 154 | On Unix style platforms (including OS X), the simplest way of getting the these is to use :command:`easy_install`:: | 225 | On Unix style platforms (including OS X), the simplest way of getting the these |
4079 | 155 | 226 | is to use :command:`easy_install`:: | |
4080 | 156 | $ easy_install zope.interface | 227 | |
4081 | 157 | $ easy_install Twisted | 228 | easy_install zope.interface |
4082 | 158 | 229 | easy_install Twisted | |
4083 | 159 | Of course, you can also download the source tarballs from the `Twisted website <twistedmatrix.org>`_ and the `zope.interface page at PyPI <http://pypi.python.org/pypi/zope.interface>`_ and do the usual ``python setup.py install`` if you prefer. | 230 | |
4084 | 160 | 231 | Of course, you can also download the source tarballs from the `Twisted website | |
4085 | 161 | Windows is a bit different. For zope.interface and Twisted, simply get the latest binary ``.exe`` installer from the Twisted website. This installer includes both zope.interface and Twisted and should just work. | 232 | <twistedmatrix.org>`_ and the `zope.interface page at PyPI |
4086 | 233 | <http://pypi.python.org/pypi/zope.interface>`_ and do the usual ``python | ||
4087 | 234 | setup.py install`` if you prefer. | ||
4088 | 235 | |||
4089 | 236 | Windows is a bit different. For zope.interface and Twisted, simply get the | ||
4090 | 237 | latest binary ``.exe`` installer from the Twisted website. This installer | ||
4091 | 238 | includes both zope.interface and Twisted and should just work. | ||
4092 | 162 | 239 | ||
4093 | 163 | Foolscap | 240 | Foolscap |
4094 | 164 | -------- | 241 | -------- |
4095 | 165 | 242 | ||
4097 | 166 | Foolscap uses Twisted to provide a very nice secure RPC protocol that we use to implement our parallel computing features. | 243 | Foolscap uses Twisted to provide a very nice secure RPC protocol that we use to |
4098 | 244 | implement our parallel computing features. | ||
4099 | 167 | 245 | ||
4100 | 168 | On all platforms a simple:: | 246 | On all platforms a simple:: |
4101 | 169 | 247 | ||
4103 | 170 | $ easy_install foolscap | 248 | easy_install foolscap |
4104 | 171 | 249 | ||
4106 | 172 | should work. You can also download the source tarballs from the `Foolscap website <http://foolscap.lothar.com/trac>`_ and do ``python setup.py install`` if you prefer. | 250 | should work. You can also download the source tarballs from the `Foolscap |
4107 | 251 | website <http://foolscap.lothar.com/trac>`_ and do ``python setup.py install`` | ||
4108 | 252 | if you prefer. | ||
4109 | 173 | 253 | ||
4110 | 174 | pyOpenSSL | 254 | pyOpenSSL |
4111 | 175 | --------- | 255 | --------- |
4112 | 176 | 256 | ||
4120 | 177 | IPython requires an older version of pyOpenSSL (0.6 rather than the current 0.7). There are a couple of options for getting this: | 257 | IPython requires an older version of pyOpenSSL (0.6 rather than the current |
4121 | 178 | 258 | 0.7). There are a couple of options for getting this: | |
4122 | 179 | 1. Most Linux distributions have packages for pyOpenSSL. | 259 | |
4123 | 180 | 2. The built-in Python 2.5 on OS X 10.5 already has it installed. | 260 | 1. Most Linux distributions have packages for pyOpenSSL. |
4124 | 181 | 3. There are source tarballs on the pyOpenSSL website. On Unix-like | 261 | |
4125 | 182 | platforms, these can be built using ``python seutp.py install``. | 262 | 2. The built-in Python 2.5 on OS X 10.5 already has it installed. |
4126 | 183 | 4. There is also a binary ``.exe`` Windows installer on the `pyOpenSSL website <http://pyopenssl.sourceforge.net/>`_. | 263 | |
4127 | 264 | 3. There are source tarballs on the pyOpenSSL website. On Unix-like | ||
4128 | 265 | platforms, these can be built using ``python seutp.py install``. | ||
4129 | 266 | |||
4130 | 267 | 4. There is also a binary ``.exe`` Windows installer on the `pyOpenSSL website | ||
4131 | 268 | <http://pyopenssl.sourceforge.net/>`_. | ||
4132 | 184 | 269 | ||
4133 | 185 | Dependencies for IPython.frontend (the IPython GUI) | 270 | Dependencies for IPython.frontend (the IPython GUI) |
4134 | 186 | =================================================== | 271 | =================================================== |
4135 | @@ -188,4 +273,9 @@ | |||
4136 | 188 | wxPython | 273 | wxPython |
4137 | 189 | -------- | 274 | -------- |
4138 | 190 | 275 | ||
4139 | 191 | Starting with IPython 0.9, IPython has a new IPython.frontend package that has a nice wxPython based IPython GUI. As you would expect, this GUI requires wxPython. Most Linux distributions have wxPython packages available and the built-in Python on OS X comes with wxPython preinstalled. For Windows, a binary installer is available on the `wxPython website <http://www.wxpython.org/>`_. | ||
4140 | 192 | \ No newline at end of file | 276 | \ No newline at end of file |
4141 | 277 | Starting with IPython 0.9, IPython has a new IPython.frontend package that has | ||
4142 | 278 | a nice wxPython based IPython GUI. As you would expect, this GUI requires | ||
4143 | 279 | wxPython. Most Linux distributions have wxPython packages available and the | ||
4144 | 280 | built-in Python on OS X comes with wxPython preinstalled. For Windows, a | ||
4145 | 281 | binary installer is available on the `wxPython website | ||
4146 | 282 | <http://www.wxpython.org/>`_. | ||
4147 | 193 | 283 | ||
4148 | === modified file 'docs/source/interactive/reference.txt' | |||
4149 | --- docs/source/interactive/reference.txt 2008-09-13 22:39:42 +0000 | |||
4150 | +++ docs/source/interactive/reference.txt 2009-03-11 01:24:53 +0000 | |||
4151 | @@ -496,9 +496,9 @@ | |||
4152 | 496 | ip.expose_magic('impall', doimp) | 496 | ip.expose_magic('impall', doimp) |
4153 | 497 | 497 | ||
4154 | 498 | You can also define your own aliased names for magic functions. In your | 498 | You can also define your own aliased names for magic functions. In your |
4156 | 499 | ipythonrc file, placing a line like: | 499 | ipythonrc file, placing a line like:: |
4157 | 500 | 500 | ||
4159 | 501 | execute __IP.magic_cl = __IP.magic_clear | 501 | execute __IP.magic_cl = __IP.magic_clear |
4160 | 502 | 502 | ||
4161 | 503 | will define %cl as a new name for %clear. | 503 | will define %cl as a new name for %clear. |
4162 | 504 | 504 | ||
4163 | @@ -508,1572 +508,9 @@ | |||
4164 | 508 | information on the '?' system) to get information about any particular | 508 | information on the '?' system) to get information about any particular |
4165 | 509 | magic function you are interested in. | 509 | magic function you are interested in. |
4166 | 510 | 510 | ||
4167 | 511 | |||
4168 | 512 | Magic commands | ||
4169 | 513 | -------------- | ||
4170 | 514 | |||
4171 | 515 | The rest of this section is automatically generated for each release | ||
4172 | 516 | from the docstrings in the IPython code. Therefore the formatting is | ||
4173 | 517 | somewhat minimal, but this method has the advantage of having | ||
4174 | 518 | information always in sync with the code. | ||
4175 | 519 | |||
4176 | 520 | A list of all the magic commands available in IPython's default | ||
4177 | 521 | installation follows. This is similar to what you'll see by simply | ||
4178 | 522 | typing %magic at the prompt, but that will also give you information | ||
4179 | 523 | about magic commands you may have added as part of your personal | ||
4180 | 524 | customizations. | ||
4181 | 525 | |||
4182 | 526 | .. magic_start | ||
4183 | 527 | |||
4184 | 528 | **%Exit**:: | ||
4185 | 529 | |||
4186 | 530 | Exit IPython without confirmation. | ||
4187 | 531 | |||
4188 | 532 | **%Pprint**:: | ||
4189 | 533 | |||
4190 | 534 | Toggle pretty printing on/off. | ||
4191 | 535 | |||
4192 | 536 | **%alias**:: | ||
4193 | 537 | |||
4194 | 538 | Define an alias for a system command. | ||
4195 | 539 | |||
4196 | 540 | '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd' | ||
4197 | 541 | |||
4198 | 542 | Then, typing 'alias_name params' will execute the system command 'cmd | ||
4199 | 543 | params' (from your underlying operating system). | ||
4200 | 544 | |||
4201 | 545 | Aliases have lower precedence than magic functions and Python normal | ||
4202 | 546 | variables, so if 'foo' is both a Python variable and an alias, the | ||
4203 | 547 | alias can not be executed until 'del foo' removes the Python variable. | ||
4204 | 548 | |||
4205 | 549 | You can use the %l specifier in an alias definition to represent the | ||
4206 | 550 | whole line when the alias is called. For example: | ||
4207 | 551 | |||
4208 | 552 | In [2]: alias all echo "Input in brackets: <%l>"\ | ||
4209 | 553 | In [3]: all hello world\ | ||
4210 | 554 | Input in brackets: <hello world> | ||
4211 | 555 | |||
4212 | 556 | You can also define aliases with parameters using %s specifiers (one | ||
4213 | 557 | per parameter): | ||
4214 | 558 | |||
4215 | 559 | In [1]: alias parts echo first %s second %s\ | ||
4216 | 560 | In [2]: %parts A B\ | ||
4217 | 561 | first A second B\ | ||
4218 | 562 | In [3]: %parts A\ | ||
4219 | 563 | Incorrect number of arguments: 2 expected.\ | ||
4220 | 564 | parts is an alias to: 'echo first %s second %s' | ||
4221 | 565 | |||
4222 | 566 | Note that %l and %s are mutually exclusive. You can only use one or | ||
4223 | 567 | the other in your aliases. | ||
4224 | 568 | |||
4225 | 569 | Aliases expand Python variables just like system calls using ! or !! | ||
4226 | 570 | do: all expressions prefixed with '$' get expanded. For details of | ||
4227 | 571 | the semantic rules, see PEP-215: | ||
4228 | 572 | http://www.python.org/peps/pep-0215.html. This is the library used by | ||
4229 | 573 | IPython for variable expansion. If you want to access a true shell | ||
4230 | 574 | variable, an extra $ is necessary to prevent its expansion by IPython: | ||
4231 | 575 | |||
4232 | 576 | In [6]: alias show echo\ | ||
4233 | 577 | In [7]: PATH='A Python string'\ | ||
4234 | 578 | In [8]: show $PATH\ | ||
4235 | 579 | A Python string\ | ||
4236 | 580 | In [9]: show $$PATH\ | ||
4237 | 581 | /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:... | ||
4238 | 582 | |||
4239 | 583 | You can use the alias facility to acess all of $PATH. See the %rehash | ||
4240 | 584 | and %rehashx functions, which automatically create aliases for the | ||
4241 | 585 | contents of your $PATH. | ||
4242 | 586 | |||
4243 | 587 | If called with no parameters, %alias prints the current alias table. | ||
4244 | 588 | |||
4245 | 589 | **%autocall**:: | ||
4246 | 590 | |||
4247 | 591 | Make functions callable without having to type parentheses. | ||
4248 | 592 | |||
4249 | 593 | Usage: | ||
4250 | 594 | |||
4251 | 595 | %autocall [mode] | ||
4252 | 596 | |||
4253 | 597 | The mode can be one of: 0->Off, 1->Smart, 2->Full. If not given, the | ||
4254 | 598 | value is toggled on and off (remembering the previous state). | ||
4255 | 599 | |||
4256 | 600 | In more detail, these values mean: | ||
4257 | 601 | |||
4258 | 602 | 0 -> fully disabled | ||
4259 | 603 | |||
4260 | 604 | 1 -> active, but do not apply if there are no arguments on the line. | ||
4261 | 605 | |||
4262 | 606 | In this mode, you get: | ||
4263 | 607 | |||
4264 | 608 | In [1]: callable | ||
4265 | 609 | Out[1]: <built-in function callable> | ||
4266 | 610 | |||
4267 | 611 | In [2]: callable 'hello' | ||
4268 | 612 | ------> callable('hello') | ||
4269 | 613 | Out[2]: False | ||
4270 | 614 | |||
4271 | 615 | 2 -> Active always. Even if no arguments are present, the callable | ||
4272 | 616 | object is called: | ||
4273 | 617 | |||
4274 | 618 | In [4]: callable | ||
4275 | 619 | ------> callable() | ||
4276 | 620 | |||
4277 | 621 | Note that even with autocall off, you can still use '/' at the start of | ||
4278 | 622 | a line to treat the first argument on the command line as a function | ||
4279 | 623 | and add parentheses to it: | ||
4280 | 624 | |||
4281 | 625 | In [8]: /str 43 | ||
4282 | 626 | ------> str(43) | ||
4283 | 627 | Out[8]: '43' | ||
4284 | 628 | |||
4285 | 629 | **%autoindent**:: | ||
4286 | 630 | |||
4287 | 631 | Toggle autoindent on/off (if available). | ||
4288 | 632 | |||
4289 | 633 | **%automagic**:: | ||
4290 | 634 | |||
4291 | 635 | Make magic functions callable without having to type the initial %. | ||
4292 | 636 | |||
4293 | 637 | Without argumentsl toggles on/off (when off, you must call it as | ||
4294 | 638 | %automagic, of course). With arguments it sets the value, and you can | ||
4295 | 639 | use any of (case insensitive): | ||
4296 | 640 | |||
4297 | 641 | - on,1,True: to activate | ||
4298 | 642 | |||
4299 | 643 | - off,0,False: to deactivate. | ||
4300 | 644 | |||
4301 | 645 | Note that magic functions have lowest priority, so if there's a | ||
4302 | 646 | variable whose name collides with that of a magic fn, automagic won't | ||
4303 | 647 | work for that function (you get the variable instead). However, if you | ||
4304 | 648 | delete the variable (del var), the previously shadowed magic function | ||
4305 | 649 | becomes visible to automagic again. | ||
4306 | 650 | |||
4307 | 651 | **%bg**:: | ||
4308 | 652 | |||
4309 | 653 | Run a job in the background, in a separate thread. | ||
4310 | 654 | |||
4311 | 655 | For example, | ||
4312 | 656 | |||
4313 | 657 | %bg myfunc(x,y,z=1) | ||
4314 | 658 | |||
4315 | 659 | will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the | ||
4316 | 660 | execution starts, a message will be printed indicating the job | ||
4317 | 661 | number. If your job number is 5, you can use | ||
4318 | 662 | |||
4319 | 663 | myvar = jobs.result(5) or myvar = jobs[5].result | ||
4320 | 664 | |||
4321 | 665 | to assign this result to variable 'myvar'. | ||
4322 | 666 | |||
4323 | 667 | IPython has a job manager, accessible via the 'jobs' object. You can | ||
4324 | 668 | type jobs? to get more information about it, and use jobs.<TAB> to see | ||
4325 | 669 | its attributes. All attributes not starting with an underscore are | ||
4326 | 670 | meant for public use. | ||
4327 | 671 | |||
4328 | 672 | In particular, look at the jobs.new() method, which is used to create | ||
4329 | 673 | new jobs. This magic %bg function is just a convenience wrapper | ||
4330 | 674 | around jobs.new(), for expression-based jobs. If you want to create a | ||
4331 | 675 | new job with an explicit function object and arguments, you must call | ||
4332 | 676 | jobs.new() directly. | ||
4333 | 677 | |||
4334 | 678 | The jobs.new docstring also describes in detail several important | ||
4335 | 679 | caveats associated with a thread-based model for background job | ||
4336 | 680 | execution. Type jobs.new? for details. | ||
4337 | 681 | |||
4338 | 682 | You can check the status of all jobs with jobs.status(). | ||
4339 | 683 | |||
4340 | 684 | The jobs variable is set by IPython into the Python builtin namespace. | ||
4341 | 685 | If you ever declare a variable named 'jobs', you will shadow this | ||
4342 | 686 | name. You can either delete your global jobs variable to regain | ||
4343 | 687 | access to the job manager, or make a new name and assign it manually | ||
4344 | 688 | to the manager (stored in IPython's namespace). For example, to | ||
4345 | 689 | assign the job manager to the Jobs name, use: | ||
4346 | 690 | |||
4347 | 691 | Jobs = __builtins__.jobs | ||
4348 | 692 | |||
4349 | 693 | **%bookmark**:: | ||
4350 | 694 | |||
4351 | 695 | Manage IPython's bookmark system. | ||
4352 | 696 | |||
4353 | 697 | %bookmark <name> - set bookmark to current dir | ||
4354 | 698 | %bookmark <name> <dir> - set bookmark to <dir> | ||
4355 | 699 | %bookmark -l - list all bookmarks | ||
4356 | 700 | %bookmark -d <name> - remove bookmark | ||
4357 | 701 | %bookmark -r - remove all bookmarks | ||
4358 | 702 | |||
4359 | 703 | You can later on access a bookmarked folder with: | ||
4360 | 704 | %cd -b <name> | ||
4361 | 705 | or simply '%cd <name>' if there is no directory called <name> AND | ||
4362 | 706 | there is such a bookmark defined. | ||
4363 | 707 | |||
4364 | 708 | Your bookmarks persist through IPython sessions, but they are | ||
4365 | 709 | associated with each profile. | ||
4366 | 710 | |||
4367 | 711 | **%cd**:: | ||
4368 | 712 | |||
4369 | 713 | Change the current working directory. | ||
4370 | 714 | |||
4371 | 715 | This command automatically maintains an internal list of directories | ||
4372 | 716 | you visit during your IPython session, in the variable _dh. The | ||
4373 | 717 | command %dhist shows this history nicely formatted. You can also | ||
4374 | 718 | do 'cd -<tab>' to see directory history conveniently. | ||
4375 | 719 | |||
4376 | 720 | Usage: | ||
4377 | 721 | |||
4378 | 722 | cd 'dir': changes to directory 'dir'. | ||
4379 | 723 | |||
4380 | 724 | cd -: changes to the last visited directory. | ||
4381 | 725 | |||
4382 | 726 | cd -<n>: changes to the n-th directory in the directory history. | ||
4383 | 727 | |||
4384 | 728 | cd -b <bookmark_name>: jump to a bookmark set by %bookmark | ||
4385 | 729 | (note: cd <bookmark_name> is enough if there is no | ||
4386 | 730 | directory <bookmark_name>, but a bookmark with the name exists.) | ||
4387 | 731 | 'cd -b <tab>' allows you to tab-complete bookmark names. | ||
4388 | 732 | |||
4389 | 733 | Options: | ||
4390 | 734 | |||
4391 | 735 | -q: quiet. Do not print the working directory after the cd command is | ||
4392 | 736 | executed. By default IPython's cd command does print this directory, | ||
4393 | 737 | since the default prompts do not display path information. | ||
4394 | 738 | |||
4395 | 739 | Note that !cd doesn't work for this purpose because the shell where | ||
4396 | 740 | !command runs is immediately discarded after executing 'command'. | ||
4397 | 741 | |||
4398 | 742 | **%clear**:: | ||
4399 | 743 | |||
4400 | 744 | Clear various data (e.g. stored history data) | ||
4401 | 745 | |||
4402 | 746 | %clear out - clear output history | ||
4403 | 747 | %clear in - clear input history | ||
4404 | 748 | %clear shadow_compress - Compresses shadow history (to speed up ipython) | ||
4405 | 749 | %clear shadow_nuke - permanently erase all entries in shadow history | ||
4406 | 750 | %clear dhist - clear dir history | ||
4407 | 751 | |||
4408 | 752 | **%color_info**:: | ||
4409 | 753 | |||
4410 | 754 | Toggle color_info. | ||
4411 | 755 | |||
4412 | 756 | The color_info configuration parameter controls whether colors are | ||
4413 | 757 | used for displaying object details (by things like %psource, %pfile or | ||
4414 | 758 | the '?' system). This function toggles this value with each call. | ||
4415 | 759 | |||
4416 | 760 | Note that unless you have a fairly recent pager (less works better | ||
4417 | 761 | than more) in your system, using colored object information displays | ||
4418 | 762 | will not work properly. Test it and see. | ||
4419 | 763 | |||
4420 | 764 | **%colors**:: | ||
4421 | 765 | |||
4422 | 766 | Switch color scheme for prompts, info system and exception handlers. | ||
4423 | 767 | |||
4424 | 768 | Currently implemented schemes: NoColor, Linux, LightBG. | ||
4425 | 769 | |||
4426 | 770 | Color scheme names are not case-sensitive. | ||
4427 | 771 | |||
4428 | 772 | **%cpaste**:: | ||
4429 | 773 | |||
4430 | 774 | Allows you to paste & execute a pre-formatted code block from clipboard | ||
4431 | 775 | |||
4432 | 776 | You must terminate the block with '--' (two minus-signs) alone on the | ||
4433 | 777 | line. You can also provide your own sentinel with '%paste -s %%' ('%%' | ||
4434 | 778 | is the new sentinel for this operation) | ||
4435 | 779 | |||
4436 | 780 | The block is dedented prior to execution to enable execution of method | ||
4437 | 781 | definitions. '>' and '+' characters at the beginning of a line are | ||
4438 | 782 | ignored, to allow pasting directly from e-mails or diff files. The | ||
4439 | 783 | executed block is also assigned to variable named 'pasted_block' for | ||
4440 | 784 | later editing with '%edit pasted_block'. | ||
4441 | 785 | |||
4442 | 786 | You can also pass a variable name as an argument, e.g. '%cpaste foo'. | ||
4443 | 787 | This assigns the pasted block to variable 'foo' as string, without | ||
4444 | 788 | dedenting or executing it. | ||
4445 | 789 | |||
4446 | 790 | Do not be alarmed by garbled output on Windows (it's a readline bug). | ||
4447 | 791 | Just press enter and type -- (and press enter again) and the block | ||
4448 | 792 | will be what was just pasted. | ||
4449 | 793 | |||
4450 | 794 | IPython statements (magics, shell escapes) are not supported (yet). | ||
4451 | 795 | |||
4452 | 796 | **%debug**:: | ||
4453 | 797 | |||
4454 | 798 | Activate the interactive debugger in post-mortem mode. | ||
4455 | 799 | |||
4456 | 800 | If an exception has just occurred, this lets you inspect its stack | ||
4457 | 801 | frames interactively. Note that this will always work only on the last | ||
4458 | 802 | traceback that occurred, so you must call this quickly after an | ||
4459 | 803 | exception that you wish to inspect has fired, because if another one | ||
4460 | 804 | occurs, it clobbers the previous one. | ||
4461 | 805 | |||
4462 | 806 | If you want IPython to automatically do this on every exception, see | ||
4463 | 807 | the %pdb magic for more details. | ||
4464 | 808 | |||
4465 | 809 | **%dhist**:: | ||
4466 | 810 | |||
4467 | 811 | Print your history of visited directories. | ||
4468 | 812 | |||
4469 | 813 | %dhist -> print full history\ | ||
4470 | 814 | %dhist n -> print last n entries only\ | ||
4471 | 815 | %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\ | ||
4472 | 816 | |||
4473 | 817 | This history is automatically maintained by the %cd command, and | ||
4474 | 818 | always available as the global list variable _dh. You can use %cd -<n> | ||
4475 | 819 | to go to directory number <n>. | ||
4476 | 820 | |||
4477 | 821 | Note that most of time, you should view directory history by entering | ||
4478 | 822 | cd -<TAB>. | ||
4479 | 823 | |||
4480 | 824 | **%dirs**:: | ||
4481 | 825 | |||
4482 | 826 | Return the current directory stack. | ||
4483 | 827 | |||
4484 | 828 | **%doctest_mode**:: | ||
4485 | 829 | |||
4486 | 830 | Toggle doctest mode on and off. | ||
4487 | 831 | |||
4488 | 832 | This mode allows you to toggle the prompt behavior between normal | ||
4489 | 833 | IPython prompts and ones that are as similar to the default IPython | ||
4490 | 834 | interpreter as possible. | ||
4491 | 835 | |||
4492 | 836 | It also supports the pasting of code snippets that have leading '>>>' | ||
4493 | 837 | and '...' prompts in them. This means that you can paste doctests from | ||
4494 | 838 | files or docstrings (even if they have leading whitespace), and the | ||
4495 | 839 | code will execute correctly. You can then use '%history -tn' to see | ||
4496 | 840 | the translated history without line numbers; this will give you the | ||
4497 | 841 | input after removal of all the leading prompts and whitespace, which | ||
4498 | 842 | can be pasted back into an editor. | ||
4499 | 843 | |||
4500 | 844 | With these features, you can switch into this mode easily whenever you | ||
4501 | 845 | need to do testing and changes to doctests, without having to leave | ||
4502 | 846 | your existing IPython session. | ||
4503 | 847 | |||
4504 | 848 | **%ed**:: | ||
4505 | 849 | |||
4506 | 850 | Alias to %edit. | ||
4507 | 851 | |||
4508 | 852 | **%edit**:: | ||
4509 | 853 | |||
4510 | 854 | Bring up an editor and execute the resulting code. | ||
4511 | 855 | |||
4512 | 856 | Usage: | ||
4513 | 857 | %edit [options] [args] | ||
4514 | 858 | |||
4515 | 859 | %edit runs IPython's editor hook. The default version of this hook is | ||
4516 | 860 | set to call the __IPYTHON__.rc.editor command. This is read from your | ||
4517 | 861 | environment variable $EDITOR. If this isn't found, it will default to | ||
4518 | 862 | vi under Linux/Unix and to notepad under Windows. See the end of this | ||
4519 | 863 | docstring for how to change the editor hook. | ||
4520 | 864 | |||
4521 | 865 | You can also set the value of this editor via the command line option | ||
4522 | 866 | '-editor' or in your ipythonrc file. This is useful if you wish to use | ||
4523 | 867 | specifically for IPython an editor different from your typical default | ||
4524 | 868 | (and for Windows users who typically don't set environment variables). | ||
4525 | 869 | |||
4526 | 870 | This command allows you to conveniently edit multi-line code right in | ||
4527 | 871 | your IPython session. | ||
4528 | 872 | |||
4529 | 873 | If called without arguments, %edit opens up an empty editor with a | ||
4530 | 874 | temporary file and will execute the contents of this file when you | ||
4531 | 875 | close it (don't forget to save it!). | ||
4532 | 876 | |||
4533 | 877 | |||
4534 | 878 | Options: | ||
4535 | 879 | |||
4536 | 880 | -n <number>: open the editor at a specified line number. By default, | ||
4537 | 881 | the IPython editor hook uses the unix syntax 'editor +N filename', but | ||
4538 | 882 | you can configure this by providing your own modified hook if your | ||
4539 | 883 | favorite editor supports line-number specifications with a different | ||
4540 | 884 | syntax. | ||
4541 | 885 | |||
4542 | 886 | -p: this will call the editor with the same data as the previous time | ||
4543 | 887 | it was used, regardless of how long ago (in your current session) it | ||
4544 | 888 | was. | ||
4545 | 889 | |||
4546 | 890 | -r: use 'raw' input. This option only applies to input taken from the | ||
4547 | 891 | user's history. By default, the 'processed' history is used, so that | ||
4548 | 892 | magics are loaded in their transformed version to valid Python. If | ||
4549 | 893 | this option is given, the raw input as typed as the command line is | ||
4550 | 894 | used instead. When you exit the editor, it will be executed by | ||
4551 | 895 | IPython's own processor. | ||
4552 | 896 | |||
4553 | 897 | -x: do not execute the edited code immediately upon exit. This is | ||
4554 | 898 | mainly useful if you are editing programs which need to be called with | ||
4555 | 899 | command line arguments, which you can then do using %run. | ||
4556 | 900 | |||
4557 | 901 | |||
4558 | 902 | Arguments: | ||
4559 | 903 | |||
4560 | 904 | If arguments are given, the following possibilites exist: | ||
4561 | 905 | |||
4562 | 906 | - The arguments are numbers or pairs of colon-separated numbers (like | ||
4563 | 907 | 1 4:8 9). These are interpreted as lines of previous input to be | ||
4564 | 908 | loaded into the editor. The syntax is the same of the %macro command. | ||
4565 | 909 | |||
4566 | 910 | - If the argument doesn't start with a number, it is evaluated as a | ||
4567 | 911 | variable and its contents loaded into the editor. You can thus edit | ||
4568 | 912 | any string which contains python code (including the result of | ||
4569 | 913 | previous edits). | ||
4570 | 914 | |||
4571 | 915 | - If the argument is the name of an object (other than a string), | ||
4572 | 916 | IPython will try to locate the file where it was defined and open the | ||
4573 | 917 | editor at the point where it is defined. You can use `%edit function` | ||
4574 | 918 | to load an editor exactly at the point where 'function' is defined, | ||
4575 | 919 | edit it and have the file be executed automatically. | ||
4576 | 920 | |||
4577 | 921 | If the object is a macro (see %macro for details), this opens up your | ||
4578 | 922 | specified editor with a temporary file containing the macro's data. | ||
4579 | 923 | Upon exit, the macro is reloaded with the contents of the file. | ||
4580 | 924 | |||
4581 | 925 | Note: opening at an exact line is only supported under Unix, and some | ||
4582 | 926 | editors (like kedit and gedit up to Gnome 2.8) do not understand the | ||
4583 | 927 | '+NUMBER' parameter necessary for this feature. Good editors like | ||
4584 | 928 | (X)Emacs, vi, jed, pico and joe all do. | ||
4585 | 929 | |||
4586 | 930 | - If the argument is not found as a variable, IPython will look for a | ||
4587 | 931 | file with that name (adding .py if necessary) and load it into the | ||
4588 | 932 | editor. It will execute its contents with execfile() when you exit, | ||
4589 | 933 | loading any code in the file into your interactive namespace. | ||
4590 | 934 | |||
4591 | 935 | After executing your code, %edit will return as output the code you | ||
4592 | 936 | typed in the editor (except when it was an existing file). This way | ||
4593 | 937 | you can reload the code in further invocations of %edit as a variable, | ||
4594 | 938 | via _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of | ||
4595 | 939 | the output. | ||
4596 | 940 | |||
4597 | 941 | Note that %edit is also available through the alias %ed. | ||
4598 | 942 | |||
4599 | 943 | This is an example of creating a simple function inside the editor and | ||
4600 | 944 | then modifying it. First, start up the editor: | ||
4601 | 945 | |||
4602 | 946 | In [1]: ed\ | ||
4603 | 947 | Editing... done. Executing edited code...\ | ||
4604 | 948 | Out[1]: 'def foo():\n print "foo() was defined in an editing session"\n' | ||
4605 | 949 | |||
4606 | 950 | We can then call the function foo(): | ||
4607 | 951 | |||
4608 | 952 | In [2]: foo()\ | ||
4609 | 953 | foo() was defined in an editing session | ||
4610 | 954 | |||
4611 | 955 | Now we edit foo. IPython automatically loads the editor with the | ||
4612 | 956 | (temporary) file where foo() was previously defined: | ||
4613 | 957 | |||
4614 | 958 | In [3]: ed foo\ | ||
4615 | 959 | Editing... done. Executing edited code... | ||
4616 | 960 | |||
4617 | 961 | And if we call foo() again we get the modified version: | ||
4618 | 962 | |||
4619 | 963 | In [4]: foo()\ | ||
4620 | 964 | foo() has now been changed! | ||
4621 | 965 | |||
4622 | 966 | Here is an example of how to edit a code snippet successive | ||
4623 | 967 | times. First we call the editor: | ||
4624 | 968 | |||
4625 | 969 | In [8]: ed\ | ||
4626 | 970 | Editing... done. Executing edited code...\ | ||
4627 | 971 | hello\ | ||
4628 | 972 | Out[8]: "print 'hello'\n" | ||
4629 | 973 | |||
4630 | 974 | Now we call it again with the previous output (stored in _): | ||
4631 | 975 | |||
4632 | 976 | In [9]: ed _\ | ||
4633 | 977 | Editing... done. Executing edited code...\ | ||
4634 | 978 | hello world\ | ||
4635 | 979 | Out[9]: "print 'hello world'\n" | ||
4636 | 980 | |||
4637 | 981 | Now we call it with the output #8 (stored in _8, also as Out[8]): | ||
4638 | 982 | |||
4639 | 983 | In [10]: ed _8\ | ||
4640 | 984 | Editing... done. Executing edited code...\ | ||
4641 | 985 | hello again\ | ||
4642 | 986 | Out[10]: "print 'hello again'\n" | ||
4643 | 987 | |||
4644 | 988 | |||
4645 | 989 | Changing the default editor hook: | ||
4646 | 990 | |||
4647 | 991 | If you wish to write your own editor hook, you can put it in a | ||
4648 | 992 | configuration file which you load at startup time. The default hook | ||
4649 | 993 | is defined in the IPython.hooks module, and you can use that as a | ||
4650 | 994 | starting example for further modifications. That file also has | ||
4651 | 995 | general instructions on how to set a new hook for use once you've | ||
4652 | 996 | defined it. | ||
4653 | 997 | |||
4654 | 998 | **%env**:: | ||
4655 | 999 | |||
4656 | 1000 | List environment variables. | ||
4657 | 1001 | |||
4658 | 1002 | **%exit**:: | ||
4659 | 1003 | |||
4660 | 1004 | Exit IPython, confirming if configured to do so. | ||
4661 | 1005 | |||
4662 | 1006 | You can configure whether IPython asks for confirmation upon exit by | ||
4663 | 1007 | setting the confirm_exit flag in the ipythonrc file. | ||
4664 | 1008 | |||
4665 | 1009 | **%hist**:: | ||
4666 | 1010 | |||
4667 | 1011 | Alternate name for %history. | ||
4668 | 1012 | |||
4669 | 1013 | **%history**:: | ||
4670 | 1014 | |||
4671 | 1015 | Print input history (_i<n> variables), with most recent last. | ||
4672 | 1016 | |||
4673 | 1017 | %history -> print at most 40 inputs (some may be multi-line)\ | ||
4674 | 1018 | %history n -> print at most n inputs\ | ||
4675 | 1019 | %history n1 n2 -> print inputs between n1 and n2 (n2 not included)\ | ||
4676 | 1020 | |||
4677 | 1021 | Each input's number <n> is shown, and is accessible as the | ||
4678 | 1022 | automatically generated variable _i<n>. Multi-line statements are | ||
4679 | 1023 | printed starting at a new line for easy copy/paste. | ||
4680 | 1024 | |||
4681 | 1025 | |||
4682 | 1026 | Options: | ||
4683 | 1027 | |||
4684 | 1028 | -n: do NOT print line numbers. This is useful if you want to get a | ||
4685 | 1029 | printout of many lines which can be directly pasted into a text | ||
4686 | 1030 | editor. | ||
4687 | 1031 | |||
4688 | 1032 | This feature is only available if numbered prompts are in use. | ||
4689 | 1033 | |||
4690 | 1034 | -t: (default) print the 'translated' history, as IPython understands it. | ||
4691 | 1035 | IPython filters your input and converts it all into valid Python source | ||
4692 | 1036 | before executing it (things like magics or aliases are turned into | ||
4693 | 1037 | function calls, for example). With this option, you'll see the native | ||
4694 | 1038 | history instead of the user-entered version: '%cd /' will be seen as | ||
4695 | 1039 | '_ip.magic("%cd /")' instead of '%cd /'. | ||
4696 | 1040 | |||
4697 | 1041 | -r: print the 'raw' history, i.e. the actual commands you typed. | ||
4698 | 1042 | |||
4699 | 1043 | -g: treat the arg as a pattern to grep for in (full) history. | ||
4700 | 1044 | This includes the "shadow history" (almost all commands ever written). | ||
4701 | 1045 | Use '%hist -g' to show full shadow history (may be very long). | ||
4702 | 1046 | In shadow history, every index nuwber starts with 0. | ||
4703 | 1047 | |||
4704 | 1048 | -f FILENAME: instead of printing the output to the screen, redirect it to | ||
4705 | 1049 | the given file. The file is always overwritten, though IPython asks for | ||
4706 | 1050 | confirmation first if it already exists. | ||
4707 | 1051 | |||
4708 | 1052 | **%logoff**:: | ||
4709 | 1053 | |||
4710 | 1054 | Temporarily stop logging. | ||
4711 | 1055 | |||
4712 | 1056 | You must have previously started logging. | ||
4713 | 1057 | |||
4714 | 1058 | **%logon**:: | ||
4715 | 1059 | |||
4716 | 1060 | Restart logging. | ||
4717 | 1061 | |||
4718 | 1062 | This function is for restarting logging which you've temporarily | ||
4719 | 1063 | stopped with %logoff. For starting logging for the first time, you | ||
4720 | 1064 | must use the %logstart function, which allows you to specify an | ||
4721 | 1065 | optional log filename. | ||
4722 | 1066 | |||
4723 | 1067 | **%logstart**:: | ||
4724 | 1068 | |||
4725 | 1069 | Start logging anywhere in a session. | ||
4726 | 1070 | |||
4727 | 1071 | %logstart [-o|-r|-t] [log_name [log_mode]] | ||
4728 | 1072 | |||
4729 | 1073 | If no name is given, it defaults to a file named 'ipython_log.py' in your | ||
4730 | 1074 | current directory, in 'rotate' mode (see below). | ||
4731 | 1075 | |||
4732 | 1076 | '%logstart name' saves to file 'name' in 'backup' mode. It saves your | ||
4733 | 1077 | history up to that point and then continues logging. | ||
4734 | 1078 | |||
4735 | 1079 | %logstart takes a second optional parameter: logging mode. This can be one | ||
4736 | 1080 | of (note that the modes are given unquoted):\ | ||
4737 | 1081 | append: well, that says it.\ | ||
4738 | 1082 | backup: rename (if exists) to name~ and start name.\ | ||
4739 | 1083 | global: single logfile in your home dir, appended to.\ | ||
4740 | 1084 | over : overwrite existing log.\ | ||
4741 | 1085 | rotate: create rotating logs name.1~, name.2~, etc. | ||
4742 | 1086 | |||
4743 | 1087 | Options: | ||
4744 | 1088 | |||
4745 | 1089 | -o: log also IPython's output. In this mode, all commands which | ||
4746 | 1090 | generate an Out[NN] prompt are recorded to the logfile, right after | ||
4747 | 1091 | their corresponding input line. The output lines are always | ||
4748 | 1092 | prepended with a '#[Out]# ' marker, so that the log remains valid | ||
4749 | 1093 | Python code. | ||
4750 | 1094 | |||
4751 | 1095 | Since this marker is always the same, filtering only the output from | ||
4752 | 1096 | a log is very easy, using for example a simple awk call: | ||
4753 | 1097 | |||
4754 | 1098 | awk -F'#\[Out\]# ' '{if($2) {print $2}}' ipython_log.py | ||
4755 | 1099 | |||
4756 | 1100 | -r: log 'raw' input. Normally, IPython's logs contain the processed | ||
4757 | 1101 | input, so that user lines are logged in their final form, converted | ||
4758 | 1102 | into valid Python. For example, %Exit is logged as | ||
4759 | 1103 | '_ip.magic("Exit"). If the -r flag is given, all input is logged | ||
4760 | 1104 | exactly as typed, with no transformations applied. | ||
4761 | 1105 | |||
4762 | 1106 | -t: put timestamps before each input line logged (these are put in | ||
4763 | 1107 | comments). | ||
4764 | 1108 | |||
4765 | 1109 | **%logstate**:: | ||
4766 | 1110 | |||
4767 | 1111 | Print the status of the logging system. | ||
4768 | 1112 | |||
4769 | 1113 | **%logstop**:: | ||
4770 | 1114 | |||
4771 | 1115 | Fully stop logging and close log file. | ||
4772 | 1116 | |||
4773 | 1117 | In order to start logging again, a new %logstart call needs to be made, | ||
4774 | 1118 | possibly (though not necessarily) with a new filename, mode and other | ||
4775 | 1119 | options. | ||
4776 | 1120 | |||
4777 | 1121 | **%lsmagic**:: | ||
4778 | 1122 | |||
4779 | 1123 | List currently available magic functions. | ||
4780 | 1124 | |||
4781 | 1125 | **%macro**:: | ||
4782 | 1126 | |||
4783 | 1127 | Define a set of input lines as a macro for future re-execution. | ||
4784 | 1128 | |||
4785 | 1129 | Usage:\ | ||
4786 | 1130 | %macro [options] name n1-n2 n3-n4 ... n5 .. n6 ... | ||
4787 | 1131 | |||
4788 | 1132 | Options: | ||
4789 | 1133 | |||
4790 | 1134 | -r: use 'raw' input. By default, the 'processed' history is used, | ||
4791 | 1135 | so that magics are loaded in their transformed version to valid | ||
4792 | 1136 | Python. If this option is given, the raw input as typed as the | ||
4793 | 1137 | command line is used instead. | ||
4794 | 1138 | |||
4795 | 1139 | This will define a global variable called `name` which is a string | ||
4796 | 1140 | made of joining the slices and lines you specify (n1,n2,... numbers | ||
4797 | 1141 | above) from your input history into a single string. This variable | ||
4798 | 1142 | acts like an automatic function which re-executes those lines as if | ||
4799 | 1143 | you had typed them. You just type 'name' at the prompt and the code | ||
4800 | 1144 | executes. | ||
4801 | 1145 | |||
4802 | 1146 | The notation for indicating number ranges is: n1-n2 means 'use line | ||
4803 | 1147 | numbers n1,...n2' (the endpoint is included). That is, '5-7' means | ||
4804 | 1148 | using the lines numbered 5,6 and 7. | ||
4805 | 1149 | |||
4806 | 1150 | Note: as a 'hidden' feature, you can also use traditional python slice | ||
4807 | 1151 | notation, where N:M means numbers N through M-1. | ||
4808 | 1152 | |||
4809 | 1153 | For example, if your history contains (%hist prints it): | ||
4810 | 1154 | |||
4811 | 1155 | 44: x=1\ | ||
4812 | 1156 | 45: y=3\ | ||
4813 | 1157 | 46: z=x+y\ | ||
4814 | 1158 | 47: print x\ | ||
4815 | 1159 | 48: a=5\ | ||
4816 | 1160 | 49: print 'x',x,'y',y\ | ||
4817 | 1161 | |||
4818 | 1162 | you can create a macro with lines 44 through 47 (included) and line 49 | ||
4819 | 1163 | called my_macro with: | ||
4820 | 1164 | |||
4821 | 1165 | In [51]: %macro my_macro 44-47 49 | ||
4822 | 1166 | |||
4823 | 1167 | Now, typing `my_macro` (without quotes) will re-execute all this code | ||
4824 | 1168 | in one pass. | ||
4825 | 1169 | |||
4826 | 1170 | You don't need to give the line-numbers in order, and any given line | ||
4827 | 1171 | number can appear multiple times. You can assemble macros with any | ||
4828 | 1172 | lines from your input history in any order. | ||
4829 | 1173 | |||
4830 | 1174 | The macro is a simple object which holds its value in an attribute, | ||
4831 | 1175 | but IPython's display system checks for macros and executes them as | ||
4832 | 1176 | code instead of printing them when you type their name. | ||
4833 | 1177 | |||
4834 | 1178 | You can view a macro's contents by explicitly printing it with: | ||
4835 | 1179 | |||
4836 | 1180 | 'print macro_name'. | ||
4837 | 1181 | |||
4838 | 1182 | For one-off cases which DON'T contain magic function calls in them you | ||
4839 | 1183 | can obtain similar results by explicitly executing slices from your | ||
4840 | 1184 | input history with: | ||
4841 | 1185 | |||
4842 | 1186 | In [60]: exec In[44:48]+In[49] | ||
4843 | 1187 | |||
4844 | 1188 | **%magic**:: | ||
4845 | 1189 | |||
4846 | 1190 | Print information about the magic function system. | ||
4847 | 1191 | |||
4848 | 1192 | **%mglob**:: | ||
4849 | 1193 | |||
4850 | 1194 | This program allows specifying filenames with "mglob" mechanism. | ||
4851 | 1195 | Supported syntax in globs (wilcard matching patterns):: | ||
4852 | 1196 | |||
4853 | 1197 | *.cpp ?ellowo* | ||
4854 | 1198 | - obvious. Differs from normal glob in that dirs are not included. | ||
4855 | 1199 | Unix users might want to write this as: "*.cpp" "?ellowo*" | ||
4856 | 1200 | rec:/usr/share=*.txt,*.doc | ||
4857 | 1201 | - get all *.txt and *.doc under /usr/share, | ||
4858 | 1202 | recursively | ||
4859 | 1203 | rec:/usr/share | ||
4860 | 1204 | - All files under /usr/share, recursively | ||
4861 | 1205 | rec:*.py | ||
4862 | 1206 | - All .py files under current working dir, recursively | ||
4863 | 1207 | foo | ||
4864 | 1208 | - File or dir foo | ||
4865 | 1209 | !*.bak readme* | ||
4866 | 1210 | - readme*, exclude files ending with .bak | ||
4867 | 1211 | !.svn/ !.hg/ !*_Data/ rec:. | ||
4868 | 1212 | - Skip .svn, .hg, foo_Data dirs (and their subdirs) in recurse. | ||
4869 | 1213 | Trailing / is the key, \ does not work! | ||
4870 | 1214 | dir:foo | ||
4871 | 1215 | - the directory foo if it exists (not files in foo) | ||
4872 | 1216 | dir:* | ||
4873 | 1217 | - all directories in current folder | ||
4874 | 1218 | foo.py bar.* !h* rec:*.py | ||
4875 | 1219 | - Obvious. !h* exclusion only applies for rec:*.py. | ||
4876 | 1220 | foo.py is *not* included twice. | ||
4877 | 1221 | @filelist.txt | ||
4878 | 1222 | - All files listed in 'filelist.txt' file, on separate lines. | ||
4879 | 1223 | |||
4880 | 1224 | **%page**:: | ||
4881 | 1225 | |||
4882 | 1226 | Pretty print the object and display it through a pager. | ||
4883 | 1227 | |||
4884 | 1228 | %page [options] OBJECT | ||
4885 | 1229 | |||
4886 | 1230 | If no object is given, use _ (last output). | ||
4887 | 1231 | |||
4888 | 1232 | Options: | ||
4889 | 1233 | |||
4890 | 1234 | -r: page str(object), don't pretty-print it. | ||
4891 | 1235 | |||
4892 | 1236 | **%pdb**:: | ||
4893 | 1237 | |||
4894 | 1238 | Control the automatic calling of the pdb interactive debugger. | ||
4895 | 1239 | |||
4896 | 1240 | Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without | ||
4897 | 1241 | argument it works as a toggle. | ||
4898 | 1242 | |||
4899 | 1243 | When an exception is triggered, IPython can optionally call the | ||
4900 | 1244 | interactive pdb debugger after the traceback printout. %pdb toggles | ||
4901 | 1245 | this feature on and off. | ||
4902 | 1246 | |||
4903 | 1247 | The initial state of this feature is set in your ipythonrc | ||
4904 | 1248 | configuration file (the variable is called 'pdb'). | ||
4905 | 1249 | |||
4906 | 1250 | If you want to just activate the debugger AFTER an exception has fired, | ||
4907 | 1251 | without having to type '%pdb on' and rerunning your code, you can use | ||
4908 | 1252 | the %debug magic. | ||
4909 | 1253 | |||
4910 | 1254 | **%pdef**:: | ||
4911 | 1255 | |||
4912 | 1256 | Print the definition header for any callable object. | ||
4913 | 1257 | |||
4914 | 1258 | If the object is a class, print the constructor information. | ||
4915 | 1259 | |||
4916 | 1260 | **%pdoc**:: | ||
4917 | 1261 | |||
4918 | 1262 | Print the docstring for an object. | ||
4919 | 1263 | |||
4920 | 1264 | If the given object is a class, it will print both the class and the | ||
4921 | 1265 | constructor docstrings. | ||
4922 | 1266 | |||
4923 | 1267 | **%pfile**:: | ||
4924 | 1268 | |||
4925 | 1269 | Print (or run through pager) the file where an object is defined. | ||
4926 | 1270 | |||
4927 | 1271 | The file opens at the line where the object definition begins. IPython | ||
4928 | 1272 | will honor the environment variable PAGER if set, and otherwise will | ||
4929 | 1273 | do its best to print the file in a convenient form. | ||
4930 | 1274 | |||
4931 | 1275 | If the given argument is not an object currently defined, IPython will | ||
4932 | 1276 | try to interpret it as a filename (automatically adding a .py extension | ||
4933 | 1277 | if needed). You can thus use %pfile as a syntax highlighting code | ||
4934 | 1278 | viewer. | ||
4935 | 1279 | |||
4936 | 1280 | **%pinfo**:: | ||
4937 | 1281 | |||
4938 | 1282 | Provide detailed information about an object. | ||
4939 | 1283 | |||
4940 | 1284 | '%pinfo object' is just a synonym for object? or ?object. | ||
4941 | 1285 | |||
4942 | 1286 | **%popd**:: | ||
4943 | 1287 | |||
4944 | 1288 | Change to directory popped off the top of the stack. | ||
4945 | 1289 | |||
4946 | 1290 | **%profile**:: | ||
4947 | 1291 | |||
4948 | 1292 | Print your currently active IPyhton profile. | ||
4949 | 1293 | |||
4950 | 1294 | **%prun**:: | ||
4951 | 1295 | |||
4952 | 1296 | Run a statement through the python code profiler. | ||
4953 | 1297 | |||
4954 | 1298 | Usage:\ | ||
4955 | 1299 | %prun [options] statement | ||
4956 | 1300 | |||
4957 | 1301 | The given statement (which doesn't require quote marks) is run via the | ||
4958 | 1302 | python profiler in a manner similar to the profile.run() function. | ||
4959 | 1303 | Namespaces are internally managed to work correctly; profile.run | ||
4960 | 1304 | cannot be used in IPython because it makes certain assumptions about | ||
4961 | 1305 | namespaces which do not hold under IPython. | ||
4962 | 1306 | |||
4963 | 1307 | Options: | ||
4964 | 1308 | |||
4965 | 1309 | -l <limit>: you can place restrictions on what or how much of the | ||
4966 | 1310 | profile gets printed. The limit value can be: | ||
4967 | 1311 | |||
4968 | 1312 | * A string: only information for function names containing this string | ||
4969 | 1313 | is printed. | ||
4970 | 1314 | |||
4971 | 1315 | * An integer: only these many lines are printed. | ||
4972 | 1316 | |||
4973 | 1317 | * A float (between 0 and 1): this fraction of the report is printed | ||
4974 | 1318 | (for example, use a limit of 0.4 to see the topmost 40% only). | ||
4975 | 1319 | |||
4976 | 1320 | You can combine several limits with repeated use of the option. For | ||
4977 | 1321 | example, '-l __init__ -l 5' will print only the topmost 5 lines of | ||
4978 | 1322 | information about class constructors. | ||
4979 | 1323 | |||
4980 | 1324 | -r: return the pstats.Stats object generated by the profiling. This | ||
4981 | 1325 | object has all the information about the profile in it, and you can | ||
4982 | 1326 | later use it for further analysis or in other functions. | ||
4983 | 1327 | |||
4984 | 1328 | -s <key>: sort profile by given key. You can provide more than one key | ||
4985 | 1329 | by using the option several times: '-s key1 -s key2 -s key3...'. The | ||
4986 | 1330 | default sorting key is 'time'. | ||
4987 | 1331 | |||
4988 | 1332 | The following is copied verbatim from the profile documentation | ||
4989 | 1333 | referenced below: | ||
4990 | 1334 | |||
4991 | 1335 | When more than one key is provided, additional keys are used as | ||
4992 | 1336 | secondary criteria when the there is equality in all keys selected | ||
4993 | 1337 | before them. | ||
4994 | 1338 | |||
4995 | 1339 | Abbreviations can be used for any key names, as long as the | ||
4996 | 1340 | abbreviation is unambiguous. The following are the keys currently | ||
4997 | 1341 | defined: | ||
4998 | 1342 | |||
4999 | 1343 | Valid Arg Meaning\ | ||
5000 | 1344 | "calls" call count\ |
I had to nuke my lp copy of my trunk because I did some local patch reordering, so I've just re-uploaded a fresh copy. The code is the same as before.
Ready for review.