Show More
@@ -1,270 +1,272 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """Modified input prompt for executing files. |
|
2 | """Modified input prompt for executing files. | |
3 |
|
3 | |||
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 | |
5 | '~', '/' or '.'. If one of those strings is encountered, it is automatically |
|
5 | '~', '/' or '.'. If one of those strings is encountered, it is automatically | |
6 | executed. |
|
6 | executed. | |
7 |
|
7 | |||
8 |
$Id: InterpreterExec.py |
|
8 | $Id: InterpreterExec.py 638 2005-07-18 03:01:41Z fperez $""" | |
9 |
|
9 | |||
10 | #***************************************************************************** |
|
10 | #***************************************************************************** | |
11 | # Copyright (C) 2004 W.J. van der Laan <gnufnork@hetdigitalegat.nl> |
|
11 | # Copyright (C) 2004 W.J. van der Laan <gnufnork@hetdigitalegat.nl> | |
12 | # Copyright (C) 2004 Fernando Perez <fperez@colorado.edu> |
|
12 | # Copyright (C) 2004 Fernando Perez <fperez@colorado.edu> | |
13 | # |
|
13 | # | |
14 | # Distributed under the terms of the BSD License. The full license is in |
|
14 | # Distributed under the terms of the BSD License. The full license is in | |
15 | # the file COPYING, distributed as part of this software. |
|
15 | # the file COPYING, distributed as part of this software. | |
16 | #***************************************************************************** |
|
16 | #***************************************************************************** | |
17 |
|
17 | |||
18 | from IPython import Release |
|
18 | from IPython import Release | |
19 | __author__ = 'W.J. van der Laan <gnufnork@hetdigitalegat.nl>, '\ |
|
19 | __author__ = 'W.J. van der Laan <gnufnork@hetdigitalegat.nl>, '\ | |
20 | '%s <%s>' % Release.authors['Fernando'] |
|
20 | '%s <%s>' % Release.authors['Fernando'] | |
21 | __license__ = Release.license |
|
21 | __license__ = Release.license | |
22 |
|
22 | |||
23 | def prefilter_shell(self,line,continuation): |
|
23 | def prefilter_shell(self,line,continuation): | |
24 | """Alternate prefilter, modified for shell-like functionality. |
|
24 | """Alternate prefilter, modified for shell-like functionality. | |
25 |
|
25 | |||
26 | - Execute all lines beginning with '~', '/' or '.' |
|
26 | - Execute all lines beginning with '~', '/' or '.' | |
27 | - $var=cmd <=> %sc var=cmd |
|
27 | - $var=cmd <=> %sc var=cmd | |
28 | - $$var=cmd <=> %sc -l var=cmd |
|
28 | - $$var=cmd <=> %sc -l var=cmd | |
29 | """ |
|
29 | """ | |
30 |
|
30 | |||
31 | if line: |
|
31 | if line: | |
32 | l0 = line[0] |
|
32 | l0 = line[0] | |
33 | if l0 in '~/.': |
|
33 | if l0 in '~/.': | |
34 | return self._prefilter("!%s"%line,continuation) |
|
34 | return self._prefilter("!%s"%line,continuation) | |
35 | elif l0=='$': |
|
35 | elif l0=='$': | |
36 | lrest = line[1:] |
|
36 | lrest = line[1:] | |
37 | if lrest.startswith('$'): |
|
37 | if lrest.startswith('$'): | |
38 | # $$var=cmd <=> %sc -l var=cmd |
|
38 | # $$var=cmd <=> %sc -l var=cmd | |
39 | return self._prefilter("%ssc -l %s" % (self.ESC_MAGIC,lrest[1:]), |
|
39 | return self._prefilter("%ssc -l %s" % (self.ESC_MAGIC,lrest[1:]), | |
40 | continuation) |
|
40 | continuation) | |
41 | else: |
|
41 | else: | |
42 | # $var=cmd <=> %sc var=cmd |
|
42 | # $var=cmd <=> %sc var=cmd | |
43 | return self._prefilter("%ssc %s" % (self.ESC_MAGIC,lrest), |
|
43 | return self._prefilter("%ssc %s" % (self.ESC_MAGIC,lrest), | |
44 | continuation) |
|
44 | continuation) | |
45 | else: |
|
45 | else: | |
46 | return self._prefilter(line,continuation) |
|
46 | return self._prefilter(line,continuation) | |
47 | else: |
|
47 | else: | |
48 | return self._prefilter(line,continuation) |
|
48 | return self._prefilter(line,continuation) | |
49 |
|
49 | |||
50 | # Rebind this to be the new IPython prefilter: |
|
50 | # Rebind this to be the new IPython prefilter: | |
51 | from IPython.iplib import InteractiveShell |
|
51 | from IPython.iplib import InteractiveShell | |
52 | InteractiveShell.prefilter = prefilter_shell |
|
52 | InteractiveShell.prefilter = prefilter_shell | |
53 | # Clean up the namespace. |
|
53 | # Clean up the namespace. | |
54 | del InteractiveShell,prefilter_shell |
|
54 | del InteractiveShell,prefilter_shell | |
55 |
|
55 | |||
56 | # Provide pysh and further shell-oriented services |
|
56 | # Provide pysh and further shell-oriented services | |
57 | import os,sys,shutil |
|
57 | import os,sys,shutil | |
58 | from IPython.genutils import system,shell,getoutput,getoutputerror |
|
58 | from IPython.genutils import system,shell,getoutput,getoutputerror | |
59 |
|
59 | |||
60 | # Short aliases for getting shell output as a string and a list |
|
60 | # Short aliases for getting shell output as a string and a list | |
61 | sout = getoutput |
|
61 | sout = getoutput | |
62 | lout = lambda cmd: getoutput(cmd,split=1) |
|
62 | lout = lambda cmd: getoutput(cmd,split=1) | |
63 |
|
63 | |||
64 | # Empty function, meant as a docstring holder so help(pysh) works. |
|
64 | # Empty function, meant as a docstring holder so help(pysh) works. | |
65 | def pysh(): |
|
65 | def pysh(): | |
66 | """Pysh is a set of modules and extensions to IPython which make shell-like |
|
66 | """Pysh is a set of modules and extensions to IPython which make shell-like | |
67 | usage with Python syntax more convenient. Keep in mind that pysh is NOT a |
|
67 | usage with Python syntax more convenient. Keep in mind that pysh is NOT a | |
68 | full-blown shell, so don't try to make it your /etc/passwd entry! |
|
68 | full-blown shell, so don't try to make it your /etc/passwd entry! | |
69 |
|
69 | |||
70 | In particular, it has no job control, so if you type Ctrl-Z (under Unix), |
|
70 | In particular, it has no job control, so if you type Ctrl-Z (under Unix), | |
71 | you'll suspend pysh itself, not the process you just started. |
|
71 | you'll suspend pysh itself, not the process you just started. | |
72 |
|
72 | |||
73 | Since pysh is really nothing but a customized IPython, you should |
|
73 | Since pysh is really nothing but a customized IPython, you should | |
74 | familiarize yourself with IPython's features. This brief help mainly |
|
74 | familiarize yourself with IPython's features. This brief help mainly | |
75 | documents areas in which pysh differs from the normal IPython. |
|
75 | documents areas in which pysh differs from the normal IPython. | |
76 |
|
76 | |||
77 | ALIASES |
|
77 | ALIASES | |
78 | ------- |
|
78 | ------- | |
79 | All of your $PATH has been loaded as IPython aliases, so you should be |
|
79 | All of your $PATH has been loaded as IPython aliases, so you should be | |
80 | able to type any normal system command and have it executed. See %alias? |
|
80 | able to type any normal system command and have it executed. See %alias? | |
81 | and %unalias? for details on the alias facilities. |
|
81 | and %unalias? for details on the alias facilities. | |
82 |
|
82 | |||
83 | SPECIAL SYNTAX |
|
83 | SPECIAL SYNTAX | |
84 | -------------- |
|
84 | -------------- | |
85 | Any lines which begin with '~', '/' and '.' will be executed as shell |
|
85 | Any lines which begin with '~', '/' and '.' will be executed as shell | |
86 | commands instead of as Python code. The special escapes below are also |
|
86 | commands instead of as Python code. The special escapes below are also | |
87 | recognized. !cmd is valid in single or multi-line input, all others are |
|
87 | recognized. !cmd is valid in single or multi-line input, all others are | |
88 | only valid in single-line input: |
|
88 | only valid in single-line input: | |
89 |
|
89 | |||
90 | !cmd - pass 'cmd' directly to the shell |
|
90 | !cmd - pass 'cmd' directly to the shell | |
91 | !!cmd - execute 'cmd' and return output as a list (split on '\\n') |
|
91 | !!cmd - execute 'cmd' and return output as a list (split on '\\n') | |
92 | $var=cmd - capture output of cmd into var, as a string |
|
92 | $var=cmd - capture output of cmd into var, as a string | |
93 | $$var=cmd - capture output of cmd into var, as a list (split on '\\n') |
|
93 | $$var=cmd - capture output of cmd into var, as a list (split on '\\n') | |
94 |
|
94 | |||
95 | The $/$$ syntaxes make Python variables from system output, which you can |
|
95 | The $/$$ syntaxes make Python variables from system output, which you can | |
96 | later use for further scripting. The converse is also possible: when |
|
96 | later use for further scripting. The converse is also possible: when | |
97 | executing an alias or calling to the system via !/!!, you can expand any |
|
97 | executing an alias or calling to the system via !/!!, you can expand any | |
98 | python variable or expression by prepending it with $. Full details of |
|
98 | python variable or expression by prepending it with $. Full details of | |
99 | the allowed syntax can be found in Python's PEP 215. |
|
99 | the allowed syntax can be found in Python's PEP 215. | |
100 |
|
100 | |||
101 | A few brief examples will illustrate these: |
|
101 | A few brief examples will illustrate these: | |
102 |
|
102 | |||
103 | fperez[~/test]|3> !ls *s.py |
|
103 | fperez[~/test]|3> !ls *s.py | |
104 | scopes.py strings.py |
|
104 | scopes.py strings.py | |
105 |
|
105 | |||
106 | ls is an internal alias, so there's no need to use !: |
|
106 | ls is an internal alias, so there's no need to use !: | |
107 | fperez[~/test]|4> ls *s.py |
|
107 | fperez[~/test]|4> ls *s.py | |
108 | scopes.py* strings.py |
|
108 | scopes.py* strings.py | |
109 |
|
109 | |||
110 | !!ls will return the output into a Python variable: |
|
110 | !!ls will return the output into a Python variable: | |
111 | fperez[~/test]|5> !!ls *s.py |
|
111 | fperez[~/test]|5> !!ls *s.py | |
112 | <5> ['scopes.py', 'strings.py'] |
|
112 | <5> ['scopes.py', 'strings.py'] | |
113 | fperez[~/test]|6> print _5 |
|
113 | fperez[~/test]|6> print _5 | |
114 | ['scopes.py', 'strings.py'] |
|
114 | ['scopes.py', 'strings.py'] | |
115 |
|
115 | |||
116 | $ and $$ allow direct capture to named variables: |
|
116 | $ and $$ allow direct capture to named variables: | |
117 | fperez[~/test]|7> $astr = ls *s.py |
|
117 | fperez[~/test]|7> $astr = ls *s.py | |
118 | fperez[~/test]|8> astr |
|
118 | fperez[~/test]|8> astr | |
119 | <8> 'scopes.py\\nstrings.py' |
|
119 | <8> 'scopes.py\\nstrings.py' | |
120 |
|
120 | |||
121 | fperez[~/test]|9> $$alist = ls *s.py |
|
121 | fperez[~/test]|9> $$alist = ls *s.py | |
122 | fperez[~/test]|10> alist |
|
122 | fperez[~/test]|10> alist | |
123 | <10> ['scopes.py', 'strings.py'] |
|
123 | <10> ['scopes.py', 'strings.py'] | |
124 |
|
124 | |||
125 | alist is now a normal python list you can loop over. Using $ will expand |
|
125 | alist is now a normal python list you can loop over. Using $ will expand | |
126 | back the python values when alias calls are made: |
|
126 | back the python values when alias calls are made: | |
127 | fperez[~/test]|11> for f in alist: |
|
127 | fperez[~/test]|11> for f in alist: | |
128 | |..> print 'file',f, |
|
128 | |..> print 'file',f, | |
129 | |..> wc -l $f |
|
129 | |..> wc -l $f | |
130 | |..> |
|
130 | |..> | |
131 | file scopes.py 13 scopes.py |
|
131 | file scopes.py 13 scopes.py | |
132 | file strings.py 4 strings.py |
|
132 | file strings.py 4 strings.py | |
133 |
|
133 | |||
134 | Note that you may need to protect your variables with braces if you want |
|
134 | Note that you may need to protect your variables with braces if you want | |
135 | to append strings to their names. To copy all files in alist to .bak |
|
135 | to append strings to their names. To copy all files in alist to .bak | |
136 | extensions, you must use: |
|
136 | extensions, you must use: | |
137 | fperez[~/test]|12> for f in alist: |
|
137 | fperez[~/test]|12> for f in alist: | |
138 | |..> cp $f ${f}.bak |
|
138 | |..> cp $f ${f}.bak | |
139 |
|
139 | |||
140 | If you try using $f.bak, you'll get an AttributeError exception saying |
|
140 | If you try using $f.bak, you'll get an AttributeError exception saying | |
141 | that your string object doesn't have a .bak attribute. This is because |
|
141 | that your string object doesn't have a .bak attribute. This is because | |
142 | the $ expansion mechanism allows you to expand full Python expressions: |
|
142 | the $ expansion mechanism allows you to expand full Python expressions: | |
143 | fperez[~/test]|13> echo "sys.platform is: $sys.platform" |
|
143 | fperez[~/test]|13> echo "sys.platform is: $sys.platform" | |
144 | sys.platform is: linux2 |
|
144 | sys.platform is: linux2 | |
145 |
|
145 | |||
146 | IPython's input history handling is still active, which allows you to |
|
146 | IPython's input history handling is still active, which allows you to | |
147 | rerun a single block of multi-line input by simply using exec: |
|
147 | rerun a single block of multi-line input by simply using exec: | |
148 | fperez[~/test]|14> $$alist = ls *.eps |
|
148 | fperez[~/test]|14> $$alist = ls *.eps | |
149 | fperez[~/test]|15> exec _i11 |
|
149 | fperez[~/test]|15> exec _i11 | |
150 | file image2.eps 921 image2.eps |
|
150 | file image2.eps 921 image2.eps | |
151 | file image.eps 921 image.eps |
|
151 | file image.eps 921 image.eps | |
152 |
|
152 | |||
153 | While these are new special-case syntaxes, they are designed to allow very |
|
153 | While these are new special-case syntaxes, they are designed to allow very | |
154 | efficient use of the shell with minimal typing. At an interactive shell |
|
154 | efficient use of the shell with minimal typing. At an interactive shell | |
155 | prompt, conciseness of expression wins over readability. |
|
155 | prompt, conciseness of expression wins over readability. | |
156 |
|
156 | |||
157 | USEFUL FUNCTIONS AND MODULES |
|
157 | USEFUL FUNCTIONS AND MODULES | |
158 | ---------------------------- |
|
158 | ---------------------------- | |
159 | The os, sys and shutil modules from the Python standard library are |
|
159 | The os, sys and shutil modules from the Python standard library are | |
160 | automatically loaded. Some additional functions, useful for shell usage, |
|
160 | automatically loaded. Some additional functions, useful for shell usage, | |
161 | are listed below. You can request more help about them with '?'. |
|
161 | are listed below. You can request more help about them with '?'. | |
162 |
|
162 | |||
163 | shell - execute a command in the underlying system shell |
|
163 | shell - execute a command in the underlying system shell | |
164 | system - like shell(), but return the exit status of the command |
|
164 | system - like shell(), but return the exit status of the command | |
165 | sout - capture the output of a command as a string |
|
165 | sout - capture the output of a command as a string | |
166 | lout - capture the output of a command as a list (split on '\\n') |
|
166 | lout - capture the output of a command as a list (split on '\\n') | |
167 | getoutputerror - capture (output,error) of a shell command |
|
167 | getoutputerror - capture (output,error) of a shell command | |
168 |
|
168 | |||
169 | sout/lout are the functional equivalents of $/$$. They are provided to |
|
169 | sout/lout are the functional equivalents of $/$$. They are provided to | |
170 | allow you to capture system output in the middle of true python code, |
|
170 | allow you to capture system output in the middle of true python code, | |
171 | function definitions, etc (where $ and $$ are invalid). |
|
171 | function definitions, etc (where $ and $$ are invalid). | |
172 |
|
172 | |||
173 | DIRECTORY MANAGEMENT |
|
173 | DIRECTORY MANAGEMENT | |
174 | -------------------- |
|
174 | -------------------- | |
175 | Since each command passed by pysh to the underlying system is executed in |
|
175 | Since each command passed by pysh to the underlying system is executed in | |
176 | a subshell which exits immediately, you can NOT use !cd to navigate the |
|
176 | a subshell which exits immediately, you can NOT use !cd to navigate the | |
177 | filesystem. |
|
177 | filesystem. | |
178 |
|
178 | |||
179 | Pysh provides its own builtin '%cd' magic command to move in the |
|
179 | Pysh provides its own builtin '%cd' magic command to move in the | |
180 | filesystem (the % is not required with automagic on). It also maintains a |
|
180 | filesystem (the % is not required with automagic on). It also maintains a | |
181 | list of visited directories (use %dhist to see it) and allows direct |
|
181 | list of visited directories (use %dhist to see it) and allows direct | |
182 | switching to any of them. Type 'cd?' for more details. |
|
182 | switching to any of them. Type 'cd?' for more details. | |
183 |
|
183 | |||
184 | %pushd, %popd and %dirs are provided for directory stack handling. |
|
184 | %pushd, %popd and %dirs are provided for directory stack handling. | |
185 |
|
185 | |||
186 | PROMPT CUSTOMIZATION |
|
186 | PROMPT CUSTOMIZATION | |
187 | -------------------- |
|
187 | -------------------- | |
188 |
|
188 | |||
189 | The supplied ipythonrc-pysh profile comes with an example of a very |
|
189 | The supplied ipythonrc-pysh profile comes with an example of a very | |
190 | colored and detailed prompt, mainly to serve as an illustration. The |
|
190 | colored and detailed prompt, mainly to serve as an illustration. The | |
191 | valid escape sequences, besides color names, are: |
|
191 | valid escape sequences, besides color names, are: | |
192 |
|
192 | |||
193 | \\# - Prompt number. |
|
193 | \\# - Prompt number. | |
194 | \\D - Dots, as many as there are digits in \\# (so they align). |
|
194 | \\D - Dots, as many as there are digits in \\# (so they align). | |
195 | \\w - Current working directory (cwd). |
|
195 | \\w - Current working directory (cwd). | |
196 | \\W - Basename of current working directory. |
|
196 | \\W - Basename of current working directory. | |
197 | \\XN - Where N=0..5. N terms of the cwd, with $HOME written as ~. |
|
197 | \\XN - Where N=0..5. N terms of the cwd, with $HOME written as ~. | |
198 | \\YN - Where N=0..5. Like XN, but if ~ is term N+1 it's also shown. |
|
198 | \\YN - Where N=0..5. Like XN, but if ~ is term N+1 it's also shown. | |
199 | \\u - Username. |
|
199 | \\u - Username. | |
200 | \\H - Full hostname. |
|
200 | \\H - Full hostname. | |
201 | \\h - Hostname up to first '.' |
|
201 | \\h - Hostname up to first '.' | |
202 | \\$ - Root symbol ($ or #). |
|
202 | \\$ - Root symbol ($ or #). | |
203 | \\t - Current time, in H:M:S format. |
|
203 | \\t - Current time, in H:M:S format. | |
204 | \\v - IPython release version. |
|
204 | \\v - IPython release version. | |
205 | \\n - Newline. |
|
205 | \\n - Newline. | |
206 | \\r - Carriage return. |
|
206 | \\r - Carriage return. | |
207 | \\\\ - An explicitly escaped '\\'. |
|
207 | \\\\ - An explicitly escaped '\\'. | |
208 |
|
208 | |||
209 | You can configure your prompt colors using any ANSI color escape. Each |
|
209 | You can configure your prompt colors using any ANSI color escape. Each | |
210 | color escape sets the color for any subsequent text, until another escape |
|
210 | color escape sets the color for any subsequent text, until another escape | |
211 | comes in and changes things. The valid color escapes are: |
|
211 | comes in and changes things. The valid color escapes are: | |
212 |
|
212 | |||
213 | \\C_Black |
|
213 | \\C_Black | |
214 | \\C_Blue |
|
214 | \\C_Blue | |
215 | \\C_Brown |
|
215 | \\C_Brown | |
216 | \\C_Cyan |
|
216 | \\C_Cyan | |
217 | \\C_DarkGray |
|
217 | \\C_DarkGray | |
218 | \\C_Green |
|
218 | \\C_Green | |
219 | \\C_LightBlue |
|
219 | \\C_LightBlue | |
220 | \\C_LightCyan |
|
220 | \\C_LightCyan | |
221 | \\C_LightGray |
|
221 | \\C_LightGray | |
222 | \\C_LightGreen |
|
222 | \\C_LightGreen | |
223 | \\C_LightPurple |
|
223 | \\C_LightPurple | |
224 | \\C_LightRed |
|
224 | \\C_LightRed | |
225 | \\C_Purple |
|
225 | \\C_Purple | |
226 | \\C_Red |
|
226 | \\C_Red | |
227 | \\C_White |
|
227 | \\C_White | |
228 | \\C_Yellow |
|
228 | \\C_Yellow | |
229 | \\C_Normal - Stop coloring, defaults to your terminal settings. |
|
229 | \\C_Normal - Stop coloring, defaults to your terminal settings. | |
230 | """ |
|
230 | """ | |
231 | pass |
|
231 | pass | |
232 |
|
232 | |||
233 | # Configure a few things. Much of this is fairly hackish, since IPython |
|
233 | # Configure a few things. Much of this is fairly hackish, since IPython | |
234 | # doesn't really expose a clean API for it. Be careful if you start making |
|
234 | # doesn't really expose a clean API for it. Be careful if you start making | |
235 | # many modifications here. |
|
235 | # many modifications here. | |
236 |
|
236 | |||
237 | print """\ |
|
237 | print """\ | |
238 | Welcome to pysh, a set of extensions to IPython for shell usage. |
|
238 | Welcome to pysh, a set of extensions to IPython for shell usage. | |
239 | help(pysh) -> help on the installed shell extensions and syntax. |
|
239 | help(pysh) -> help on the installed shell extensions and syntax. | |
240 | """ |
|
240 | """ | |
241 |
|
241 | |||
242 | # Set the 'cd' command to quiet mode, a more shell-like behavior |
|
242 | # Set the 'cd' command to quiet mode, a more shell-like behavior | |
243 | __IPYTHON__.default_option('cd','-q') |
|
243 | __IPYTHON__.default_option('cd','-q') | |
244 |
|
244 | |||
245 | # Load all of $PATH as aliases |
|
245 | # Load all of $PATH as aliases | |
246 | if os.name == 'posix': |
|
246 | if os.name == 'posix': | |
247 | # %rehash is very fast, but it doesn't check for executability, it simply |
|
247 | # %rehash is very fast, but it doesn't check for executability, it simply | |
248 | # dumps everything in $PATH as an alias. Use rehashx if you want more |
|
248 | # dumps everything in $PATH as an alias. Use rehashx if you want more | |
249 | # checks. |
|
249 | # checks. | |
250 | __IPYTHON__.magic_rehash() |
|
250 | __IPYTHON__.magic_rehash() | |
251 | else: |
|
251 | else: | |
252 | # Windows users: the list of extensions considered executable is read from |
|
252 | # Windows users: the list of extensions considered executable is read from | |
253 | # the environment variable 'pathext'. If this is undefined, IPython |
|
253 | # the environment variable 'pathext'. If this is undefined, IPython | |
254 | # defaults to EXE, COM and BAT. |
|
254 | # defaults to EXE, COM and BAT. | |
255 | # %rehashx is the one which does extension analysis, at the cost of |
|
255 | # %rehashx is the one which does extension analysis, at the cost of | |
256 | # being much slower than %rehash. |
|
256 | # being much slower than %rehash. | |
257 | __IPYTHON__.magic_rehashx() |
|
257 | __IPYTHON__.magic_rehashx() | |
258 |
|
258 | |||
259 | # Remove %sc,%sx if present as aliases |
|
259 | # Remove %sc,%sx if present as aliases | |
260 | __IPYTHON__.magic_unalias('sc') |
|
260 | __IPYTHON__.magic_unalias('sc') | |
261 | __IPYTHON__.magic_unalias('sx') |
|
261 | __IPYTHON__.magic_unalias('sx') | |
262 |
|
262 | |||
263 | # We need different criteria for line-splitting, so that aliases such as |
|
263 | # We need different criteria for line-splitting, so that aliases such as | |
264 | # 'gnome-terminal' are interpreted as a single alias instead of variable |
|
264 | # 'gnome-terminal' are interpreted as a single alias instead of variable | |
265 | # 'gnome' minus variable 'terminal'. |
|
265 | # 'gnome' minus variable 'terminal'. | |
266 | import re |
|
266 | import re | |
267 |
__IPYTHON__.line_split = re.compile(r'^(\s* |
|
267 | __IPYTHON__.line_split = re.compile(r'^([\s*,;/])' | |
|
268 | r'([\?\w\.\-\+]+\w*\s*)' | |||
|
269 | r'(\(?.*$)') | |||
268 |
|
270 | |||
269 | # Namespace cleanup |
|
271 | # Namespace cleanup | |
270 | del re |
|
272 | del re |
@@ -1,199 +1,192 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """Word completion for GNU readline 2.0. |
|
2 | """Word completion for GNU readline 2.0. | |
3 |
|
3 | |||
4 | --------------------------------------------------------------------------- |
|
4 | --------------------------------------------------------------------------- | |
5 | NOTE: This version is a re-implementation of rlcompleter with selectable |
|
5 | NOTE: This version is a re-implementation of rlcompleter with selectable | |
6 | namespace. |
|
6 | namespace. | |
7 |
|
7 | |||
8 | The problem with rlcompleter is that it's hardwired to work with |
|
8 | The problem with rlcompleter is that it's hardwired to work with | |
9 | __main__.__dict__, and in some cases one may have 'sandboxed' namespaces. So |
|
9 | __main__.__dict__, and in some cases one may have 'sandboxed' namespaces. So | |
10 | this class is a ripoff of rlcompleter, with the namespace to work in as an |
|
10 | this class is a ripoff of rlcompleter, with the namespace to work in as an | |
11 | optional parameter. |
|
11 | optional parameter. | |
12 |
|
12 | |||
13 | This class can be used just like rlcompleter, but the Completer class now has |
|
13 | This class can be used just like rlcompleter, but the Completer class now has | |
14 | a constructor with the optional 'namespace' parameter. |
|
14 | a constructor with the optional 'namespace' parameter. | |
15 |
|
15 | |||
16 | A patch has been submitted to Python@sourceforge for these changes to go in |
|
16 | A patch has been submitted to Python@sourceforge for these changes to go in | |
17 | the standard Python distribution. |
|
17 | the standard Python distribution. | |
18 |
|
18 | |||
19 | The patch went in for Python 2.3. Once IPython drops support for Python 2.2, |
|
19 | The patch went in for Python 2.3. Once IPython drops support for Python 2.2, | |
20 | this file can be significantly reduced. |
|
20 | this file can be significantly reduced. | |
21 | --------------------------------------------------------------------------- |
|
21 | --------------------------------------------------------------------------- | |
22 |
|
22 | |||
23 | Original rlcompleter documentation: |
|
23 | Original rlcompleter documentation: | |
24 |
|
24 | |||
25 | This requires the latest extension to the readline module (the |
|
25 | This requires the latest extension to the readline module (the | |
26 | completes keywords, built-ins and globals in __main__; when completing |
|
26 | completes keywords, built-ins and globals in __main__; when completing | |
27 | NAME.NAME..., it evaluates (!) the expression up to the last dot and |
|
27 | NAME.NAME..., it evaluates (!) the expression up to the last dot and | |
28 | completes its attributes. |
|
28 | completes its attributes. | |
29 |
|
29 | |||
30 | It's very cool to do "import string" type "string.", hit the |
|
30 | It's very cool to do "import string" type "string.", hit the | |
31 | completion key (twice), and see the list of names defined by the |
|
31 | completion key (twice), and see the list of names defined by the | |
32 | string module! |
|
32 | string module! | |
33 |
|
33 | |||
34 | Tip: to use the tab key as the completion key, call |
|
34 | Tip: to use the tab key as the completion key, call | |
35 |
|
35 | |||
36 | readline.parse_and_bind("tab: complete") |
|
36 | readline.parse_and_bind("tab: complete") | |
37 |
|
37 | |||
38 | Notes: |
|
38 | Notes: | |
39 |
|
39 | |||
40 | - Exceptions raised by the completer function are *ignored* (and |
|
40 | - Exceptions raised by the completer function are *ignored* (and | |
41 | generally cause the completion to fail). This is a feature -- since |
|
41 | generally cause the completion to fail). This is a feature -- since | |
42 | readline sets the tty device in raw (or cbreak) mode, printing a |
|
42 | readline sets the tty device in raw (or cbreak) mode, printing a | |
43 | traceback wouldn't work well without some complicated hoopla to save, |
|
43 | traceback wouldn't work well without some complicated hoopla to save, | |
44 | reset and restore the tty state. |
|
44 | reset and restore the tty state. | |
45 |
|
45 | |||
46 | - The evaluation of the NAME.NAME... form may cause arbitrary |
|
46 | - The evaluation of the NAME.NAME... form may cause arbitrary | |
47 | application defined code to be executed if an object with a |
|
47 | application defined code to be executed if an object with a | |
48 | __getattr__ hook is found. Since it is the responsibility of the |
|
48 | __getattr__ hook is found. Since it is the responsibility of the | |
49 | application (or the user) to enable this feature, I consider this an |
|
49 | application (or the user) to enable this feature, I consider this an | |
50 | acceptable risk. More complicated expressions (e.g. function calls or |
|
50 | acceptable risk. More complicated expressions (e.g. function calls or | |
51 | indexing operations) are *not* evaluated. |
|
51 | indexing operations) are *not* evaluated. | |
52 |
|
52 | |||
53 | - GNU readline is also used by the built-in functions input() and |
|
53 | - GNU readline is also used by the built-in functions input() and | |
54 | raw_input(), and thus these also benefit/suffer from the completer |
|
54 | raw_input(), and thus these also benefit/suffer from the completer | |
55 | features. Clearly an interactive application can benefit by |
|
55 | features. Clearly an interactive application can benefit by | |
56 | specifying its own completer function and using raw_input() for all |
|
56 | specifying its own completer function and using raw_input() for all | |
57 | its input. |
|
57 | its input. | |
58 |
|
58 | |||
59 | - When the original stdin is not a tty device, GNU readline is never |
|
59 | - When the original stdin is not a tty device, GNU readline is never | |
60 | used, and this module (and the readline module) are silently inactive. |
|
60 | used, and this module (and the readline module) are silently inactive. | |
61 |
|
61 | |||
62 | """ |
|
62 | """ | |
63 |
|
63 | |||
64 | #***************************************************************************** |
|
64 | #***************************************************************************** | |
65 | # |
|
65 | # | |
66 | # Since this file is essentially a minimally modified copy of the rlcompleter |
|
66 | # Since this file is essentially a minimally modified copy of the rlcompleter | |
67 | # module which is part of the standard Python distribution, I assume that the |
|
67 | # module which is part of the standard Python distribution, I assume that the | |
68 | # proper procedure is to maintain its copyright as belonging to the Python |
|
68 | # proper procedure is to maintain its copyright as belonging to the Python | |
69 | # Software Foundation: |
|
69 | # Software Foundation: | |
70 | # |
|
70 | # | |
71 | # Copyright (C) 2001 Python Software Foundation, www.python.org |
|
71 | # Copyright (C) 2001 Python Software Foundation, www.python.org | |
72 | # |
|
72 | # | |
73 | # Distributed under the terms of the Python Software Foundation license. |
|
73 | # Distributed under the terms of the Python Software Foundation license. | |
74 | # |
|
74 | # | |
75 | # Full text available at: |
|
75 | # Full text available at: | |
76 | # |
|
76 | # | |
77 | # http://www.python.org/2.1/license.html |
|
77 | # http://www.python.org/2.1/license.html | |
78 | # |
|
78 | # | |
79 | #***************************************************************************** |
|
79 | #***************************************************************************** | |
80 |
|
80 | |||
81 | import readline |
|
81 | import readline | |
82 | import __builtin__ |
|
82 | import __builtin__ | |
83 | import __main__ |
|
83 | import __main__ | |
84 |
|
84 | |||
85 | __all__ = ["Completer"] |
|
85 | __all__ = ["Completer"] | |
86 |
|
86 | |||
87 | # declares Python 2.2 compatibility symbols: |
|
|||
88 | try: |
|
|||
89 | basestring |
|
|||
90 | except NameError: |
|
|||
91 | import types |
|
|||
92 | basestring = (types.StringType, types.UnicodeType) |
|
|||
93 |
|
||||
94 | class Completer: |
|
87 | class Completer: | |
95 | def __init__(self, namespace = None): |
|
88 | def __init__(self, namespace = None): | |
96 | """Create a new completer for the command line. |
|
89 | """Create a new completer for the command line. | |
97 |
|
90 | |||
98 | Completer([namespace]) -> completer instance. |
|
91 | Completer([namespace]) -> completer instance. | |
99 |
|
92 | |||
100 | If unspecified, the default namespace where completions are performed |
|
93 | If unspecified, the default namespace where completions are performed | |
101 | is __main__ (technically, __main__.__dict__). Namespaces should be |
|
94 | is __main__ (technically, __main__.__dict__). Namespaces should be | |
102 | given as dictionaries. |
|
95 | given as dictionaries. | |
103 |
|
96 | |||
104 | Completer instances should be used as the completion mechanism of |
|
97 | Completer instances should be used as the completion mechanism of | |
105 | readline via the set_completer() call: |
|
98 | readline via the set_completer() call: | |
106 |
|
99 | |||
107 | readline.set_completer(Completer(my_namespace).complete) |
|
100 | readline.set_completer(Completer(my_namespace).complete) | |
108 | """ |
|
101 | """ | |
109 |
|
102 | |||
110 | if namespace and type(namespace) != type({}): |
|
103 | if namespace and type(namespace) != type({}): | |
111 | raise TypeError,'namespace must be a dictionary' |
|
104 | raise TypeError,'namespace must be a dictionary' | |
112 |
|
105 | |||
113 | # Don't bind to namespace quite yet, but flag whether the user wants a |
|
106 | # Don't bind to namespace quite yet, but flag whether the user wants a | |
114 | # specific namespace or to use __main__.__dict__. This will allow us |
|
107 | # specific namespace or to use __main__.__dict__. This will allow us | |
115 | # to bind to __main__.__dict__ at completion time, not now. |
|
108 | # to bind to __main__.__dict__ at completion time, not now. | |
116 | if namespace is None: |
|
109 | if namespace is None: | |
117 | self.use_main_ns = 1 |
|
110 | self.use_main_ns = 1 | |
118 | else: |
|
111 | else: | |
119 | self.use_main_ns = 0 |
|
112 | self.use_main_ns = 0 | |
120 | self.namespace = namespace |
|
113 | self.namespace = namespace | |
121 |
|
114 | |||
122 | def complete(self, text, state): |
|
115 | def complete(self, text, state): | |
123 | """Return the next possible completion for 'text'. |
|
116 | """Return the next possible completion for 'text'. | |
124 |
|
117 | |||
125 | This is called successively with state == 0, 1, 2, ... until it |
|
118 | This is called successively with state == 0, 1, 2, ... until it | |
126 | returns None. The completion should begin with 'text'. |
|
119 | returns None. The completion should begin with 'text'. | |
127 |
|
120 | |||
128 | """ |
|
121 | """ | |
129 | if self.use_main_ns: |
|
122 | if self.use_main_ns: | |
130 | self.namespace = __main__.__dict__ |
|
123 | self.namespace = __main__.__dict__ | |
131 |
|
124 | |||
132 | if state == 0: |
|
125 | if state == 0: | |
133 | if "." in text: |
|
126 | if "." in text: | |
134 | self.matches = self.attr_matches(text) |
|
127 | self.matches = self.attr_matches(text) | |
135 | else: |
|
128 | else: | |
136 | self.matches = self.global_matches(text) |
|
129 | self.matches = self.global_matches(text) | |
137 | try: |
|
130 | try: | |
138 | return self.matches[state] |
|
131 | return self.matches[state] | |
139 | except IndexError: |
|
132 | except IndexError: | |
140 | return None |
|
133 | return None | |
141 |
|
134 | |||
142 | def global_matches(self, text): |
|
135 | def global_matches(self, text): | |
143 | """Compute matches when text is a simple name. |
|
136 | """Compute matches when text is a simple name. | |
144 |
|
137 | |||
145 | Return a list of all keywords, built-in functions and names currently |
|
138 | Return a list of all keywords, built-in functions and names currently | |
146 | defined in self.namespace that match. |
|
139 | defined in self.namespace that match. | |
147 |
|
140 | |||
148 | """ |
|
141 | """ | |
149 | import keyword |
|
142 | import keyword | |
150 | matches = [] |
|
143 | matches = [] | |
151 | n = len(text) |
|
144 | n = len(text) | |
152 | for list in [keyword.kwlist, |
|
145 | for list in [keyword.kwlist, | |
153 | __builtin__.__dict__.keys(), |
|
146 | __builtin__.__dict__.keys(), | |
154 | self.namespace.keys()]: |
|
147 | self.namespace.keys()]: | |
155 | for word in list: |
|
148 | for word in list: | |
156 | if word[:n] == text and word != "__builtins__": |
|
149 | if word[:n] == text and word != "__builtins__": | |
157 | matches.append(word) |
|
150 | matches.append(word) | |
158 | return matches |
|
151 | return matches | |
159 |
|
152 | |||
160 | def attr_matches(self, text): |
|
153 | def attr_matches(self, text): | |
161 | """Compute matches when text contains a dot. |
|
154 | """Compute matches when text contains a dot. | |
162 |
|
155 | |||
163 | Assuming the text is of the form NAME.NAME....[NAME], and is |
|
156 | Assuming the text is of the form NAME.NAME....[NAME], and is | |
164 | evaluatable in self.namespace, it will be evaluated and its attributes |
|
157 | evaluatable in self.namespace, it will be evaluated and its attributes | |
165 | (as revealed by dir()) are used as possible completions. (For class |
|
158 | (as revealed by dir()) are used as possible completions. (For class | |
166 | instances, class members are are also considered.) |
|
159 | instances, class members are are also considered.) | |
167 |
|
160 | |||
168 | WARNING: this can still invoke arbitrary C code, if an object |
|
161 | WARNING: this can still invoke arbitrary C code, if an object | |
169 | with a __getattr__ hook is evaluated. |
|
162 | with a __getattr__ hook is evaluated. | |
170 |
|
163 | |||
171 | """ |
|
164 | """ | |
172 | import re |
|
165 | import re | |
173 |
|
166 | |||
174 | # Another option, seems to work great. Catches things like ''.<tab> |
|
167 | # Another option, seems to work great. Catches things like ''.<tab> | |
175 | m = re.match(r"(\S+(\.\w+)*)\.(\w*)$", text) |
|
168 | m = re.match(r"(\S+(\.\w+)*)\.(\w*)$", text) | |
176 |
|
169 | |||
177 | if not m: |
|
170 | if not m: | |
178 | return [] |
|
171 | return [] | |
179 | expr, attr = m.group(1, 3) |
|
172 | expr, attr = m.group(1, 3) | |
180 | object = eval(expr, self.namespace) |
|
173 | object = eval(expr, self.namespace) | |
181 | words = [w for w in dir(object) if isinstance(w, basestring)] |
|
174 | words = [w for w in dir(object) if isinstance(w, basestring)] | |
182 | if hasattr(object,'__class__'): |
|
175 | if hasattr(object,'__class__'): | |
183 | words.append('__class__') |
|
176 | words.append('__class__') | |
184 | words.extend(get_class_members(object.__class__)) |
|
177 | words.extend(get_class_members(object.__class__)) | |
185 | n = len(attr) |
|
178 | n = len(attr) | |
186 | matches = [] |
|
179 | matches = [] | |
187 | for word in words: |
|
180 | for word in words: | |
188 | if word[:n] == attr and word != "__builtins__": |
|
181 | if word[:n] == attr and word != "__builtins__": | |
189 | matches.append("%s.%s" % (expr, word)) |
|
182 | matches.append("%s.%s" % (expr, word)) | |
190 | return matches |
|
183 | return matches | |
191 |
|
184 | |||
192 | def get_class_members(klass): |
|
185 | def get_class_members(klass): | |
193 | ret = dir(klass) |
|
186 | ret = dir(klass) | |
194 | if hasattr(klass,'__bases__'): |
|
187 | if hasattr(klass,'__bases__'): | |
195 | for base in klass.__bases__: |
|
188 | for base in klass.__bases__: | |
196 | ret.extend(get_class_members(base)) |
|
189 | ret.extend(get_class_members(base)) | |
197 | return ret |
|
190 | return ret | |
198 |
|
191 | |||
199 | readline.set_completer(Completer().complete) |
|
192 | readline.set_completer(Completer().complete) |
@@ -1,253 +1,277 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """String interpolation for Python (by Ka-Ping Yee, 14 Feb 2000). |
|
2 | """String interpolation for Python (by Ka-Ping Yee, 14 Feb 2000). | |
3 |
|
3 | |||
4 | This module lets you quickly and conveniently interpolate values into |
|
4 | This module lets you quickly and conveniently interpolate values into | |
5 | strings (in the flavour of Perl or Tcl, but with less extraneous |
|
5 | strings (in the flavour of Perl or Tcl, but with less extraneous | |
6 | punctuation). You get a bit more power than in the other languages, |
|
6 | punctuation). You get a bit more power than in the other languages, | |
7 | because this module allows subscripting, slicing, function calls, |
|
7 | because this module allows subscripting, slicing, function calls, | |
8 | attribute lookup, or arbitrary expressions. Variables and expressions |
|
8 | attribute lookup, or arbitrary expressions. Variables and expressions | |
9 | are evaluated in the namespace of the caller. |
|
9 | are evaluated in the namespace of the caller. | |
10 |
|
10 | |||
11 | The itpl() function returns the result of interpolating a string, and |
|
11 | The itpl() function returns the result of interpolating a string, and | |
12 | printpl() prints out an interpolated string. Here are some examples: |
|
12 | printpl() prints out an interpolated string. Here are some examples: | |
13 |
|
13 | |||
14 | from Itpl import printpl |
|
14 | from Itpl import printpl | |
15 | printpl("Here is a $string.") |
|
15 | printpl("Here is a $string.") | |
16 | printpl("Here is a $module.member.") |
|
16 | printpl("Here is a $module.member.") | |
17 | printpl("Here is an $object.member.") |
|
17 | printpl("Here is an $object.member.") | |
18 | printpl("Here is a $functioncall(with, arguments).") |
|
18 | printpl("Here is a $functioncall(with, arguments).") | |
19 | printpl("Here is an ${arbitrary + expression}.") |
|
19 | printpl("Here is an ${arbitrary + expression}.") | |
20 | printpl("Here is an $array[3] member.") |
|
20 | printpl("Here is an $array[3] member.") | |
21 | printpl("Here is a $dictionary['member'].") |
|
21 | printpl("Here is a $dictionary['member'].") | |
22 |
|
22 | |||
23 | The filter() function filters a file object so that output through it |
|
23 | The filter() function filters a file object so that output through it | |
24 | is interpolated. This lets you produce the illusion that Python knows |
|
24 | is interpolated. This lets you produce the illusion that Python knows | |
25 | how to do interpolation: |
|
25 | how to do interpolation: | |
26 |
|
26 | |||
27 | import Itpl |
|
27 | import Itpl | |
28 | sys.stdout = Itpl.filter() |
|
28 | sys.stdout = Itpl.filter() | |
29 | f = "fancy" |
|
29 | f = "fancy" | |
30 | print "Isn't this $f?" |
|
30 | print "Isn't this $f?" | |
31 | print "Standard output has been replaced with a $sys.stdout object." |
|
31 | print "Standard output has been replaced with a $sys.stdout object." | |
32 | sys.stdout = Itpl.unfilter() |
|
32 | sys.stdout = Itpl.unfilter() | |
33 | print "Okay, back $to $normal." |
|
33 | print "Okay, back $to $normal." | |
34 |
|
34 | |||
35 | Under the hood, the Itpl class represents a string that knows how to |
|
35 | Under the hood, the Itpl class represents a string that knows how to | |
36 | interpolate values. An instance of the class parses the string once |
|
36 | interpolate values. An instance of the class parses the string once | |
37 | upon initialization; the evaluation and substitution can then be done |
|
37 | upon initialization; the evaluation and substitution can then be done | |
38 | each time the instance is evaluated with str(instance). For example: |
|
38 | each time the instance is evaluated with str(instance). For example: | |
39 |
|
39 | |||
40 | from Itpl import Itpl |
|
40 | from Itpl import Itpl | |
41 | s = Itpl("Here is $foo.") |
|
41 | s = Itpl("Here is $foo.") | |
42 | foo = 5 |
|
42 | foo = 5 | |
43 | print str(s) |
|
43 | print str(s) | |
44 | foo = "bar" |
|
44 | foo = "bar" | |
45 | print str(s) |
|
45 | print str(s) | |
46 |
|
46 | |||
47 |
$Id: Itpl.py |
|
47 | $Id: Itpl.py 638 2005-07-18 03:01:41Z fperez $ | |
48 | """ # ' -> close an open quote for stupid emacs |
|
48 | """ # ' -> close an open quote for stupid emacs | |
49 |
|
49 | |||
50 | #***************************************************************************** |
|
50 | #***************************************************************************** | |
51 | # |
|
51 | # | |
52 | # Copyright (c) 2001 Ka-Ping Yee <ping@lfw.org> |
|
52 | # Copyright (c) 2001 Ka-Ping Yee <ping@lfw.org> | |
53 | # |
|
53 | # | |
54 | # |
|
54 | # | |
55 | # Published under the terms of the MIT license, hereby reproduced: |
|
55 | # Published under the terms of the MIT license, hereby reproduced: | |
56 | # |
|
56 | # | |
57 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
|
57 | # Permission is hereby granted, free of charge, to any person obtaining a copy | |
58 | # of this software and associated documentation files (the "Software"), to |
|
58 | # of this software and associated documentation files (the "Software"), to | |
59 | # deal in the Software without restriction, including without limitation the |
|
59 | # deal in the Software without restriction, including without limitation the | |
60 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|
60 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |
61 | # sell copies of the Software, and to permit persons to whom the Software is |
|
61 | # sell copies of the Software, and to permit persons to whom the Software is | |
62 | # furnished to do so, subject to the following conditions: |
|
62 | # furnished to do so, subject to the following conditions: | |
63 | # |
|
63 | # | |
64 | # The above copyright notice and this permission notice shall be included in |
|
64 | # The above copyright notice and this permission notice shall be included in | |
65 | # all copies or substantial portions of the Software. |
|
65 | # all copies or substantial portions of the Software. | |
66 | # |
|
66 | # | |
67 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
67 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
68 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
68 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
69 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
69 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
70 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
70 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
71 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
71 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
72 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
|
72 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
73 | # IN THE SOFTWARE. |
|
73 | # IN THE SOFTWARE. | |
74 | # |
|
74 | # | |
75 | #***************************************************************************** |
|
75 | #***************************************************************************** | |
76 |
|
76 | |||
77 | __author__ = 'Ka-Ping Yee <ping@lfw.org>' |
|
77 | __author__ = 'Ka-Ping Yee <ping@lfw.org>' | |
78 | __license__ = 'MIT' |
|
78 | __license__ = 'MIT' | |
79 |
|
79 | |||
80 | import sys, string |
|
80 | import sys, string | |
81 | from types import StringType |
|
81 | from types import StringType | |
82 | from tokenize import tokenprog |
|
82 | from tokenize import tokenprog | |
83 |
|
83 | |||
84 | class ItplError(ValueError): |
|
84 | class ItplError(ValueError): | |
85 | def __init__(self, text, pos): |
|
85 | def __init__(self, text, pos): | |
86 | self.text = text |
|
86 | self.text = text | |
87 | self.pos = pos |
|
87 | self.pos = pos | |
88 | def __str__(self): |
|
88 | def __str__(self): | |
89 | return "unfinished expression in %s at char %d" % ( |
|
89 | return "unfinished expression in %s at char %d" % ( | |
90 | repr(self.text), self.pos) |
|
90 | repr(self.text), self.pos) | |
91 |
|
91 | |||
92 | def matchorfail(text, pos): |
|
92 | def matchorfail(text, pos): | |
93 | match = tokenprog.match(text, pos) |
|
93 | match = tokenprog.match(text, pos) | |
94 | if match is None: |
|
94 | if match is None: | |
95 | raise ItplError(text, pos) |
|
95 | raise ItplError(text, pos) | |
96 | return match, match.end() |
|
96 | return match, match.end() | |
97 |
|
97 | |||
98 | class Itpl: |
|
98 | class Itpl: | |
99 | """Class representing a string with interpolation abilities. |
|
99 | """Class representing a string with interpolation abilities. | |
100 |
|
100 | |||
101 | Upon creation, an instance works out what parts of the format |
|
101 | Upon creation, an instance works out what parts of the format | |
102 | string are literal and what parts need to be evaluated. The |
|
102 | string are literal and what parts need to be evaluated. The | |
103 | evaluation and substitution happens in the namespace of the |
|
103 | evaluation and substitution happens in the namespace of the | |
104 | caller when str(instance) is called.""" |
|
104 | caller when str(instance) is called.""" | |
105 |
|
105 | |||
106 | def __init__(self, format): |
|
106 | def __init__(self, format,codec='utf_8',encoding_errors='backslashreplace'): | |
107 |
"""The single argument to this constructor is a format |
|
107 | """The single mandatory argument to this constructor is a format | |
|
108 | string. | |||
108 |
|
109 | |||
109 | The format string is parsed according to the following rules: |
|
110 | The format string is parsed according to the following rules: | |
110 |
|
111 | |||
111 | 1. A dollar sign and a name, possibly followed by any of: |
|
112 | 1. A dollar sign and a name, possibly followed by any of: | |
112 | - an open-paren, and anything up to the matching paren |
|
113 | - an open-paren, and anything up to the matching paren | |
113 | - an open-bracket, and anything up to the matching bracket |
|
114 | - an open-bracket, and anything up to the matching bracket | |
114 | - a period and a name |
|
115 | - a period and a name | |
115 | any number of times, is evaluated as a Python expression. |
|
116 | any number of times, is evaluated as a Python expression. | |
116 |
|
117 | |||
117 | 2. A dollar sign immediately followed by an open-brace, and |
|
118 | 2. A dollar sign immediately followed by an open-brace, and | |
118 | anything up to the matching close-brace, is evaluated as |
|
119 | anything up to the matching close-brace, is evaluated as | |
119 | a Python expression. |
|
120 | a Python expression. | |
120 |
|
121 | |||
121 | 3. Outside of the expressions described in the above two rules, |
|
122 | 3. Outside of the expressions described in the above two rules, | |
122 |
two dollar signs in a row give you one literal dollar sign. |
|
123 | two dollar signs in a row give you one literal dollar sign. | |
123 |
|
|
124 | ||
124 | if type(format) != StringType: |
|
125 | Optional arguments: | |
|
126 | ||||
|
127 | - codec('utf_8'): a string containing the name of a valid Python | |||
|
128 | codec. | |||
|
129 | ||||
|
130 | - encoding_errors('backslashreplace'): a string with a valid error handling | |||
|
131 | policy. See the codecs module documentation for details. | |||
|
132 | ||||
|
133 | These are used to encode the format string if a call to str() fails on | |||
|
134 | the expanded result.""" | |||
|
135 | ||||
|
136 | if not isinstance(format,basestring): | |||
125 | raise TypeError, "needs string initializer" |
|
137 | raise TypeError, "needs string initializer" | |
126 | self.format = format |
|
138 | self.format = format | |
127 |
|
139 | self.codec = codec | ||
|
140 | self.encoding_errors = encoding_errors | |||
|
141 | ||||
128 | namechars = "abcdefghijklmnopqrstuvwxyz" \ |
|
142 | namechars = "abcdefghijklmnopqrstuvwxyz" \ | |
129 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"; |
|
143 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"; | |
130 | chunks = [] |
|
144 | chunks = [] | |
131 | pos = 0 |
|
145 | pos = 0 | |
132 |
|
146 | |||
133 | while 1: |
|
147 | while 1: | |
134 | dollar = string.find(format, "$", pos) |
|
148 | dollar = string.find(format, "$", pos) | |
135 | if dollar < 0: break |
|
149 | if dollar < 0: break | |
136 | nextchar = format[dollar+1] |
|
150 | nextchar = format[dollar+1] | |
137 |
|
151 | |||
138 | if nextchar == "{": |
|
152 | if nextchar == "{": | |
139 | chunks.append((0, format[pos:dollar])) |
|
153 | chunks.append((0, format[pos:dollar])) | |
140 | pos, level = dollar+2, 1 |
|
154 | pos, level = dollar+2, 1 | |
141 | while level: |
|
155 | while level: | |
142 | match, pos = matchorfail(format, pos) |
|
156 | match, pos = matchorfail(format, pos) | |
143 | tstart, tend = match.regs[3] |
|
157 | tstart, tend = match.regs[3] | |
144 | token = format[tstart:tend] |
|
158 | token = format[tstart:tend] | |
145 | if token == "{": level = level+1 |
|
159 | if token == "{": level = level+1 | |
146 | elif token == "}": level = level-1 |
|
160 | elif token == "}": level = level-1 | |
147 | chunks.append((1, format[dollar+2:pos-1])) |
|
161 | chunks.append((1, format[dollar+2:pos-1])) | |
148 |
|
162 | |||
149 | elif nextchar in namechars: |
|
163 | elif nextchar in namechars: | |
150 | chunks.append((0, format[pos:dollar])) |
|
164 | chunks.append((0, format[pos:dollar])) | |
151 | match, pos = matchorfail(format, dollar+1) |
|
165 | match, pos = matchorfail(format, dollar+1) | |
152 | while pos < len(format): |
|
166 | while pos < len(format): | |
153 | if format[pos] == "." and \ |
|
167 | if format[pos] == "." and \ | |
154 | pos+1 < len(format) and format[pos+1] in namechars: |
|
168 | pos+1 < len(format) and format[pos+1] in namechars: | |
155 | match, pos = matchorfail(format, pos+1) |
|
169 | match, pos = matchorfail(format, pos+1) | |
156 | elif format[pos] in "([": |
|
170 | elif format[pos] in "([": | |
157 | pos, level = pos+1, 1 |
|
171 | pos, level = pos+1, 1 | |
158 | while level: |
|
172 | while level: | |
159 | match, pos = matchorfail(format, pos) |
|
173 | match, pos = matchorfail(format, pos) | |
160 | tstart, tend = match.regs[3] |
|
174 | tstart, tend = match.regs[3] | |
161 | token = format[tstart:tend] |
|
175 | token = format[tstart:tend] | |
162 | if token[0] in "([": level = level+1 |
|
176 | if token[0] in "([": level = level+1 | |
163 | elif token[0] in ")]": level = level-1 |
|
177 | elif token[0] in ")]": level = level-1 | |
164 | else: break |
|
178 | else: break | |
165 | chunks.append((1, format[dollar+1:pos])) |
|
179 | chunks.append((1, format[dollar+1:pos])) | |
166 |
|
180 | |||
167 | else: |
|
181 | else: | |
168 | chunks.append((0, format[pos:dollar+1])) |
|
182 | chunks.append((0, format[pos:dollar+1])) | |
169 | pos = dollar + 1 + (nextchar == "$") |
|
183 | pos = dollar + 1 + (nextchar == "$") | |
170 |
|
184 | |||
171 | if pos < len(format): chunks.append((0, format[pos:])) |
|
185 | if pos < len(format): chunks.append((0, format[pos:])) | |
172 | self.chunks = chunks |
|
186 | self.chunks = chunks | |
173 |
|
187 | |||
174 | def __repr__(self): |
|
188 | def __repr__(self): | |
175 | return "<Itpl %s >" % repr(self.format) |
|
189 | return "<Itpl %s >" % repr(self.format) | |
176 |
|
190 | |||
|
191 | def _str(self,glob,loc): | |||
|
192 | """Evaluate to a string in the given globals/locals. | |||
|
193 | ||||
|
194 | The final output is built by calling str(), but if this fails, the | |||
|
195 | result is encoded with the instance's codec and error handling policy, | |||
|
196 | via a call to out.encode(self.codec,self.encoding_errors)""" | |||
|
197 | result = [] | |||
|
198 | app = result.append | |||
|
199 | for live, chunk in self.chunks: | |||
|
200 | if live: app(str(eval(chunk,glob,loc))) | |||
|
201 | else: app(chunk) | |||
|
202 | out = ''.join(result) | |||
|
203 | try: | |||
|
204 | return str(out) | |||
|
205 | except UnicodeError: | |||
|
206 | return out.encode(self.codec,self.encoding_errors) | |||
|
207 | ||||
177 | def __str__(self): |
|
208 | def __str__(self): | |
178 | """Evaluate and substitute the appropriate parts of the string.""" |
|
209 | """Evaluate and substitute the appropriate parts of the string.""" | |
179 |
|
210 | |||
180 | # We need to skip enough frames to get to the actual caller outside of |
|
211 | # We need to skip enough frames to get to the actual caller outside of | |
181 | # Itpl. |
|
212 | # Itpl. | |
182 | frame = sys._getframe(1) |
|
213 | frame = sys._getframe(1) | |
183 | while frame.f_globals["__name__"] == __name__: frame = frame.f_back |
|
214 | while frame.f_globals["__name__"] == __name__: frame = frame.f_back | |
184 | loc, glob = frame.f_locals, frame.f_globals |
|
215 | loc, glob = frame.f_locals, frame.f_globals | |
185 |
|
216 | |||
186 | result = [] |
|
217 | return self._str(glob,loc) | |
187 | for live, chunk in self.chunks: |
|
218 | ||
188 | if live: result.append(str(eval(chunk,glob,loc))) |
|
|||
189 | else: result.append(chunk) |
|
|||
190 |
|
||||
191 | return ''.join(result) |
|
|||
192 |
|
||||
193 | class ItplNS(Itpl): |
|
219 | class ItplNS(Itpl): | |
194 | """Class representing a string with interpolation abilities. |
|
220 | """Class representing a string with interpolation abilities. | |
195 |
|
221 | |||
196 | This inherits from Itpl, but at creation time a namespace is provided |
|
222 | This inherits from Itpl, but at creation time a namespace is provided | |
197 | where the evaluation will occur. The interpolation becomes a bit more |
|
223 | where the evaluation will occur. The interpolation becomes a bit more | |
198 | efficient, as no traceback needs to be extracte. It also allows the |
|
224 | efficient, as no traceback needs to be extracte. It also allows the | |
199 | caller to supply a different namespace for the interpolation to occur than |
|
225 | caller to supply a different namespace for the interpolation to occur than | |
200 | its own.""" |
|
226 | its own.""" | |
201 |
|
227 | |||
202 |
def __init__(self, format,globals,locals=None |
|
228 | def __init__(self, format,globals,locals=None, | |
|
229 | codec='utf_8',encoding_errors='backslashreplace'): | |||
203 | """ItplNS(format,globals[,locals]) -> interpolating string instance. |
|
230 | """ItplNS(format,globals[,locals]) -> interpolating string instance. | |
204 |
|
231 | |||
205 | This constructor, besides a format string, takes a globals dictionary |
|
232 | This constructor, besides a format string, takes a globals dictionary | |
206 | and optionally a locals (which defaults to globals if not provided). |
|
233 | and optionally a locals (which defaults to globals if not provided). | |
207 |
|
234 | |||
208 | For further details, see the Itpl constructor.""" |
|
235 | For further details, see the Itpl constructor.""" | |
209 |
|
236 | |||
210 | if locals is None: |
|
237 | if locals is None: | |
211 | locals = globals |
|
238 | locals = globals | |
212 | self.globals = globals |
|
239 | self.globals = globals | |
213 | self.locals = locals |
|
240 | self.locals = locals | |
214 | Itpl.__init__(self,format) |
|
241 | Itpl.__init__(self,format,codec,encoding_errors) | |
215 |
|
242 | |||
216 | def __str__(self): |
|
243 | def __str__(self): | |
217 | """Evaluate and substitute the appropriate parts of the string.""" |
|
244 | """Evaluate and substitute the appropriate parts of the string.""" | |
218 | glob = self.globals |
|
245 | return self._str(self.globals,self.locals) | |
219 | loc = self.locals |
|
246 | ||
220 | result = [] |
|
247 | def __repr__(self): | |
221 | for live, chunk in self.chunks: |
|
248 | return "<ItplNS %s >" % repr(self.format) | |
222 | if live: result.append(str(eval(chunk,glob,loc))) |
|
|||
223 | else: result.append(chunk) |
|
|||
224 | return ''.join(result) |
|
|||
225 |
|
249 | |||
226 | # utilities for fast printing |
|
250 | # utilities for fast printing | |
227 | def itpl(text): return str(Itpl(text)) |
|
251 | def itpl(text): return str(Itpl(text)) | |
228 | def printpl(text): print itpl(text) |
|
252 | def printpl(text): print itpl(text) | |
229 | # versions with namespace |
|
253 | # versions with namespace | |
230 | def itplns(text,globals,locals=None): return str(ItplNS(text,globals,locals)) |
|
254 | def itplns(text,globals,locals=None): return str(ItplNS(text,globals,locals)) | |
231 | def printplns(text,globals,locals=None): print itplns(text,globals,locals) |
|
255 | def printplns(text,globals,locals=None): print itplns(text,globals,locals) | |
232 |
|
256 | |||
233 | class ItplFile: |
|
257 | class ItplFile: | |
234 | """A file object that filters each write() through an interpolator.""" |
|
258 | """A file object that filters each write() through an interpolator.""" | |
235 | def __init__(self, file): self.file = file |
|
259 | def __init__(self, file): self.file = file | |
236 | def __repr__(self): return "<interpolated " + repr(self.file) + ">" |
|
260 | def __repr__(self): return "<interpolated " + repr(self.file) + ">" | |
237 | def __getattr__(self, attr): return getattr(self.file, attr) |
|
261 | def __getattr__(self, attr): return getattr(self.file, attr) | |
238 | def write(self, text): self.file.write(str(Itpl(text))) |
|
262 | def write(self, text): self.file.write(str(Itpl(text))) | |
239 |
|
263 | |||
240 | def filter(file=sys.stdout): |
|
264 | def filter(file=sys.stdout): | |
241 | """Return an ItplFile that filters writes to the given file object. |
|
265 | """Return an ItplFile that filters writes to the given file object. | |
242 |
|
266 | |||
243 | 'file = filter(file)' replaces 'file' with a filtered object that |
|
267 | 'file = filter(file)' replaces 'file' with a filtered object that | |
244 | has a write() method. When called with no argument, this creates |
|
268 | has a write() method. When called with no argument, this creates | |
245 | a filter to sys.stdout.""" |
|
269 | a filter to sys.stdout.""" | |
246 | return ItplFile(file) |
|
270 | return ItplFile(file) | |
247 |
|
271 | |||
248 | def unfilter(ifile=None): |
|
272 | def unfilter(ifile=None): | |
249 | """Return the original file that corresponds to the given ItplFile. |
|
273 | """Return the original file that corresponds to the given ItplFile. | |
250 |
|
274 | |||
251 | 'file = unfilter(file)' undoes the effect of 'file = filter(file)'. |
|
275 | 'file = unfilter(file)' undoes the effect of 'file = filter(file)'. | |
252 | 'sys.stdout = unfilter()' undoes the effect of 'sys.stdout = filter()'.""" |
|
276 | 'sys.stdout = unfilter()' undoes the effect of 'sys.stdout = filter()'.""" | |
253 | return ifile and ifile.file or sys.stdout.file |
|
277 | return ifile and ifile.file or sys.stdout.file |
@@ -1,574 +1,572 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """ |
|
2 | """ | |
3 | Classes for handling input/output prompts. |
|
3 | Classes for handling input/output prompts. | |
4 |
|
4 | |||
5 |
$Id: Prompts.py |
|
5 | $Id: Prompts.py 638 2005-07-18 03:01:41Z fperez $""" | |
6 |
|
6 | |||
7 | #***************************************************************************** |
|
7 | #***************************************************************************** | |
8 | # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu> |
|
8 | # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu> | |
9 | # |
|
9 | # | |
10 | # Distributed under the terms of the BSD License. The full license is in |
|
10 | # Distributed under the terms of the BSD License. The full license is in | |
11 | # the file COPYING, distributed as part of this software. |
|
11 | # the file COPYING, distributed as part of this software. | |
12 | #***************************************************************************** |
|
12 | #***************************************************************************** | |
13 |
|
13 | |||
14 | from IPython import Release |
|
14 | from IPython import Release | |
15 | __author__ = '%s <%s>' % Release.authors['Fernando'] |
|
15 | __author__ = '%s <%s>' % Release.authors['Fernando'] | |
16 | __license__ = Release.license |
|
16 | __license__ = Release.license | |
17 | __version__ = Release.version |
|
17 | __version__ = Release.version | |
18 |
|
18 | |||
19 | #**************************************************************************** |
|
19 | #**************************************************************************** | |
20 | # Required modules |
|
20 | # Required modules | |
21 | import __builtin__ |
|
21 | import __builtin__ | |
22 | import os,sys,socket |
|
22 | import os,sys,socket | |
23 | import time |
|
23 | import time | |
24 | from pprint import pprint,pformat |
|
24 | from pprint import pprint,pformat | |
25 |
|
25 | |||
26 | # IPython's own |
|
26 | # IPython's own | |
27 | from IPython.genutils import * |
|
27 | from IPython.genutils import * | |
28 | from IPython.Struct import Struct |
|
28 | from IPython.Struct import Struct | |
29 | from IPython.Magic import Macro |
|
29 | from IPython.Magic import Macro | |
30 | from IPython.Itpl import ItplNS |
|
30 | from IPython.Itpl import ItplNS | |
31 | from IPython import ColorANSI |
|
31 | from IPython import ColorANSI | |
32 |
|
32 | |||
33 | #**************************************************************************** |
|
33 | #**************************************************************************** | |
34 | #Color schemes for Prompts. |
|
34 | #Color schemes for Prompts. | |
35 |
|
35 | |||
36 | PromptColors = ColorANSI.ColorSchemeTable() |
|
36 | PromptColors = ColorANSI.ColorSchemeTable() | |
37 | InputColors = ColorANSI.InputTermColors # just a shorthand |
|
37 | InputColors = ColorANSI.InputTermColors # just a shorthand | |
38 | Colors = ColorANSI.TermColors # just a shorthand |
|
38 | Colors = ColorANSI.TermColors # just a shorthand | |
39 |
|
39 | |||
40 | PromptColors.add_scheme(ColorANSI.ColorScheme( |
|
40 | PromptColors.add_scheme(ColorANSI.ColorScheme( | |
41 | 'NoColor', |
|
41 | 'NoColor', | |
42 | in_prompt = InputColors.NoColor, # Input prompt |
|
42 | in_prompt = InputColors.NoColor, # Input prompt | |
43 | in_number = InputColors.NoColor, # Input prompt number |
|
43 | in_number = InputColors.NoColor, # Input prompt number | |
44 | in_prompt2 = InputColors.NoColor, # Continuation prompt |
|
44 | in_prompt2 = InputColors.NoColor, # Continuation prompt | |
45 | in_normal = InputColors.NoColor, # color off (usu. Colors.Normal) |
|
45 | in_normal = InputColors.NoColor, # color off (usu. Colors.Normal) | |
46 |
|
46 | |||
47 | out_prompt = Colors.NoColor, # Output prompt |
|
47 | out_prompt = Colors.NoColor, # Output prompt | |
48 | out_number = Colors.NoColor, # Output prompt number |
|
48 | out_number = Colors.NoColor, # Output prompt number | |
49 |
|
49 | |||
50 | normal = Colors.NoColor # color off (usu. Colors.Normal) |
|
50 | normal = Colors.NoColor # color off (usu. Colors.Normal) | |
51 | )) |
|
51 | )) | |
52 | # make some schemes as instances so we can copy them for modification easily: |
|
52 | # make some schemes as instances so we can copy them for modification easily: | |
53 | __PColLinux = ColorANSI.ColorScheme( |
|
53 | __PColLinux = ColorANSI.ColorScheme( | |
54 | 'Linux', |
|
54 | 'Linux', | |
55 | in_prompt = InputColors.Green, |
|
55 | in_prompt = InputColors.Green, | |
56 | in_number = InputColors.LightGreen, |
|
56 | in_number = InputColors.LightGreen, | |
57 | in_prompt2 = InputColors.Green, |
|
57 | in_prompt2 = InputColors.Green, | |
58 | in_normal = InputColors.Normal, # color off (usu. Colors.Normal) |
|
58 | in_normal = InputColors.Normal, # color off (usu. Colors.Normal) | |
59 |
|
59 | |||
60 | out_prompt = Colors.Red, |
|
60 | out_prompt = Colors.Red, | |
61 | out_number = Colors.LightRed, |
|
61 | out_number = Colors.LightRed, | |
62 |
|
62 | |||
63 | normal = Colors.Normal |
|
63 | normal = Colors.Normal | |
64 | ) |
|
64 | ) | |
65 | # Don't forget to enter it into the table! |
|
65 | # Don't forget to enter it into the table! | |
66 | PromptColors.add_scheme(__PColLinux) |
|
66 | PromptColors.add_scheme(__PColLinux) | |
67 | # Slightly modified Linux for light backgrounds |
|
67 | # Slightly modified Linux for light backgrounds | |
68 | __PColLightBG = ColorANSI.ColorScheme('LightBG',**__PColLinux.colors.dict().copy()) |
|
68 | __PColLightBG = ColorANSI.ColorScheme('LightBG',**__PColLinux.colors.dict().copy()) | |
69 |
|
69 | |||
70 | __PColLightBG.colors.update( |
|
70 | __PColLightBG.colors.update( | |
71 | in_prompt = InputColors.Blue, |
|
71 | in_prompt = InputColors.Blue, | |
72 | in_number = InputColors.LightBlue, |
|
72 | in_number = InputColors.LightBlue, | |
73 | in_prompt2 = InputColors.Blue |
|
73 | in_prompt2 = InputColors.Blue | |
74 | ) |
|
74 | ) | |
75 | PromptColors.add_scheme(__PColLightBG) |
|
75 | PromptColors.add_scheme(__PColLightBG) | |
76 |
|
76 | |||
77 | del Colors,InputColors |
|
77 | del Colors,InputColors | |
78 |
|
78 | |||
79 | #----------------------------------------------------------------------------- |
|
79 | #----------------------------------------------------------------------------- | |
80 | def multiple_replace(dict, text): |
|
80 | def multiple_replace(dict, text): | |
81 | """ Replace in 'text' all occurences of any key in the given |
|
81 | """ Replace in 'text' all occurences of any key in the given | |
82 | dictionary by its corresponding value. Returns the new string.""" |
|
82 | dictionary by its corresponding value. Returns the new string.""" | |
83 |
|
83 | |||
84 | # Function by Xavier Defrang, originally found at: |
|
84 | # Function by Xavier Defrang, originally found at: | |
85 | # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81330 |
|
85 | # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81330 | |
86 |
|
86 | |||
87 | # Create a regular expression from the dictionary keys |
|
87 | # Create a regular expression from the dictionary keys | |
88 | regex = re.compile("(%s)" % "|".join(map(re.escape, dict.keys()))) |
|
88 | regex = re.compile("(%s)" % "|".join(map(re.escape, dict.keys()))) | |
89 | # For each match, look-up corresponding value in dictionary |
|
89 | # For each match, look-up corresponding value in dictionary | |
90 | return regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], text) |
|
90 | return regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], text) | |
91 |
|
91 | |||
92 | #----------------------------------------------------------------------------- |
|
92 | #----------------------------------------------------------------------------- | |
93 | # Special characters that can be used in prompt templates, mainly bash-like |
|
93 | # Special characters that can be used in prompt templates, mainly bash-like | |
94 |
|
94 | |||
95 | # If $HOME isn't defined (Windows), make it an absurd string so that it can |
|
95 | # If $HOME isn't defined (Windows), make it an absurd string so that it can | |
96 | # never be expanded out into '~'. Basically anything which can never be a |
|
96 | # never be expanded out into '~'. Basically anything which can never be a | |
97 | # reasonable directory name will do, we just want the $HOME -> '~' operation |
|
97 | # reasonable directory name will do, we just want the $HOME -> '~' operation | |
98 | # to become a no-op. We pre-compute $HOME here so it's not done on every |
|
98 | # to become a no-op. We pre-compute $HOME here so it's not done on every | |
99 | # prompt call. |
|
99 | # prompt call. | |
100 |
|
100 | |||
101 | # FIXME: |
|
101 | # FIXME: | |
102 |
|
102 | |||
103 | # - This should be turned into a class which does proper namespace management, |
|
103 | # - This should be turned into a class which does proper namespace management, | |
104 | # since the prompt specials need to be evaluated in a certain namespace. |
|
104 | # since the prompt specials need to be evaluated in a certain namespace. | |
105 | # Currently it's just globals, which need to be managed manually by code |
|
105 | # Currently it's just globals, which need to be managed manually by code | |
106 | # below. |
|
106 | # below. | |
107 |
|
107 | |||
108 | # - I also need to split up the color schemes from the prompt specials |
|
108 | # - I also need to split up the color schemes from the prompt specials | |
109 | # somehow. I don't have a clean design for that quite yet. |
|
109 | # somehow. I don't have a clean design for that quite yet. | |
110 |
|
110 | |||
111 | HOME = os.environ.get("HOME","//////:::::ZZZZZ,,,~~~") |
|
111 | HOME = os.environ.get("HOME","//////:::::ZZZZZ,,,~~~") | |
112 |
|
112 | |||
113 | # We precompute a few more strings here for the prompt_specials, which are |
|
113 | # We precompute a few more strings here for the prompt_specials, which are | |
114 | # fixed once ipython starts. This reduces the runtime overhead of computing |
|
114 | # fixed once ipython starts. This reduces the runtime overhead of computing | |
115 | # prompt strings. |
|
115 | # prompt strings. | |
116 | USER = os.environ.get("USER") |
|
116 | USER = os.environ.get("USER") | |
117 | HOSTNAME = socket.gethostname() |
|
117 | HOSTNAME = socket.gethostname() | |
118 | HOSTNAME_SHORT = HOSTNAME.split(".")[0] |
|
118 | HOSTNAME_SHORT = HOSTNAME.split(".")[0] | |
119 | ROOT_SYMBOL = "$#"[os.name=='nt' or os.getuid()==0] |
|
119 | ROOT_SYMBOL = "$#"[os.name=='nt' or os.getuid()==0] | |
120 |
|
120 | |||
121 | prompt_specials_color = { |
|
121 | prompt_specials_color = { | |
122 | # Prompt/history count |
|
122 | # Prompt/history count | |
123 | '%n' : '${self.col_num}' '${self.cache.prompt_count}' '${self.col_p}', |
|
123 | '%n' : '${self.col_num}' '${self.cache.prompt_count}' '${self.col_p}', | |
124 | '\\#': '${self.col_num}' '${self.cache.prompt_count}' '${self.col_p}', |
|
124 | '\\#': '${self.col_num}' '${self.cache.prompt_count}' '${self.col_p}', | |
125 | # Prompt/history count, with the actual digits replaced by dots. Used |
|
125 | # Prompt/history count, with the actual digits replaced by dots. Used | |
126 | # mainly in continuation prompts (prompt_in2) |
|
126 | # mainly in continuation prompts (prompt_in2) | |
127 | '\\D': '${"."*len(str(self.cache.prompt_count))}', |
|
127 | '\\D': '${"."*len(str(self.cache.prompt_count))}', | |
128 | # Current working directory |
|
128 | # Current working directory | |
129 | '\\w': '${os.getcwd()}', |
|
129 | '\\w': '${os.getcwd()}', | |
130 | # Current time |
|
130 | # Current time | |
131 | '\\t' : '${time.strftime("%H:%M:%S")}', |
|
131 | '\\t' : '${time.strftime("%H:%M:%S")}', | |
132 | # Basename of current working directory. |
|
132 | # Basename of current working directory. | |
133 | # (use os.sep to make this portable across OSes) |
|
133 | # (use os.sep to make this portable across OSes) | |
134 | '\\W' : '${os.getcwd().split("%s")[-1]}' % os.sep, |
|
134 | '\\W' : '${os.getcwd().split("%s")[-1]}' % os.sep, | |
135 | # These X<N> are an extension to the normal bash prompts. They return |
|
135 | # These X<N> are an extension to the normal bash prompts. They return | |
136 | # N terms of the path, after replacing $HOME with '~' |
|
136 | # N terms of the path, after replacing $HOME with '~' | |
137 | '\\X0': '${os.getcwd().replace("%s","~")}' % HOME, |
|
137 | '\\X0': '${os.getcwd().replace("%s","~")}' % HOME, | |
138 | '\\X1': '${self.cwd_filt(1)}', |
|
138 | '\\X1': '${self.cwd_filt(1)}', | |
139 | '\\X2': '${self.cwd_filt(2)}', |
|
139 | '\\X2': '${self.cwd_filt(2)}', | |
140 | '\\X3': '${self.cwd_filt(3)}', |
|
140 | '\\X3': '${self.cwd_filt(3)}', | |
141 | '\\X4': '${self.cwd_filt(4)}', |
|
141 | '\\X4': '${self.cwd_filt(4)}', | |
142 | '\\X5': '${self.cwd_filt(5)}', |
|
142 | '\\X5': '${self.cwd_filt(5)}', | |
143 | # Y<N> are similar to X<N>, but they show '~' if it's the directory |
|
143 | # Y<N> are similar to X<N>, but they show '~' if it's the directory | |
144 | # N+1 in the list. Somewhat like %cN in tcsh. |
|
144 | # N+1 in the list. Somewhat like %cN in tcsh. | |
145 | '\\Y0': '${self.cwd_filt2(0)}', |
|
145 | '\\Y0': '${self.cwd_filt2(0)}', | |
146 | '\\Y1': '${self.cwd_filt2(1)}', |
|
146 | '\\Y1': '${self.cwd_filt2(1)}', | |
147 | '\\Y2': '${self.cwd_filt2(2)}', |
|
147 | '\\Y2': '${self.cwd_filt2(2)}', | |
148 | '\\Y3': '${self.cwd_filt2(3)}', |
|
148 | '\\Y3': '${self.cwd_filt2(3)}', | |
149 | '\\Y4': '${self.cwd_filt2(4)}', |
|
149 | '\\Y4': '${self.cwd_filt2(4)}', | |
150 | '\\Y5': '${self.cwd_filt2(5)}', |
|
150 | '\\Y5': '${self.cwd_filt2(5)}', | |
151 | # Hostname up to first . |
|
151 | # Hostname up to first . | |
152 | '\\h': HOSTNAME_SHORT, |
|
152 | '\\h': HOSTNAME_SHORT, | |
153 | # Full hostname |
|
153 | # Full hostname | |
154 | '\\H': HOSTNAME, |
|
154 | '\\H': HOSTNAME, | |
155 | # Username of current user |
|
155 | # Username of current user | |
156 | '\\u': USER, |
|
156 | '\\u': USER, | |
157 | # Escaped '\' |
|
157 | # Escaped '\' | |
158 | '\\\\': '\\', |
|
158 | '\\\\': '\\', | |
159 | # Newline |
|
159 | # Newline | |
160 | '\\n': '\n', |
|
160 | '\\n': '\n', | |
161 | # Carriage return |
|
161 | # Carriage return | |
162 | '\\r': '\r', |
|
162 | '\\r': '\r', | |
163 | # Release version |
|
163 | # Release version | |
164 | '\\v': __version__, |
|
164 | '\\v': __version__, | |
165 | # Root symbol ($ or #) |
|
165 | # Root symbol ($ or #) | |
166 | '\\$': ROOT_SYMBOL, |
|
166 | '\\$': ROOT_SYMBOL, | |
167 | } |
|
167 | } | |
168 |
|
168 | |||
169 | # A copy of the prompt_specials dictionary but with all color escapes removed, |
|
169 | # A copy of the prompt_specials dictionary but with all color escapes removed, | |
170 | # so we can correctly compute the prompt length for the auto_rewrite method. |
|
170 | # so we can correctly compute the prompt length for the auto_rewrite method. | |
171 | prompt_specials_nocolor = prompt_specials_color.copy() |
|
171 | prompt_specials_nocolor = prompt_specials_color.copy() | |
172 | prompt_specials_nocolor['%n'] = '${self.cache.prompt_count}' |
|
172 | prompt_specials_nocolor['%n'] = '${self.cache.prompt_count}' | |
173 | prompt_specials_nocolor['\\#'] = '${self.cache.prompt_count}' |
|
173 | prompt_specials_nocolor['\\#'] = '${self.cache.prompt_count}' | |
174 |
|
174 | |||
175 | # Add in all the InputTermColors color escapes as valid prompt characters. |
|
175 | # Add in all the InputTermColors color escapes as valid prompt characters. | |
176 | # They all get added as \\C_COLORNAME, so that we don't have any conflicts |
|
176 | # They all get added as \\C_COLORNAME, so that we don't have any conflicts | |
177 | # with a color name which may begin with a letter used by any other of the |
|
177 | # with a color name which may begin with a letter used by any other of the | |
178 | # allowed specials. This of course means that \\C will never be allowed for |
|
178 | # allowed specials. This of course means that \\C will never be allowed for | |
179 | # anything else. |
|
179 | # anything else. | |
180 | input_colors = ColorANSI.InputTermColors |
|
180 | input_colors = ColorANSI.InputTermColors | |
181 | for _color in dir(input_colors): |
|
181 | for _color in dir(input_colors): | |
182 | if _color[0] != '_': |
|
182 | if _color[0] != '_': | |
183 | c_name = '\\C_'+_color |
|
183 | c_name = '\\C_'+_color | |
184 | prompt_specials_color[c_name] = getattr(input_colors,_color) |
|
184 | prompt_specials_color[c_name] = getattr(input_colors,_color) | |
185 | prompt_specials_nocolor[c_name] = '' |
|
185 | prompt_specials_nocolor[c_name] = '' | |
186 |
|
186 | |||
187 | # we default to no color for safety. Note that prompt_specials is a global |
|
187 | # we default to no color for safety. Note that prompt_specials is a global | |
188 | # variable used by all prompt objects. |
|
188 | # variable used by all prompt objects. | |
189 | prompt_specials = prompt_specials_nocolor |
|
189 | prompt_specials = prompt_specials_nocolor | |
190 |
|
190 | |||
191 | #----------------------------------------------------------------------------- |
|
191 | #----------------------------------------------------------------------------- | |
192 | def str_safe(arg): |
|
192 | def str_safe(arg): | |
193 | """Convert to a string, without ever raising an exception. |
|
193 | """Convert to a string, without ever raising an exception. | |
194 |
|
194 | |||
195 | If str(arg) fails, <ERROR: ... > is returned, where ... is the exception |
|
195 | If str(arg) fails, <ERROR: ... > is returned, where ... is the exception | |
196 | error message.""" |
|
196 | error message.""" | |
197 |
|
197 | |||
198 | try: |
|
198 | try: | |
199 |
|
|
199 | out = str(arg) | |
|
200 | except UnicodeError: | |||
|
201 | try: | |||
|
202 | out = arg.encode('utf_8','replace') | |||
|
203 | except Exception,msg: | |||
|
204 | # let's keep this little duplication here, so that the most common | |||
|
205 | # case doesn't suffer from a double try wrapping. | |||
|
206 | out = '<ERROR: %s>' % msg | |||
200 | except Exception,msg: |
|
207 | except Exception,msg: | |
201 |
|
|
208 | out = '<ERROR: %s>' % msg | |
|
209 | return out | |||
202 |
|
210 | |||
203 | class BasePrompt: |
|
211 | class BasePrompt: | |
204 | """Interactive prompt similar to Mathematica's.""" |
|
212 | """Interactive prompt similar to Mathematica's.""" | |
205 | def __init__(self,cache,sep,prompt,pad_left=False): |
|
213 | def __init__(self,cache,sep,prompt,pad_left=False): | |
206 |
|
214 | |||
207 | # Hack: we access information about the primary prompt through the |
|
215 | # Hack: we access information about the primary prompt through the | |
208 | # cache argument. We need this, because we want the secondary prompt |
|
216 | # cache argument. We need this, because we want the secondary prompt | |
209 | # to be aligned with the primary one. Color table info is also shared |
|
217 | # to be aligned with the primary one. Color table info is also shared | |
210 | # by all prompt classes through the cache. Nice OO spaghetti code! |
|
218 | # by all prompt classes through the cache. Nice OO spaghetti code! | |
211 | self.cache = cache |
|
219 | self.cache = cache | |
212 | self.sep = sep |
|
220 | self.sep = sep | |
213 |
|
221 | |||
214 | # regexp to count the number of spaces at the end of a prompt |
|
222 | # regexp to count the number of spaces at the end of a prompt | |
215 | # expression, useful for prompt auto-rewriting |
|
223 | # expression, useful for prompt auto-rewriting | |
216 | self.rspace = re.compile(r'(\s*)$') |
|
224 | self.rspace = re.compile(r'(\s*)$') | |
217 | # Flag to left-pad prompt strings to match the length of the primary |
|
225 | # Flag to left-pad prompt strings to match the length of the primary | |
218 | # prompt |
|
226 | # prompt | |
219 | self.pad_left = pad_left |
|
227 | self.pad_left = pad_left | |
220 | # Set template to create each actual prompt (where numbers change) |
|
228 | # Set template to create each actual prompt (where numbers change) | |
221 | self.p_template = prompt |
|
229 | self.p_template = prompt | |
222 | self.set_p_str() |
|
230 | self.set_p_str() | |
223 |
|
231 | |||
224 | def set_p_str(self): |
|
232 | def set_p_str(self): | |
225 | """ Set the interpolating prompt strings. |
|
233 | """ Set the interpolating prompt strings. | |
226 |
|
234 | |||
227 | This must be called every time the color settings change, because the |
|
235 | This must be called every time the color settings change, because the | |
228 | prompt_specials global may have changed.""" |
|
236 | prompt_specials global may have changed.""" | |
229 |
|
237 | |||
230 | import os,time # needed in locals for prompt string handling |
|
238 | import os,time # needed in locals for prompt string handling | |
231 | loc = locals() |
|
239 | loc = locals() | |
232 | self.p_str = ItplNS('%s%s%s' % |
|
240 | self.p_str = ItplNS('%s%s%s' % | |
233 | ('${self.sep}${self.col_p}', |
|
241 | ('${self.sep}${self.col_p}', | |
234 | multiple_replace(prompt_specials, self.p_template), |
|
242 | multiple_replace(prompt_specials, self.p_template), | |
235 | '${self.col_norm}'),self.cache.user_ns,loc) |
|
243 | '${self.col_norm}'),self.cache.user_ns,loc) | |
236 |
|
244 | |||
237 | self.p_str_nocolor = ItplNS(multiple_replace(prompt_specials_nocolor, |
|
245 | self.p_str_nocolor = ItplNS(multiple_replace(prompt_specials_nocolor, | |
238 | self.p_template), |
|
246 | self.p_template), | |
239 | self.cache.user_ns,loc) |
|
247 | self.cache.user_ns,loc) | |
240 |
|
248 | |||
241 | def write(self,msg): # dbg |
|
249 | def write(self,msg): # dbg | |
242 | sys.stdout.write(msg) |
|
250 | sys.stdout.write(msg) | |
243 | return '' |
|
251 | return '' | |
244 |
|
252 | |||
245 | def __str__(self): |
|
253 | def __str__(self): | |
246 | """Return a string form of the prompt. |
|
254 | """Return a string form of the prompt. | |
247 |
|
255 | |||
248 | This for is useful for continuation and output prompts, since it is |
|
256 | This for is useful for continuation and output prompts, since it is | |
249 | left-padded to match lengths with the primary one (if the |
|
257 | left-padded to match lengths with the primary one (if the | |
250 | self.pad_left attribute is set).""" |
|
258 | self.pad_left attribute is set).""" | |
251 |
|
259 | |||
252 | out_str = str_safe(self.p_str) |
|
260 | out_str = str_safe(self.p_str) | |
253 | if self.pad_left: |
|
261 | if self.pad_left: | |
254 | # We must find the amount of padding required to match lengths, |
|
262 | # We must find the amount of padding required to match lengths, | |
255 | # taking the color escapes (which are invisible on-screen) into |
|
263 | # taking the color escapes (which are invisible on-screen) into | |
256 | # account. |
|
264 | # account. | |
257 | esc_pad = len(out_str) - len(str_safe(self.p_str_nocolor)) |
|
265 | esc_pad = len(out_str) - len(str_safe(self.p_str_nocolor)) | |
258 | format = '%%%ss' % (len(str(self.cache.last_prompt))+esc_pad) |
|
266 | format = '%%%ss' % (len(str(self.cache.last_prompt))+esc_pad) | |
259 | return format % out_str |
|
267 | return format % out_str | |
260 | else: |
|
268 | else: | |
261 | return out_str |
|
269 | return out_str | |
262 |
|
270 | |||
263 | # these path filters are put in as methods so that we can control the |
|
271 | # these path filters are put in as methods so that we can control the | |
264 | # namespace where the prompt strings get evaluated |
|
272 | # namespace where the prompt strings get evaluated | |
265 | def cwd_filt(self,depth): |
|
273 | def cwd_filt(self,depth): | |
266 | """Return the last depth elements of the current working directory. |
|
274 | """Return the last depth elements of the current working directory. | |
267 |
|
275 | |||
268 | $HOME is always replaced with '~'. |
|
276 | $HOME is always replaced with '~'. | |
269 | If depth==0, the full path is returned.""" |
|
277 | If depth==0, the full path is returned.""" | |
270 |
|
278 | |||
271 | cwd = os.getcwd().replace(HOME,"~") |
|
279 | cwd = os.getcwd().replace(HOME,"~") | |
272 | out = os.sep.join(cwd.split(os.sep)[-depth:]) |
|
280 | out = os.sep.join(cwd.split(os.sep)[-depth:]) | |
273 | if out: |
|
281 | if out: | |
274 | return out |
|
282 | return out | |
275 | else: |
|
283 | else: | |
276 | return os.sep |
|
284 | return os.sep | |
277 |
|
285 | |||
278 | def cwd_filt2(self,depth): |
|
286 | def cwd_filt2(self,depth): | |
279 | """Return the last depth elements of the current working directory. |
|
287 | """Return the last depth elements of the current working directory. | |
280 |
|
288 | |||
281 | $HOME is always replaced with '~'. |
|
289 | $HOME is always replaced with '~'. | |
282 | If depth==0, the full path is returned.""" |
|
290 | If depth==0, the full path is returned.""" | |
283 |
|
291 | |||
284 | cwd = os.getcwd().replace(HOME,"~").split(os.sep) |
|
292 | cwd = os.getcwd().replace(HOME,"~").split(os.sep) | |
285 | if '~' in cwd and len(cwd) == depth+1: |
|
293 | if '~' in cwd and len(cwd) == depth+1: | |
286 | depth += 1 |
|
294 | depth += 1 | |
287 | out = os.sep.join(cwd[-depth:]) |
|
295 | out = os.sep.join(cwd[-depth:]) | |
288 | if out: |
|
296 | if out: | |
289 | return out |
|
297 | return out | |
290 | else: |
|
298 | else: | |
291 | return os.sep |
|
299 | return os.sep | |
292 |
|
300 | |||
293 | class Prompt1(BasePrompt): |
|
301 | class Prompt1(BasePrompt): | |
294 | """Input interactive prompt similar to Mathematica's.""" |
|
302 | """Input interactive prompt similar to Mathematica's.""" | |
295 |
|
303 | |||
296 | def __init__(self,cache,sep='\n',prompt='In [\\#]: ',pad_left=True): |
|
304 | def __init__(self,cache,sep='\n',prompt='In [\\#]: ',pad_left=True): | |
297 | BasePrompt.__init__(self,cache,sep,prompt,pad_left) |
|
305 | BasePrompt.__init__(self,cache,sep,prompt,pad_left) | |
298 |
|
306 | |||
299 | def set_colors(self): |
|
307 | def set_colors(self): | |
300 | self.set_p_str() |
|
308 | self.set_p_str() | |
301 | Colors = self.cache.color_table.active_colors # shorthand |
|
309 | Colors = self.cache.color_table.active_colors # shorthand | |
302 | self.col_p = Colors.in_prompt |
|
310 | self.col_p = Colors.in_prompt | |
303 | self.col_num = Colors.in_number |
|
311 | self.col_num = Colors.in_number | |
304 | self.col_norm = Colors.in_normal |
|
312 | self.col_norm = Colors.in_normal | |
305 | # We need a non-input version of these escapes for the '--->' |
|
313 | # We need a non-input version of these escapes for the '--->' | |
306 | # auto-call prompts used in the auto_rewrite() method. |
|
314 | # auto-call prompts used in the auto_rewrite() method. | |
307 | self.col_p_ni = self.col_p.replace('\001','').replace('\002','') |
|
315 | self.col_p_ni = self.col_p.replace('\001','').replace('\002','') | |
308 | self.col_norm_ni = Colors.normal |
|
316 | self.col_norm_ni = Colors.normal | |
309 |
|
317 | |||
310 | def __str__(self): |
|
318 | def __str__(self): | |
311 | self.cache.prompt_count += 1 |
|
319 | self.cache.prompt_count += 1 | |
312 | self.cache.last_prompt = str_safe(self.p_str_nocolor).split('\n')[-1] |
|
320 | self.cache.last_prompt = str_safe(self.p_str_nocolor).split('\n')[-1] | |
313 | return str_safe(self.p_str) |
|
321 | return str_safe(self.p_str) | |
314 |
|
322 | |||
315 | def auto_rewrite(self): |
|
323 | def auto_rewrite(self): | |
316 | """Print a string of the form '--->' which lines up with the previous |
|
324 | """Print a string of the form '--->' which lines up with the previous | |
317 | input string. Useful for systems which re-write the user input when |
|
325 | input string. Useful for systems which re-write the user input when | |
318 | handling automatically special syntaxes.""" |
|
326 | handling automatically special syntaxes.""" | |
319 |
|
327 | |||
320 | curr = str(self.cache.last_prompt) |
|
328 | curr = str(self.cache.last_prompt) | |
321 | nrspaces = len(self.rspace.search(curr).group()) |
|
329 | nrspaces = len(self.rspace.search(curr).group()) | |
322 | return '%s%s>%s%s' % (self.col_p_ni,'-'*(len(curr)-nrspaces-1), |
|
330 | return '%s%s>%s%s' % (self.col_p_ni,'-'*(len(curr)-nrspaces-1), | |
323 | ' '*nrspaces,self.col_norm_ni) |
|
331 | ' '*nrspaces,self.col_norm_ni) | |
324 |
|
332 | |||
325 | class PromptOut(BasePrompt): |
|
333 | class PromptOut(BasePrompt): | |
326 | """Output interactive prompt similar to Mathematica's.""" |
|
334 | """Output interactive prompt similar to Mathematica's.""" | |
327 |
|
335 | |||
328 | def __init__(self,cache,sep='',prompt='Out[\\#]: ',pad_left=True): |
|
336 | def __init__(self,cache,sep='',prompt='Out[\\#]: ',pad_left=True): | |
329 | BasePrompt.__init__(self,cache,sep,prompt,pad_left) |
|
337 | BasePrompt.__init__(self,cache,sep,prompt,pad_left) | |
330 | if not self.p_template: |
|
338 | if not self.p_template: | |
331 | self.__str__ = lambda: '' |
|
339 | self.__str__ = lambda: '' | |
332 |
|
340 | |||
333 | def set_colors(self): |
|
341 | def set_colors(self): | |
334 | self.set_p_str() |
|
342 | self.set_p_str() | |
335 | Colors = self.cache.color_table.active_colors # shorthand |
|
343 | Colors = self.cache.color_table.active_colors # shorthand | |
336 | self.col_p = Colors.out_prompt |
|
344 | self.col_p = Colors.out_prompt | |
337 | self.col_num = Colors.out_number |
|
345 | self.col_num = Colors.out_number | |
338 | self.col_norm = Colors.normal |
|
346 | self.col_norm = Colors.normal | |
339 |
|
347 | |||
340 | class Prompt2(BasePrompt): |
|
348 | class Prompt2(BasePrompt): | |
341 | """Interactive continuation prompt.""" |
|
349 | """Interactive continuation prompt.""" | |
342 |
|
350 | |||
343 | def __init__(self,cache,prompt=' .\\D.: ',pad_left=True): |
|
351 | def __init__(self,cache,prompt=' .\\D.: ',pad_left=True): | |
344 | self.cache = cache |
|
352 | self.cache = cache | |
345 | self.p_template = prompt |
|
353 | self.p_template = prompt | |
346 | self.pad_left = pad_left |
|
354 | self.pad_left = pad_left | |
347 | self.set_p_str() |
|
355 | self.set_p_str() | |
348 |
|
356 | |||
349 | def set_p_str(self): |
|
357 | def set_p_str(self): | |
350 | import os,time # needed in locals for prompt string handling |
|
358 | import os,time # needed in locals for prompt string handling | |
351 | loc = locals() |
|
359 | loc = locals() | |
352 | self.p_str = ItplNS('%s%s%s' % |
|
360 | self.p_str = ItplNS('%s%s%s' % | |
353 | ('${self.col_p2}', |
|
361 | ('${self.col_p2}', | |
354 | multiple_replace(prompt_specials, self.p_template), |
|
362 | multiple_replace(prompt_specials, self.p_template), | |
355 | '$self.col_norm'), |
|
363 | '$self.col_norm'), | |
356 | self.cache.user_ns,loc) |
|
364 | self.cache.user_ns,loc) | |
357 | self.p_str_nocolor = ItplNS(multiple_replace(prompt_specials_nocolor, |
|
365 | self.p_str_nocolor = ItplNS(multiple_replace(prompt_specials_nocolor, | |
358 | self.p_template), |
|
366 | self.p_template), | |
359 | self.cache.user_ns,loc) |
|
367 | self.cache.user_ns,loc) | |
360 |
|
368 | |||
361 | def set_colors(self): |
|
369 | def set_colors(self): | |
362 | self.set_p_str() |
|
370 | self.set_p_str() | |
363 | Colors = self.cache.color_table.active_colors |
|
371 | Colors = self.cache.color_table.active_colors | |
364 | self.col_p2 = Colors.in_prompt2 |
|
372 | self.col_p2 = Colors.in_prompt2 | |
365 | self.col_norm = Colors.in_normal |
|
373 | self.col_norm = Colors.in_normal | |
366 | # FIXME (2004-06-16) HACK: prevent crashes for users who haven't |
|
374 | # FIXME (2004-06-16) HACK: prevent crashes for users who haven't | |
367 | # updated their prompt_in2 definitions. Remove eventually. |
|
375 | # updated their prompt_in2 definitions. Remove eventually. | |
368 | self.col_p = Colors.out_prompt |
|
376 | self.col_p = Colors.out_prompt | |
369 | self.col_num = Colors.out_number |
|
377 | self.col_num = Colors.out_number | |
370 |
|
378 | |||
371 | #----------------------------------------------------------------------------- |
|
379 | #----------------------------------------------------------------------------- | |
372 | class CachedOutput: |
|
380 | class CachedOutput: | |
373 | """Class for printing output from calculations while keeping a cache of |
|
381 | """Class for printing output from calculations while keeping a cache of | |
374 | reults. It dynamically creates global variables prefixed with _ which |
|
382 | reults. It dynamically creates global variables prefixed with _ which | |
375 | contain these results. |
|
383 | contain these results. | |
376 |
|
384 | |||
377 | Meant to be used as a sys.displayhook replacement, providing numbered |
|
385 | Meant to be used as a sys.displayhook replacement, providing numbered | |
378 | prompts and cache services. |
|
386 | prompts and cache services. | |
379 |
|
387 | |||
380 | Initialize with initial and final values for cache counter (this defines |
|
388 | Initialize with initial and final values for cache counter (this defines | |
381 | the maximum size of the cache.""" |
|
389 | the maximum size of the cache.""" | |
382 |
|
390 | |||
383 | def __init__(self,cache_size,Pprint,colors='NoColor',input_sep='\n', |
|
391 | def __init__(self,cache_size,Pprint,colors='NoColor',input_sep='\n', | |
384 | output_sep='\n',output_sep2='',user_ns={}, |
|
392 | output_sep='\n',output_sep2='',user_ns={}, | |
385 | ps1 = None, ps2 = None,ps_out = None, |
|
393 | ps1 = None, ps2 = None,ps_out = None, | |
386 | input_hist = None,pad_left=True): |
|
394 | input_hist = None,pad_left=True): | |
387 |
|
395 | |||
388 | cache_size_min = 20 |
|
396 | cache_size_min = 20 | |
389 | if cache_size <= 0: |
|
397 | if cache_size <= 0: | |
390 | self.do_full_cache = 0 |
|
398 | self.do_full_cache = 0 | |
391 | cache_size = 0 |
|
399 | cache_size = 0 | |
392 | elif cache_size < cache_size_min: |
|
400 | elif cache_size < cache_size_min: | |
393 | self.do_full_cache = 0 |
|
401 | self.do_full_cache = 0 | |
394 | cache_size = 0 |
|
402 | cache_size = 0 | |
395 | warn('caching was disabled (min value for cache size is %s).' % |
|
403 | warn('caching was disabled (min value for cache size is %s).' % | |
396 | cache_size_min,level=3) |
|
404 | cache_size_min,level=3) | |
397 | else: |
|
405 | else: | |
398 | self.do_full_cache = 1 |
|
406 | self.do_full_cache = 1 | |
399 |
|
407 | |||
400 | self.cache_size = cache_size |
|
408 | self.cache_size = cache_size | |
401 | self.input_sep = input_sep |
|
409 | self.input_sep = input_sep | |
402 |
|
410 | |||
403 | # we need a reference to the user-level namespace |
|
411 | # we need a reference to the user-level namespace | |
404 | self.user_ns = user_ns |
|
412 | self.user_ns = user_ns | |
405 | # and to the user's input |
|
413 | # and to the user's input | |
406 | self.input_hist = input_hist |
|
414 | self.input_hist = input_hist | |
407 |
|
415 | |||
408 | # Set input prompt strings and colors |
|
416 | # Set input prompt strings and colors | |
409 | if cache_size == 0: |
|
417 | if cache_size == 0: | |
410 | if ps1.find('%n') > -1 or ps1.find('\\#') > -1: ps1 = '>>> ' |
|
418 | if ps1.find('%n') > -1 or ps1.find('\\#') > -1: ps1 = '>>> ' | |
411 | if ps2.find('%n') > -1 or ps2.find('\\#') > -1: ps2 = '... ' |
|
419 | if ps2.find('%n') > -1 or ps2.find('\\#') > -1: ps2 = '... ' | |
412 | self.ps1_str = self._set_prompt_str(ps1,'In [\\#]: ','>>> ') |
|
420 | self.ps1_str = self._set_prompt_str(ps1,'In [\\#]: ','>>> ') | |
413 | self.ps2_str = self._set_prompt_str(ps2,' .\\D.: ','... ') |
|
421 | self.ps2_str = self._set_prompt_str(ps2,' .\\D.: ','... ') | |
414 | self.ps_out_str = self._set_prompt_str(ps_out,'Out[\\#]: ','') |
|
422 | self.ps_out_str = self._set_prompt_str(ps_out,'Out[\\#]: ','') | |
415 |
|
423 | |||
|
424 | self.color_table = PromptColors | |||
416 | self.prompt1 = Prompt1(self,sep=input_sep,prompt=self.ps1_str, |
|
425 | self.prompt1 = Prompt1(self,sep=input_sep,prompt=self.ps1_str, | |
417 | pad_left=pad_left) |
|
426 | pad_left=pad_left) | |
418 | self.prompt2 = Prompt2(self,prompt=self.ps2_str,pad_left=pad_left) |
|
427 | self.prompt2 = Prompt2(self,prompt=self.ps2_str,pad_left=pad_left) | |
419 | self.prompt_out = PromptOut(self,sep='',prompt=self.ps_out_str, |
|
428 | self.prompt_out = PromptOut(self,sep='',prompt=self.ps_out_str, | |
420 | pad_left=pad_left) |
|
429 | pad_left=pad_left) | |
421 | self.color_table = PromptColors |
|
|||
422 | self.set_colors(colors) |
|
430 | self.set_colors(colors) | |
423 |
|
431 | |||
424 | # other more normal stuff |
|
432 | # other more normal stuff | |
425 | # b/c each call to the In[] prompt raises it by 1, even the first. |
|
433 | # b/c each call to the In[] prompt raises it by 1, even the first. | |
426 | self.prompt_count = 0 |
|
434 | self.prompt_count = 0 | |
427 | self.cache_count = 1 |
|
435 | self.cache_count = 1 | |
428 | # Store the last prompt string each time, we need it for aligning |
|
436 | # Store the last prompt string each time, we need it for aligning | |
429 | # continuation and auto-rewrite prompts |
|
437 | # continuation and auto-rewrite prompts | |
430 | self.last_prompt = '' |
|
438 | self.last_prompt = '' | |
431 | self.entries = [None] # output counter starts at 1 for the user |
|
439 | self.entries = [None] # output counter starts at 1 for the user | |
432 | self.Pprint = Pprint |
|
440 | self.Pprint = Pprint | |
433 | self.output_sep = output_sep |
|
441 | self.output_sep = output_sep | |
434 | self.output_sep2 = output_sep2 |
|
442 | self.output_sep2 = output_sep2 | |
435 | self._,self.__,self.___ = '','','' |
|
443 | self._,self.__,self.___ = '','','' | |
436 | self.pprint_types = map(type,[(),[],{}]) |
|
444 | self.pprint_types = map(type,[(),[],{}]) | |
437 |
|
445 | |||
438 | # these are deliberately global: |
|
446 | # these are deliberately global: | |
439 | to_user_ns = {'_':self._,'__':self.__,'___':self.___} |
|
447 | to_user_ns = {'_':self._,'__':self.__,'___':self.___} | |
440 | self.user_ns.update(to_user_ns) |
|
448 | self.user_ns.update(to_user_ns) | |
441 |
|
449 | |||
442 | def _set_prompt_str(self,p_str,cache_def,no_cache_def): |
|
450 | def _set_prompt_str(self,p_str,cache_def,no_cache_def): | |
443 | if p_str is None: |
|
451 | if p_str is None: | |
444 | if self.do_full_cache: |
|
452 | if self.do_full_cache: | |
445 | return cache_def |
|
453 | return cache_def | |
446 | else: |
|
454 | else: | |
447 | return no_cache_def |
|
455 | return no_cache_def | |
448 | else: |
|
456 | else: | |
449 | return p_str |
|
457 | return p_str | |
450 |
|
458 | |||
451 | def set_colors(self,colors): |
|
459 | def set_colors(self,colors): | |
452 | """Set the active color scheme and configure colors for the three |
|
460 | """Set the active color scheme and configure colors for the three | |
453 | prompt subsystems.""" |
|
461 | prompt subsystems.""" | |
454 |
|
462 | |||
455 | # FIXME: the prompt_specials global should be gobbled inside this |
|
463 | # FIXME: the prompt_specials global should be gobbled inside this | |
456 | # class instead. Do it when cleaning up the whole 3-prompt system. |
|
464 | # class instead. Do it when cleaning up the whole 3-prompt system. | |
457 | global prompt_specials |
|
465 | global prompt_specials | |
458 | if colors.lower()=='nocolor': |
|
466 | if colors.lower()=='nocolor': | |
459 | prompt_specials = prompt_specials_nocolor |
|
467 | prompt_specials = prompt_specials_nocolor | |
460 | else: |
|
468 | else: | |
461 | prompt_specials = prompt_specials_color |
|
469 | prompt_specials = prompt_specials_color | |
462 |
|
470 | |||
463 | self.color_table.set_active_scheme(colors) |
|
471 | self.color_table.set_active_scheme(colors) | |
464 | self.prompt1.set_colors() |
|
472 | self.prompt1.set_colors() | |
465 | self.prompt2.set_colors() |
|
473 | self.prompt2.set_colors() | |
466 | self.prompt_out.set_colors() |
|
474 | self.prompt_out.set_colors() | |
467 |
|
475 | |||
468 | def __call__(self,arg=None): |
|
476 | def __call__(self,arg=None): | |
469 | """Printing with history cache management. |
|
477 | """Printing with history cache management. | |
470 |
|
478 | |||
471 | This is invoked everytime the interpreter needs to print, and is |
|
479 | This is invoked everytime the interpreter needs to print, and is | |
472 | activated by setting the variable sys.displayhook to it.""" |
|
480 | activated by setting the variable sys.displayhook to it.""" | |
473 |
|
481 | |||
474 | # If something injected a '_' variable in __builtin__, delete |
|
482 | # If something injected a '_' variable in __builtin__, delete | |
475 | # ipython's automatic one so we don't clobber that. gettext() in |
|
483 | # ipython's automatic one so we don't clobber that. gettext() in | |
476 | # particular uses _, so we need to stay away from it. |
|
484 | # particular uses _, so we need to stay away from it. | |
477 | if '_' in __builtin__.__dict__: |
|
485 | if '_' in __builtin__.__dict__: | |
478 | try: |
|
486 | try: | |
479 | del self.user_ns['_'] |
|
487 | del self.user_ns['_'] | |
480 | except KeyError: |
|
488 | except KeyError: | |
481 | pass |
|
489 | pass | |
482 | if arg is not None: |
|
490 | if arg is not None: | |
|
491 | cout_write = Term.cout.write # fast lookup | |||
483 | # first handle the cache and counters |
|
492 | # first handle the cache and counters | |
484 | self.update(arg) |
|
493 | self.update(arg) | |
485 | # do not print output if input ends in ';' |
|
494 | # do not print output if input ends in ';' | |
486 | if self.input_hist[self.prompt_count].endswith(';\n'): |
|
495 | if self.input_hist[self.prompt_count].endswith(';\n'): | |
487 | return |
|
496 | return | |
488 | # don't use print, puts an extra space |
|
497 | # don't use print, puts an extra space | |
489 |
|
|
498 | cout_write(self.output_sep) | |
490 | if self.do_full_cache: |
|
499 | if self.do_full_cache: | |
491 |
|
|
500 | cout_write(str(self.prompt_out)) | |
492 |
|
501 | |||
493 | if isinstance(arg,Macro): |
|
502 | if isinstance(arg,Macro): | |
494 | print 'Executing Macro...' |
|
503 | print 'Executing Macro...' | |
495 | # in case the macro takes a long time to execute |
|
504 | # in case the macro takes a long time to execute | |
496 | Term.cout.flush() |
|
505 | Term.cout.flush() | |
497 | exec arg.value in self.user_ns |
|
506 | exec arg.value in self.user_ns | |
498 | return None |
|
507 | return None | |
499 |
|
508 | |||
500 | # and now call a possibly user-defined print mechanism |
|
509 | # and now call a possibly user-defined print mechanism | |
501 | self.display(arg) |
|
510 | self.display(arg) | |
502 |
|
|
511 | cout_write(self.output_sep2) | |
503 | Term.cout.flush() |
|
512 | Term.cout.flush() | |
504 |
|
513 | |||
505 | def _display(self,arg): |
|
514 | def _display(self,arg): | |
506 | """Default printer method, uses pprint. |
|
515 | """Default printer method, uses pprint. | |
507 |
|
516 | |||
508 | This can be over-ridden by the users to implement special formatting |
|
517 | This can be over-ridden by the users to implement special formatting | |
509 | of certain types of output.""" |
|
518 | of certain types of output.""" | |
510 |
|
519 | |||
511 | if self.Pprint: |
|
520 | if self.Pprint: | |
512 | # The following is an UGLY kludge, b/c python fails to properly |
|
521 | out = pformat(arg) | |
513 | # identify instances of classes imported in the user namespace |
|
|||
514 | # (they have different memory locations, I guess). Structs are |
|
|||
515 | # essentially dicts but pprint doesn't know what to do with them. |
|
|||
516 | try: |
|
|||
517 | if arg.__class__.__module__ == 'Struct' and \ |
|
|||
518 | arg.__class__.__name__ == 'Struct': |
|
|||
519 | out = 'Struct:\n%s' % pformat(arg.dict()) |
|
|||
520 | else: |
|
|||
521 | out = pformat(arg) |
|
|||
522 | except: |
|
|||
523 | out = pformat(arg) |
|
|||
524 | if '\n' in out: |
|
522 | if '\n' in out: | |
525 | # So that multi-line strings line up with the left column of |
|
523 | # So that multi-line strings line up with the left column of | |
526 | # the screen, instead of having the output prompt mess up |
|
524 | # the screen, instead of having the output prompt mess up | |
527 | # their first line. |
|
525 | # their first line. | |
528 | Term.cout.write('\n') |
|
526 | Term.cout.write('\n') | |
529 | print >>Term.cout, out |
|
527 | print >>Term.cout, out | |
530 | else: |
|
528 | else: | |
531 | print >>Term.cout, arg |
|
529 | print >>Term.cout, arg | |
532 |
|
530 | |||
533 | # Assign the default display method: |
|
531 | # Assign the default display method: | |
534 | display = _display |
|
532 | display = _display | |
535 |
|
533 | |||
536 | def update(self,arg): |
|
534 | def update(self,arg): | |
537 | #print '***cache_count', self.cache_count # dbg |
|
535 | #print '***cache_count', self.cache_count # dbg | |
538 | if self.cache_count >= self.cache_size and self.do_full_cache: |
|
536 | if self.cache_count >= self.cache_size and self.do_full_cache: | |
539 | self.flush() |
|
537 | self.flush() | |
540 | # Don't overwrite '_' and friends if '_' is in __builtin__ (otherwise |
|
538 | # Don't overwrite '_' and friends if '_' is in __builtin__ (otherwise | |
541 | # we cause buggy behavior for things like gettext). |
|
539 | # we cause buggy behavior for things like gettext). | |
542 | if '_' not in __builtin__.__dict__: |
|
540 | if '_' not in __builtin__.__dict__: | |
543 | self.___ = self.__ |
|
541 | self.___ = self.__ | |
544 | self.__ = self._ |
|
542 | self.__ = self._ | |
545 | self._ = arg |
|
543 | self._ = arg | |
546 | self.user_ns.update({'_':self._,'__':self.__,'___':self.___}) |
|
544 | self.user_ns.update({'_':self._,'__':self.__,'___':self.___}) | |
547 |
|
545 | |||
548 | # hackish access to top-level namespace to create _1,_2... dynamically |
|
546 | # hackish access to top-level namespace to create _1,_2... dynamically | |
549 | to_main = {} |
|
547 | to_main = {} | |
550 | if self.do_full_cache: |
|
548 | if self.do_full_cache: | |
551 | self.cache_count += 1 |
|
549 | self.cache_count += 1 | |
552 | self.entries.append(arg) |
|
550 | self.entries.append(arg) | |
553 | new_result = '_'+`self.prompt_count` |
|
551 | new_result = '_'+`self.prompt_count` | |
554 | to_main[new_result] = self.entries[-1] |
|
552 | to_main[new_result] = self.entries[-1] | |
555 | self.user_ns.update(to_main) |
|
553 | self.user_ns.update(to_main) | |
556 | self.user_ns['_oh'][self.prompt_count] = arg |
|
554 | self.user_ns['_oh'][self.prompt_count] = arg | |
557 |
|
555 | |||
558 | def flush(self): |
|
556 | def flush(self): | |
559 | if not self.do_full_cache: |
|
557 | if not self.do_full_cache: | |
560 | raise ValueError,"You shouldn't have reached the cache flush "\ |
|
558 | raise ValueError,"You shouldn't have reached the cache flush "\ | |
561 | "if full caching is not enabled!" |
|
559 | "if full caching is not enabled!" | |
562 | warn('Output cache limit (currently '+\ |
|
560 | warn('Output cache limit (currently '+\ | |
563 | `self.cache_count`+' entries) hit.\n' |
|
561 | `self.cache_count`+' entries) hit.\n' | |
564 | 'Flushing cache and resetting history counter...\n' |
|
562 | 'Flushing cache and resetting history counter...\n' | |
565 | 'The only history variables available will be _,__,___ and _1\n' |
|
563 | 'The only history variables available will be _,__,___ and _1\n' | |
566 | 'with the current result.') |
|
564 | 'with the current result.') | |
567 | # delete auto-generated vars from global namespace |
|
565 | # delete auto-generated vars from global namespace | |
568 | for n in range(1,self.prompt_count + 1): |
|
566 | for n in range(1,self.prompt_count + 1): | |
569 | key = '_'+`n` |
|
567 | key = '_'+`n` | |
570 | try: |
|
568 | try: | |
571 | del self.user_ns[key] |
|
569 | del self.user_ns[key] | |
572 | except: pass |
|
570 | except: pass | |
573 | self.prompt_count = 1 |
|
571 | self.prompt_count = 1 | |
574 | self.cache_count = 1 |
|
572 | self.cache_count = 1 |
@@ -1,376 +1,375 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """Mimic C structs with lots of extra functionality. |
|
2 | """Mimic C structs with lots of extra functionality. | |
3 |
|
3 | |||
4 |
$Id: Struct.py |
|
4 | $Id: Struct.py 638 2005-07-18 03:01:41Z fperez $""" | |
5 |
|
5 | |||
6 | #***************************************************************************** |
|
6 | #***************************************************************************** | |
7 | # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu> |
|
7 | # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu> | |
8 | # |
|
8 | # | |
9 | # Distributed under the terms of the BSD License. The full license is in |
|
9 | # Distributed under the terms of the BSD License. The full license is in | |
10 | # the file COPYING, distributed as part of this software. |
|
10 | # the file COPYING, distributed as part of this software. | |
11 | #***************************************************************************** |
|
11 | #***************************************************************************** | |
12 |
|
12 | |||
13 | from IPython import Release |
|
13 | from IPython import Release | |
14 | __author__ = '%s <%s>' % Release.authors['Fernando'] |
|
14 | __author__ = '%s <%s>' % Release.authors['Fernando'] | |
15 | __license__ = Release.license |
|
15 | __license__ = Release.license | |
16 |
|
16 | |||
17 | __all__ = ['Struct'] |
|
17 | __all__ = ['Struct'] | |
18 |
|
18 | |||
19 | import types |
|
19 | import types | |
20 | from IPython.genutils import list2dict2 |
|
20 | from IPython.genutils import list2dict2 | |
21 |
|
21 | |||
22 | class Struct: |
|
22 | class Struct: | |
23 | """Class to mimic C structs but also provide convenient dictionary-like |
|
23 | """Class to mimic C structs but also provide convenient dictionary-like | |
24 | functionality. |
|
24 | functionality. | |
25 |
|
25 | |||
26 | Instances can be initialized with a dictionary, a list of key=value pairs |
|
26 | Instances can be initialized with a dictionary, a list of key=value pairs | |
27 | or both. If both are present, the dictionary must come first. |
|
27 | or both. If both are present, the dictionary must come first. | |
28 |
|
28 | |||
29 | Because Python classes provide direct assignment to their members, it's |
|
29 | Because Python classes provide direct assignment to their members, it's | |
30 | easy to overwrite normal methods (S.copy = 1 would destroy access to |
|
30 | easy to overwrite normal methods (S.copy = 1 would destroy access to | |
31 | S.copy()). For this reason, all builtin method names are protected and |
|
31 | S.copy()). For this reason, all builtin method names are protected and | |
32 | can't be assigned to. An attempt to do s.copy=1 or s['copy']=1 will raise |
|
32 | can't be assigned to. An attempt to do s.copy=1 or s['copy']=1 will raise | |
33 | a KeyError exception. If you really want to, you can bypass this |
|
33 | a KeyError exception. If you really want to, you can bypass this | |
34 | protection by directly assigning to __dict__: s.__dict__['copy']=1 will |
|
34 | protection by directly assigning to __dict__: s.__dict__['copy']=1 will | |
35 | still work. Doing this will break functionality, though. As in most of |
|
35 | still work. Doing this will break functionality, though. As in most of | |
36 | Python, namespace protection is weakly enforced, so feel free to shoot |
|
36 | Python, namespace protection is weakly enforced, so feel free to shoot | |
37 | yourself if you really want to. |
|
37 | yourself if you really want to. | |
38 |
|
38 | |||
39 | Note that this class uses more memory and is *much* slower than a regular |
|
39 | Note that this class uses more memory and is *much* slower than a regular | |
40 | dictionary, so be careful in situations where memory or performance are |
|
40 | dictionary, so be careful in situations where memory or performance are | |
41 | critical. But for day to day use it should behave fine. It is particularly |
|
41 | critical. But for day to day use it should behave fine. It is particularly | |
42 | convenient for storing configuration data in programs. |
|
42 | convenient for storing configuration data in programs. | |
43 |
|
43 | |||
44 | +,+=,- and -= are implemented. +/+= do merges (non-destructive updates), |
|
44 | +,+=,- and -= are implemented. +/+= do merges (non-destructive updates), | |
45 | -/-= remove keys from the original. See the method descripitions. |
|
45 | -/-= remove keys from the original. See the method descripitions. | |
46 |
|
46 | |||
47 | This class allows a quick access syntax: both s.key and s['key'] are |
|
47 | This class allows a quick access syntax: both s.key and s['key'] are | |
48 | valid. This syntax has a limitation: each 'key' has to be explicitly |
|
48 | valid. This syntax has a limitation: each 'key' has to be explicitly | |
49 | accessed by its original name. The normal s.key syntax doesn't provide |
|
49 | accessed by its original name. The normal s.key syntax doesn't provide | |
50 | access to the keys via variables whose values evaluate to the desired |
|
50 | access to the keys via variables whose values evaluate to the desired | |
51 | keys. An example should clarify this: |
|
51 | keys. An example should clarify this: | |
52 |
|
52 | |||
53 | Define a dictionary and initialize both with dict and k=v pairs: |
|
53 | Define a dictionary and initialize both with dict and k=v pairs: | |
54 | >>> d={'a':1,'b':2} |
|
54 | >>> d={'a':1,'b':2} | |
55 | >>> s=Struct(d,hi=10,ho=20) |
|
55 | >>> s=Struct(d,hi=10,ho=20) | |
56 | The return of __repr__ can be used to create a new instance: |
|
56 | The return of __repr__ can be used to create a new instance: | |
57 | >>> s |
|
57 | >>> s | |
58 | Struct({'ho': 20, 'b': 2, 'hi': 10, 'a': 1}) |
|
58 | Struct({'ho': 20, 'b': 2, 'hi': 10, 'a': 1}) | |
59 | __str__ (called by print) shows it's not quite a regular dictionary: |
|
59 | __str__ (called by print) shows it's not quite a regular dictionary: | |
60 | >>> print s |
|
60 | >>> print s | |
61 | Struct {a: 1, b: 2, hi: 10, ho: 20} |
|
61 | Struct {a: 1, b: 2, hi: 10, ho: 20} | |
62 | Access by explicitly named key with dot notation: |
|
62 | Access by explicitly named key with dot notation: | |
63 | >>> s.a |
|
63 | >>> s.a | |
64 | 1 |
|
64 | 1 | |
65 | Or like a dictionary: |
|
65 | Or like a dictionary: | |
66 | >>> s['a'] |
|
66 | >>> s['a'] | |
67 | 1 |
|
67 | 1 | |
68 | If you want a variable to hold the key value, only dictionary access works: |
|
68 | If you want a variable to hold the key value, only dictionary access works: | |
69 | >>> key='hi' |
|
69 | >>> key='hi' | |
70 | >>> s.key |
|
70 | >>> s.key | |
71 | Traceback (most recent call last): |
|
71 | Traceback (most recent call last): | |
72 | File "<stdin>", line 1, in ? |
|
72 | File "<stdin>", line 1, in ? | |
73 | AttributeError: Struct instance has no attribute 'key' |
|
73 | AttributeError: Struct instance has no attribute 'key' | |
74 | >>> s[key] |
|
74 | >>> s[key] | |
75 | 10 |
|
75 | 10 | |
76 |
|
76 | |||
77 | Another limitation of the s.key syntax (and Struct(key=val) |
|
77 | Another limitation of the s.key syntax (and Struct(key=val) | |
78 | initialization): keys can't be numbers. But numeric keys can be used and |
|
78 | initialization): keys can't be numbers. But numeric keys can be used and | |
79 | accessed using the dictionary syntax. Again, an example: |
|
79 | accessed using the dictionary syntax. Again, an example: | |
80 |
|
80 | |||
81 | This doesn't work: |
|
81 | This doesn't work: | |
82 | >>> s=Struct(4='hi') |
|
82 | >>> s=Struct(4='hi') | |
83 | SyntaxError: keyword can't be an expression |
|
83 | SyntaxError: keyword can't be an expression | |
84 | But this does: |
|
84 | But this does: | |
85 | >>> s=Struct() |
|
85 | >>> s=Struct() | |
86 | >>> s[4]='hi' |
|
86 | >>> s[4]='hi' | |
87 | >>> s |
|
87 | >>> s | |
88 | Struct({4: 'hi'}) |
|
88 | Struct({4: 'hi'}) | |
89 | >>> s[4] |
|
89 | >>> s[4] | |
90 | 'hi' |
|
90 | 'hi' | |
91 | """ |
|
91 | """ | |
92 |
|
92 | |||
93 | # Attributes to which __setitem__ and __setattr__ will block access. |
|
93 | # Attributes to which __setitem__ and __setattr__ will block access. | |
94 | # Note: much of this will be moot in Python 2.2 and will be done in a much |
|
94 | # Note: much of this will be moot in Python 2.2 and will be done in a much | |
95 | # cleaner way. |
|
95 | # cleaner way. | |
96 | __protected = ('copy dict dictcopy get has_attr has_key items keys ' |
|
96 | __protected = ('copy dict dictcopy get has_attr has_key items keys ' | |
97 | 'merge popitem setdefault update values ' |
|
97 | 'merge popitem setdefault update values ' | |
98 | '__make_dict __dict_invert ').split() |
|
98 | '__make_dict __dict_invert ').split() | |
99 |
|
99 | |||
100 | def __init__(self,dict=None,**kw): |
|
100 | def __init__(self,dict=None,**kw): | |
101 | """Initialize with a dictionary, another Struct, or by giving |
|
101 | """Initialize with a dictionary, another Struct, or by giving | |
102 | explicitly the list of attributes. |
|
102 | explicitly the list of attributes. | |
103 |
|
103 | |||
104 | Both can be used, but the dictionary must come first: |
|
104 | Both can be used, but the dictionary must come first: | |
105 | Struct(dict), Struct(k1=v1,k2=v2) or Struct(dict,k1=v1,k2=v2). |
|
105 | Struct(dict), Struct(k1=v1,k2=v2) or Struct(dict,k1=v1,k2=v2). | |
106 | """ |
|
106 | """ | |
107 | if dict is None: |
|
107 | if dict is None: | |
108 | dict = {} |
|
108 | dict = {} | |
109 | if isinstance(dict,Struct): |
|
109 | if isinstance(dict,Struct): | |
110 | dict = dict.dict() |
|
110 | dict = dict.dict() | |
111 | elif dict and type(dict) is not types.DictType: |
|
111 | elif dict and type(dict) is not types.DictType: | |
112 | raise TypeError,\ |
|
112 | raise TypeError,\ | |
113 | 'Initialize with a dictionary or key=val pairs.' |
|
113 | 'Initialize with a dictionary or key=val pairs.' | |
114 | dict.update(kw) |
|
114 | dict.update(kw) | |
115 | # do the updating by hand to guarantee that we go through the |
|
115 | # do the updating by hand to guarantee that we go through the | |
116 | # safety-checked __setitem__ |
|
116 | # safety-checked __setitem__ | |
117 | for k,v in dict.items(): |
|
117 | for k,v in dict.items(): | |
118 | self[k] = v |
|
118 | self[k] = v | |
119 |
|
119 | |||
120 | def __setitem__(self,key,value): |
|
120 | def __setitem__(self,key,value): | |
121 | """Used when struct[key] = val calls are made.""" |
|
121 | """Used when struct[key] = val calls are made.""" | |
122 | if key in Struct.__protected: |
|
122 | if key in Struct.__protected: | |
123 | raise KeyError,'Key '+`key`+' is a protected key of class Struct.' |
|
123 | raise KeyError,'Key '+`key`+' is a protected key of class Struct.' | |
124 | self.__dict__[key] = value |
|
124 | self.__dict__[key] = value | |
125 |
|
125 | |||
126 | def __setattr__(self, key, value): |
|
126 | def __setattr__(self, key, value): | |
127 | """Used when struct.key = val calls are made.""" |
|
127 | """Used when struct.key = val calls are made.""" | |
128 | self.__setitem__(key,value) |
|
128 | self.__setitem__(key,value) | |
129 |
|
129 | |||
130 | def __str__(self): |
|
130 | def __str__(self): | |
131 | """Gets called by print.""" |
|
131 | """Gets called by print.""" | |
132 |
|
132 | |||
133 | return 'Struct('+str(self.__dict__)+')' |
|
133 | return 'Struct('+str(self.__dict__)+')' | |
134 |
|
134 | |||
135 | def __repr__(self): |
|
135 | def __repr__(self): | |
136 | """Gets called by repr. |
|
136 | """Gets called by repr. | |
137 |
|
137 | |||
138 | A Struct can be recreated with S_new=eval(repr(S_old)).""" |
|
138 | A Struct can be recreated with S_new=eval(repr(S_old)).""" | |
139 | return 'Struct('+str(self.__dict__)+')' |
|
139 | return 'Struct('+str(self.__dict__)+')' | |
140 |
|
140 | |||
141 | def __getitem__(self,key): |
|
141 | def __getitem__(self,key): | |
142 | """Allows struct[key] access.""" |
|
142 | """Allows struct[key] access.""" | |
143 | return self.__dict__[key] |
|
143 | return self.__dict__[key] | |
144 |
|
144 | |||
145 | def __contains__(self,key): |
|
145 | def __contains__(self,key): | |
146 | """Allows use of the 'in' operator.""" |
|
146 | """Allows use of the 'in' operator.""" | |
147 | return self.__dict__.has_key(key) |
|
147 | return self.__dict__.has_key(key) | |
148 |
|
148 | |||
149 | def __iadd__(self,other): |
|
149 | def __iadd__(self,other): | |
150 | """S += S2 is a shorthand for S.merge(S2).""" |
|
150 | """S += S2 is a shorthand for S.merge(S2).""" | |
151 | self.merge(other) |
|
151 | self.merge(other) | |
152 | return self |
|
152 | return self | |
153 |
|
153 | |||
154 | def __add__(self,other): |
|
154 | def __add__(self,other): | |
155 | """S + S2 -> New Struct made form S and S.merge(S2)""" |
|
155 | """S + S2 -> New Struct made form S and S.merge(S2)""" | |
156 | Sout = self.copy() |
|
156 | Sout = self.copy() | |
157 | Sout.merge(other) |
|
157 | Sout.merge(other) | |
158 | return Sout |
|
158 | return Sout | |
159 |
|
159 | |||
160 | def __sub__(self,other): |
|
160 | def __sub__(self,other): | |
161 | """Return S1-S2, where all keys in S2 have been deleted (if present) |
|
161 | """Return S1-S2, where all keys in S2 have been deleted (if present) | |
162 | from S1.""" |
|
162 | from S1.""" | |
163 | Sout = self.copy() |
|
163 | Sout = self.copy() | |
164 | Sout -= other |
|
164 | Sout -= other | |
165 | return Sout |
|
165 | return Sout | |
166 |
|
166 | |||
167 | def __isub__(self,other): |
|
167 | def __isub__(self,other): | |
168 | """Do in place S = S - S2, meaning all keys in S2 have been deleted |
|
168 | """Do in place S = S - S2, meaning all keys in S2 have been deleted | |
169 | (if present) from S1.""" |
|
169 | (if present) from S1.""" | |
170 |
|
170 | |||
171 | for k in other.keys(): |
|
171 | for k in other.keys(): | |
172 | if self.has_key(k): |
|
172 | if self.has_key(k): | |
173 | del self.__dict__[k] |
|
173 | del self.__dict__[k] | |
174 |
|
174 | |||
175 | def __make_dict(self,__loc_data__,**kw): |
|
175 | def __make_dict(self,__loc_data__,**kw): | |
176 | "Helper function for update and merge. Return a dict from data." |
|
176 | "Helper function for update and merge. Return a dict from data." | |
177 |
|
177 | |||
178 | if __loc_data__ == None: |
|
178 | if __loc_data__ == None: | |
179 | dict = {} |
|
179 | dict = {} | |
180 | elif type(__loc_data__) is types.DictType: |
|
180 | elif type(__loc_data__) is types.DictType: | |
181 | dict = __loc_data__ |
|
181 | dict = __loc_data__ | |
182 | elif isinstance(__loc_data__,Struct): |
|
182 | elif isinstance(__loc_data__,Struct): | |
183 | dict = __loc_data__.__dict__ |
|
183 | dict = __loc_data__.__dict__ | |
184 | else: |
|
184 | else: | |
185 | raise TypeError, 'Update with a dict, a Struct or key=val pairs.' |
|
185 | raise TypeError, 'Update with a dict, a Struct or key=val pairs.' | |
186 | if kw: |
|
186 | if kw: | |
187 | dict.update(kw) |
|
187 | dict.update(kw) | |
188 | return dict |
|
188 | return dict | |
189 |
|
189 | |||
190 | def __dict_invert(self,dict): |
|
190 | def __dict_invert(self,dict): | |
191 | """Helper function for merge. Takes a dictionary whose values are |
|
191 | """Helper function for merge. Takes a dictionary whose values are | |
192 | lists and returns a dict. with the elements of each list as keys and |
|
192 | lists and returns a dict. with the elements of each list as keys and | |
193 | the original keys as values.""" |
|
193 | the original keys as values.""" | |
194 |
|
194 | |||
195 | outdict = {} |
|
195 | outdict = {} | |
196 | for k,lst in dict.items(): |
|
196 | for k,lst in dict.items(): | |
197 | if type(lst) is types.StringType: |
|
197 | if type(lst) is types.StringType: | |
198 | lst = lst.split() |
|
198 | lst = lst.split() | |
199 | for entry in lst: |
|
199 | for entry in lst: | |
200 | outdict[entry] = k |
|
200 | outdict[entry] = k | |
201 | return outdict |
|
201 | return outdict | |
202 |
|
202 | |||
203 | def clear(self): |
|
203 | def clear(self): | |
204 | """Clear all attributes.""" |
|
204 | """Clear all attributes.""" | |
205 | self.__dict__.clear() |
|
205 | self.__dict__.clear() | |
206 |
|
206 | |||
207 | def copy(self): |
|
207 | def copy(self): | |
208 | """Return a (shallow) copy of a Struct.""" |
|
208 | """Return a (shallow) copy of a Struct.""" | |
209 | return Struct(self.__dict__.copy()) |
|
209 | return Struct(self.__dict__.copy()) | |
210 |
|
210 | |||
211 | def dict(self): |
|
211 | def dict(self): | |
212 | """Return the Struct's dictionary.""" |
|
212 | """Return the Struct's dictionary.""" | |
213 | return self.__dict__ |
|
213 | return self.__dict__ | |
214 |
|
214 | |||
215 | def dictcopy(self): |
|
215 | def dictcopy(self): | |
216 | """Return a (shallow) copy of the Struct's dictionary.""" |
|
216 | """Return a (shallow) copy of the Struct's dictionary.""" | |
217 | return self.__dict__.copy() |
|
217 | return self.__dict__.copy() | |
218 |
|
218 | |||
219 | def popitem(self): |
|
219 | def popitem(self): | |
220 | """S.popitem() -> (k, v), remove and return some (key, value) pair as |
|
220 | """S.popitem() -> (k, v), remove and return some (key, value) pair as | |
221 | a 2-tuple; but raise KeyError if S is empty.""" |
|
221 | a 2-tuple; but raise KeyError if S is empty.""" | |
222 | return self.__dict__.popitem() |
|
222 | return self.__dict__.popitem() | |
223 |
|
223 | |||
224 | def update(self,__loc_data__=None,**kw): |
|
224 | def update(self,__loc_data__=None,**kw): | |
225 | """Update (merge) with data from another Struct or from a dictionary. |
|
225 | """Update (merge) with data from another Struct or from a dictionary. | |
226 | Optionally, one or more key=value pairs can be given at the end for |
|
226 | Optionally, one or more key=value pairs can be given at the end for | |
227 | direct update.""" |
|
227 | direct update.""" | |
228 |
|
228 | |||
229 | # The funny name __loc_data__ is to prevent a common variable name which |
|
229 | # The funny name __loc_data__ is to prevent a common variable name which | |
230 | # could be a fieled of a Struct to collide with this parameter. The problem |
|
230 | # could be a fieled of a Struct to collide with this parameter. The problem | |
231 | # would arise if the function is called with a keyword with this same name |
|
231 | # would arise if the function is called with a keyword with this same name | |
232 | # that a user means to add as a Struct field. |
|
232 | # that a user means to add as a Struct field. | |
233 | newdict = Struct.__make_dict(self,__loc_data__,**kw) |
|
233 | newdict = Struct.__make_dict(self,__loc_data__,**kw) | |
234 | for k,v in newdict.items(): |
|
234 | for k,v in newdict.items(): | |
235 | self[k] = v |
|
235 | self[k] = v | |
236 |
|
236 | |||
237 | def merge(self,__loc_data__=None,__conflict_solve=None,**kw): |
|
237 | def merge(self,__loc_data__=None,__conflict_solve=None,**kw): | |
238 | """S.merge(data,conflict,k=v1,k=v2,...) -> merge data and k=v into S. |
|
238 | """S.merge(data,conflict,k=v1,k=v2,...) -> merge data and k=v into S. | |
239 |
|
239 | |||
240 | This is similar to update(), but much more flexible. First, a dict is |
|
240 | This is similar to update(), but much more flexible. First, a dict is | |
241 | made from data+key=value pairs. When merging this dict with the Struct |
|
241 | made from data+key=value pairs. When merging this dict with the Struct | |
242 | S, the optional dictionary 'conflict' is used to decide what to do. |
|
242 | S, the optional dictionary 'conflict' is used to decide what to do. | |
243 |
|
243 | |||
244 | If conflict is not given, the default behavior is to preserve any keys |
|
244 | If conflict is not given, the default behavior is to preserve any keys | |
245 | with their current value (the opposite of the update method's |
|
245 | with their current value (the opposite of the update method's | |
246 | behavior). |
|
246 | behavior). | |
247 |
|
247 | |||
248 | conflict is a dictionary of binary functions which will be used to |
|
248 | conflict is a dictionary of binary functions which will be used to | |
249 | solve key conflicts. It must have the following structure: |
|
249 | solve key conflicts. It must have the following structure: | |
250 |
|
250 | |||
251 | conflict == { fn1 : [Skey1,Skey2,...], fn2 : [Skey3], etc } |
|
251 | conflict == { fn1 : [Skey1,Skey2,...], fn2 : [Skey3], etc } | |
252 |
|
252 | |||
253 | Values must be lists or whitespace separated strings which are |
|
253 | Values must be lists or whitespace separated strings which are | |
254 | automatically converted to lists of strings by calling string.split(). |
|
254 | automatically converted to lists of strings by calling string.split(). | |
255 |
|
255 | |||
256 | Each key of conflict is a function which defines a policy for |
|
256 | Each key of conflict is a function which defines a policy for | |
257 | resolving conflicts when merging with the input data. Each fn must be |
|
257 | resolving conflicts when merging with the input data. Each fn must be | |
258 | a binary function which returns the desired outcome for a key |
|
258 | a binary function which returns the desired outcome for a key | |
259 | conflict. These functions will be called as fn(old,new). |
|
259 | conflict. These functions will be called as fn(old,new). | |
260 |
|
260 | |||
261 | An example is probably in order. Suppose you are merging the struct S |
|
261 | An example is probably in order. Suppose you are merging the struct S | |
262 | with a dict D and the following conflict policy dict: |
|
262 | with a dict D and the following conflict policy dict: | |
263 |
|
263 | |||
264 | S.merge(D,{fn1:['a','b',4], fn2:'key_c key_d'}) |
|
264 | S.merge(D,{fn1:['a','b',4], fn2:'key_c key_d'}) | |
265 |
|
265 | |||
266 | If the key 'a' is found in both S and D, the merge method will call: |
|
266 | If the key 'a' is found in both S and D, the merge method will call: | |
267 |
|
267 | |||
268 | S['a'] = fn1(S['a'],D['a']) |
|
268 | S['a'] = fn1(S['a'],D['a']) | |
269 |
|
269 | |||
270 | As a convenience, merge() provides five (the most commonly needed) |
|
270 | As a convenience, merge() provides five (the most commonly needed) | |
271 | pre-defined policies: preserve, update, add, add_flip and add_s. The |
|
271 | pre-defined policies: preserve, update, add, add_flip and add_s. The | |
272 | easiest explanation is their implementation: |
|
272 | easiest explanation is their implementation: | |
273 |
|
273 | |||
274 | preserve = lambda old,new: old |
|
274 | preserve = lambda old,new: old | |
275 | update = lambda old,new: new |
|
275 | update = lambda old,new: new | |
276 | add = lambda old,new: old + new |
|
276 | add = lambda old,new: old + new | |
277 | add_flip = lambda old,new: new + old # note change of order! |
|
277 | add_flip = lambda old,new: new + old # note change of order! | |
278 | add_s = lambda old,new: old + ' ' + new # only works for strings! |
|
278 | add_s = lambda old,new: old + ' ' + new # only works for strings! | |
279 |
|
279 | |||
280 | You can use those four words (as strings) as keys in conflict instead |
|
280 | You can use those four words (as strings) as keys in conflict instead | |
281 | of defining them as functions, and the merge method will substitute |
|
281 | of defining them as functions, and the merge method will substitute | |
282 | the appropriate functions for you. That is, the call |
|
282 | the appropriate functions for you. That is, the call | |
283 |
|
283 | |||
284 | S.merge(D,{'preserve':'a b c','add':[4,5,'d'],my_function:[6]}) |
|
284 | S.merge(D,{'preserve':'a b c','add':[4,5,'d'],my_function:[6]}) | |
285 |
|
285 | |||
286 | will automatically substitute the functions preserve and add for the |
|
286 | will automatically substitute the functions preserve and add for the | |
287 | names 'preserve' and 'add' before making any function calls. |
|
287 | names 'preserve' and 'add' before making any function calls. | |
288 |
|
288 | |||
289 | For more complicated conflict resolution policies, you still need to |
|
289 | For more complicated conflict resolution policies, you still need to | |
290 | construct your own functions. """ |
|
290 | construct your own functions. """ | |
291 |
|
291 | |||
292 | data_dict = Struct.__make_dict(self,__loc_data__,**kw) |
|
292 | data_dict = Struct.__make_dict(self,__loc_data__,**kw) | |
293 |
|
293 | |||
294 | # policies for conflict resolution: two argument functions which return |
|
294 | # policies for conflict resolution: two argument functions which return | |
295 | # the value that will go in the new struct |
|
295 | # the value that will go in the new struct | |
296 | preserve = lambda old,new: old |
|
296 | preserve = lambda old,new: old | |
297 | update = lambda old,new: new |
|
297 | update = lambda old,new: new | |
298 | add = lambda old,new: old + new |
|
298 | add = lambda old,new: old + new | |
299 | add_flip = lambda old,new: new + old # note change of order! |
|
299 | add_flip = lambda old,new: new + old # note change of order! | |
300 | add_s = lambda old,new: old + ' ' + new |
|
300 | add_s = lambda old,new: old + ' ' + new | |
301 |
|
301 | |||
302 | # default policy is to keep current keys when there's a conflict |
|
302 | # default policy is to keep current keys when there's a conflict | |
303 | conflict_solve = list2dict2(self.keys(),default = preserve) |
|
303 | conflict_solve = list2dict2(self.keys(),default = preserve) | |
304 |
|
304 | |||
305 | # the conflict_solve dictionary is given by the user 'inverted': we |
|
305 | # the conflict_solve dictionary is given by the user 'inverted': we | |
306 | # need a name-function mapping, it comes as a function -> names |
|
306 | # need a name-function mapping, it comes as a function -> names | |
307 | # dict. Make a local copy (b/c we'll make changes), replace user |
|
307 | # dict. Make a local copy (b/c we'll make changes), replace user | |
308 | # strings for the three builtin policies and invert it. |
|
308 | # strings for the three builtin policies and invert it. | |
309 | if __conflict_solve: |
|
309 | if __conflict_solve: | |
310 | inv_conflict_solve_user = __conflict_solve.copy() |
|
310 | inv_conflict_solve_user = __conflict_solve.copy() | |
311 | for name, func in [('preserve',preserve), ('update',update), |
|
311 | for name, func in [('preserve',preserve), ('update',update), | |
312 | ('add',add), ('add_flip',add_flip), ('add_s',add_s)]: |
|
312 | ('add',add), ('add_flip',add_flip), ('add_s',add_s)]: | |
313 | if name in inv_conflict_solve_user.keys(): |
|
313 | if name in inv_conflict_solve_user.keys(): | |
314 | inv_conflict_solve_user[func] = inv_conflict_solve_user[name] |
|
314 | inv_conflict_solve_user[func] = inv_conflict_solve_user[name] | |
315 | del inv_conflict_solve_user[name] |
|
315 | del inv_conflict_solve_user[name] | |
316 | conflict_solve.update(Struct.__dict_invert(self,inv_conflict_solve_user)) |
|
316 | conflict_solve.update(Struct.__dict_invert(self,inv_conflict_solve_user)) | |
317 | #print 'merge. conflict_solve: '; pprint(conflict_solve) # dbg |
|
317 | #print 'merge. conflict_solve: '; pprint(conflict_solve) # dbg | |
318 | # after Python 2.2, use iterators: for key in data_dict will then work |
|
|||
319 | #print '*'*50,'in merger. conflict_solver:'; pprint(conflict_solve) |
|
318 | #print '*'*50,'in merger. conflict_solver:'; pprint(conflict_solve) | |
320 |
for key in data_dict |
|
319 | for key in data_dict: | |
321 | if key not in self: |
|
320 | if key not in self: | |
322 | self[key] = data_dict[key] |
|
321 | self[key] = data_dict[key] | |
323 | else: |
|
322 | else: | |
324 | self[key] = conflict_solve[key](self[key],data_dict[key]) |
|
323 | self[key] = conflict_solve[key](self[key],data_dict[key]) | |
325 |
|
324 | |||
326 | def has_key(self,key): |
|
325 | def has_key(self,key): | |
327 | """Like has_key() dictionary method.""" |
|
326 | """Like has_key() dictionary method.""" | |
328 | return self.__dict__.has_key(key) |
|
327 | return self.__dict__.has_key(key) | |
329 |
|
328 | |||
330 | def hasattr(self,key): |
|
329 | def hasattr(self,key): | |
331 | """hasattr function available as a method. |
|
330 | """hasattr function available as a method. | |
332 |
|
331 | |||
333 | Implemented like has_key, to make sure that all available keys in the |
|
332 | Implemented like has_key, to make sure that all available keys in the | |
334 | internal dictionary of the Struct appear also as attributes (even |
|
333 | internal dictionary of the Struct appear also as attributes (even | |
335 | numeric keys).""" |
|
334 | numeric keys).""" | |
336 | return self.__dict__.has_key(key) |
|
335 | return self.__dict__.has_key(key) | |
337 |
|
336 | |||
338 | def items(self): |
|
337 | def items(self): | |
339 | """Return the items in the Struct's dictionary, in the same format |
|
338 | """Return the items in the Struct's dictionary, in the same format | |
340 | as a call to {}.items().""" |
|
339 | as a call to {}.items().""" | |
341 | return self.__dict__.items() |
|
340 | return self.__dict__.items() | |
342 |
|
341 | |||
343 | def keys(self): |
|
342 | def keys(self): | |
344 | """Return the keys in the Struct's dictionary, in the same format |
|
343 | """Return the keys in the Struct's dictionary, in the same format | |
345 | as a call to {}.keys().""" |
|
344 | as a call to {}.keys().""" | |
346 | return self.__dict__.keys() |
|
345 | return self.__dict__.keys() | |
347 |
|
346 | |||
348 | def values(self,keys=None): |
|
347 | def values(self,keys=None): | |
349 | """Return the values in the Struct's dictionary, in the same format |
|
348 | """Return the values in the Struct's dictionary, in the same format | |
350 | as a call to {}.values(). |
|
349 | as a call to {}.values(). | |
351 |
|
350 | |||
352 | Can be called with an optional argument keys, which must be a list or |
|
351 | Can be called with an optional argument keys, which must be a list or | |
353 | tuple of keys. In this case it returns only the values corresponding |
|
352 | tuple of keys. In this case it returns only the values corresponding | |
354 | to those keys (allowing a form of 'slicing' for Structs).""" |
|
353 | to those keys (allowing a form of 'slicing' for Structs).""" | |
355 | if not keys: |
|
354 | if not keys: | |
356 | return self.__dict__.values() |
|
355 | return self.__dict__.values() | |
357 | else: |
|
356 | else: | |
358 | ret=[] |
|
357 | ret=[] | |
359 | for k in keys: |
|
358 | for k in keys: | |
360 | ret.append(self[k]) |
|
359 | ret.append(self[k]) | |
361 | return ret |
|
360 | return ret | |
362 |
|
361 | |||
363 | def get(self,attr,val=None): |
|
362 | def get(self,attr,val=None): | |
364 | """S.get(k[,d]) -> S[k] if S.has_key(k), else d. d defaults to None.""" |
|
363 | """S.get(k[,d]) -> S[k] if S.has_key(k), else d. d defaults to None.""" | |
365 | try: |
|
364 | try: | |
366 | return self[attr] |
|
365 | return self[attr] | |
367 | except KeyError: |
|
366 | except KeyError: | |
368 | return val |
|
367 | return val | |
369 |
|
368 | |||
370 | def setdefault(self,attr,val=None): |
|
369 | def setdefault(self,attr,val=None): | |
371 | """S.setdefault(k[,d]) -> S.get(k,d), also set S[k]=d if not S.has_key(k)""" |
|
370 | """S.setdefault(k[,d]) -> S.get(k,d), also set S[k]=d if not S.has_key(k)""" | |
372 | if not self.has_key(attr): |
|
371 | if not self.has_key(attr): | |
373 | self[attr] = val |
|
372 | self[attr] = val | |
374 | return self.get(attr,val) |
|
373 | return self.get(attr,val) | |
375 | # end class Struct |
|
374 | # end class Struct | |
376 |
|
375 |
@@ -1,504 +1,495 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """Manage background (threaded) jobs conveniently from an interactive shell. |
|
2 | """Manage background (threaded) jobs conveniently from an interactive shell. | |
3 |
|
3 | |||
4 | This module provides a BackgroundJobManager class. This is the main class |
|
4 | This module provides a BackgroundJobManager class. This is the main class | |
5 | meant for public usage, it implements an object which can create and manage |
|
5 | meant for public usage, it implements an object which can create and manage | |
6 | new background jobs. |
|
6 | new background jobs. | |
7 |
|
7 | |||
8 | It also provides the actual job classes managed by these BackgroundJobManager |
|
8 | It also provides the actual job classes managed by these BackgroundJobManager | |
9 | objects, see their docstrings below. |
|
9 | objects, see their docstrings below. | |
10 |
|
10 | |||
11 |
|
11 | |||
12 | This system was inspired by discussions with B. Granger and the |
|
12 | This system was inspired by discussions with B. Granger and the | |
13 | BackgroundCommand class described in the book Python Scripting for |
|
13 | BackgroundCommand class described in the book Python Scripting for | |
14 | Computational Science, by H. P. Langtangen: |
|
14 | Computational Science, by H. P. Langtangen: | |
15 |
|
15 | |||
16 | http://folk.uio.no/hpl/scripting |
|
16 | http://folk.uio.no/hpl/scripting | |
17 |
|
17 | |||
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 | |
19 | separate implementation). |
|
19 | separate implementation). | |
20 |
|
20 | |||
21 |
$Id: background_jobs.py |
|
21 | $Id: background_jobs.py 638 2005-07-18 03:01:41Z fperez $ | |
22 | """ |
|
22 | """ | |
23 |
|
23 | |||
24 | #***************************************************************************** |
|
24 | #***************************************************************************** | |
25 | # Copyright (C) 2005 Fernando Perez <fperez@colorado.edu> |
|
25 | # Copyright (C) 2005 Fernando Perez <fperez@colorado.edu> | |
26 | # |
|
26 | # | |
27 | # Distributed under the terms of the BSD License. The full license is in |
|
27 | # Distributed under the terms of the BSD License. The full license is in | |
28 | # the file COPYING, distributed as part of this software. |
|
28 | # the file COPYING, distributed as part of this software. | |
29 | #***************************************************************************** |
|
29 | #***************************************************************************** | |
30 |
|
30 | |||
31 | from IPython import Release |
|
31 | from IPython import Release | |
32 | __author__ = '%s <%s>' % Release.authors['Fernando'] |
|
32 | __author__ = '%s <%s>' % Release.authors['Fernando'] | |
33 | __license__ = Release.license |
|
33 | __license__ = Release.license | |
34 |
|
34 | |||
35 | # Code begins |
|
35 | # Code begins | |
36 | import threading,sys |
|
36 | import threading,sys | |
37 |
|
37 | |||
38 | from IPython.ultraTB import AutoFormattedTB |
|
38 | from IPython.ultraTB import AutoFormattedTB | |
39 | from IPython.genutils import warn,error |
|
39 | from IPython.genutils import warn,error | |
40 |
|
40 | |||
41 | # declares Python 2.2 compatibility symbols: |
|
|||
42 | try: |
|
|||
43 | basestring |
|
|||
44 | except NameError: |
|
|||
45 | import types |
|
|||
46 | basestring = (types.StringType, types.UnicodeType) |
|
|||
47 | True = 1==1 |
|
|||
48 | False = 1==0 |
|
|||
49 |
|
||||
50 | class BackgroundJobManager: |
|
41 | class BackgroundJobManager: | |
51 | """Class to manage a pool of backgrounded threaded jobs. |
|
42 | """Class to manage a pool of backgrounded threaded jobs. | |
52 |
|
43 | |||
53 | Below, we assume that 'jobs' is a BackgroundJobManager instance. |
|
44 | Below, we assume that 'jobs' is a BackgroundJobManager instance. | |
54 |
|
45 | |||
55 | Usage summary (see the method docstrings for details): |
|
46 | Usage summary (see the method docstrings for details): | |
56 |
|
47 | |||
57 | jobs.new(...) -> start a new job |
|
48 | jobs.new(...) -> start a new job | |
58 |
|
49 | |||
59 | jobs() or jobs.status() -> print status summary of all jobs |
|
50 | jobs() or jobs.status() -> print status summary of all jobs | |
60 |
|
51 | |||
61 | jobs[N] -> returns job number N. |
|
52 | jobs[N] -> returns job number N. | |
62 |
|
53 | |||
63 | foo = jobs[N].result -> assign to variable foo the result of job N |
|
54 | foo = jobs[N].result -> assign to variable foo the result of job N | |
64 |
|
55 | |||
65 | jobs[N].traceback() -> print the traceback of dead job N |
|
56 | jobs[N].traceback() -> print the traceback of dead job N | |
66 |
|
57 | |||
67 | jobs.remove(N) -> remove (finished) job N |
|
58 | jobs.remove(N) -> remove (finished) job N | |
68 |
|
59 | |||
69 | jobs.flush_finished() -> remove all finished jobs |
|
60 | jobs.flush_finished() -> remove all finished jobs | |
70 |
|
61 | |||
71 | As a convenience feature, BackgroundJobManager instances provide the |
|
62 | As a convenience feature, BackgroundJobManager instances provide the | |
72 | utility result and traceback methods which retrieve the corresponding |
|
63 | utility result and traceback methods which retrieve the corresponding | |
73 | information from the jobs list: |
|
64 | information from the jobs list: | |
74 |
|
65 | |||
75 | jobs.result(N) <--> jobs[N].result |
|
66 | jobs.result(N) <--> jobs[N].result | |
76 | jobs.traceback(N) <--> jobs[N].traceback() |
|
67 | jobs.traceback(N) <--> jobs[N].traceback() | |
77 |
|
68 | |||
78 | While this appears minor, it allows you to use tab completion |
|
69 | While this appears minor, it allows you to use tab completion | |
79 | interactively on the job manager instance. |
|
70 | interactively on the job manager instance. | |
80 |
|
71 | |||
81 | In interactive mode, IPython provides the magic fuction %bg for quick |
|
72 | In interactive mode, IPython provides the magic fuction %bg for quick | |
82 | creation of backgrounded expression-based jobs. Type bg? for details.""" |
|
73 | creation of backgrounded expression-based jobs. Type bg? for details.""" | |
83 |
|
74 | |||
84 | def __init__(self): |
|
75 | def __init__(self): | |
85 | # Lists for job management |
|
76 | # Lists for job management | |
86 | self.jobs_run = [] |
|
77 | self.jobs_run = [] | |
87 | self.jobs_comp = [] |
|
78 | self.jobs_comp = [] | |
88 | self.jobs_dead = [] |
|
79 | self.jobs_dead = [] | |
89 | # A dict of all jobs, so users can easily access any of them |
|
80 | # A dict of all jobs, so users can easily access any of them | |
90 | self.jobs_all = {} |
|
81 | self.jobs_all = {} | |
91 | # For reporting |
|
82 | # For reporting | |
92 | self._comp_report = [] |
|
83 | self._comp_report = [] | |
93 | self._dead_report = [] |
|
84 | self._dead_report = [] | |
94 | # Store status codes locally for fast lookups |
|
85 | # Store status codes locally for fast lookups | |
95 | self._s_created = BackgroundJobBase.stat_created_c |
|
86 | self._s_created = BackgroundJobBase.stat_created_c | |
96 | self._s_running = BackgroundJobBase.stat_running_c |
|
87 | self._s_running = BackgroundJobBase.stat_running_c | |
97 | self._s_completed = BackgroundJobBase.stat_completed_c |
|
88 | self._s_completed = BackgroundJobBase.stat_completed_c | |
98 | self._s_dead = BackgroundJobBase.stat_dead_c |
|
89 | self._s_dead = BackgroundJobBase.stat_dead_c | |
99 |
|
90 | |||
100 | def new(self,func_or_exp,*args,**kwargs): |
|
91 | def new(self,func_or_exp,*args,**kwargs): | |
101 | """Add a new background job and start it in a separate thread. |
|
92 | """Add a new background job and start it in a separate thread. | |
102 |
|
93 | |||
103 | There are two types of jobs which can be created: |
|
94 | There are two types of jobs which can be created: | |
104 |
|
95 | |||
105 | 1. Jobs based on expressions which can be passed to an eval() call. |
|
96 | 1. Jobs based on expressions which can be passed to an eval() call. | |
106 | The expression must be given as a string. For example: |
|
97 | The expression must be given as a string. For example: | |
107 |
|
98 | |||
108 | job_manager.new('myfunc(x,y,z=1)'[,glob[,loc]]) |
|
99 | job_manager.new('myfunc(x,y,z=1)'[,glob[,loc]]) | |
109 |
|
100 | |||
110 | The given expression is passed to eval(), along with the optional |
|
101 | The given expression is passed to eval(), along with the optional | |
111 | global/local dicts provided. If no dicts are given, they are |
|
102 | global/local dicts provided. If no dicts are given, they are | |
112 | extracted automatically from the caller's frame. |
|
103 | extracted automatically from the caller's frame. | |
113 |
|
104 | |||
114 | A Python statement is NOT a valid eval() expression. Basically, you |
|
105 | A Python statement is NOT a valid eval() expression. Basically, you | |
115 | can only use as an eval() argument something which can go on the right |
|
106 | can only use as an eval() argument something which can go on the right | |
116 | of an '=' sign and be assigned to a variable. |
|
107 | of an '=' sign and be assigned to a variable. | |
117 |
|
108 | |||
118 | For example,"print 'hello'" is not valid, but '2+3' is. |
|
109 | For example,"print 'hello'" is not valid, but '2+3' is. | |
119 |
|
110 | |||
120 | 2. Jobs given a function object, optionally passing additional |
|
111 | 2. Jobs given a function object, optionally passing additional | |
121 | positional arguments: |
|
112 | positional arguments: | |
122 |
|
113 | |||
123 | job_manager.new(myfunc,x,y) |
|
114 | job_manager.new(myfunc,x,y) | |
124 |
|
115 | |||
125 | The function is called with the given arguments. |
|
116 | The function is called with the given arguments. | |
126 |
|
117 | |||
127 | If you need to pass keyword arguments to your function, you must |
|
118 | If you need to pass keyword arguments to your function, you must | |
128 | supply them as a dict named kw: |
|
119 | supply them as a dict named kw: | |
129 |
|
120 | |||
130 | job_manager.new(myfunc,x,y,kw=dict(z=1)) |
|
121 | job_manager.new(myfunc,x,y,kw=dict(z=1)) | |
131 |
|
122 | |||
132 | The reason for this assymmetry is that the new() method needs to |
|
123 | The reason for this assymmetry is that the new() method needs to | |
133 | maintain access to its own keywords, and this prevents name collisions |
|
124 | maintain access to its own keywords, and this prevents name collisions | |
134 | between arguments to new() and arguments to your own functions. |
|
125 | between arguments to new() and arguments to your own functions. | |
135 |
|
126 | |||
136 | In both cases, the result is stored in the job.result field of the |
|
127 | In both cases, the result is stored in the job.result field of the | |
137 | background job object. |
|
128 | background job object. | |
138 |
|
129 | |||
139 |
|
130 | |||
140 | Notes and caveats: |
|
131 | Notes and caveats: | |
141 |
|
132 | |||
142 | 1. All threads running share the same standard output. Thus, if your |
|
133 | 1. All threads running share the same standard output. Thus, if your | |
143 | background jobs generate output, it will come out on top of whatever |
|
134 | background jobs generate output, it will come out on top of whatever | |
144 | you are currently writing. For this reason, background jobs are best |
|
135 | you are currently writing. For this reason, background jobs are best | |
145 | used with silent functions which simply return their output. |
|
136 | used with silent functions which simply return their output. | |
146 |
|
137 | |||
147 | 2. Threads also all work within the same global namespace, and this |
|
138 | 2. Threads also all work within the same global namespace, and this | |
148 | system does not lock interactive variables. So if you send job to the |
|
139 | system does not lock interactive variables. So if you send job to the | |
149 | background which operates on a mutable object for a long time, and |
|
140 | background which operates on a mutable object for a long time, and | |
150 | start modifying that same mutable object interactively (or in another |
|
141 | start modifying that same mutable object interactively (or in another | |
151 | backgrounded job), all sorts of bizarre behaviour will occur. |
|
142 | backgrounded job), all sorts of bizarre behaviour will occur. | |
152 |
|
143 | |||
153 | 3. If a background job is spending a lot of time inside a C extension |
|
144 | 3. If a background job is spending a lot of time inside a C extension | |
154 | module which does not release the Python Global Interpreter Lock |
|
145 | module which does not release the Python Global Interpreter Lock | |
155 | (GIL), this will block the IPython prompt. This is simply because the |
|
146 | (GIL), this will block the IPython prompt. This is simply because the | |
156 | Python interpreter can only switch between threads at Python |
|
147 | Python interpreter can only switch between threads at Python | |
157 | bytecodes. While the execution is inside C code, the interpreter must |
|
148 | bytecodes. While the execution is inside C code, the interpreter must | |
158 | simply wait unless the extension module releases the GIL. |
|
149 | simply wait unless the extension module releases the GIL. | |
159 |
|
150 | |||
160 | 4. There is no way, due to limitations in the Python threads library, |
|
151 | 4. There is no way, due to limitations in the Python threads library, | |
161 | to kill a thread once it has started.""" |
|
152 | to kill a thread once it has started.""" | |
162 |
|
153 | |||
163 | if callable(func_or_exp): |
|
154 | if callable(func_or_exp): | |
164 | kw = kwargs.get('kw',{}) |
|
155 | kw = kwargs.get('kw',{}) | |
165 | job = BackgroundJobFunc(func_or_exp,*args,**kw) |
|
156 | job = BackgroundJobFunc(func_or_exp,*args,**kw) | |
166 | elif isinstance(func_or_exp,basestring): |
|
157 | elif isinstance(func_or_exp,basestring): | |
167 | if not args: |
|
158 | if not args: | |
168 | frame = sys._getframe(1) |
|
159 | frame = sys._getframe(1) | |
169 | glob, loc = frame.f_globals, frame.f_locals |
|
160 | glob, loc = frame.f_globals, frame.f_locals | |
170 | elif len(args)==1: |
|
161 | elif len(args)==1: | |
171 | glob = loc = args[0] |
|
162 | glob = loc = args[0] | |
172 | elif len(args)==2: |
|
163 | elif len(args)==2: | |
173 | glob,loc = args |
|
164 | glob,loc = args | |
174 | else: |
|
165 | else: | |
175 | raise ValueError,\ |
|
166 | raise ValueError,\ | |
176 | 'Expression jobs take at most 2 args (globals,locals)' |
|
167 | 'Expression jobs take at most 2 args (globals,locals)' | |
177 | job = BackgroundJobExpr(func_or_exp,glob,loc) |
|
168 | job = BackgroundJobExpr(func_or_exp,glob,loc) | |
178 | else: |
|
169 | else: | |
179 | raise |
|
170 | raise | |
180 | jkeys = self.jobs_all.keys() |
|
171 | jkeys = self.jobs_all.keys() | |
181 | if jkeys: |
|
172 | if jkeys: | |
182 | job.num = max(jkeys)+1 |
|
173 | job.num = max(jkeys)+1 | |
183 | else: |
|
174 | else: | |
184 | job.num = 0 |
|
175 | job.num = 0 | |
185 | self.jobs_run.append(job) |
|
176 | self.jobs_run.append(job) | |
186 | self.jobs_all[job.num] = job |
|
177 | self.jobs_all[job.num] = job | |
187 | print 'Starting job # %s in a separate thread.' % job.num |
|
178 | print 'Starting job # %s in a separate thread.' % job.num | |
188 | job.start() |
|
179 | job.start() | |
189 | return job |
|
180 | return job | |
190 |
|
181 | |||
191 | def __getitem__(self,key): |
|
182 | def __getitem__(self,key): | |
192 | return self.jobs_all[key] |
|
183 | return self.jobs_all[key] | |
193 |
|
184 | |||
194 | def __call__(self): |
|
185 | def __call__(self): | |
195 | """An alias to self.status(), |
|
186 | """An alias to self.status(), | |
196 |
|
187 | |||
197 | This allows you to simply call a job manager instance much like the |
|
188 | This allows you to simply call a job manager instance much like the | |
198 | Unix jobs shell command.""" |
|
189 | Unix jobs shell command.""" | |
199 |
|
190 | |||
200 | return self.status() |
|
191 | return self.status() | |
201 |
|
192 | |||
202 | def _update_status(self): |
|
193 | def _update_status(self): | |
203 | """Update the status of the job lists. |
|
194 | """Update the status of the job lists. | |
204 |
|
195 | |||
205 | This method moves finished jobs to one of two lists: |
|
196 | This method moves finished jobs to one of two lists: | |
206 | - self.jobs_comp: jobs which completed successfully |
|
197 | - self.jobs_comp: jobs which completed successfully | |
207 | - self.jobs_dead: jobs which finished but died. |
|
198 | - self.jobs_dead: jobs which finished but died. | |
208 |
|
199 | |||
209 | It also copies those jobs to corresponding _report lists. These lists |
|
200 | It also copies those jobs to corresponding _report lists. These lists | |
210 | are used to report jobs completed/dead since the last update, and are |
|
201 | are used to report jobs completed/dead since the last update, and are | |
211 | then cleared by the reporting function after each call.""" |
|
202 | then cleared by the reporting function after each call.""" | |
212 |
|
203 | |||
213 | run,comp,dead = self._s_running,self._s_completed,self._s_dead |
|
204 | run,comp,dead = self._s_running,self._s_completed,self._s_dead | |
214 | jobs_run = self.jobs_run |
|
205 | jobs_run = self.jobs_run | |
215 | for num in range(len(jobs_run)): |
|
206 | for num in range(len(jobs_run)): | |
216 | job = jobs_run[num] |
|
207 | job = jobs_run[num] | |
217 | stat = job.stat_code |
|
208 | stat = job.stat_code | |
218 | if stat == run: |
|
209 | if stat == run: | |
219 | continue |
|
210 | continue | |
220 | elif stat == comp: |
|
211 | elif stat == comp: | |
221 | self.jobs_comp.append(job) |
|
212 | self.jobs_comp.append(job) | |
222 | self._comp_report.append(job) |
|
213 | self._comp_report.append(job) | |
223 | jobs_run[num] = False |
|
214 | jobs_run[num] = False | |
224 | elif stat == dead: |
|
215 | elif stat == dead: | |
225 | self.jobs_dead.append(job) |
|
216 | self.jobs_dead.append(job) | |
226 | self._dead_report.append(job) |
|
217 | self._dead_report.append(job) | |
227 | jobs_run[num] = False |
|
218 | jobs_run[num] = False | |
228 | self.jobs_run = filter(None,self.jobs_run) |
|
219 | self.jobs_run = filter(None,self.jobs_run) | |
229 |
|
220 | |||
230 | def _group_report(self,group,name): |
|
221 | def _group_report(self,group,name): | |
231 | """Report summary for a given job group. |
|
222 | """Report summary for a given job group. | |
232 |
|
223 | |||
233 | Return True if the group had any elements.""" |
|
224 | Return True if the group had any elements.""" | |
234 |
|
225 | |||
235 | if group: |
|
226 | if group: | |
236 | print '%s jobs:' % name |
|
227 | print '%s jobs:' % name | |
237 | for job in group: |
|
228 | for job in group: | |
238 | print '%s : %s' % (job.num,job) |
|
229 | print '%s : %s' % (job.num,job) | |
239 |
|
230 | |||
240 | return True |
|
231 | return True | |
241 |
|
232 | |||
242 | def _group_flush(self,group,name): |
|
233 | def _group_flush(self,group,name): | |
243 | """Flush a given job group |
|
234 | """Flush a given job group | |
244 |
|
235 | |||
245 | Return True if the group had any elements.""" |
|
236 | Return True if the group had any elements.""" | |
246 |
|
237 | |||
247 | njobs = len(group) |
|
238 | njobs = len(group) | |
248 | if njobs: |
|
239 | if njobs: | |
249 | plural = {1:''}.setdefault(njobs,'s') |
|
240 | plural = {1:''}.setdefault(njobs,'s') | |
250 | print 'Flushing %s %s job%s.' % (njobs,name,plural) |
|
241 | print 'Flushing %s %s job%s.' % (njobs,name,plural) | |
251 | group[:] = [] |
|
242 | group[:] = [] | |
252 | return True |
|
243 | return True | |
253 |
|
244 | |||
254 | def _status_new(self): |
|
245 | def _status_new(self): | |
255 | """Print the status of newly finished jobs. |
|
246 | """Print the status of newly finished jobs. | |
256 |
|
247 | |||
257 | Return True if any new jobs are reported. |
|
248 | Return True if any new jobs are reported. | |
258 |
|
249 | |||
259 | This call resets its own state every time, so it only reports jobs |
|
250 | This call resets its own state every time, so it only reports jobs | |
260 | which have finished since the last time it was called.""" |
|
251 | which have finished since the last time it was called.""" | |
261 |
|
252 | |||
262 | self._update_status() |
|
253 | self._update_status() | |
263 | new_comp = self._group_report(self._comp_report,'Completed') |
|
254 | new_comp = self._group_report(self._comp_report,'Completed') | |
264 | new_dead = self._group_report(self._dead_report, |
|
255 | new_dead = self._group_report(self._dead_report, | |
265 | 'Dead, call job.traceback() for details') |
|
256 | 'Dead, call job.traceback() for details') | |
266 | self._comp_report[:] = [] |
|
257 | self._comp_report[:] = [] | |
267 | self._dead_report[:] = [] |
|
258 | self._dead_report[:] = [] | |
268 | return new_comp or new_dead |
|
259 | return new_comp or new_dead | |
269 |
|
260 | |||
270 | def status(self,verbose=0): |
|
261 | def status(self,verbose=0): | |
271 | """Print a status of all jobs currently being managed.""" |
|
262 | """Print a status of all jobs currently being managed.""" | |
272 |
|
263 | |||
273 | self._update_status() |
|
264 | self._update_status() | |
274 | self._group_report(self.jobs_run,'Running') |
|
265 | self._group_report(self.jobs_run,'Running') | |
275 | self._group_report(self.jobs_comp,'Completed') |
|
266 | self._group_report(self.jobs_comp,'Completed') | |
276 | self._group_report(self.jobs_dead,'Dead') |
|
267 | self._group_report(self.jobs_dead,'Dead') | |
277 | # Also flush the report queues |
|
268 | # Also flush the report queues | |
278 | self._comp_report[:] = [] |
|
269 | self._comp_report[:] = [] | |
279 | self._dead_report[:] = [] |
|
270 | self._dead_report[:] = [] | |
280 |
|
271 | |||
281 | def remove(self,num): |
|
272 | def remove(self,num): | |
282 | """Remove a finished (completed or dead) job.""" |
|
273 | """Remove a finished (completed or dead) job.""" | |
283 |
|
274 | |||
284 | try: |
|
275 | try: | |
285 | job = self.jobs_all[num] |
|
276 | job = self.jobs_all[num] | |
286 | except KeyError: |
|
277 | except KeyError: | |
287 | error('Job #%s not found' % num) |
|
278 | error('Job #%s not found' % num) | |
288 | else: |
|
279 | else: | |
289 | stat_code = job.stat_code |
|
280 | stat_code = job.stat_code | |
290 | if stat_code == self._s_running: |
|
281 | if stat_code == self._s_running: | |
291 | error('Job #%s is still running, it can not be removed.' % num) |
|
282 | error('Job #%s is still running, it can not be removed.' % num) | |
292 | return |
|
283 | return | |
293 | elif stat_code == self._s_completed: |
|
284 | elif stat_code == self._s_completed: | |
294 | self.jobs_comp.remove(job) |
|
285 | self.jobs_comp.remove(job) | |
295 | elif stat_code == self._s_dead: |
|
286 | elif stat_code == self._s_dead: | |
296 | self.jobs_dead.remove(job) |
|
287 | self.jobs_dead.remove(job) | |
297 |
|
288 | |||
298 | def flush_finished(self): |
|
289 | def flush_finished(self): | |
299 | """Flush all jobs finished (completed and dead) from lists. |
|
290 | """Flush all jobs finished (completed and dead) from lists. | |
300 |
|
291 | |||
301 | Running jobs are never flushed. |
|
292 | Running jobs are never flushed. | |
302 |
|
293 | |||
303 | It first calls _status_new(), to update info. If any jobs have |
|
294 | It first calls _status_new(), to update info. If any jobs have | |
304 | completed since the last _status_new() call, the flush operation |
|
295 | completed since the last _status_new() call, the flush operation | |
305 | aborts.""" |
|
296 | aborts.""" | |
306 |
|
297 | |||
307 | if self._status_new(): |
|
298 | if self._status_new(): | |
308 | error('New jobs completed since last '\ |
|
299 | error('New jobs completed since last '\ | |
309 | '_status_new(), aborting flush.') |
|
300 | '_status_new(), aborting flush.') | |
310 | return |
|
301 | return | |
311 |
|
302 | |||
312 | # Remove the finished jobs from the master dict |
|
303 | # Remove the finished jobs from the master dict | |
313 | jobs_all = self.jobs_all |
|
304 | jobs_all = self.jobs_all | |
314 | for job in self.jobs_comp+self.jobs_dead: |
|
305 | for job in self.jobs_comp+self.jobs_dead: | |
315 | del(jobs_all[job.num]) |
|
306 | del(jobs_all[job.num]) | |
316 |
|
307 | |||
317 | # Now flush these lists completely |
|
308 | # Now flush these lists completely | |
318 | fl_comp = self._group_flush(self.jobs_comp,'Completed') |
|
309 | fl_comp = self._group_flush(self.jobs_comp,'Completed') | |
319 | fl_dead = self._group_flush(self.jobs_dead,'Dead') |
|
310 | fl_dead = self._group_flush(self.jobs_dead,'Dead') | |
320 | if not (fl_comp or fl_dead): |
|
311 | if not (fl_comp or fl_dead): | |
321 | print 'No jobs to flush.' |
|
312 | print 'No jobs to flush.' | |
322 |
|
313 | |||
323 | def result(self,num): |
|
314 | def result(self,num): | |
324 | """result(N) -> return the result of job N.""" |
|
315 | """result(N) -> return the result of job N.""" | |
325 | try: |
|
316 | try: | |
326 | return self.jobs_all[num].result |
|
317 | return self.jobs_all[num].result | |
327 | except KeyError: |
|
318 | except KeyError: | |
328 | error('Job #%s not found' % num) |
|
319 | error('Job #%s not found' % num) | |
329 |
|
320 | |||
330 | def traceback(self,num): |
|
321 | def traceback(self,num): | |
331 | try: |
|
322 | try: | |
332 | self.jobs_all[num].traceback() |
|
323 | self.jobs_all[num].traceback() | |
333 | except KeyError: |
|
324 | except KeyError: | |
334 | error('Job #%s not found' % num) |
|
325 | error('Job #%s not found' % num) | |
335 |
|
326 | |||
336 |
|
327 | |||
337 | class BackgroundJobBase(threading.Thread): |
|
328 | class BackgroundJobBase(threading.Thread): | |
338 | """Base class to build BackgroundJob classes. |
|
329 | """Base class to build BackgroundJob classes. | |
339 |
|
330 | |||
340 | The derived classes must implement: |
|
331 | The derived classes must implement: | |
341 |
|
332 | |||
342 | - Their own __init__, since the one here raises NotImplementedError. The |
|
333 | - Their own __init__, since the one here raises NotImplementedError. The | |
343 | derived constructor must call self._init() at the end, to provide common |
|
334 | derived constructor must call self._init() at the end, to provide common | |
344 | initialization. |
|
335 | initialization. | |
345 |
|
336 | |||
346 | - A strform attribute used in calls to __str__. |
|
337 | - A strform attribute used in calls to __str__. | |
347 |
|
338 | |||
348 | - A call() method, which will make the actual execution call and must |
|
339 | - A call() method, which will make the actual execution call and must | |
349 | return a value to be held in the 'result' field of the job object.""" |
|
340 | return a value to be held in the 'result' field of the job object.""" | |
350 |
|
341 | |||
351 | # Class constants for status, in string and as numerical codes (when |
|
342 | # Class constants for status, in string and as numerical codes (when | |
352 | # updating jobs lists, we don't want to do string comparisons). This will |
|
343 | # updating jobs lists, we don't want to do string comparisons). This will | |
353 | # be done at every user prompt, so it has to be as fast as possible |
|
344 | # be done at every user prompt, so it has to be as fast as possible | |
354 | stat_created = 'Created'; stat_created_c = 0 |
|
345 | stat_created = 'Created'; stat_created_c = 0 | |
355 | stat_running = 'Running'; stat_running_c = 1 |
|
346 | stat_running = 'Running'; stat_running_c = 1 | |
356 | stat_completed = 'Completed'; stat_completed_c = 2 |
|
347 | stat_completed = 'Completed'; stat_completed_c = 2 | |
357 | stat_dead = 'Dead (Exception), call job.traceback() for details' |
|
348 | stat_dead = 'Dead (Exception), call job.traceback() for details' | |
358 | stat_dead_c = -1 |
|
349 | stat_dead_c = -1 | |
359 |
|
350 | |||
360 | def __init__(self): |
|
351 | def __init__(self): | |
361 | raise NotImplementedError, \ |
|
352 | raise NotImplementedError, \ | |
362 | "This class can not be instantiated directly." |
|
353 | "This class can not be instantiated directly." | |
363 |
|
354 | |||
364 | def _init(self): |
|
355 | def _init(self): | |
365 | """Common initialization for all BackgroundJob objects""" |
|
356 | """Common initialization for all BackgroundJob objects""" | |
366 |
|
357 | |||
367 | for attr in ['call','strform']: |
|
358 | for attr in ['call','strform']: | |
368 | assert hasattr(self,attr), "Missing attribute <%s>" % attr |
|
359 | assert hasattr(self,attr), "Missing attribute <%s>" % attr | |
369 |
|
360 | |||
370 | # The num tag can be set by an external job manager |
|
361 | # The num tag can be set by an external job manager | |
371 | self.num = None |
|
362 | self.num = None | |
372 |
|
363 | |||
373 | self.status = BackgroundJobBase.stat_created |
|
364 | self.status = BackgroundJobBase.stat_created | |
374 | self.stat_code = BackgroundJobBase.stat_created_c |
|
365 | self.stat_code = BackgroundJobBase.stat_created_c | |
375 | self.finished = False |
|
366 | self.finished = False | |
376 | self.result = '<BackgroundJob has not completed>' |
|
367 | self.result = '<BackgroundJob has not completed>' | |
377 | # reuse the ipython traceback handler if we can get to it, otherwise |
|
368 | # reuse the ipython traceback handler if we can get to it, otherwise | |
378 | # make a new one |
|
369 | # make a new one | |
379 | try: |
|
370 | try: | |
380 | self._make_tb = __IPYTHON__.InteractiveTB.text |
|
371 | self._make_tb = __IPYTHON__.InteractiveTB.text | |
381 | except: |
|
372 | except: | |
382 | self._make_tb = AutoFormattedTB(mode = 'Context', |
|
373 | self._make_tb = AutoFormattedTB(mode = 'Context', | |
383 | color_scheme='NoColor', |
|
374 | color_scheme='NoColor', | |
384 | tb_offset = 1).text |
|
375 | tb_offset = 1).text | |
385 | # Hold a formatted traceback if one is generated. |
|
376 | # Hold a formatted traceback if one is generated. | |
386 | self._tb = None |
|
377 | self._tb = None | |
387 |
|
378 | |||
388 | threading.Thread.__init__(self) |
|
379 | threading.Thread.__init__(self) | |
389 |
|
380 | |||
390 | def __str__(self): |
|
381 | def __str__(self): | |
391 | return self.strform |
|
382 | return self.strform | |
392 |
|
383 | |||
393 | def __repr__(self): |
|
384 | def __repr__(self): | |
394 | return '<BackgroundJob: %s>' % self.strform |
|
385 | return '<BackgroundJob: %s>' % self.strform | |
395 |
|
386 | |||
396 | def traceback(self): |
|
387 | def traceback(self): | |
397 | print self._tb |
|
388 | print self._tb | |
398 |
|
389 | |||
399 | def run(self): |
|
390 | def run(self): | |
400 | try: |
|
391 | try: | |
401 | self.status = BackgroundJobBase.stat_running |
|
392 | self.status = BackgroundJobBase.stat_running | |
402 | self.stat_code = BackgroundJobBase.stat_running_c |
|
393 | self.stat_code = BackgroundJobBase.stat_running_c | |
403 | self.result = self.call() |
|
394 | self.result = self.call() | |
404 | except: |
|
395 | except: | |
405 | self.status = BackgroundJobBase.stat_dead |
|
396 | self.status = BackgroundJobBase.stat_dead | |
406 | self.stat_code = BackgroundJobBase.stat_dead_c |
|
397 | self.stat_code = BackgroundJobBase.stat_dead_c | |
407 | self.finished = None |
|
398 | self.finished = None | |
408 | self.result = ('<BackgroundJob died, call job.traceback() for details>') |
|
399 | self.result = ('<BackgroundJob died, call job.traceback() for details>') | |
409 | self._tb = self._make_tb() |
|
400 | self._tb = self._make_tb() | |
410 | else: |
|
401 | else: | |
411 | self.status = BackgroundJobBase.stat_completed |
|
402 | self.status = BackgroundJobBase.stat_completed | |
412 | self.stat_code = BackgroundJobBase.stat_completed_c |
|
403 | self.stat_code = BackgroundJobBase.stat_completed_c | |
413 | self.finished = True |
|
404 | self.finished = True | |
414 |
|
405 | |||
415 | class BackgroundJobExpr(BackgroundJobBase): |
|
406 | class BackgroundJobExpr(BackgroundJobBase): | |
416 | """Evaluate an expression as a background job (uses a separate thread).""" |
|
407 | """Evaluate an expression as a background job (uses a separate thread).""" | |
417 |
|
408 | |||
418 | def __init__(self,expression,glob=None,loc=None): |
|
409 | def __init__(self,expression,glob=None,loc=None): | |
419 | """Create a new job from a string which can be fed to eval(). |
|
410 | """Create a new job from a string which can be fed to eval(). | |
420 |
|
411 | |||
421 | global/locals dicts can be provided, which will be passed to the eval |
|
412 | global/locals dicts can be provided, which will be passed to the eval | |
422 | call.""" |
|
413 | call.""" | |
423 |
|
414 | |||
424 | # fail immediately if the given expression can't be compiled |
|
415 | # fail immediately if the given expression can't be compiled | |
425 | self.code = compile(expression,'<BackgroundJob compilation>','eval') |
|
416 | self.code = compile(expression,'<BackgroundJob compilation>','eval') | |
426 |
|
417 | |||
427 | if glob is None: |
|
418 | if glob is None: | |
428 | glob = {} |
|
419 | glob = {} | |
429 | if loc is None: |
|
420 | if loc is None: | |
430 | loc = {} |
|
421 | loc = {} | |
431 |
|
422 | |||
432 | self.expression = self.strform = expression |
|
423 | self.expression = self.strform = expression | |
433 | self.glob = glob |
|
424 | self.glob = glob | |
434 | self.loc = loc |
|
425 | self.loc = loc | |
435 | self._init() |
|
426 | self._init() | |
436 |
|
427 | |||
437 | def call(self): |
|
428 | def call(self): | |
438 | return eval(self.code,self.glob,self.loc) |
|
429 | return eval(self.code,self.glob,self.loc) | |
439 |
|
430 | |||
440 | class BackgroundJobFunc(BackgroundJobBase): |
|
431 | class BackgroundJobFunc(BackgroundJobBase): | |
441 | """Run a function call as a background job (uses a separate thread).""" |
|
432 | """Run a function call as a background job (uses a separate thread).""" | |
442 |
|
433 | |||
443 | def __init__(self,func,*args,**kwargs): |
|
434 | def __init__(self,func,*args,**kwargs): | |
444 | """Create a new job from a callable object. |
|
435 | """Create a new job from a callable object. | |
445 |
|
436 | |||
446 | Any positional arguments and keyword args given to this constructor |
|
437 | Any positional arguments and keyword args given to this constructor | |
447 | after the initial callable are passed directly to it.""" |
|
438 | after the initial callable are passed directly to it.""" | |
448 |
|
439 | |||
449 | assert callable(func),'first argument must be callable' |
|
440 | assert callable(func),'first argument must be callable' | |
450 |
|
441 | |||
451 | if args is None: |
|
442 | if args is None: | |
452 | args = [] |
|
443 | args = [] | |
453 | if kwargs is None: |
|
444 | if kwargs is None: | |
454 | kwargs = {} |
|
445 | kwargs = {} | |
455 |
|
446 | |||
456 | self.func = func |
|
447 | self.func = func | |
457 | self.args = args |
|
448 | self.args = args | |
458 | self.kwargs = kwargs |
|
449 | self.kwargs = kwargs | |
459 | # The string form will only include the function passed, because |
|
450 | # The string form will only include the function passed, because | |
460 | # generating string representations of the arguments is a potentially |
|
451 | # generating string representations of the arguments is a potentially | |
461 | # _very_ expensive operation (e.g. with large arrays). |
|
452 | # _very_ expensive operation (e.g. with large arrays). | |
462 | self.strform = str(func) |
|
453 | self.strform = str(func) | |
463 | self._init() |
|
454 | self._init() | |
464 |
|
455 | |||
465 | def call(self): |
|
456 | def call(self): | |
466 | return self.func(*self.args,**self.kwargs) |
|
457 | return self.func(*self.args,**self.kwargs) | |
467 |
|
458 | |||
468 |
|
459 | |||
469 | if __name__=='__main__': |
|
460 | if __name__=='__main__': | |
470 |
|
461 | |||
471 | import time |
|
462 | import time | |
472 |
|
463 | |||
473 | def sleepfunc(interval=2,*a,**kw): |
|
464 | def sleepfunc(interval=2,*a,**kw): | |
474 | args = dict(interval=interval, |
|
465 | args = dict(interval=interval, | |
475 | args=a, |
|
466 | args=a, | |
476 | kwargs=kw) |
|
467 | kwargs=kw) | |
477 | time.sleep(interval) |
|
468 | time.sleep(interval) | |
478 | return args |
|
469 | return args | |
479 |
|
470 | |||
480 | def diefunc(interval=2,*a,**kw): |
|
471 | def diefunc(interval=2,*a,**kw): | |
481 | time.sleep(interval) |
|
472 | time.sleep(interval) | |
482 | die |
|
473 | die | |
483 |
|
474 | |||
484 | def printfunc(interval=1,reps=5): |
|
475 | def printfunc(interval=1,reps=5): | |
485 | for n in range(reps): |
|
476 | for n in range(reps): | |
486 | time.sleep(interval) |
|
477 | time.sleep(interval) | |
487 | print 'In the background...' |
|
478 | print 'In the background...' | |
488 |
|
479 | |||
489 | jobs = BackgroundJobManager() |
|
480 | jobs = BackgroundJobManager() | |
490 | # first job will have # 0 |
|
481 | # first job will have # 0 | |
491 | jobs.new(sleepfunc,4) |
|
482 | jobs.new(sleepfunc,4) | |
492 | jobs.new(sleepfunc,kw={'reps':2}) |
|
483 | jobs.new(sleepfunc,kw={'reps':2}) | |
493 | # This makes a job which will die |
|
484 | # This makes a job which will die | |
494 | jobs.new(diefunc,1) |
|
485 | jobs.new(diefunc,1) | |
495 | jobs.new('printfunc(1,3)') |
|
486 | jobs.new('printfunc(1,3)') | |
496 |
|
487 | |||
497 | # after a while, you can get the traceback of a dead job. Run the line |
|
488 | # after a while, you can get the traceback of a dead job. Run the line | |
498 | # below again interactively until it prints a traceback (check the status |
|
489 | # below again interactively until it prints a traceback (check the status | |
499 | # of the job): |
|
490 | # of the job): | |
500 | print jobs[1].status |
|
491 | print jobs[1].status | |
501 | jobs[1].traceback() |
|
492 | jobs[1].traceback() | |
502 |
|
493 | |||
503 | # Run this line again until the printed result changes |
|
494 | # Run this line again until the printed result changes | |
504 | print "The result of job #0 is:",jobs[0].result |
|
495 | print "The result of job #0 is:",jobs[0].result |
@@ -1,1519 +1,1508 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """ |
|
2 | """ | |
3 | General purpose utilities. |
|
3 | General purpose utilities. | |
4 |
|
4 | |||
5 | This is a grab-bag of stuff I find useful in most programs I write. Some of |
|
5 | This is a grab-bag of stuff I find useful in most programs I write. Some of | |
6 | these things are also convenient when working at the command line. |
|
6 | these things are also convenient when working at the command line. | |
7 |
|
7 | |||
8 |
$Id: genutils.py 63 |
|
8 | $Id: genutils.py 638 2005-07-18 03:01:41Z fperez $""" | |
9 |
|
9 | |||
10 | #***************************************************************************** |
|
10 | #***************************************************************************** | |
11 | # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu> |
|
11 | # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu> | |
12 | # |
|
12 | # | |
13 | # Distributed under the terms of the BSD License. The full license is in |
|
13 | # Distributed under the terms of the BSD License. The full license is in | |
14 | # the file COPYING, distributed as part of this software. |
|
14 | # the file COPYING, distributed as part of this software. | |
15 | #***************************************************************************** |
|
15 | #***************************************************************************** | |
16 |
|
16 | |||
17 | from IPython import Release |
|
17 | from IPython import Release | |
18 | __author__ = '%s <%s>' % Release.authors['Fernando'] |
|
18 | __author__ = '%s <%s>' % Release.authors['Fernando'] | |
19 | __license__ = Release.license |
|
19 | __license__ = Release.license | |
20 |
|
20 | |||
21 | #**************************************************************************** |
|
21 | #**************************************************************************** | |
22 | # required modules |
|
22 | # required modules | |
23 | import __main__ |
|
23 | import __main__ | |
24 | import types,commands,time,sys,os,re,shutil |
|
24 | import types,commands,time,sys,os,re,shutil | |
25 | import tempfile |
|
25 | import tempfile | |
|
26 | import codecs | |||
26 | from IPython.Itpl import Itpl,itpl,printpl |
|
27 | from IPython.Itpl import Itpl,itpl,printpl | |
27 | from IPython import DPyGetOpt |
|
28 | from IPython import DPyGetOpt | |
28 |
|
29 | |||
|
30 | # Build objects which appeared in Python 2.3 for 2.2, to make ipython | |||
|
31 | # 2.2-friendly | |||
|
32 | try: | |||
|
33 | basestring | |||
|
34 | except NameError: | |||
|
35 | import types | |||
|
36 | basestring = (types.StringType, types.UnicodeType) | |||
|
37 | True = 1==1 | |||
|
38 | False = 1==0 | |||
|
39 | ||||
|
40 | def enumerate(obj): | |||
|
41 | i = -1 | |||
|
42 | for item in obj: | |||
|
43 | i += 1 | |||
|
44 | yield i, item | |||
|
45 | ||||
|
46 | # add these to the builtin namespace, so that all modules find them | |||
|
47 | import __builtin__ | |||
|
48 | __builtin__.basestring = basestring | |||
|
49 | __builtin__.True = True | |||
|
50 | __builtin__.False = False | |||
|
51 | __builtin__.enumerate = enumerate | |||
|
52 | ||||
29 | #**************************************************************************** |
|
53 | #**************************************************************************** | |
30 | # Exceptions |
|
54 | # Exceptions | |
31 | class Error(Exception): |
|
55 | class Error(Exception): | |
32 | """Base class for exceptions in this module.""" |
|
56 | """Base class for exceptions in this module.""" | |
33 | pass |
|
57 | pass | |
34 |
|
58 | |||
35 | #---------------------------------------------------------------------------- |
|
59 | #---------------------------------------------------------------------------- | |
36 | class Stream: |
|
60 | class IOStream: | |
37 | """Simple class to hold the various I/O streams in Term""" |
|
61 | def __init__(self,stream,fallback): | |
38 |
|
62 | if not hasattr(stream,'write') or not hasattr(stream,'flush'): | ||
39 | def __init__(self,stream,name): |
|
63 | stream = fallback | |
40 | self.stream = stream |
|
64 | self.stream = stream | |
41 |
self. |
|
65 | self._swrite = stream.write | |
42 | try: |
|
66 | self.flush = stream.flush | |
43 | self.fileno = stream.fileno() |
|
|||
44 | except AttributeError: |
|
|||
45 | msg = ("Stream <%s> looks suspicious: it lacks a 'fileno' attribute." |
|
|||
46 | % name) |
|
|||
47 | print >> sys.stderr, 'WARNING:',msg |
|
|||
48 | try: |
|
|||
49 | self.mode = stream.mode |
|
|||
50 | except AttributeError: |
|
|||
51 | msg = ("Stream <%s> looks suspicious: it lacks a 'mode' attribute." |
|
|||
52 | % name) |
|
|||
53 | print >> sys.stderr, 'WARNING:',msg |
|
|||
54 |
|
67 | |||
55 | class Term: |
|
68 | def write(self,data): | |
|
69 | try: | |||
|
70 | self._swrite(data) | |||
|
71 | except: | |||
|
72 | try: | |||
|
73 | # print handles some unicode issues which may trip a plain | |||
|
74 | # write() call. Attempt to emulate write() by using a | |||
|
75 | # trailing comma | |||
|
76 | print >> self.stream, data, | |||
|
77 | except: | |||
|
78 | # if we get here, something is seriously broken. | |||
|
79 | print >> sys.stderr, \ | |||
|
80 | 'ERROR - failed to write data to stream:', stream | |||
|
81 | ||||
|
82 | class IOTerm: | |||
56 | """ Term holds the file or file-like objects for handling I/O operations. |
|
83 | """ Term holds the file or file-like objects for handling I/O operations. | |
57 |
|
84 | |||
58 | These are normally just sys.stdin, sys.stdout and sys.stderr but for |
|
85 | These are normally just sys.stdin, sys.stdout and sys.stderr but for | |
59 | Windows they can can replaced to allow editing the strings before they are |
|
86 | Windows they can can replaced to allow editing the strings before they are | |
60 | displayed.""" |
|
87 | displayed.""" | |
61 |
|
88 | |||
62 | # In the future, having IPython channel all its I/O operations through |
|
89 | # In the future, having IPython channel all its I/O operations through | |
63 | # this class will make it easier to embed it into other environments which |
|
90 | # this class will make it easier to embed it into other environments which | |
64 | # are not a normal terminal (such as a GUI-based shell) |
|
91 | # are not a normal terminal (such as a GUI-based shell) | |
65 | in_s = Stream(sys.stdin,'cin') |
|
92 | def __init__(self,cin=None,cout=None,cerr=None): | |
66 | out_s = Stream(sys.stdout,'cout') |
|
93 | self.cin = IOStream(cin,sys.stdin) | |
67 | err_s = Stream(sys.stderr,'cerr') |
|
94 | self.cout = IOStream(cout,sys.stdout) | |
68 |
|
95 | self.cerr = IOStream(cerr,sys.stderr) | ||
69 | # Store the three streams in (err,out,in) order so that if we need to reopen |
|
96 | ||
70 | # them, the error channel is reopened first to provide info. |
|
97 | # Global variable to be used for all I/O | |
71 | streams = [err_s,out_s,in_s] |
|
98 | Term = IOTerm() | |
72 |
|
||||
73 | # The class globals should be the actual 'bare' streams for normal I/O to work |
|
|||
74 | cin = streams[2].stream |
|
|||
75 | cout = streams[1].stream |
|
|||
76 | cerr = streams[0].stream |
|
|||
77 |
|
||||
78 | def reopen_all(cls): |
|
|||
79 | """Reopen all streams if necessary. |
|
|||
80 |
|
||||
81 | This should only be called if it is suspected that someting closed |
|
|||
82 | accidentally one of the I/O streams.""" |
|
|||
83 |
|
||||
84 | any_closed = 0 |
|
|||
85 |
|
||||
86 | for sn in range(len(cls.streams)): |
|
|||
87 | st = cls.streams[sn] |
|
|||
88 | if st.stream.closed: |
|
|||
89 | any_closed = 1 |
|
|||
90 | new_stream = os.fdopen(os.dup(st.fileno), st.mode,0) |
|
|||
91 | cls.streams[sn] = Stream(new_stream,st.name) |
|
|||
92 | print >> cls.streams[0].stream, \ |
|
|||
93 | '\nWARNING:\nStream Term.%s had to be reopened!' % st.name |
|
|||
94 |
|
||||
95 | # Rebuild the class globals |
|
|||
96 | cls.cin = cls.streams[2].stream |
|
|||
97 | cls.cout = cls.streams[1].stream |
|
|||
98 | cls.cerr = cls.streams[0].stream |
|
|||
99 |
|
||||
100 | reopen_all = classmethod(reopen_all) |
|
|||
101 |
|
||||
102 | def set_stdout(cls,stream): |
|
|||
103 | """Set the stream """ |
|
|||
104 | cls.cout = stream |
|
|||
105 | set_stdout = classmethod(set_stdout) |
|
|||
106 |
|
||||
107 | def set_stderr(cls,stream): |
|
|||
108 | cls.cerr = stream |
|
|||
109 | set_stderr = classmethod(set_stderr) |
|
|||
110 |
|
99 | |||
111 | # Windows-specific code to load Gary Bishop's readline and configure it |
|
100 | # Windows-specific code to load Gary Bishop's readline and configure it | |
112 | # automatically for the users |
|
101 | # automatically for the users | |
113 | # Note: os.name on cygwin returns posix, so this should only pick up 'native' |
|
102 | # Note: os.name on cygwin returns posix, so this should only pick up 'native' | |
114 | # windows. Cygwin returns 'cygwin' for sys.platform. |
|
103 | # windows. Cygwin returns 'cygwin' for sys.platform. | |
115 | if os.name == 'nt': |
|
104 | if os.name == 'nt': | |
116 | try: |
|
105 | try: | |
117 | import readline |
|
106 | import readline | |
118 | except ImportError: |
|
107 | except ImportError: | |
119 | pass |
|
108 | pass | |
120 | else: |
|
109 | else: | |
121 | try: |
|
110 | try: | |
122 | _out = readline.GetOutputFile() |
|
111 | _out = readline.GetOutputFile() | |
123 | except AttributeError: |
|
112 | except AttributeError: | |
124 | pass |
|
113 | pass | |
125 | else: |
|
114 | else: | |
126 | Term.set_stdout(_out) |
|
115 | # Remake Term to use the readline i/o facilities | |
127 |
Term |
|
116 | Term = IOTerm(cout=_out,cerr=_out) | |
128 | del _out |
|
117 | del _out | |
129 |
|
118 | |||
130 | #**************************************************************************** |
|
119 | #**************************************************************************** | |
131 | # Generic warning/error printer, used by everything else |
|
120 | # Generic warning/error printer, used by everything else | |
132 | def warn(msg,level=2,exit_val=1): |
|
121 | def warn(msg,level=2,exit_val=1): | |
133 | """Standard warning printer. Gives formatting consistency. |
|
122 | """Standard warning printer. Gives formatting consistency. | |
134 |
|
123 | |||
135 | Output is sent to Term.cerr (sys.stderr by default). |
|
124 | Output is sent to Term.cerr (sys.stderr by default). | |
136 |
|
125 | |||
137 | Options: |
|
126 | Options: | |
138 |
|
127 | |||
139 | -level(2): allows finer control: |
|
128 | -level(2): allows finer control: | |
140 | 0 -> Do nothing, dummy function. |
|
129 | 0 -> Do nothing, dummy function. | |
141 | 1 -> Print message. |
|
130 | 1 -> Print message. | |
142 | 2 -> Print 'WARNING:' + message. (Default level). |
|
131 | 2 -> Print 'WARNING:' + message. (Default level). | |
143 | 3 -> Print 'ERROR:' + message. |
|
132 | 3 -> Print 'ERROR:' + message. | |
144 | 4 -> Print 'FATAL ERROR:' + message and trigger a sys.exit(exit_val). |
|
133 | 4 -> Print 'FATAL ERROR:' + message and trigger a sys.exit(exit_val). | |
145 |
|
134 | |||
146 | -exit_val (1): exit value returned by sys.exit() for a level 4 |
|
135 | -exit_val (1): exit value returned by sys.exit() for a level 4 | |
147 | warning. Ignored for all other levels.""" |
|
136 | warning. Ignored for all other levels.""" | |
148 |
|
137 | |||
149 | if level>0: |
|
138 | if level>0: | |
150 | header = ['','','WARNING: ','ERROR: ','FATAL ERROR: '] |
|
139 | header = ['','','WARNING: ','ERROR: ','FATAL ERROR: '] | |
151 | print >> Term.cerr, '%s%s' % (header[level],msg) |
|
140 | print >> Term.cerr, '%s%s' % (header[level],msg) | |
152 | if level == 4: |
|
141 | if level == 4: | |
153 | print >> Term.cerr,'Exiting.\n' |
|
142 | print >> Term.cerr,'Exiting.\n' | |
154 | sys.exit(exit_val) |
|
143 | sys.exit(exit_val) | |
155 |
|
144 | |||
156 | def info(msg): |
|
145 | def info(msg): | |
157 | """Equivalent to warn(msg,level=1).""" |
|
146 | """Equivalent to warn(msg,level=1).""" | |
158 |
|
147 | |||
159 | warn(msg,level=1) |
|
148 | warn(msg,level=1) | |
160 |
|
149 | |||
161 | def error(msg): |
|
150 | def error(msg): | |
162 | """Equivalent to warn(msg,level=3).""" |
|
151 | """Equivalent to warn(msg,level=3).""" | |
163 |
|
152 | |||
164 | warn(msg,level=3) |
|
153 | warn(msg,level=3) | |
165 |
|
154 | |||
166 | def fatal(msg,exit_val=1): |
|
155 | def fatal(msg,exit_val=1): | |
167 | """Equivalent to warn(msg,exit_val=exit_val,level=4).""" |
|
156 | """Equivalent to warn(msg,exit_val=exit_val,level=4).""" | |
168 |
|
157 | |||
169 | warn(msg,exit_val=exit_val,level=4) |
|
158 | warn(msg,exit_val=exit_val,level=4) | |
170 |
|
159 | |||
171 | #---------------------------------------------------------------------------- |
|
160 | #---------------------------------------------------------------------------- | |
172 | StringTypes = types.StringTypes |
|
161 | StringTypes = types.StringTypes | |
173 |
|
162 | |||
174 | # Basic timing functionality |
|
163 | # Basic timing functionality | |
175 |
|
164 | |||
176 | # If possible (Unix), use the resource module instead of time.clock() |
|
165 | # If possible (Unix), use the resource module instead of time.clock() | |
177 | try: |
|
166 | try: | |
178 | import resource |
|
167 | import resource | |
179 | def clock(): |
|
168 | def clock(): | |
180 | """clock() -> floating point number |
|
169 | """clock() -> floating point number | |
181 |
|
170 | |||
182 | Return the CPU time in seconds (user time only, system time is |
|
171 | Return the CPU time in seconds (user time only, system time is | |
183 | ignored) since the start of the process. This is done via a call to |
|
172 | ignored) since the start of the process. This is done via a call to | |
184 | resource.getrusage, so it avoids the wraparound problems in |
|
173 | resource.getrusage, so it avoids the wraparound problems in | |
185 | time.clock().""" |
|
174 | time.clock().""" | |
186 |
|
175 | |||
187 | return resource.getrusage(resource.RUSAGE_SELF)[0] |
|
176 | return resource.getrusage(resource.RUSAGE_SELF)[0] | |
188 |
|
177 | |||
189 | def clock2(): |
|
178 | def clock2(): | |
190 | """clock2() -> (t_user,t_system) |
|
179 | """clock2() -> (t_user,t_system) | |
191 |
|
180 | |||
192 | Similar to clock(), but return a tuple of user/system times.""" |
|
181 | Similar to clock(), but return a tuple of user/system times.""" | |
193 | return resource.getrusage(resource.RUSAGE_SELF)[:2] |
|
182 | return resource.getrusage(resource.RUSAGE_SELF)[:2] | |
194 |
|
183 | |||
195 | except ImportError: |
|
184 | except ImportError: | |
196 | clock = time.clock |
|
185 | clock = time.clock | |
197 | def clock2(): |
|
186 | def clock2(): | |
198 | """Under windows, system CPU time can't be measured. |
|
187 | """Under windows, system CPU time can't be measured. | |
199 |
|
188 | |||
200 | This just returns clock() and zero.""" |
|
189 | This just returns clock() and zero.""" | |
201 | return time.clock(),0.0 |
|
190 | return time.clock(),0.0 | |
202 |
|
191 | |||
203 | def timings_out(reps,func,*args,**kw): |
|
192 | def timings_out(reps,func,*args,**kw): | |
204 | """timings_out(reps,func,*args,**kw) -> (t_total,t_per_call,output) |
|
193 | """timings_out(reps,func,*args,**kw) -> (t_total,t_per_call,output) | |
205 |
|
194 | |||
206 | Execute a function reps times, return a tuple with the elapsed total |
|
195 | Execute a function reps times, return a tuple with the elapsed total | |
207 | CPU time in seconds, the time per call and the function's output. |
|
196 | CPU time in seconds, the time per call and the function's output. | |
208 |
|
197 | |||
209 | Under Unix, the return value is the sum of user+system time consumed by |
|
198 | Under Unix, the return value is the sum of user+system time consumed by | |
210 | the process, computed via the resource module. This prevents problems |
|
199 | the process, computed via the resource module. This prevents problems | |
211 | related to the wraparound effect which the time.clock() function has. |
|
200 | related to the wraparound effect which the time.clock() function has. | |
212 |
|
201 | |||
213 | Under Windows the return value is in wall clock seconds. See the |
|
202 | Under Windows the return value is in wall clock seconds. See the | |
214 | documentation for the time module for more details.""" |
|
203 | documentation for the time module for more details.""" | |
215 |
|
204 | |||
216 | reps = int(reps) |
|
205 | reps = int(reps) | |
217 | assert reps >=1, 'reps must be >= 1' |
|
206 | assert reps >=1, 'reps must be >= 1' | |
218 | if reps==1: |
|
207 | if reps==1: | |
219 | start = clock() |
|
208 | start = clock() | |
220 | out = func(*args,**kw) |
|
209 | out = func(*args,**kw) | |
221 | tot_time = clock()-start |
|
210 | tot_time = clock()-start | |
222 | else: |
|
211 | else: | |
223 | rng = xrange(reps-1) # the last time is executed separately to store output |
|
212 | rng = xrange(reps-1) # the last time is executed separately to store output | |
224 | start = clock() |
|
213 | start = clock() | |
225 | for dummy in rng: func(*args,**kw) |
|
214 | for dummy in rng: func(*args,**kw) | |
226 | out = func(*args,**kw) # one last time |
|
215 | out = func(*args,**kw) # one last time | |
227 | tot_time = clock()-start |
|
216 | tot_time = clock()-start | |
228 | av_time = tot_time / reps |
|
217 | av_time = tot_time / reps | |
229 | return tot_time,av_time,out |
|
218 | return tot_time,av_time,out | |
230 |
|
219 | |||
231 | def timings(reps,func,*args,**kw): |
|
220 | def timings(reps,func,*args,**kw): | |
232 | """timings(reps,func,*args,**kw) -> (t_total,t_per_call) |
|
221 | """timings(reps,func,*args,**kw) -> (t_total,t_per_call) | |
233 |
|
222 | |||
234 | Execute a function reps times, return a tuple with the elapsed total CPU |
|
223 | Execute a function reps times, return a tuple with the elapsed total CPU | |
235 | time in seconds and the time per call. These are just the first two values |
|
224 | time in seconds and the time per call. These are just the first two values | |
236 | in timings_out().""" |
|
225 | in timings_out().""" | |
237 |
|
226 | |||
238 | return timings_out(reps,func,*args,**kw)[0:2] |
|
227 | return timings_out(reps,func,*args,**kw)[0:2] | |
239 |
|
228 | |||
240 | def timing(func,*args,**kw): |
|
229 | def timing(func,*args,**kw): | |
241 | """timing(func,*args,**kw) -> t_total |
|
230 | """timing(func,*args,**kw) -> t_total | |
242 |
|
231 | |||
243 | Execute a function once, return the elapsed total CPU time in |
|
232 | Execute a function once, return the elapsed total CPU time in | |
244 | seconds. This is just the first value in timings_out().""" |
|
233 | seconds. This is just the first value in timings_out().""" | |
245 |
|
234 | |||
246 | return timings_out(1,func,*args,**kw)[0] |
|
235 | return timings_out(1,func,*args,**kw)[0] | |
247 |
|
236 | |||
248 | #**************************************************************************** |
|
237 | #**************************************************************************** | |
249 | # file and system |
|
238 | # file and system | |
250 |
|
239 | |||
251 | def system(cmd,verbose=0,debug=0,header=''): |
|
240 | def system(cmd,verbose=0,debug=0,header=''): | |
252 | """Execute a system command, return its exit status. |
|
241 | """Execute a system command, return its exit status. | |
253 |
|
242 | |||
254 | Options: |
|
243 | Options: | |
255 |
|
244 | |||
256 | - verbose (0): print the command to be executed. |
|
245 | - verbose (0): print the command to be executed. | |
257 |
|
246 | |||
258 | - debug (0): only print, do not actually execute. |
|
247 | - debug (0): only print, do not actually execute. | |
259 |
|
248 | |||
260 | - header (''): Header to print on screen prior to the executed command (it |
|
249 | - header (''): Header to print on screen prior to the executed command (it | |
261 | is only prepended to the command, no newlines are added). |
|
250 | is only prepended to the command, no newlines are added). | |
262 |
|
251 | |||
263 | Note: a stateful version of this function is available through the |
|
252 | Note: a stateful version of this function is available through the | |
264 | SystemExec class.""" |
|
253 | SystemExec class.""" | |
265 |
|
254 | |||
266 | stat = 0 |
|
255 | stat = 0 | |
267 | if verbose or debug: print header+cmd |
|
256 | if verbose or debug: print header+cmd | |
268 | sys.stdout.flush() |
|
257 | sys.stdout.flush() | |
269 | if not debug: stat = os.system(cmd) |
|
258 | if not debug: stat = os.system(cmd) | |
270 | return stat |
|
259 | return stat | |
271 |
|
260 | |||
272 | def shell(cmd,verbose=0,debug=0,header=''): |
|
261 | def shell(cmd,verbose=0,debug=0,header=''): | |
273 | """Execute a command in the system shell, always return None. |
|
262 | """Execute a command in the system shell, always return None. | |
274 |
|
263 | |||
275 | Options: |
|
264 | Options: | |
276 |
|
265 | |||
277 | - verbose (0): print the command to be executed. |
|
266 | - verbose (0): print the command to be executed. | |
278 |
|
267 | |||
279 | - debug (0): only print, do not actually execute. |
|
268 | - debug (0): only print, do not actually execute. | |
280 |
|
269 | |||
281 | - header (''): Header to print on screen prior to the executed command (it |
|
270 | - header (''): Header to print on screen prior to the executed command (it | |
282 | is only prepended to the command, no newlines are added). |
|
271 | is only prepended to the command, no newlines are added). | |
283 |
|
272 | |||
284 | Note: this is similar to genutils.system(), but it returns None so it can |
|
273 | Note: this is similar to genutils.system(), but it returns None so it can | |
285 | be conveniently used in interactive loops without getting the return value |
|
274 | be conveniently used in interactive loops without getting the return value | |
286 | (typically 0) printed many times.""" |
|
275 | (typically 0) printed many times.""" | |
287 |
|
276 | |||
288 | stat = 0 |
|
277 | stat = 0 | |
289 | if verbose or debug: print header+cmd |
|
278 | if verbose or debug: print header+cmd | |
290 | # flush stdout so we don't mangle python's buffering |
|
279 | # flush stdout so we don't mangle python's buffering | |
291 | sys.stdout.flush() |
|
280 | sys.stdout.flush() | |
292 | if not debug: |
|
281 | if not debug: | |
293 | os.system(cmd) |
|
282 | os.system(cmd) | |
294 |
|
283 | |||
295 | def getoutput(cmd,verbose=0,debug=0,header='',split=0): |
|
284 | def getoutput(cmd,verbose=0,debug=0,header='',split=0): | |
296 | """Dummy substitute for perl's backquotes. |
|
285 | """Dummy substitute for perl's backquotes. | |
297 |
|
286 | |||
298 | Executes a command and returns the output. |
|
287 | Executes a command and returns the output. | |
299 |
|
288 | |||
300 | Accepts the same arguments as system(), plus: |
|
289 | Accepts the same arguments as system(), plus: | |
301 |
|
290 | |||
302 | - split(0): if true, the output is returned as a list split on newlines. |
|
291 | - split(0): if true, the output is returned as a list split on newlines. | |
303 |
|
292 | |||
304 | Note: a stateful version of this function is available through the |
|
293 | Note: a stateful version of this function is available through the | |
305 | SystemExec class.""" |
|
294 | SystemExec class.""" | |
306 |
|
295 | |||
307 | if verbose or debug: print header+cmd |
|
296 | if verbose or debug: print header+cmd | |
308 | if not debug: |
|
297 | if not debug: | |
309 | output = commands.getoutput(cmd) |
|
298 | output = commands.getoutput(cmd) | |
310 | if split: |
|
299 | if split: | |
311 | return output.split('\n') |
|
300 | return output.split('\n') | |
312 | else: |
|
301 | else: | |
313 | return output |
|
302 | return output | |
314 |
|
303 | |||
315 | def getoutputerror(cmd,verbose=0,debug=0,header='',split=0): |
|
304 | def getoutputerror(cmd,verbose=0,debug=0,header='',split=0): | |
316 | """Return (standard output,standard error) of executing cmd in a shell. |
|
305 | """Return (standard output,standard error) of executing cmd in a shell. | |
317 |
|
306 | |||
318 | Accepts the same arguments as system(), plus: |
|
307 | Accepts the same arguments as system(), plus: | |
319 |
|
308 | |||
320 | - split(0): if true, each of stdout/err is returned as a list split on |
|
309 | - split(0): if true, each of stdout/err is returned as a list split on | |
321 | newlines. |
|
310 | newlines. | |
322 |
|
311 | |||
323 | Note: a stateful version of this function is available through the |
|
312 | Note: a stateful version of this function is available through the | |
324 | SystemExec class.""" |
|
313 | SystemExec class.""" | |
325 |
|
314 | |||
326 | if verbose or debug: print header+cmd |
|
315 | if verbose or debug: print header+cmd | |
327 | if not cmd: |
|
316 | if not cmd: | |
328 | if split: |
|
317 | if split: | |
329 | return [],[] |
|
318 | return [],[] | |
330 | else: |
|
319 | else: | |
331 | return '','' |
|
320 | return '','' | |
332 | if not debug: |
|
321 | if not debug: | |
333 | pin,pout,perr = os.popen3(cmd) |
|
322 | pin,pout,perr = os.popen3(cmd) | |
334 | tout = pout.read().rstrip() |
|
323 | tout = pout.read().rstrip() | |
335 | terr = perr.read().rstrip() |
|
324 | terr = perr.read().rstrip() | |
336 | pin.close() |
|
325 | pin.close() | |
337 | pout.close() |
|
326 | pout.close() | |
338 | perr.close() |
|
327 | perr.close() | |
339 | if split: |
|
328 | if split: | |
340 | return tout.split('\n'),terr.split('\n') |
|
329 | return tout.split('\n'),terr.split('\n') | |
341 | else: |
|
330 | else: | |
342 | return tout,terr |
|
331 | return tout,terr | |
343 |
|
332 | |||
344 | # for compatibility with older naming conventions |
|
333 | # for compatibility with older naming conventions | |
345 | xsys = system |
|
334 | xsys = system | |
346 | bq = getoutput |
|
335 | bq = getoutput | |
347 |
|
336 | |||
348 | class SystemExec: |
|
337 | class SystemExec: | |
349 | """Access the system and getoutput functions through a stateful interface. |
|
338 | """Access the system and getoutput functions through a stateful interface. | |
350 |
|
339 | |||
351 | Note: here we refer to the system and getoutput functions from this |
|
340 | Note: here we refer to the system and getoutput functions from this | |
352 | library, not the ones from the standard python library. |
|
341 | library, not the ones from the standard python library. | |
353 |
|
342 | |||
354 | This class offers the system and getoutput functions as methods, but the |
|
343 | This class offers the system and getoutput functions as methods, but the | |
355 | verbose, debug and header parameters can be set for the instance (at |
|
344 | verbose, debug and header parameters can be set for the instance (at | |
356 | creation time or later) so that they don't need to be specified on each |
|
345 | creation time or later) so that they don't need to be specified on each | |
357 | call. |
|
346 | call. | |
358 |
|
347 | |||
359 | For efficiency reasons, there's no way to override the parameters on a |
|
348 | For efficiency reasons, there's no way to override the parameters on a | |
360 | per-call basis other than by setting instance attributes. If you need |
|
349 | per-call basis other than by setting instance attributes. If you need | |
361 | local overrides, it's best to directly call system() or getoutput(). |
|
350 | local overrides, it's best to directly call system() or getoutput(). | |
362 |
|
351 | |||
363 | The following names are provided as alternate options: |
|
352 | The following names are provided as alternate options: | |
364 | - xsys: alias to system |
|
353 | - xsys: alias to system | |
365 | - bq: alias to getoutput |
|
354 | - bq: alias to getoutput | |
366 |
|
355 | |||
367 | An instance can then be created as: |
|
356 | An instance can then be created as: | |
368 | >>> sysexec = SystemExec(verbose=1,debug=0,header='Calling: ') |
|
357 | >>> sysexec = SystemExec(verbose=1,debug=0,header='Calling: ') | |
369 |
|
358 | |||
370 | And used as: |
|
359 | And used as: | |
371 | >>> sysexec.xsys('pwd') |
|
360 | >>> sysexec.xsys('pwd') | |
372 | >>> dirlist = sysexec.bq('ls -l') |
|
361 | >>> dirlist = sysexec.bq('ls -l') | |
373 | """ |
|
362 | """ | |
374 |
|
363 | |||
375 | def __init__(self,verbose=0,debug=0,header='',split=0): |
|
364 | def __init__(self,verbose=0,debug=0,header='',split=0): | |
376 | """Specify the instance's values for verbose, debug and header.""" |
|
365 | """Specify the instance's values for verbose, debug and header.""" | |
377 | setattr_list(self,'verbose debug header split') |
|
366 | setattr_list(self,'verbose debug header split') | |
378 |
|
367 | |||
379 | def system(self,cmd): |
|
368 | def system(self,cmd): | |
380 | """Stateful interface to system(), with the same keyword parameters.""" |
|
369 | """Stateful interface to system(), with the same keyword parameters.""" | |
381 |
|
370 | |||
382 | system(cmd,self.verbose,self.debug,self.header) |
|
371 | system(cmd,self.verbose,self.debug,self.header) | |
383 |
|
372 | |||
384 | def shell(self,cmd): |
|
373 | def shell(self,cmd): | |
385 | """Stateful interface to shell(), with the same keyword parameters.""" |
|
374 | """Stateful interface to shell(), with the same keyword parameters.""" | |
386 |
|
375 | |||
387 | shell(cmd,self.verbose,self.debug,self.header) |
|
376 | shell(cmd,self.verbose,self.debug,self.header) | |
388 |
|
377 | |||
389 | xsys = system # alias |
|
378 | xsys = system # alias | |
390 |
|
379 | |||
391 | def getoutput(self,cmd): |
|
380 | def getoutput(self,cmd): | |
392 | """Stateful interface to getoutput().""" |
|
381 | """Stateful interface to getoutput().""" | |
393 |
|
382 | |||
394 | return getoutput(cmd,self.verbose,self.debug,self.header,self.split) |
|
383 | return getoutput(cmd,self.verbose,self.debug,self.header,self.split) | |
395 |
|
384 | |||
396 | def getoutputerror(self,cmd): |
|
385 | def getoutputerror(self,cmd): | |
397 | """Stateful interface to getoutputerror().""" |
|
386 | """Stateful interface to getoutputerror().""" | |
398 |
|
387 | |||
399 | return getoutputerror(cmd,self.verbose,self.debug,self.header,self.split) |
|
388 | return getoutputerror(cmd,self.verbose,self.debug,self.header,self.split) | |
400 |
|
389 | |||
401 | bq = getoutput # alias |
|
390 | bq = getoutput # alias | |
402 |
|
391 | |||
403 | #----------------------------------------------------------------------------- |
|
392 | #----------------------------------------------------------------------------- | |
404 | def mutex_opts(dict,ex_op): |
|
393 | def mutex_opts(dict,ex_op): | |
405 | """Check for presence of mutually exclusive keys in a dict. |
|
394 | """Check for presence of mutually exclusive keys in a dict. | |
406 |
|
395 | |||
407 | Call: mutex_opts(dict,[[op1a,op1b],[op2a,op2b]...]""" |
|
396 | Call: mutex_opts(dict,[[op1a,op1b],[op2a,op2b]...]""" | |
408 | for op1,op2 in ex_op: |
|
397 | for op1,op2 in ex_op: | |
409 | if op1 in dict and op2 in dict: |
|
398 | if op1 in dict and op2 in dict: | |
410 | raise ValueError,'\n*** ERROR in Arguments *** '\ |
|
399 | raise ValueError,'\n*** ERROR in Arguments *** '\ | |
411 | 'Options '+op1+' and '+op2+' are mutually exclusive.' |
|
400 | 'Options '+op1+' and '+op2+' are mutually exclusive.' | |
412 |
|
401 | |||
413 | #----------------------------------------------------------------------------- |
|
402 | #----------------------------------------------------------------------------- | |
414 | def filefind(fname,alt_dirs = None): |
|
403 | def filefind(fname,alt_dirs = None): | |
415 | """Return the given filename either in the current directory, if it |
|
404 | """Return the given filename either in the current directory, if it | |
416 | exists, or in a specified list of directories. |
|
405 | exists, or in a specified list of directories. | |
417 |
|
406 | |||
418 | ~ expansion is done on all file and directory names. |
|
407 | ~ expansion is done on all file and directory names. | |
419 |
|
408 | |||
420 | Upon an unsuccessful search, raise an IOError exception.""" |
|
409 | Upon an unsuccessful search, raise an IOError exception.""" | |
421 |
|
410 | |||
422 | if alt_dirs is None: |
|
411 | if alt_dirs is None: | |
423 | try: |
|
412 | try: | |
424 | alt_dirs = get_home_dir() |
|
413 | alt_dirs = get_home_dir() | |
425 | except HomeDirError: |
|
414 | except HomeDirError: | |
426 | alt_dirs = os.getcwd() |
|
415 | alt_dirs = os.getcwd() | |
427 | search = [fname] + list_strings(alt_dirs) |
|
416 | search = [fname] + list_strings(alt_dirs) | |
428 | search = map(os.path.expanduser,search) |
|
417 | search = map(os.path.expanduser,search) | |
429 | #print 'search list for',fname,'list:',search # dbg |
|
418 | #print 'search list for',fname,'list:',search # dbg | |
430 | fname = search[0] |
|
419 | fname = search[0] | |
431 | if os.path.isfile(fname): |
|
420 | if os.path.isfile(fname): | |
432 | return fname |
|
421 | return fname | |
433 | for direc in search[1:]: |
|
422 | for direc in search[1:]: | |
434 | testname = os.path.join(direc,fname) |
|
423 | testname = os.path.join(direc,fname) | |
435 | #print 'testname',testname # dbg |
|
424 | #print 'testname',testname # dbg | |
436 | if os.path.isfile(testname): |
|
425 | if os.path.isfile(testname): | |
437 | return testname |
|
426 | return testname | |
438 | raise IOError,'File' + `fname` + \ |
|
427 | raise IOError,'File' + `fname` + \ | |
439 | ' not found in current or supplied directories:' + `alt_dirs` |
|
428 | ' not found in current or supplied directories:' + `alt_dirs` | |
440 |
|
429 | |||
441 | #---------------------------------------------------------------------------- |
|
430 | #---------------------------------------------------------------------------- | |
442 | def target_outdated(target,deps): |
|
431 | def target_outdated(target,deps): | |
443 | """Determine whether a target is out of date. |
|
432 | """Determine whether a target is out of date. | |
444 |
|
433 | |||
445 | target_outdated(target,deps) -> 1/0 |
|
434 | target_outdated(target,deps) -> 1/0 | |
446 |
|
435 | |||
447 | deps: list of filenames which MUST exist. |
|
436 | deps: list of filenames which MUST exist. | |
448 | target: single filename which may or may not exist. |
|
437 | target: single filename which may or may not exist. | |
449 |
|
438 | |||
450 | If target doesn't exist or is older than any file listed in deps, return |
|
439 | If target doesn't exist or is older than any file listed in deps, return | |
451 | true, otherwise return false. |
|
440 | true, otherwise return false. | |
452 | """ |
|
441 | """ | |
453 | try: |
|
442 | try: | |
454 | target_time = os.path.getmtime(target) |
|
443 | target_time = os.path.getmtime(target) | |
455 | except os.error: |
|
444 | except os.error: | |
456 | return 1 |
|
445 | return 1 | |
457 | for dep in deps: |
|
446 | for dep in deps: | |
458 | dep_time = os.path.getmtime(dep) |
|
447 | dep_time = os.path.getmtime(dep) | |
459 | if dep_time > target_time: |
|
448 | if dep_time > target_time: | |
460 | #print "For target",target,"Dep failed:",dep # dbg |
|
449 | #print "For target",target,"Dep failed:",dep # dbg | |
461 | #print "times (dep,tar):",dep_time,target_time # dbg |
|
450 | #print "times (dep,tar):",dep_time,target_time # dbg | |
462 | return 1 |
|
451 | return 1 | |
463 | return 0 |
|
452 | return 0 | |
464 |
|
453 | |||
465 | #----------------------------------------------------------------------------- |
|
454 | #----------------------------------------------------------------------------- | |
466 | def target_update(target,deps,cmd): |
|
455 | def target_update(target,deps,cmd): | |
467 | """Update a target with a given command given a list of dependencies. |
|
456 | """Update a target with a given command given a list of dependencies. | |
468 |
|
457 | |||
469 | target_update(target,deps,cmd) -> runs cmd if target is outdated. |
|
458 | target_update(target,deps,cmd) -> runs cmd if target is outdated. | |
470 |
|
459 | |||
471 | This is just a wrapper around target_outdated() which calls the given |
|
460 | This is just a wrapper around target_outdated() which calls the given | |
472 | command if target is outdated.""" |
|
461 | command if target is outdated.""" | |
473 |
|
462 | |||
474 | if target_outdated(target,deps): |
|
463 | if target_outdated(target,deps): | |
475 | xsys(cmd) |
|
464 | xsys(cmd) | |
476 |
|
465 | |||
477 | #---------------------------------------------------------------------------- |
|
466 | #---------------------------------------------------------------------------- | |
478 | def unquote_ends(istr): |
|
467 | def unquote_ends(istr): | |
479 | """Remove a single pair of quotes from the endpoints of a string.""" |
|
468 | """Remove a single pair of quotes from the endpoints of a string.""" | |
480 |
|
469 | |||
481 | if not istr: |
|
470 | if not istr: | |
482 | return istr |
|
471 | return istr | |
483 | if (istr[0]=="'" and istr[-1]=="'") or \ |
|
472 | if (istr[0]=="'" and istr[-1]=="'") or \ | |
484 | (istr[0]=='"' and istr[-1]=='"'): |
|
473 | (istr[0]=='"' and istr[-1]=='"'): | |
485 | return istr[1:-1] |
|
474 | return istr[1:-1] | |
486 | else: |
|
475 | else: | |
487 | return istr |
|
476 | return istr | |
488 |
|
477 | |||
489 | #---------------------------------------------------------------------------- |
|
478 | #---------------------------------------------------------------------------- | |
490 | def process_cmdline(argv,names=[],defaults={},usage=''): |
|
479 | def process_cmdline(argv,names=[],defaults={},usage=''): | |
491 | """ Process command-line options and arguments. |
|
480 | """ Process command-line options and arguments. | |
492 |
|
481 | |||
493 | Arguments: |
|
482 | Arguments: | |
494 |
|
483 | |||
495 | - argv: list of arguments, typically sys.argv. |
|
484 | - argv: list of arguments, typically sys.argv. | |
496 |
|
485 | |||
497 | - names: list of option names. See DPyGetOpt docs for details on options |
|
486 | - names: list of option names. See DPyGetOpt docs for details on options | |
498 | syntax. |
|
487 | syntax. | |
499 |
|
488 | |||
500 | - defaults: dict of default values. |
|
489 | - defaults: dict of default values. | |
501 |
|
490 | |||
502 | - usage: optional usage notice to print if a wrong argument is passed. |
|
491 | - usage: optional usage notice to print if a wrong argument is passed. | |
503 |
|
492 | |||
504 | Return a dict of options and a list of free arguments.""" |
|
493 | Return a dict of options and a list of free arguments.""" | |
505 |
|
494 | |||
506 | getopt = DPyGetOpt.DPyGetOpt() |
|
495 | getopt = DPyGetOpt.DPyGetOpt() | |
507 | getopt.setIgnoreCase(0) |
|
496 | getopt.setIgnoreCase(0) | |
508 | getopt.parseConfiguration(names) |
|
497 | getopt.parseConfiguration(names) | |
509 |
|
498 | |||
510 | try: |
|
499 | try: | |
511 | getopt.processArguments(argv) |
|
500 | getopt.processArguments(argv) | |
512 | except: |
|
501 | except: | |
513 | print usage |
|
502 | print usage | |
514 | warn(`sys.exc_value`,level=4) |
|
503 | warn(`sys.exc_value`,level=4) | |
515 |
|
504 | |||
516 | defaults.update(getopt.optionValues) |
|
505 | defaults.update(getopt.optionValues) | |
517 | args = getopt.freeValues |
|
506 | args = getopt.freeValues | |
518 |
|
507 | |||
519 | return defaults,args |
|
508 | return defaults,args | |
520 |
|
509 | |||
521 | #---------------------------------------------------------------------------- |
|
510 | #---------------------------------------------------------------------------- | |
522 | def optstr2types(ostr): |
|
511 | def optstr2types(ostr): | |
523 | """Convert a string of option names to a dict of type mappings. |
|
512 | """Convert a string of option names to a dict of type mappings. | |
524 |
|
513 | |||
525 | optstr2types(str) -> {None:'string_opts',int:'int_opts',float:'float_opts'} |
|
514 | optstr2types(str) -> {None:'string_opts',int:'int_opts',float:'float_opts'} | |
526 |
|
515 | |||
527 | This is used to get the types of all the options in a string formatted |
|
516 | This is used to get the types of all the options in a string formatted | |
528 | with the conventions of DPyGetOpt. The 'type' None is used for options |
|
517 | with the conventions of DPyGetOpt. The 'type' None is used for options | |
529 | which are strings (they need no further conversion). This function's main |
|
518 | which are strings (they need no further conversion). This function's main | |
530 | use is to get a typemap for use with read_dict(). |
|
519 | use is to get a typemap for use with read_dict(). | |
531 | """ |
|
520 | """ | |
532 |
|
521 | |||
533 | typeconv = {None:'',int:'',float:''} |
|
522 | typeconv = {None:'',int:'',float:''} | |
534 | typemap = {'s':None,'i':int,'f':float} |
|
523 | typemap = {'s':None,'i':int,'f':float} | |
535 | opt_re = re.compile(r'([\w]*)([^:=]*:?=?)([sif]?)') |
|
524 | opt_re = re.compile(r'([\w]*)([^:=]*:?=?)([sif]?)') | |
536 |
|
525 | |||
537 | for w in ostr.split(): |
|
526 | for w in ostr.split(): | |
538 | oname,alias,otype = opt_re.match(w).groups() |
|
527 | oname,alias,otype = opt_re.match(w).groups() | |
539 | if otype == '' or alias == '!': # simple switches are integers too |
|
528 | if otype == '' or alias == '!': # simple switches are integers too | |
540 | otype = 'i' |
|
529 | otype = 'i' | |
541 | typeconv[typemap[otype]] += oname + ' ' |
|
530 | typeconv[typemap[otype]] += oname + ' ' | |
542 | return typeconv |
|
531 | return typeconv | |
543 |
|
532 | |||
544 | #---------------------------------------------------------------------------- |
|
533 | #---------------------------------------------------------------------------- | |
545 | def read_dict(filename,type_conv=None,**opt): |
|
534 | def read_dict(filename,type_conv=None,**opt): | |
546 |
|
535 | |||
547 | """Read a dictionary of key=value pairs from an input file, optionally |
|
536 | """Read a dictionary of key=value pairs from an input file, optionally | |
548 | performing conversions on the resulting values. |
|
537 | performing conversions on the resulting values. | |
549 |
|
538 | |||
550 | read_dict(filename,type_conv,**opt) -> dict |
|
539 | read_dict(filename,type_conv,**opt) -> dict | |
551 |
|
540 | |||
552 | Only one value per line is accepted, the format should be |
|
541 | Only one value per line is accepted, the format should be | |
553 | # optional comments are ignored |
|
542 | # optional comments are ignored | |
554 | key value\n |
|
543 | key value\n | |
555 |
|
544 | |||
556 | Args: |
|
545 | Args: | |
557 |
|
546 | |||
558 | - type_conv: A dictionary specifying which keys need to be converted to |
|
547 | - type_conv: A dictionary specifying which keys need to be converted to | |
559 | which types. By default all keys are read as strings. This dictionary |
|
548 | which types. By default all keys are read as strings. This dictionary | |
560 | should have as its keys valid conversion functions for strings |
|
549 | should have as its keys valid conversion functions for strings | |
561 | (int,long,float,complex, or your own). The value for each key |
|
550 | (int,long,float,complex, or your own). The value for each key | |
562 | (converter) should be a whitespace separated string containing the names |
|
551 | (converter) should be a whitespace separated string containing the names | |
563 | of all the entries in the file to be converted using that function. For |
|
552 | of all the entries in the file to be converted using that function. For | |
564 | keys to be left alone, use None as the conversion function (only needed |
|
553 | keys to be left alone, use None as the conversion function (only needed | |
565 | with purge=1, see below). |
|
554 | with purge=1, see below). | |
566 |
|
555 | |||
567 | - opt: dictionary with extra options as below (default in parens) |
|
556 | - opt: dictionary with extra options as below (default in parens) | |
568 |
|
557 | |||
569 | purge(0): if set to 1, all keys *not* listed in type_conv are purged out |
|
558 | purge(0): if set to 1, all keys *not* listed in type_conv are purged out | |
570 | of the dictionary to be returned. If purge is going to be used, the |
|
559 | of the dictionary to be returned. If purge is going to be used, the | |
571 | set of keys to be left as strings also has to be explicitly specified |
|
560 | set of keys to be left as strings also has to be explicitly specified | |
572 | using the (non-existent) conversion function None. |
|
561 | using the (non-existent) conversion function None. | |
573 |
|
562 | |||
574 | fs(None): field separator. This is the key/value separator to be used |
|
563 | fs(None): field separator. This is the key/value separator to be used | |
575 | when parsing the file. The None default means any whitespace [behavior |
|
564 | when parsing the file. The None default means any whitespace [behavior | |
576 | of string.split()]. |
|
565 | of string.split()]. | |
577 |
|
566 | |||
578 | strip(0): if 1, strip string values of leading/trailinig whitespace. |
|
567 | strip(0): if 1, strip string values of leading/trailinig whitespace. | |
579 |
|
568 | |||
580 | warn(1): warning level if requested keys are not found in file. |
|
569 | warn(1): warning level if requested keys are not found in file. | |
581 | - 0: silently ignore. |
|
570 | - 0: silently ignore. | |
582 | - 1: inform but proceed. |
|
571 | - 1: inform but proceed. | |
583 | - 2: raise KeyError exception. |
|
572 | - 2: raise KeyError exception. | |
584 |
|
573 | |||
585 | no_empty(0): if 1, remove keys with whitespace strings as a value. |
|
574 | no_empty(0): if 1, remove keys with whitespace strings as a value. | |
586 |
|
575 | |||
587 | unique([]): list of keys (or space separated string) which can't be |
|
576 | unique([]): list of keys (or space separated string) which can't be | |
588 | repeated. If one such key is found in the file, each new instance |
|
577 | repeated. If one such key is found in the file, each new instance | |
589 | overwrites the previous one. For keys not listed here, the behavior is |
|
578 | overwrites the previous one. For keys not listed here, the behavior is | |
590 | to make a list of all appearances. |
|
579 | to make a list of all appearances. | |
591 |
|
580 | |||
592 | Example: |
|
581 | Example: | |
593 | If the input file test.ini has: |
|
582 | If the input file test.ini has: | |
594 | i 3 |
|
583 | i 3 | |
595 | x 4.5 |
|
584 | x 4.5 | |
596 | y 5.5 |
|
585 | y 5.5 | |
597 | s hi ho |
|
586 | s hi ho | |
598 | Then: |
|
587 | Then: | |
599 |
|
588 | |||
600 | >>> type_conv={int:'i',float:'x',None:'s'} |
|
589 | >>> type_conv={int:'i',float:'x',None:'s'} | |
601 | >>> read_dict('test.ini') |
|
590 | >>> read_dict('test.ini') | |
602 | {'i': '3', 's': 'hi ho', 'x': '4.5', 'y': '5.5'} |
|
591 | {'i': '3', 's': 'hi ho', 'x': '4.5', 'y': '5.5'} | |
603 | >>> read_dict('test.ini',type_conv) |
|
592 | >>> read_dict('test.ini',type_conv) | |
604 | {'i': 3, 's': 'hi ho', 'x': 4.5, 'y': '5.5'} |
|
593 | {'i': 3, 's': 'hi ho', 'x': 4.5, 'y': '5.5'} | |
605 | >>> read_dict('test.ini',type_conv,purge=1) |
|
594 | >>> read_dict('test.ini',type_conv,purge=1) | |
606 | {'i': 3, 's': 'hi ho', 'x': 4.5} |
|
595 | {'i': 3, 's': 'hi ho', 'x': 4.5} | |
607 | """ |
|
596 | """ | |
608 |
|
597 | |||
609 | # starting config |
|
598 | # starting config | |
610 | opt.setdefault('purge',0) |
|
599 | opt.setdefault('purge',0) | |
611 | opt.setdefault('fs',None) # field sep defaults to any whitespace |
|
600 | opt.setdefault('fs',None) # field sep defaults to any whitespace | |
612 | opt.setdefault('strip',0) |
|
601 | opt.setdefault('strip',0) | |
613 | opt.setdefault('warn',1) |
|
602 | opt.setdefault('warn',1) | |
614 | opt.setdefault('no_empty',0) |
|
603 | opt.setdefault('no_empty',0) | |
615 | opt.setdefault('unique','') |
|
604 | opt.setdefault('unique','') | |
616 | if type(opt['unique']) in StringTypes: |
|
605 | if type(opt['unique']) in StringTypes: | |
617 | unique_keys = qw(opt['unique']) |
|
606 | unique_keys = qw(opt['unique']) | |
618 | elif type(opt['unique']) in (types.TupleType,types.ListType): |
|
607 | elif type(opt['unique']) in (types.TupleType,types.ListType): | |
619 | unique_keys = opt['unique'] |
|
608 | unique_keys = opt['unique'] | |
620 | else: |
|
609 | else: | |
621 | raise ValueError, 'Unique keys must be given as a string, List or Tuple' |
|
610 | raise ValueError, 'Unique keys must be given as a string, List or Tuple' | |
622 |
|
611 | |||
623 | dict = {} |
|
612 | dict = {} | |
624 | # first read in table of values as strings |
|
613 | # first read in table of values as strings | |
625 | file = open(filename,'r') |
|
614 | file = open(filename,'r') | |
626 | for line in file.readlines(): |
|
615 | for line in file.readlines(): | |
627 | line = line.strip() |
|
616 | line = line.strip() | |
628 | if len(line) and line[0]=='#': continue |
|
617 | if len(line) and line[0]=='#': continue | |
629 | if len(line)>0: |
|
618 | if len(line)>0: | |
630 | lsplit = line.split(opt['fs'],1) |
|
619 | lsplit = line.split(opt['fs'],1) | |
631 | try: |
|
620 | try: | |
632 | key,val = lsplit |
|
621 | key,val = lsplit | |
633 | except ValueError: |
|
622 | except ValueError: | |
634 | key,val = lsplit[0],'' |
|
623 | key,val = lsplit[0],'' | |
635 | key = key.strip() |
|
624 | key = key.strip() | |
636 | if opt['strip']: val = val.strip() |
|
625 | if opt['strip']: val = val.strip() | |
637 | if val == "''" or val == '""': val = '' |
|
626 | if val == "''" or val == '""': val = '' | |
638 | if opt['no_empty'] and (val=='' or val.isspace()): |
|
627 | if opt['no_empty'] and (val=='' or val.isspace()): | |
639 | continue |
|
628 | continue | |
640 | # if a key is found more than once in the file, build a list |
|
629 | # if a key is found more than once in the file, build a list | |
641 | # unless it's in the 'unique' list. In that case, last found in file |
|
630 | # unless it's in the 'unique' list. In that case, last found in file | |
642 | # takes precedence. User beware. |
|
631 | # takes precedence. User beware. | |
643 | try: |
|
632 | try: | |
644 | if dict[key] and key in unique_keys: |
|
633 | if dict[key] and key in unique_keys: | |
645 | dict[key] = val |
|
634 | dict[key] = val | |
646 | elif type(dict[key]) is types.ListType: |
|
635 | elif type(dict[key]) is types.ListType: | |
647 | dict[key].append(val) |
|
636 | dict[key].append(val) | |
648 | else: |
|
637 | else: | |
649 | dict[key] = [dict[key],val] |
|
638 | dict[key] = [dict[key],val] | |
650 | except KeyError: |
|
639 | except KeyError: | |
651 | dict[key] = val |
|
640 | dict[key] = val | |
652 | # purge if requested |
|
641 | # purge if requested | |
653 | if opt['purge']: |
|
642 | if opt['purge']: | |
654 | accepted_keys = qwflat(type_conv.values()) |
|
643 | accepted_keys = qwflat(type_conv.values()) | |
655 | for key in dict.keys(): |
|
644 | for key in dict.keys(): | |
656 | if key in accepted_keys: continue |
|
645 | if key in accepted_keys: continue | |
657 | del(dict[key]) |
|
646 | del(dict[key]) | |
658 | # now convert if requested |
|
647 | # now convert if requested | |
659 | if type_conv==None: return dict |
|
648 | if type_conv==None: return dict | |
660 | conversions = type_conv.keys() |
|
649 | conversions = type_conv.keys() | |
661 | try: conversions.remove(None) |
|
650 | try: conversions.remove(None) | |
662 | except: pass |
|
651 | except: pass | |
663 | for convert in conversions: |
|
652 | for convert in conversions: | |
664 | for val in qw(type_conv[convert]): |
|
653 | for val in qw(type_conv[convert]): | |
665 | try: |
|
654 | try: | |
666 | dict[val] = convert(dict[val]) |
|
655 | dict[val] = convert(dict[val]) | |
667 | except KeyError,e: |
|
656 | except KeyError,e: | |
668 | if opt['warn'] == 0: |
|
657 | if opt['warn'] == 0: | |
669 | pass |
|
658 | pass | |
670 | elif opt['warn'] == 1: |
|
659 | elif opt['warn'] == 1: | |
671 | print >>sys.stderr, 'Warning: key',val,\ |
|
660 | print >>sys.stderr, 'Warning: key',val,\ | |
672 | 'not found in file',filename |
|
661 | 'not found in file',filename | |
673 | elif opt['warn'] == 2: |
|
662 | elif opt['warn'] == 2: | |
674 | raise KeyError,e |
|
663 | raise KeyError,e | |
675 | else: |
|
664 | else: | |
676 | raise ValueError,'Warning level must be 0,1 or 2' |
|
665 | raise ValueError,'Warning level must be 0,1 or 2' | |
677 |
|
666 | |||
678 | return dict |
|
667 | return dict | |
679 |
|
668 | |||
680 | #---------------------------------------------------------------------------- |
|
669 | #---------------------------------------------------------------------------- | |
681 | def flag_calls(func): |
|
670 | def flag_calls(func): | |
682 | """Wrap a function to detect and flag when it gets called. |
|
671 | """Wrap a function to detect and flag when it gets called. | |
683 |
|
672 | |||
684 | This is a decorator which takes a function and wraps it in a function with |
|
673 | This is a decorator which takes a function and wraps it in a function with | |
685 | a 'called' attribute. wrapper.called is initialized to False. |
|
674 | a 'called' attribute. wrapper.called is initialized to False. | |
686 |
|
675 | |||
687 | The wrapper.called attribute is set to False right before each call to the |
|
676 | The wrapper.called attribute is set to False right before each call to the | |
688 | wrapped function, so if the call fails it remains False. After the call |
|
677 | wrapped function, so if the call fails it remains False. After the call | |
689 | completes, wrapper.called is set to True and the output is returned. |
|
678 | completes, wrapper.called is set to True and the output is returned. | |
690 |
|
679 | |||
691 | Testing for truth in wrapper.called allows you to determine if a call to |
|
680 | Testing for truth in wrapper.called allows you to determine if a call to | |
692 | func() was attempted and succeeded.""" |
|
681 | func() was attempted and succeeded.""" | |
693 |
|
682 | |||
694 | def wrapper(*args,**kw): |
|
683 | def wrapper(*args,**kw): | |
695 | wrapper.called = False |
|
684 | wrapper.called = False | |
696 | out = func(*args,**kw) |
|
685 | out = func(*args,**kw) | |
697 | wrapper.called = True |
|
686 | wrapper.called = True | |
698 | return out |
|
687 | return out | |
699 |
|
688 | |||
700 | wrapper.called = False |
|
689 | wrapper.called = False | |
701 | wrapper.__doc__ = func.__doc__ |
|
690 | wrapper.__doc__ = func.__doc__ | |
702 | return wrapper |
|
691 | return wrapper | |
703 |
|
692 | |||
704 | #---------------------------------------------------------------------------- |
|
693 | #---------------------------------------------------------------------------- | |
705 | class HomeDirError(Error): |
|
694 | class HomeDirError(Error): | |
706 | pass |
|
695 | pass | |
707 |
|
696 | |||
708 | def get_home_dir(): |
|
697 | def get_home_dir(): | |
709 | """Return the closest possible equivalent to a 'home' directory. |
|
698 | """Return the closest possible equivalent to a 'home' directory. | |
710 |
|
699 | |||
711 | We first try $HOME. Absent that, on NT it's $HOMEDRIVE\$HOMEPATH. |
|
700 | We first try $HOME. Absent that, on NT it's $HOMEDRIVE\$HOMEPATH. | |
712 |
|
701 | |||
713 | Currently only Posix and NT are implemented, a HomeDirError exception is |
|
702 | Currently only Posix and NT are implemented, a HomeDirError exception is | |
714 | raised for all other OSes. """ |
|
703 | raised for all other OSes. """ | |
715 |
|
704 | |||
716 | try: |
|
705 | try: | |
717 | return os.environ['HOME'] |
|
706 | return os.environ['HOME'] | |
718 | except KeyError: |
|
707 | except KeyError: | |
719 | if os.name == 'posix': |
|
708 | if os.name == 'posix': | |
720 | raise HomeDirError,'undefined $HOME, IPython can not proceed.' |
|
709 | raise HomeDirError,'undefined $HOME, IPython can not proceed.' | |
721 | elif os.name == 'nt': |
|
710 | elif os.name == 'nt': | |
722 | # For some strange reason, win9x returns 'nt' for os.name. |
|
711 | # For some strange reason, win9x returns 'nt' for os.name. | |
723 | try: |
|
712 | try: | |
724 | return os.path.join(os.environ['HOMEDRIVE'],os.environ['HOMEPATH']) |
|
713 | return os.path.join(os.environ['HOMEDRIVE'],os.environ['HOMEPATH']) | |
725 | except: |
|
714 | except: | |
726 | try: |
|
715 | try: | |
727 | # Use the registry to get the 'My Documents' folder. |
|
716 | # Use the registry to get the 'My Documents' folder. | |
728 | import _winreg as wreg |
|
717 | import _winreg as wreg | |
729 | key = wreg.OpenKey(wreg.HKEY_CURRENT_USER, |
|
718 | key = wreg.OpenKey(wreg.HKEY_CURRENT_USER, | |
730 | "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders") |
|
719 | "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders") | |
731 | homedir = wreg.QueryValueEx(key,'Personal')[0] |
|
720 | homedir = wreg.QueryValueEx(key,'Personal')[0] | |
732 | key.Close() |
|
721 | key.Close() | |
733 | return homedir |
|
722 | return homedir | |
734 | except: |
|
723 | except: | |
735 | return 'C:\\' |
|
724 | return 'C:\\' | |
736 | elif os.name == 'dos': |
|
725 | elif os.name == 'dos': | |
737 | # Desperate, may do absurd things in classic MacOS. May work under DOS. |
|
726 | # Desperate, may do absurd things in classic MacOS. May work under DOS. | |
738 | return 'C:\\' |
|
727 | return 'C:\\' | |
739 | else: |
|
728 | else: | |
740 | raise HomeDirError,'support for your operating system not implemented.' |
|
729 | raise HomeDirError,'support for your operating system not implemented.' | |
741 |
|
730 | |||
742 | #**************************************************************************** |
|
731 | #**************************************************************************** | |
743 | # strings and text |
|
732 | # strings and text | |
744 |
|
733 | |||
745 | class LSString(str): |
|
734 | class LSString(str): | |
746 | """String derivative with a special access attributes. |
|
735 | """String derivative with a special access attributes. | |
747 |
|
736 | |||
748 | These are normal strings, but with the special attributes: |
|
737 | These are normal strings, but with the special attributes: | |
749 |
|
738 | |||
750 | .l (or .list) : value as list (split on newlines). |
|
739 | .l (or .list) : value as list (split on newlines). | |
751 | .n (or .nlstr): original value (the string itself). |
|
740 | .n (or .nlstr): original value (the string itself). | |
752 | .s (or .spstr): value as whitespace-separated string. |
|
741 | .s (or .spstr): value as whitespace-separated string. | |
753 |
|
742 | |||
754 | Any values which require transformations are computed only once and |
|
743 | Any values which require transformations are computed only once and | |
755 | cached. |
|
744 | cached. | |
756 |
|
745 | |||
757 | Such strings are very useful to efficiently interact with the shell, which |
|
746 | Such strings are very useful to efficiently interact with the shell, which | |
758 | typically only understands whitespace-separated options for commands.""" |
|
747 | typically only understands whitespace-separated options for commands.""" | |
759 |
|
748 | |||
760 | def get_list(self): |
|
749 | def get_list(self): | |
761 | try: |
|
750 | try: | |
762 | return self.__list |
|
751 | return self.__list | |
763 | except AttributeError: |
|
752 | except AttributeError: | |
764 | self.__list = self.split('\n') |
|
753 | self.__list = self.split('\n') | |
765 | return self.__list |
|
754 | return self.__list | |
766 |
|
755 | |||
767 | l = list = property(get_list) |
|
756 | l = list = property(get_list) | |
768 |
|
757 | |||
769 | def get_spstr(self): |
|
758 | def get_spstr(self): | |
770 | try: |
|
759 | try: | |
771 | return self.__spstr |
|
760 | return self.__spstr | |
772 | except AttributeError: |
|
761 | except AttributeError: | |
773 | self.__spstr = self.replace('\n',' ') |
|
762 | self.__spstr = self.replace('\n',' ') | |
774 | return self.__spstr |
|
763 | return self.__spstr | |
775 |
|
764 | |||
776 | s = spstr = property(get_spstr) |
|
765 | s = spstr = property(get_spstr) | |
777 |
|
766 | |||
778 | def get_nlstr(self): |
|
767 | def get_nlstr(self): | |
779 | return self |
|
768 | return self | |
780 |
|
769 | |||
781 | n = nlstr = property(get_nlstr) |
|
770 | n = nlstr = property(get_nlstr) | |
782 |
|
771 | |||
783 | class SList(list): |
|
772 | class SList(list): | |
784 | """List derivative with a special access attributes. |
|
773 | """List derivative with a special access attributes. | |
785 |
|
774 | |||
786 | These are normal lists, but with the special attributes: |
|
775 | These are normal lists, but with the special attributes: | |
787 |
|
776 | |||
788 | .l (or .list) : value as list (the list itself). |
|
777 | .l (or .list) : value as list (the list itself). | |
789 | .n (or .nlstr): value as a string, joined on newlines. |
|
778 | .n (or .nlstr): value as a string, joined on newlines. | |
790 | .s (or .spstr): value as a string, joined on spaces. |
|
779 | .s (or .spstr): value as a string, joined on spaces. | |
791 |
|
780 | |||
792 | Any values which require transformations are computed only once and |
|
781 | Any values which require transformations are computed only once and | |
793 | cached.""" |
|
782 | cached.""" | |
794 |
|
783 | |||
795 | def get_list(self): |
|
784 | def get_list(self): | |
796 | return self |
|
785 | return self | |
797 |
|
786 | |||
798 | l = list = property(get_list) |
|
787 | l = list = property(get_list) | |
799 |
|
788 | |||
800 | def get_spstr(self): |
|
789 | def get_spstr(self): | |
801 | try: |
|
790 | try: | |
802 | return self.__spstr |
|
791 | return self.__spstr | |
803 | except AttributeError: |
|
792 | except AttributeError: | |
804 | self.__spstr = ' '.join(self) |
|
793 | self.__spstr = ' '.join(self) | |
805 | return self.__spstr |
|
794 | return self.__spstr | |
806 |
|
795 | |||
807 | s = spstr = property(get_spstr) |
|
796 | s = spstr = property(get_spstr) | |
808 |
|
797 | |||
809 | def get_nlstr(self): |
|
798 | def get_nlstr(self): | |
810 | try: |
|
799 | try: | |
811 | return self.__nlstr |
|
800 | return self.__nlstr | |
812 | except AttributeError: |
|
801 | except AttributeError: | |
813 | self.__nlstr = '\n'.join(self) |
|
802 | self.__nlstr = '\n'.join(self) | |
814 | return self.__nlstr |
|
803 | return self.__nlstr | |
815 |
|
804 | |||
816 | n = nlstr = property(get_nlstr) |
|
805 | n = nlstr = property(get_nlstr) | |
817 |
|
806 | |||
818 | def raw_input_multi(header='', ps1='==> ', ps2='..> ',terminate_str = '.'): |
|
807 | def raw_input_multi(header='', ps1='==> ', ps2='..> ',terminate_str = '.'): | |
819 | """Take multiple lines of input. |
|
808 | """Take multiple lines of input. | |
820 |
|
809 | |||
821 | A list with each line of input as a separate element is returned when a |
|
810 | A list with each line of input as a separate element is returned when a | |
822 | termination string is entered (defaults to a single '.'). Input can also |
|
811 | termination string is entered (defaults to a single '.'). Input can also | |
823 | terminate via EOF (^D in Unix, ^Z-RET in Windows). |
|
812 | terminate via EOF (^D in Unix, ^Z-RET in Windows). | |
824 |
|
813 | |||
825 | Lines of input which end in \\ are joined into single entries (and a |
|
814 | Lines of input which end in \\ are joined into single entries (and a | |
826 | secondary continuation prompt is issued as long as the user terminates |
|
815 | secondary continuation prompt is issued as long as the user terminates | |
827 | lines with \\). This allows entering very long strings which are still |
|
816 | lines with \\). This allows entering very long strings which are still | |
828 | meant to be treated as single entities. |
|
817 | meant to be treated as single entities. | |
829 | """ |
|
818 | """ | |
830 |
|
819 | |||
831 | try: |
|
820 | try: | |
832 | if header: |
|
821 | if header: | |
833 | header += '\n' |
|
822 | header += '\n' | |
834 | lines = [raw_input(header + ps1)] |
|
823 | lines = [raw_input(header + ps1)] | |
835 | except EOFError: |
|
824 | except EOFError: | |
836 | return [] |
|
825 | return [] | |
837 | terminate = [terminate_str] |
|
826 | terminate = [terminate_str] | |
838 | try: |
|
827 | try: | |
839 | while lines[-1:] != terminate: |
|
828 | while lines[-1:] != terminate: | |
840 | new_line = raw_input(ps1) |
|
829 | new_line = raw_input(ps1) | |
841 | while new_line.endswith('\\'): |
|
830 | while new_line.endswith('\\'): | |
842 | new_line = new_line[:-1] + raw_input(ps2) |
|
831 | new_line = new_line[:-1] + raw_input(ps2) | |
843 | lines.append(new_line) |
|
832 | lines.append(new_line) | |
844 |
|
833 | |||
845 | return lines[:-1] # don't return the termination command |
|
834 | return lines[:-1] # don't return the termination command | |
846 | except EOFError: |
|
835 | except EOFError: | |
847 |
|
836 | |||
848 | return lines |
|
837 | return lines | |
849 |
|
838 | |||
850 | #---------------------------------------------------------------------------- |
|
839 | #---------------------------------------------------------------------------- | |
851 | def raw_input_ext(prompt='', ps2='... '): |
|
840 | def raw_input_ext(prompt='', ps2='... '): | |
852 | """Similar to raw_input(), but accepts extended lines if input ends with \\.""" |
|
841 | """Similar to raw_input(), but accepts extended lines if input ends with \\.""" | |
853 |
|
842 | |||
854 | line = raw_input(prompt) |
|
843 | line = raw_input(prompt) | |
855 | while line.endswith('\\'): |
|
844 | while line.endswith('\\'): | |
856 | line = line[:-1] + raw_input(ps2) |
|
845 | line = line[:-1] + raw_input(ps2) | |
857 | return line |
|
846 | return line | |
858 |
|
847 | |||
859 | #---------------------------------------------------------------------------- |
|
848 | #---------------------------------------------------------------------------- | |
860 | def ask_yes_no(prompt,default=None): |
|
849 | def ask_yes_no(prompt,default=None): | |
861 | """Asks a question and returns an integer 1/0 (y/n) answer. |
|
850 | """Asks a question and returns an integer 1/0 (y/n) answer. | |
862 |
|
851 | |||
863 | If default is given (one of 'y','n'), it is used if the user input is |
|
852 | If default is given (one of 'y','n'), it is used if the user input is | |
864 | empty. Otherwise the question is repeated until an answer is given. |
|
853 | empty. Otherwise the question is repeated until an answer is given. | |
865 | If EOF occurs 20 times consecutively, the default answer is assumed, |
|
854 | If EOF occurs 20 times consecutively, the default answer is assumed, | |
866 | or if there is no default, an exception is raised to prevent infinite |
|
855 | or if there is no default, an exception is raised to prevent infinite | |
867 | loops. |
|
856 | loops. | |
868 |
|
857 | |||
869 | Valid answers are: y/yes/n/no (match is not case sensitive).""" |
|
858 | Valid answers are: y/yes/n/no (match is not case sensitive).""" | |
870 |
|
859 | |||
871 | answers = {'y':1,'n':0,'yes':1,'no':0} |
|
860 | answers = {'y':1,'n':0,'yes':1,'no':0} | |
872 | ans = None |
|
861 | ans = None | |
873 | eofs, max_eofs = 0, 20 |
|
862 | eofs, max_eofs = 0, 20 | |
874 | while ans not in answers.keys(): |
|
863 | while ans not in answers.keys(): | |
875 | try: |
|
864 | try: | |
876 | ans = raw_input(prompt+' ').lower() |
|
865 | ans = raw_input(prompt+' ').lower() | |
877 | if not ans: # response was an empty string |
|
866 | if not ans: # response was an empty string | |
878 | ans = default |
|
867 | ans = default | |
879 | eofs = 0 |
|
868 | eofs = 0 | |
880 | except (EOFError,KeyboardInterrupt): |
|
869 | except (EOFError,KeyboardInterrupt): | |
881 | eofs = eofs + 1 |
|
870 | eofs = eofs + 1 | |
882 | if eofs >= max_eofs: |
|
871 | if eofs >= max_eofs: | |
883 | if default in answers.keys(): |
|
872 | if default in answers.keys(): | |
884 | ans = default |
|
873 | ans = default | |
885 | else: |
|
874 | else: | |
886 | raise |
|
875 | raise | |
887 |
|
876 | |||
888 | return answers[ans] |
|
877 | return answers[ans] | |
889 |
|
878 | |||
890 | #---------------------------------------------------------------------------- |
|
879 | #---------------------------------------------------------------------------- | |
891 | class EvalDict: |
|
880 | class EvalDict: | |
892 | """ |
|
881 | """ | |
893 | Emulate a dict which evaluates its contents in the caller's frame. |
|
882 | Emulate a dict which evaluates its contents in the caller's frame. | |
894 |
|
883 | |||
895 | Usage: |
|
884 | Usage: | |
896 | >>>number = 19 |
|
885 | >>>number = 19 | |
897 | >>>text = "python" |
|
886 | >>>text = "python" | |
898 | >>>print "%(text.capitalize())s %(number/9.0).1f rules!" % EvalDict() |
|
887 | >>>print "%(text.capitalize())s %(number/9.0).1f rules!" % EvalDict() | |
899 | """ |
|
888 | """ | |
900 |
|
889 | |||
901 | # This version is due to sismex01@hebmex.com on c.l.py, and is basically a |
|
890 | # This version is due to sismex01@hebmex.com on c.l.py, and is basically a | |
902 | # modified (shorter) version of: |
|
891 | # modified (shorter) version of: | |
903 | # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66018 by |
|
892 | # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66018 by | |
904 | # Skip Montanaro (skip@pobox.com). |
|
893 | # Skip Montanaro (skip@pobox.com). | |
905 |
|
894 | |||
906 | def __getitem__(self, name): |
|
895 | def __getitem__(self, name): | |
907 | frame = sys._getframe(1) |
|
896 | frame = sys._getframe(1) | |
908 | return eval(name, frame.f_globals, frame.f_locals) |
|
897 | return eval(name, frame.f_globals, frame.f_locals) | |
909 |
|
898 | |||
910 | EvalString = EvalDict # for backwards compatibility |
|
899 | EvalString = EvalDict # for backwards compatibility | |
911 | #---------------------------------------------------------------------------- |
|
900 | #---------------------------------------------------------------------------- | |
912 | def qw(words,flat=0,sep=None,maxsplit=-1): |
|
901 | def qw(words,flat=0,sep=None,maxsplit=-1): | |
913 | """Similar to Perl's qw() operator, but with some more options. |
|
902 | """Similar to Perl's qw() operator, but with some more options. | |
914 |
|
903 | |||
915 | qw(words,flat=0,sep=' ',maxsplit=-1) -> words.split(sep,maxsplit) |
|
904 | qw(words,flat=0,sep=' ',maxsplit=-1) -> words.split(sep,maxsplit) | |
916 |
|
905 | |||
917 | words can also be a list itself, and with flat=1, the output will be |
|
906 | words can also be a list itself, and with flat=1, the output will be | |
918 | recursively flattened. Examples: |
|
907 | recursively flattened. Examples: | |
919 |
|
908 | |||
920 | >>> qw('1 2') |
|
909 | >>> qw('1 2') | |
921 | ['1', '2'] |
|
910 | ['1', '2'] | |
922 | >>> qw(['a b','1 2',['m n','p q']]) |
|
911 | >>> qw(['a b','1 2',['m n','p q']]) | |
923 | [['a', 'b'], ['1', '2'], [['m', 'n'], ['p', 'q']]] |
|
912 | [['a', 'b'], ['1', '2'], [['m', 'n'], ['p', 'q']]] | |
924 | >>> qw(['a b','1 2',['m n','p q']],flat=1) |
|
913 | >>> qw(['a b','1 2',['m n','p q']],flat=1) | |
925 | ['a', 'b', '1', '2', 'm', 'n', 'p', 'q'] """ |
|
914 | ['a', 'b', '1', '2', 'm', 'n', 'p', 'q'] """ | |
926 |
|
915 | |||
927 | if type(words) in StringTypes: |
|
916 | if type(words) in StringTypes: | |
928 | return [word.strip() for word in words.split(sep,maxsplit) |
|
917 | return [word.strip() for word in words.split(sep,maxsplit) | |
929 | if word and not word.isspace() ] |
|
918 | if word and not word.isspace() ] | |
930 | if flat: |
|
919 | if flat: | |
931 | return flatten(map(qw,words,[1]*len(words))) |
|
920 | return flatten(map(qw,words,[1]*len(words))) | |
932 | return map(qw,words) |
|
921 | return map(qw,words) | |
933 |
|
922 | |||
934 | #---------------------------------------------------------------------------- |
|
923 | #---------------------------------------------------------------------------- | |
935 | def qwflat(words,sep=None,maxsplit=-1): |
|
924 | def qwflat(words,sep=None,maxsplit=-1): | |
936 | """Calls qw(words) in flat mode. It's just a convenient shorthand.""" |
|
925 | """Calls qw(words) in flat mode. It's just a convenient shorthand.""" | |
937 | return qw(words,1,sep,maxsplit) |
|
926 | return qw(words,1,sep,maxsplit) | |
938 |
|
927 | |||
939 | #----------------------------------------------------------------------------- |
|
928 | #----------------------------------------------------------------------------- | |
940 | def list_strings(arg): |
|
929 | def list_strings(arg): | |
941 | """Always return a list of strings, given a string or list of strings |
|
930 | """Always return a list of strings, given a string or list of strings | |
942 | as input.""" |
|
931 | as input.""" | |
943 |
|
932 | |||
944 | if type(arg) in StringTypes: return [arg] |
|
933 | if type(arg) in StringTypes: return [arg] | |
945 | else: return arg |
|
934 | else: return arg | |
946 |
|
935 | |||
947 | #---------------------------------------------------------------------------- |
|
936 | #---------------------------------------------------------------------------- | |
948 | def grep(pat,list,case=1): |
|
937 | def grep(pat,list,case=1): | |
949 | """Simple minded grep-like function. |
|
938 | """Simple minded grep-like function. | |
950 | grep(pat,list) returns occurrences of pat in list, None on failure. |
|
939 | grep(pat,list) returns occurrences of pat in list, None on failure. | |
951 |
|
940 | |||
952 | It only does simple string matching, with no support for regexps. Use the |
|
941 | It only does simple string matching, with no support for regexps. Use the | |
953 | option case=0 for case-insensitive matching.""" |
|
942 | option case=0 for case-insensitive matching.""" | |
954 |
|
943 | |||
955 | # This is pretty crude. At least it should implement copying only references |
|
944 | # This is pretty crude. At least it should implement copying only references | |
956 | # to the original data in case it's big. Now it copies the data for output. |
|
945 | # to the original data in case it's big. Now it copies the data for output. | |
957 | out=[] |
|
946 | out=[] | |
958 | if case: |
|
947 | if case: | |
959 | for term in list: |
|
948 | for term in list: | |
960 | if term.find(pat)>-1: out.append(term) |
|
949 | if term.find(pat)>-1: out.append(term) | |
961 | else: |
|
950 | else: | |
962 | lpat=pat.lower() |
|
951 | lpat=pat.lower() | |
963 | for term in list: |
|
952 | for term in list: | |
964 | if term.lower().find(lpat)>-1: out.append(term) |
|
953 | if term.lower().find(lpat)>-1: out.append(term) | |
965 |
|
954 | |||
966 | if len(out): return out |
|
955 | if len(out): return out | |
967 | else: return None |
|
956 | else: return None | |
968 |
|
957 | |||
969 | #---------------------------------------------------------------------------- |
|
958 | #---------------------------------------------------------------------------- | |
970 | def dgrep(pat,*opts): |
|
959 | def dgrep(pat,*opts): | |
971 | """Return grep() on dir()+dir(__builtins__). |
|
960 | """Return grep() on dir()+dir(__builtins__). | |
972 |
|
961 | |||
973 | A very common use of grep() when working interactively.""" |
|
962 | A very common use of grep() when working interactively.""" | |
974 |
|
963 | |||
975 | return grep(pat,dir(__main__)+dir(__main__.__builtins__),*opts) |
|
964 | return grep(pat,dir(__main__)+dir(__main__.__builtins__),*opts) | |
976 |
|
965 | |||
977 | #---------------------------------------------------------------------------- |
|
966 | #---------------------------------------------------------------------------- | |
978 | def idgrep(pat): |
|
967 | def idgrep(pat): | |
979 | """Case-insensitive dgrep()""" |
|
968 | """Case-insensitive dgrep()""" | |
980 |
|
969 | |||
981 | return dgrep(pat,0) |
|
970 | return dgrep(pat,0) | |
982 |
|
971 | |||
983 | #---------------------------------------------------------------------------- |
|
972 | #---------------------------------------------------------------------------- | |
984 | def igrep(pat,list): |
|
973 | def igrep(pat,list): | |
985 | """Synonym for case-insensitive grep.""" |
|
974 | """Synonym for case-insensitive grep.""" | |
986 |
|
975 | |||
987 | return grep(pat,list,case=0) |
|
976 | return grep(pat,list,case=0) | |
988 |
|
977 | |||
989 | #---------------------------------------------------------------------------- |
|
978 | #---------------------------------------------------------------------------- | |
990 | def indent(str,nspaces=4,ntabs=0): |
|
979 | def indent(str,nspaces=4,ntabs=0): | |
991 | """Indent a string a given number of spaces or tabstops. |
|
980 | """Indent a string a given number of spaces or tabstops. | |
992 |
|
981 | |||
993 | indent(str,nspaces=4,ntabs=0) -> indent str by ntabs+nspaces. |
|
982 | indent(str,nspaces=4,ntabs=0) -> indent str by ntabs+nspaces. | |
994 | """ |
|
983 | """ | |
995 | if str is None: |
|
984 | if str is None: | |
996 | return |
|
985 | return | |
997 | ind = '\t'*ntabs+' '*nspaces |
|
986 | ind = '\t'*ntabs+' '*nspaces | |
998 | outstr = '%s%s' % (ind,str.replace(os.linesep,os.linesep+ind)) |
|
987 | outstr = '%s%s' % (ind,str.replace(os.linesep,os.linesep+ind)) | |
999 | if outstr.endswith(os.linesep+ind): |
|
988 | if outstr.endswith(os.linesep+ind): | |
1000 | return outstr[:-len(ind)] |
|
989 | return outstr[:-len(ind)] | |
1001 | else: |
|
990 | else: | |
1002 | return outstr |
|
991 | return outstr | |
1003 |
|
992 | |||
1004 | #----------------------------------------------------------------------------- |
|
993 | #----------------------------------------------------------------------------- | |
1005 | def native_line_ends(filename,backup=1): |
|
994 | def native_line_ends(filename,backup=1): | |
1006 | """Convert (in-place) a file to line-ends native to the current OS. |
|
995 | """Convert (in-place) a file to line-ends native to the current OS. | |
1007 |
|
996 | |||
1008 | If the optional backup argument is given as false, no backup of the |
|
997 | If the optional backup argument is given as false, no backup of the | |
1009 | original file is left. """ |
|
998 | original file is left. """ | |
1010 |
|
999 | |||
1011 | backup_suffixes = {'posix':'~','dos':'.bak','nt':'.bak','mac':'.bak'} |
|
1000 | backup_suffixes = {'posix':'~','dos':'.bak','nt':'.bak','mac':'.bak'} | |
1012 |
|
1001 | |||
1013 | bak_filename = filename + backup_suffixes[os.name] |
|
1002 | bak_filename = filename + backup_suffixes[os.name] | |
1014 |
|
1003 | |||
1015 | original = open(filename).read() |
|
1004 | original = open(filename).read() | |
1016 | shutil.copy2(filename,bak_filename) |
|
1005 | shutil.copy2(filename,bak_filename) | |
1017 | try: |
|
1006 | try: | |
1018 | new = open(filename,'wb') |
|
1007 | new = open(filename,'wb') | |
1019 | new.write(os.linesep.join(original.splitlines())) |
|
1008 | new.write(os.linesep.join(original.splitlines())) | |
1020 | new.write(os.linesep) # ALWAYS put an eol at the end of the file |
|
1009 | new.write(os.linesep) # ALWAYS put an eol at the end of the file | |
1021 | new.close() |
|
1010 | new.close() | |
1022 | except: |
|
1011 | except: | |
1023 | os.rename(bak_filename,filename) |
|
1012 | os.rename(bak_filename,filename) | |
1024 | if not backup: |
|
1013 | if not backup: | |
1025 | try: |
|
1014 | try: | |
1026 | os.remove(bak_filename) |
|
1015 | os.remove(bak_filename) | |
1027 | except: |
|
1016 | except: | |
1028 | pass |
|
1017 | pass | |
1029 |
|
1018 | |||
1030 | #---------------------------------------------------------------------------- |
|
1019 | #---------------------------------------------------------------------------- | |
1031 | def get_pager_cmd(pager_cmd = None): |
|
1020 | def get_pager_cmd(pager_cmd = None): | |
1032 | """Return a pager command. |
|
1021 | """Return a pager command. | |
1033 |
|
1022 | |||
1034 | Makes some attempts at finding an OS-correct one.""" |
|
1023 | Makes some attempts at finding an OS-correct one.""" | |
1035 |
|
1024 | |||
1036 | if os.name == 'posix': |
|
1025 | if os.name == 'posix': | |
1037 | default_pager_cmd = 'less -r' # -r for color control sequences |
|
1026 | default_pager_cmd = 'less -r' # -r for color control sequences | |
1038 | elif os.name in ['nt','dos']: |
|
1027 | elif os.name in ['nt','dos']: | |
1039 | default_pager_cmd = 'type' |
|
1028 | default_pager_cmd = 'type' | |
1040 |
|
1029 | |||
1041 | if pager_cmd is None: |
|
1030 | if pager_cmd is None: | |
1042 | try: |
|
1031 | try: | |
1043 | pager_cmd = os.environ['PAGER'] |
|
1032 | pager_cmd = os.environ['PAGER'] | |
1044 | except: |
|
1033 | except: | |
1045 | pager_cmd = default_pager_cmd |
|
1034 | pager_cmd = default_pager_cmd | |
1046 | return pager_cmd |
|
1035 | return pager_cmd | |
1047 |
|
1036 | |||
1048 | #----------------------------------------------------------------------------- |
|
1037 | #----------------------------------------------------------------------------- | |
1049 | def get_pager_start(pager,start): |
|
1038 | def get_pager_start(pager,start): | |
1050 | """Return the string for paging files with an offset. |
|
1039 | """Return the string for paging files with an offset. | |
1051 |
|
1040 | |||
1052 | This is the '+N' argument which less and more (under Unix) accept. |
|
1041 | This is the '+N' argument which less and more (under Unix) accept. | |
1053 | """ |
|
1042 | """ | |
1054 |
|
1043 | |||
1055 | if pager in ['less','more']: |
|
1044 | if pager in ['less','more']: | |
1056 | if start: |
|
1045 | if start: | |
1057 | start_string = '+' + str(start) |
|
1046 | start_string = '+' + str(start) | |
1058 | else: |
|
1047 | else: | |
1059 | start_string = '' |
|
1048 | start_string = '' | |
1060 | else: |
|
1049 | else: | |
1061 | start_string = '' |
|
1050 | start_string = '' | |
1062 | return start_string |
|
1051 | return start_string | |
1063 |
|
1052 | |||
1064 | #---------------------------------------------------------------------------- |
|
1053 | #---------------------------------------------------------------------------- | |
1065 | def page_dumb(strng,start=0,screen_lines=25): |
|
1054 | def page_dumb(strng,start=0,screen_lines=25): | |
1066 | """Very dumb 'pager' in Python, for when nothing else works. |
|
1055 | """Very dumb 'pager' in Python, for when nothing else works. | |
1067 |
|
1056 | |||
1068 | Only moves forward, same interface as page(), except for pager_cmd and |
|
1057 | Only moves forward, same interface as page(), except for pager_cmd and | |
1069 | mode.""" |
|
1058 | mode.""" | |
1070 |
|
1059 | |||
1071 | out_ln = strng.splitlines()[start:] |
|
1060 | out_ln = strng.splitlines()[start:] | |
1072 | screens = chop(out_ln,screen_lines-1) |
|
1061 | screens = chop(out_ln,screen_lines-1) | |
1073 | if len(screens) == 1: |
|
1062 | if len(screens) == 1: | |
1074 | print >>Term.cout, os.linesep.join(screens[0]) |
|
1063 | print >>Term.cout, os.linesep.join(screens[0]) | |
1075 | else: |
|
1064 | else: | |
1076 | for scr in screens[0:-1]: |
|
1065 | for scr in screens[0:-1]: | |
1077 | print >>Term.cout, os.linesep.join(scr) |
|
1066 | print >>Term.cout, os.linesep.join(scr) | |
1078 | ans = raw_input('---Return to continue, q to quit--- ') |
|
1067 | ans = raw_input('---Return to continue, q to quit--- ') | |
1079 | if ans.lower().startswith('q'): |
|
1068 | if ans.lower().startswith('q'): | |
1080 | return |
|
1069 | return | |
1081 | print >>Term.cout, os.linesep.join(screens[-1]) |
|
1070 | print >>Term.cout, os.linesep.join(screens[-1]) | |
1082 |
|
1071 | |||
1083 | #---------------------------------------------------------------------------- |
|
1072 | #---------------------------------------------------------------------------- | |
1084 | def page(strng,start=0,screen_lines=0,pager_cmd = None): |
|
1073 | def page(strng,start=0,screen_lines=0,pager_cmd = None): | |
1085 | """Print a string, piping through a pager after a certain length. |
|
1074 | """Print a string, piping through a pager after a certain length. | |
1086 |
|
1075 | |||
1087 | The screen_lines parameter specifies the number of *usable* lines of your |
|
1076 | The screen_lines parameter specifies the number of *usable* lines of your | |
1088 | terminal screen (total lines minus lines you need to reserve to show other |
|
1077 | terminal screen (total lines minus lines you need to reserve to show other | |
1089 | information). |
|
1078 | information). | |
1090 |
|
1079 | |||
1091 | If you set screen_lines to a number <=0, page() will try to auto-determine |
|
1080 | If you set screen_lines to a number <=0, page() will try to auto-determine | |
1092 | your screen size and will only use up to (screen_size+screen_lines) for |
|
1081 | your screen size and will only use up to (screen_size+screen_lines) for | |
1093 | printing, paging after that. That is, if you want auto-detection but need |
|
1082 | printing, paging after that. That is, if you want auto-detection but need | |
1094 | to reserve the bottom 3 lines of the screen, use screen_lines = -3, and for |
|
1083 | to reserve the bottom 3 lines of the screen, use screen_lines = -3, and for | |
1095 | auto-detection without any lines reserved simply use screen_lines = 0. |
|
1084 | auto-detection without any lines reserved simply use screen_lines = 0. | |
1096 |
|
1085 | |||
1097 | If a string won't fit in the allowed lines, it is sent through the |
|
1086 | If a string won't fit in the allowed lines, it is sent through the | |
1098 | specified pager command. If none given, look for PAGER in the environment, |
|
1087 | specified pager command. If none given, look for PAGER in the environment, | |
1099 | and ultimately default to less. |
|
1088 | and ultimately default to less. | |
1100 |
|
1089 | |||
1101 | If no system pager works, the string is sent through a 'dumb pager' |
|
1090 | If no system pager works, the string is sent through a 'dumb pager' | |
1102 | written in python, very simplistic. |
|
1091 | written in python, very simplistic. | |
1103 | """ |
|
1092 | """ | |
1104 |
|
1093 | |||
1105 | # Ugly kludge, but calling curses.initscr() flat out crashes in emacs |
|
1094 | # Ugly kludge, but calling curses.initscr() flat out crashes in emacs | |
1106 | TERM = os.environ.get('TERM','dumb') |
|
1095 | TERM = os.environ.get('TERM','dumb') | |
1107 | if TERM in ['dumb','emacs'] and os.name != 'nt': |
|
1096 | if TERM in ['dumb','emacs'] and os.name != 'nt': | |
1108 | print strng |
|
1097 | print strng | |
1109 | return |
|
1098 | return | |
1110 | # chop off the topmost part of the string we don't want to see |
|
1099 | # chop off the topmost part of the string we don't want to see | |
1111 | str_lines = strng.split(os.linesep)[start:] |
|
1100 | str_lines = strng.split(os.linesep)[start:] | |
1112 | str_toprint = os.linesep.join(str_lines) |
|
1101 | str_toprint = os.linesep.join(str_lines) | |
1113 | num_newlines = len(str_lines) |
|
1102 | num_newlines = len(str_lines) | |
1114 | len_str = len(str_toprint) |
|
1103 | len_str = len(str_toprint) | |
1115 |
|
1104 | |||
1116 | # Dumb heuristics to guesstimate number of on-screen lines the string |
|
1105 | # Dumb heuristics to guesstimate number of on-screen lines the string | |
1117 | # takes. Very basic, but good enough for docstrings in reasonable |
|
1106 | # takes. Very basic, but good enough for docstrings in reasonable | |
1118 | # terminals. If someone later feels like refining it, it's not hard. |
|
1107 | # terminals. If someone later feels like refining it, it's not hard. | |
1119 | numlines = max(num_newlines,int(len_str/80)+1) |
|
1108 | numlines = max(num_newlines,int(len_str/80)+1) | |
1120 |
|
1109 | |||
1121 | screen_lines_def = 25 # default value if we can't auto-determine |
|
1110 | screen_lines_def = 25 # default value if we can't auto-determine | |
1122 |
|
1111 | |||
1123 | # auto-determine screen size |
|
1112 | # auto-determine screen size | |
1124 | if screen_lines <= 0: |
|
1113 | if screen_lines <= 0: | |
1125 | if TERM=='xterm': |
|
1114 | if TERM=='xterm': | |
1126 | try: |
|
1115 | try: | |
1127 | import curses |
|
1116 | import curses | |
1128 | if hasattr(curses,'initscr'): |
|
1117 | if hasattr(curses,'initscr'): | |
1129 | use_curses = 1 |
|
1118 | use_curses = 1 | |
1130 | else: |
|
1119 | else: | |
1131 | use_curses = 0 |
|
1120 | use_curses = 0 | |
1132 | except ImportError: |
|
1121 | except ImportError: | |
1133 | use_curses = 0 |
|
1122 | use_curses = 0 | |
1134 | else: |
|
1123 | else: | |
1135 | # curses causes problems on many terminals other than xterm. |
|
1124 | # curses causes problems on many terminals other than xterm. | |
1136 | use_curses = 0 |
|
1125 | use_curses = 0 | |
1137 | if use_curses: |
|
1126 | if use_curses: | |
1138 | scr = curses.initscr() |
|
1127 | scr = curses.initscr() | |
1139 | screen_lines_real,screen_cols = scr.getmaxyx() |
|
1128 | screen_lines_real,screen_cols = scr.getmaxyx() | |
1140 | curses.endwin() |
|
1129 | curses.endwin() | |
1141 | screen_lines += screen_lines_real |
|
1130 | screen_lines += screen_lines_real | |
1142 | #print '***Screen size:',screen_lines_real,'lines x',\ |
|
1131 | #print '***Screen size:',screen_lines_real,'lines x',\ | |
1143 | #screen_cols,'columns.' # dbg |
|
1132 | #screen_cols,'columns.' # dbg | |
1144 | else: |
|
1133 | else: | |
1145 | screen_lines += screen_lines_def |
|
1134 | screen_lines += screen_lines_def | |
1146 |
|
1135 | |||
1147 | #print 'numlines',numlines,'screenlines',screen_lines # dbg |
|
1136 | #print 'numlines',numlines,'screenlines',screen_lines # dbg | |
1148 | if numlines <= screen_lines : |
|
1137 | if numlines <= screen_lines : | |
1149 | #print '*** normal print' # dbg |
|
1138 | #print '*** normal print' # dbg | |
1150 | print >>Term.cout, str_toprint |
|
1139 | print >>Term.cout, str_toprint | |
1151 | else: |
|
1140 | else: | |
1152 | # Try to open pager and default to internal one if that fails. |
|
1141 | # Try to open pager and default to internal one if that fails. | |
1153 | # All failure modes are tagged as 'retval=1', to match the return |
|
1142 | # All failure modes are tagged as 'retval=1', to match the return | |
1154 | # value of a failed system command. If any intermediate attempt |
|
1143 | # value of a failed system command. If any intermediate attempt | |
1155 | # sets retval to 1, at the end we resort to our own page_dumb() pager. |
|
1144 | # sets retval to 1, at the end we resort to our own page_dumb() pager. | |
1156 | pager_cmd = get_pager_cmd(pager_cmd) |
|
1145 | pager_cmd = get_pager_cmd(pager_cmd) | |
1157 | pager_cmd += ' ' + get_pager_start(pager_cmd,start) |
|
1146 | pager_cmd += ' ' + get_pager_start(pager_cmd,start) | |
1158 | if os.name == 'nt': |
|
1147 | if os.name == 'nt': | |
1159 | if pager_cmd.startswith('type'): |
|
1148 | if pager_cmd.startswith('type'): | |
1160 | # The default WinXP 'type' command is failing on complex strings. |
|
1149 | # The default WinXP 'type' command is failing on complex strings. | |
1161 | retval = 1 |
|
1150 | retval = 1 | |
1162 | else: |
|
1151 | else: | |
1163 | tmpname = tempfile.mktemp('.txt') |
|
1152 | tmpname = tempfile.mktemp('.txt') | |
1164 | tmpfile = file(tmpname,'wt') |
|
1153 | tmpfile = file(tmpname,'wt') | |
1165 | tmpfile.write(strng) |
|
1154 | tmpfile.write(strng) | |
1166 | tmpfile.close() |
|
1155 | tmpfile.close() | |
1167 | cmd = "%s < %s" % (pager_cmd,tmpname) |
|
1156 | cmd = "%s < %s" % (pager_cmd,tmpname) | |
1168 | if os.system(cmd): |
|
1157 | if os.system(cmd): | |
1169 | retval = 1 |
|
1158 | retval = 1 | |
1170 | else: |
|
1159 | else: | |
1171 | retval = None |
|
1160 | retval = None | |
1172 | os.remove(tmpname) |
|
1161 | os.remove(tmpname) | |
1173 | else: |
|
1162 | else: | |
1174 | try: |
|
1163 | try: | |
1175 | retval = None |
|
1164 | retval = None | |
1176 | # if I use popen4, things hang. No idea why. |
|
1165 | # if I use popen4, things hang. No idea why. | |
1177 | #pager,shell_out = os.popen4(pager_cmd) |
|
1166 | #pager,shell_out = os.popen4(pager_cmd) | |
1178 | pager = os.popen(pager_cmd,'w') |
|
1167 | pager = os.popen(pager_cmd,'w') | |
1179 | pager.write(strng) |
|
1168 | pager.write(strng) | |
1180 | pager.close() |
|
1169 | pager.close() | |
1181 | retval = pager.close() # success returns None |
|
1170 | retval = pager.close() # success returns None | |
1182 | except IOError,msg: # broken pipe when user quits |
|
1171 | except IOError,msg: # broken pipe when user quits | |
1183 | if msg.args == (32,'Broken pipe'): |
|
1172 | if msg.args == (32,'Broken pipe'): | |
1184 | retval = None |
|
1173 | retval = None | |
1185 | else: |
|
1174 | else: | |
1186 | retval = 1 |
|
1175 | retval = 1 | |
1187 | except OSError: |
|
1176 | except OSError: | |
1188 | # Other strange problems, sometimes seen in Win2k/cygwin |
|
1177 | # Other strange problems, sometimes seen in Win2k/cygwin | |
1189 | retval = 1 |
|
1178 | retval = 1 | |
1190 | if retval is not None: |
|
1179 | if retval is not None: | |
1191 | page_dumb(strng,screen_lines=screen_lines) |
|
1180 | page_dumb(strng,screen_lines=screen_lines) | |
1192 |
|
1181 | |||
1193 | #---------------------------------------------------------------------------- |
|
1182 | #---------------------------------------------------------------------------- | |
1194 | def page_file(fname,start = 0, pager_cmd = None): |
|
1183 | def page_file(fname,start = 0, pager_cmd = None): | |
1195 | """Page a file, using an optional pager command and starting line. |
|
1184 | """Page a file, using an optional pager command and starting line. | |
1196 | """ |
|
1185 | """ | |
1197 |
|
1186 | |||
1198 | pager_cmd = get_pager_cmd(pager_cmd) |
|
1187 | pager_cmd = get_pager_cmd(pager_cmd) | |
1199 | pager_cmd += ' ' + get_pager_start(pager_cmd,start) |
|
1188 | pager_cmd += ' ' + get_pager_start(pager_cmd,start) | |
1200 |
|
1189 | |||
1201 | try: |
|
1190 | try: | |
1202 | if os.environ['TERM'] in ['emacs','dumb']: |
|
1191 | if os.environ['TERM'] in ['emacs','dumb']: | |
1203 | raise EnvironmentError |
|
1192 | raise EnvironmentError | |
1204 | xsys(pager_cmd + ' ' + fname) |
|
1193 | xsys(pager_cmd + ' ' + fname) | |
1205 | except: |
|
1194 | except: | |
1206 | try: |
|
1195 | try: | |
1207 | if start > 0: |
|
1196 | if start > 0: | |
1208 | start -= 1 |
|
1197 | start -= 1 | |
1209 | page(open(fname).read(),start) |
|
1198 | page(open(fname).read(),start) | |
1210 | except: |
|
1199 | except: | |
1211 | print 'Unable to show file',`fname` |
|
1200 | print 'Unable to show file',`fname` | |
1212 |
|
1201 | |||
1213 | #---------------------------------------------------------------------------- |
|
1202 | #---------------------------------------------------------------------------- | |
1214 | def snip_print(str,width = 75,print_full = 0,header = ''): |
|
1203 | def snip_print(str,width = 75,print_full = 0,header = ''): | |
1215 | """Print a string snipping the midsection to fit in width. |
|
1204 | """Print a string snipping the midsection to fit in width. | |
1216 |
|
1205 | |||
1217 | print_full: mode control: |
|
1206 | print_full: mode control: | |
1218 | - 0: only snip long strings |
|
1207 | - 0: only snip long strings | |
1219 | - 1: send to page() directly. |
|
1208 | - 1: send to page() directly. | |
1220 | - 2: snip long strings and ask for full length viewing with page() |
|
1209 | - 2: snip long strings and ask for full length viewing with page() | |
1221 | Return 1 if snipping was necessary, 0 otherwise.""" |
|
1210 | Return 1 if snipping was necessary, 0 otherwise.""" | |
1222 |
|
1211 | |||
1223 | if print_full == 1: |
|
1212 | if print_full == 1: | |
1224 | page(header+str) |
|
1213 | page(header+str) | |
1225 | return 0 |
|
1214 | return 0 | |
1226 |
|
1215 | |||
1227 | print header, |
|
1216 | print header, | |
1228 | if len(str) < width: |
|
1217 | if len(str) < width: | |
1229 | print str |
|
1218 | print str | |
1230 | snip = 0 |
|
1219 | snip = 0 | |
1231 | else: |
|
1220 | else: | |
1232 | whalf = int((width -5)/2) |
|
1221 | whalf = int((width -5)/2) | |
1233 | print str[:whalf] + ' <...> ' + str[-whalf:] |
|
1222 | print str[:whalf] + ' <...> ' + str[-whalf:] | |
1234 | snip = 1 |
|
1223 | snip = 1 | |
1235 | if snip and print_full == 2: |
|
1224 | if snip and print_full == 2: | |
1236 | if raw_input(header+' Snipped. View (y/n)? [N]').lower() == 'y': |
|
1225 | if raw_input(header+' Snipped. View (y/n)? [N]').lower() == 'y': | |
1237 | page(str) |
|
1226 | page(str) | |
1238 | return snip |
|
1227 | return snip | |
1239 |
|
1228 | |||
1240 | #**************************************************************************** |
|
1229 | #**************************************************************************** | |
1241 | # lists, dicts and structures |
|
1230 | # lists, dicts and structures | |
1242 |
|
1231 | |||
1243 | def belong(candidates,checklist): |
|
1232 | def belong(candidates,checklist): | |
1244 | """Check whether a list of items appear in a given list of options. |
|
1233 | """Check whether a list of items appear in a given list of options. | |
1245 |
|
1234 | |||
1246 | Returns a list of 1 and 0, one for each candidate given.""" |
|
1235 | Returns a list of 1 and 0, one for each candidate given.""" | |
1247 |
|
1236 | |||
1248 | return [x in checklist for x in candidates] |
|
1237 | return [x in checklist for x in candidates] | |
1249 |
|
1238 | |||
1250 | #---------------------------------------------------------------------------- |
|
1239 | #---------------------------------------------------------------------------- | |
1251 | def uniq_stable(elems): |
|
1240 | def uniq_stable(elems): | |
1252 | """uniq_stable(elems) -> list |
|
1241 | """uniq_stable(elems) -> list | |
1253 |
|
1242 | |||
1254 | Return from an iterable, a list of all the unique elements in the input, |
|
1243 | Return from an iterable, a list of all the unique elements in the input, | |
1255 | but maintaining the order in which they first appear. |
|
1244 | but maintaining the order in which they first appear. | |
1256 |
|
1245 | |||
1257 | A naive solution to this problem which just makes a dictionary with the |
|
1246 | A naive solution to this problem which just makes a dictionary with the | |
1258 | elements as keys fails to respect the stability condition, since |
|
1247 | elements as keys fails to respect the stability condition, since | |
1259 | dictionaries are unsorted by nature. |
|
1248 | dictionaries are unsorted by nature. | |
1260 |
|
1249 | |||
1261 | Note: All elements in the input must be valid dictionary keys for this |
|
1250 | Note: All elements in the input must be valid dictionary keys for this | |
1262 | routine to work, as it internally uses a dictionary for efficiency |
|
1251 | routine to work, as it internally uses a dictionary for efficiency | |
1263 | reasons.""" |
|
1252 | reasons.""" | |
1264 |
|
1253 | |||
1265 | unique = [] |
|
1254 | unique = [] | |
1266 | unique_dict = {} |
|
1255 | unique_dict = {} | |
1267 | for nn in elems: |
|
1256 | for nn in elems: | |
1268 | if nn not in unique_dict: |
|
1257 | if nn not in unique_dict: | |
1269 | unique.append(nn) |
|
1258 | unique.append(nn) | |
1270 | unique_dict[nn] = None |
|
1259 | unique_dict[nn] = None | |
1271 | return unique |
|
1260 | return unique | |
1272 |
|
1261 | |||
1273 | #---------------------------------------------------------------------------- |
|
1262 | #---------------------------------------------------------------------------- | |
1274 | class NLprinter: |
|
1263 | class NLprinter: | |
1275 | """Print an arbitrarily nested list, indicating index numbers. |
|
1264 | """Print an arbitrarily nested list, indicating index numbers. | |
1276 |
|
1265 | |||
1277 | An instance of this class called nlprint is available and callable as a |
|
1266 | An instance of this class called nlprint is available and callable as a | |
1278 | function. |
|
1267 | function. | |
1279 |
|
1268 | |||
1280 | nlprint(list,indent=' ',sep=': ') -> prints indenting each level by 'indent' |
|
1269 | nlprint(list,indent=' ',sep=': ') -> prints indenting each level by 'indent' | |
1281 | and using 'sep' to separate the index from the value. """ |
|
1270 | and using 'sep' to separate the index from the value. """ | |
1282 |
|
1271 | |||
1283 | def __init__(self): |
|
1272 | def __init__(self): | |
1284 | self.depth = 0 |
|
1273 | self.depth = 0 | |
1285 |
|
1274 | |||
1286 | def __call__(self,lst,pos='',**kw): |
|
1275 | def __call__(self,lst,pos='',**kw): | |
1287 | """Prints the nested list numbering levels.""" |
|
1276 | """Prints the nested list numbering levels.""" | |
1288 | kw.setdefault('indent',' ') |
|
1277 | kw.setdefault('indent',' ') | |
1289 | kw.setdefault('sep',': ') |
|
1278 | kw.setdefault('sep',': ') | |
1290 | kw.setdefault('start',0) |
|
1279 | kw.setdefault('start',0) | |
1291 | kw.setdefault('stop',len(lst)) |
|
1280 | kw.setdefault('stop',len(lst)) | |
1292 | # we need to remove start and stop from kw so they don't propagate |
|
1281 | # we need to remove start and stop from kw so they don't propagate | |
1293 | # into a recursive call for a nested list. |
|
1282 | # into a recursive call for a nested list. | |
1294 | start = kw['start']; del kw['start'] |
|
1283 | start = kw['start']; del kw['start'] | |
1295 | stop = kw['stop']; del kw['stop'] |
|
1284 | stop = kw['stop']; del kw['stop'] | |
1296 | if self.depth == 0 and 'header' in kw.keys(): |
|
1285 | if self.depth == 0 and 'header' in kw.keys(): | |
1297 | print kw['header'] |
|
1286 | print kw['header'] | |
1298 |
|
1287 | |||
1299 | for idx in range(start,stop): |
|
1288 | for idx in range(start,stop): | |
1300 | elem = lst[idx] |
|
1289 | elem = lst[idx] | |
1301 | if type(elem)==type([]): |
|
1290 | if type(elem)==type([]): | |
1302 | self.depth += 1 |
|
1291 | self.depth += 1 | |
1303 | self.__call__(elem,itpl('$pos$idx,'),**kw) |
|
1292 | self.__call__(elem,itpl('$pos$idx,'),**kw) | |
1304 | self.depth -= 1 |
|
1293 | self.depth -= 1 | |
1305 | else: |
|
1294 | else: | |
1306 | printpl(kw['indent']*self.depth+'$pos$idx$kw["sep"]$elem') |
|
1295 | printpl(kw['indent']*self.depth+'$pos$idx$kw["sep"]$elem') | |
1307 |
|
1296 | |||
1308 | nlprint = NLprinter() |
|
1297 | nlprint = NLprinter() | |
1309 | #---------------------------------------------------------------------------- |
|
1298 | #---------------------------------------------------------------------------- | |
1310 | def all_belong(candidates,checklist): |
|
1299 | def all_belong(candidates,checklist): | |
1311 | """Check whether a list of items ALL appear in a given list of options. |
|
1300 | """Check whether a list of items ALL appear in a given list of options. | |
1312 |
|
1301 | |||
1313 | Returns a single 1 or 0 value.""" |
|
1302 | Returns a single 1 or 0 value.""" | |
1314 |
|
1303 | |||
1315 | return 1-(0 in [x in checklist for x in candidates]) |
|
1304 | return 1-(0 in [x in checklist for x in candidates]) | |
1316 |
|
1305 | |||
1317 | #---------------------------------------------------------------------------- |
|
1306 | #---------------------------------------------------------------------------- | |
1318 | def sort_compare(lst1,lst2,inplace = 1): |
|
1307 | def sort_compare(lst1,lst2,inplace = 1): | |
1319 | """Sort and compare two lists. |
|
1308 | """Sort and compare two lists. | |
1320 |
|
1309 | |||
1321 | By default it does it in place, thus modifying the lists. Use inplace = 0 |
|
1310 | By default it does it in place, thus modifying the lists. Use inplace = 0 | |
1322 | to avoid that (at the cost of temporary copy creation).""" |
|
1311 | to avoid that (at the cost of temporary copy creation).""" | |
1323 | if not inplace: |
|
1312 | if not inplace: | |
1324 | lst1 = lst1[:] |
|
1313 | lst1 = lst1[:] | |
1325 | lst2 = lst2[:] |
|
1314 | lst2 = lst2[:] | |
1326 | lst1.sort(); lst2.sort() |
|
1315 | lst1.sort(); lst2.sort() | |
1327 | return lst1 == lst2 |
|
1316 | return lst1 == lst2 | |
1328 |
|
1317 | |||
1329 | #---------------------------------------------------------------------------- |
|
1318 | #---------------------------------------------------------------------------- | |
1330 | def mkdict(**kwargs): |
|
1319 | def mkdict(**kwargs): | |
1331 | """Return a dict from a keyword list. |
|
1320 | """Return a dict from a keyword list. | |
1332 |
|
1321 | |||
1333 | It's just syntactic sugar for making ditcionary creation more convenient: |
|
1322 | It's just syntactic sugar for making ditcionary creation more convenient: | |
1334 | # the standard way |
|
1323 | # the standard way | |
1335 | >>>data = { 'red' : 1, 'green' : 2, 'blue' : 3 } |
|
1324 | >>>data = { 'red' : 1, 'green' : 2, 'blue' : 3 } | |
1336 | # a cleaner way |
|
1325 | # a cleaner way | |
1337 | >>>data = dict(red=1, green=2, blue=3) |
|
1326 | >>>data = dict(red=1, green=2, blue=3) | |
1338 |
|
1327 | |||
1339 | If you need more than this, look at the Struct() class.""" |
|
1328 | If you need more than this, look at the Struct() class.""" | |
1340 |
|
1329 | |||
1341 | return kwargs |
|
1330 | return kwargs | |
1342 |
|
1331 | |||
1343 | #---------------------------------------------------------------------------- |
|
1332 | #---------------------------------------------------------------------------- | |
1344 | def list2dict(lst): |
|
1333 | def list2dict(lst): | |
1345 | """Takes a list of (key,value) pairs and turns it into a dict.""" |
|
1334 | """Takes a list of (key,value) pairs and turns it into a dict.""" | |
1346 |
|
1335 | |||
1347 | dic = {} |
|
1336 | dic = {} | |
1348 | for k,v in lst: dic[k] = v |
|
1337 | for k,v in lst: dic[k] = v | |
1349 | return dic |
|
1338 | return dic | |
1350 |
|
1339 | |||
1351 | #---------------------------------------------------------------------------- |
|
1340 | #---------------------------------------------------------------------------- | |
1352 | def list2dict2(lst,default=''): |
|
1341 | def list2dict2(lst,default=''): | |
1353 | """Takes a list and turns it into a dict. |
|
1342 | """Takes a list and turns it into a dict. | |
1354 | Much slower than list2dict, but more versatile. This version can take |
|
1343 | Much slower than list2dict, but more versatile. This version can take | |
1355 | lists with sublists of arbitrary length (including sclars).""" |
|
1344 | lists with sublists of arbitrary length (including sclars).""" | |
1356 |
|
1345 | |||
1357 | dic = {} |
|
1346 | dic = {} | |
1358 | for elem in lst: |
|
1347 | for elem in lst: | |
1359 | if type(elem) in (types.ListType,types.TupleType): |
|
1348 | if type(elem) in (types.ListType,types.TupleType): | |
1360 | size = len(elem) |
|
1349 | size = len(elem) | |
1361 | if size == 0: |
|
1350 | if size == 0: | |
1362 | pass |
|
1351 | pass | |
1363 | elif size == 1: |
|
1352 | elif size == 1: | |
1364 | dic[elem] = default |
|
1353 | dic[elem] = default | |
1365 | else: |
|
1354 | else: | |
1366 | k,v = elem[0], elem[1:] |
|
1355 | k,v = elem[0], elem[1:] | |
1367 | if len(v) == 1: v = v[0] |
|
1356 | if len(v) == 1: v = v[0] | |
1368 | dic[k] = v |
|
1357 | dic[k] = v | |
1369 | else: |
|
1358 | else: | |
1370 | dic[elem] = default |
|
1359 | dic[elem] = default | |
1371 | return dic |
|
1360 | return dic | |
1372 |
|
1361 | |||
1373 | #---------------------------------------------------------------------------- |
|
1362 | #---------------------------------------------------------------------------- | |
1374 | def flatten(seq): |
|
1363 | def flatten(seq): | |
1375 | """Flatten a list of lists (NOT recursive, only works for 2d lists).""" |
|
1364 | """Flatten a list of lists (NOT recursive, only works for 2d lists).""" | |
1376 |
|
1365 | |||
1377 | # bug in python??? (YES. Fixed in 2.2, let's leave the kludgy fix in). |
|
1366 | # bug in python??? (YES. Fixed in 2.2, let's leave the kludgy fix in). | |
1378 |
|
1367 | |||
1379 | # if the x=0 isn't made, a *global* variable x is left over after calling |
|
1368 | # if the x=0 isn't made, a *global* variable x is left over after calling | |
1380 | # this function, with the value of the last element in the return |
|
1369 | # this function, with the value of the last element in the return | |
1381 | # list. This does seem like a bug big time to me. |
|
1370 | # list. This does seem like a bug big time to me. | |
1382 |
|
1371 | |||
1383 | # the problem is fixed with the x=0, which seems to force the creation of |
|
1372 | # the problem is fixed with the x=0, which seems to force the creation of | |
1384 | # a local name |
|
1373 | # a local name | |
1385 |
|
1374 | |||
1386 | x = 0 |
|
1375 | x = 0 | |
1387 | return [x for subseq in seq for x in subseq] |
|
1376 | return [x for subseq in seq for x in subseq] | |
1388 |
|
1377 | |||
1389 | #---------------------------------------------------------------------------- |
|
1378 | #---------------------------------------------------------------------------- | |
1390 | def get_slice(seq,start=0,stop=None,step=1): |
|
1379 | def get_slice(seq,start=0,stop=None,step=1): | |
1391 | """Get a slice of a sequence with variable step. Specify start,stop,step.""" |
|
1380 | """Get a slice of a sequence with variable step. Specify start,stop,step.""" | |
1392 | if stop == None: |
|
1381 | if stop == None: | |
1393 | stop = len(seq) |
|
1382 | stop = len(seq) | |
1394 | item = lambda i: seq[i] |
|
1383 | item = lambda i: seq[i] | |
1395 | return map(item,xrange(start,stop,step)) |
|
1384 | return map(item,xrange(start,stop,step)) | |
1396 |
|
1385 | |||
1397 | #---------------------------------------------------------------------------- |
|
1386 | #---------------------------------------------------------------------------- | |
1398 | def chop(seq,size): |
|
1387 | def chop(seq,size): | |
1399 | """Chop a sequence into chunks of the given size.""" |
|
1388 | """Chop a sequence into chunks of the given size.""" | |
1400 | chunk = lambda i: seq[i:i+size] |
|
1389 | chunk = lambda i: seq[i:i+size] | |
1401 | return map(chunk,xrange(0,len(seq),size)) |
|
1390 | return map(chunk,xrange(0,len(seq),size)) | |
1402 |
|
1391 | |||
1403 | #---------------------------------------------------------------------------- |
|
1392 | #---------------------------------------------------------------------------- | |
1404 | def with(object, **args): |
|
1393 | def with(object, **args): | |
1405 | """Set multiple attributes for an object, similar to Pascal's with. |
|
1394 | """Set multiple attributes for an object, similar to Pascal's with. | |
1406 |
|
1395 | |||
1407 | Example: |
|
1396 | Example: | |
1408 | with(jim, |
|
1397 | with(jim, | |
1409 | born = 1960, |
|
1398 | born = 1960, | |
1410 | haircolour = 'Brown', |
|
1399 | haircolour = 'Brown', | |
1411 | eyecolour = 'Green') |
|
1400 | eyecolour = 'Green') | |
1412 |
|
1401 | |||
1413 | Credit: Greg Ewing, in |
|
1402 | Credit: Greg Ewing, in | |
1414 | http://mail.python.org/pipermail/python-list/2001-May/040703.html""" |
|
1403 | http://mail.python.org/pipermail/python-list/2001-May/040703.html""" | |
1415 |
|
1404 | |||
1416 | object.__dict__.update(args) |
|
1405 | object.__dict__.update(args) | |
1417 |
|
1406 | |||
1418 | #---------------------------------------------------------------------------- |
|
1407 | #---------------------------------------------------------------------------- | |
1419 | def setattr_list(obj,alist,nspace = None): |
|
1408 | def setattr_list(obj,alist,nspace = None): | |
1420 | """Set a list of attributes for an object taken from a namespace. |
|
1409 | """Set a list of attributes for an object taken from a namespace. | |
1421 |
|
1410 | |||
1422 | setattr_list(obj,alist,nspace) -> sets in obj all the attributes listed in |
|
1411 | setattr_list(obj,alist,nspace) -> sets in obj all the attributes listed in | |
1423 | alist with their values taken from nspace, which must be a dict (something |
|
1412 | alist with their values taken from nspace, which must be a dict (something | |
1424 | like locals() will often do) If nspace isn't given, locals() of the |
|
1413 | like locals() will often do) If nspace isn't given, locals() of the | |
1425 | *caller* is used, so in most cases you can omit it. |
|
1414 | *caller* is used, so in most cases you can omit it. | |
1426 |
|
1415 | |||
1427 | Note that alist can be given as a string, which will be automatically |
|
1416 | Note that alist can be given as a string, which will be automatically | |
1428 | split into a list on whitespace. If given as a list, it must be a list of |
|
1417 | split into a list on whitespace. If given as a list, it must be a list of | |
1429 | *strings* (the variable names themselves), not of variables.""" |
|
1418 | *strings* (the variable names themselves), not of variables.""" | |
1430 |
|
1419 | |||
1431 | # this grabs the local variables from the *previous* call frame -- that is |
|
1420 | # this grabs the local variables from the *previous* call frame -- that is | |
1432 | # the locals from the function that called setattr_list(). |
|
1421 | # the locals from the function that called setattr_list(). | |
1433 | # - snipped from weave.inline() |
|
1422 | # - snipped from weave.inline() | |
1434 | if nspace is None: |
|
1423 | if nspace is None: | |
1435 | call_frame = sys._getframe().f_back |
|
1424 | call_frame = sys._getframe().f_back | |
1436 | nspace = call_frame.f_locals |
|
1425 | nspace = call_frame.f_locals | |
1437 |
|
1426 | |||
1438 | if type(alist) in StringTypes: |
|
1427 | if type(alist) in StringTypes: | |
1439 | alist = alist.split() |
|
1428 | alist = alist.split() | |
1440 | for attr in alist: |
|
1429 | for attr in alist: | |
1441 | val = eval(attr,nspace) |
|
1430 | val = eval(attr,nspace) | |
1442 | setattr(obj,attr,val) |
|
1431 | setattr(obj,attr,val) | |
1443 |
|
1432 | |||
1444 | #---------------------------------------------------------------------------- |
|
1433 | #---------------------------------------------------------------------------- | |
1445 | def getattr_list(obj,alist,*args): |
|
1434 | def getattr_list(obj,alist,*args): | |
1446 | """getattr_list(obj,alist[, default]) -> attribute list. |
|
1435 | """getattr_list(obj,alist[, default]) -> attribute list. | |
1447 |
|
1436 | |||
1448 | Get a list of named attributes for an object. When a default argument is |
|
1437 | Get a list of named attributes for an object. When a default argument is | |
1449 | given, it is returned when the attribute doesn't exist; without it, an |
|
1438 | given, it is returned when the attribute doesn't exist; without it, an | |
1450 | exception is raised in that case. |
|
1439 | exception is raised in that case. | |
1451 |
|
1440 | |||
1452 | Note that alist can be given as a string, which will be automatically |
|
1441 | Note that alist can be given as a string, which will be automatically | |
1453 | split into a list on whitespace. If given as a list, it must be a list of |
|
1442 | split into a list on whitespace. If given as a list, it must be a list of | |
1454 | *strings* (the variable names themselves), not of variables.""" |
|
1443 | *strings* (the variable names themselves), not of variables.""" | |
1455 |
|
1444 | |||
1456 | if type(alist) in StringTypes: |
|
1445 | if type(alist) in StringTypes: | |
1457 | alist = alist.split() |
|
1446 | alist = alist.split() | |
1458 | if args: |
|
1447 | if args: | |
1459 | if len(args)==1: |
|
1448 | if len(args)==1: | |
1460 | default = args[0] |
|
1449 | default = args[0] | |
1461 | return map(lambda attr: getattr(obj,attr,default),alist) |
|
1450 | return map(lambda attr: getattr(obj,attr,default),alist) | |
1462 | else: |
|
1451 | else: | |
1463 | raise ValueError,'getattr_list() takes only one optional argument' |
|
1452 | raise ValueError,'getattr_list() takes only one optional argument' | |
1464 | else: |
|
1453 | else: | |
1465 | return map(lambda attr: getattr(obj,attr),alist) |
|
1454 | return map(lambda attr: getattr(obj,attr),alist) | |
1466 |
|
1455 | |||
1467 | #---------------------------------------------------------------------------- |
|
1456 | #---------------------------------------------------------------------------- | |
1468 | def map_method(method,object_list,*argseq,**kw): |
|
1457 | def map_method(method,object_list,*argseq,**kw): | |
1469 | """map_method(method,object_list,*args,**kw) -> list |
|
1458 | """map_method(method,object_list,*args,**kw) -> list | |
1470 |
|
1459 | |||
1471 | Return a list of the results of applying the methods to the items of the |
|
1460 | Return a list of the results of applying the methods to the items of the | |
1472 | argument sequence(s). If more than one sequence is given, the method is |
|
1461 | argument sequence(s). If more than one sequence is given, the method is | |
1473 | called with an argument list consisting of the corresponding item of each |
|
1462 | called with an argument list consisting of the corresponding item of each | |
1474 | sequence. All sequences must be of the same length. |
|
1463 | sequence. All sequences must be of the same length. | |
1475 |
|
1464 | |||
1476 | Keyword arguments are passed verbatim to all objects called. |
|
1465 | Keyword arguments are passed verbatim to all objects called. | |
1477 |
|
1466 | |||
1478 | This is Python code, so it's not nearly as fast as the builtin map().""" |
|
1467 | This is Python code, so it's not nearly as fast as the builtin map().""" | |
1479 |
|
1468 | |||
1480 | out_list = [] |
|
1469 | out_list = [] | |
1481 | idx = 0 |
|
1470 | idx = 0 | |
1482 | for object in object_list: |
|
1471 | for object in object_list: | |
1483 | try: |
|
1472 | try: | |
1484 | handler = getattr(object, method) |
|
1473 | handler = getattr(object, method) | |
1485 | except AttributeError: |
|
1474 | except AttributeError: | |
1486 | out_list.append(None) |
|
1475 | out_list.append(None) | |
1487 | else: |
|
1476 | else: | |
1488 | if argseq: |
|
1477 | if argseq: | |
1489 | args = map(lambda lst:lst[idx],argseq) |
|
1478 | args = map(lambda lst:lst[idx],argseq) | |
1490 | #print 'ob',object,'hand',handler,'ar',args # dbg |
|
1479 | #print 'ob',object,'hand',handler,'ar',args # dbg | |
1491 | out_list.append(handler(args,**kw)) |
|
1480 | out_list.append(handler(args,**kw)) | |
1492 | else: |
|
1481 | else: | |
1493 | out_list.append(handler(**kw)) |
|
1482 | out_list.append(handler(**kw)) | |
1494 | idx += 1 |
|
1483 | idx += 1 | |
1495 | return out_list |
|
1484 | return out_list | |
1496 |
|
1485 | |||
1497 | #---------------------------------------------------------------------------- |
|
1486 | #---------------------------------------------------------------------------- | |
1498 | # Proposed popitem() extension, written as a method |
|
1487 | # Proposed popitem() extension, written as a method | |
1499 |
|
1488 | |||
1500 | class NotGiven: pass |
|
1489 | class NotGiven: pass | |
1501 |
|
1490 | |||
1502 | def popkey(dct,key,default=NotGiven): |
|
1491 | def popkey(dct,key,default=NotGiven): | |
1503 | """Return dct[key] and delete dct[key]. |
|
1492 | """Return dct[key] and delete dct[key]. | |
1504 |
|
1493 | |||
1505 | If default is given, return it if dct[key] doesn't exist, otherwise raise |
|
1494 | If default is given, return it if dct[key] doesn't exist, otherwise raise | |
1506 | KeyError. """ |
|
1495 | KeyError. """ | |
1507 |
|
1496 | |||
1508 | try: |
|
1497 | try: | |
1509 | val = dct[key] |
|
1498 | val = dct[key] | |
1510 | except KeyError: |
|
1499 | except KeyError: | |
1511 | if default is NotGiven: |
|
1500 | if default is NotGiven: | |
1512 | raise |
|
1501 | raise | |
1513 | else: |
|
1502 | else: | |
1514 | return default |
|
1503 | return default | |
1515 | else: |
|
1504 | else: | |
1516 | del dct[key] |
|
1505 | del dct[key] | |
1517 | return val |
|
1506 | return val | |
1518 | #*************************** end of file <genutils.py> ********************** |
|
1507 | #*************************** end of file <genutils.py> ********************** | |
1519 |
|
1508 |
@@ -1,2084 +1,1999 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """ |
|
2 | """ | |
3 | IPython -- An enhanced Interactive Python |
|
3 | IPython -- An enhanced Interactive Python | |
4 |
|
4 | |||
5 | Requires Python 2.1 or newer. |
|
5 | Requires Python 2.1 or newer. | |
6 |
|
6 | |||
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. | |
8 |
|
8 | |||
9 |
$Id: iplib.py 6 |
|
9 | $Id: iplib.py 638 2005-07-18 03:01:41Z fperez $ | |
10 | """ |
|
10 | """ | |
11 |
|
11 | |||
12 | #***************************************************************************** |
|
12 | #***************************************************************************** | |
13 | # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and |
|
13 | # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and | |
14 | # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu> |
|
14 | # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu> | |
15 | # |
|
15 | # | |
16 | # Distributed under the terms of the BSD License. The full license is in |
|
16 | # Distributed under the terms of the BSD License. The full license is in | |
17 | # the file COPYING, distributed as part of this software. |
|
17 | # the file COPYING, distributed as part of this software. | |
18 | # |
|
18 | # | |
19 | # Note: this code originally subclassed code.InteractiveConsole from the |
|
19 | # Note: this code originally subclassed code.InteractiveConsole from the | |
20 | # Python standard library. Over time, much of that class has been copied |
|
20 | # Python standard library. Over time, much of that class has been copied | |
21 | # verbatim here for modifications which could not be accomplished by |
|
21 | # verbatim here for modifications which could not be accomplished by | |
22 | # subclassing. The Python License (sec. 2) allows for this, but it's always |
|
22 | # subclassing. The Python License (sec. 2) allows for this, but it's always | |
23 | # nice to acknowledge credit where credit is due. |
|
23 | # nice to acknowledge credit where credit is due. | |
24 | #***************************************************************************** |
|
24 | #***************************************************************************** | |
25 |
|
25 | |||
26 | #**************************************************************************** |
|
26 | #**************************************************************************** | |
27 | # Modules and globals |
|
27 | # Modules and globals | |
28 |
|
28 | |||
29 | from __future__ import generators # for 2.2 backwards-compatibility |
|
29 | from __future__ import generators # for 2.2 backwards-compatibility | |
30 |
|
30 | |||
31 | from IPython import Release |
|
31 | from IPython import Release | |
32 | __author__ = '%s <%s>\n%s <%s>' % \ |
|
32 | __author__ = '%s <%s>\n%s <%s>' % \ | |
33 | ( Release.authors['Janko'] + Release.authors['Fernando'] ) |
|
33 | ( Release.authors['Janko'] + Release.authors['Fernando'] ) | |
34 | __license__ = Release.license |
|
34 | __license__ = Release.license | |
35 | __version__ = Release.version |
|
35 | __version__ = Release.version | |
36 |
|
36 | |||
37 | # Python standard modules |
|
37 | # Python standard modules | |
38 | import __main__ |
|
38 | import __main__ | |
39 | import __builtin__ |
|
39 | import __builtin__ | |
40 | import exceptions |
|
40 | import exceptions | |
41 | import keyword |
|
41 | import keyword | |
42 | import new |
|
42 | import new | |
43 | import os, sys, shutil |
|
43 | import os, sys, shutil | |
44 | import code, glob, types, re |
|
44 | import code, glob, types, re | |
45 | import string, StringIO |
|
45 | import string, StringIO | |
46 | import inspect, pydoc |
|
46 | import inspect, pydoc | |
47 | import bdb, pdb |
|
47 | import bdb, pdb | |
48 | import UserList # don't subclass list so this works with Python2.1 |
|
48 | import UserList # don't subclass list so this works with Python2.1 | |
49 | from pprint import pprint, pformat |
|
49 | from pprint import pprint, pformat | |
50 | import cPickle as pickle |
|
50 | import cPickle as pickle | |
51 | import traceback |
|
51 | import traceback | |
52 |
|
52 | |||
53 | # IPython's own modules |
|
53 | # IPython's own modules | |
54 | import IPython |
|
54 | import IPython | |
55 | from IPython import OInspect,PyColorize,ultraTB |
|
55 | from IPython import OInspect,PyColorize,ultraTB | |
56 | from IPython.ultraTB import ColorScheme,ColorSchemeTable # too long names |
|
56 | from IPython.ultraTB import ColorScheme,ColorSchemeTable # too long names | |
57 | from IPython.Logger import Logger |
|
57 | from IPython.Logger import Logger | |
58 | from IPython.Magic import Magic,magic2python,shlex_split |
|
58 | from IPython.Magic import Magic,magic2python,shlex_split | |
59 | from IPython.usage import cmd_line_usage,interactive_usage |
|
59 | from IPython.usage import cmd_line_usage,interactive_usage | |
60 | from IPython.Struct import Struct |
|
60 | from IPython.Struct import Struct | |
61 | from IPython.Itpl import Itpl,itpl,printpl,ItplNS,itplns |
|
61 | from IPython.Itpl import Itpl,itpl,printpl,ItplNS,itplns | |
62 | from IPython.FakeModule import FakeModule |
|
62 | from IPython.FakeModule import FakeModule | |
63 | from IPython.background_jobs import BackgroundJobManager |
|
63 | from IPython.background_jobs import BackgroundJobManager | |
64 | from IPython.genutils import * |
|
64 | from IPython.genutils import * | |
65 |
|
65 | |||
66 | # Global pointer to the running |
|
66 | # Global pointer to the running | |
67 |
|
67 | |||
68 | # store the builtin raw_input globally, and use this always, in case user code |
|
68 | # store the builtin raw_input globally, and use this always, in case user code | |
69 | # overwrites it (like wx.py.PyShell does) |
|
69 | # overwrites it (like wx.py.PyShell does) | |
70 | raw_input_original = raw_input |
|
70 | raw_input_original = raw_input | |
71 |
|
71 | |||
72 | # declares Python 2.2 compatibility symbols: |
|
|||
73 | try: |
|
|||
74 | enumerate |
|
|||
75 | except NameError: |
|
|||
76 | def enumerate(obj): |
|
|||
77 | i = -1 |
|
|||
78 | for item in obj: |
|
|||
79 | i += 1 |
|
|||
80 | yield i, item |
|
|||
81 | #**************************************************************************** |
|
72 | #**************************************************************************** | |
82 | # Some utility function definitions |
|
73 | # Some utility function definitions | |
83 |
|
74 | |||
84 | class Bunch: pass |
|
75 | class Bunch: pass | |
85 |
|
76 | |||
86 | def esc_quotes(strng): |
|
77 | def esc_quotes(strng): | |
87 | """Return the input string with single and double quotes escaped out""" |
|
78 | """Return the input string with single and double quotes escaped out""" | |
88 |
|
79 | |||
89 | return strng.replace('"','\\"').replace("'","\\'") |
|
80 | return strng.replace('"','\\"').replace("'","\\'") | |
90 |
|
81 | |||
91 | def import_fail_info(mod_name,fns=None): |
|
82 | def import_fail_info(mod_name,fns=None): | |
92 | """Inform load failure for a module.""" |
|
83 | """Inform load failure for a module.""" | |
93 |
|
84 | |||
94 | if fns == None: |
|
85 | if fns == None: | |
95 | warn("Loading of %s failed.\n" % (mod_name,)) |
|
86 | warn("Loading of %s failed.\n" % (mod_name,)) | |
96 | else: |
|
87 | else: | |
97 | warn("Loading of %s from %s failed.\n" % (fns,mod_name)) |
|
88 | warn("Loading of %s from %s failed.\n" % (fns,mod_name)) | |
98 |
|
89 | |||
99 | def qw_lol(indata): |
|
90 | def qw_lol(indata): | |
100 | """qw_lol('a b') -> [['a','b']], |
|
91 | """qw_lol('a b') -> [['a','b']], | |
101 | otherwise it's just a call to qw(). |
|
92 | otherwise it's just a call to qw(). | |
102 |
|
93 | |||
103 | We need this to make sure the modules_some keys *always* end up as a |
|
94 | We need this to make sure the modules_some keys *always* end up as a | |
104 | list of lists.""" |
|
95 | list of lists.""" | |
105 |
|
96 | |||
106 | if type(indata) in StringTypes: |
|
97 | if type(indata) in StringTypes: | |
107 | return [qw(indata)] |
|
98 | return [qw(indata)] | |
108 | else: |
|
99 | else: | |
109 | return qw(indata) |
|
100 | return qw(indata) | |
110 |
|
101 | |||
111 | def ipmagic(arg_s): |
|
102 | def ipmagic(arg_s): | |
112 | """Call a magic function by name. |
|
103 | """Call a magic function by name. | |
113 |
|
104 | |||
114 | Input: a string containing the name of the magic function to call and any |
|
105 | Input: a string containing the name of the magic function to call and any | |
115 | additional arguments to be passed to the magic. |
|
106 | additional arguments to be passed to the magic. | |
116 |
|
107 | |||
117 | ipmagic('name -opt foo bar') is equivalent to typing at the ipython |
|
108 | ipmagic('name -opt foo bar') is equivalent to typing at the ipython | |
118 | prompt: |
|
109 | prompt: | |
119 |
|
110 | |||
120 | In[1]: %name -opt foo bar |
|
111 | In[1]: %name -opt foo bar | |
121 |
|
112 | |||
122 | To call a magic without arguments, simply use ipmagic('name'). |
|
113 | To call a magic without arguments, simply use ipmagic('name'). | |
123 |
|
114 | |||
124 | This provides a proper Python function to call IPython's magics in any |
|
115 | This provides a proper Python function to call IPython's magics in any | |
125 | valid Python code you can type at the interpreter, including loops and |
|
116 | valid Python code you can type at the interpreter, including loops and | |
126 | compound statements. It is added by IPython to the Python builtin |
|
117 | compound statements. It is added by IPython to the Python builtin | |
127 | namespace upon initialization.""" |
|
118 | namespace upon initialization.""" | |
128 |
|
119 | |||
129 | args = arg_s.split(' ',1) |
|
120 | args = arg_s.split(' ',1) | |
130 | magic_name = args[0] |
|
121 | magic_name = args[0] | |
131 | if magic_name.startswith(__IPYTHON__.ESC_MAGIC): |
|
122 | if magic_name.startswith(__IPYTHON__.ESC_MAGIC): | |
132 | magic_name = magic_name[1:] |
|
123 | magic_name = magic_name[1:] | |
133 | try: |
|
124 | try: | |
134 | magic_args = args[1] |
|
125 | magic_args = args[1] | |
135 | except IndexError: |
|
126 | except IndexError: | |
136 | magic_args = '' |
|
127 | magic_args = '' | |
137 | fn = getattr(__IPYTHON__,'magic_'+magic_name,None) |
|
128 | fn = getattr(__IPYTHON__,'magic_'+magic_name,None) | |
138 | if fn is None: |
|
129 | if fn is None: | |
139 | error("Magic function `%s` not found." % magic_name) |
|
130 | error("Magic function `%s` not found." % magic_name) | |
140 | else: |
|
131 | else: | |
141 | magic_args = __IPYTHON__.var_expand(magic_args) |
|
132 | magic_args = __IPYTHON__.var_expand(magic_args) | |
142 | return fn(magic_args) |
|
133 | return fn(magic_args) | |
143 |
|
134 | |||
144 | def ipalias(arg_s): |
|
135 | def ipalias(arg_s): | |
145 | """Call an alias by name. |
|
136 | """Call an alias by name. | |
146 |
|
137 | |||
147 | Input: a string containing the name of the alias to call and any |
|
138 | Input: a string containing the name of the alias to call and any | |
148 | additional arguments to be passed to the magic. |
|
139 | additional arguments to be passed to the magic. | |
149 |
|
140 | |||
150 | ipalias('name -opt foo bar') is equivalent to typing at the ipython |
|
141 | ipalias('name -opt foo bar') is equivalent to typing at the ipython | |
151 | prompt: |
|
142 | prompt: | |
152 |
|
143 | |||
153 | In[1]: name -opt foo bar |
|
144 | In[1]: name -opt foo bar | |
154 |
|
145 | |||
155 | To call an alias without arguments, simply use ipalias('name'). |
|
146 | To call an alias without arguments, simply use ipalias('name'). | |
156 |
|
147 | |||
157 | This provides a proper Python function to call IPython's aliases in any |
|
148 | This provides a proper Python function to call IPython's aliases in any | |
158 | valid Python code you can type at the interpreter, including loops and |
|
149 | valid Python code you can type at the interpreter, including loops and | |
159 | compound statements. It is added by IPython to the Python builtin |
|
150 | compound statements. It is added by IPython to the Python builtin | |
160 | namespace upon initialization.""" |
|
151 | namespace upon initialization.""" | |
161 |
|
152 | |||
162 | args = arg_s.split(' ',1) |
|
153 | args = arg_s.split(' ',1) | |
163 | alias_name = args[0] |
|
154 | alias_name = args[0] | |
164 | try: |
|
155 | try: | |
165 | alias_args = args[1] |
|
156 | alias_args = args[1] | |
166 | except IndexError: |
|
157 | except IndexError: | |
167 | alias_args = '' |
|
158 | alias_args = '' | |
168 | if alias_name in __IPYTHON__.alias_table: |
|
159 | if alias_name in __IPYTHON__.alias_table: | |
169 | __IPYTHON__.call_alias(alias_name,alias_args) |
|
160 | __IPYTHON__.call_alias(alias_name,alias_args) | |
170 | else: |
|
161 | else: | |
171 | error("Alias `%s` not found." % alias_name) |
|
162 | error("Alias `%s` not found." % alias_name) | |
172 |
|
163 | |||
173 | #----------------------------------------------------------------------------- |
|
164 | #----------------------------------------------------------------------------- | |
174 | # Local use classes |
|
165 | # Local use classes | |
175 | try: |
|
166 | try: | |
176 | from IPython import FlexCompleter |
|
167 | from IPython import FlexCompleter | |
177 |
|
168 | |||
178 | class MagicCompleter(FlexCompleter.Completer): |
|
169 | class MagicCompleter(FlexCompleter.Completer): | |
179 | """Extension of the completer class to work on %-prefixed lines.""" |
|
170 | """Extension of the completer class to work on %-prefixed lines.""" | |
180 |
|
171 | |||
181 | def __init__(self,shell,namespace=None,omit__names=0,alias_table=None): |
|
172 | def __init__(self,shell,namespace=None,omit__names=0,alias_table=None): | |
182 | """MagicCompleter() -> completer |
|
173 | """MagicCompleter() -> completer | |
183 |
|
174 | |||
184 | Return a completer object suitable for use by the readline library |
|
175 | Return a completer object suitable for use by the readline library | |
185 | via readline.set_completer(). |
|
176 | via readline.set_completer(). | |
186 |
|
177 | |||
187 | Inputs: |
|
178 | Inputs: | |
188 |
|
179 | |||
189 | - shell: a pointer to the ipython shell itself. This is needed |
|
180 | - shell: a pointer to the ipython shell itself. This is needed | |
190 | because this completer knows about magic functions, and those can |
|
181 | because this completer knows about magic functions, and those can | |
191 | only be accessed via the ipython instance. |
|
182 | only be accessed via the ipython instance. | |
192 |
|
183 | |||
193 | - namespace: an optional dict where completions are performed. |
|
184 | - namespace: an optional dict where completions are performed. | |
194 |
|
185 | |||
195 | - The optional omit__names parameter sets the completer to omit the |
|
186 | - The optional omit__names parameter sets the completer to omit the | |
196 | 'magic' names (__magicname__) for python objects unless the text |
|
187 | 'magic' names (__magicname__) for python objects unless the text | |
197 | to be completed explicitly starts with one or more underscores. |
|
188 | to be completed explicitly starts with one or more underscores. | |
198 |
|
189 | |||
199 | - If alias_table is supplied, it should be a dictionary of aliases |
|
190 | - If alias_table is supplied, it should be a dictionary of aliases | |
200 | to complete. """ |
|
191 | to complete. """ | |
201 |
|
192 | |||
202 | FlexCompleter.Completer.__init__(self,namespace) |
|
193 | FlexCompleter.Completer.__init__(self,namespace) | |
203 | self.magic_prefix = shell.name+'.magic_' |
|
194 | self.magic_prefix = shell.name+'.magic_' | |
204 | self.magic_escape = shell.ESC_MAGIC |
|
195 | self.magic_escape = shell.ESC_MAGIC | |
205 | self.readline = FlexCompleter.readline |
|
196 | self.readline = FlexCompleter.readline | |
206 | delims = self.readline.get_completer_delims() |
|
197 | delims = self.readline.get_completer_delims() | |
207 | delims = delims.replace(self.magic_escape,'') |
|
198 | delims = delims.replace(self.magic_escape,'') | |
208 | self.readline.set_completer_delims(delims) |
|
199 | self.readline.set_completer_delims(delims) | |
209 | self.get_line_buffer = self.readline.get_line_buffer |
|
200 | self.get_line_buffer = self.readline.get_line_buffer | |
210 | self.omit__names = omit__names |
|
201 | self.omit__names = omit__names | |
211 | self.merge_completions = shell.rc.readline_merge_completions |
|
202 | self.merge_completions = shell.rc.readline_merge_completions | |
212 |
|
203 | |||
213 | if alias_table is None: |
|
204 | if alias_table is None: | |
214 | alias_table = {} |
|
205 | alias_table = {} | |
215 | self.alias_table = alias_table |
|
206 | self.alias_table = alias_table | |
216 | # Regexp to split filenames with spaces in them |
|
207 | # Regexp to split filenames with spaces in them | |
217 | self.space_name_re = re.compile(r'([^\\] )') |
|
208 | self.space_name_re = re.compile(r'([^\\] )') | |
218 | # Hold a local ref. to glob.glob for speed |
|
209 | # Hold a local ref. to glob.glob for speed | |
219 | self.glob = glob.glob |
|
210 | self.glob = glob.glob | |
220 | # Special handling of backslashes needed in win32 platforms |
|
211 | # Special handling of backslashes needed in win32 platforms | |
221 | if sys.platform == "win32": |
|
212 | if sys.platform == "win32": | |
222 | self.clean_glob = self._clean_glob_win32 |
|
213 | self.clean_glob = self._clean_glob_win32 | |
223 | else: |
|
214 | else: | |
224 | self.clean_glob = self._clean_glob |
|
215 | self.clean_glob = self._clean_glob | |
225 | self.matchers = [self.python_matches, |
|
216 | self.matchers = [self.python_matches, | |
226 | self.file_matches, |
|
217 | self.file_matches, | |
227 | self.alias_matches, |
|
218 | self.alias_matches, | |
228 | self.python_func_kw_matches] |
|
219 | self.python_func_kw_matches] | |
229 |
|
220 | |||
230 | # Code contributed by Alex Schmolck, for ipython/emacs integration |
|
221 | # Code contributed by Alex Schmolck, for ipython/emacs integration | |
231 | def all_completions(self, text): |
|
222 | def all_completions(self, text): | |
232 | """Return all possible completions for the benefit of emacs.""" |
|
223 | """Return all possible completions for the benefit of emacs.""" | |
233 |
|
224 | |||
234 | completions = [] |
|
225 | completions = [] | |
235 | try: |
|
226 | try: | |
236 | for i in xrange(sys.maxint): |
|
227 | for i in xrange(sys.maxint): | |
237 | res = self.complete(text, i) |
|
228 | res = self.complete(text, i) | |
238 |
|
229 | |||
239 | if not res: break |
|
230 | if not res: break | |
240 |
|
231 | |||
241 | completions.append(res) |
|
232 | completions.append(res) | |
242 | #XXX workaround for ``notDefined.<tab>`` |
|
233 | #XXX workaround for ``notDefined.<tab>`` | |
243 | except NameError: |
|
234 | except NameError: | |
244 | pass |
|
235 | pass | |
245 | return completions |
|
236 | return completions | |
246 | # /end Alex Schmolck code. |
|
237 | # /end Alex Schmolck code. | |
247 |
|
238 | |||
248 | def _clean_glob(self,text): |
|
239 | def _clean_glob(self,text): | |
249 | return self.glob("%s*" % text) |
|
240 | return self.glob("%s*" % text) | |
250 |
|
241 | |||
251 | def _clean_glob_win32(self,text): |
|
242 | def _clean_glob_win32(self,text): | |
252 | return [f.replace("\\","/") |
|
243 | return [f.replace("\\","/") | |
253 | for f in self.glob("%s*" % text)] |
|
244 | for f in self.glob("%s*" % text)] | |
254 |
|
245 | |||
255 | def file_matches(self, text): |
|
246 | def file_matches(self, text): | |
256 | """Match filneames, expanding ~USER type strings. |
|
247 | """Match filneames, expanding ~USER type strings. | |
257 |
|
248 | |||
258 | Most of the seemingly convoluted logic in this completer is an |
|
249 | Most of the seemingly convoluted logic in this completer is an | |
259 | attempt to handle filenames with spaces in them. And yet it's not |
|
250 | attempt to handle filenames with spaces in them. And yet it's not | |
260 | quite perfect, because Python's readline doesn't expose all of the |
|
251 | quite perfect, because Python's readline doesn't expose all of the | |
261 | GNU readline details needed for this to be done correctly. |
|
252 | GNU readline details needed for this to be done correctly. | |
262 |
|
253 | |||
263 | For a filename with a space in it, the printed completions will be |
|
254 | For a filename with a space in it, the printed completions will be | |
264 | only the parts after what's already been typed (instead of the |
|
255 | only the parts after what's already been typed (instead of the | |
265 | full completions, as is normally done). I don't think with the |
|
256 | full completions, as is normally done). I don't think with the | |
266 | current (as of Python 2.3) Python readline it's possible to do |
|
257 | current (as of Python 2.3) Python readline it's possible to do | |
267 | better.""" |
|
258 | better.""" | |
268 |
|
259 | |||
269 | #print 'Completer->file_matches: <%s>' % text # dbg |
|
260 | #print 'Completer->file_matches: <%s>' % text # dbg | |
270 |
|
261 | |||
271 | # chars that require escaping with backslash - i.e. chars |
|
262 | # chars that require escaping with backslash - i.e. chars | |
272 | # that readline treats incorrectly as delimiters, but we |
|
263 | # that readline treats incorrectly as delimiters, but we | |
273 | # don't want to treat as delimiters in filename matching |
|
264 | # don't want to treat as delimiters in filename matching | |
274 | # when escaped with backslash |
|
265 | # when escaped with backslash | |
275 |
|
266 | |||
276 | protectables = ' ()[]{}' |
|
267 | protectables = ' ()[]{}' | |
277 |
|
268 | |||
278 | def protect_filename(s): |
|
269 | def protect_filename(s): | |
279 | return "".join([(ch in protectables and '\\' + ch or ch) |
|
270 | return "".join([(ch in protectables and '\\' + ch or ch) | |
280 | for ch in s]) |
|
271 | for ch in s]) | |
281 |
|
272 | |||
282 | lbuf = self.get_line_buffer()[:self.readline.get_endidx()] |
|
273 | lbuf = self.get_line_buffer()[:self.readline.get_endidx()] | |
283 | open_quotes = 0 # track strings with open quotes |
|
274 | open_quotes = 0 # track strings with open quotes | |
284 | try: |
|
275 | try: | |
285 | lsplit = shlex_split(lbuf)[-1] |
|
276 | lsplit = shlex_split(lbuf)[-1] | |
286 | except ValueError: |
|
277 | except ValueError: | |
287 | # typically an unmatched ", or backslash without escaped char. |
|
278 | # typically an unmatched ", or backslash without escaped char. | |
288 | if lbuf.count('"')==1: |
|
279 | if lbuf.count('"')==1: | |
289 | open_quotes = 1 |
|
280 | open_quotes = 1 | |
290 | lsplit = lbuf.split('"')[-1] |
|
281 | lsplit = lbuf.split('"')[-1] | |
291 | elif lbuf.count("'")==1: |
|
282 | elif lbuf.count("'")==1: | |
292 | open_quotes = 1 |
|
283 | open_quotes = 1 | |
293 | lsplit = lbuf.split("'")[-1] |
|
284 | lsplit = lbuf.split("'")[-1] | |
294 | else: |
|
285 | else: | |
295 | return None |
|
286 | return None | |
296 | except IndexError: |
|
287 | except IndexError: | |
297 | # tab pressed on empty line |
|
288 | # tab pressed on empty line | |
298 | lsplit = "" |
|
289 | lsplit = "" | |
299 |
|
290 | |||
300 | if lsplit != protect_filename(lsplit): |
|
291 | if lsplit != protect_filename(lsplit): | |
301 | # if protectables are found, do matching on the whole escaped |
|
292 | # if protectables are found, do matching on the whole escaped | |
302 | # name |
|
293 | # name | |
303 | has_protectables = 1 |
|
294 | has_protectables = 1 | |
304 | text0,text = text,lsplit |
|
295 | text0,text = text,lsplit | |
305 | else: |
|
296 | else: | |
306 | has_protectables = 0 |
|
297 | has_protectables = 0 | |
307 | text = os.path.expanduser(text) |
|
298 | text = os.path.expanduser(text) | |
308 |
|
299 | |||
309 | if text == "": |
|
300 | if text == "": | |
310 | return [protect_filename(f) for f in self.glob("*")] |
|
301 | return [protect_filename(f) for f in self.glob("*")] | |
311 |
|
302 | |||
312 | m0 = self.clean_glob(text.replace('\\','')) |
|
303 | m0 = self.clean_glob(text.replace('\\','')) | |
313 | if has_protectables: |
|
304 | if has_protectables: | |
314 | # If we had protectables, we need to revert our changes to the |
|
305 | # If we had protectables, we need to revert our changes to the | |
315 | # beginning of filename so that we don't double-write the part |
|
306 | # beginning of filename so that we don't double-write the part | |
316 | # of the filename we have so far |
|
307 | # of the filename we have so far | |
317 | len_lsplit = len(lsplit) |
|
308 | len_lsplit = len(lsplit) | |
318 | matches = [text0 + protect_filename(f[len_lsplit:]) for f in m0] |
|
309 | matches = [text0 + protect_filename(f[len_lsplit:]) for f in m0] | |
319 | else: |
|
310 | else: | |
320 | if open_quotes: |
|
311 | if open_quotes: | |
321 | # if we have a string with an open quote, we don't need to |
|
312 | # if we have a string with an open quote, we don't need to | |
322 | # protect the names at all (and we _shouldn't_, as it |
|
313 | # protect the names at all (and we _shouldn't_, as it | |
323 | # would cause bugs when the filesystem call is made). |
|
314 | # would cause bugs when the filesystem call is made). | |
324 | matches = m0 |
|
315 | matches = m0 | |
325 | else: |
|
316 | else: | |
326 | matches = [protect_filename(f) for f in m0] |
|
317 | matches = [protect_filename(f) for f in m0] | |
327 | if len(matches) == 1 and os.path.isdir(matches[0]): |
|
318 | if len(matches) == 1 and os.path.isdir(matches[0]): | |
328 | # Takes care of links to directories also. Use '/' |
|
319 | # Takes care of links to directories also. Use '/' | |
329 | # explicitly, even under Windows, so that name completions |
|
320 | # explicitly, even under Windows, so that name completions | |
330 | # don't end up escaped. |
|
321 | # don't end up escaped. | |
331 | matches[0] += '/' |
|
322 | matches[0] += '/' | |
332 | return matches |
|
323 | return matches | |
333 |
|
324 | |||
334 | def alias_matches(self, text): |
|
325 | def alias_matches(self, text): | |
335 | """Match internal system aliases""" |
|
326 | """Match internal system aliases""" | |
336 | #print 'Completer->alias_matches:',text # dbg |
|
327 | #print 'Completer->alias_matches:',text # dbg | |
337 | text = os.path.expanduser(text) |
|
328 | text = os.path.expanduser(text) | |
338 | aliases = self.alias_table.keys() |
|
329 | aliases = self.alias_table.keys() | |
339 | if text == "": |
|
330 | if text == "": | |
340 | return aliases |
|
331 | return aliases | |
341 | else: |
|
332 | else: | |
342 | return [alias for alias in aliases if alias.startswith(text)] |
|
333 | return [alias for alias in aliases if alias.startswith(text)] | |
343 |
|
334 | |||
344 | def python_matches(self,text): |
|
335 | def python_matches(self,text): | |
345 | """Match attributes or global python names""" |
|
336 | """Match attributes or global python names""" | |
346 | #print 'Completer->python_matches' # dbg |
|
337 | #print 'Completer->python_matches' # dbg | |
347 | if "." in text: |
|
338 | if "." in text: | |
348 | try: |
|
339 | try: | |
349 | matches = self.attr_matches(text) |
|
340 | matches = self.attr_matches(text) | |
350 | if text.endswith('.') and self.omit__names: |
|
341 | if text.endswith('.') and self.omit__names: | |
351 | if self.omit__names == 1: |
|
342 | if self.omit__names == 1: | |
352 | # true if txt is _not_ a __ name, false otherwise: |
|
343 | # true if txt is _not_ a __ name, false otherwise: | |
353 | no__name = (lambda txt: |
|
344 | no__name = (lambda txt: | |
354 | re.match(r'.*\.__.*?__',txt) is None) |
|
345 | re.match(r'.*\.__.*?__',txt) is None) | |
355 | else: |
|
346 | else: | |
356 | # true if txt is _not_ a _ name, false otherwise: |
|
347 | # true if txt is _not_ a _ name, false otherwise: | |
357 | no__name = (lambda txt: |
|
348 | no__name = (lambda txt: | |
358 | re.match(r'.*\._.*?',txt) is None) |
|
349 | re.match(r'.*\._.*?',txt) is None) | |
359 | matches = filter(no__name, matches) |
|
350 | matches = filter(no__name, matches) | |
360 | except NameError: |
|
351 | except NameError: | |
361 | # catches <undefined attributes>.<tab> |
|
352 | # catches <undefined attributes>.<tab> | |
362 | matches = [] |
|
353 | matches = [] | |
363 | else: |
|
354 | else: | |
364 | matches = self.global_matches(text) |
|
355 | matches = self.global_matches(text) | |
365 | # this is so completion finds magics when automagic is on: |
|
356 | # this is so completion finds magics when automagic is on: | |
366 | if matches == [] and not text.startswith(os.sep): |
|
357 | if matches == [] and not text.startswith(os.sep): | |
367 | matches = self.attr_matches(self.magic_prefix+text) |
|
358 | matches = self.attr_matches(self.magic_prefix+text) | |
368 | return matches |
|
359 | return matches | |
369 |
|
360 | |||
370 | def _default_arguments(self, obj): |
|
361 | def _default_arguments(self, obj): | |
371 | """Return the list of default arguments of obj if it is callable, |
|
362 | """Return the list of default arguments of obj if it is callable, | |
372 | or empty list otherwise.""" |
|
363 | or empty list otherwise.""" | |
373 |
|
364 | |||
374 | if not (inspect.isfunction(obj) or inspect.ismethod(obj)): |
|
365 | if not (inspect.isfunction(obj) or inspect.ismethod(obj)): | |
375 | # for classes, check for __init__,__new__ |
|
366 | # for classes, check for __init__,__new__ | |
376 | if inspect.isclass(obj): |
|
367 | if inspect.isclass(obj): | |
377 | obj = (getattr(obj,'__init__',None) or |
|
368 | obj = (getattr(obj,'__init__',None) or | |
378 | getattr(obj,'__new__',None)) |
|
369 | getattr(obj,'__new__',None)) | |
379 | # for all others, check if they are __call__able |
|
370 | # for all others, check if they are __call__able | |
380 | elif hasattr(obj, '__call__'): |
|
371 | elif hasattr(obj, '__call__'): | |
381 | obj = obj.__call__ |
|
372 | obj = obj.__call__ | |
382 | # XXX: is there a way to handle the builtins ? |
|
373 | # XXX: is there a way to handle the builtins ? | |
383 | try: |
|
374 | try: | |
384 | args,_,_1,defaults = inspect.getargspec(obj) |
|
375 | args,_,_1,defaults = inspect.getargspec(obj) | |
385 | if defaults: |
|
376 | if defaults: | |
386 | return args[-len(defaults):] |
|
377 | return args[-len(defaults):] | |
387 | except TypeError: pass |
|
378 | except TypeError: pass | |
388 | return [] |
|
379 | return [] | |
389 |
|
380 | |||
390 | def python_func_kw_matches(self,text): |
|
381 | def python_func_kw_matches(self,text): | |
391 | """Match named parameters (kwargs) of the last open function""" |
|
382 | """Match named parameters (kwargs) of the last open function""" | |
392 |
|
383 | |||
393 | if "." in text: # a parameter cannot be dotted |
|
384 | if "." in text: # a parameter cannot be dotted | |
394 | return [] |
|
385 | return [] | |
395 | try: regexp = self.__funcParamsRegex |
|
386 | try: regexp = self.__funcParamsRegex | |
396 | except AttributeError: |
|
387 | except AttributeError: | |
397 | regexp = self.__funcParamsRegex = re.compile(r''' |
|
388 | regexp = self.__funcParamsRegex = re.compile(r''' | |
398 | '.*?' | # single quoted strings or |
|
389 | '.*?' | # single quoted strings or | |
399 | ".*?" | # double quoted strings or |
|
390 | ".*?" | # double quoted strings or | |
400 | \w+ | # identifier |
|
391 | \w+ | # identifier | |
401 | \S # other characters |
|
392 | \S # other characters | |
402 | ''', re.VERBOSE | re.DOTALL) |
|
393 | ''', re.VERBOSE | re.DOTALL) | |
403 | # 1. find the nearest identifier that comes before an unclosed |
|
394 | # 1. find the nearest identifier that comes before an unclosed | |
404 | # parenthesis e.g. for "foo (1+bar(x), pa", the candidate is "foo" |
|
395 | # parenthesis e.g. for "foo (1+bar(x), pa", the candidate is "foo" | |
405 | tokens = regexp.findall(self.get_line_buffer()) |
|
396 | tokens = regexp.findall(self.get_line_buffer()) | |
406 | tokens.reverse() |
|
397 | tokens.reverse() | |
407 | iterTokens = iter(tokens); openPar = 0 |
|
398 | iterTokens = iter(tokens); openPar = 0 | |
408 | for token in iterTokens: |
|
399 | for token in iterTokens: | |
409 | if token == ')': |
|
400 | if token == ')': | |
410 | openPar -= 1 |
|
401 | openPar -= 1 | |
411 | elif token == '(': |
|
402 | elif token == '(': | |
412 | openPar += 1 |
|
403 | openPar += 1 | |
413 | if openPar > 0: |
|
404 | if openPar > 0: | |
414 | # found the last unclosed parenthesis |
|
405 | # found the last unclosed parenthesis | |
415 | break |
|
406 | break | |
416 | else: |
|
407 | else: | |
417 | return [] |
|
408 | return [] | |
418 | # 2. Concatenate any dotted names (e.g. "foo.bar" for "foo.bar(x, pa" ) |
|
409 | # 2. Concatenate any dotted names (e.g. "foo.bar" for "foo.bar(x, pa" ) | |
419 | ids = [] |
|
410 | ids = [] | |
420 | isId = re.compile(r'\w+$').match |
|
411 | isId = re.compile(r'\w+$').match | |
421 | while True: |
|
412 | while True: | |
422 | try: |
|
413 | try: | |
423 | ids.append(iterTokens.next()) |
|
414 | ids.append(iterTokens.next()) | |
424 | if not isId(ids[-1]): |
|
415 | if not isId(ids[-1]): | |
425 | ids.pop(); break |
|
416 | ids.pop(); break | |
426 | if not iterTokens.next() == '.': |
|
417 | if not iterTokens.next() == '.': | |
427 | break |
|
418 | break | |
428 | except StopIteration: |
|
419 | except StopIteration: | |
429 | break |
|
420 | break | |
430 | # lookup the candidate callable matches either using global_matches |
|
421 | # lookup the candidate callable matches either using global_matches | |
431 | # or attr_matches for dotted names |
|
422 | # or attr_matches for dotted names | |
432 | if len(ids) == 1: |
|
423 | if len(ids) == 1: | |
433 | callableMatches = self.global_matches(ids[0]) |
|
424 | callableMatches = self.global_matches(ids[0]) | |
434 | else: |
|
425 | else: | |
435 | callableMatches = self.attr_matches('.'.join(ids[::-1])) |
|
426 | callableMatches = self.attr_matches('.'.join(ids[::-1])) | |
436 | argMatches = [] |
|
427 | argMatches = [] | |
437 | for callableMatch in callableMatches: |
|
428 | for callableMatch in callableMatches: | |
438 | try: namedArgs = self._default_arguments(eval(callableMatch, |
|
429 | try: namedArgs = self._default_arguments(eval(callableMatch, | |
439 | self.namespace)) |
|
430 | self.namespace)) | |
440 | except: continue |
|
431 | except: continue | |
441 | for namedArg in namedArgs: |
|
432 | for namedArg in namedArgs: | |
442 | if namedArg.startswith(text): |
|
433 | if namedArg.startswith(text): | |
443 | argMatches.append("%s=" %namedArg) |
|
434 | argMatches.append("%s=" %namedArg) | |
444 | return argMatches |
|
435 | return argMatches | |
445 |
|
436 | |||
446 | def complete(self, text, state): |
|
437 | def complete(self, text, state): | |
447 | """Return the next possible completion for 'text'. |
|
438 | """Return the next possible completion for 'text'. | |
448 |
|
439 | |||
449 | This is called successively with state == 0, 1, 2, ... until it |
|
440 | This is called successively with state == 0, 1, 2, ... until it | |
450 | returns None. The completion should begin with 'text'. """ |
|
441 | returns None. The completion should begin with 'text'. """ | |
451 |
|
442 | |||
452 | #print '\n*** COMPLETE: <%s> (%s)' % (text,state) # dbg |
|
443 | #print '\n*** COMPLETE: <%s> (%s)' % (text,state) # dbg | |
453 | magic_escape = self.magic_escape |
|
444 | magic_escape = self.magic_escape | |
454 | magic_prefix = self.magic_prefix |
|
445 | magic_prefix = self.magic_prefix | |
455 |
|
446 | |||
456 | try: |
|
447 | try: | |
457 | if text.startswith(magic_escape): |
|
448 | if text.startswith(magic_escape): | |
458 | text = text.replace(magic_escape,magic_prefix) |
|
449 | text = text.replace(magic_escape,magic_prefix) | |
459 | elif text.startswith('~'): |
|
450 | elif text.startswith('~'): | |
460 | text = os.path.expanduser(text) |
|
451 | text = os.path.expanduser(text) | |
461 | if state == 0: |
|
452 | if state == 0: | |
462 | # Extend the list of completions with the results of each |
|
453 | # Extend the list of completions with the results of each | |
463 | # matcher, so we return results to the user from all |
|
454 | # matcher, so we return results to the user from all | |
464 | # namespaces. |
|
455 | # namespaces. | |
465 | if self.merge_completions: |
|
456 | if self.merge_completions: | |
466 | self.matches = [] |
|
457 | self.matches = [] | |
467 | for matcher in self.matchers: |
|
458 | for matcher in self.matchers: | |
468 | self.matches.extend(matcher(text)) |
|
459 | self.matches.extend(matcher(text)) | |
469 | else: |
|
460 | else: | |
470 | for matcher in self.matchers: |
|
461 | for matcher in self.matchers: | |
471 | self.matches = matcher(text) |
|
462 | self.matches = matcher(text) | |
472 | if self.matches: |
|
463 | if self.matches: | |
473 | break |
|
464 | break | |
474 |
|
465 | |||
475 | try: |
|
466 | try: | |
476 | return self.matches[state].replace(magic_prefix,magic_escape) |
|
467 | return self.matches[state].replace(magic_prefix,magic_escape) | |
477 | except IndexError: |
|
468 | except IndexError: | |
478 | return None |
|
469 | return None | |
479 | except: |
|
470 | except: | |
480 | # If completion fails, don't annoy the user. |
|
471 | # If completion fails, don't annoy the user. | |
481 | pass |
|
472 | pass | |
482 |
|
473 | |||
483 | except ImportError: |
|
474 | except ImportError: | |
484 | pass # no readline support |
|
475 | pass # no readline support | |
485 |
|
476 | |||
486 | except KeyError: |
|
477 | except KeyError: | |
487 | pass # Windows doesn't set TERM, it doesn't matter |
|
478 | pass # Windows doesn't set TERM, it doesn't matter | |
488 |
|
479 | |||
489 |
|
480 | |||
490 | class InputList(UserList.UserList): |
|
481 | class InputList(UserList.UserList): | |
491 | """Class to store user input. |
|
482 | """Class to store user input. | |
492 |
|
483 | |||
493 | It's basically a list, but slices return a string instead of a list, thus |
|
484 | It's basically a list, but slices return a string instead of a list, thus | |
494 | allowing things like (assuming 'In' is an instance): |
|
485 | allowing things like (assuming 'In' is an instance): | |
495 |
|
486 | |||
496 | exec In[4:7] |
|
487 | exec In[4:7] | |
497 |
|
488 | |||
498 | or |
|
489 | or | |
499 |
|
490 | |||
500 | exec In[5:9] + In[14] + In[21:25]""" |
|
491 | exec In[5:9] + In[14] + In[21:25]""" | |
501 |
|
492 | |||
502 | def __getslice__(self,i,j): |
|
493 | def __getslice__(self,i,j): | |
503 | return ''.join(UserList.UserList.__getslice__(self,i,j)) |
|
494 | return ''.join(UserList.UserList.__getslice__(self,i,j)) | |
504 |
|
495 | |||
505 | #**************************************************************************** |
|
496 | #**************************************************************************** | |
506 | # Local use exceptions |
|
497 | # Local use exceptions | |
507 | class SpaceInInput(exceptions.Exception): |
|
498 | class SpaceInInput(exceptions.Exception): | |
508 | pass |
|
499 | pass | |
509 |
|
500 | |||
510 | #**************************************************************************** |
|
501 | #**************************************************************************** | |
511 | # Main IPython class |
|
502 | # Main IPython class | |
512 |
|
503 | |||
513 | class InteractiveShell(code.InteractiveConsole, Logger, Magic): |
|
504 | class InteractiveShell(code.InteractiveConsole, Logger, Magic): | |
514 | """An enhanced console for Python.""" |
|
505 | """An enhanced console for Python.""" | |
515 |
|
506 | |||
516 | def __init__(self,name,usage=None,rc=Struct(opts=None,args=None), |
|
507 | def __init__(self,name,usage=None,rc=Struct(opts=None,args=None), | |
517 | user_ns = None,banner2='', |
|
508 | user_ns = None,banner2='', | |
518 | custom_exceptions=((),None)): |
|
509 | custom_exceptions=((),None)): | |
519 |
|
510 | |||
520 | # Put a reference to self in builtins so that any form of embedded or |
|
511 | # Put a reference to self in builtins so that any form of embedded or | |
521 | # imported code can test for being inside IPython. |
|
512 | # imported code can test for being inside IPython. | |
522 | __builtin__.__IPYTHON__ = self |
|
513 | __builtin__.__IPYTHON__ = self | |
523 |
|
514 | |||
524 | # And load into builtins ipmagic/ipalias as well |
|
515 | # And load into builtins ipmagic/ipalias as well | |
525 | __builtin__.ipmagic = ipmagic |
|
516 | __builtin__.ipmagic = ipmagic | |
526 | __builtin__.ipalias = ipalias |
|
517 | __builtin__.ipalias = ipalias | |
527 |
|
518 | |||
528 | # Add to __builtin__ other parts of IPython's public API |
|
519 | # Add to __builtin__ other parts of IPython's public API | |
529 | __builtin__.ip_set_hook = self.set_hook |
|
520 | __builtin__.ip_set_hook = self.set_hook | |
530 |
|
521 | |||
531 | # Keep in the builtins a flag for when IPython is active. We set it |
|
522 | # Keep in the builtins a flag for when IPython is active. We set it | |
532 | # with setdefault so that multiple nested IPythons don't clobber one |
|
523 | # with setdefault so that multiple nested IPythons don't clobber one | |
533 | # another. Each will increase its value by one upon being activated, |
|
524 | # another. Each will increase its value by one upon being activated, | |
534 | # which also gives us a way to determine the nesting level. |
|
525 | # which also gives us a way to determine the nesting level. | |
535 | __builtin__.__dict__.setdefault('__IPYTHON__active',0) |
|
526 | __builtin__.__dict__.setdefault('__IPYTHON__active',0) | |
536 |
|
527 | |||
537 | # Inform the user of ipython's fast exit magics. |
|
528 | # Inform the user of ipython's fast exit magics. | |
538 | _exit = ' Use %Exit or %Quit to exit without confirmation.' |
|
529 | _exit = ' Use %Exit or %Quit to exit without confirmation.' | |
539 | __builtin__.exit += _exit |
|
530 | __builtin__.exit += _exit | |
540 | __builtin__.quit += _exit |
|
531 | __builtin__.quit += _exit | |
541 |
|
532 | |||
542 | # Create the namespace where the user will operate: |
|
533 | # Create the namespace where the user will operate: | |
543 |
|
534 | |||
544 | # FIXME. For some strange reason, __builtins__ is showing up at user |
|
535 | # FIXME. For some strange reason, __builtins__ is showing up at user | |
545 | # level as a dict instead of a module. This is a manual fix, but I |
|
536 | # level as a dict instead of a module. This is a manual fix, but I | |
546 | # should really track down where the problem is coming from. Alex |
|
537 | # should really track down where the problem is coming from. Alex | |
547 | # Schmolck reported this problem first. |
|
538 | # Schmolck reported this problem first. | |
548 |
|
539 | |||
549 | # A useful post by Alex Martelli on this topic: |
|
540 | # A useful post by Alex Martelli on this topic: | |
550 | # Re: inconsistent value from __builtins__ |
|
541 | # Re: inconsistent value from __builtins__ | |
551 | # Von: Alex Martelli <aleaxit@yahoo.com> |
|
542 | # Von: Alex Martelli <aleaxit@yahoo.com> | |
552 | # Datum: Freitag 01 Oktober 2004 04:45:34 nachmittags/abends |
|
543 | # Datum: Freitag 01 Oktober 2004 04:45:34 nachmittags/abends | |
553 | # Gruppen: comp.lang.python |
|
544 | # Gruppen: comp.lang.python | |
554 | # Referenzen: 1 |
|
545 | # Referenzen: 1 | |
555 |
|
546 | |||
556 | # Michael Hohn <hohn@hooknose.lbl.gov> wrote: |
|
547 | # Michael Hohn <hohn@hooknose.lbl.gov> wrote: | |
557 | # > >>> print type(builtin_check.get_global_binding('__builtins__')) |
|
548 | # > >>> print type(builtin_check.get_global_binding('__builtins__')) | |
558 | # > <type 'dict'> |
|
549 | # > <type 'dict'> | |
559 | # > >>> print type(__builtins__) |
|
550 | # > >>> print type(__builtins__) | |
560 | # > <type 'module'> |
|
551 | # > <type 'module'> | |
561 | # > Is this difference in return value intentional? |
|
552 | # > Is this difference in return value intentional? | |
562 |
|
553 | |||
563 | # Well, it's documented that '__builtins__' can be either a dictionary |
|
554 | # Well, it's documented that '__builtins__' can be either a dictionary | |
564 | # or a module, and it's been that way for a long time. Whether it's |
|
555 | # or a module, and it's been that way for a long time. Whether it's | |
565 | # intentional (or sensible), I don't know. In any case, the idea is that |
|
556 | # intentional (or sensible), I don't know. In any case, the idea is that | |
566 | # if you need to access the built-in namespace directly, you should start |
|
557 | # if you need to access the built-in namespace directly, you should start | |
567 | # with "import __builtin__" (note, no 's') which will definitely give you |
|
558 | # with "import __builtin__" (note, no 's') which will definitely give you | |
568 | # a module. Yeah, it's somewhatΒ confusing:-(. |
|
559 | # a module. Yeah, it's somewhatΒ confusing:-(. | |
569 |
|
560 | |||
570 | if user_ns is None: |
|
561 | if user_ns is None: | |
571 | # Set __name__ to __main__ to better match the behavior of the |
|
562 | # Set __name__ to __main__ to better match the behavior of the | |
572 | # normal interpreter. |
|
563 | # normal interpreter. | |
573 | self.user_ns = {'__name__' :'__main__', |
|
564 | self.user_ns = {'__name__' :'__main__', | |
574 | '__builtins__' : __builtin__, |
|
565 | '__builtins__' : __builtin__, | |
575 | } |
|
566 | } | |
576 | else: |
|
567 | else: | |
577 | self.user_ns = user_ns |
|
568 | self.user_ns = user_ns | |
578 |
|
569 | |||
579 | # The user namespace MUST have a pointer to the shell itself. |
|
570 | # The user namespace MUST have a pointer to the shell itself. | |
580 | self.user_ns[name] = self |
|
571 | self.user_ns[name] = self | |
581 |
|
572 | |||
582 | # We need to insert into sys.modules something that looks like a |
|
573 | # We need to insert into sys.modules something that looks like a | |
583 | # module but which accesses the IPython namespace, for shelve and |
|
574 | # module but which accesses the IPython namespace, for shelve and | |
584 | # pickle to work interactively. Normally they rely on getting |
|
575 | # pickle to work interactively. Normally they rely on getting | |
585 | # everything out of __main__, but for embedding purposes each IPython |
|
576 | # everything out of __main__, but for embedding purposes each IPython | |
586 | # instance has its own private namespace, so we can't go shoving |
|
577 | # instance has its own private namespace, so we can't go shoving | |
587 | # everything into __main__. |
|
578 | # everything into __main__. | |
588 |
|
579 | |||
589 | try: |
|
580 | try: | |
590 | main_name = self.user_ns['__name__'] |
|
581 | main_name = self.user_ns['__name__'] | |
591 | except KeyError: |
|
582 | except KeyError: | |
592 | raise KeyError,'user_ns dictionary MUST have a "__name__" key' |
|
583 | raise KeyError,'user_ns dictionary MUST have a "__name__" key' | |
593 | else: |
|
584 | else: | |
594 | #print "pickle hack in place" # dbg |
|
585 | #print "pickle hack in place" # dbg | |
595 | sys.modules[main_name] = FakeModule(self.user_ns) |
|
586 | sys.modules[main_name] = FakeModule(self.user_ns) | |
596 |
|
587 | |||
597 | # List of input with multi-line handling. |
|
588 | # List of input with multi-line handling. | |
598 | # Fill its zero entry, user counter starts at 1 |
|
589 | # Fill its zero entry, user counter starts at 1 | |
599 | self.input_hist = InputList(['\n']) |
|
590 | self.input_hist = InputList(['\n']) | |
600 |
|
591 | |||
601 | # list of visited directories |
|
592 | # list of visited directories | |
602 | self.dir_hist = [os.getcwd()] |
|
593 | self.dir_hist = [os.getcwd()] | |
603 |
|
594 | |||
604 | # dict of output history |
|
595 | # dict of output history | |
605 | self.output_hist = {} |
|
596 | self.output_hist = {} | |
606 |
|
597 | |||
607 | # dict of names to be treated as system aliases. Each entry in the |
|
598 | # dict of names to be treated as system aliases. Each entry in the | |
608 | # alias table must be a 2-tuple of the form (N,name), where N is the |
|
599 | # alias table must be a 2-tuple of the form (N,name), where N is the | |
609 | # number of positional arguments of the alias. |
|
600 | # number of positional arguments of the alias. | |
610 | self.alias_table = {} |
|
601 | self.alias_table = {} | |
611 |
|
602 | |||
612 | # dict of things NOT to alias (keywords and builtins) |
|
603 | # dict of things NOT to alias (keywords and builtins) | |
613 | self.no_alias = {} |
|
604 | self.no_alias = {} | |
614 | for key in keyword.kwlist: |
|
605 | for key in keyword.kwlist: | |
615 | self.no_alias[key] = 1 |
|
606 | self.no_alias[key] = 1 | |
616 | self.no_alias.update(__builtin__.__dict__) |
|
607 | self.no_alias.update(__builtin__.__dict__) | |
617 |
|
608 | |||
618 | # make global variables for user access to these |
|
609 | # make global variables for user access to these | |
619 | self.user_ns['_ih'] = self.input_hist |
|
610 | self.user_ns['_ih'] = self.input_hist | |
620 | self.user_ns['_oh'] = self.output_hist |
|
611 | self.user_ns['_oh'] = self.output_hist | |
621 | self.user_ns['_dh'] = self.dir_hist |
|
612 | self.user_ns['_dh'] = self.dir_hist | |
622 |
|
613 | |||
623 | # user aliases to input and output histories |
|
614 | # user aliases to input and output histories | |
624 | self.user_ns['In'] = self.input_hist |
|
615 | self.user_ns['In'] = self.input_hist | |
625 | self.user_ns['Out'] = self.output_hist |
|
616 | self.user_ns['Out'] = self.output_hist | |
626 |
|
617 | |||
627 | # Store the actual shell's name |
|
618 | # Store the actual shell's name | |
628 | self.name = name |
|
619 | self.name = name | |
629 |
|
620 | |||
630 | # Object variable to store code object waiting execution. This is |
|
621 | # Object variable to store code object waiting execution. This is | |
631 | # used mainly by the multithreaded shells, but it can come in handy in |
|
622 | # used mainly by the multithreaded shells, but it can come in handy in | |
632 | # other situations. No need to use a Queue here, since it's a single |
|
623 | # other situations. No need to use a Queue here, since it's a single | |
633 | # item which gets cleared once run. |
|
624 | # item which gets cleared once run. | |
634 | self.code_to_run = None |
|
625 | self.code_to_run = None | |
635 | self.code_to_run_src = '' # corresponding source |
|
626 | self.code_to_run_src = '' # corresponding source | |
636 |
|
627 | |||
637 | # Job manager (for jobs run as background threads) |
|
628 | # Job manager (for jobs run as background threads) | |
638 | self.jobs = BackgroundJobManager() |
|
629 | self.jobs = BackgroundJobManager() | |
639 | # Put the job manager into builtins so it's always there. |
|
630 | # Put the job manager into builtins so it's always there. | |
640 | __builtin__.jobs = self.jobs |
|
631 | __builtin__.jobs = self.jobs | |
641 |
|
632 | |||
642 | # escapes for automatic behavior on the command line |
|
633 | # escapes for automatic behavior on the command line | |
643 | self.ESC_SHELL = '!' |
|
634 | self.ESC_SHELL = '!' | |
644 | self.ESC_HELP = '?' |
|
635 | self.ESC_HELP = '?' | |
645 | self.ESC_MAGIC = '%' |
|
636 | self.ESC_MAGIC = '%' | |
646 | self.ESC_QUOTE = ',' |
|
637 | self.ESC_QUOTE = ',' | |
647 | self.ESC_QUOTE2 = ';' |
|
638 | self.ESC_QUOTE2 = ';' | |
648 | self.ESC_PAREN = '/' |
|
639 | self.ESC_PAREN = '/' | |
649 |
|
640 | |||
650 | # And their associated handlers |
|
641 | # And their associated handlers | |
651 | self.esc_handlers = {self.ESC_PAREN:self.handle_auto, |
|
642 | self.esc_handlers = {self.ESC_PAREN:self.handle_auto, | |
652 | self.ESC_QUOTE:self.handle_auto, |
|
643 | self.ESC_QUOTE:self.handle_auto, | |
653 | self.ESC_QUOTE2:self.handle_auto, |
|
644 | self.ESC_QUOTE2:self.handle_auto, | |
654 | self.ESC_MAGIC:self.handle_magic, |
|
645 | self.ESC_MAGIC:self.handle_magic, | |
655 | self.ESC_HELP:self.handle_help, |
|
646 | self.ESC_HELP:self.handle_help, | |
656 | self.ESC_SHELL:self.handle_shell_escape, |
|
647 | self.ESC_SHELL:self.handle_shell_escape, | |
657 | } |
|
648 | } | |
658 |
|
649 | |||
659 | # class initializations |
|
650 | # class initializations | |
660 | code.InteractiveConsole.__init__(self,locals = self.user_ns) |
|
651 | code.InteractiveConsole.__init__(self,locals = self.user_ns) | |
661 | Logger.__init__(self,log_ns = self.user_ns) |
|
652 | Logger.__init__(self,log_ns = self.user_ns) | |
662 | Magic.__init__(self,self) |
|
653 | Magic.__init__(self,self) | |
663 |
|
654 | |||
664 | # an ugly hack to get a pointer to the shell, so I can start writing |
|
655 | # an ugly hack to get a pointer to the shell, so I can start writing | |
665 | # magic code via this pointer instead of the current mixin salad. |
|
656 | # magic code via this pointer instead of the current mixin salad. | |
666 | Magic.set_shell(self,self) |
|
657 | Magic.set_shell(self,self) | |
667 |
|
658 | |||
668 | # hooks holds pointers used for user-side customizations |
|
659 | # hooks holds pointers used for user-side customizations | |
669 | self.hooks = Struct() |
|
660 | self.hooks = Struct() | |
670 |
|
661 | |||
671 | # Set all default hooks, defined in the IPython.hooks module. |
|
662 | # Set all default hooks, defined in the IPython.hooks module. | |
672 | hooks = IPython.hooks |
|
663 | hooks = IPython.hooks | |
673 | for hook_name in hooks.__all__: |
|
664 | for hook_name in hooks.__all__: | |
674 | self.set_hook(hook_name,getattr(hooks,hook_name)) |
|
665 | self.set_hook(hook_name,getattr(hooks,hook_name)) | |
675 |
|
666 | |||
676 | # Flag to mark unconditional exit |
|
667 | # Flag to mark unconditional exit | |
677 | self.exit_now = False |
|
668 | self.exit_now = False | |
678 |
|
669 | |||
679 | self.usage_min = """\ |
|
670 | self.usage_min = """\ | |
680 | An enhanced console for Python. |
|
671 | An enhanced console for Python. | |
681 | Some of its features are: |
|
672 | Some of its features are: | |
682 | - Readline support if the readline library is present. |
|
673 | - Readline support if the readline library is present. | |
683 | - Tab completion in the local namespace. |
|
674 | - Tab completion in the local namespace. | |
684 | - Logging of input, see command-line options. |
|
675 | - Logging of input, see command-line options. | |
685 | - System shell escape via ! , eg !ls. |
|
676 | - System shell escape via ! , eg !ls. | |
686 | - Magic commands, starting with a % (like %ls, %pwd, %cd, etc.) |
|
677 | - Magic commands, starting with a % (like %ls, %pwd, %cd, etc.) | |
687 | - Keeps track of locally defined variables via %who, %whos. |
|
678 | - Keeps track of locally defined variables via %who, %whos. | |
688 | - Show object information with a ? eg ?x or x? (use ?? for more info). |
|
679 | - Show object information with a ? eg ?x or x? (use ?? for more info). | |
689 | """ |
|
680 | """ | |
690 | if usage: self.usage = usage |
|
681 | if usage: self.usage = usage | |
691 | else: self.usage = self.usage_min |
|
682 | else: self.usage = self.usage_min | |
692 |
|
683 | |||
693 | # Storage |
|
684 | # Storage | |
694 | self.rc = rc # This will hold all configuration information |
|
685 | self.rc = rc # This will hold all configuration information | |
695 | self.inputcache = [] |
|
686 | self.inputcache = [] | |
696 | self._boundcache = [] |
|
687 | self._boundcache = [] | |
697 | self.pager = 'less' |
|
688 | self.pager = 'less' | |
698 | # temporary files used for various purposes. Deleted at exit. |
|
689 | # temporary files used for various purposes. Deleted at exit. | |
699 | self.tempfiles = [] |
|
690 | self.tempfiles = [] | |
700 |
|
691 | |||
701 | # for pushd/popd management |
|
692 | # for pushd/popd management | |
702 | try: |
|
693 | try: | |
703 | self.home_dir = get_home_dir() |
|
694 | self.home_dir = get_home_dir() | |
704 | except HomeDirError,msg: |
|
695 | except HomeDirError,msg: | |
705 | fatal(msg) |
|
696 | fatal(msg) | |
706 |
|
697 | |||
707 | self.dir_stack = [os.getcwd().replace(self.home_dir,'~')] |
|
698 | self.dir_stack = [os.getcwd().replace(self.home_dir,'~')] | |
708 |
|
699 | |||
709 | # Functions to call the underlying shell. |
|
700 | # Functions to call the underlying shell. | |
710 |
|
701 | |||
711 | # utility to expand user variables via Itpl |
|
702 | # utility to expand user variables via Itpl | |
712 | self.var_expand = lambda cmd: str(ItplNS(cmd.replace('#','\#'), |
|
703 | self.var_expand = lambda cmd: str(ItplNS(cmd.replace('#','\#'), | |
713 | self.user_ns)) |
|
704 | self.user_ns)) | |
714 | # The first is similar to os.system, but it doesn't return a value, |
|
705 | # The first is similar to os.system, but it doesn't return a value, | |
715 | # and it allows interpolation of variables in the user's namespace. |
|
706 | # and it allows interpolation of variables in the user's namespace. | |
716 | self.system = lambda cmd: shell(self.var_expand(cmd), |
|
707 | self.system = lambda cmd: shell(self.var_expand(cmd), | |
717 | header='IPython system call: ', |
|
708 | header='IPython system call: ', | |
718 | verbose=self.rc.system_verbose) |
|
709 | verbose=self.rc.system_verbose) | |
719 | # These are for getoutput and getoutputerror: |
|
710 | # These are for getoutput and getoutputerror: | |
720 | self.getoutput = lambda cmd: \ |
|
711 | self.getoutput = lambda cmd: \ | |
721 | getoutput(self.var_expand(cmd), |
|
712 | getoutput(self.var_expand(cmd), | |
722 | header='IPython system call: ', |
|
713 | header='IPython system call: ', | |
723 | verbose=self.rc.system_verbose) |
|
714 | verbose=self.rc.system_verbose) | |
724 | self.getoutputerror = lambda cmd: \ |
|
715 | self.getoutputerror = lambda cmd: \ | |
725 | getoutputerror(str(ItplNS(cmd.replace('#','\#'), |
|
716 | getoutputerror(str(ItplNS(cmd.replace('#','\#'), | |
726 | self.user_ns)), |
|
717 | self.user_ns)), | |
727 | header='IPython system call: ', |
|
718 | header='IPython system call: ', | |
728 | verbose=self.rc.system_verbose) |
|
719 | verbose=self.rc.system_verbose) | |
729 |
|
720 | |||
730 | # RegExp for splitting line contents into pre-char//first |
|
721 | # RegExp for splitting line contents into pre-char//first | |
731 | # word-method//rest. For clarity, each group in on one line. |
|
722 | # word-method//rest. For clarity, each group in on one line. | |
732 |
|
723 | |||
733 | # WARNING: update the regexp if the above escapes are changed, as they |
|
724 | # WARNING: update the regexp if the above escapes are changed, as they | |
734 | # are hardwired in. |
|
725 | # are hardwired in. | |
735 |
|
726 | |||
736 | # Don't get carried away with trying to make the autocalling catch too |
|
727 | # Don't get carried away with trying to make the autocalling catch too | |
737 | # much: it's better to be conservative rather than to trigger hidden |
|
728 | # much: it's better to be conservative rather than to trigger hidden | |
738 | # evals() somewhere and end up causing side effects. |
|
729 | # evals() somewhere and end up causing side effects. | |
739 |
|
730 | |||
740 | self.line_split = re.compile(r'^([\s*,;/])' |
|
731 | self.line_split = re.compile(r'^([\s*,;/])' | |
741 | r'([\?\w\.]+\w*\s*)' |
|
732 | r'([\?\w\.]+\w*\s*)' | |
742 | r'(\(?.*$)') |
|
733 | r'(\(?.*$)') | |
743 |
|
734 | |||
744 | # Original re, keep around for a while in case changes break something |
|
735 | # Original re, keep around for a while in case changes break something | |
745 | #self.line_split = re.compile(r'(^[\s*!\?%,/]?)' |
|
736 | #self.line_split = re.compile(r'(^[\s*!\?%,/]?)' | |
746 | # r'(\s*[\?\w\.]+\w*\s*)' |
|
737 | # r'(\s*[\?\w\.]+\w*\s*)' | |
747 | # r'(\(?.*$)') |
|
738 | # r'(\(?.*$)') | |
748 |
|
739 | |||
749 | # RegExp to identify potential function names |
|
740 | # RegExp to identify potential function names | |
750 | self.re_fun_name = re.compile(r'[a-zA-Z_]([a-zA-Z0-9_.]*) *$') |
|
741 | self.re_fun_name = re.compile(r'[a-zA-Z_]([a-zA-Z0-9_.]*) *$') | |
751 | # RegExp to exclude strings with this start from autocalling |
|
742 | # RegExp to exclude strings with this start from autocalling | |
752 | self.re_exclude_auto = re.compile('^[!=()<>,\*/\+-]|^is ') |
|
743 | self.re_exclude_auto = re.compile('^[!=()<>,\*/\+-]|^is ') | |
753 | # try to catch also methods for stuff in lists/tuples/dicts: off |
|
744 | # try to catch also methods for stuff in lists/tuples/dicts: off | |
754 | # (experimental). For this to work, the line_split regexp would need |
|
745 | # (experimental). For this to work, the line_split regexp would need | |
755 | # to be modified so it wouldn't break things at '['. That line is |
|
746 | # to be modified so it wouldn't break things at '['. That line is | |
756 | # nasty enough that I shouldn't change it until I can test it _well_. |
|
747 | # nasty enough that I shouldn't change it until I can test it _well_. | |
757 | #self.re_fun_name = re.compile (r'[a-zA-Z_]([a-zA-Z0-9_.\[\]]*) ?$') |
|
748 | #self.re_fun_name = re.compile (r'[a-zA-Z_]([a-zA-Z0-9_.\[\]]*) ?$') | |
758 |
|
749 | |||
759 | # keep track of where we started running (mainly for crash post-mortem) |
|
750 | # keep track of where we started running (mainly for crash post-mortem) | |
760 | self.starting_dir = os.getcwd() |
|
751 | self.starting_dir = os.getcwd() | |
761 |
|
752 | |||
762 | # Attributes for Logger mixin class, make defaults here |
|
753 | # Attributes for Logger mixin class, make defaults here | |
763 | self._dolog = 0 |
|
754 | self._dolog = 0 | |
764 | self.LOG = '' |
|
755 | self.LOG = '' | |
765 | self.LOGDEF = '.InteractiveShell.log' |
|
756 | self.LOGDEF = '.InteractiveShell.log' | |
766 | self.LOGMODE = 'over' |
|
757 | self.LOGMODE = 'over' | |
767 | self.LOGHEAD = Itpl( |
|
758 | self.LOGHEAD = Itpl( | |
768 | """#log# Automatic Logger file. *** THIS MUST BE THE FIRST LINE *** |
|
759 | """#log# Automatic Logger file. *** THIS MUST BE THE FIRST LINE *** | |
769 | #log# DO NOT CHANGE THIS LINE OR THE TWO BELOW |
|
760 | #log# DO NOT CHANGE THIS LINE OR THE TWO BELOW | |
770 | #log# opts = $self.rc.opts |
|
761 | #log# opts = $self.rc.opts | |
771 | #log# args = $self.rc.args |
|
762 | #log# args = $self.rc.args | |
772 | #log# It is safe to make manual edits below here. |
|
763 | #log# It is safe to make manual edits below here. | |
773 | #log#----------------------------------------------------------------------- |
|
764 | #log#----------------------------------------------------------------------- | |
774 | """) |
|
765 | """) | |
775 | # Various switches which can be set |
|
766 | # Various switches which can be set | |
776 | self.CACHELENGTH = 5000 # this is cheap, it's just text |
|
767 | self.CACHELENGTH = 5000 # this is cheap, it's just text | |
777 | self.BANNER = "Python %(version)s on %(platform)s\n" % sys.__dict__ |
|
768 | self.BANNER = "Python %(version)s on %(platform)s\n" % sys.__dict__ | |
778 | self.banner2 = banner2 |
|
769 | self.banner2 = banner2 | |
779 |
|
770 | |||
780 | # TraceBack handlers: |
|
771 | # TraceBack handlers: | |
781 | # Need two, one for syntax errors and one for other exceptions. |
|
772 | # Need two, one for syntax errors and one for other exceptions. | |
782 | self.SyntaxTB = ultraTB.ListTB(color_scheme='NoColor') |
|
773 | self.SyntaxTB = ultraTB.ListTB(color_scheme='NoColor') | |
783 | # This one is initialized with an offset, meaning we always want to |
|
774 | # This one is initialized with an offset, meaning we always want to | |
784 | # remove the topmost item in the traceback, which is our own internal |
|
775 | # remove the topmost item in the traceback, which is our own internal | |
785 | # code. Valid modes: ['Plain','Context','Verbose'] |
|
776 | # code. Valid modes: ['Plain','Context','Verbose'] | |
786 | self.InteractiveTB = ultraTB.AutoFormattedTB(mode = 'Plain', |
|
777 | self.InteractiveTB = ultraTB.AutoFormattedTB(mode = 'Plain', | |
787 | color_scheme='NoColor', |
|
778 | color_scheme='NoColor', | |
788 | tb_offset = 1) |
|
779 | tb_offset = 1) | |
789 | # and add any custom exception handlers the user may have specified |
|
780 | # and add any custom exception handlers the user may have specified | |
790 | self.set_custom_exc(*custom_exceptions) |
|
781 | self.set_custom_exc(*custom_exceptions) | |
791 |
|
782 | |||
792 | # Object inspector |
|
783 | # Object inspector | |
793 | ins_colors = OInspect.InspectColors |
|
784 | ins_colors = OInspect.InspectColors | |
794 | code_colors = PyColorize.ANSICodeColors |
|
785 | code_colors = PyColorize.ANSICodeColors | |
795 | self.inspector = OInspect.Inspector(ins_colors,code_colors,'NoColor') |
|
786 | self.inspector = OInspect.Inspector(ins_colors,code_colors,'NoColor') | |
796 | self.autoindent = 0 |
|
787 | self.autoindent = 0 | |
797 |
|
788 | |||
798 | # Make some aliases automatically |
|
789 | # Make some aliases automatically | |
799 | # Prepare list of shell aliases to auto-define |
|
790 | # Prepare list of shell aliases to auto-define | |
800 | if os.name == 'posix': |
|
791 | if os.name == 'posix': | |
801 | auto_alias = ('mkdir mkdir', 'rmdir rmdir', |
|
792 | auto_alias = ('mkdir mkdir', 'rmdir rmdir', | |
802 | 'mv mv -i','rm rm -i','cp cp -i', |
|
793 | 'mv mv -i','rm rm -i','cp cp -i', | |
803 | 'cat cat','less less','clear clear', |
|
794 | 'cat cat','less less','clear clear', | |
804 | # a better ls |
|
795 | # a better ls | |
805 | 'ls ls -F', |
|
796 | 'ls ls -F', | |
806 | # long ls |
|
797 | # long ls | |
807 | 'll ls -lF', |
|
798 | 'll ls -lF', | |
808 | # color ls |
|
799 | # color ls | |
809 | 'lc ls -F -o --color', |
|
800 | 'lc ls -F -o --color', | |
810 | # ls normal files only |
|
801 | # ls normal files only | |
811 | 'lf ls -F -o --color %l | grep ^-', |
|
802 | 'lf ls -F -o --color %l | grep ^-', | |
812 | # ls symbolic links |
|
803 | # ls symbolic links | |
813 | 'lk ls -F -o --color %l | grep ^l', |
|
804 | 'lk ls -F -o --color %l | grep ^l', | |
814 | # directories or links to directories, |
|
805 | # directories or links to directories, | |
815 | 'ldir ls -F -o --color %l | grep /$', |
|
806 | 'ldir ls -F -o --color %l | grep /$', | |
816 | # things which are executable |
|
807 | # things which are executable | |
817 | 'lx ls -F -o --color %l | grep ^-..x', |
|
808 | 'lx ls -F -o --color %l | grep ^-..x', | |
818 | ) |
|
809 | ) | |
819 | elif os.name in ['nt','dos']: |
|
810 | elif os.name in ['nt','dos']: | |
820 | auto_alias = ('dir dir /on', 'ls dir /on', |
|
811 | auto_alias = ('dir dir /on', 'ls dir /on', | |
821 | 'ddir dir /ad /on', 'ldir dir /ad /on', |
|
812 | 'ddir dir /ad /on', 'ldir dir /ad /on', | |
822 | 'mkdir mkdir','rmdir rmdir','echo echo', |
|
813 | 'mkdir mkdir','rmdir rmdir','echo echo', | |
823 | 'ren ren','cls cls','copy copy') |
|
814 | 'ren ren','cls cls','copy copy') | |
824 | else: |
|
815 | else: | |
825 | auto_alias = () |
|
816 | auto_alias = () | |
826 | self.auto_alias = map(lambda s:s.split(None,1),auto_alias) |
|
817 | self.auto_alias = map(lambda s:s.split(None,1),auto_alias) | |
827 | # Call the actual (public) initializer |
|
818 | # Call the actual (public) initializer | |
828 | self.init_auto_alias() |
|
819 | self.init_auto_alias() | |
829 | # end __init__ |
|
820 | # end __init__ | |
830 |
|
821 | |||
831 | def set_hook(self,name,hook): |
|
822 | def set_hook(self,name,hook): | |
832 | """set_hook(name,hook) -> sets an internal IPython hook. |
|
823 | """set_hook(name,hook) -> sets an internal IPython hook. | |
833 |
|
824 | |||
834 | IPython exposes some of its internal API as user-modifiable hooks. By |
|
825 | IPython exposes some of its internal API as user-modifiable hooks. By | |
835 | resetting one of these hooks, you can modify IPython's behavior to |
|
826 | resetting one of these hooks, you can modify IPython's behavior to | |
836 | call at runtime your own routines.""" |
|
827 | call at runtime your own routines.""" | |
837 |
|
828 | |||
838 | # At some point in the future, this should validate the hook before it |
|
829 | # At some point in the future, this should validate the hook before it | |
839 | # accepts it. Probably at least check that the hook takes the number |
|
830 | # accepts it. Probably at least check that the hook takes the number | |
840 | # of args it's supposed to. |
|
831 | # of args it's supposed to. | |
841 | setattr(self.hooks,name,new.instancemethod(hook,self,self.__class__)) |
|
832 | setattr(self.hooks,name,new.instancemethod(hook,self,self.__class__)) | |
842 |
|
833 | |||
843 | def set_custom_exc(self,exc_tuple,handler): |
|
834 | def set_custom_exc(self,exc_tuple,handler): | |
844 | """set_custom_exc(exc_tuple,handler) |
|
835 | """set_custom_exc(exc_tuple,handler) | |
845 |
|
836 | |||
846 | Set a custom exception handler, which will be called if any of the |
|
837 | Set a custom exception handler, which will be called if any of the | |
847 | exceptions in exc_tuple occur in the mainloop (specifically, in the |
|
838 | exceptions in exc_tuple occur in the mainloop (specifically, in the | |
848 | runcode() method. |
|
839 | runcode() method. | |
849 |
|
840 | |||
850 | Inputs: |
|
841 | Inputs: | |
851 |
|
842 | |||
852 | - exc_tuple: a *tuple* of valid exceptions to call the defined |
|
843 | - exc_tuple: a *tuple* of valid exceptions to call the defined | |
853 | handler for. It is very important that you use a tuple, and NOT A |
|
844 | handler for. It is very important that you use a tuple, and NOT A | |
854 | LIST here, because of the way Python's except statement works. If |
|
845 | LIST here, because of the way Python's except statement works. If | |
855 | you only want to trap a single exception, use a singleton tuple: |
|
846 | you only want to trap a single exception, use a singleton tuple: | |
856 |
|
847 | |||
857 | exc_tuple == (MyCustomException,) |
|
848 | exc_tuple == (MyCustomException,) | |
858 |
|
849 | |||
859 | - handler: this must be defined as a function with the following |
|
850 | - handler: this must be defined as a function with the following | |
860 | basic interface: def my_handler(self,etype,value,tb). |
|
851 | basic interface: def my_handler(self,etype,value,tb). | |
861 |
|
852 | |||
862 | This will be made into an instance method (via new.instancemethod) |
|
853 | This will be made into an instance method (via new.instancemethod) | |
863 | of IPython itself, and it will be called if any of the exceptions |
|
854 | of IPython itself, and it will be called if any of the exceptions | |
864 | listed in the exc_tuple are caught. If the handler is None, an |
|
855 | listed in the exc_tuple are caught. If the handler is None, an | |
865 | internal basic one is used, which just prints basic info. |
|
856 | internal basic one is used, which just prints basic info. | |
866 |
|
857 | |||
867 | WARNING: by putting in your own exception handler into IPython's main |
|
858 | WARNING: by putting in your own exception handler into IPython's main | |
868 | execution loop, you run a very good chance of nasty crashes. This |
|
859 | execution loop, you run a very good chance of nasty crashes. This | |
869 | facility should only be used if you really know what you are doing.""" |
|
860 | facility should only be used if you really know what you are doing.""" | |
870 |
|
861 | |||
871 | assert type(exc_tuple)==type(()) , \ |
|
862 | assert type(exc_tuple)==type(()) , \ | |
872 | "The custom exceptions must be given AS A TUPLE." |
|
863 | "The custom exceptions must be given AS A TUPLE." | |
873 |
|
864 | |||
874 | def dummy_handler(self,etype,value,tb): |
|
865 | def dummy_handler(self,etype,value,tb): | |
875 | print '*** Simple custom exception handler ***' |
|
866 | print '*** Simple custom exception handler ***' | |
876 | print 'Exception type :',etype |
|
867 | print 'Exception type :',etype | |
877 | print 'Exception value:',value |
|
868 | print 'Exception value:',value | |
878 | print 'Traceback :',tb |
|
869 | print 'Traceback :',tb | |
879 | print 'Source code :',self.code_to_run_src |
|
870 | print 'Source code :',self.code_to_run_src | |
880 |
|
871 | |||
881 | if handler is None: handler = dummy_handler |
|
872 | if handler is None: handler = dummy_handler | |
882 |
|
873 | |||
883 | self.CustomTB = new.instancemethod(handler,self,self.__class__) |
|
874 | self.CustomTB = new.instancemethod(handler,self,self.__class__) | |
884 | self.custom_exceptions = exc_tuple |
|
875 | self.custom_exceptions = exc_tuple | |
885 |
|
876 | |||
886 | def set_custom_completer(self,completer,pos=0): |
|
877 | def set_custom_completer(self,completer,pos=0): | |
887 | """set_custom_completer(completer,pos=0) |
|
878 | """set_custom_completer(completer,pos=0) | |
888 |
|
879 | |||
889 | Adds a new custom completer function. |
|
880 | Adds a new custom completer function. | |
890 |
|
881 | |||
891 | The position argument (defaults to 0) is the index in the completers |
|
882 | The position argument (defaults to 0) is the index in the completers | |
892 | list where you want the completer to be inserted.""" |
|
883 | list where you want the completer to be inserted.""" | |
893 |
|
884 | |||
894 | newcomp = new.instancemethod(completer,self.Completer, |
|
885 | newcomp = new.instancemethod(completer,self.Completer, | |
895 | self.Completer.__class__) |
|
886 | self.Completer.__class__) | |
896 | self.Completer.matchers.insert(pos,newcomp) |
|
887 | self.Completer.matchers.insert(pos,newcomp) | |
897 |
|
888 | |||
898 | def post_config_initialization(self): |
|
889 | def post_config_initialization(self): | |
899 | """Post configuration init method |
|
890 | """Post configuration init method | |
900 |
|
891 | |||
901 | This is called after the configuration files have been processed to |
|
892 | This is called after the configuration files have been processed to | |
902 | 'finalize' the initialization.""" |
|
893 | 'finalize' the initialization.""" | |
903 |
|
894 | |||
904 | # dynamic data that survives through sessions |
|
895 | # dynamic data that survives through sessions | |
905 | # XXX make the filename a config option? |
|
896 | # XXX make the filename a config option? | |
906 | persist_base = 'persist' |
|
897 | persist_base = 'persist' | |
907 | if self.rc.profile: |
|
898 | if self.rc.profile: | |
908 | persist_base += '_%s' % self.rc.profile |
|
899 | persist_base += '_%s' % self.rc.profile | |
909 | self.persist_fname = os.path.join(self.rc.ipythondir,persist_base) |
|
900 | self.persist_fname = os.path.join(self.rc.ipythondir,persist_base) | |
910 |
|
901 | |||
911 | try: |
|
902 | try: | |
912 | self.persist = pickle.load(file(self.persist_fname)) |
|
903 | self.persist = pickle.load(file(self.persist_fname)) | |
913 | except: |
|
904 | except: | |
914 | self.persist = {} |
|
905 | self.persist = {} | |
915 |
|
906 | |||
916 | def init_auto_alias(self): |
|
907 | def init_auto_alias(self): | |
917 | """Define some aliases automatically. |
|
908 | """Define some aliases automatically. | |
918 |
|
909 | |||
919 | These are ALL parameter-less aliases""" |
|
910 | These are ALL parameter-less aliases""" | |
920 | for alias,cmd in self.auto_alias: |
|
911 | for alias,cmd in self.auto_alias: | |
921 | self.alias_table[alias] = (0,cmd) |
|
912 | self.alias_table[alias] = (0,cmd) | |
922 |
|
913 | |||
923 | def alias_table_validate(self,verbose=0): |
|
914 | def alias_table_validate(self,verbose=0): | |
924 | """Update information about the alias table. |
|
915 | """Update information about the alias table. | |
925 |
|
916 | |||
926 | In particular, make sure no Python keywords/builtins are in it.""" |
|
917 | In particular, make sure no Python keywords/builtins are in it.""" | |
927 |
|
918 | |||
928 | no_alias = self.no_alias |
|
919 | no_alias = self.no_alias | |
929 | for k in self.alias_table.keys(): |
|
920 | for k in self.alias_table.keys(): | |
930 | if k in no_alias: |
|
921 | if k in no_alias: | |
931 | del self.alias_table[k] |
|
922 | del self.alias_table[k] | |
932 | if verbose: |
|
923 | if verbose: | |
933 | print ("Deleting alias <%s>, it's a Python " |
|
924 | print ("Deleting alias <%s>, it's a Python " | |
934 | "keyword or builtin." % k) |
|
925 | "keyword or builtin." % k) | |
935 |
|
926 | |||
936 | def set_autoindent(self,value=None): |
|
927 | def set_autoindent(self,value=None): | |
937 | """Set the autoindent flag, checking for readline support. |
|
928 | """Set the autoindent flag, checking for readline support. | |
938 |
|
929 | |||
939 | If called with no arguments, it acts as a toggle.""" |
|
930 | If called with no arguments, it acts as a toggle.""" | |
940 |
|
931 | |||
941 | if not self.has_readline: |
|
932 | if not self.has_readline: | |
942 | if os.name == 'posix': |
|
933 | if os.name == 'posix': | |
943 | warn("The auto-indent feature requires the readline library") |
|
934 | warn("The auto-indent feature requires the readline library") | |
944 | self.autoindent = 0 |
|
935 | self.autoindent = 0 | |
945 | return |
|
936 | return | |
946 | if value is None: |
|
937 | if value is None: | |
947 | self.autoindent = not self.autoindent |
|
938 | self.autoindent = not self.autoindent | |
948 | else: |
|
939 | else: | |
949 | self.autoindent = value |
|
940 | self.autoindent = value | |
950 |
|
941 | |||
951 | def rc_set_toggle(self,rc_field,value=None): |
|
942 | def rc_set_toggle(self,rc_field,value=None): | |
952 | """Set or toggle a field in IPython's rc config. structure. |
|
943 | """Set or toggle a field in IPython's rc config. structure. | |
953 |
|
944 | |||
954 | If called with no arguments, it acts as a toggle. |
|
945 | If called with no arguments, it acts as a toggle. | |
955 |
|
946 | |||
956 | If called with a non-existent field, the resulting AttributeError |
|
947 | If called with a non-existent field, the resulting AttributeError | |
957 | exception will propagate out.""" |
|
948 | exception will propagate out.""" | |
958 |
|
949 | |||
959 | rc_val = getattr(self.rc,rc_field) |
|
950 | rc_val = getattr(self.rc,rc_field) | |
960 | if value is None: |
|
951 | if value is None: | |
961 | value = not rc_val |
|
952 | value = not rc_val | |
962 | setattr(self.rc,rc_field,value) |
|
953 | setattr(self.rc,rc_field,value) | |
963 |
|
954 | |||
964 | def user_setup(self,ipythondir,rc_suffix,mode='install'): |
|
955 | def user_setup(self,ipythondir,rc_suffix,mode='install'): | |
965 | """Install the user configuration directory. |
|
956 | """Install the user configuration directory. | |
966 |
|
957 | |||
967 | Can be called when running for the first time or to upgrade the user's |
|
958 | Can be called when running for the first time or to upgrade the user's | |
968 | .ipython/ directory with the mode parameter. Valid modes are 'install' |
|
959 | .ipython/ directory with the mode parameter. Valid modes are 'install' | |
969 | and 'upgrade'.""" |
|
960 | and 'upgrade'.""" | |
970 |
|
961 | |||
971 | def wait(): |
|
962 | def wait(): | |
972 | try: |
|
963 | try: | |
973 | raw_input("Please press <RETURN> to start IPython.") |
|
964 | raw_input("Please press <RETURN> to start IPython.") | |
974 | except EOFError: |
|
965 | except EOFError: | |
975 | print >> Term.cout |
|
966 | print >> Term.cout | |
976 | print '*'*70 |
|
967 | print '*'*70 | |
977 |
|
968 | |||
978 | cwd = os.getcwd() # remember where we started |
|
969 | cwd = os.getcwd() # remember where we started | |
979 | glb = glob.glob |
|
970 | glb = glob.glob | |
980 | print '*'*70 |
|
971 | print '*'*70 | |
981 | if mode == 'install': |
|
972 | if mode == 'install': | |
982 | print \ |
|
973 | print \ | |
983 | """Welcome to IPython. I will try to create a personal configuration directory |
|
974 | """Welcome to IPython. I will try to create a personal configuration directory | |
984 | where you can customize many aspects of IPython's functionality in:\n""" |
|
975 | where you can customize many aspects of IPython's functionality in:\n""" | |
985 | else: |
|
976 | else: | |
986 | print 'I am going to upgrade your configuration in:' |
|
977 | print 'I am going to upgrade your configuration in:' | |
987 |
|
978 | |||
988 | print ipythondir |
|
979 | print ipythondir | |
989 |
|
980 | |||
990 | rcdirend = os.path.join('IPython','UserConfig') |
|
981 | rcdirend = os.path.join('IPython','UserConfig') | |
991 | cfg = lambda d: os.path.join(d,rcdirend) |
|
982 | cfg = lambda d: os.path.join(d,rcdirend) | |
992 | try: |
|
983 | try: | |
993 | rcdir = filter(os.path.isdir,map(cfg,sys.path))[0] |
|
984 | rcdir = filter(os.path.isdir,map(cfg,sys.path))[0] | |
994 | except IOError: |
|
985 | except IOError: | |
995 | warning = """ |
|
986 | warning = """ | |
996 | Installation error. IPython's directory was not found. |
|
987 | Installation error. IPython's directory was not found. | |
997 |
|
988 | |||
998 | Check the following: |
|
989 | Check the following: | |
999 |
|
990 | |||
1000 | The ipython/IPython directory should be in a directory belonging to your |
|
991 | The ipython/IPython directory should be in a directory belonging to your | |
1001 | PYTHONPATH environment variable (that is, it should be in a directory |
|
992 | PYTHONPATH environment variable (that is, it should be in a directory | |
1002 | belonging to sys.path). You can copy it explicitly there or just link to it. |
|
993 | belonging to sys.path). You can copy it explicitly there or just link to it. | |
1003 |
|
994 | |||
1004 | IPython will proceed with builtin defaults. |
|
995 | IPython will proceed with builtin defaults. | |
1005 | """ |
|
996 | """ | |
1006 | warn(warning) |
|
997 | warn(warning) | |
1007 | wait() |
|
998 | wait() | |
1008 | return |
|
999 | return | |
1009 |
|
1000 | |||
1010 | if mode == 'install': |
|
1001 | if mode == 'install': | |
1011 | try: |
|
1002 | try: | |
1012 | shutil.copytree(rcdir,ipythondir) |
|
1003 | shutil.copytree(rcdir,ipythondir) | |
1013 | os.chdir(ipythondir) |
|
1004 | os.chdir(ipythondir) | |
1014 | rc_files = glb("ipythonrc*") |
|
1005 | rc_files = glb("ipythonrc*") | |
1015 | for rc_file in rc_files: |
|
1006 | for rc_file in rc_files: | |
1016 | os.rename(rc_file,rc_file+rc_suffix) |
|
1007 | os.rename(rc_file,rc_file+rc_suffix) | |
1017 | except: |
|
1008 | except: | |
1018 | warning = """ |
|
1009 | warning = """ | |
1019 |
|
1010 | |||
1020 | There was a problem with the installation: |
|
1011 | There was a problem with the installation: | |
1021 | %s |
|
1012 | %s | |
1022 | Try to correct it or contact the developers if you think it's a bug. |
|
1013 | Try to correct it or contact the developers if you think it's a bug. | |
1023 | IPython will proceed with builtin defaults.""" % sys.exc_info()[1] |
|
1014 | IPython will proceed with builtin defaults.""" % sys.exc_info()[1] | |
1024 | warn(warning) |
|
1015 | warn(warning) | |
1025 | wait() |
|
1016 | wait() | |
1026 | return |
|
1017 | return | |
1027 |
|
1018 | |||
1028 | elif mode == 'upgrade': |
|
1019 | elif mode == 'upgrade': | |
1029 | try: |
|
1020 | try: | |
1030 | os.chdir(ipythondir) |
|
1021 | os.chdir(ipythondir) | |
1031 | except: |
|
1022 | except: | |
1032 | print """ |
|
1023 | print """ | |
1033 | Can not upgrade: changing to directory %s failed. Details: |
|
1024 | Can not upgrade: changing to directory %s failed. Details: | |
1034 | %s |
|
1025 | %s | |
1035 | """ % (ipythondir,sys.exc_info()[1]) |
|
1026 | """ % (ipythondir,sys.exc_info()[1]) | |
1036 | wait() |
|
1027 | wait() | |
1037 | return |
|
1028 | return | |
1038 | else: |
|
1029 | else: | |
1039 | sources = glb(os.path.join(rcdir,'[A-Za-z]*')) |
|
1030 | sources = glb(os.path.join(rcdir,'[A-Za-z]*')) | |
1040 | for new_full_path in sources: |
|
1031 | for new_full_path in sources: | |
1041 | new_filename = os.path.basename(new_full_path) |
|
1032 | new_filename = os.path.basename(new_full_path) | |
1042 | if new_filename.startswith('ipythonrc'): |
|
1033 | if new_filename.startswith('ipythonrc'): | |
1043 | new_filename = new_filename + rc_suffix |
|
1034 | new_filename = new_filename + rc_suffix | |
1044 | # The config directory should only contain files, skip any |
|
1035 | # The config directory should only contain files, skip any | |
1045 | # directories which may be there (like CVS) |
|
1036 | # directories which may be there (like CVS) | |
1046 | if os.path.isdir(new_full_path): |
|
1037 | if os.path.isdir(new_full_path): | |
1047 | continue |
|
1038 | continue | |
1048 | if os.path.exists(new_filename): |
|
1039 | if os.path.exists(new_filename): | |
1049 | old_file = new_filename+'.old' |
|
1040 | old_file = new_filename+'.old' | |
1050 | if os.path.exists(old_file): |
|
1041 | if os.path.exists(old_file): | |
1051 | os.remove(old_file) |
|
1042 | os.remove(old_file) | |
1052 | os.rename(new_filename,old_file) |
|
1043 | os.rename(new_filename,old_file) | |
1053 | shutil.copy(new_full_path,new_filename) |
|
1044 | shutil.copy(new_full_path,new_filename) | |
1054 | else: |
|
1045 | else: | |
1055 | raise ValueError,'unrecognized mode for install:',`mode` |
|
1046 | raise ValueError,'unrecognized mode for install:',`mode` | |
1056 |
|
1047 | |||
1057 | # Fix line-endings to those native to each platform in the config |
|
1048 | # Fix line-endings to those native to each platform in the config | |
1058 | # directory. |
|
1049 | # directory. | |
1059 | try: |
|
1050 | try: | |
1060 | os.chdir(ipythondir) |
|
1051 | os.chdir(ipythondir) | |
1061 | except: |
|
1052 | except: | |
1062 | print """ |
|
1053 | print """ | |
1063 | Problem: changing to directory %s failed. |
|
1054 | Problem: changing to directory %s failed. | |
1064 | Details: |
|
1055 | Details: | |
1065 | %s |
|
1056 | %s | |
1066 |
|
1057 | |||
1067 | Some configuration files may have incorrect line endings. This should not |
|
1058 | Some configuration files may have incorrect line endings. This should not | |
1068 | cause any problems during execution. """ % (ipythondir,sys.exc_info()[1]) |
|
1059 | cause any problems during execution. """ % (ipythondir,sys.exc_info()[1]) | |
1069 | wait() |
|
1060 | wait() | |
1070 | else: |
|
1061 | else: | |
1071 | for fname in glb('ipythonrc*'): |
|
1062 | for fname in glb('ipythonrc*'): | |
1072 | try: |
|
1063 | try: | |
1073 | native_line_ends(fname,backup=0) |
|
1064 | native_line_ends(fname,backup=0) | |
1074 | except IOError: |
|
1065 | except IOError: | |
1075 | pass |
|
1066 | pass | |
1076 |
|
1067 | |||
1077 | if mode == 'install': |
|
1068 | if mode == 'install': | |
1078 | print """ |
|
1069 | print """ | |
1079 | Successful installation! |
|
1070 | Successful installation! | |
1080 |
|
1071 | |||
1081 | Please read the sections 'Initial Configuration' and 'Quick Tips' in the |
|
1072 | Please read the sections 'Initial Configuration' and 'Quick Tips' in the | |
1082 | IPython manual (there are both HTML and PDF versions supplied with the |
|
1073 | IPython manual (there are both HTML and PDF versions supplied with the | |
1083 | distribution) to make sure that your system environment is properly configured |
|
1074 | distribution) to make sure that your system environment is properly configured | |
1084 | to take advantage of IPython's features.""" |
|
1075 | to take advantage of IPython's features.""" | |
1085 | else: |
|
1076 | else: | |
1086 | print """ |
|
1077 | print """ | |
1087 | Successful upgrade! |
|
1078 | Successful upgrade! | |
1088 |
|
1079 | |||
1089 | All files in your directory: |
|
1080 | All files in your directory: | |
1090 | %(ipythondir)s |
|
1081 | %(ipythondir)s | |
1091 | which would have been overwritten by the upgrade were backed up with a .old |
|
1082 | which would have been overwritten by the upgrade were backed up with a .old | |
1092 | extension. If you had made particular customizations in those files you may |
|
1083 | extension. If you had made particular customizations in those files you may | |
1093 | want to merge them back into the new files.""" % locals() |
|
1084 | want to merge them back into the new files.""" % locals() | |
1094 | wait() |
|
1085 | wait() | |
1095 | os.chdir(cwd) |
|
1086 | os.chdir(cwd) | |
1096 | # end user_setup() |
|
1087 | # end user_setup() | |
1097 |
|
1088 | |||
1098 | def atexit_operations(self): |
|
1089 | def atexit_operations(self): | |
1099 | """This will be executed at the time of exit. |
|
1090 | """This will be executed at the time of exit. | |
1100 |
|
1091 | |||
1101 | Saving of persistent data should be performed here. """ |
|
1092 | Saving of persistent data should be performed here. """ | |
1102 |
|
1093 | |||
1103 | # input history |
|
1094 | # input history | |
1104 | self.savehist() |
|
1095 | self.savehist() | |
1105 |
|
1096 | |||
1106 | # Cleanup all tempfiles left around |
|
1097 | # Cleanup all tempfiles left around | |
1107 | for tfile in self.tempfiles: |
|
1098 | for tfile in self.tempfiles: | |
1108 | try: |
|
1099 | try: | |
1109 | os.unlink(tfile) |
|
1100 | os.unlink(tfile) | |
1110 | except OSError: |
|
1101 | except OSError: | |
1111 | pass |
|
1102 | pass | |
1112 |
|
1103 | |||
1113 | # save the "persistent data" catch-all dictionary |
|
1104 | # save the "persistent data" catch-all dictionary | |
1114 | try: |
|
1105 | try: | |
1115 | pickle.dump(self.persist, open(self.persist_fname,"w")) |
|
1106 | pickle.dump(self.persist, open(self.persist_fname,"w")) | |
1116 | except: |
|
1107 | except: | |
1117 | print "*** ERROR *** persistent data saving failed." |
|
1108 | print "*** ERROR *** persistent data saving failed." | |
1118 |
|
1109 | |||
1119 | def savehist(self): |
|
1110 | def savehist(self): | |
1120 | """Save input history to a file (via readline library).""" |
|
1111 | """Save input history to a file (via readline library).""" | |
1121 | try: |
|
1112 | try: | |
1122 | self.readline.write_history_file(self.histfile) |
|
1113 | self.readline.write_history_file(self.histfile) | |
1123 | except: |
|
1114 | except: | |
1124 | print 'Unable to save IPython command history to file: ' + \ |
|
1115 | print 'Unable to save IPython command history to file: ' + \ | |
1125 | `self.histfile` |
|
1116 | `self.histfile` | |
1126 |
|
1117 | |||
1127 | def pre_readline(self): |
|
1118 | def pre_readline(self): | |
1128 | """readline hook to be used at the start of each line. |
|
1119 | """readline hook to be used at the start of each line. | |
1129 |
|
1120 | |||
1130 | Currently it handles auto-indent only.""" |
|
1121 | Currently it handles auto-indent only.""" | |
1131 |
|
1122 | |||
1132 | self.readline.insert_text(' '* self.readline_indent) |
|
1123 | self.readline.insert_text(' '* self.readline_indent) | |
1133 |
|
1124 | |||
1134 | def init_readline(self): |
|
1125 | def init_readline(self): | |
1135 | """Command history completion/saving/reloading.""" |
|
1126 | """Command history completion/saving/reloading.""" | |
1136 | try: |
|
1127 | try: | |
1137 | import readline |
|
1128 | import readline | |
1138 | self.Completer = MagicCompleter(self, |
|
1129 | self.Completer = MagicCompleter(self, | |
1139 | self.user_ns, |
|
1130 | self.user_ns, | |
1140 | self.rc.readline_omit__names, |
|
1131 | self.rc.readline_omit__names, | |
1141 | self.alias_table) |
|
1132 | self.alias_table) | |
1142 | except ImportError,NameError: |
|
1133 | except ImportError,NameError: | |
1143 | # If FlexCompleter failed to import, MagicCompleter won't be |
|
1134 | # If FlexCompleter failed to import, MagicCompleter won't be | |
1144 | # defined. This can happen because of a problem with readline |
|
1135 | # defined. This can happen because of a problem with readline | |
1145 | self.has_readline = 0 |
|
1136 | self.has_readline = 0 | |
1146 | # no point in bugging windows users with this every time: |
|
1137 | # no point in bugging windows users with this every time: | |
1147 | if os.name == 'posix': |
|
1138 | if os.name == 'posix': | |
1148 | warn('Readline services not available on this platform.') |
|
1139 | warn('Readline services not available on this platform.') | |
1149 | else: |
|
1140 | else: | |
1150 | import atexit |
|
1141 | import atexit | |
1151 |
|
1142 | |||
1152 | # Platform-specific configuration |
|
1143 | # Platform-specific configuration | |
1153 | if os.name == 'nt': |
|
1144 | if os.name == 'nt': | |
1154 | # readline under Windows modifies the default exit behavior |
|
1145 | # readline under Windows modifies the default exit behavior | |
1155 | # from being Ctrl-Z/Return to the Unix Ctrl-D one. |
|
1146 | # from being Ctrl-Z/Return to the Unix Ctrl-D one. | |
1156 | __builtin__.exit = __builtin__.quit = \ |
|
1147 | __builtin__.exit = __builtin__.quit = \ | |
1157 | ('Use Ctrl-D (i.e. EOF) to exit. ' |
|
1148 | ('Use Ctrl-D (i.e. EOF) to exit. ' | |
1158 | 'Use %Exit or %Quit to exit without confirmation.') |
|
1149 | 'Use %Exit or %Quit to exit without confirmation.') | |
1159 | self.readline_startup_hook = readline.set_pre_input_hook |
|
1150 | self.readline_startup_hook = readline.set_pre_input_hook | |
1160 | else: |
|
1151 | else: | |
1161 | self.readline_startup_hook = readline.set_startup_hook |
|
1152 | self.readline_startup_hook = readline.set_startup_hook | |
1162 |
|
1153 | |||
1163 | # Load user's initrc file (readline config) |
|
1154 | # Load user's initrc file (readline config) | |
1164 | inputrc_name = os.environ.get('INPUTRC') |
|
1155 | inputrc_name = os.environ.get('INPUTRC') | |
1165 | if inputrc_name is None: |
|
1156 | if inputrc_name is None: | |
1166 | home_dir = get_home_dir() |
|
1157 | home_dir = get_home_dir() | |
1167 | if home_dir is not None: |
|
1158 | if home_dir is not None: | |
1168 | inputrc_name = os.path.join(home_dir,'.inputrc') |
|
1159 | inputrc_name = os.path.join(home_dir,'.inputrc') | |
1169 | if os.path.isfile(inputrc_name): |
|
1160 | if os.path.isfile(inputrc_name): | |
1170 | try: |
|
1161 | try: | |
1171 | readline.read_init_file(inputrc_name) |
|
1162 | readline.read_init_file(inputrc_name) | |
1172 | except: |
|
1163 | except: | |
1173 | warn('Problems reading readline initialization file <%s>' |
|
1164 | warn('Problems reading readline initialization file <%s>' | |
1174 | % inputrc_name) |
|
1165 | % inputrc_name) | |
1175 |
|
1166 | |||
1176 | self.has_readline = 1 |
|
1167 | self.has_readline = 1 | |
1177 | self.readline = readline |
|
1168 | self.readline = readline | |
1178 | self.readline_indent = 0 # for auto-indenting via readline |
|
1169 | self.readline_indent = 0 # for auto-indenting via readline | |
1179 | # save this in sys so embedded copies can restore it properly |
|
1170 | # save this in sys so embedded copies can restore it properly | |
1180 | sys.ipcompleter = self.Completer.complete |
|
1171 | sys.ipcompleter = self.Completer.complete | |
1181 | readline.set_completer(self.Completer.complete) |
|
1172 | readline.set_completer(self.Completer.complete) | |
1182 |
|
1173 | |||
1183 | # Configure readline according to user's prefs |
|
1174 | # Configure readline according to user's prefs | |
1184 | for rlcommand in self.rc.readline_parse_and_bind: |
|
1175 | for rlcommand in self.rc.readline_parse_and_bind: | |
1185 | readline.parse_and_bind(rlcommand) |
|
1176 | readline.parse_and_bind(rlcommand) | |
1186 |
|
1177 | |||
1187 | # remove some chars from the delimiters list |
|
1178 | # remove some chars from the delimiters list | |
1188 | delims = readline.get_completer_delims() |
|
1179 | delims = readline.get_completer_delims() | |
1189 | delims = delims.translate(string._idmap, |
|
1180 | delims = delims.translate(string._idmap, | |
1190 | self.rc.readline_remove_delims) |
|
1181 | self.rc.readline_remove_delims) | |
1191 | readline.set_completer_delims(delims) |
|
1182 | readline.set_completer_delims(delims) | |
1192 | # otherwise we end up with a monster history after a while: |
|
1183 | # otherwise we end up with a monster history after a while: | |
1193 | readline.set_history_length(1000) |
|
1184 | readline.set_history_length(1000) | |
1194 | try: |
|
1185 | try: | |
1195 | #print '*** Reading readline history' # dbg |
|
1186 | #print '*** Reading readline history' # dbg | |
1196 | readline.read_history_file(self.histfile) |
|
1187 | readline.read_history_file(self.histfile) | |
1197 | except IOError: |
|
1188 | except IOError: | |
1198 | pass # It doesn't exist yet. |
|
1189 | pass # It doesn't exist yet. | |
1199 |
|
1190 | |||
1200 | atexit.register(self.atexit_operations) |
|
1191 | atexit.register(self.atexit_operations) | |
1201 | del atexit |
|
1192 | del atexit | |
1202 |
|
1193 | |||
1203 | # Configure auto-indent for all platforms |
|
1194 | # Configure auto-indent for all platforms | |
1204 | self.set_autoindent(self.rc.autoindent) |
|
1195 | self.set_autoindent(self.rc.autoindent) | |
1205 |
|
1196 | |||
1206 | def showsyntaxerror(self, filename=None): |
|
1197 | def showsyntaxerror(self, filename=None): | |
1207 | """Display the syntax error that just occurred. |
|
1198 | """Display the syntax error that just occurred. | |
1208 |
|
1199 | |||
1209 | This doesn't display a stack trace because there isn't one. |
|
1200 | This doesn't display a stack trace because there isn't one. | |
1210 |
|
1201 | |||
1211 | If a filename is given, it is stuffed in the exception instead |
|
1202 | If a filename is given, it is stuffed in the exception instead | |
1212 | of what was there before (because Python's parser always uses |
|
1203 | of what was there before (because Python's parser always uses | |
1213 | "<string>" when reading from a string). |
|
1204 | "<string>" when reading from a string). | |
1214 | """ |
|
1205 | """ | |
1215 | type, value, sys.last_traceback = sys.exc_info() |
|
1206 | type, value, sys.last_traceback = sys.exc_info() | |
1216 | sys.last_type = type |
|
1207 | sys.last_type = type | |
1217 | sys.last_value = value |
|
1208 | sys.last_value = value | |
1218 | if filename and type is SyntaxError: |
|
1209 | if filename and type is SyntaxError: | |
1219 | # Work hard to stuff the correct filename in the exception |
|
1210 | # Work hard to stuff the correct filename in the exception | |
1220 | try: |
|
1211 | try: | |
1221 | msg, (dummy_filename, lineno, offset, line) = value |
|
1212 | msg, (dummy_filename, lineno, offset, line) = value | |
1222 | except: |
|
1213 | except: | |
1223 | # Not the format we expect; leave it alone |
|
1214 | # Not the format we expect; leave it alone | |
1224 | pass |
|
1215 | pass | |
1225 | else: |
|
1216 | else: | |
1226 | # Stuff in the right filename |
|
1217 | # Stuff in the right filename | |
1227 | try: |
|
1218 | try: | |
1228 | # Assume SyntaxError is a class exception |
|
1219 | # Assume SyntaxError is a class exception | |
1229 | value = SyntaxError(msg, (filename, lineno, offset, line)) |
|
1220 | value = SyntaxError(msg, (filename, lineno, offset, line)) | |
1230 | except: |
|
1221 | except: | |
1231 | # If that failed, assume SyntaxError is a string |
|
1222 | # If that failed, assume SyntaxError is a string | |
1232 | value = msg, (filename, lineno, offset, line) |
|
1223 | value = msg, (filename, lineno, offset, line) | |
1233 | self.SyntaxTB(type,value,[]) |
|
1224 | self.SyntaxTB(type,value,[]) | |
1234 |
|
1225 | |||
1235 | def debugger(self): |
|
1226 | def debugger(self): | |
1236 | """Call the pdb debugger.""" |
|
1227 | """Call the pdb debugger.""" | |
1237 |
|
1228 | |||
1238 | if not self.rc.pdb: |
|
1229 | if not self.rc.pdb: | |
1239 | return |
|
1230 | return | |
1240 | pdb.pm() |
|
1231 | pdb.pm() | |
1241 |
|
1232 | |||
1242 | def showtraceback(self,exc_tuple = None): |
|
1233 | def showtraceback(self,exc_tuple = None): | |
1243 | """Display the exception that just occurred.""" |
|
1234 | """Display the exception that just occurred.""" | |
1244 |
|
1235 | |||
1245 | # Though this won't be called by syntax errors in the input line, |
|
1236 | # Though this won't be called by syntax errors in the input line, | |
1246 | # there may be SyntaxError cases whith imported code. |
|
1237 | # there may be SyntaxError cases whith imported code. | |
1247 | if exc_tuple is None: |
|
1238 | if exc_tuple is None: | |
1248 | type, value, tb = sys.exc_info() |
|
1239 | type, value, tb = sys.exc_info() | |
1249 | else: |
|
1240 | else: | |
1250 | type, value, tb = exc_tuple |
|
1241 | type, value, tb = exc_tuple | |
1251 | if type is SyntaxError: |
|
1242 | if type is SyntaxError: | |
1252 | self.showsyntaxerror() |
|
1243 | self.showsyntaxerror() | |
1253 | else: |
|
1244 | else: | |
1254 | sys.last_type = type |
|
1245 | sys.last_type = type | |
1255 | sys.last_value = value |
|
1246 | sys.last_value = value | |
1256 | sys.last_traceback = tb |
|
1247 | sys.last_traceback = tb | |
1257 | self.InteractiveTB() |
|
1248 | self.InteractiveTB() | |
1258 | if self.InteractiveTB.call_pdb and self.has_readline: |
|
1249 | if self.InteractiveTB.call_pdb and self.has_readline: | |
1259 | # pdb mucks up readline, fix it back |
|
1250 | # pdb mucks up readline, fix it back | |
1260 | self.readline.set_completer(self.Completer.complete) |
|
1251 | self.readline.set_completer(self.Completer.complete) | |
1261 |
|
1252 | |||
1262 | def update_cache(self, line): |
|
1253 | def update_cache(self, line): | |
1263 | """puts line into cache""" |
|
1254 | """puts line into cache""" | |
1264 | self.inputcache.insert(0, line) # This copies the cache every time ... :-( |
|
1255 | self.inputcache.insert(0, line) # This copies the cache every time ... :-( | |
1265 | if len(self.inputcache) >= self.CACHELENGTH: |
|
1256 | if len(self.inputcache) >= self.CACHELENGTH: | |
1266 | self.inputcache.pop() # This not :-) |
|
1257 | self.inputcache.pop() # This not :-) | |
1267 |
|
1258 | |||
1268 | def name_space_init(self): |
|
1259 | def name_space_init(self): | |
1269 | """Create local namespace.""" |
|
1260 | """Create local namespace.""" | |
1270 | # We want this to be a method to facilitate embedded initialization. |
|
1261 | # We want this to be a method to facilitate embedded initialization. | |
1271 | code.InteractiveConsole.__init__(self,self.user_ns) |
|
1262 | code.InteractiveConsole.__init__(self,self.user_ns) | |
1272 |
|
1263 | |||
1273 | def mainloop(self,banner=None): |
|
1264 | def mainloop(self,banner=None): | |
1274 | """Creates the local namespace and starts the mainloop. |
|
1265 | """Creates the local namespace and starts the mainloop. | |
1275 |
|
1266 | |||
1276 | If an optional banner argument is given, it will override the |
|
1267 | If an optional banner argument is given, it will override the | |
1277 | internally created default banner.""" |
|
1268 | internally created default banner.""" | |
1278 |
|
1269 | |||
1279 | self.name_space_init() |
|
1270 | self.name_space_init() | |
1280 | if self.rc.c: # Emulate Python's -c option |
|
1271 | if self.rc.c: # Emulate Python's -c option | |
1281 | self.exec_init_cmd() |
|
1272 | self.exec_init_cmd() | |
1282 | if banner is None: |
|
1273 | if banner is None: | |
1283 | if self.rc.banner: |
|
1274 | if self.rc.banner: | |
1284 | banner = self.BANNER+self.banner2 |
|
1275 | banner = self.BANNER+self.banner2 | |
1285 | else: |
|
1276 | else: | |
1286 | banner = '' |
|
1277 | banner = '' | |
1287 | self.interact(banner) |
|
1278 | self.interact(banner) | |
1288 |
|
1279 | |||
1289 | def exec_init_cmd(self): |
|
1280 | def exec_init_cmd(self): | |
1290 | """Execute a command given at the command line. |
|
1281 | """Execute a command given at the command line. | |
1291 |
|
1282 | |||
1292 | This emulates Python's -c option.""" |
|
1283 | This emulates Python's -c option.""" | |
1293 |
|
1284 | |||
1294 | sys.argv = ['-c'] |
|
1285 | sys.argv = ['-c'] | |
1295 | self.push(self.rc.c) |
|
1286 | self.push(self.rc.c) | |
1296 |
|
1287 | |||
1297 | def embed_mainloop(self,header='',local_ns=None,global_ns=None,stack_depth=0): |
|
1288 | def embed_mainloop(self,header='',local_ns=None,global_ns=None,stack_depth=0): | |
1298 | """Embeds IPython into a running python program. |
|
1289 | """Embeds IPython into a running python program. | |
1299 |
|
1290 | |||
1300 | Input: |
|
1291 | Input: | |
1301 |
|
1292 | |||
1302 | - header: An optional header message can be specified. |
|
1293 | - header: An optional header message can be specified. | |
1303 |
|
1294 | |||
1304 | - local_ns, global_ns: working namespaces. If given as None, the |
|
1295 | - local_ns, global_ns: working namespaces. If given as None, the | |
1305 | IPython-initialized one is updated with __main__.__dict__, so that |
|
1296 | IPython-initialized one is updated with __main__.__dict__, so that | |
1306 | program variables become visible but user-specific configuration |
|
1297 | program variables become visible but user-specific configuration | |
1307 | remains possible. |
|
1298 | remains possible. | |
1308 |
|
1299 | |||
1309 | - stack_depth: specifies how many levels in the stack to go to |
|
1300 | - stack_depth: specifies how many levels in the stack to go to | |
1310 | looking for namespaces (when local_ns and global_ns are None). This |
|
1301 | looking for namespaces (when local_ns and global_ns are None). This | |
1311 | allows an intermediate caller to make sure that this function gets |
|
1302 | allows an intermediate caller to make sure that this function gets | |
1312 | the namespace from the intended level in the stack. By default (0) |
|
1303 | the namespace from the intended level in the stack. By default (0) | |
1313 | it will get its locals and globals from the immediate caller. |
|
1304 | it will get its locals and globals from the immediate caller. | |
1314 |
|
1305 | |||
1315 | Warning: it's possible to use this in a program which is being run by |
|
1306 | Warning: it's possible to use this in a program which is being run by | |
1316 | IPython itself (via %run), but some funny things will happen (a few |
|
1307 | IPython itself (via %run), but some funny things will happen (a few | |
1317 | globals get overwritten). In the future this will be cleaned up, as |
|
1308 | globals get overwritten). In the future this will be cleaned up, as | |
1318 | there is no fundamental reason why it can't work perfectly.""" |
|
1309 | there is no fundamental reason why it can't work perfectly.""" | |
1319 |
|
1310 | |||
1320 | # Patch for global embedding to make sure that things don't overwrite |
|
1311 | # Patch for global embedding to make sure that things don't overwrite | |
1321 | # user globals accidentally. Thanks to Richard <rxe@renre-europe.com> |
|
1312 | # user globals accidentally. Thanks to Richard <rxe@renre-europe.com> | |
1322 | # FIXME. Test this a bit more carefully (the if.. is new) |
|
1313 | # FIXME. Test this a bit more carefully (the if.. is new) | |
1323 | if local_ns is None and global_ns is None: |
|
1314 | if local_ns is None and global_ns is None: | |
1324 | self.user_ns.update(__main__.__dict__) |
|
1315 | self.user_ns.update(__main__.__dict__) | |
1325 |
|
1316 | |||
1326 | # Get locals and globals from caller |
|
1317 | # Get locals and globals from caller | |
1327 | if local_ns is None or global_ns is None: |
|
1318 | if local_ns is None or global_ns is None: | |
1328 | call_frame = sys._getframe(stack_depth).f_back |
|
1319 | call_frame = sys._getframe(stack_depth).f_back | |
1329 |
|
1320 | |||
1330 | if local_ns is None: |
|
1321 | if local_ns is None: | |
1331 | local_ns = call_frame.f_locals |
|
1322 | local_ns = call_frame.f_locals | |
1332 | if global_ns is None: |
|
1323 | if global_ns is None: | |
1333 | global_ns = call_frame.f_globals |
|
1324 | global_ns = call_frame.f_globals | |
1334 |
|
1325 | |||
1335 | # Update namespaces and fire up interpreter |
|
1326 | # Update namespaces and fire up interpreter | |
1336 | self.user_ns.update(local_ns) |
|
1327 | self.user_ns.update(local_ns) | |
1337 | self.interact(header) |
|
1328 | self.interact(header) | |
1338 |
|
1329 | |||
1339 | # Remove locals from namespace |
|
1330 | # Remove locals from namespace | |
1340 |
for k in local_ns |
|
1331 | for k in local_ns: | |
1341 | del self.user_ns[k] |
|
1332 | del self.user_ns[k] | |
1342 |
|
1333 | |||
1343 | def interact(self, banner=None): |
|
1334 | def interact(self, banner=None): | |
1344 | """Closely emulate the interactive Python console. |
|
1335 | """Closely emulate the interactive Python console. | |
1345 |
|
1336 | |||
1346 | The optional banner argument specify the banner to print |
|
1337 | The optional banner argument specify the banner to print | |
1347 | before the first interaction; by default it prints a banner |
|
1338 | before the first interaction; by default it prints a banner | |
1348 | similar to the one printed by the real Python interpreter, |
|
1339 | similar to the one printed by the real Python interpreter, | |
1349 | followed by the current class name in parentheses (so as not |
|
1340 | followed by the current class name in parentheses (so as not | |
1350 | to confuse this with the real interpreter -- since it's so |
|
1341 | to confuse this with the real interpreter -- since it's so | |
1351 | close!). |
|
1342 | close!). | |
1352 |
|
1343 | |||
1353 | """ |
|
1344 | """ | |
1354 | cprt = 'Type "copyright", "credits" or "license" for more information.' |
|
1345 | cprt = 'Type "copyright", "credits" or "license" for more information.' | |
1355 | if banner is None: |
|
1346 | if banner is None: | |
1356 | self.write("Python %s on %s\n%s\n(%s)\n" % |
|
1347 | self.write("Python %s on %s\n%s\n(%s)\n" % | |
1357 | (sys.version, sys.platform, cprt, |
|
1348 | (sys.version, sys.platform, cprt, | |
1358 | self.__class__.__name__)) |
|
1349 | self.__class__.__name__)) | |
1359 | else: |
|
1350 | else: | |
1360 | self.write(banner) |
|
1351 | self.write(banner) | |
1361 |
|
1352 | |||
1362 | more = 0 |
|
1353 | more = 0 | |
1363 |
|
1354 | |||
1364 | # Mark activity in the builtins |
|
1355 | # Mark activity in the builtins | |
1365 | __builtin__.__dict__['__IPYTHON__active'] += 1 |
|
1356 | __builtin__.__dict__['__IPYTHON__active'] += 1 | |
1366 | while 1: |
|
1357 | ||
1367 |
|
|
1358 | # exit_now is set by a call to %Exit or %Quit | |
1368 |
|
|
1359 | while not self.exit_now: | |
1369 | break |
|
|||
1370 | try: |
|
1360 | try: | |
1371 | if more: |
|
1361 | if more: | |
1372 | prompt = self.outputcache.prompt2 |
|
1362 | prompt = self.outputcache.prompt2 | |
1373 | if self.autoindent: |
|
1363 | if self.autoindent: | |
1374 | self.readline_startup_hook(self.pre_readline) |
|
1364 | self.readline_startup_hook(self.pre_readline) | |
1375 | else: |
|
1365 | else: | |
1376 | prompt = self.outputcache.prompt1 |
|
1366 | prompt = self.outputcache.prompt1 | |
1377 | try: |
|
1367 | try: | |
1378 | line = self.raw_input(prompt) |
|
1368 | line = self.raw_input(prompt) | |
1379 | if self.autoindent: |
|
1369 | if self.autoindent: | |
1380 | self.readline_startup_hook(None) |
|
1370 | self.readline_startup_hook(None) | |
1381 | except EOFError: |
|
1371 | except EOFError: | |
1382 | if self.autoindent: |
|
1372 | if self.autoindent: | |
1383 | self.readline_startup_hook(None) |
|
1373 | self.readline_startup_hook(None) | |
1384 | self.write("\n") |
|
1374 | self.write("\n") | |
1385 | if self.rc.confirm_exit: |
|
1375 | if self.rc.confirm_exit: | |
1386 | if ask_yes_no('Do you really want to exit ([y]/n)?','y'): |
|
1376 | if ask_yes_no('Do you really want to exit ([y]/n)?','y'): | |
1387 | break |
|
1377 | break | |
1388 | else: |
|
1378 | else: | |
1389 | break |
|
1379 | break | |
1390 | else: |
|
1380 | else: | |
1391 | more = self.push(line) |
|
1381 | more = self.push(line) | |
1392 | # Auto-indent management |
|
1382 | # Auto-indent management | |
1393 | if self.autoindent: |
|
1383 | if self.autoindent: | |
1394 | if line: |
|
1384 | if line: | |
1395 | ini_spaces = re.match('^(\s+)',line) |
|
1385 | ini_spaces = re.match('^(\s+)',line) | |
1396 | if ini_spaces: |
|
1386 | if ini_spaces: | |
1397 | nspaces = ini_spaces.end() |
|
1387 | nspaces = ini_spaces.end() | |
1398 | else: |
|
1388 | else: | |
1399 | nspaces = 0 |
|
1389 | nspaces = 0 | |
1400 | self.readline_indent = nspaces |
|
1390 | self.readline_indent = nspaces | |
1401 |
|
1391 | |||
1402 | if line[-1] == ':': |
|
1392 | if line[-1] == ':': | |
1403 | self.readline_indent += 4 |
|
1393 | self.readline_indent += 4 | |
1404 | elif re.match(r'^\s+raise|^\s+return',line): |
|
1394 | elif re.match(r'^\s+raise|^\s+return',line): | |
1405 | self.readline_indent -= 4 |
|
1395 | self.readline_indent -= 4 | |
1406 | else: |
|
1396 | else: | |
1407 | self.readline_indent = 0 |
|
1397 | self.readline_indent = 0 | |
1408 |
|
1398 | |||
1409 | except KeyboardInterrupt: |
|
1399 | except KeyboardInterrupt: | |
1410 | self.write("\nKeyboardInterrupt\n") |
|
1400 | self.write("\nKeyboardInterrupt\n") | |
1411 | self.resetbuffer() |
|
1401 | self.resetbuffer() | |
1412 | more = 0 |
|
1402 | more = 0 | |
1413 | # keep cache in sync with the prompt counter: |
|
1403 | # keep cache in sync with the prompt counter: | |
1414 | self.outputcache.prompt_count -= 1 |
|
1404 | self.outputcache.prompt_count -= 1 | |
1415 |
|
1405 | |||
1416 | if self.autoindent: |
|
1406 | if self.autoindent: | |
1417 | self.readline_indent = 0 |
|
1407 | self.readline_indent = 0 | |
1418 |
|
1408 | |||
1419 | except bdb.BdbQuit: |
|
1409 | except bdb.BdbQuit: | |
1420 | warn("The Python debugger has exited with a BdbQuit exception.\n" |
|
1410 | warn("The Python debugger has exited with a BdbQuit exception.\n" | |
1421 | "Because of how pdb handles the stack, it is impossible\n" |
|
1411 | "Because of how pdb handles the stack, it is impossible\n" | |
1422 | "for IPython to properly format this particular exception.\n" |
|
1412 | "for IPython to properly format this particular exception.\n" | |
1423 | "IPython will resume normal operation.") |
|
1413 | "IPython will resume normal operation.") | |
1424 |
|
|
1414 | ||
1425 | # We should never get here except in fairly bizarre situations |
|
|||
1426 | # (or b/c of an IPython bug). One reasonable exception is if |
|
|||
1427 | # the user sets stdin/out/err to a broken object (or closes |
|
|||
1428 | # any of them!) |
|
|||
1429 |
|
||||
1430 | fixed_in_out_err = 0 |
|
|||
1431 |
|
||||
1432 | # Call the Term I/O class and have it reopen any stream which |
|
|||
1433 | # the user might have closed. |
|
|||
1434 | Term.reopen_all() |
|
|||
1435 |
|
||||
1436 | # Do the same manually for sys.stderr/out/in |
|
|||
1437 |
|
||||
1438 | # err first, so we can print at least warnings |
|
|||
1439 | if sys.__stderr__.closed: |
|
|||
1440 | sys.__stderr__ = os.fdopen(os.dup(2),'w',0) |
|
|||
1441 | fixed_err_err = 1 |
|
|||
1442 | print >> sys.__stderr__,""" |
|
|||
1443 | WARNING: |
|
|||
1444 | sys.__stderr__ was closed! |
|
|||
1445 | I've tried to reopen it, but bear in mind that things may not work normally |
|
|||
1446 | from now. In particular, readline support may have broken. |
|
|||
1447 | """ |
|
|||
1448 | # Next, check stdin/out |
|
|||
1449 | if sys.__stdin__.closed: |
|
|||
1450 | sys.__stdin__ = os.fdopen(os.dup(0),'r',0) |
|
|||
1451 | fixed_in_out_err = 1 |
|
|||
1452 | print >> sys.__stderr__,""" |
|
|||
1453 | WARNING: |
|
|||
1454 | sys.__stdin__ was closed! |
|
|||
1455 | I've tried to reopen it, but bear in mind that things may not work normally |
|
|||
1456 | from now. In particular, readline support may have broken. |
|
|||
1457 | """ |
|
|||
1458 | if sys.__stdout__.closed: |
|
|||
1459 | sys.__stdout__ = os.fdopen(os.dup(1),'w',0) |
|
|||
1460 | fixed_in_out_err = 1 |
|
|||
1461 | print >> sys.__stderr__,""" |
|
|||
1462 | WARNING: |
|
|||
1463 | sys.__stdout__ was closed! |
|
|||
1464 | I've tried to reopen it, but bear in mind that things may not work normally |
|
|||
1465 | from now. In particular, readline support may have broken. |
|
|||
1466 | """ |
|
|||
1467 |
|
||||
1468 | # Now, check mismatch of objects |
|
|||
1469 | if sys.stdin is not sys.__stdin__: |
|
|||
1470 | sys.stdin = sys.__stdin__ |
|
|||
1471 | fixed_in_out_err = 1 |
|
|||
1472 | print >> sys.__stderr__,""" |
|
|||
1473 | WARNING: |
|
|||
1474 | sys.stdin has been reset to sys.__stdin__. |
|
|||
1475 | There seemed to be a problem with your sys.stdin. |
|
|||
1476 | """ |
|
|||
1477 | if sys.stdout is not sys.__stdout__: |
|
|||
1478 | sys.stdout = sys.__stdout__ |
|
|||
1479 | fixed_in_out_err = 1 |
|
|||
1480 | print >> sys.__stderr__,""" |
|
|||
1481 | WARNING: |
|
|||
1482 | sys.stdout has been reset to sys.__stdout__. |
|
|||
1483 | There seemed to be a problem with your sys.stdout. |
|
|||
1484 | """ |
|
|||
1485 |
|
||||
1486 | if sys.stderr is not sys.__stderr__: |
|
|||
1487 | sys.stderr = sys.__stderr__ |
|
|||
1488 | fixed_in_out_err = 1 |
|
|||
1489 | print >> sys.__stderr__,""" |
|
|||
1490 | WARNING: |
|
|||
1491 | sys.stderr has been reset to sys.__stderr__. |
|
|||
1492 | There seemed to be a problem with your sys.stderr. |
|
|||
1493 | """ |
|
|||
1494 | # If the problem wasn't a broken out/err, it's an IPython bug |
|
|||
1495 | # I wish we could ask the user whether to crash or not, but |
|
|||
1496 | # calling any function at this point messes up the stack. |
|
|||
1497 | if not fixed_in_out_err: |
|
|||
1498 | raise |
|
|||
1499 |
|
||||
1500 | # We are off again... |
|
1415 | # We are off again... | |
1501 | __builtin__.__dict__['__IPYTHON__active'] -= 1 |
|
1416 | __builtin__.__dict__['__IPYTHON__active'] -= 1 | |
1502 |
|
1417 | |||
1503 | def excepthook(self, type, value, tb): |
|
1418 | def excepthook(self, type, value, tb): | |
1504 | """One more defense for GUI apps that call sys.excepthook. |
|
1419 | """One more defense for GUI apps that call sys.excepthook. | |
1505 |
|
1420 | |||
1506 | GUI frameworks like wxPython trap exceptions and call |
|
1421 | GUI frameworks like wxPython trap exceptions and call | |
1507 | sys.excepthook themselves. I guess this is a feature that |
|
1422 | sys.excepthook themselves. I guess this is a feature that | |
1508 | enables them to keep running after exceptions that would |
|
1423 | enables them to keep running after exceptions that would | |
1509 | otherwise kill their mainloop. This is a bother for IPython |
|
1424 | otherwise kill their mainloop. This is a bother for IPython | |
1510 | which excepts to catch all of the program exceptions with a try: |
|
1425 | which excepts to catch all of the program exceptions with a try: | |
1511 | except: statement. |
|
1426 | except: statement. | |
1512 |
|
1427 | |||
1513 | Normally, IPython sets sys.excepthook to a CrashHandler instance, so if |
|
1428 | Normally, IPython sets sys.excepthook to a CrashHandler instance, so if | |
1514 | any app directly invokes sys.excepthook, it will look to the user like |
|
1429 | any app directly invokes sys.excepthook, it will look to the user like | |
1515 | IPython crashed. In order to work around this, we can disable the |
|
1430 | IPython crashed. In order to work around this, we can disable the | |
1516 | CrashHandler and replace it with this excepthook instead, which prints a |
|
1431 | CrashHandler and replace it with this excepthook instead, which prints a | |
1517 | regular traceback using our InteractiveTB. In this fashion, apps which |
|
1432 | regular traceback using our InteractiveTB. In this fashion, apps which | |
1518 | call sys.excepthook will generate a regular-looking exception from |
|
1433 | call sys.excepthook will generate a regular-looking exception from | |
1519 | IPython, and the CrashHandler will only be triggered by real IPython |
|
1434 | IPython, and the CrashHandler will only be triggered by real IPython | |
1520 | crashes. |
|
1435 | crashes. | |
1521 |
|
1436 | |||
1522 | This hook should be used sparingly, only in places which are not likely |
|
1437 | This hook should be used sparingly, only in places which are not likely | |
1523 | to be true IPython errors. |
|
1438 | to be true IPython errors. | |
1524 | """ |
|
1439 | """ | |
1525 |
|
1440 | |||
1526 | self.InteractiveTB(type, value, tb, tb_offset=0) |
|
1441 | self.InteractiveTB(type, value, tb, tb_offset=0) | |
1527 | if self.InteractiveTB.call_pdb and self.has_readline: |
|
1442 | if self.InteractiveTB.call_pdb and self.has_readline: | |
1528 | self.readline.set_completer(self.Completer.complete) |
|
1443 | self.readline.set_completer(self.Completer.complete) | |
1529 |
|
1444 | |||
1530 | def call_alias(self,alias,rest=''): |
|
1445 | def call_alias(self,alias,rest=''): | |
1531 | """Call an alias given its name and the rest of the line. |
|
1446 | """Call an alias given its name and the rest of the line. | |
1532 |
|
1447 | |||
1533 | This function MUST be given a proper alias, because it doesn't make |
|
1448 | This function MUST be given a proper alias, because it doesn't make | |
1534 | any checks when looking up into the alias table. The caller is |
|
1449 | any checks when looking up into the alias table. The caller is | |
1535 | responsible for invoking it only with a valid alias.""" |
|
1450 | responsible for invoking it only with a valid alias.""" | |
1536 |
|
1451 | |||
1537 | #print 'ALIAS: <%s>+<%s>' % (alias,rest) # dbg |
|
1452 | #print 'ALIAS: <%s>+<%s>' % (alias,rest) # dbg | |
1538 | nargs,cmd = self.alias_table[alias] |
|
1453 | nargs,cmd = self.alias_table[alias] | |
1539 | # Expand the %l special to be the user's input line |
|
1454 | # Expand the %l special to be the user's input line | |
1540 | if cmd.find('%l') >= 0: |
|
1455 | if cmd.find('%l') >= 0: | |
1541 | cmd = cmd.replace('%l',rest) |
|
1456 | cmd = cmd.replace('%l',rest) | |
1542 | rest = '' |
|
1457 | rest = '' | |
1543 | if nargs==0: |
|
1458 | if nargs==0: | |
1544 | # Simple, argument-less aliases |
|
1459 | # Simple, argument-less aliases | |
1545 | cmd = '%s %s' % (cmd,rest) |
|
1460 | cmd = '%s %s' % (cmd,rest) | |
1546 | else: |
|
1461 | else: | |
1547 | # Handle aliases with positional arguments |
|
1462 | # Handle aliases with positional arguments | |
1548 | args = rest.split(None,nargs) |
|
1463 | args = rest.split(None,nargs) | |
1549 | if len(args)< nargs: |
|
1464 | if len(args)< nargs: | |
1550 | error('Alias <%s> requires %s arguments, %s given.' % |
|
1465 | error('Alias <%s> requires %s arguments, %s given.' % | |
1551 | (alias,nargs,len(args))) |
|
1466 | (alias,nargs,len(args))) | |
1552 | return |
|
1467 | return | |
1553 | cmd = '%s %s' % (cmd % tuple(args[:nargs]),' '.join(args[nargs:])) |
|
1468 | cmd = '%s %s' % (cmd % tuple(args[:nargs]),' '.join(args[nargs:])) | |
1554 | # Now call the macro, evaluating in the user's namespace |
|
1469 | # Now call the macro, evaluating in the user's namespace | |
1555 | try: |
|
1470 | try: | |
1556 | self.system(cmd) |
|
1471 | self.system(cmd) | |
1557 | except: |
|
1472 | except: | |
1558 | self.showtraceback() |
|
1473 | self.showtraceback() | |
1559 |
|
1474 | |||
1560 | def runlines(self,lines): |
|
1475 | def runlines(self,lines): | |
1561 | """Run a string of one or more lines of source. |
|
1476 | """Run a string of one or more lines of source. | |
1562 |
|
1477 | |||
1563 | This method is capable of running a string containing multiple source |
|
1478 | This method is capable of running a string containing multiple source | |
1564 | lines, as if they had been entered at the IPython prompt. Since it |
|
1479 | lines, as if they had been entered at the IPython prompt. Since it | |
1565 | exposes IPython's processing machinery, the given strings can contain |
|
1480 | exposes IPython's processing machinery, the given strings can contain | |
1566 | magic calls (%magic), special shell access (!cmd), etc.""" |
|
1481 | magic calls (%magic), special shell access (!cmd), etc.""" | |
1567 |
|
1482 | |||
1568 | # We must start with a clean buffer, in case this is run from an |
|
1483 | # We must start with a clean buffer, in case this is run from an | |
1569 | # interactive IPython session (via a magic, for example). |
|
1484 | # interactive IPython session (via a magic, for example). | |
1570 | self.resetbuffer() |
|
1485 | self.resetbuffer() | |
1571 | lines = lines.split('\n') |
|
1486 | lines = lines.split('\n') | |
1572 | more = 0 |
|
1487 | more = 0 | |
1573 | for line in lines: |
|
1488 | for line in lines: | |
1574 | # skip blank lines so we don't mess up the prompt counter, but do |
|
1489 | # skip blank lines so we don't mess up the prompt counter, but do | |
1575 | # NOT skip even a blank line if we are in a code block (more is |
|
1490 | # NOT skip even a blank line if we are in a code block (more is | |
1576 | # true) |
|
1491 | # true) | |
1577 | if line or more: |
|
1492 | if line or more: | |
1578 | more = self.push((self.prefilter(line,more))) |
|
1493 | more = self.push((self.prefilter(line,more))) | |
1579 | # IPython's runsource returns None if there was an error |
|
1494 | # IPython's runsource returns None if there was an error | |
1580 | # compiling the code. This allows us to stop processing right |
|
1495 | # compiling the code. This allows us to stop processing right | |
1581 | # away, so the user gets the error message at the right place. |
|
1496 | # away, so the user gets the error message at the right place. | |
1582 | if more is None: |
|
1497 | if more is None: | |
1583 | break |
|
1498 | break | |
1584 | # final newline in case the input didn't have it, so that the code |
|
1499 | # final newline in case the input didn't have it, so that the code | |
1585 | # actually does get executed |
|
1500 | # actually does get executed | |
1586 | if more: |
|
1501 | if more: | |
1587 | self.push('\n') |
|
1502 | self.push('\n') | |
1588 |
|
1503 | |||
1589 | def runsource(self, source, filename="<input>", symbol="single"): |
|
1504 | def runsource(self, source, filename="<input>", symbol="single"): | |
1590 | """Compile and run some source in the interpreter. |
|
1505 | """Compile and run some source in the interpreter. | |
1591 |
|
1506 | |||
1592 | Arguments are as for compile_command(). |
|
1507 | Arguments are as for compile_command(). | |
1593 |
|
1508 | |||
1594 | One several things can happen: |
|
1509 | One several things can happen: | |
1595 |
|
1510 | |||
1596 | 1) The input is incorrect; compile_command() raised an |
|
1511 | 1) The input is incorrect; compile_command() raised an | |
1597 | exception (SyntaxError or OverflowError). A syntax traceback |
|
1512 | exception (SyntaxError or OverflowError). A syntax traceback | |
1598 | will be printed by calling the showsyntaxerror() method. |
|
1513 | will be printed by calling the showsyntaxerror() method. | |
1599 |
|
1514 | |||
1600 | 2) The input is incomplete, and more input is required; |
|
1515 | 2) The input is incomplete, and more input is required; | |
1601 | compile_command() returned None. Nothing happens. |
|
1516 | compile_command() returned None. Nothing happens. | |
1602 |
|
1517 | |||
1603 | 3) The input is complete; compile_command() returned a code |
|
1518 | 3) The input is complete; compile_command() returned a code | |
1604 | object. The code is executed by calling self.runcode() (which |
|
1519 | object. The code is executed by calling self.runcode() (which | |
1605 | also handles run-time exceptions, except for SystemExit). |
|
1520 | also handles run-time exceptions, except for SystemExit). | |
1606 |
|
1521 | |||
1607 | The return value is: |
|
1522 | The return value is: | |
1608 |
|
1523 | |||
1609 | - True in case 2 |
|
1524 | - True in case 2 | |
1610 |
|
1525 | |||
1611 | - False in the other cases, unless an exception is raised, where |
|
1526 | - False in the other cases, unless an exception is raised, where | |
1612 | None is returned instead. This can be used by external callers to |
|
1527 | None is returned instead. This can be used by external callers to | |
1613 | know whether to continue feeding input or not. |
|
1528 | know whether to continue feeding input or not. | |
1614 |
|
1529 | |||
1615 | The return value can be used to decide whether to use sys.ps1 or |
|
1530 | The return value can be used to decide whether to use sys.ps1 or | |
1616 | sys.ps2 to prompt the next line.""" |
|
1531 | sys.ps2 to prompt the next line.""" | |
1617 | try: |
|
1532 | try: | |
1618 | code = self.compile(source, filename, symbol) |
|
1533 | code = self.compile(source, filename, symbol) | |
1619 | except (OverflowError, SyntaxError, ValueError): |
|
1534 | except (OverflowError, SyntaxError, ValueError): | |
1620 | # Case 1 |
|
1535 | # Case 1 | |
1621 | self.showsyntaxerror(filename) |
|
1536 | self.showsyntaxerror(filename) | |
1622 | return None |
|
1537 | return None | |
1623 |
|
1538 | |||
1624 | if code is None: |
|
1539 | if code is None: | |
1625 | # Case 2 |
|
1540 | # Case 2 | |
1626 | return True |
|
1541 | return True | |
1627 |
|
1542 | |||
1628 | # Case 3 |
|
1543 | # Case 3 | |
1629 | # We store the code source and object so that threaded shells and |
|
1544 | # We store the code source and object so that threaded shells and | |
1630 | # custom exception handlers can access all this info if needed. |
|
1545 | # custom exception handlers can access all this info if needed. | |
1631 | self.code_to_run_src = source |
|
1546 | self.code_to_run_src = source | |
1632 | self.code_to_run = code |
|
1547 | self.code_to_run = code | |
1633 | # now actually execute the code object |
|
1548 | # now actually execute the code object | |
1634 | if self.runcode(code) == 0: |
|
1549 | if self.runcode(code) == 0: | |
1635 | return False |
|
1550 | return False | |
1636 | else: |
|
1551 | else: | |
1637 | return None |
|
1552 | return None | |
1638 |
|
1553 | |||
1639 | def runcode(self,code_obj): |
|
1554 | def runcode(self,code_obj): | |
1640 | """Execute a code object. |
|
1555 | """Execute a code object. | |
1641 |
|
1556 | |||
1642 | When an exception occurs, self.showtraceback() is called to display a |
|
1557 | When an exception occurs, self.showtraceback() is called to display a | |
1643 | traceback. |
|
1558 | traceback. | |
1644 |
|
1559 | |||
1645 | Return value: a flag indicating whether the code to be run completed |
|
1560 | Return value: a flag indicating whether the code to be run completed | |
1646 | successfully: |
|
1561 | successfully: | |
1647 |
|
1562 | |||
1648 | - 0: successful execution. |
|
1563 | - 0: successful execution. | |
1649 | - 1: an error occurred. |
|
1564 | - 1: an error occurred. | |
1650 | """ |
|
1565 | """ | |
1651 |
|
1566 | |||
1652 | # Set our own excepthook in case the user code tries to call it |
|
1567 | # Set our own excepthook in case the user code tries to call it | |
1653 | # directly, so that the IPython crash handler doesn't get triggered |
|
1568 | # directly, so that the IPython crash handler doesn't get triggered | |
1654 | old_excepthook,sys.excepthook = sys.excepthook, self.excepthook |
|
1569 | old_excepthook,sys.excepthook = sys.excepthook, self.excepthook | |
1655 | outflag = 1 # happens in more places, so it's easier as default |
|
1570 | outflag = 1 # happens in more places, so it's easier as default | |
1656 | try: |
|
1571 | try: | |
1657 | try: |
|
1572 | try: | |
1658 | exec code_obj in self.locals |
|
1573 | exec code_obj in self.locals | |
1659 | finally: |
|
1574 | finally: | |
1660 | # Reset our crash handler in place |
|
1575 | # Reset our crash handler in place | |
1661 | sys.excepthook = old_excepthook |
|
1576 | sys.excepthook = old_excepthook | |
1662 | except SystemExit: |
|
1577 | except SystemExit: | |
1663 | self.resetbuffer() |
|
1578 | self.resetbuffer() | |
1664 | self.showtraceback() |
|
1579 | self.showtraceback() | |
1665 | warn( __builtin__.exit,level=1) |
|
1580 | warn( __builtin__.exit,level=1) | |
1666 | except self.custom_exceptions: |
|
1581 | except self.custom_exceptions: | |
1667 | etype,value,tb = sys.exc_info() |
|
1582 | etype,value,tb = sys.exc_info() | |
1668 | self.CustomTB(etype,value,tb) |
|
1583 | self.CustomTB(etype,value,tb) | |
1669 | except: |
|
1584 | except: | |
1670 | self.showtraceback() |
|
1585 | self.showtraceback() | |
1671 | else: |
|
1586 | else: | |
1672 | outflag = 0 |
|
1587 | outflag = 0 | |
1673 | if code.softspace(sys.stdout, 0): |
|
1588 | if code.softspace(sys.stdout, 0): | |
1674 |
|
1589 | |||
1675 | # Flush out code object which has been run (and source) |
|
1590 | # Flush out code object which has been run (and source) | |
1676 | self.code_to_run = None |
|
1591 | self.code_to_run = None | |
1677 | self.code_to_run_src = '' |
|
1592 | self.code_to_run_src = '' | |
1678 | return outflag |
|
1593 | return outflag | |
1679 |
|
1594 | |||
1680 | def raw_input(self, prompt=""): |
|
1595 | def raw_input(self, prompt=""): | |
1681 | """Write a prompt and read a line. |
|
1596 | """Write a prompt and read a line. | |
1682 |
|
1597 | |||
1683 | The returned line does not include the trailing newline. |
|
1598 | The returned line does not include the trailing newline. | |
1684 | When the user enters the EOF key sequence, EOFError is raised. |
|
1599 | When the user enters the EOF key sequence, EOFError is raised. | |
1685 |
|
1600 | |||
1686 | The base implementation uses the built-in function |
|
1601 | The base implementation uses the built-in function | |
1687 | raw_input(); a subclass may replace this with a different |
|
1602 | raw_input(); a subclass may replace this with a different | |
1688 | implementation. |
|
1603 | implementation. | |
1689 | """ |
|
1604 | """ | |
1690 | return self.prefilter(raw_input_original(prompt), |
|
1605 | return self.prefilter(raw_input_original(prompt), | |
1691 | prompt==self.outputcache.prompt2) |
|
1606 | prompt==self.outputcache.prompt2) | |
1692 |
|
1607 | |||
1693 | def split_user_input(self,line): |
|
1608 | def split_user_input(self,line): | |
1694 | """Split user input into pre-char, function part and rest.""" |
|
1609 | """Split user input into pre-char, function part and rest.""" | |
1695 |
|
1610 | |||
1696 | lsplit = self.line_split.match(line) |
|
1611 | lsplit = self.line_split.match(line) | |
1697 | if lsplit is None: # no regexp match returns None |
|
1612 | if lsplit is None: # no regexp match returns None | |
1698 | try: |
|
1613 | try: | |
1699 | iFun,theRest = line.split(None,1) |
|
1614 | iFun,theRest = line.split(None,1) | |
1700 | except ValueError: |
|
1615 | except ValueError: | |
1701 | iFun,theRest = line,'' |
|
1616 | iFun,theRest = line,'' | |
1702 | pre = re.match('^(\s*)(.*)',line).groups()[0] |
|
1617 | pre = re.match('^(\s*)(.*)',line).groups()[0] | |
1703 | else: |
|
1618 | else: | |
1704 | pre,iFun,theRest = lsplit.groups() |
|
1619 | pre,iFun,theRest = lsplit.groups() | |
1705 |
|
1620 | |||
1706 | #print 'line:<%s>' % line # dbg |
|
1621 | #print 'line:<%s>' % line # dbg | |
1707 | #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun.strip(),theRest) # dbg |
|
1622 | #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun.strip(),theRest) # dbg | |
1708 | return pre,iFun.strip(),theRest |
|
1623 | return pre,iFun.strip(),theRest | |
1709 |
|
1624 | |||
1710 | def _prefilter(self, line, continue_prompt): |
|
1625 | def _prefilter(self, line, continue_prompt): | |
1711 | """Calls different preprocessors, depending on the form of line.""" |
|
1626 | """Calls different preprocessors, depending on the form of line.""" | |
1712 |
|
1627 | |||
1713 | # All handlers *must* return a value, even if it's blank (''). |
|
1628 | # All handlers *must* return a value, even if it's blank (''). | |
1714 |
|
1629 | |||
1715 | # Lines are NOT logged here. Handlers should process the line as |
|
1630 | # Lines are NOT logged here. Handlers should process the line as | |
1716 | # needed, update the cache AND log it (so that the input cache array |
|
1631 | # needed, update the cache AND log it (so that the input cache array | |
1717 | # stays synced). |
|
1632 | # stays synced). | |
1718 |
|
1633 | |||
1719 | # This function is _very_ delicate, and since it's also the one which |
|
1634 | # This function is _very_ delicate, and since it's also the one which | |
1720 | # determines IPython's response to user input, it must be as efficient |
|
1635 | # determines IPython's response to user input, it must be as efficient | |
1721 | # as possible. For this reason it has _many_ returns in it, trying |
|
1636 | # as possible. For this reason it has _many_ returns in it, trying | |
1722 | # always to exit as quickly as it can figure out what it needs to do. |
|
1637 | # always to exit as quickly as it can figure out what it needs to do. | |
1723 |
|
1638 | |||
1724 | # This function is the main responsible for maintaining IPython's |
|
1639 | # This function is the main responsible for maintaining IPython's | |
1725 | # behavior respectful of Python's semantics. So be _very_ careful if |
|
1640 | # behavior respectful of Python's semantics. So be _very_ careful if | |
1726 | # making changes to anything here. |
|
1641 | # making changes to anything here. | |
1727 |
|
1642 | |||
1728 | #..................................................................... |
|
1643 | #..................................................................... | |
1729 | # Code begins |
|
1644 | # Code begins | |
1730 |
|
1645 | |||
1731 | #if line.startswith('%crash'): raise RuntimeError,'Crash now!' # dbg |
|
1646 | #if line.startswith('%crash'): raise RuntimeError,'Crash now!' # dbg | |
1732 |
|
1647 | |||
1733 | # save the line away in case we crash, so the post-mortem handler can |
|
1648 | # save the line away in case we crash, so the post-mortem handler can | |
1734 | # record it |
|
1649 | # record it | |
1735 | self._last_input_line = line |
|
1650 | self._last_input_line = line | |
1736 |
|
1651 | |||
1737 | #print '***line: <%s>' % line # dbg |
|
1652 | #print '***line: <%s>' % line # dbg | |
1738 |
|
1653 | |||
1739 | # the input history needs to track even empty lines |
|
1654 | # the input history needs to track even empty lines | |
1740 | if not line.strip(): |
|
1655 | if not line.strip(): | |
1741 | if not continue_prompt: |
|
1656 | if not continue_prompt: | |
1742 | self.outputcache.prompt_count -= 1 |
|
1657 | self.outputcache.prompt_count -= 1 | |
1743 | return self.handle_normal('',continue_prompt) |
|
1658 | return self.handle_normal('',continue_prompt) | |
1744 |
|
1659 | |||
1745 | # print '***cont',continue_prompt # dbg |
|
1660 | # print '***cont',continue_prompt # dbg | |
1746 | # special handlers are only allowed for single line statements |
|
1661 | # special handlers are only allowed for single line statements | |
1747 | if continue_prompt and not self.rc.multi_line_specials: |
|
1662 | if continue_prompt and not self.rc.multi_line_specials: | |
1748 | return self.handle_normal(line,continue_prompt) |
|
1663 | return self.handle_normal(line,continue_prompt) | |
1749 |
|
1664 | |||
1750 | # For the rest, we need the structure of the input |
|
1665 | # For the rest, we need the structure of the input | |
1751 | pre,iFun,theRest = self.split_user_input(line) |
|
1666 | pre,iFun,theRest = self.split_user_input(line) | |
1752 | #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg |
|
1667 | #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg | |
1753 |
|
1668 | |||
1754 | # First check for explicit escapes in the last/first character |
|
1669 | # First check for explicit escapes in the last/first character | |
1755 | handler = None |
|
1670 | handler = None | |
1756 | if line[-1] == self.ESC_HELP: |
|
1671 | if line[-1] == self.ESC_HELP: | |
1757 | handler = self.esc_handlers.get(line[-1]) # the ? can be at the end |
|
1672 | handler = self.esc_handlers.get(line[-1]) # the ? can be at the end | |
1758 | if handler is None: |
|
1673 | if handler is None: | |
1759 | # look at the first character of iFun, NOT of line, so we skip |
|
1674 | # look at the first character of iFun, NOT of line, so we skip | |
1760 | # leading whitespace in multiline input |
|
1675 | # leading whitespace in multiline input | |
1761 | handler = self.esc_handlers.get(iFun[0:1]) |
|
1676 | handler = self.esc_handlers.get(iFun[0:1]) | |
1762 | if handler is not None: |
|
1677 | if handler is not None: | |
1763 | return handler(line,continue_prompt,pre,iFun,theRest) |
|
1678 | return handler(line,continue_prompt,pre,iFun,theRest) | |
1764 | # Emacs ipython-mode tags certain input lines |
|
1679 | # Emacs ipython-mode tags certain input lines | |
1765 | if line.endswith('# PYTHON-MODE'): |
|
1680 | if line.endswith('# PYTHON-MODE'): | |
1766 | return self.handle_emacs(line,continue_prompt) |
|
1681 | return self.handle_emacs(line,continue_prompt) | |
1767 |
|
1682 | |||
1768 | # Next, check if we can automatically execute this thing |
|
1683 | # Next, check if we can automatically execute this thing | |
1769 |
|
1684 | |||
1770 | # Allow ! in multi-line statements if multi_line_specials is on: |
|
1685 | # Allow ! in multi-line statements if multi_line_specials is on: | |
1771 | if continue_prompt and self.rc.multi_line_specials and \ |
|
1686 | if continue_prompt and self.rc.multi_line_specials and \ | |
1772 | iFun.startswith(self.ESC_SHELL): |
|
1687 | iFun.startswith(self.ESC_SHELL): | |
1773 | return self.handle_shell_escape(line,continue_prompt, |
|
1688 | return self.handle_shell_escape(line,continue_prompt, | |
1774 | pre=pre,iFun=iFun, |
|
1689 | pre=pre,iFun=iFun, | |
1775 | theRest=theRest) |
|
1690 | theRest=theRest) | |
1776 |
|
1691 | |||
1777 | # Let's try to find if the input line is a magic fn |
|
1692 | # Let's try to find if the input line is a magic fn | |
1778 | oinfo = None |
|
1693 | oinfo = None | |
1779 | if hasattr(self,'magic_'+iFun): |
|
1694 | if hasattr(self,'magic_'+iFun): | |
1780 | oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic |
|
1695 | oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic | |
1781 | if oinfo['ismagic']: |
|
1696 | if oinfo['ismagic']: | |
1782 | # Be careful not to call magics when a variable assignment is |
|
1697 | # Be careful not to call magics when a variable assignment is | |
1783 | # being made (ls='hi', for example) |
|
1698 | # being made (ls='hi', for example) | |
1784 | if self.rc.automagic and \ |
|
1699 | if self.rc.automagic and \ | |
1785 | (len(theRest)==0 or theRest[0] not in '!=()<>,') and \ |
|
1700 | (len(theRest)==0 or theRest[0] not in '!=()<>,') and \ | |
1786 | (self.rc.multi_line_specials or not continue_prompt): |
|
1701 | (self.rc.multi_line_specials or not continue_prompt): | |
1787 | return self.handle_magic(line,continue_prompt, |
|
1702 | return self.handle_magic(line,continue_prompt, | |
1788 | pre,iFun,theRest) |
|
1703 | pre,iFun,theRest) | |
1789 | else: |
|
1704 | else: | |
1790 | return self.handle_normal(line,continue_prompt) |
|
1705 | return self.handle_normal(line,continue_prompt) | |
1791 |
|
1706 | |||
1792 | # If the rest of the line begins with an (in)equality, assginment or |
|
1707 | # If the rest of the line begins with an (in)equality, assginment or | |
1793 | # function call, we should not call _ofind but simply execute it. |
|
1708 | # function call, we should not call _ofind but simply execute it. | |
1794 | # This avoids spurious geattr() accesses on objects upon assignment. |
|
1709 | # This avoids spurious geattr() accesses on objects upon assignment. | |
1795 | # |
|
1710 | # | |
1796 | # It also allows users to assign to either alias or magic names true |
|
1711 | # It also allows users to assign to either alias or magic names true | |
1797 | # python variables (the magic/alias systems always take second seat to |
|
1712 | # python variables (the magic/alias systems always take second seat to | |
1798 | # true python code). |
|
1713 | # true python code). | |
1799 | if theRest and theRest[0] in '!=()': |
|
1714 | if theRest and theRest[0] in '!=()': | |
1800 | return self.handle_normal(line,continue_prompt) |
|
1715 | return self.handle_normal(line,continue_prompt) | |
1801 |
|
1716 | |||
1802 | if oinfo is None: |
|
1717 | if oinfo is None: | |
1803 | oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic |
|
1718 | oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic | |
1804 |
|
1719 | |||
1805 | if not oinfo['found']: |
|
1720 | if not oinfo['found']: | |
1806 | return self.handle_normal(line,continue_prompt) |
|
1721 | return self.handle_normal(line,continue_prompt) | |
1807 | else: |
|
1722 | else: | |
1808 | #print 'iFun <%s> rest <%s>' % (iFun,theRest) # dbg |
|
1723 | #print 'iFun <%s> rest <%s>' % (iFun,theRest) # dbg | |
1809 | if oinfo['isalias']: |
|
1724 | if oinfo['isalias']: | |
1810 | return self.handle_alias(line,continue_prompt, |
|
1725 | return self.handle_alias(line,continue_prompt, | |
1811 | pre,iFun,theRest) |
|
1726 | pre,iFun,theRest) | |
1812 |
|
1727 | |||
1813 | if self.rc.autocall and \ |
|
1728 | if self.rc.autocall and \ | |
1814 | not self.re_exclude_auto.match(theRest) and \ |
|
1729 | not self.re_exclude_auto.match(theRest) and \ | |
1815 | self.re_fun_name.match(iFun) and \ |
|
1730 | self.re_fun_name.match(iFun) and \ | |
1816 | callable(oinfo['obj']) : |
|
1731 | callable(oinfo['obj']) : | |
1817 | #print 'going auto' # dbg |
|
1732 | #print 'going auto' # dbg | |
1818 | return self.handle_auto(line,continue_prompt,pre,iFun,theRest) |
|
1733 | return self.handle_auto(line,continue_prompt,pre,iFun,theRest) | |
1819 | else: |
|
1734 | else: | |
1820 | #print 'was callable?', callable(oinfo['obj']) # dbg |
|
1735 | #print 'was callable?', callable(oinfo['obj']) # dbg | |
1821 | return self.handle_normal(line,continue_prompt) |
|
1736 | return self.handle_normal(line,continue_prompt) | |
1822 |
|
1737 | |||
1823 | # If we get here, we have a normal Python line. Log and return. |
|
1738 | # If we get here, we have a normal Python line. Log and return. | |
1824 | return self.handle_normal(line,continue_prompt) |
|
1739 | return self.handle_normal(line,continue_prompt) | |
1825 |
|
1740 | |||
1826 | def _prefilter_dumb(self, line, continue_prompt): |
|
1741 | def _prefilter_dumb(self, line, continue_prompt): | |
1827 | """simple prefilter function, for debugging""" |
|
1742 | """simple prefilter function, for debugging""" | |
1828 | return self.handle_normal(line,continue_prompt) |
|
1743 | return self.handle_normal(line,continue_prompt) | |
1829 |
|
1744 | |||
1830 | # Set the default prefilter() function (this can be user-overridden) |
|
1745 | # Set the default prefilter() function (this can be user-overridden) | |
1831 | prefilter = _prefilter |
|
1746 | prefilter = _prefilter | |
1832 |
|
1747 | |||
1833 | def handle_normal(self,line,continue_prompt=None, |
|
1748 | def handle_normal(self,line,continue_prompt=None, | |
1834 | pre=None,iFun=None,theRest=None): |
|
1749 | pre=None,iFun=None,theRest=None): | |
1835 | """Handle normal input lines. Use as a template for handlers.""" |
|
1750 | """Handle normal input lines. Use as a template for handlers.""" | |
1836 |
|
1751 | |||
1837 | self.log(line,continue_prompt) |
|
1752 | self.log(line,continue_prompt) | |
1838 | self.update_cache(line) |
|
1753 | self.update_cache(line) | |
1839 | return line |
|
1754 | return line | |
1840 |
|
1755 | |||
1841 | def handle_alias(self,line,continue_prompt=None, |
|
1756 | def handle_alias(self,line,continue_prompt=None, | |
1842 | pre=None,iFun=None,theRest=None): |
|
1757 | pre=None,iFun=None,theRest=None): | |
1843 | """Handle alias input lines. """ |
|
1758 | """Handle alias input lines. """ | |
1844 |
|
1759 | |||
1845 | theRest = esc_quotes(theRest) |
|
1760 | theRest = esc_quotes(theRest) | |
1846 | line_out = "%s%s.call_alias('%s','%s')" % (pre,self.name,iFun,theRest) |
|
1761 | line_out = "%s%s.call_alias('%s','%s')" % (pre,self.name,iFun,theRest) | |
1847 | self.log(line_out,continue_prompt) |
|
1762 | self.log(line_out,continue_prompt) | |
1848 | self.update_cache(line_out) |
|
1763 | self.update_cache(line_out) | |
1849 | return line_out |
|
1764 | return line_out | |
1850 |
|
1765 | |||
1851 | def handle_shell_escape(self, line, continue_prompt=None, |
|
1766 | def handle_shell_escape(self, line, continue_prompt=None, | |
1852 | pre=None,iFun=None,theRest=None): |
|
1767 | pre=None,iFun=None,theRest=None): | |
1853 | """Execute the line in a shell, empty return value""" |
|
1768 | """Execute the line in a shell, empty return value""" | |
1854 |
|
1769 | |||
1855 | # Example of a special handler. Others follow a similar pattern. |
|
1770 | # Example of a special handler. Others follow a similar pattern. | |
1856 | if continue_prompt: # multi-line statements |
|
1771 | if continue_prompt: # multi-line statements | |
1857 | if iFun.startswith('!!'): |
|
1772 | if iFun.startswith('!!'): | |
1858 | print 'SyntaxError: !! is not allowed in multiline statements' |
|
1773 | print 'SyntaxError: !! is not allowed in multiline statements' | |
1859 | return pre |
|
1774 | return pre | |
1860 | else: |
|
1775 | else: | |
1861 | cmd = ("%s %s" % (iFun[1:],theRest)).replace('"','\\"') |
|
1776 | cmd = ("%s %s" % (iFun[1:],theRest)).replace('"','\\"') | |
1862 | line_out = '%s%s.system("%s")' % (pre,self.name,cmd) |
|
1777 | line_out = '%s%s.system("%s")' % (pre,self.name,cmd) | |
1863 | else: # single-line input |
|
1778 | else: # single-line input | |
1864 | if line.startswith('!!'): |
|
1779 | if line.startswith('!!'): | |
1865 | # rewrite iFun/theRest to properly hold the call to %sx and |
|
1780 | # rewrite iFun/theRest to properly hold the call to %sx and | |
1866 | # the actual command to be executed, so handle_magic can work |
|
1781 | # the actual command to be executed, so handle_magic can work | |
1867 | # correctly |
|
1782 | # correctly | |
1868 | theRest = '%s %s' % (iFun[2:],theRest) |
|
1783 | theRest = '%s %s' % (iFun[2:],theRest) | |
1869 | iFun = 'sx' |
|
1784 | iFun = 'sx' | |
1870 | return self.handle_magic('%ssx %s' % (self.ESC_MAGIC,line[2:]), |
|
1785 | return self.handle_magic('%ssx %s' % (self.ESC_MAGIC,line[2:]), | |
1871 | continue_prompt,pre,iFun,theRest) |
|
1786 | continue_prompt,pre,iFun,theRest) | |
1872 | else: |
|
1787 | else: | |
1873 | cmd = esc_quotes(line[1:]) |
|
1788 | cmd = esc_quotes(line[1:]) | |
1874 | line_out = '%s.system("%s")' % (self.name,cmd) |
|
1789 | line_out = '%s.system("%s")' % (self.name,cmd) | |
1875 | # update cache/log and return |
|
1790 | # update cache/log and return | |
1876 | self.log(line_out,continue_prompt) |
|
1791 | self.log(line_out,continue_prompt) | |
1877 | self.update_cache(line_out) # readline cache gets normal line |
|
1792 | self.update_cache(line_out) # readline cache gets normal line | |
1878 | return line_out |
|
1793 | return line_out | |
1879 |
|
1794 | |||
1880 | def handle_magic(self, line, continue_prompt=None, |
|
1795 | def handle_magic(self, line, continue_prompt=None, | |
1881 | pre=None,iFun=None,theRest=None): |
|
1796 | pre=None,iFun=None,theRest=None): | |
1882 | """Execute magic functions. |
|
1797 | """Execute magic functions. | |
1883 |
|
1798 | |||
1884 | Also log them with a prepended # so the log is clean Python.""" |
|
1799 | Also log them with a prepended # so the log is clean Python.""" | |
1885 |
|
1800 | |||
1886 | cmd = '%sipmagic("%s")' % (pre,esc_quotes('%s %s' % (iFun,theRest))) |
|
1801 | cmd = '%sipmagic("%s")' % (pre,esc_quotes('%s %s' % (iFun,theRest))) | |
1887 | self.log(cmd,continue_prompt) |
|
1802 | self.log(cmd,continue_prompt) | |
1888 | self.update_cache(line) |
|
1803 | self.update_cache(line) | |
1889 | #print 'in handle_magic, cmd=<%s>' % cmd # dbg |
|
1804 | #print 'in handle_magic, cmd=<%s>' % cmd # dbg | |
1890 | return cmd |
|
1805 | return cmd | |
1891 |
|
1806 | |||
1892 | def handle_auto(self, line, continue_prompt=None, |
|
1807 | def handle_auto(self, line, continue_prompt=None, | |
1893 | pre=None,iFun=None,theRest=None): |
|
1808 | pre=None,iFun=None,theRest=None): | |
1894 | """Hande lines which can be auto-executed, quoting if requested.""" |
|
1809 | """Hande lines which can be auto-executed, quoting if requested.""" | |
1895 |
|
1810 | |||
1896 | #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg |
|
1811 | #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg | |
1897 |
|
1812 | |||
1898 | # This should only be active for single-line input! |
|
1813 | # This should only be active for single-line input! | |
1899 | if continue_prompt: |
|
1814 | if continue_prompt: | |
1900 | return line |
|
1815 | return line | |
1901 |
|
1816 | |||
1902 | if pre == self.ESC_QUOTE: |
|
1817 | if pre == self.ESC_QUOTE: | |
1903 | # Auto-quote splitting on whitespace |
|
1818 | # Auto-quote splitting on whitespace | |
1904 | newcmd = '%s("%s")\n' % (iFun,'", "'.join(theRest.split()) ) |
|
1819 | newcmd = '%s("%s")\n' % (iFun,'", "'.join(theRest.split()) ) | |
1905 | elif pre == self.ESC_QUOTE2: |
|
1820 | elif pre == self.ESC_QUOTE2: | |
1906 | # Auto-quote whole string |
|
1821 | # Auto-quote whole string | |
1907 | newcmd = '%s("%s")\n' % (iFun,theRest) |
|
1822 | newcmd = '%s("%s")\n' % (iFun,theRest) | |
1908 | else: |
|
1823 | else: | |
1909 | # Auto-paren |
|
1824 | # Auto-paren | |
1910 | if theRest[0:1] in ('=','['): |
|
1825 | if theRest[0:1] in ('=','['): | |
1911 | # Don't autocall in these cases. They can be either |
|
1826 | # Don't autocall in these cases. They can be either | |
1912 | # rebindings of an existing callable's name, or item access |
|
1827 | # rebindings of an existing callable's name, or item access | |
1913 | # for an object which is BOTH callable and implements |
|
1828 | # for an object which is BOTH callable and implements | |
1914 | # __getitem__. |
|
1829 | # __getitem__. | |
1915 | return '%s %s\n' % (iFun,theRest) |
|
1830 | return '%s %s\n' % (iFun,theRest) | |
1916 | if theRest.endswith(';'): |
|
1831 | if theRest.endswith(';'): | |
1917 | newcmd = '%s(%s);\n' % (iFun.rstrip(),theRest[:-1]) |
|
1832 | newcmd = '%s(%s);\n' % (iFun.rstrip(),theRest[:-1]) | |
1918 | else: |
|
1833 | else: | |
1919 | newcmd = '%s(%s)\n' % (iFun.rstrip(),theRest) |
|
1834 | newcmd = '%s(%s)\n' % (iFun.rstrip(),theRest) | |
1920 |
|
1835 | |||
1921 | print >>Term.cout, self.outputcache.prompt1.auto_rewrite() + newcmd, |
|
1836 | print >>Term.cout, self.outputcache.prompt1.auto_rewrite() + newcmd, | |
1922 | # log what is now valid Python, not the actual user input (without the |
|
1837 | # log what is now valid Python, not the actual user input (without the | |
1923 | # final newline) |
|
1838 | # final newline) | |
1924 | self.log(newcmd.strip(),continue_prompt) |
|
1839 | self.log(newcmd.strip(),continue_prompt) | |
1925 | return newcmd |
|
1840 | return newcmd | |
1926 |
|
1841 | |||
1927 | def handle_help(self, line, continue_prompt=None, |
|
1842 | def handle_help(self, line, continue_prompt=None, | |
1928 | pre=None,iFun=None,theRest=None): |
|
1843 | pre=None,iFun=None,theRest=None): | |
1929 | """Try to get some help for the object. |
|
1844 | """Try to get some help for the object. | |
1930 |
|
1845 | |||
1931 | obj? or ?obj -> basic information. |
|
1846 | obj? or ?obj -> basic information. | |
1932 | obj?? or ??obj -> more details. |
|
1847 | obj?? or ??obj -> more details. | |
1933 | """ |
|
1848 | """ | |
1934 |
|
1849 | |||
1935 | # We need to make sure that we don't process lines which would be |
|
1850 | # We need to make sure that we don't process lines which would be | |
1936 | # otherwise valid python, such as "x=1 # what?" |
|
1851 | # otherwise valid python, such as "x=1 # what?" | |
1937 | try: |
|
1852 | try: | |
1938 | code.compile_command(line) |
|
1853 | code.compile_command(line) | |
1939 | except SyntaxError: |
|
1854 | except SyntaxError: | |
1940 | # We should only handle as help stuff which is NOT valid syntax |
|
1855 | # We should only handle as help stuff which is NOT valid syntax | |
1941 | if line[0]==self.ESC_HELP: |
|
1856 | if line[0]==self.ESC_HELP: | |
1942 | line = line[1:] |
|
1857 | line = line[1:] | |
1943 | elif line[-1]==self.ESC_HELP: |
|
1858 | elif line[-1]==self.ESC_HELP: | |
1944 | line = line[:-1] |
|
1859 | line = line[:-1] | |
1945 | self.log('#?'+line) |
|
1860 | self.log('#?'+line) | |
1946 | self.update_cache(line) |
|
1861 | self.update_cache(line) | |
1947 | if line: |
|
1862 | if line: | |
1948 | self.magic_pinfo(line) |
|
1863 | self.magic_pinfo(line) | |
1949 | else: |
|
1864 | else: | |
1950 | page(self.usage,screen_lines=self.rc.screen_length) |
|
1865 | page(self.usage,screen_lines=self.rc.screen_length) | |
1951 | return '' # Empty string is needed here! |
|
1866 | return '' # Empty string is needed here! | |
1952 | except: |
|
1867 | except: | |
1953 | # Pass any other exceptions through to the normal handler |
|
1868 | # Pass any other exceptions through to the normal handler | |
1954 | return self.handle_normal(line,continue_prompt) |
|
1869 | return self.handle_normal(line,continue_prompt) | |
1955 | else: |
|
1870 | else: | |
1956 | # If the code compiles ok, we should handle it normally |
|
1871 | # If the code compiles ok, we should handle it normally | |
1957 | return self.handle_normal(line,continue_prompt) |
|
1872 | return self.handle_normal(line,continue_prompt) | |
1958 |
|
1873 | |||
1959 | def handle_emacs(self,line,continue_prompt=None, |
|
1874 | def handle_emacs(self,line,continue_prompt=None, | |
1960 | pre=None,iFun=None,theRest=None): |
|
1875 | pre=None,iFun=None,theRest=None): | |
1961 | """Handle input lines marked by python-mode.""" |
|
1876 | """Handle input lines marked by python-mode.""" | |
1962 |
|
1877 | |||
1963 | # Currently, nothing is done. Later more functionality can be added |
|
1878 | # Currently, nothing is done. Later more functionality can be added | |
1964 | # here if needed. |
|
1879 | # here if needed. | |
1965 |
|
1880 | |||
1966 | # The input cache shouldn't be updated |
|
1881 | # The input cache shouldn't be updated | |
1967 |
|
1882 | |||
1968 | return line |
|
1883 | return line | |
1969 |
|
1884 | |||
1970 | def write(self,data): |
|
1885 | def write(self,data): | |
1971 | """Write a string to the default output""" |
|
1886 | """Write a string to the default output""" | |
1972 | Term.cout.write(data) |
|
1887 | Term.cout.write(data) | |
1973 |
|
1888 | |||
1974 | def write_err(self,data): |
|
1889 | def write_err(self,data): | |
1975 | """Write a string to the default error output""" |
|
1890 | """Write a string to the default error output""" | |
1976 | Term.cerr.write(data) |
|
1891 | Term.cerr.write(data) | |
1977 |
|
1892 | |||
1978 | def safe_execfile(self,fname,*where,**kw): |
|
1893 | def safe_execfile(self,fname,*where,**kw): | |
1979 | fname = os.path.expanduser(fname) |
|
1894 | fname = os.path.expanduser(fname) | |
1980 |
|
1895 | |||
1981 | # find things also in current directory |
|
1896 | # find things also in current directory | |
1982 | dname = os.path.dirname(fname) |
|
1897 | dname = os.path.dirname(fname) | |
1983 | if not sys.path.count(dname): |
|
1898 | if not sys.path.count(dname): | |
1984 | sys.path.append(dname) |
|
1899 | sys.path.append(dname) | |
1985 |
|
1900 | |||
1986 | try: |
|
1901 | try: | |
1987 | xfile = open(fname) |
|
1902 | xfile = open(fname) | |
1988 | except: |
|
1903 | except: | |
1989 | print >> Term.cerr, \ |
|
1904 | print >> Term.cerr, \ | |
1990 | 'Could not open file <%s> for safe execution.' % fname |
|
1905 | 'Could not open file <%s> for safe execution.' % fname | |
1991 | return None |
|
1906 | return None | |
1992 |
|
1907 | |||
1993 | kw.setdefault('islog',0) |
|
1908 | kw.setdefault('islog',0) | |
1994 | kw.setdefault('quiet',1) |
|
1909 | kw.setdefault('quiet',1) | |
1995 | kw.setdefault('exit_ignore',0) |
|
1910 | kw.setdefault('exit_ignore',0) | |
1996 | first = xfile.readline() |
|
1911 | first = xfile.readline() | |
1997 | _LOGHEAD = str(self.LOGHEAD).split('\n',1)[0].strip() |
|
1912 | _LOGHEAD = str(self.LOGHEAD).split('\n',1)[0].strip() | |
1998 | xfile.close() |
|
1913 | xfile.close() | |
1999 | # line by line execution |
|
1914 | # line by line execution | |
2000 | if first.startswith(_LOGHEAD) or kw['islog']: |
|
1915 | if first.startswith(_LOGHEAD) or kw['islog']: | |
2001 | print 'Loading log file <%s> one line at a time...' % fname |
|
1916 | print 'Loading log file <%s> one line at a time...' % fname | |
2002 | if kw['quiet']: |
|
1917 | if kw['quiet']: | |
2003 | stdout_save = sys.stdout |
|
1918 | stdout_save = sys.stdout | |
2004 | sys.stdout = StringIO.StringIO() |
|
1919 | sys.stdout = StringIO.StringIO() | |
2005 | try: |
|
1920 | try: | |
2006 | globs,locs = where[0:2] |
|
1921 | globs,locs = where[0:2] | |
2007 | except: |
|
1922 | except: | |
2008 | try: |
|
1923 | try: | |
2009 | globs = locs = where[0] |
|
1924 | globs = locs = where[0] | |
2010 | except: |
|
1925 | except: | |
2011 | globs = locs = globals() |
|
1926 | globs = locs = globals() | |
2012 | badblocks = [] |
|
1927 | badblocks = [] | |
2013 |
|
1928 | |||
2014 | # we also need to identify indented blocks of code when replaying |
|
1929 | # we also need to identify indented blocks of code when replaying | |
2015 | # logs and put them together before passing them to an exec |
|
1930 | # logs and put them together before passing them to an exec | |
2016 | # statement. This takes a bit of regexp and look-ahead work in the |
|
1931 | # statement. This takes a bit of regexp and look-ahead work in the | |
2017 | # file. It's easiest if we swallow the whole thing in memory |
|
1932 | # file. It's easiest if we swallow the whole thing in memory | |
2018 | # first, and manually walk through the lines list moving the |
|
1933 | # first, and manually walk through the lines list moving the | |
2019 | # counter ourselves. |
|
1934 | # counter ourselves. | |
2020 | indent_re = re.compile('\s+\S') |
|
1935 | indent_re = re.compile('\s+\S') | |
2021 | xfile = open(fname) |
|
1936 | xfile = open(fname) | |
2022 | filelines = xfile.readlines() |
|
1937 | filelines = xfile.readlines() | |
2023 | xfile.close() |
|
1938 | xfile.close() | |
2024 | nlines = len(filelines) |
|
1939 | nlines = len(filelines) | |
2025 | lnum = 0 |
|
1940 | lnum = 0 | |
2026 | while lnum < nlines: |
|
1941 | while lnum < nlines: | |
2027 | line = filelines[lnum] |
|
1942 | line = filelines[lnum] | |
2028 | lnum += 1 |
|
1943 | lnum += 1 | |
2029 | # don't re-insert logger status info into cache |
|
1944 | # don't re-insert logger status info into cache | |
2030 | if line.startswith('#log#'): |
|
1945 | if line.startswith('#log#'): | |
2031 | continue |
|
1946 | continue | |
2032 | elif line.startswith('#%s'% self.ESC_MAGIC): |
|
1947 | elif line.startswith('#%s'% self.ESC_MAGIC): | |
2033 | self.update_cache(line[1:]) |
|
1948 | self.update_cache(line[1:]) | |
2034 | line = magic2python(line) |
|
1949 | line = magic2python(line) | |
2035 | elif line.startswith('#!'): |
|
1950 | elif line.startswith('#!'): | |
2036 | self.update_cache(line[1:]) |
|
1951 | self.update_cache(line[1:]) | |
2037 | else: |
|
1952 | else: | |
2038 | # build a block of code (maybe a single line) for execution |
|
1953 | # build a block of code (maybe a single line) for execution | |
2039 | block = line |
|
1954 | block = line | |
2040 | try: |
|
1955 | try: | |
2041 | next = filelines[lnum] # lnum has already incremented |
|
1956 | next = filelines[lnum] # lnum has already incremented | |
2042 | except: |
|
1957 | except: | |
2043 | next = None |
|
1958 | next = None | |
2044 | while next and indent_re.match(next): |
|
1959 | while next and indent_re.match(next): | |
2045 | block += next |
|
1960 | block += next | |
2046 | lnum += 1 |
|
1961 | lnum += 1 | |
2047 | try: |
|
1962 | try: | |
2048 | next = filelines[lnum] |
|
1963 | next = filelines[lnum] | |
2049 | except: |
|
1964 | except: | |
2050 | next = None |
|
1965 | next = None | |
2051 | # now execute the block of one or more lines |
|
1966 | # now execute the block of one or more lines | |
2052 | try: |
|
1967 | try: | |
2053 | exec block in globs,locs |
|
1968 | exec block in globs,locs | |
2054 | self.update_cache(block.rstrip()) |
|
1969 | self.update_cache(block.rstrip()) | |
2055 | except SystemExit: |
|
1970 | except SystemExit: | |
2056 | pass |
|
1971 | pass | |
2057 | except: |
|
1972 | except: | |
2058 | badblocks.append(block.rstrip()) |
|
1973 | badblocks.append(block.rstrip()) | |
2059 | if kw['quiet']: # restore stdout |
|
1974 | if kw['quiet']: # restore stdout | |
2060 | sys.stdout.close() |
|
1975 | sys.stdout.close() | |
2061 | sys.stdout = stdout_save |
|
1976 | sys.stdout = stdout_save | |
2062 | print 'Finished replaying log file <%s>' % fname |
|
1977 | print 'Finished replaying log file <%s>' % fname | |
2063 | if badblocks: |
|
1978 | if badblocks: | |
2064 | print >> sys.stderr, \ |
|
1979 | print >> sys.stderr, \ | |
2065 | '\nThe following lines/blocks in file <%s> reported errors:' \ |
|
1980 | '\nThe following lines/blocks in file <%s> reported errors:' \ | |
2066 | % fname |
|
1981 | % fname | |
2067 | for badline in badblocks: |
|
1982 | for badline in badblocks: | |
2068 | print >> sys.stderr, badline |
|
1983 | print >> sys.stderr, badline | |
2069 | else: # regular file execution |
|
1984 | else: # regular file execution | |
2070 | try: |
|
1985 | try: | |
2071 | execfile(fname,*where) |
|
1986 | execfile(fname,*where) | |
2072 | except SyntaxError: |
|
1987 | except SyntaxError: | |
2073 | etype, evalue = sys.exc_info()[0:2] |
|
1988 | etype, evalue = sys.exc_info()[0:2] | |
2074 | self.SyntaxTB(etype,evalue,[]) |
|
1989 | self.SyntaxTB(etype,evalue,[]) | |
2075 | warn('Failure executing file: <%s>' % fname) |
|
1990 | warn('Failure executing file: <%s>' % fname) | |
2076 | except SystemExit,status: |
|
1991 | except SystemExit,status: | |
2077 | if not kw['exit_ignore']: |
|
1992 | if not kw['exit_ignore']: | |
2078 | self.InteractiveTB() |
|
1993 | self.InteractiveTB() | |
2079 | warn('Failure executing file: <%s>' % fname) |
|
1994 | warn('Failure executing file: <%s>' % fname) | |
2080 | except: |
|
1995 | except: | |
2081 | self.InteractiveTB() |
|
1996 | self.InteractiveTB() | |
2082 | warn('Failure executing file: <%s>' % fname) |
|
1997 | warn('Failure executing file: <%s>' % fname) | |
2083 |
|
1998 | |||
2084 | #************************* end of file <iplib.py> ***************************** |
|
1999 | #************************* end of file <iplib.py> ***************************** |
@@ -1,736 +1,725 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """ |
|
2 | """ | |
3 | IPython -- An enhanced Interactive Python |
|
3 | IPython -- An enhanced Interactive Python | |
4 |
|
4 | |||
5 | Requires Python 2.1 or better. |
|
5 | Requires Python 2.1 or better. | |
6 |
|
6 | |||
7 | This file contains the main make_IPython() starter function. |
|
7 | This file contains the main make_IPython() starter function. | |
8 |
|
8 | |||
9 |
$Id: ipmaker.py |
|
9 | $Id: ipmaker.py 638 2005-07-18 03:01:41Z fperez $""" | |
10 |
|
10 | |||
11 | #***************************************************************************** |
|
11 | #***************************************************************************** | |
12 | # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu> |
|
12 | # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu> | |
13 | # |
|
13 | # | |
14 | # Distributed under the terms of the BSD License. The full license is in |
|
14 | # Distributed under the terms of the BSD License. The full license is in | |
15 | # the file COPYING, distributed as part of this software. |
|
15 | # the file COPYING, distributed as part of this software. | |
16 | #***************************************************************************** |
|
16 | #***************************************************************************** | |
17 |
|
17 | |||
18 | from IPython import Release |
|
18 | from IPython import Release | |
19 | __author__ = '%s <%s>' % Release.authors['Fernando'] |
|
19 | __author__ = '%s <%s>' % Release.authors['Fernando'] | |
20 | __license__ = Release.license |
|
20 | __license__ = Release.license | |
21 | __version__ = Release.version |
|
21 | __version__ = Release.version | |
22 |
|
22 | |||
23 | credits._Printer__data = """ |
|
23 | credits._Printer__data = """ | |
24 | Python: %s |
|
24 | Python: %s | |
25 |
|
25 | |||
26 | IPython: Fernando Perez, Janko Hauser, Nathan Gray, and many users. |
|
26 | IPython: Fernando Perez, Janko Hauser, Nathan Gray, and many users. | |
27 | See http://ipython.scipy.org for more information.""" \ |
|
27 | See http://ipython.scipy.org for more information.""" \ | |
28 | % credits._Printer__data |
|
28 | % credits._Printer__data | |
29 |
|
29 | |||
30 | copyright._Printer__data += """ |
|
30 | copyright._Printer__data += """ | |
31 |
|
31 | |||
32 | Copyright (c) 2001-2004 Fernando Perez, Janko Hauser, Nathan Gray. |
|
32 | Copyright (c) 2001-2004 Fernando Perez, Janko Hauser, Nathan Gray. | |
33 | All Rights Reserved.""" |
|
33 | All Rights Reserved.""" | |
34 |
|
34 | |||
35 | #**************************************************************************** |
|
35 | #**************************************************************************** | |
36 | # Required modules |
|
36 | # Required modules | |
37 |
|
37 | |||
38 | # From the standard library |
|
38 | # From the standard library | |
39 | import __main__, __builtin__ |
|
39 | import __main__, __builtin__ | |
40 | import os,sys,types,re |
|
40 | import os,sys,types,re | |
41 | from pprint import pprint,pformat |
|
41 | from pprint import pprint,pformat | |
42 |
|
42 | |||
43 | # Our own |
|
43 | # Our own | |
44 | from IPython import DPyGetOpt |
|
44 | from IPython import DPyGetOpt | |
45 | from IPython.Struct import Struct |
|
45 | from IPython.Struct import Struct | |
46 | from IPython.OutputTrap import OutputTrap |
|
46 | from IPython.OutputTrap import OutputTrap | |
47 | from IPython.ConfigLoader import ConfigLoader |
|
47 | from IPython.ConfigLoader import ConfigLoader | |
48 | from IPython.iplib import InteractiveShell,qw_lol,import_fail_info |
|
48 | from IPython.iplib import InteractiveShell,qw_lol,import_fail_info | |
49 | from IPython.usage import cmd_line_usage,interactive_usage |
|
49 | from IPython.usage import cmd_line_usage,interactive_usage | |
50 | from IPython.Prompts import CachedOutput |
|
50 | from IPython.Prompts import CachedOutput | |
51 | from IPython.genutils import * |
|
51 | from IPython.genutils import * | |
52 |
|
52 | |||
53 | #----------------------------------------------------------------------------- |
|
53 | #----------------------------------------------------------------------------- | |
54 | def make_IPython(argv=None,user_ns=None,debug=1,rc_override=None, |
|
54 | def make_IPython(argv=None,user_ns=None,debug=1,rc_override=None, | |
55 | shell_class=InteractiveShell,embedded=False,**kw): |
|
55 | shell_class=InteractiveShell,embedded=False,**kw): | |
56 | """This is a dump of IPython into a single function. |
|
56 | """This is a dump of IPython into a single function. | |
57 |
|
57 | |||
58 | Later it will have to be broken up in a sensible manner. |
|
58 | Later it will have to be broken up in a sensible manner. | |
59 |
|
59 | |||
60 | Arguments: |
|
60 | Arguments: | |
61 |
|
61 | |||
62 | - argv: a list similar to sys.argv[1:]. It should NOT contain the desired |
|
62 | - argv: a list similar to sys.argv[1:]. It should NOT contain the desired | |
63 | script name, b/c DPyGetOpt strips the first argument only for the real |
|
63 | script name, b/c DPyGetOpt strips the first argument only for the real | |
64 | sys.argv. |
|
64 | sys.argv. | |
65 |
|
65 | |||
66 | - user_ns: a dict to be used as the user's namespace.""" |
|
66 | - user_ns: a dict to be used as the user's namespace.""" | |
67 |
|
67 | |||
68 | #---------------------------------------------------------------------- |
|
68 | #---------------------------------------------------------------------- | |
69 | # Defaults and initialization |
|
69 | # Defaults and initialization | |
70 |
|
70 | |||
71 | # For developer debugging, deactivates crash handler and uses pdb. |
|
71 | # For developer debugging, deactivates crash handler and uses pdb. | |
72 | DEVDEBUG = False |
|
72 | DEVDEBUG = False | |
73 |
|
73 | |||
74 | if argv is None: |
|
74 | if argv is None: | |
75 | argv = sys.argv |
|
75 | argv = sys.argv | |
76 |
|
76 | |||
77 | # __IP is the main global that lives throughout and represents the whole |
|
77 | # __IP is the main global that lives throughout and represents the whole | |
78 | # application. If the user redefines it, all bets are off as to what |
|
78 | # application. If the user redefines it, all bets are off as to what | |
79 | # happens. |
|
79 | # happens. | |
80 |
|
80 | |||
81 | # __IP is the name of he global which the caller will have accessible as |
|
81 | # __IP is the name of he global which the caller will have accessible as | |
82 | # __IP.name. We set its name via the first parameter passed to |
|
82 | # __IP.name. We set its name via the first parameter passed to | |
83 | # InteractiveShell: |
|
83 | # InteractiveShell: | |
84 |
|
84 | |||
85 | IP = shell_class('__IP',user_ns=user_ns,**kw) |
|
85 | IP = shell_class('__IP',user_ns=user_ns,**kw) | |
86 |
|
86 | |||
87 | # Put 'help' in the user namespace |
|
87 | # Put 'help' in the user namespace | |
88 | try: |
|
88 | from site import _Helper | |
89 | from site import _Helper |
|
89 | IP.user_ns['help'] = _Helper() | |
90 | except ImportError: |
|
|||
91 | # Use the _Helper class from Python 2.2 for older Python versions |
|
|||
92 | class _Helper: |
|
|||
93 | def __repr__(self): |
|
|||
94 | return "Type help() for interactive help, " \ |
|
|||
95 | "or help(object) for help about object." |
|
|||
96 | def __call__(self, *args, **kwds): |
|
|||
97 | import pydoc |
|
|||
98 | return pydoc.help(*args, **kwds) |
|
|||
99 | else: |
|
|||
100 | IP.user_ns['help'] = _Helper() |
|
|||
101 |
|
90 | |||
102 | if DEVDEBUG: |
|
91 | if DEVDEBUG: | |
103 | # For developer debugging only (global flag) |
|
92 | # For developer debugging only (global flag) | |
104 | from IPython import ultraTB |
|
93 | from IPython import ultraTB | |
105 | sys.excepthook = ultraTB.VerboseTB(call_pdb=1) |
|
94 | sys.excepthook = ultraTB.VerboseTB(call_pdb=1) | |
106 | else: |
|
95 | else: | |
107 | # IPython itself shouldn't crash. This will produce a detailed |
|
96 | # IPython itself shouldn't crash. This will produce a detailed | |
108 | # post-mortem if it does |
|
97 | # post-mortem if it does | |
109 | from IPython import CrashHandler |
|
98 | from IPython import CrashHandler | |
110 | sys.excepthook = CrashHandler.CrashHandler(IP) |
|
99 | sys.excepthook = CrashHandler.CrashHandler(IP) | |
111 |
|
100 | |||
112 | IP.BANNER_PARTS = ['Python %s\n' |
|
101 | IP.BANNER_PARTS = ['Python %s\n' | |
113 | 'Type "copyright", "credits" or "license" ' |
|
102 | 'Type "copyright", "credits" or "license" ' | |
114 | 'for more information.\n' |
|
103 | 'for more information.\n' | |
115 | % (sys.version.split('\n')[0],), |
|
104 | % (sys.version.split('\n')[0],), | |
116 | "IPython %s -- An enhanced Interactive Python." |
|
105 | "IPython %s -- An enhanced Interactive Python." | |
117 | % (__version__,), |
|
106 | % (__version__,), | |
118 | """? -> Introduction to IPython's features. |
|
107 | """? -> Introduction to IPython's features. | |
119 | %magic -> Information about IPython's 'magic' % functions. |
|
108 | %magic -> Information about IPython's 'magic' % functions. | |
120 | help -> Python's own help system. |
|
109 | help -> Python's own help system. | |
121 | object? -> Details about 'object'. ?object also works, ?? prints more. |
|
110 | object? -> Details about 'object'. ?object also works, ?? prints more. | |
122 | """ ] |
|
111 | """ ] | |
123 |
|
112 | |||
124 | IP.usage = interactive_usage |
|
113 | IP.usage = interactive_usage | |
125 |
|
114 | |||
126 | # Platform-dependent suffix and directory names |
|
115 | # Platform-dependent suffix and directory names | |
127 | if os.name == 'posix': |
|
116 | if os.name == 'posix': | |
128 | rc_suffix = '' |
|
117 | rc_suffix = '' | |
129 | ipdir_def = '.ipython' |
|
118 | ipdir_def = '.ipython' | |
130 | else: |
|
119 | else: | |
131 | rc_suffix = '.ini' |
|
120 | rc_suffix = '.ini' | |
132 | ipdir_def = '_ipython' |
|
121 | ipdir_def = '_ipython' | |
133 |
|
122 | |||
134 | # default directory for configuration |
|
123 | # default directory for configuration | |
135 | ipythondir = os.path.abspath(os.environ.get('IPYTHONDIR', |
|
124 | ipythondir = os.path.abspath(os.environ.get('IPYTHONDIR', | |
136 | os.path.join(IP.home_dir,ipdir_def))) |
|
125 | os.path.join(IP.home_dir,ipdir_def))) | |
137 |
|
126 | |||
138 | # we need the directory where IPython itself is installed |
|
127 | # we need the directory where IPython itself is installed | |
139 | import IPython |
|
128 | import IPython | |
140 | IPython_dir = os.path.dirname(IPython.__file__) |
|
129 | IPython_dir = os.path.dirname(IPython.__file__) | |
141 | del IPython |
|
130 | del IPython | |
142 |
|
131 | |||
143 | #------------------------------------------------------------------------- |
|
132 | #------------------------------------------------------------------------- | |
144 | # Command line handling |
|
133 | # Command line handling | |
145 |
|
134 | |||
146 | # Valid command line options (uses DPyGetOpt syntax, like Perl's |
|
135 | # Valid command line options (uses DPyGetOpt syntax, like Perl's | |
147 | # GetOpt::Long) |
|
136 | # GetOpt::Long) | |
148 |
|
137 | |||
149 | # Any key not listed here gets deleted even if in the file (like session |
|
138 | # Any key not listed here gets deleted even if in the file (like session | |
150 | # or profile). That's deliberate, to maintain the rc namespace clean. |
|
139 | # or profile). That's deliberate, to maintain the rc namespace clean. | |
151 |
|
140 | |||
152 | # Each set of options appears twice: under _conv only the names are |
|
141 | # Each set of options appears twice: under _conv only the names are | |
153 | # listed, indicating which type they must be converted to when reading the |
|
142 | # listed, indicating which type they must be converted to when reading the | |
154 | # ipythonrc file. And under DPyGetOpt they are listed with the regular |
|
143 | # ipythonrc file. And under DPyGetOpt they are listed with the regular | |
155 | # DPyGetOpt syntax (=s,=i,:f,etc). |
|
144 | # DPyGetOpt syntax (=s,=i,:f,etc). | |
156 |
|
145 | |||
157 | # Make sure there's a space before each end of line (they get auto-joined!) |
|
146 | # Make sure there's a space before each end of line (they get auto-joined!) | |
158 | cmdline_opts = ('autocall! autoindent! automagic! banner! cache_size|cs=i ' |
|
147 | cmdline_opts = ('autocall! autoindent! automagic! banner! cache_size|cs=i ' | |
159 | 'c=s classic|cl color_info! colors=s confirm_exit! ' |
|
148 | 'c=s classic|cl color_info! colors=s confirm_exit! ' | |
160 | 'debug! deep_reload! editor=s log|l messages! nosep pdb! ' |
|
149 | 'debug! deep_reload! editor=s log|l messages! nosep pdb! ' | |
161 | 'pprint! prompt_in1|pi1=s prompt_in2|pi2=s prompt_out|po=s ' |
|
150 | 'pprint! prompt_in1|pi1=s prompt_in2|pi2=s prompt_out|po=s ' | |
162 | 'quick screen_length|sl=i prompts_pad_left=i ' |
|
151 | 'quick screen_length|sl=i prompts_pad_left=i ' | |
163 | 'logfile|lf=s logplay|lp=s profile|p=s ' |
|
152 | 'logfile|lf=s logplay|lp=s profile|p=s ' | |
164 | 'readline! readline_merge_completions! ' |
|
153 | 'readline! readline_merge_completions! ' | |
165 | 'readline_omit__names! ' |
|
154 | 'readline_omit__names! ' | |
166 | 'rcfile=s separate_in|si=s separate_out|so=s ' |
|
155 | 'rcfile=s separate_in|si=s separate_out|so=s ' | |
167 | 'separate_out2|so2=s xmode=s ' |
|
156 | 'separate_out2|so2=s xmode=s ' | |
168 | 'magic_docstrings system_verbose! ' |
|
157 | 'magic_docstrings system_verbose! ' | |
169 | 'multi_line_specials!') |
|
158 | 'multi_line_specials!') | |
170 |
|
159 | |||
171 | # Options that can *only* appear at the cmd line (not in rcfiles). |
|
160 | # Options that can *only* appear at the cmd line (not in rcfiles). | |
172 |
|
161 | |||
173 | # The "ignore" option is a kludge so that Emacs buffers don't crash, since |
|
162 | # The "ignore" option is a kludge so that Emacs buffers don't crash, since | |
174 | # the 'C-c !' command in emacs automatically appends a -i option at the end. |
|
163 | # the 'C-c !' command in emacs automatically appends a -i option at the end. | |
175 | cmdline_only = ('help ignore|i ipythondir=s Version upgrade ' |
|
164 | cmdline_only = ('help ignore|i ipythondir=s Version upgrade ' | |
176 | 'gthread! qthread! wthread! pylab! tk!') |
|
165 | 'gthread! qthread! wthread! pylab! tk!') | |
177 |
|
166 | |||
178 | # Build the actual name list to be used by DPyGetOpt |
|
167 | # Build the actual name list to be used by DPyGetOpt | |
179 | opts_names = qw(cmdline_opts) + qw(cmdline_only) |
|
168 | opts_names = qw(cmdline_opts) + qw(cmdline_only) | |
180 |
|
169 | |||
181 | # Set sensible command line defaults. |
|
170 | # Set sensible command line defaults. | |
182 | # This should have everything from cmdline_opts and cmdline_only |
|
171 | # This should have everything from cmdline_opts and cmdline_only | |
183 | opts_def = Struct(autocall = 1, |
|
172 | opts_def = Struct(autocall = 1, | |
184 | autoindent=0, |
|
173 | autoindent=0, | |
185 | automagic = 1, |
|
174 | automagic = 1, | |
186 | banner = 1, |
|
175 | banner = 1, | |
187 | cache_size = 1000, |
|
176 | cache_size = 1000, | |
188 | c = '', |
|
177 | c = '', | |
189 | classic = 0, |
|
178 | classic = 0, | |
190 | colors = 'NoColor', |
|
179 | colors = 'NoColor', | |
191 | color_info = 0, |
|
180 | color_info = 0, | |
192 | confirm_exit = 1, |
|
181 | confirm_exit = 1, | |
193 | debug = 0, |
|
182 | debug = 0, | |
194 | deep_reload = 0, |
|
183 | deep_reload = 0, | |
195 | editor = '0', |
|
184 | editor = '0', | |
196 | help = 0, |
|
185 | help = 0, | |
197 | ignore = 0, |
|
186 | ignore = 0, | |
198 | ipythondir = ipythondir, |
|
187 | ipythondir = ipythondir, | |
199 | log = 0, |
|
188 | log = 0, | |
200 | logfile = '', |
|
189 | logfile = '', | |
201 | logplay = '', |
|
190 | logplay = '', | |
202 | multi_line_specials = 1, |
|
191 | multi_line_specials = 1, | |
203 | messages = 1, |
|
192 | messages = 1, | |
204 | nosep = 0, |
|
193 | nosep = 0, | |
205 | pdb = 0, |
|
194 | pdb = 0, | |
206 | pprint = 0, |
|
195 | pprint = 0, | |
207 | profile = '', |
|
196 | profile = '', | |
208 | prompt_in1 = 'In [\\#]:', |
|
197 | prompt_in1 = 'In [\\#]:', | |
209 | prompt_in2 = ' .\\D.:', |
|
198 | prompt_in2 = ' .\\D.:', | |
210 | prompt_out = 'Out[\\#]:', |
|
199 | prompt_out = 'Out[\\#]:', | |
211 | prompts_pad_left = 1, |
|
200 | prompts_pad_left = 1, | |
212 | quick = 0, |
|
201 | quick = 0, | |
213 | readline = 1, |
|
202 | readline = 1, | |
214 | readline_merge_completions = 1, |
|
203 | readline_merge_completions = 1, | |
215 | readline_omit__names = 0, |
|
204 | readline_omit__names = 0, | |
216 | rcfile = 'ipythonrc' + rc_suffix, |
|
205 | rcfile = 'ipythonrc' + rc_suffix, | |
217 | screen_length = 0, |
|
206 | screen_length = 0, | |
218 | separate_in = '\n', |
|
207 | separate_in = '\n', | |
219 | separate_out = '\n', |
|
208 | separate_out = '\n', | |
220 | separate_out2 = '', |
|
209 | separate_out2 = '', | |
221 | system_verbose = 0, |
|
210 | system_verbose = 0, | |
222 | gthread = 0, |
|
211 | gthread = 0, | |
223 | qthread = 0, |
|
212 | qthread = 0, | |
224 | wthread = 0, |
|
213 | wthread = 0, | |
225 | pylab = 0, |
|
214 | pylab = 0, | |
226 | tk = 0, |
|
215 | tk = 0, | |
227 | upgrade = 0, |
|
216 | upgrade = 0, | |
228 | Version = 0, |
|
217 | Version = 0, | |
229 | xmode = 'Verbose', |
|
218 | xmode = 'Verbose', | |
230 | magic_docstrings = 0, # undocumented, for doc generation |
|
219 | magic_docstrings = 0, # undocumented, for doc generation | |
231 | ) |
|
220 | ) | |
232 |
|
221 | |||
233 | # Things that will *only* appear in rcfiles (not at the command line). |
|
222 | # Things that will *only* appear in rcfiles (not at the command line). | |
234 | # Make sure there's a space before each end of line (they get auto-joined!) |
|
223 | # Make sure there's a space before each end of line (they get auto-joined!) | |
235 | rcfile_opts = { qwflat: 'include import_mod import_all execfile ', |
|
224 | rcfile_opts = { qwflat: 'include import_mod import_all execfile ', | |
236 | qw_lol: 'import_some ', |
|
225 | qw_lol: 'import_some ', | |
237 | # for things with embedded whitespace: |
|
226 | # for things with embedded whitespace: | |
238 | list_strings:'execute alias readline_parse_and_bind ', |
|
227 | list_strings:'execute alias readline_parse_and_bind ', | |
239 | # Regular strings need no conversion: |
|
228 | # Regular strings need no conversion: | |
240 | None:'readline_remove_delims ', |
|
229 | None:'readline_remove_delims ', | |
241 | } |
|
230 | } | |
242 | # Default values for these |
|
231 | # Default values for these | |
243 | rc_def = Struct(include = [], |
|
232 | rc_def = Struct(include = [], | |
244 | import_mod = [], |
|
233 | import_mod = [], | |
245 | import_all = [], |
|
234 | import_all = [], | |
246 | import_some = [[]], |
|
235 | import_some = [[]], | |
247 | execute = [], |
|
236 | execute = [], | |
248 | execfile = [], |
|
237 | execfile = [], | |
249 | alias = [], |
|
238 | alias = [], | |
250 | readline_parse_and_bind = [], |
|
239 | readline_parse_and_bind = [], | |
251 | readline_remove_delims = '', |
|
240 | readline_remove_delims = '', | |
252 | ) |
|
241 | ) | |
253 |
|
242 | |||
254 | # Build the type conversion dictionary from the above tables: |
|
243 | # Build the type conversion dictionary from the above tables: | |
255 | typeconv = rcfile_opts.copy() |
|
244 | typeconv = rcfile_opts.copy() | |
256 | typeconv.update(optstr2types(cmdline_opts)) |
|
245 | typeconv.update(optstr2types(cmdline_opts)) | |
257 |
|
246 | |||
258 | # FIXME: the None key appears in both, put that back together by hand. Ugly! |
|
247 | # FIXME: the None key appears in both, put that back together by hand. Ugly! | |
259 | typeconv[None] += ' ' + rcfile_opts[None] |
|
248 | typeconv[None] += ' ' + rcfile_opts[None] | |
260 |
|
249 | |||
261 | # Remove quotes at ends of all strings (used to protect spaces) |
|
250 | # Remove quotes at ends of all strings (used to protect spaces) | |
262 | typeconv[unquote_ends] = typeconv[None] |
|
251 | typeconv[unquote_ends] = typeconv[None] | |
263 | del typeconv[None] |
|
252 | del typeconv[None] | |
264 |
|
253 | |||
265 | # Build the list we'll use to make all config decisions with defaults: |
|
254 | # Build the list we'll use to make all config decisions with defaults: | |
266 | opts_all = opts_def.copy() |
|
255 | opts_all = opts_def.copy() | |
267 | opts_all.update(rc_def) |
|
256 | opts_all.update(rc_def) | |
268 |
|
257 | |||
269 | # Build conflict resolver for recursive loading of config files: |
|
258 | # Build conflict resolver for recursive loading of config files: | |
270 | # - preserve means the outermost file maintains the value, it is not |
|
259 | # - preserve means the outermost file maintains the value, it is not | |
271 | # overwritten if an included file has the same key. |
|
260 | # overwritten if an included file has the same key. | |
272 | # - add_flip applies + to the two values, so it better make sense to add |
|
261 | # - add_flip applies + to the two values, so it better make sense to add | |
273 | # those types of keys. But it flips them first so that things loaded |
|
262 | # those types of keys. But it flips them first so that things loaded | |
274 | # deeper in the inclusion chain have lower precedence. |
|
263 | # deeper in the inclusion chain have lower precedence. | |
275 | conflict = {'preserve': ' '.join([ typeconv[int], |
|
264 | conflict = {'preserve': ' '.join([ typeconv[int], | |
276 | typeconv[unquote_ends] ]), |
|
265 | typeconv[unquote_ends] ]), | |
277 | 'add_flip': ' '.join([ typeconv[qwflat], |
|
266 | 'add_flip': ' '.join([ typeconv[qwflat], | |
278 | typeconv[qw_lol], |
|
267 | typeconv[qw_lol], | |
279 | typeconv[list_strings] ]) |
|
268 | typeconv[list_strings] ]) | |
280 | } |
|
269 | } | |
281 |
|
270 | |||
282 | # Now actually process the command line |
|
271 | # Now actually process the command line | |
283 | getopt = DPyGetOpt.DPyGetOpt() |
|
272 | getopt = DPyGetOpt.DPyGetOpt() | |
284 | getopt.setIgnoreCase(0) |
|
273 | getopt.setIgnoreCase(0) | |
285 |
|
274 | |||
286 | getopt.parseConfiguration(opts_names) |
|
275 | getopt.parseConfiguration(opts_names) | |
287 |
|
276 | |||
288 | try: |
|
277 | try: | |
289 | getopt.processArguments(argv) |
|
278 | getopt.processArguments(argv) | |
290 | except: |
|
279 | except: | |
291 | print cmd_line_usage |
|
280 | print cmd_line_usage | |
292 | warn('\nError in Arguments: ' + `sys.exc_value`) |
|
281 | warn('\nError in Arguments: ' + `sys.exc_value`) | |
293 | sys.exit() |
|
282 | sys.exit() | |
294 |
|
283 | |||
295 | # convert the options dict to a struct for much lighter syntax later |
|
284 | # convert the options dict to a struct for much lighter syntax later | |
296 | opts = Struct(getopt.optionValues) |
|
285 | opts = Struct(getopt.optionValues) | |
297 | args = getopt.freeValues |
|
286 | args = getopt.freeValues | |
298 |
|
287 | |||
299 | # this is the struct (which has default values at this point) with which |
|
288 | # this is the struct (which has default values at this point) with which | |
300 | # we make all decisions: |
|
289 | # we make all decisions: | |
301 | opts_all.update(opts) |
|
290 | opts_all.update(opts) | |
302 |
|
291 | |||
303 | # Options that force an immediate exit |
|
292 | # Options that force an immediate exit | |
304 | if opts_all.help: |
|
293 | if opts_all.help: | |
305 | page(cmd_line_usage) |
|
294 | page(cmd_line_usage) | |
306 | sys.exit() |
|
295 | sys.exit() | |
307 |
|
296 | |||
308 | if opts_all.Version: |
|
297 | if opts_all.Version: | |
309 | print __version__ |
|
298 | print __version__ | |
310 | sys.exit() |
|
299 | sys.exit() | |
311 |
|
300 | |||
312 | if opts_all.magic_docstrings: |
|
301 | if opts_all.magic_docstrings: | |
313 | IP.magic_magic('-latex') |
|
302 | IP.magic_magic('-latex') | |
314 | sys.exit() |
|
303 | sys.exit() | |
315 |
|
304 | |||
316 | # Create user config directory if it doesn't exist. This must be done |
|
305 | # Create user config directory if it doesn't exist. This must be done | |
317 | # *after* getting the cmd line options. |
|
306 | # *after* getting the cmd line options. | |
318 | if not os.path.isdir(opts_all.ipythondir): |
|
307 | if not os.path.isdir(opts_all.ipythondir): | |
319 | IP.user_setup(opts_all.ipythondir,rc_suffix,'install') |
|
308 | IP.user_setup(opts_all.ipythondir,rc_suffix,'install') | |
320 |
|
309 | |||
321 | # upgrade user config files while preserving a copy of the originals |
|
310 | # upgrade user config files while preserving a copy of the originals | |
322 | if opts_all.upgrade: |
|
311 | if opts_all.upgrade: | |
323 | IP.user_setup(opts_all.ipythondir,rc_suffix,'upgrade') |
|
312 | IP.user_setup(opts_all.ipythondir,rc_suffix,'upgrade') | |
324 |
|
313 | |||
325 | # check mutually exclusive options in the *original* command line |
|
314 | # check mutually exclusive options in the *original* command line | |
326 | mutex_opts(opts,[qw('log logfile'),qw('rcfile profile'), |
|
315 | mutex_opts(opts,[qw('log logfile'),qw('rcfile profile'), | |
327 | qw('classic profile'),qw('classic rcfile')]) |
|
316 | qw('classic profile'),qw('classic rcfile')]) | |
328 |
|
317 | |||
329 | # default logfilename used when -log is called. |
|
318 | # default logfilename used when -log is called. | |
330 | IP.LOGDEF = 'ipython.log' |
|
319 | IP.LOGDEF = 'ipython.log' | |
331 |
|
320 | |||
332 | #--------------------------------------------------------------------------- |
|
321 | #--------------------------------------------------------------------------- | |
333 | # Log replay |
|
322 | # Log replay | |
334 |
|
323 | |||
335 | # if -logplay, we need to 'become' the other session. That basically means |
|
324 | # if -logplay, we need to 'become' the other session. That basically means | |
336 | # replacing the current command line environment with that of the old |
|
325 | # replacing the current command line environment with that of the old | |
337 | # session and moving on. |
|
326 | # session and moving on. | |
338 |
|
327 | |||
339 | # this is needed so that later we know we're in session reload mode, as |
|
328 | # this is needed so that later we know we're in session reload mode, as | |
340 | # opts_all will get overwritten: |
|
329 | # opts_all will get overwritten: | |
341 | load_logplay = 0 |
|
330 | load_logplay = 0 | |
342 |
|
331 | |||
343 | if opts_all.logplay: |
|
332 | if opts_all.logplay: | |
344 | load_logplay = opts_all.logplay |
|
333 | load_logplay = opts_all.logplay | |
345 | opts_debug_save = opts_all.debug |
|
334 | opts_debug_save = opts_all.debug | |
346 | try: |
|
335 | try: | |
347 | logplay = open(opts_all.logplay) |
|
336 | logplay = open(opts_all.logplay) | |
348 | except IOError: |
|
337 | except IOError: | |
349 | if opts_all.debug: IP.InteractiveTB() |
|
338 | if opts_all.debug: IP.InteractiveTB() | |
350 | warn('Could not open logplay file '+`opts_all.logplay`) |
|
339 | warn('Could not open logplay file '+`opts_all.logplay`) | |
351 | # restore state as if nothing had happened and move on, but make |
|
340 | # restore state as if nothing had happened and move on, but make | |
352 | # sure that later we don't try to actually load the session file |
|
341 | # sure that later we don't try to actually load the session file | |
353 | logplay = None |
|
342 | logplay = None | |
354 | load_logplay = 0 |
|
343 | load_logplay = 0 | |
355 | del opts_all.logplay |
|
344 | del opts_all.logplay | |
356 | else: |
|
345 | else: | |
357 | try: |
|
346 | try: | |
358 | logplay.readline() |
|
347 | logplay.readline() | |
359 | logplay.readline(); |
|
348 | logplay.readline(); | |
360 | # this reloads that session's command line |
|
349 | # this reloads that session's command line | |
361 | cmd = logplay.readline()[6:] |
|
350 | cmd = logplay.readline()[6:] | |
362 | exec cmd |
|
351 | exec cmd | |
363 | # restore the true debug flag given so that the process of |
|
352 | # restore the true debug flag given so that the process of | |
364 | # session loading itself can be monitored. |
|
353 | # session loading itself can be monitored. | |
365 | opts.debug = opts_debug_save |
|
354 | opts.debug = opts_debug_save | |
366 | # save the logplay flag so later we don't overwrite the log |
|
355 | # save the logplay flag so later we don't overwrite the log | |
367 | opts.logplay = load_logplay |
|
356 | opts.logplay = load_logplay | |
368 | # now we must update our own structure with defaults |
|
357 | # now we must update our own structure with defaults | |
369 | opts_all.update(opts) |
|
358 | opts_all.update(opts) | |
370 | # now load args |
|
359 | # now load args | |
371 | cmd = logplay.readline()[6:] |
|
360 | cmd = logplay.readline()[6:] | |
372 | exec cmd |
|
361 | exec cmd | |
373 | logplay.close() |
|
362 | logplay.close() | |
374 | except: |
|
363 | except: | |
375 | logplay.close() |
|
364 | logplay.close() | |
376 | if opts_all.debug: IP.InteractiveTB() |
|
365 | if opts_all.debug: IP.InteractiveTB() | |
377 | warn("Logplay file lacking full configuration information.\n" |
|
366 | warn("Logplay file lacking full configuration information.\n" | |
378 | "I'll try to read it, but some things may not work.") |
|
367 | "I'll try to read it, but some things may not work.") | |
379 |
|
368 | |||
380 | #------------------------------------------------------------------------- |
|
369 | #------------------------------------------------------------------------- | |
381 | # set up output traps: catch all output from files, being run, modules |
|
370 | # set up output traps: catch all output from files, being run, modules | |
382 | # loaded, etc. Then give it to the user in a clean form at the end. |
|
371 | # loaded, etc. Then give it to the user in a clean form at the end. | |
383 |
|
372 | |||
384 | msg_out = 'Output messages. ' |
|
373 | msg_out = 'Output messages. ' | |
385 | msg_err = 'Error messages. ' |
|
374 | msg_err = 'Error messages. ' | |
386 | msg_sep = '\n' |
|
375 | msg_sep = '\n' | |
387 | msg = Struct(config = OutputTrap('Configuration Loader',msg_out, |
|
376 | msg = Struct(config = OutputTrap('Configuration Loader',msg_out, | |
388 | msg_err,msg_sep,debug, |
|
377 | msg_err,msg_sep,debug, | |
389 | quiet_out=1), |
|
378 | quiet_out=1), | |
390 | user_exec = OutputTrap('User File Execution',msg_out, |
|
379 | user_exec = OutputTrap('User File Execution',msg_out, | |
391 | msg_err,msg_sep,debug), |
|
380 | msg_err,msg_sep,debug), | |
392 | logplay = OutputTrap('Log Loader',msg_out, |
|
381 | logplay = OutputTrap('Log Loader',msg_out, | |
393 | msg_err,msg_sep,debug), |
|
382 | msg_err,msg_sep,debug), | |
394 | summary = '' |
|
383 | summary = '' | |
395 | ) |
|
384 | ) | |
396 |
|
385 | |||
397 | #------------------------------------------------------------------------- |
|
386 | #------------------------------------------------------------------------- | |
398 | # Process user ipythonrc-type configuration files |
|
387 | # Process user ipythonrc-type configuration files | |
399 |
|
388 | |||
400 | # turn on output trapping and log to msg.config |
|
389 | # turn on output trapping and log to msg.config | |
401 | # remember that with debug on, trapping is actually disabled |
|
390 | # remember that with debug on, trapping is actually disabled | |
402 | msg.config.trap_all() |
|
391 | msg.config.trap_all() | |
403 |
|
392 | |||
404 | # look for rcfile in current or default directory |
|
393 | # look for rcfile in current or default directory | |
405 | try: |
|
394 | try: | |
406 | opts_all.rcfile = filefind(opts_all.rcfile,opts_all.ipythondir) |
|
395 | opts_all.rcfile = filefind(opts_all.rcfile,opts_all.ipythondir) | |
407 | except IOError: |
|
396 | except IOError: | |
408 | if opts_all.debug: IP.InteractiveTB() |
|
397 | if opts_all.debug: IP.InteractiveTB() | |
409 | warn('Configuration file %s not found. Ignoring request.' |
|
398 | warn('Configuration file %s not found. Ignoring request.' | |
410 | % (opts_all.rcfile) ) |
|
399 | % (opts_all.rcfile) ) | |
411 |
|
400 | |||
412 | # 'profiles' are a shorthand notation for config filenames |
|
401 | # 'profiles' are a shorthand notation for config filenames | |
413 | if opts_all.profile: |
|
402 | if opts_all.profile: | |
414 | try: |
|
403 | try: | |
415 | opts_all.rcfile = filefind('ipythonrc-' + opts_all.profile |
|
404 | opts_all.rcfile = filefind('ipythonrc-' + opts_all.profile | |
416 | + rc_suffix, |
|
405 | + rc_suffix, | |
417 | opts_all.ipythondir) |
|
406 | opts_all.ipythondir) | |
418 | except IOError: |
|
407 | except IOError: | |
419 | if opts_all.debug: IP.InteractiveTB() |
|
408 | if opts_all.debug: IP.InteractiveTB() | |
420 | opts.profile = '' # remove profile from options if invalid |
|
409 | opts.profile = '' # remove profile from options if invalid | |
421 | warn('Profile configuration file %s not found. Ignoring request.' |
|
410 | warn('Profile configuration file %s not found. Ignoring request.' | |
422 | % (opts_all.profile) ) |
|
411 | % (opts_all.profile) ) | |
423 |
|
412 | |||
424 | # load the config file |
|
413 | # load the config file | |
425 | rcfiledata = None |
|
414 | rcfiledata = None | |
426 | if opts_all.quick: |
|
415 | if opts_all.quick: | |
427 | print 'Launching IPython in quick mode. No config file read.' |
|
416 | print 'Launching IPython in quick mode. No config file read.' | |
428 | elif opts_all.classic: |
|
417 | elif opts_all.classic: | |
429 | print 'Launching IPython in classic mode. No config file read.' |
|
418 | print 'Launching IPython in classic mode. No config file read.' | |
430 | elif opts_all.rcfile: |
|
419 | elif opts_all.rcfile: | |
431 | try: |
|
420 | try: | |
432 | cfg_loader = ConfigLoader(conflict) |
|
421 | cfg_loader = ConfigLoader(conflict) | |
433 | rcfiledata = cfg_loader.load(opts_all.rcfile,typeconv, |
|
422 | rcfiledata = cfg_loader.load(opts_all.rcfile,typeconv, | |
434 | 'include',opts_all.ipythondir, |
|
423 | 'include',opts_all.ipythondir, | |
435 | purge = 1, |
|
424 | purge = 1, | |
436 | unique = conflict['preserve']) |
|
425 | unique = conflict['preserve']) | |
437 | except: |
|
426 | except: | |
438 | IP.InteractiveTB() |
|
427 | IP.InteractiveTB() | |
439 | warn('Problems loading configuration file '+ |
|
428 | warn('Problems loading configuration file '+ | |
440 | `opts_all.rcfile`+ |
|
429 | `opts_all.rcfile`+ | |
441 | '\nStarting with default -bare bones- configuration.') |
|
430 | '\nStarting with default -bare bones- configuration.') | |
442 | else: |
|
431 | else: | |
443 | warn('No valid configuration file found in either currrent directory\n'+ |
|
432 | warn('No valid configuration file found in either currrent directory\n'+ | |
444 | 'or in the IPython config. directory: '+`opts_all.ipythondir`+ |
|
433 | 'or in the IPython config. directory: '+`opts_all.ipythondir`+ | |
445 | '\nProceeding with internal defaults.') |
|
434 | '\nProceeding with internal defaults.') | |
446 |
|
435 | |||
447 | #------------------------------------------------------------------------ |
|
436 | #------------------------------------------------------------------------ | |
448 | # Set exception handlers in mode requested by user. |
|
437 | # Set exception handlers in mode requested by user. | |
449 | otrap = OutputTrap(trap_out=1) # trap messages from magic_xmode |
|
438 | otrap = OutputTrap(trap_out=1) # trap messages from magic_xmode | |
450 | IP.magic_xmode(opts_all.xmode) |
|
439 | IP.magic_xmode(opts_all.xmode) | |
451 | otrap.release_out() |
|
440 | otrap.release_out() | |
452 |
|
441 | |||
453 | #------------------------------------------------------------------------ |
|
442 | #------------------------------------------------------------------------ | |
454 | # Execute user config |
|
443 | # Execute user config | |
455 |
|
444 | |||
456 | # first, create a valid config structure with the right precedence order: |
|
445 | # first, create a valid config structure with the right precedence order: | |
457 | # defaults < rcfile < command line |
|
446 | # defaults < rcfile < command line | |
458 | IP.rc = rc_def.copy() |
|
447 | IP.rc = rc_def.copy() | |
459 | IP.rc.update(opts_def) |
|
448 | IP.rc.update(opts_def) | |
460 | if rcfiledata: |
|
449 | if rcfiledata: | |
461 | # now we can update |
|
450 | # now we can update | |
462 | IP.rc.update(rcfiledata) |
|
451 | IP.rc.update(rcfiledata) | |
463 | IP.rc.update(opts) |
|
452 | IP.rc.update(opts) | |
464 | IP.rc.update(rc_override) |
|
453 | IP.rc.update(rc_override) | |
465 |
|
454 | |||
466 | # Store the original cmd line for reference: |
|
455 | # Store the original cmd line for reference: | |
467 | IP.rc.opts = opts |
|
456 | IP.rc.opts = opts | |
468 | IP.rc.args = args |
|
457 | IP.rc.args = args | |
469 |
|
458 | |||
470 | # create a *runtime* Struct like rc for holding parameters which may be |
|
459 | # create a *runtime* Struct like rc for holding parameters which may be | |
471 | # created and/or modified by runtime user extensions. |
|
460 | # created and/or modified by runtime user extensions. | |
472 | IP.runtime_rc = Struct() |
|
461 | IP.runtime_rc = Struct() | |
473 |
|
462 | |||
474 | # from this point on, all config should be handled through IP.rc, |
|
463 | # from this point on, all config should be handled through IP.rc, | |
475 | # opts* shouldn't be used anymore. |
|
464 | # opts* shouldn't be used anymore. | |
476 |
|
465 | |||
477 | # add personal .ipython dir to sys.path so that users can put things in |
|
466 | # add personal .ipython dir to sys.path so that users can put things in | |
478 | # there for customization |
|
467 | # there for customization | |
479 | sys.path.append(IP.rc.ipythondir) |
|
468 | sys.path.append(IP.rc.ipythondir) | |
480 | sys.path.insert(0, '') # add . to sys.path. Fix from Prabhu Ramachandran |
|
469 | sys.path.insert(0, '') # add . to sys.path. Fix from Prabhu Ramachandran | |
481 |
|
470 | |||
482 | # update IP.rc with some special things that need manual |
|
471 | # update IP.rc with some special things that need manual | |
483 | # tweaks. Basically options which affect other options. I guess this |
|
472 | # tweaks. Basically options which affect other options. I guess this | |
484 | # should just be written so that options are fully orthogonal and we |
|
473 | # should just be written so that options are fully orthogonal and we | |
485 | # wouldn't worry about this stuff! |
|
474 | # wouldn't worry about this stuff! | |
486 |
|
475 | |||
487 | if IP.rc.classic: |
|
476 | if IP.rc.classic: | |
488 | IP.rc.quick = 1 |
|
477 | IP.rc.quick = 1 | |
489 | IP.rc.cache_size = 0 |
|
478 | IP.rc.cache_size = 0 | |
490 | IP.rc.pprint = 0 |
|
479 | IP.rc.pprint = 0 | |
491 | IP.rc.prompt_in1 = '>>> ' |
|
480 | IP.rc.prompt_in1 = '>>> ' | |
492 | IP.rc.prompt_in2 = '... ' |
|
481 | IP.rc.prompt_in2 = '... ' | |
493 | IP.rc.prompt_out = '' |
|
482 | IP.rc.prompt_out = '' | |
494 | IP.rc.separate_in = IP.rc.separate_out = IP.rc.separate_out2 = '0' |
|
483 | IP.rc.separate_in = IP.rc.separate_out = IP.rc.separate_out2 = '0' | |
495 | IP.rc.colors = 'NoColor' |
|
484 | IP.rc.colors = 'NoColor' | |
496 | IP.rc.xmode = 'Plain' |
|
485 | IP.rc.xmode = 'Plain' | |
497 |
|
486 | |||
498 | # configure readline |
|
487 | # configure readline | |
499 | # Define the history file for saving commands in between sessions |
|
488 | # Define the history file for saving commands in between sessions | |
500 | if IP.rc.profile: |
|
489 | if IP.rc.profile: | |
501 | histfname = 'history-%s' % IP.rc.profile |
|
490 | histfname = 'history-%s' % IP.rc.profile | |
502 | else: |
|
491 | else: | |
503 | histfname = 'history' |
|
492 | histfname = 'history' | |
504 | IP.histfile = os.path.join(opts_all.ipythondir,histfname) |
|
493 | IP.histfile = os.path.join(opts_all.ipythondir,histfname) | |
505 | # Load readline proper |
|
494 | # Load readline proper | |
506 | if IP.rc.readline: |
|
495 | if IP.rc.readline: | |
507 | IP.init_readline() |
|
496 | IP.init_readline() | |
508 |
|
497 | |||
509 | # update exception handlers with rc file status |
|
498 | # update exception handlers with rc file status | |
510 | otrap.trap_out() # I don't want these messages ever. |
|
499 | otrap.trap_out() # I don't want these messages ever. | |
511 | IP.magic_xmode(IP.rc.xmode) |
|
500 | IP.magic_xmode(IP.rc.xmode) | |
512 | otrap.release_out() |
|
501 | otrap.release_out() | |
513 |
|
502 | |||
514 | # activate logging if requested and not reloading a log |
|
503 | # activate logging if requested and not reloading a log | |
515 | if IP.rc.logplay: |
|
504 | if IP.rc.logplay: | |
516 | IP.magic_logstart(IP.rc.logplay + ' append') |
|
505 | IP.magic_logstart(IP.rc.logplay + ' append') | |
517 | elif IP.rc.logfile: |
|
506 | elif IP.rc.logfile: | |
518 | IP.magic_logstart(IP.rc.logfile) |
|
507 | IP.magic_logstart(IP.rc.logfile) | |
519 | elif IP.rc.log: |
|
508 | elif IP.rc.log: | |
520 | IP.magic_logstart() |
|
509 | IP.magic_logstart() | |
521 |
|
510 | |||
522 | # find user editor so that it we don't have to look it up constantly |
|
511 | # find user editor so that it we don't have to look it up constantly | |
523 | if IP.rc.editor.strip()=='0': |
|
512 | if IP.rc.editor.strip()=='0': | |
524 | try: |
|
513 | try: | |
525 | ed = os.environ['EDITOR'] |
|
514 | ed = os.environ['EDITOR'] | |
526 | except KeyError: |
|
515 | except KeyError: | |
527 | if os.name == 'posix': |
|
516 | if os.name == 'posix': | |
528 | ed = 'vi' # the only one guaranteed to be there! |
|
517 | ed = 'vi' # the only one guaranteed to be there! | |
529 | else: |
|
518 | else: | |
530 | ed = 'notepad' # same in Windows! |
|
519 | ed = 'notepad' # same in Windows! | |
531 | IP.rc.editor = ed |
|
520 | IP.rc.editor = ed | |
532 |
|
521 | |||
533 | # Recursive reload |
|
522 | # Recursive reload | |
534 | try: |
|
523 | try: | |
535 | from IPython import deep_reload |
|
524 | from IPython import deep_reload | |
536 | if IP.rc.deep_reload: |
|
525 | if IP.rc.deep_reload: | |
537 | __builtin__.reload = deep_reload.reload |
|
526 | __builtin__.reload = deep_reload.reload | |
538 | else: |
|
527 | else: | |
539 | __builtin__.dreload = deep_reload.reload |
|
528 | __builtin__.dreload = deep_reload.reload | |
540 | del deep_reload |
|
529 | del deep_reload | |
541 | except ImportError: |
|
530 | except ImportError: | |
542 | pass |
|
531 | pass | |
543 |
|
532 | |||
544 | # Save the current state of our namespace so that the interactive shell |
|
533 | # Save the current state of our namespace so that the interactive shell | |
545 | # can later know which variables have been created by us from config files |
|
534 | # can later know which variables have been created by us from config files | |
546 | # and loading. This way, loading a file (in any way) is treated just like |
|
535 | # and loading. This way, loading a file (in any way) is treated just like | |
547 | # defining things on the command line, and %who works as expected. |
|
536 | # defining things on the command line, and %who works as expected. | |
548 |
|
537 | |||
549 | # DON'T do anything that affects the namespace beyond this point! |
|
538 | # DON'T do anything that affects the namespace beyond this point! | |
550 | IP.internal_ns = __main__.__dict__.copy() |
|
539 | IP.internal_ns = __main__.__dict__.copy() | |
551 |
|
540 | |||
552 | #IP.internal_ns.update(locals()) # so our stuff doesn't show up in %who |
|
541 | #IP.internal_ns.update(locals()) # so our stuff doesn't show up in %who | |
553 |
|
542 | |||
554 | # Now run through the different sections of the users's config |
|
543 | # Now run through the different sections of the users's config | |
555 | if IP.rc.debug: |
|
544 | if IP.rc.debug: | |
556 | print 'Trying to execute the following configuration structure:' |
|
545 | print 'Trying to execute the following configuration structure:' | |
557 | print '(Things listed first are deeper in the inclusion tree and get' |
|
546 | print '(Things listed first are deeper in the inclusion tree and get' | |
558 | print 'loaded first).\n' |
|
547 | print 'loaded first).\n' | |
559 | pprint(IP.rc.__dict__) |
|
548 | pprint(IP.rc.__dict__) | |
560 |
|
549 | |||
561 | for mod in IP.rc.import_mod: |
|
550 | for mod in IP.rc.import_mod: | |
562 | try: |
|
551 | try: | |
563 | exec 'import '+mod in IP.user_ns |
|
552 | exec 'import '+mod in IP.user_ns | |
564 | except : |
|
553 | except : | |
565 | IP.InteractiveTB() |
|
554 | IP.InteractiveTB() | |
566 | import_fail_info(mod) |
|
555 | import_fail_info(mod) | |
567 |
|
556 | |||
568 | for mod_fn in IP.rc.import_some: |
|
557 | for mod_fn in IP.rc.import_some: | |
569 | if mod_fn == []: break |
|
558 | if mod_fn == []: break | |
570 | mod,fn = mod_fn[0],','.join(mod_fn[1:]) |
|
559 | mod,fn = mod_fn[0],','.join(mod_fn[1:]) | |
571 | try: |
|
560 | try: | |
572 | exec 'from '+mod+' import '+fn in IP.user_ns |
|
561 | exec 'from '+mod+' import '+fn in IP.user_ns | |
573 | except : |
|
562 | except : | |
574 | IP.InteractiveTB() |
|
563 | IP.InteractiveTB() | |
575 | import_fail_info(mod,fn) |
|
564 | import_fail_info(mod,fn) | |
576 |
|
565 | |||
577 | for mod in IP.rc.import_all: |
|
566 | for mod in IP.rc.import_all: | |
578 | try: |
|
567 | try: | |
579 | exec 'from '+mod+' import *' in IP.user_ns |
|
568 | exec 'from '+mod+' import *' in IP.user_ns | |
580 | except : |
|
569 | except : | |
581 | IP.InteractiveTB() |
|
570 | IP.InteractiveTB() | |
582 | import_fail_info(mod) |
|
571 | import_fail_info(mod) | |
583 |
|
572 | |||
584 | for code in IP.rc.execute: |
|
573 | for code in IP.rc.execute: | |
585 | try: |
|
574 | try: | |
586 | exec code in IP.user_ns |
|
575 | exec code in IP.user_ns | |
587 | except: |
|
576 | except: | |
588 | IP.InteractiveTB() |
|
577 | IP.InteractiveTB() | |
589 | warn('Failure executing code: ' + `code`) |
|
578 | warn('Failure executing code: ' + `code`) | |
590 |
|
579 | |||
591 | # Execute the files the user wants in ipythonrc |
|
580 | # Execute the files the user wants in ipythonrc | |
592 | for file in IP.rc.execfile: |
|
581 | for file in IP.rc.execfile: | |
593 | try: |
|
582 | try: | |
594 | file = filefind(file,sys.path+[IPython_dir]) |
|
583 | file = filefind(file,sys.path+[IPython_dir]) | |
595 | except IOError: |
|
584 | except IOError: | |
596 | warn(itpl('File $file not found. Skipping it.')) |
|
585 | warn(itpl('File $file not found. Skipping it.')) | |
597 | else: |
|
586 | else: | |
598 | IP.safe_execfile(os.path.expanduser(file),IP.user_ns) |
|
587 | IP.safe_execfile(os.path.expanduser(file),IP.user_ns) | |
599 |
|
588 | |||
600 | # Load user aliases |
|
589 | # Load user aliases | |
601 | for alias in IP.rc.alias: |
|
590 | for alias in IP.rc.alias: | |
602 | IP.magic_alias(alias) |
|
591 | IP.magic_alias(alias) | |
603 |
|
592 | |||
604 | # release stdout and stderr and save config log into a global summary |
|
593 | # release stdout and stderr and save config log into a global summary | |
605 | msg.config.release_all() |
|
594 | msg.config.release_all() | |
606 | if IP.rc.messages: |
|
595 | if IP.rc.messages: | |
607 | msg.summary += msg.config.summary_all() |
|
596 | msg.summary += msg.config.summary_all() | |
608 |
|
597 | |||
609 | #------------------------------------------------------------------------ |
|
598 | #------------------------------------------------------------------------ | |
610 | # Setup interactive session |
|
599 | # Setup interactive session | |
611 |
|
600 | |||
612 | # Now we should be fully configured. We can then execute files or load |
|
601 | # Now we should be fully configured. We can then execute files or load | |
613 | # things only needed for interactive use. Then we'll open the shell. |
|
602 | # things only needed for interactive use. Then we'll open the shell. | |
614 |
|
603 | |||
615 | # Take a snapshot of the user namespace before opening the shell. That way |
|
604 | # Take a snapshot of the user namespace before opening the shell. That way | |
616 | # we'll be able to identify which things were interactively defined and |
|
605 | # we'll be able to identify which things were interactively defined and | |
617 | # which were defined through config files. |
|
606 | # which were defined through config files. | |
618 | IP.user_config_ns = IP.user_ns.copy() |
|
607 | IP.user_config_ns = IP.user_ns.copy() | |
619 |
|
608 | |||
620 | # Force reading a file as if it were a session log. Slower but safer. |
|
609 | # Force reading a file as if it were a session log. Slower but safer. | |
621 | if load_logplay: |
|
610 | if load_logplay: | |
622 | print 'Replaying log...' |
|
611 | print 'Replaying log...' | |
623 | try: |
|
612 | try: | |
624 | if IP.rc.debug: |
|
613 | if IP.rc.debug: | |
625 | logplay_quiet = 0 |
|
614 | logplay_quiet = 0 | |
626 | else: |
|
615 | else: | |
627 | logplay_quiet = 1 |
|
616 | logplay_quiet = 1 | |
628 |
|
617 | |||
629 | msg.logplay.trap_all() |
|
618 | msg.logplay.trap_all() | |
630 | IP.safe_execfile(load_logplay,IP.user_ns, |
|
619 | IP.safe_execfile(load_logplay,IP.user_ns, | |
631 | islog = 1, quiet = logplay_quiet) |
|
620 | islog = 1, quiet = logplay_quiet) | |
632 | msg.logplay.release_all() |
|
621 | msg.logplay.release_all() | |
633 | if IP.rc.messages: |
|
622 | if IP.rc.messages: | |
634 | msg.summary += msg.logplay.summary_all() |
|
623 | msg.summary += msg.logplay.summary_all() | |
635 | except: |
|
624 | except: | |
636 | warn('Problems replaying logfile %s.' % load_logplay) |
|
625 | warn('Problems replaying logfile %s.' % load_logplay) | |
637 | IP.InteractiveTB() |
|
626 | IP.InteractiveTB() | |
638 |
|
627 | |||
639 | # Load remaining files in command line |
|
628 | # Load remaining files in command line | |
640 | msg.user_exec.trap_all() |
|
629 | msg.user_exec.trap_all() | |
641 |
|
630 | |||
642 | # Do NOT execute files named in the command line as scripts to be loaded |
|
631 | # Do NOT execute files named in the command line as scripts to be loaded | |
643 | # by embedded instances. Doing so has the potential for an infinite |
|
632 | # by embedded instances. Doing so has the potential for an infinite | |
644 | # recursion if there are exceptions thrown in the process. |
|
633 | # recursion if there are exceptions thrown in the process. | |
645 |
|
634 | |||
646 | # XXX FIXME: the execution of user files should be moved out to after |
|
635 | # XXX FIXME: the execution of user files should be moved out to after | |
647 | # ipython is fully initialized, just as if they were run via %run at the |
|
636 | # ipython is fully initialized, just as if they were run via %run at the | |
648 | # ipython prompt. This would also give them the benefit of ipython's |
|
637 | # ipython prompt. This would also give them the benefit of ipython's | |
649 | # nice tracebacks. |
|
638 | # nice tracebacks. | |
650 |
|
639 | |||
651 | if not embedded and IP.rc.args: |
|
640 | if not embedded and IP.rc.args: | |
652 | name_save = IP.user_ns['__name__'] |
|
641 | name_save = IP.user_ns['__name__'] | |
653 | IP.user_ns['__name__'] = '__main__' |
|
642 | IP.user_ns['__name__'] = '__main__' | |
654 | try: |
|
643 | try: | |
655 | # Set our own excepthook in case the user code tries to call it |
|
644 | # Set our own excepthook in case the user code tries to call it | |
656 | # directly. This prevents triggering the IPython crash handler. |
|
645 | # directly. This prevents triggering the IPython crash handler. | |
657 | old_excepthook,sys.excepthook = sys.excepthook, IP.excepthook |
|
646 | old_excepthook,sys.excepthook = sys.excepthook, IP.excepthook | |
658 | for run in args: |
|
647 | for run in args: | |
659 | IP.safe_execfile(run,IP.user_ns) |
|
648 | IP.safe_execfile(run,IP.user_ns) | |
660 | finally: |
|
649 | finally: | |
661 | # Reset our crash handler in place |
|
650 | # Reset our crash handler in place | |
662 | sys.excepthook = old_excepthook |
|
651 | sys.excepthook = old_excepthook | |
663 |
|
652 | |||
664 | IP.user_ns['__name__'] = name_save |
|
653 | IP.user_ns['__name__'] = name_save | |
665 |
|
654 | |||
666 | msg.user_exec.release_all() |
|
655 | msg.user_exec.release_all() | |
667 | if IP.rc.messages: |
|
656 | if IP.rc.messages: | |
668 | msg.summary += msg.user_exec.summary_all() |
|
657 | msg.summary += msg.user_exec.summary_all() | |
669 |
|
658 | |||
670 | # since we can't specify a null string on the cmd line, 0 is the equivalent: |
|
659 | # since we can't specify a null string on the cmd line, 0 is the equivalent: | |
671 | if IP.rc.nosep: |
|
660 | if IP.rc.nosep: | |
672 | IP.rc.separate_in = IP.rc.separate_out = IP.rc.separate_out2 = '0' |
|
661 | IP.rc.separate_in = IP.rc.separate_out = IP.rc.separate_out2 = '0' | |
673 | if IP.rc.separate_in == '0': IP.rc.separate_in = '' |
|
662 | if IP.rc.separate_in == '0': IP.rc.separate_in = '' | |
674 | if IP.rc.separate_out == '0': IP.rc.separate_out = '' |
|
663 | if IP.rc.separate_out == '0': IP.rc.separate_out = '' | |
675 | if IP.rc.separate_out2 == '0': IP.rc.separate_out2 = '' |
|
664 | if IP.rc.separate_out2 == '0': IP.rc.separate_out2 = '' | |
676 | IP.rc.separate_in = IP.rc.separate_in.replace('\\n','\n') |
|
665 | IP.rc.separate_in = IP.rc.separate_in.replace('\\n','\n') | |
677 | IP.rc.separate_out = IP.rc.separate_out.replace('\\n','\n') |
|
666 | IP.rc.separate_out = IP.rc.separate_out.replace('\\n','\n') | |
678 | IP.rc.separate_out2 = IP.rc.separate_out2.replace('\\n','\n') |
|
667 | IP.rc.separate_out2 = IP.rc.separate_out2.replace('\\n','\n') | |
679 |
|
668 | |||
680 | # Determine how many lines at the bottom of the screen are needed for |
|
669 | # Determine how many lines at the bottom of the screen are needed for | |
681 | # showing prompts, so we can know wheter long strings are to be printed or |
|
670 | # showing prompts, so we can know wheter long strings are to be printed or | |
682 | # paged: |
|
671 | # paged: | |
683 | num_lines_bot = IP.rc.separate_in.count('\n')+1 |
|
672 | num_lines_bot = IP.rc.separate_in.count('\n')+1 | |
684 | IP.rc.screen_length = IP.rc.screen_length - num_lines_bot |
|
673 | IP.rc.screen_length = IP.rc.screen_length - num_lines_bot | |
685 | # Initialize cache, set in/out prompts and printing system |
|
674 | # Initialize cache, set in/out prompts and printing system | |
686 | IP.outputcache = CachedOutput(IP.rc.cache_size, |
|
675 | IP.outputcache = CachedOutput(IP.rc.cache_size, | |
687 | IP.rc.pprint, |
|
676 | IP.rc.pprint, | |
688 | input_sep = IP.rc.separate_in, |
|
677 | input_sep = IP.rc.separate_in, | |
689 | output_sep = IP.rc.separate_out, |
|
678 | output_sep = IP.rc.separate_out, | |
690 | output_sep2 = IP.rc.separate_out2, |
|
679 | output_sep2 = IP.rc.separate_out2, | |
691 | ps1 = IP.rc.prompt_in1, |
|
680 | ps1 = IP.rc.prompt_in1, | |
692 | ps2 = IP.rc.prompt_in2, |
|
681 | ps2 = IP.rc.prompt_in2, | |
693 | ps_out = IP.rc.prompt_out, |
|
682 | ps_out = IP.rc.prompt_out, | |
694 | user_ns = IP.user_ns, |
|
683 | user_ns = IP.user_ns, | |
695 | input_hist = IP.input_hist, |
|
684 | input_hist = IP.input_hist, | |
696 | pad_left = IP.rc.prompts_pad_left) |
|
685 | pad_left = IP.rc.prompts_pad_left) | |
697 |
|
686 | |||
698 | # Set user colors (don't do it in the constructor above so that it doesn't |
|
687 | # Set user colors (don't do it in the constructor above so that it doesn't | |
699 | # crash if colors option is invalid) |
|
688 | # crash if colors option is invalid) | |
700 | IP.magic_colors(IP.rc.colors) |
|
689 | IP.magic_colors(IP.rc.colors) | |
701 |
|
690 | |||
702 | # user may have over-ridden the default print hook: |
|
691 | # user may have over-ridden the default print hook: | |
703 | try: |
|
692 | try: | |
704 | IP.outputcache.__class__.display = IP.hooks.display |
|
693 | IP.outputcache.__class__.display = IP.hooks.display | |
705 | except AttributeError: |
|
694 | except AttributeError: | |
706 | pass |
|
695 | pass | |
707 |
|
696 | |||
708 | # Set calling of pdb on exceptions |
|
697 | # Set calling of pdb on exceptions | |
709 | IP.InteractiveTB.call_pdb = IP.rc.pdb |
|
698 | IP.InteractiveTB.call_pdb = IP.rc.pdb | |
710 |
|
699 | |||
711 | # I don't like assigning globally to sys, because it means when embedding |
|
700 | # I don't like assigning globally to sys, because it means when embedding | |
712 | # instances, each embedded instance overrides the previous choice. But |
|
701 | # instances, each embedded instance overrides the previous choice. But | |
713 | # sys.displayhook seems to be called internally by exec, so I don't see a |
|
702 | # sys.displayhook seems to be called internally by exec, so I don't see a | |
714 | # way around it. |
|
703 | # way around it. | |
715 | sys.displayhook = IP.outputcache |
|
704 | sys.displayhook = IP.outputcache | |
716 |
|
705 | |||
717 | # we need to know globally if we're caching i/o or not |
|
706 | # we need to know globally if we're caching i/o or not | |
718 | IP.do_full_cache = IP.outputcache.do_full_cache |
|
707 | IP.do_full_cache = IP.outputcache.do_full_cache | |
719 |
|
708 | |||
720 | # configure startup banner |
|
709 | # configure startup banner | |
721 | if IP.rc.c: # regular python doesn't print the banner with -c |
|
710 | if IP.rc.c: # regular python doesn't print the banner with -c | |
722 | IP.rc.banner = 0 |
|
711 | IP.rc.banner = 0 | |
723 | if IP.rc.banner: |
|
712 | if IP.rc.banner: | |
724 | IP.BANNER = '\n'.join(IP.BANNER_PARTS) |
|
713 | IP.BANNER = '\n'.join(IP.BANNER_PARTS) | |
725 | else: |
|
714 | else: | |
726 | IP.BANNER = '' |
|
715 | IP.BANNER = '' | |
727 |
|
716 | |||
728 | if IP.rc.profile: IP.BANNER += '\nIPython profile: '+IP.rc.profile+'\n' |
|
717 | if IP.rc.profile: IP.BANNER += '\nIPython profile: '+IP.rc.profile+'\n' | |
729 |
|
718 | |||
730 | # add message log (possibly empty) |
|
719 | # add message log (possibly empty) | |
731 | IP.BANNER += msg.summary |
|
720 | IP.BANNER += msg.summary | |
732 |
|
721 | |||
733 | IP.post_config_initialization() |
|
722 | IP.post_config_initialization() | |
734 |
|
723 | |||
735 | return IP |
|
724 | return IP | |
736 | #************************ end of file <ipmaker.py> ************************** |
|
725 | #************************ end of file <ipmaker.py> ************************** |
@@ -1,4258 +1,4294 b'' | |||||
|
1 | 2005-07-17 Fernando Perez <fperez@colorado.edu> | |||
|
2 | ||||
|
3 | * IPython/Prompts.py (str_safe): Make unicode-safe. Also remove | |||
|
4 | some old hacks and clean up a bit other routines; code should be | |||
|
5 | simpler and a bit faster. | |||
|
6 | ||||
|
7 | * IPython/iplib.py (interact): removed some last-resort attempts | |||
|
8 | to survive broken stdout/stderr. That code was only making it | |||
|
9 | harder to abstract out the i/o (necessary for gui integration), | |||
|
10 | and the crashes it could prevent were extremely rare in practice | |||
|
11 | (besides being fully user-induced in a pretty violent manner). | |||
|
12 | ||||
|
13 | * IPython/genutils.py (IOStream.__init__): Simplify the i/o stuff. | |||
|
14 | Nothing major yet, but the code is simpler to read; this should | |||
|
15 | make it easier to do more serious modifications in the future. | |||
|
16 | ||||
|
17 | * IPython/Extensions/InterpreterExec.py: Fix auto-quoting in pysh, | |||
|
18 | which broke in .15 (thanks to a report by Ville). | |||
|
19 | ||||
|
20 | * IPython/Itpl.py (Itpl.__init__): add unicode support (it may not | |||
|
21 | be quite correct, I know next to nothing about unicode). This | |||
|
22 | will allow unicode strings to be used in prompts, amongst other | |||
|
23 | cases. It also will prevent ipython from crashing when unicode | |||
|
24 | shows up unexpectedly in many places. If ascii encoding fails, we | |||
|
25 | assume utf_8. Currently the encoding is not a user-visible | |||
|
26 | setting, though it could be made so if there is demand for it. | |||
|
27 | ||||
|
28 | * IPython/ipmaker.py (make_IPython): remove old 2.1-specific hack. | |||
|
29 | ||||
|
30 | * IPython/Struct.py (Struct.merge): switch keys() to iterator. | |||
|
31 | ||||
|
32 | * IPython/background_jobs.py: moved 2.2 compatibility to genutils. | |||
|
33 | ||||
|
34 | * IPython/genutils.py: Add 2.2 compatibility here, so all other | |||
|
35 | code can work transparently for 2.2/2.3. | |||
|
36 | ||||
1 | 2005-07-16 Fernando Perez <fperez@colorado.edu> |
|
37 | 2005-07-16 Fernando Perez <fperez@colorado.edu> | |
2 |
|
38 | |||
3 | * IPython/ultraTB.py (ExceptionColors): Make a global variable |
|
39 | * IPython/ultraTB.py (ExceptionColors): Make a global variable | |
4 | out of the color scheme table used for coloring exception |
|
40 | out of the color scheme table used for coloring exception | |
5 | tracebacks. This allows user code to add new schemes at runtime. |
|
41 | tracebacks. This allows user code to add new schemes at runtime. | |
6 | This is a minimally modified version of the patch at |
|
42 | This is a minimally modified version of the patch at | |
7 | http://www.scipy.net/roundup/ipython/issue35, many thanks to pabw |
|
43 | http://www.scipy.net/roundup/ipython/issue35, many thanks to pabw | |
8 | for the contribution. |
|
44 | for the contribution. | |
9 |
|
45 | |||
10 | * IPython/FlexCompleter.py (Completer.attr_matches): Add a |
|
46 | * IPython/FlexCompleter.py (Completer.attr_matches): Add a | |
11 | slightly modified version of the patch in |
|
47 | slightly modified version of the patch in | |
12 | http://www.scipy.net/roundup/ipython/issue34, which also allows me |
|
48 | http://www.scipy.net/roundup/ipython/issue34, which also allows me | |
13 | to remove the previous try/except solution (which was costlier). |
|
49 | to remove the previous try/except solution (which was costlier). | |
14 | Thanks to glehmann for the fix. |
|
50 | Thanks to Gaetan Lehmann <gaetan.lehmann AT jouy.inra.fr> for the fix. | |
15 |
|
51 | |||
16 | 2005-06-08 Fernando Perez <fperez@colorado.edu> |
|
52 | 2005-06-08 Fernando Perez <fperez@colorado.edu> | |
17 |
|
53 | |||
18 | * IPython/iplib.py (write/write_err): Add methods to abstract all |
|
54 | * IPython/iplib.py (write/write_err): Add methods to abstract all | |
19 | I/O a bit more. |
|
55 | I/O a bit more. | |
20 |
|
56 | |||
21 | * IPython/Shell.py (IPShellGTK.mainloop): Fix GTK deprecation |
|
57 | * IPython/Shell.py (IPShellGTK.mainloop): Fix GTK deprecation | |
22 | warning, reported by Aric Hagberg, fix by JD Hunter. |
|
58 | warning, reported by Aric Hagberg, fix by JD Hunter. | |
23 |
|
59 | |||
24 | 2005-06-02 *** Released version 0.6.15 |
|
60 | 2005-06-02 *** Released version 0.6.15 | |
25 |
|
61 | |||
26 | 2005-06-01 Fernando Perez <fperez@colorado.edu> |
|
62 | 2005-06-01 Fernando Perez <fperez@colorado.edu> | |
27 |
|
63 | |||
28 | * IPython/iplib.py (MagicCompleter.file_matches): Fix |
|
64 | * IPython/iplib.py (MagicCompleter.file_matches): Fix | |
29 | tab-completion of filenames within open-quoted strings. Note that |
|
65 | tab-completion of filenames within open-quoted strings. Note that | |
30 | this requires that in ~/.ipython/ipythonrc, users change the |
|
66 | this requires that in ~/.ipython/ipythonrc, users change the | |
31 | readline delimiters configuration to read: |
|
67 | readline delimiters configuration to read: | |
32 |
|
68 | |||
33 | readline_remove_delims -/~ |
|
69 | readline_remove_delims -/~ | |
34 |
|
70 | |||
35 |
|
71 | |||
36 | 2005-05-31 *** Released version 0.6.14 |
|
72 | 2005-05-31 *** Released version 0.6.14 | |
37 |
|
73 | |||
38 | 2005-05-29 Fernando Perez <fperez@colorado.edu> |
|
74 | 2005-05-29 Fernando Perez <fperez@colorado.edu> | |
39 |
|
75 | |||
40 | * IPython/ultraTB.py (VerboseTB.text): Fix crash for tracebacks |
|
76 | * IPython/ultraTB.py (VerboseTB.text): Fix crash for tracebacks | |
41 | with files not on the filesystem. Reported by Eliyahu Sandler |
|
77 | with files not on the filesystem. Reported by Eliyahu Sandler | |
42 | <eli@gondolin.net> |
|
78 | <eli@gondolin.net> | |
43 |
|
79 | |||
44 | 2005-05-22 Fernando Perez <fperez@colorado.edu> |
|
80 | 2005-05-22 Fernando Perez <fperez@colorado.edu> | |
45 |
|
81 | |||
46 | * IPython/iplib.py: Fix a few crashes in the --upgrade option. |
|
82 | * IPython/iplib.py: Fix a few crashes in the --upgrade option. | |
47 | After an initial report by LUK ShunTim <shuntim.luk@polyu.edu.hk>. |
|
83 | After an initial report by LUK ShunTim <shuntim.luk@polyu.edu.hk>. | |
48 |
|
84 | |||
49 | 2005-05-19 Fernando Perez <fperez@colorado.edu> |
|
85 | 2005-05-19 Fernando Perez <fperez@colorado.edu> | |
50 |
|
86 | |||
51 | * IPython/iplib.py (safe_execfile): close a file which could be |
|
87 | * IPython/iplib.py (safe_execfile): close a file which could be | |
52 | left open (causing problems in win32, which locks open files). |
|
88 | left open (causing problems in win32, which locks open files). | |
53 | Thanks to a bug report by D Brown <dbrown2@yahoo.com>. |
|
89 | Thanks to a bug report by D Brown <dbrown2@yahoo.com>. | |
54 |
|
90 | |||
55 | 2005-05-18 Fernando Perez <fperez@colorado.edu> |
|
91 | 2005-05-18 Fernando Perez <fperez@colorado.edu> | |
56 |
|
92 | |||
57 | * IPython/Shell.py (MatplotlibShellBase.mplot_exec): pass all |
|
93 | * IPython/Shell.py (MatplotlibShellBase.mplot_exec): pass all | |
58 | keyword arguments correctly to safe_execfile(). |
|
94 | keyword arguments correctly to safe_execfile(). | |
59 |
|
95 | |||
60 | 2005-05-13 Fernando Perez <fperez@colorado.edu> |
|
96 | 2005-05-13 Fernando Perez <fperez@colorado.edu> | |
61 |
|
97 | |||
62 | * ipython.1: Added info about Qt to manpage, and threads warning |
|
98 | * ipython.1: Added info about Qt to manpage, and threads warning | |
63 | to usage page (invoked with --help). |
|
99 | to usage page (invoked with --help). | |
64 |
|
100 | |||
65 | * IPython/iplib.py (MagicCompleter.python_func_kw_matches): Added |
|
101 | * IPython/iplib.py (MagicCompleter.python_func_kw_matches): Added | |
66 | new matcher (it goes at the end of the priority list) to do |
|
102 | new matcher (it goes at the end of the priority list) to do | |
67 | tab-completion on named function arguments. Submitted by George |
|
103 | tab-completion on named function arguments. Submitted by George | |
68 | Sakkis <gsakkis-AT-eden.rutgers.edu>. See the thread at |
|
104 | Sakkis <gsakkis-AT-eden.rutgers.edu>. See the thread at | |
69 | http://www.scipy.net/pipermail/ipython-dev/2005-April/000436.html |
|
105 | http://www.scipy.net/pipermail/ipython-dev/2005-April/000436.html | |
70 | for more details. |
|
106 | for more details. | |
71 |
|
107 | |||
72 | * IPython/Magic.py (magic_run): Added new -e flag to ignore |
|
108 | * IPython/Magic.py (magic_run): Added new -e flag to ignore | |
73 | SystemExit exceptions in the script being run. Thanks to a report |
|
109 | SystemExit exceptions in the script being run. Thanks to a report | |
74 | by danny shevitz <danny_shevitz-AT-yahoo.com>, about this |
|
110 | by danny shevitz <danny_shevitz-AT-yahoo.com>, about this | |
75 | producing very annoying behavior when running unit tests. |
|
111 | producing very annoying behavior when running unit tests. | |
76 |
|
112 | |||
77 | 2005-05-12 Fernando Perez <fperez@colorado.edu> |
|
113 | 2005-05-12 Fernando Perez <fperez@colorado.edu> | |
78 |
|
114 | |||
79 | * IPython/iplib.py (handle_auto): fixed auto-quoting and parens, |
|
115 | * IPython/iplib.py (handle_auto): fixed auto-quoting and parens, | |
80 | which I'd broken (again) due to a changed regexp. In the process, |
|
116 | which I'd broken (again) due to a changed regexp. In the process, | |
81 | added ';' as an escape to auto-quote the whole line without |
|
117 | added ';' as an escape to auto-quote the whole line without | |
82 | splitting its arguments. Thanks to a report by Jerry McRae |
|
118 | splitting its arguments. Thanks to a report by Jerry McRae | |
83 | <qrs0xyc02-AT-sneakemail.com>. |
|
119 | <qrs0xyc02-AT-sneakemail.com>. | |
84 |
|
120 | |||
85 | * IPython/ultraTB.py (VerboseTB.text): protect against rare but |
|
121 | * IPython/ultraTB.py (VerboseTB.text): protect against rare but | |
86 | possible crashes caused by a TokenError. Reported by Ed Schofield |
|
122 | possible crashes caused by a TokenError. Reported by Ed Schofield | |
87 | <schofield-AT-ftw.at>. |
|
123 | <schofield-AT-ftw.at>. | |
88 |
|
124 | |||
89 | 2005-05-06 Fernando Perez <fperez@colorado.edu> |
|
125 | 2005-05-06 Fernando Perez <fperez@colorado.edu> | |
90 |
|
126 | |||
91 | * IPython/Shell.py (hijack_wx): Fix to work with WX v.2.6. |
|
127 | * IPython/Shell.py (hijack_wx): Fix to work with WX v.2.6. | |
92 |
|
128 | |||
93 | 2005-04-29 Fernando Perez <fperez@colorado.edu> |
|
129 | 2005-04-29 Fernando Perez <fperez@colorado.edu> | |
94 |
|
130 | |||
95 | * IPython/Shell.py (IPShellQt): Thanks to Denis Rivière |
|
131 | * IPython/Shell.py (IPShellQt): Thanks to Denis Rivière | |
96 | <nudz-AT-free.fr>, Yann Cointepas <yann-AT-sapetnioc.org> and Benjamin |
|
132 | <nudz-AT-free.fr>, Yann Cointepas <yann-AT-sapetnioc.org> and Benjamin | |
97 | Thyreau <Benji2-AT-decideur.info>, we now have a -qthread option |
|
133 | Thyreau <Benji2-AT-decideur.info>, we now have a -qthread option | |
98 | which provides support for Qt interactive usage (similar to the |
|
134 | which provides support for Qt interactive usage (similar to the | |
99 | existing one for WX and GTK). This had been often requested. |
|
135 | existing one for WX and GTK). This had been often requested. | |
100 |
|
136 | |||
101 | 2005-04-14 *** Released version 0.6.13 |
|
137 | 2005-04-14 *** Released version 0.6.13 | |
102 |
|
138 | |||
103 | 2005-04-08 Fernando Perez <fperez@colorado.edu> |
|
139 | 2005-04-08 Fernando Perez <fperez@colorado.edu> | |
104 |
|
140 | |||
105 | * IPython/Magic.py (Magic._ofind): remove docstring evaluation |
|
141 | * IPython/Magic.py (Magic._ofind): remove docstring evaluation | |
106 | from _ofind, which gets called on almost every input line. Now, |
|
142 | from _ofind, which gets called on almost every input line. Now, | |
107 | we only try to get docstrings if they are actually going to be |
|
143 | we only try to get docstrings if they are actually going to be | |
108 | used (the overhead of fetching unnecessary docstrings can be |
|
144 | used (the overhead of fetching unnecessary docstrings can be | |
109 | noticeable for certain objects, such as Pyro proxies). |
|
145 | noticeable for certain objects, such as Pyro proxies). | |
110 |
|
146 | |||
111 | * IPython/iplib.py (MagicCompleter.python_matches): Change the API |
|
147 | * IPython/iplib.py (MagicCompleter.python_matches): Change the API | |
112 | for completers. For some reason I had been passing them the state |
|
148 | for completers. For some reason I had been passing them the state | |
113 | variable, which completers never actually need, and was in |
|
149 | variable, which completers never actually need, and was in | |
114 | conflict with the rlcompleter API. Custom completers ONLY need to |
|
150 | conflict with the rlcompleter API. Custom completers ONLY need to | |
115 | take the text parameter. |
|
151 | take the text parameter. | |
116 |
|
152 | |||
117 | * IPython/Extensions/InterpreterExec.py: Fix regexp so that magics |
|
153 | * IPython/Extensions/InterpreterExec.py: Fix regexp so that magics | |
118 | work correctly in pysh. I've also moved all the logic which used |
|
154 | work correctly in pysh. I've also moved all the logic which used | |
119 | to be in pysh.py here, which will prevent problems with future |
|
155 | to be in pysh.py here, which will prevent problems with future | |
120 | upgrades. However, this time I must warn users to update their |
|
156 | upgrades. However, this time I must warn users to update their | |
121 | pysh profile to include the line |
|
157 | pysh profile to include the line | |
122 |
|
158 | |||
123 | import_all IPython.Extensions.InterpreterExec |
|
159 | import_all IPython.Extensions.InterpreterExec | |
124 |
|
160 | |||
125 | because otherwise things won't work for them. They MUST also |
|
161 | because otherwise things won't work for them. They MUST also | |
126 | delete pysh.py and the line |
|
162 | delete pysh.py and the line | |
127 |
|
163 | |||
128 | execfile pysh.py |
|
164 | execfile pysh.py | |
129 |
|
165 | |||
130 | from their ipythonrc-pysh. |
|
166 | from their ipythonrc-pysh. | |
131 |
|
167 | |||
132 | * IPython/FlexCompleter.py (Completer.attr_matches): Make more |
|
168 | * IPython/FlexCompleter.py (Completer.attr_matches): Make more | |
133 | robust in the face of objects whose dir() returns non-strings |
|
169 | robust in the face of objects whose dir() returns non-strings | |
134 | (which it shouldn't, but some broken libs like ITK do). Thanks to |
|
170 | (which it shouldn't, but some broken libs like ITK do). Thanks to | |
135 | a patch by John Hunter (implemented differently, though). Also |
|
171 | a patch by John Hunter (implemented differently, though). Also | |
136 | minor improvements by using .extend instead of + on lists. |
|
172 | minor improvements by using .extend instead of + on lists. | |
137 |
|
173 | |||
138 | * pysh.py: |
|
174 | * pysh.py: | |
139 |
|
175 | |||
140 | 2005-04-06 Fernando Perez <fperez@colorado.edu> |
|
176 | 2005-04-06 Fernando Perez <fperez@colorado.edu> | |
141 |
|
177 | |||
142 | * IPython/ipmaker.py (make_IPython): Make multi_line_specials on |
|
178 | * IPython/ipmaker.py (make_IPython): Make multi_line_specials on | |
143 | by default, so that all users benefit from it. Those who don't |
|
179 | by default, so that all users benefit from it. Those who don't | |
144 | want it can still turn it off. |
|
180 | want it can still turn it off. | |
145 |
|
181 | |||
146 | * IPython/UserConfig/ipythonrc: Add multi_line_specials to the |
|
182 | * IPython/UserConfig/ipythonrc: Add multi_line_specials to the | |
147 | config file, I'd forgotten about this, so users were getting it |
|
183 | config file, I'd forgotten about this, so users were getting it | |
148 | off by default. |
|
184 | off by default. | |
149 |
|
185 | |||
150 | * IPython/iplib.py (ipmagic): big overhaul of the magic system for |
|
186 | * IPython/iplib.py (ipmagic): big overhaul of the magic system for | |
151 | consistency. Now magics can be called in multiline statements, |
|
187 | consistency. Now magics can be called in multiline statements, | |
152 | and python variables can be expanded in magic calls via $var. |
|
188 | and python variables can be expanded in magic calls via $var. | |
153 | This makes the magic system behave just like aliases or !system |
|
189 | This makes the magic system behave just like aliases or !system | |
154 | calls. |
|
190 | calls. | |
155 |
|
191 | |||
156 | 2005-03-28 Fernando Perez <fperez@colorado.edu> |
|
192 | 2005-03-28 Fernando Perez <fperez@colorado.edu> | |
157 |
|
193 | |||
158 | * IPython/iplib.py (handle_auto): cleanup to use %s instead of |
|
194 | * IPython/iplib.py (handle_auto): cleanup to use %s instead of | |
159 | expensive string additions for building command. Add support for |
|
195 | expensive string additions for building command. Add support for | |
160 | trailing ';' when autocall is used. |
|
196 | trailing ';' when autocall is used. | |
161 |
|
197 | |||
162 | 2005-03-26 Fernando Perez <fperez@colorado.edu> |
|
198 | 2005-03-26 Fernando Perez <fperez@colorado.edu> | |
163 |
|
199 | |||
164 | * ipython.el: Fix http://www.scipy.net/roundup/ipython/issue31. |
|
200 | * ipython.el: Fix http://www.scipy.net/roundup/ipython/issue31. | |
165 | Bugfix by A. Schmolck, the ipython.el maintainer. Also make |
|
201 | Bugfix by A. Schmolck, the ipython.el maintainer. Also make | |
166 | ipython.el robust against prompts with any number of spaces |
|
202 | ipython.el robust against prompts with any number of spaces | |
167 | (including 0) after the ':' character. |
|
203 | (including 0) after the ':' character. | |
168 |
|
204 | |||
169 | * IPython/Prompts.py (Prompt2.set_p_str): Fix spurious space in |
|
205 | * IPython/Prompts.py (Prompt2.set_p_str): Fix spurious space in | |
170 | continuation prompt, which misled users to think the line was |
|
206 | continuation prompt, which misled users to think the line was | |
171 | already indented. Closes debian Bug#300847, reported to me by |
|
207 | already indented. Closes debian Bug#300847, reported to me by | |
172 | Norbert Tretkowski <tretkowski-AT-inittab.de>. |
|
208 | Norbert Tretkowski <tretkowski-AT-inittab.de>. | |
173 |
|
209 | |||
174 | 2005-03-23 Fernando Perez <fperez@colorado.edu> |
|
210 | 2005-03-23 Fernando Perez <fperez@colorado.edu> | |
175 |
|
211 | |||
176 | * IPython/Prompts.py (Prompt1.__str__): Make sure that prompts are |
|
212 | * IPython/Prompts.py (Prompt1.__str__): Make sure that prompts are | |
177 | properly aligned if they have embedded newlines. |
|
213 | properly aligned if they have embedded newlines. | |
178 |
|
214 | |||
179 | * IPython/iplib.py (runlines): Add a public method to expose |
|
215 | * IPython/iplib.py (runlines): Add a public method to expose | |
180 | IPython's code execution machinery, so that users can run strings |
|
216 | IPython's code execution machinery, so that users can run strings | |
181 | as if they had been typed at the prompt interactively. |
|
217 | as if they had been typed at the prompt interactively. | |
182 | (InteractiveShell.__init__): Added getoutput() to the __IPYTHON__ |
|
218 | (InteractiveShell.__init__): Added getoutput() to the __IPYTHON__ | |
183 | methods which can call the system shell, but with python variable |
|
219 | methods which can call the system shell, but with python variable | |
184 | expansion. The three such methods are: __IPYTHON__.system, |
|
220 | expansion. The three such methods are: __IPYTHON__.system, | |
185 | .getoutput and .getoutputerror. These need to be documented in a |
|
221 | .getoutput and .getoutputerror. These need to be documented in a | |
186 | 'public API' section (to be written) of the manual. |
|
222 | 'public API' section (to be written) of the manual. | |
187 |
|
223 | |||
188 | 2005-03-20 Fernando Perez <fperez@colorado.edu> |
|
224 | 2005-03-20 Fernando Perez <fperez@colorado.edu> | |
189 |
|
225 | |||
190 | * IPython/iplib.py (InteractiveShell.set_custom_exc): new system |
|
226 | * IPython/iplib.py (InteractiveShell.set_custom_exc): new system | |
191 | for custom exception handling. This is quite powerful, and it |
|
227 | for custom exception handling. This is quite powerful, and it | |
192 | allows for user-installable exception handlers which can trap |
|
228 | allows for user-installable exception handlers which can trap | |
193 | custom exceptions at runtime and treat them separately from |
|
229 | custom exceptions at runtime and treat them separately from | |
194 | IPython's default mechanisms. At the request of FrΓ©dΓ©ric |
|
230 | IPython's default mechanisms. At the request of FrΓ©dΓ©ric | |
195 | Mantegazza <mantegazza-AT-ill.fr>. |
|
231 | Mantegazza <mantegazza-AT-ill.fr>. | |
196 | (InteractiveShell.set_custom_completer): public API function to |
|
232 | (InteractiveShell.set_custom_completer): public API function to | |
197 | add new completers at runtime. |
|
233 | add new completers at runtime. | |
198 |
|
234 | |||
199 | 2005-03-19 Fernando Perez <fperez@colorado.edu> |
|
235 | 2005-03-19 Fernando Perez <fperez@colorado.edu> | |
200 |
|
236 | |||
201 | * IPython/OInspect.py (getdoc): Add a call to obj.getdoc(), to |
|
237 | * IPython/OInspect.py (getdoc): Add a call to obj.getdoc(), to | |
202 | allow objects which provide their docstrings via non-standard |
|
238 | allow objects which provide their docstrings via non-standard | |
203 | mechanisms (like Pyro proxies) to still be inspected by ipython's |
|
239 | mechanisms (like Pyro proxies) to still be inspected by ipython's | |
204 | ? system. |
|
240 | ? system. | |
205 |
|
241 | |||
206 | * IPython/iplib.py (InteractiveShell.__init__): back off the _o/_e |
|
242 | * IPython/iplib.py (InteractiveShell.__init__): back off the _o/_e | |
207 | automatic capture system. I tried quite hard to make it work |
|
243 | automatic capture system. I tried quite hard to make it work | |
208 | reliably, and simply failed. I tried many combinations with the |
|
244 | reliably, and simply failed. I tried many combinations with the | |
209 | subprocess module, but eventually nothing worked in all needed |
|
245 | subprocess module, but eventually nothing worked in all needed | |
210 | cases (not blocking stdin for the child, duplicating stdout |
|
246 | cases (not blocking stdin for the child, duplicating stdout | |
211 | without blocking, etc). The new %sc/%sx still do capture to these |
|
247 | without blocking, etc). The new %sc/%sx still do capture to these | |
212 | magical list/string objects which make shell use much more |
|
248 | magical list/string objects which make shell use much more | |
213 | conveninent, so not all is lost. |
|
249 | conveninent, so not all is lost. | |
214 |
|
250 | |||
215 | XXX - FIX MANUAL for the change above! |
|
251 | XXX - FIX MANUAL for the change above! | |
216 |
|
252 | |||
217 | (runsource): I copied code.py's runsource() into ipython to modify |
|
253 | (runsource): I copied code.py's runsource() into ipython to modify | |
218 | it a bit. Now the code object and source to be executed are |
|
254 | it a bit. Now the code object and source to be executed are | |
219 | stored in ipython. This makes this info accessible to third-party |
|
255 | stored in ipython. This makes this info accessible to third-party | |
220 | tools, like custom exception handlers. After a request by FrΓ©dΓ©ric |
|
256 | tools, like custom exception handlers. After a request by FrΓ©dΓ©ric | |
221 | Mantegazza <mantegazza-AT-ill.fr>. |
|
257 | Mantegazza <mantegazza-AT-ill.fr>. | |
222 |
|
258 | |||
223 | * IPython/UserConfig/ipythonrc: Add up/down arrow keys to |
|
259 | * IPython/UserConfig/ipythonrc: Add up/down arrow keys to | |
224 | history-search via readline (like C-p/C-n). I'd wanted this for a |
|
260 | history-search via readline (like C-p/C-n). I'd wanted this for a | |
225 | long time, but only recently found out how to do it. For users |
|
261 | long time, but only recently found out how to do it. For users | |
226 | who already have their ipythonrc files made and want this, just |
|
262 | who already have their ipythonrc files made and want this, just | |
227 | add: |
|
263 | add: | |
228 |
|
264 | |||
229 | readline_parse_and_bind "\e[A": history-search-backward |
|
265 | readline_parse_and_bind "\e[A": history-search-backward | |
230 | readline_parse_and_bind "\e[B": history-search-forward |
|
266 | readline_parse_and_bind "\e[B": history-search-forward | |
231 |
|
267 | |||
232 | 2005-03-18 Fernando Perez <fperez@colorado.edu> |
|
268 | 2005-03-18 Fernando Perez <fperez@colorado.edu> | |
233 |
|
269 | |||
234 | * IPython/Magic.py (magic_sc): %sc and %sx now use the fancy |
|
270 | * IPython/Magic.py (magic_sc): %sc and %sx now use the fancy | |
235 | LSString and SList classes which allow transparent conversions |
|
271 | LSString and SList classes which allow transparent conversions | |
236 | between list mode and whitespace-separated string. |
|
272 | between list mode and whitespace-separated string. | |
237 | (magic_r): Fix recursion problem in %r. |
|
273 | (magic_r): Fix recursion problem in %r. | |
238 |
|
274 | |||
239 | * IPython/genutils.py (LSString): New class to be used for |
|
275 | * IPython/genutils.py (LSString): New class to be used for | |
240 | automatic storage of the results of all alias/system calls in _o |
|
276 | automatic storage of the results of all alias/system calls in _o | |
241 | and _e (stdout/err). These provide a .l/.list attribute which |
|
277 | and _e (stdout/err). These provide a .l/.list attribute which | |
242 | does automatic splitting on newlines. This means that for most |
|
278 | does automatic splitting on newlines. This means that for most | |
243 | uses, you'll never need to do capturing of output with %sc/%sx |
|
279 | uses, you'll never need to do capturing of output with %sc/%sx | |
244 | anymore, since ipython keeps this always done for you. Note that |
|
280 | anymore, since ipython keeps this always done for you. Note that | |
245 | only the LAST results are stored, the _o/e variables are |
|
281 | only the LAST results are stored, the _o/e variables are | |
246 | overwritten on each call. If you need to save their contents |
|
282 | overwritten on each call. If you need to save their contents | |
247 | further, simply bind them to any other name. |
|
283 | further, simply bind them to any other name. | |
248 |
|
284 | |||
249 | 2005-03-17 Fernando Perez <fperez@colorado.edu> |
|
285 | 2005-03-17 Fernando Perez <fperez@colorado.edu> | |
250 |
|
286 | |||
251 | * IPython/Prompts.py (BasePrompt.cwd_filt): a few more fixes for |
|
287 | * IPython/Prompts.py (BasePrompt.cwd_filt): a few more fixes for | |
252 | prompt namespace handling. |
|
288 | prompt namespace handling. | |
253 |
|
289 | |||
254 | 2005-03-16 Fernando Perez <fperez@colorado.edu> |
|
290 | 2005-03-16 Fernando Perez <fperez@colorado.edu> | |
255 |
|
291 | |||
256 | * IPython/Prompts.py (CachedOutput.__init__): Fix default and |
|
292 | * IPython/Prompts.py (CachedOutput.__init__): Fix default and | |
257 | classic prompts to be '>>> ' (final space was missing, and it |
|
293 | classic prompts to be '>>> ' (final space was missing, and it | |
258 | trips the emacs python mode). |
|
294 | trips the emacs python mode). | |
259 | (BasePrompt.__str__): Added safe support for dynamic prompt |
|
295 | (BasePrompt.__str__): Added safe support for dynamic prompt | |
260 | strings. Now you can set your prompt string to be '$x', and the |
|
296 | strings. Now you can set your prompt string to be '$x', and the | |
261 | value of x will be printed from your interactive namespace. The |
|
297 | value of x will be printed from your interactive namespace. The | |
262 | interpolation syntax includes the full Itpl support, so |
|
298 | interpolation syntax includes the full Itpl support, so | |
263 | ${foo()+x+bar()} is a valid prompt string now, and the function |
|
299 | ${foo()+x+bar()} is a valid prompt string now, and the function | |
264 | calls will be made at runtime. |
|
300 | calls will be made at runtime. | |
265 |
|
301 | |||
266 | 2005-03-15 Fernando Perez <fperez@colorado.edu> |
|
302 | 2005-03-15 Fernando Perez <fperez@colorado.edu> | |
267 |
|
303 | |||
268 | * IPython/Magic.py (magic_history): renamed %hist to %history, to |
|
304 | * IPython/Magic.py (magic_history): renamed %hist to %history, to | |
269 | avoid name clashes in pylab. %hist still works, it just forwards |
|
305 | avoid name clashes in pylab. %hist still works, it just forwards | |
270 | the call to %history. |
|
306 | the call to %history. | |
271 |
|
307 | |||
272 | 2005-03-02 *** Released version 0.6.12 |
|
308 | 2005-03-02 *** Released version 0.6.12 | |
273 |
|
309 | |||
274 | 2005-03-02 Fernando Perez <fperez@colorado.edu> |
|
310 | 2005-03-02 Fernando Perez <fperez@colorado.edu> | |
275 |
|
311 | |||
276 | * IPython/iplib.py (handle_magic): log magic calls properly as |
|
312 | * IPython/iplib.py (handle_magic): log magic calls properly as | |
277 | ipmagic() function calls. |
|
313 | ipmagic() function calls. | |
278 |
|
314 | |||
279 | * IPython/Magic.py (magic_time): Improved %time to support |
|
315 | * IPython/Magic.py (magic_time): Improved %time to support | |
280 | statements and provide wall-clock as well as CPU time. |
|
316 | statements and provide wall-clock as well as CPU time. | |
281 |
|
317 | |||
282 | 2005-02-27 Fernando Perez <fperez@colorado.edu> |
|
318 | 2005-02-27 Fernando Perez <fperez@colorado.edu> | |
283 |
|
319 | |||
284 | * IPython/hooks.py: New hooks module, to expose user-modifiable |
|
320 | * IPython/hooks.py: New hooks module, to expose user-modifiable | |
285 | IPython functionality in a clean manner. For now only the editor |
|
321 | IPython functionality in a clean manner. For now only the editor | |
286 | hook is actually written, and other thigns which I intend to turn |
|
322 | hook is actually written, and other thigns which I intend to turn | |
287 | into proper hooks aren't yet there. The display and prefilter |
|
323 | into proper hooks aren't yet there. The display and prefilter | |
288 | stuff, for example, should be hooks. But at least now the |
|
324 | stuff, for example, should be hooks. But at least now the | |
289 | framework is in place, and the rest can be moved here with more |
|
325 | framework is in place, and the rest can be moved here with more | |
290 | time later. IPython had had a .hooks variable for a long time for |
|
326 | time later. IPython had had a .hooks variable for a long time for | |
291 | this purpose, but I'd never actually used it for anything. |
|
327 | this purpose, but I'd never actually used it for anything. | |
292 |
|
328 | |||
293 | 2005-02-26 Fernando Perez <fperez@colorado.edu> |
|
329 | 2005-02-26 Fernando Perez <fperez@colorado.edu> | |
294 |
|
330 | |||
295 | * IPython/ipmaker.py (make_IPython): make the default ipython |
|
331 | * IPython/ipmaker.py (make_IPython): make the default ipython | |
296 | directory be called _ipython under win32, to follow more the |
|
332 | directory be called _ipython under win32, to follow more the | |
297 | naming peculiarities of that platform (where buggy software like |
|
333 | naming peculiarities of that platform (where buggy software like | |
298 | Visual Sourcesafe breaks with .named directories). Reported by |
|
334 | Visual Sourcesafe breaks with .named directories). Reported by | |
299 | Ville Vainio. |
|
335 | Ville Vainio. | |
300 |
|
336 | |||
301 | 2005-02-23 Fernando Perez <fperez@colorado.edu> |
|
337 | 2005-02-23 Fernando Perez <fperez@colorado.edu> | |
302 |
|
338 | |||
303 | * IPython/iplib.py (InteractiveShell.__init__): removed a few |
|
339 | * IPython/iplib.py (InteractiveShell.__init__): removed a few | |
304 | auto_aliases for win32 which were causing problems. Users can |
|
340 | auto_aliases for win32 which were causing problems. Users can | |
305 | define the ones they personally like. |
|
341 | define the ones they personally like. | |
306 |
|
342 | |||
307 | 2005-02-21 Fernando Perez <fperez@colorado.edu> |
|
343 | 2005-02-21 Fernando Perez <fperez@colorado.edu> | |
308 |
|
344 | |||
309 | * IPython/Magic.py (magic_time): new magic to time execution of |
|
345 | * IPython/Magic.py (magic_time): new magic to time execution of | |
310 | expressions. After a request by Charles Moad <cmoad-AT-indiana.edu>. |
|
346 | expressions. After a request by Charles Moad <cmoad-AT-indiana.edu>. | |
311 |
|
347 | |||
312 | 2005-02-19 Fernando Perez <fperez@colorado.edu> |
|
348 | 2005-02-19 Fernando Perez <fperez@colorado.edu> | |
313 |
|
349 | |||
314 | * IPython/ConfigLoader.py (ConfigLoader.load): Allow empty strings |
|
350 | * IPython/ConfigLoader.py (ConfigLoader.load): Allow empty strings | |
315 | into keys (for prompts, for example). |
|
351 | into keys (for prompts, for example). | |
316 |
|
352 | |||
317 | * IPython/Prompts.py (BasePrompt.set_p_str): Fix to allow empty |
|
353 | * IPython/Prompts.py (BasePrompt.set_p_str): Fix to allow empty | |
318 | prompts in case users want them. This introduces a small behavior |
|
354 | prompts in case users want them. This introduces a small behavior | |
319 | change: ipython does not automatically add a space to all prompts |
|
355 | change: ipython does not automatically add a space to all prompts | |
320 | anymore. To get the old prompts with a space, users should add it |
|
356 | anymore. To get the old prompts with a space, users should add it | |
321 | manually to their ipythonrc file, so for example prompt_in1 should |
|
357 | manually to their ipythonrc file, so for example prompt_in1 should | |
322 | now read 'In [\#]: ' instead of 'In [\#]:'. |
|
358 | now read 'In [\#]: ' instead of 'In [\#]:'. | |
323 | (BasePrompt.__init__): New option prompts_pad_left (only in rc |
|
359 | (BasePrompt.__init__): New option prompts_pad_left (only in rc | |
324 | file) to control left-padding of secondary prompts. |
|
360 | file) to control left-padding of secondary prompts. | |
325 |
|
361 | |||
326 | * IPython/Magic.py (Magic.profile_missing_notice): Don't crash if |
|
362 | * IPython/Magic.py (Magic.profile_missing_notice): Don't crash if | |
327 | the profiler can't be imported. Fix for Debian, which removed |
|
363 | the profiler can't be imported. Fix for Debian, which removed | |
328 | profile.py because of License issues. I applied a slightly |
|
364 | profile.py because of License issues. I applied a slightly | |
329 | modified version of the original Debian patch at |
|
365 | modified version of the original Debian patch at | |
330 | http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=294500. |
|
366 | http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=294500. | |
331 |
|
367 | |||
332 | 2005-02-17 Fernando Perez <fperez@colorado.edu> |
|
368 | 2005-02-17 Fernando Perez <fperez@colorado.edu> | |
333 |
|
369 | |||
334 | * IPython/genutils.py (native_line_ends): Fix bug which would |
|
370 | * IPython/genutils.py (native_line_ends): Fix bug which would | |
335 | cause improper line-ends under win32 b/c I was not opening files |
|
371 | cause improper line-ends under win32 b/c I was not opening files | |
336 | in binary mode. Bug report and fix thanks to Ville. |
|
372 | in binary mode. Bug report and fix thanks to Ville. | |
337 |
|
373 | |||
338 | * IPython/iplib.py (handle_auto): Fix bug which I introduced when |
|
374 | * IPython/iplib.py (handle_auto): Fix bug which I introduced when | |
339 | trying to catch spurious foo[1] autocalls. My fix actually broke |
|
375 | trying to catch spurious foo[1] autocalls. My fix actually broke | |
340 | ',/' autoquote/call with explicit escape (bad regexp). |
|
376 | ',/' autoquote/call with explicit escape (bad regexp). | |
341 |
|
377 | |||
342 | 2005-02-15 *** Released version 0.6.11 |
|
378 | 2005-02-15 *** Released version 0.6.11 | |
343 |
|
379 | |||
344 | 2005-02-14 Fernando Perez <fperez@colorado.edu> |
|
380 | 2005-02-14 Fernando Perez <fperez@colorado.edu> | |
345 |
|
381 | |||
346 | * IPython/background_jobs.py: New background job management |
|
382 | * IPython/background_jobs.py: New background job management | |
347 | subsystem. This is implemented via a new set of classes, and |
|
383 | subsystem. This is implemented via a new set of classes, and | |
348 | IPython now provides a builtin 'jobs' object for background job |
|
384 | IPython now provides a builtin 'jobs' object for background job | |
349 | execution. A convenience %bg magic serves as a lightweight |
|
385 | execution. A convenience %bg magic serves as a lightweight | |
350 | frontend for starting the more common type of calls. This was |
|
386 | frontend for starting the more common type of calls. This was | |
351 | inspired by discussions with B. Granger and the BackgroundCommand |
|
387 | inspired by discussions with B. Granger and the BackgroundCommand | |
352 | class described in the book Python Scripting for Computational |
|
388 | class described in the book Python Scripting for Computational | |
353 | Science, by H. P. Langtangen: http://folk.uio.no/hpl/scripting |
|
389 | Science, by H. P. Langtangen: http://folk.uio.no/hpl/scripting | |
354 | (although ultimately no code from this text was used, as IPython's |
|
390 | (although ultimately no code from this text was used, as IPython's | |
355 | system is a separate implementation). |
|
391 | system is a separate implementation). | |
356 |
|
392 | |||
357 | * IPython/iplib.py (MagicCompleter.python_matches): add new option |
|
393 | * IPython/iplib.py (MagicCompleter.python_matches): add new option | |
358 | to control the completion of single/double underscore names |
|
394 | to control the completion of single/double underscore names | |
359 | separately. As documented in the example ipytonrc file, the |
|
395 | separately. As documented in the example ipytonrc file, the | |
360 | readline_omit__names variable can now be set to 2, to omit even |
|
396 | readline_omit__names variable can now be set to 2, to omit even | |
361 | single underscore names. Thanks to a patch by Brian Wong |
|
397 | single underscore names. Thanks to a patch by Brian Wong | |
362 | <BrianWong-AT-AirgoNetworks.Com>. |
|
398 | <BrianWong-AT-AirgoNetworks.Com>. | |
363 | (InteractiveShell.__init__): Fix bug which would cause foo[1] to |
|
399 | (InteractiveShell.__init__): Fix bug which would cause foo[1] to | |
364 | be autocalled as foo([1]) if foo were callable. A problem for |
|
400 | be autocalled as foo([1]) if foo were callable. A problem for | |
365 | things which are both callable and implement __getitem__. |
|
401 | things which are both callable and implement __getitem__. | |
366 | (init_readline): Fix autoindentation for win32. Thanks to a patch |
|
402 | (init_readline): Fix autoindentation for win32. Thanks to a patch | |
367 | by Vivian De Smedt <vivian-AT-vdesmedt.com>. |
|
403 | by Vivian De Smedt <vivian-AT-vdesmedt.com>. | |
368 |
|
404 | |||
369 | 2005-02-12 Fernando Perez <fperez@colorado.edu> |
|
405 | 2005-02-12 Fernando Perez <fperez@colorado.edu> | |
370 |
|
406 | |||
371 | * IPython/ipmaker.py (make_IPython): Disabled the stout traps |
|
407 | * IPython/ipmaker.py (make_IPython): Disabled the stout traps | |
372 | which I had written long ago to sort out user error messages which |
|
408 | which I had written long ago to sort out user error messages which | |
373 | may occur during startup. This seemed like a good idea initially, |
|
409 | may occur during startup. This seemed like a good idea initially, | |
374 | but it has proven a disaster in retrospect. I don't want to |
|
410 | but it has proven a disaster in retrospect. I don't want to | |
375 | change much code for now, so my fix is to set the internal 'debug' |
|
411 | change much code for now, so my fix is to set the internal 'debug' | |
376 | flag to true everywhere, whose only job was precisely to control |
|
412 | flag to true everywhere, whose only job was precisely to control | |
377 | this subsystem. This closes issue 28 (as well as avoiding all |
|
413 | this subsystem. This closes issue 28 (as well as avoiding all | |
378 | sorts of strange hangups which occur from time to time). |
|
414 | sorts of strange hangups which occur from time to time). | |
379 |
|
415 | |||
380 | 2005-02-07 Fernando Perez <fperez@colorado.edu> |
|
416 | 2005-02-07 Fernando Perez <fperez@colorado.edu> | |
381 |
|
417 | |||
382 | * IPython/Magic.py (magic_edit): Fix 'ed -p' not working when the |
|
418 | * IPython/Magic.py (magic_edit): Fix 'ed -p' not working when the | |
383 | previous call produced a syntax error. |
|
419 | previous call produced a syntax error. | |
384 |
|
420 | |||
385 | * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting |
|
421 | * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting | |
386 | classes without constructor. |
|
422 | classes without constructor. | |
387 |
|
423 | |||
388 | 2005-02-06 Fernando Perez <fperez@colorado.edu> |
|
424 | 2005-02-06 Fernando Perez <fperez@colorado.edu> | |
389 |
|
425 | |||
390 | * IPython/iplib.py (MagicCompleter.complete): Extend the list of |
|
426 | * IPython/iplib.py (MagicCompleter.complete): Extend the list of | |
391 | completions with the results of each matcher, so we return results |
|
427 | completions with the results of each matcher, so we return results | |
392 | to the user from all namespaces. This breaks with ipython |
|
428 | to the user from all namespaces. This breaks with ipython | |
393 | tradition, but I think it's a nicer behavior. Now you get all |
|
429 | tradition, but I think it's a nicer behavior. Now you get all | |
394 | possible completions listed, from all possible namespaces (python, |
|
430 | possible completions listed, from all possible namespaces (python, | |
395 | filesystem, magics...) After a request by John Hunter |
|
431 | filesystem, magics...) After a request by John Hunter | |
396 | <jdhunter-AT-nitace.bsd.uchicago.edu>. |
|
432 | <jdhunter-AT-nitace.bsd.uchicago.edu>. | |
397 |
|
433 | |||
398 | 2005-02-05 Fernando Perez <fperez@colorado.edu> |
|
434 | 2005-02-05 Fernando Perez <fperez@colorado.edu> | |
399 |
|
435 | |||
400 | * IPython/Magic.py (magic_prun): Fix bug where prun would fail if |
|
436 | * IPython/Magic.py (magic_prun): Fix bug where prun would fail if | |
401 | the call had quote characters in it (the quotes were stripped). |
|
437 | the call had quote characters in it (the quotes were stripped). | |
402 |
|
438 | |||
403 | 2005-01-31 Fernando Perez <fperez@colorado.edu> |
|
439 | 2005-01-31 Fernando Perez <fperez@colorado.edu> | |
404 |
|
440 | |||
405 | * IPython/iplib.py (InteractiveShell.__init__): reduce reliance on |
|
441 | * IPython/iplib.py (InteractiveShell.__init__): reduce reliance on | |
406 | Itpl.itpl() to make the code more robust against psyco |
|
442 | Itpl.itpl() to make the code more robust against psyco | |
407 | optimizations. |
|
443 | optimizations. | |
408 |
|
444 | |||
409 | * IPython/Itpl.py (Itpl.__str__): Use a _getframe() call instead |
|
445 | * IPython/Itpl.py (Itpl.__str__): Use a _getframe() call instead | |
410 | of causing an exception. Quicker, cleaner. |
|
446 | of causing an exception. Quicker, cleaner. | |
411 |
|
447 | |||
412 | 2005-01-28 Fernando Perez <fperez@colorado.edu> |
|
448 | 2005-01-28 Fernando Perez <fperez@colorado.edu> | |
413 |
|
449 | |||
414 | * scripts/ipython_win_post_install.py (install): hardcode |
|
450 | * scripts/ipython_win_post_install.py (install): hardcode | |
415 | sys.prefix+'python.exe' as the executable path. It turns out that |
|
451 | sys.prefix+'python.exe' as the executable path. It turns out that | |
416 | during the post-installation run, sys.executable resolves to the |
|
452 | during the post-installation run, sys.executable resolves to the | |
417 | name of the binary installer! I should report this as a distutils |
|
453 | name of the binary installer! I should report this as a distutils | |
418 | bug, I think. I updated the .10 release with this tiny fix, to |
|
454 | bug, I think. I updated the .10 release with this tiny fix, to | |
419 | avoid annoying the lists further. |
|
455 | avoid annoying the lists further. | |
420 |
|
456 | |||
421 | 2005-01-27 *** Released version 0.6.10 |
|
457 | 2005-01-27 *** Released version 0.6.10 | |
422 |
|
458 | |||
423 | 2005-01-27 Fernando Perez <fperez@colorado.edu> |
|
459 | 2005-01-27 Fernando Perez <fperez@colorado.edu> | |
424 |
|
460 | |||
425 | * IPython/numutils.py (norm): Added 'inf' as optional name for |
|
461 | * IPython/numutils.py (norm): Added 'inf' as optional name for | |
426 | L-infinity norm, included references to mathworld.com for vector |
|
462 | L-infinity norm, included references to mathworld.com for vector | |
427 | norm definitions. |
|
463 | norm definitions. | |
428 | (amin/amax): added amin/amax for array min/max. Similar to what |
|
464 | (amin/amax): added amin/amax for array min/max. Similar to what | |
429 | pylab ships with after the recent reorganization of names. |
|
465 | pylab ships with after the recent reorganization of names. | |
430 | (spike/spike_odd): removed deprecated spike/spike_odd functions. |
|
466 | (spike/spike_odd): removed deprecated spike/spike_odd functions. | |
431 |
|
467 | |||
432 | * ipython.el: committed Alex's recent fixes and improvements. |
|
468 | * ipython.el: committed Alex's recent fixes and improvements. | |
433 | Tested with python-mode from CVS, and it looks excellent. Since |
|
469 | Tested with python-mode from CVS, and it looks excellent. Since | |
434 | python-mode hasn't released anything in a while, I'm temporarily |
|
470 | python-mode hasn't released anything in a while, I'm temporarily | |
435 | putting a copy of today's CVS (v 4.70) of python-mode in: |
|
471 | putting a copy of today's CVS (v 4.70) of python-mode in: | |
436 | http://ipython.scipy.org/tmp/python-mode.el |
|
472 | http://ipython.scipy.org/tmp/python-mode.el | |
437 |
|
473 | |||
438 | * scripts/ipython_win_post_install.py (install): Win32 fix to use |
|
474 | * scripts/ipython_win_post_install.py (install): Win32 fix to use | |
439 | sys.executable for the executable name, instead of assuming it's |
|
475 | sys.executable for the executable name, instead of assuming it's | |
440 | called 'python.exe' (the post-installer would have produced broken |
|
476 | called 'python.exe' (the post-installer would have produced broken | |
441 | setups on systems with a differently named python binary). |
|
477 | setups on systems with a differently named python binary). | |
442 |
|
478 | |||
443 | * IPython/PyColorize.py (Parser.__call__): change explicit '\n' |
|
479 | * IPython/PyColorize.py (Parser.__call__): change explicit '\n' | |
444 | references to os.linesep, to make the code more |
|
480 | references to os.linesep, to make the code more | |
445 | platform-independent. This is also part of the win32 coloring |
|
481 | platform-independent. This is also part of the win32 coloring | |
446 | fixes. |
|
482 | fixes. | |
447 |
|
483 | |||
448 | * IPython/genutils.py (page_dumb): Remove attempts to chop long |
|
484 | * IPython/genutils.py (page_dumb): Remove attempts to chop long | |
449 | lines, which actually cause coloring bugs because the length of |
|
485 | lines, which actually cause coloring bugs because the length of | |
450 | the line is very difficult to correctly compute with embedded |
|
486 | the line is very difficult to correctly compute with embedded | |
451 | escapes. This was the source of all the coloring problems under |
|
487 | escapes. This was the source of all the coloring problems under | |
452 | Win32. I think that _finally_, Win32 users have a properly |
|
488 | Win32. I think that _finally_, Win32 users have a properly | |
453 | working ipython in all respects. This would never have happened |
|
489 | working ipython in all respects. This would never have happened | |
454 | if not for Gary Bishop and Viktor Ransmayr's great help and work. |
|
490 | if not for Gary Bishop and Viktor Ransmayr's great help and work. | |
455 |
|
491 | |||
456 | 2005-01-26 *** Released version 0.6.9 |
|
492 | 2005-01-26 *** Released version 0.6.9 | |
457 |
|
493 | |||
458 | 2005-01-25 Fernando Perez <fperez@colorado.edu> |
|
494 | 2005-01-25 Fernando Perez <fperez@colorado.edu> | |
459 |
|
495 | |||
460 | * setup.py: finally, we have a true Windows installer, thanks to |
|
496 | * setup.py: finally, we have a true Windows installer, thanks to | |
461 | the excellent work of Viktor Ransmayr |
|
497 | the excellent work of Viktor Ransmayr | |
462 | <viktor.ransmayr-AT-t-online.de>. The docs have been updated for |
|
498 | <viktor.ransmayr-AT-t-online.de>. The docs have been updated for | |
463 | Windows users. The setup routine is quite a bit cleaner thanks to |
|
499 | Windows users. The setup routine is quite a bit cleaner thanks to | |
464 | this, and the post-install script uses the proper functions to |
|
500 | this, and the post-install script uses the proper functions to | |
465 | allow a clean de-installation using the standard Windows Control |
|
501 | allow a clean de-installation using the standard Windows Control | |
466 | Panel. |
|
502 | Panel. | |
467 |
|
503 | |||
468 | * IPython/genutils.py (get_home_dir): changed to use the $HOME |
|
504 | * IPython/genutils.py (get_home_dir): changed to use the $HOME | |
469 | environment variable under all OSes (including win32) if |
|
505 | environment variable under all OSes (including win32) if | |
470 | available. This will give consistency to win32 users who have set |
|
506 | available. This will give consistency to win32 users who have set | |
471 | this variable for any reason. If os.environ['HOME'] fails, the |
|
507 | this variable for any reason. If os.environ['HOME'] fails, the | |
472 | previous policy of using HOMEDRIVE\HOMEPATH kicks in. |
|
508 | previous policy of using HOMEDRIVE\HOMEPATH kicks in. | |
473 |
|
509 | |||
474 | 2005-01-24 Fernando Perez <fperez@colorado.edu> |
|
510 | 2005-01-24 Fernando Perez <fperez@colorado.edu> | |
475 |
|
511 | |||
476 | * IPython/numutils.py (empty_like): add empty_like(), similar to |
|
512 | * IPython/numutils.py (empty_like): add empty_like(), similar to | |
477 | zeros_like() but taking advantage of the new empty() Numeric routine. |
|
513 | zeros_like() but taking advantage of the new empty() Numeric routine. | |
478 |
|
514 | |||
479 | 2005-01-23 *** Released version 0.6.8 |
|
515 | 2005-01-23 *** Released version 0.6.8 | |
480 |
|
516 | |||
481 | 2005-01-22 Fernando Perez <fperez@colorado.edu> |
|
517 | 2005-01-22 Fernando Perez <fperez@colorado.edu> | |
482 |
|
518 | |||
483 | * IPython/Shell.py (MatplotlibShellBase.mplot_exec): I removed the |
|
519 | * IPython/Shell.py (MatplotlibShellBase.mplot_exec): I removed the | |
484 | automatic show() calls. After discussing things with JDH, it |
|
520 | automatic show() calls. After discussing things with JDH, it | |
485 | turns out there are too many corner cases where this can go wrong. |
|
521 | turns out there are too many corner cases where this can go wrong. | |
486 | It's best not to try to be 'too smart', and simply have ipython |
|
522 | It's best not to try to be 'too smart', and simply have ipython | |
487 | reproduce as much as possible the default behavior of a normal |
|
523 | reproduce as much as possible the default behavior of a normal | |
488 | python shell. |
|
524 | python shell. | |
489 |
|
525 | |||
490 | * IPython/iplib.py (InteractiveShell.__init__): Modified the |
|
526 | * IPython/iplib.py (InteractiveShell.__init__): Modified the | |
491 | line-splitting regexp and _prefilter() to avoid calling getattr() |
|
527 | line-splitting regexp and _prefilter() to avoid calling getattr() | |
492 | on assignments. This closes |
|
528 | on assignments. This closes | |
493 | http://www.scipy.net/roundup/ipython/issue24. Note that Python's |
|
529 | http://www.scipy.net/roundup/ipython/issue24. Note that Python's | |
494 | readline uses getattr(), so a simple <TAB> keypress is still |
|
530 | readline uses getattr(), so a simple <TAB> keypress is still | |
495 | enough to trigger getattr() calls on an object. |
|
531 | enough to trigger getattr() calls on an object. | |
496 |
|
532 | |||
497 | 2005-01-21 Fernando Perez <fperez@colorado.edu> |
|
533 | 2005-01-21 Fernando Perez <fperez@colorado.edu> | |
498 |
|
534 | |||
499 | * IPython/Shell.py (MatplotlibShellBase.magic_run): Fix the %run |
|
535 | * IPython/Shell.py (MatplotlibShellBase.magic_run): Fix the %run | |
500 | docstring under pylab so it doesn't mask the original. |
|
536 | docstring under pylab so it doesn't mask the original. | |
501 |
|
537 | |||
502 | 2005-01-21 *** Released version 0.6.7 |
|
538 | 2005-01-21 *** Released version 0.6.7 | |
503 |
|
539 | |||
504 | 2005-01-21 Fernando Perez <fperez@colorado.edu> |
|
540 | 2005-01-21 Fernando Perez <fperez@colorado.edu> | |
505 |
|
541 | |||
506 | * IPython/Shell.py (MTInteractiveShell.runcode): Trap a crash with |
|
542 | * IPython/Shell.py (MTInteractiveShell.runcode): Trap a crash with | |
507 | signal handling for win32 users in multithreaded mode. |
|
543 | signal handling for win32 users in multithreaded mode. | |
508 |
|
544 | |||
509 | 2005-01-17 Fernando Perez <fperez@colorado.edu> |
|
545 | 2005-01-17 Fernando Perez <fperez@colorado.edu> | |
510 |
|
546 | |||
511 | * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting |
|
547 | * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting | |
512 | instances with no __init__. After a crash report by Norbert Nemec |
|
548 | instances with no __init__. After a crash report by Norbert Nemec | |
513 | <Norbert-AT-nemec-online.de>. |
|
549 | <Norbert-AT-nemec-online.de>. | |
514 |
|
550 | |||
515 | 2005-01-14 Fernando Perez <fperez@colorado.edu> |
|
551 | 2005-01-14 Fernando Perez <fperez@colorado.edu> | |
516 |
|
552 | |||
517 | * IPython/ultraTB.py (VerboseTB.text): Fix bug in reporting of |
|
553 | * IPython/ultraTB.py (VerboseTB.text): Fix bug in reporting of | |
518 | names for verbose exceptions, when multiple dotted names and the |
|
554 | names for verbose exceptions, when multiple dotted names and the | |
519 | 'parent' object were present on the same line. |
|
555 | 'parent' object were present on the same line. | |
520 |
|
556 | |||
521 | 2005-01-11 Fernando Perez <fperez@colorado.edu> |
|
557 | 2005-01-11 Fernando Perez <fperez@colorado.edu> | |
522 |
|
558 | |||
523 | * IPython/genutils.py (flag_calls): new utility to trap and flag |
|
559 | * IPython/genutils.py (flag_calls): new utility to trap and flag | |
524 | calls in functions. I need it to clean up matplotlib support. |
|
560 | calls in functions. I need it to clean up matplotlib support. | |
525 | Also removed some deprecated code in genutils. |
|
561 | Also removed some deprecated code in genutils. | |
526 |
|
562 | |||
527 | * IPython/Shell.py (MatplotlibShellBase.mplot_exec): small fix so |
|
563 | * IPython/Shell.py (MatplotlibShellBase.mplot_exec): small fix so | |
528 | that matplotlib scripts called with %run, which don't call show() |
|
564 | that matplotlib scripts called with %run, which don't call show() | |
529 | themselves, still have their plotting windows open. |
|
565 | themselves, still have their plotting windows open. | |
530 |
|
566 | |||
531 | 2005-01-05 Fernando Perez <fperez@colorado.edu> |
|
567 | 2005-01-05 Fernando Perez <fperez@colorado.edu> | |
532 |
|
568 | |||
533 | * IPython/Shell.py (IPShellGTK.__init__): Patch by Andrew Straw |
|
569 | * IPython/Shell.py (IPShellGTK.__init__): Patch by Andrew Straw | |
534 | <astraw-AT-caltech.edu>, to fix gtk deprecation warnings. |
|
570 | <astraw-AT-caltech.edu>, to fix gtk deprecation warnings. | |
535 |
|
571 | |||
536 | 2004-12-19 Fernando Perez <fperez@colorado.edu> |
|
572 | 2004-12-19 Fernando Perez <fperez@colorado.edu> | |
537 |
|
573 | |||
538 | * IPython/Shell.py (MTInteractiveShell.runcode): Get rid of |
|
574 | * IPython/Shell.py (MTInteractiveShell.runcode): Get rid of | |
539 | parent_runcode, which was an eyesore. The same result can be |
|
575 | parent_runcode, which was an eyesore. The same result can be | |
540 | obtained with Python's regular superclass mechanisms. |
|
576 | obtained with Python's regular superclass mechanisms. | |
541 |
|
577 | |||
542 | 2004-12-17 Fernando Perez <fperez@colorado.edu> |
|
578 | 2004-12-17 Fernando Perez <fperez@colorado.edu> | |
543 |
|
579 | |||
544 | * IPython/Magic.py (Magic.magic_sc): Fix quote stripping problem |
|
580 | * IPython/Magic.py (Magic.magic_sc): Fix quote stripping problem | |
545 | reported by Prabhu. |
|
581 | reported by Prabhu. | |
546 | (Magic.magic_sx): direct all errors to Term.cerr (defaults to |
|
582 | (Magic.magic_sx): direct all errors to Term.cerr (defaults to | |
547 | sys.stderr) instead of explicitly calling sys.stderr. This helps |
|
583 | sys.stderr) instead of explicitly calling sys.stderr. This helps | |
548 | maintain our I/O abstractions clean, for future GUI embeddings. |
|
584 | maintain our I/O abstractions clean, for future GUI embeddings. | |
549 |
|
585 | |||
550 | * IPython/genutils.py (info): added new utility for sys.stderr |
|
586 | * IPython/genutils.py (info): added new utility for sys.stderr | |
551 | unified info message handling (thin wrapper around warn()). |
|
587 | unified info message handling (thin wrapper around warn()). | |
552 |
|
588 | |||
553 | * IPython/ultraTB.py (VerboseTB.text): Fix misreported global |
|
589 | * IPython/ultraTB.py (VerboseTB.text): Fix misreported global | |
554 | composite (dotted) names on verbose exceptions. |
|
590 | composite (dotted) names on verbose exceptions. | |
555 | (VerboseTB.nullrepr): harden against another kind of errors which |
|
591 | (VerboseTB.nullrepr): harden against another kind of errors which | |
556 | Python's inspect module can trigger, and which were crashing |
|
592 | Python's inspect module can trigger, and which were crashing | |
557 | IPython. Thanks to a report by Marco Lombardi |
|
593 | IPython. Thanks to a report by Marco Lombardi | |
558 | <mlombard-AT-ma010192.hq.eso.org>. |
|
594 | <mlombard-AT-ma010192.hq.eso.org>. | |
559 |
|
595 | |||
560 | 2004-12-13 *** Released version 0.6.6 |
|
596 | 2004-12-13 *** Released version 0.6.6 | |
561 |
|
597 | |||
562 | 2004-12-12 Fernando Perez <fperez@colorado.edu> |
|
598 | 2004-12-12 Fernando Perez <fperez@colorado.edu> | |
563 |
|
599 | |||
564 | * IPython/Shell.py (IPShellGTK.mainloop): catch RuntimeErrors |
|
600 | * IPython/Shell.py (IPShellGTK.mainloop): catch RuntimeErrors | |
565 | generated by pygtk upon initialization if it was built without |
|
601 | generated by pygtk upon initialization if it was built without | |
566 | threads (for matplotlib users). After a crash reported by |
|
602 | threads (for matplotlib users). After a crash reported by | |
567 | Leguijt, Jaap J SIEP-EPT-RES <Jaap.Leguijt-AT-shell.com>. |
|
603 | Leguijt, Jaap J SIEP-EPT-RES <Jaap.Leguijt-AT-shell.com>. | |
568 |
|
604 | |||
569 | * IPython/ipmaker.py (make_IPython): fix small bug in the |
|
605 | * IPython/ipmaker.py (make_IPython): fix small bug in the | |
570 | import_some parameter for multiple imports. |
|
606 | import_some parameter for multiple imports. | |
571 |
|
607 | |||
572 | * IPython/iplib.py (ipmagic): simplified the interface of |
|
608 | * IPython/iplib.py (ipmagic): simplified the interface of | |
573 | ipmagic() to take a single string argument, just as it would be |
|
609 | ipmagic() to take a single string argument, just as it would be | |
574 | typed at the IPython cmd line. |
|
610 | typed at the IPython cmd line. | |
575 | (ipalias): Added new ipalias() with an interface identical to |
|
611 | (ipalias): Added new ipalias() with an interface identical to | |
576 | ipmagic(). This completes exposing a pure python interface to the |
|
612 | ipmagic(). This completes exposing a pure python interface to the | |
577 | alias and magic system, which can be used in loops or more complex |
|
613 | alias and magic system, which can be used in loops or more complex | |
578 | code where IPython's automatic line mangling is not active. |
|
614 | code where IPython's automatic line mangling is not active. | |
579 |
|
615 | |||
580 | * IPython/genutils.py (timing): changed interface of timing to |
|
616 | * IPython/genutils.py (timing): changed interface of timing to | |
581 | simply run code once, which is the most common case. timings() |
|
617 | simply run code once, which is the most common case. timings() | |
582 | remains unchanged, for the cases where you want multiple runs. |
|
618 | remains unchanged, for the cases where you want multiple runs. | |
583 |
|
619 | |||
584 | * IPython/Shell.py (MatplotlibShellBase._matplotlib_config): Fix a |
|
620 | * IPython/Shell.py (MatplotlibShellBase._matplotlib_config): Fix a | |
585 | bug where Python2.2 crashes with exec'ing code which does not end |
|
621 | bug where Python2.2 crashes with exec'ing code which does not end | |
586 | in a single newline. Python 2.3 is OK, so I hadn't noticed this |
|
622 | in a single newline. Python 2.3 is OK, so I hadn't noticed this | |
587 | before. |
|
623 | before. | |
588 |
|
624 | |||
589 | 2004-12-10 Fernando Perez <fperez@colorado.edu> |
|
625 | 2004-12-10 Fernando Perez <fperez@colorado.edu> | |
590 |
|
626 | |||
591 | * IPython/Magic.py (Magic.magic_prun): changed name of option from |
|
627 | * IPython/Magic.py (Magic.magic_prun): changed name of option from | |
592 | -t to -T, to accomodate the new -t flag in %run (the %run and |
|
628 | -t to -T, to accomodate the new -t flag in %run (the %run and | |
593 | %prun options are kind of intermixed, and it's not easy to change |
|
629 | %prun options are kind of intermixed, and it's not easy to change | |
594 | this with the limitations of python's getopt). |
|
630 | this with the limitations of python's getopt). | |
595 |
|
631 | |||
596 | * IPython/Magic.py (Magic.magic_run): Added new -t option to time |
|
632 | * IPython/Magic.py (Magic.magic_run): Added new -t option to time | |
597 | the execution of scripts. It's not as fine-tuned as timeit.py, |
|
633 | the execution of scripts. It's not as fine-tuned as timeit.py, | |
598 | but it works from inside ipython (and under 2.2, which lacks |
|
634 | but it works from inside ipython (and under 2.2, which lacks | |
599 | timeit.py). Optionally a number of runs > 1 can be given for |
|
635 | timeit.py). Optionally a number of runs > 1 can be given for | |
600 | timing very short-running code. |
|
636 | timing very short-running code. | |
601 |
|
637 | |||
602 | * IPython/genutils.py (uniq_stable): new routine which returns a |
|
638 | * IPython/genutils.py (uniq_stable): new routine which returns a | |
603 | list of unique elements in any iterable, but in stable order of |
|
639 | list of unique elements in any iterable, but in stable order of | |
604 | appearance. I needed this for the ultraTB fixes, and it's a handy |
|
640 | appearance. I needed this for the ultraTB fixes, and it's a handy | |
605 | utility. |
|
641 | utility. | |
606 |
|
642 | |||
607 | * IPython/ultraTB.py (VerboseTB.text): Fix proper reporting of |
|
643 | * IPython/ultraTB.py (VerboseTB.text): Fix proper reporting of | |
608 | dotted names in Verbose exceptions. This had been broken since |
|
644 | dotted names in Verbose exceptions. This had been broken since | |
609 | the very start, now x.y will properly be printed in a Verbose |
|
645 | the very start, now x.y will properly be printed in a Verbose | |
610 | traceback, instead of x being shown and y appearing always as an |
|
646 | traceback, instead of x being shown and y appearing always as an | |
611 | 'undefined global'. Getting this to work was a bit tricky, |
|
647 | 'undefined global'. Getting this to work was a bit tricky, | |
612 | because by default python tokenizers are stateless. Saved by |
|
648 | because by default python tokenizers are stateless. Saved by | |
613 | python's ability to easily add a bit of state to an arbitrary |
|
649 | python's ability to easily add a bit of state to an arbitrary | |
614 | function (without needing to build a full-blown callable object). |
|
650 | function (without needing to build a full-blown callable object). | |
615 |
|
651 | |||
616 | Also big cleanup of this code, which had horrendous runtime |
|
652 | Also big cleanup of this code, which had horrendous runtime | |
617 | lookups of zillions of attributes for colorization. Moved all |
|
653 | lookups of zillions of attributes for colorization. Moved all | |
618 | this code into a few templates, which make it cleaner and quicker. |
|
654 | this code into a few templates, which make it cleaner and quicker. | |
619 |
|
655 | |||
620 | Printout quality was also improved for Verbose exceptions: one |
|
656 | Printout quality was also improved for Verbose exceptions: one | |
621 | variable per line, and memory addresses are printed (this can be |
|
657 | variable per line, and memory addresses are printed (this can be | |
622 | quite handy in nasty debugging situations, which is what Verbose |
|
658 | quite handy in nasty debugging situations, which is what Verbose | |
623 | is for). |
|
659 | is for). | |
624 |
|
660 | |||
625 | * IPython/ipmaker.py (make_IPython): Do NOT execute files named in |
|
661 | * IPython/ipmaker.py (make_IPython): Do NOT execute files named in | |
626 | the command line as scripts to be loaded by embedded instances. |
|
662 | the command line as scripts to be loaded by embedded instances. | |
627 | Doing so has the potential for an infinite recursion if there are |
|
663 | Doing so has the potential for an infinite recursion if there are | |
628 | exceptions thrown in the process. This fixes a strange crash |
|
664 | exceptions thrown in the process. This fixes a strange crash | |
629 | reported by Philippe MULLER <muller-AT-irit.fr>. |
|
665 | reported by Philippe MULLER <muller-AT-irit.fr>. | |
630 |
|
666 | |||
631 | 2004-12-09 Fernando Perez <fperez@colorado.edu> |
|
667 | 2004-12-09 Fernando Perez <fperez@colorado.edu> | |
632 |
|
668 | |||
633 | * IPython/Shell.py (MatplotlibShellBase.use): Change pylab support |
|
669 | * IPython/Shell.py (MatplotlibShellBase.use): Change pylab support | |
634 | to reflect new names in matplotlib, which now expose the |
|
670 | to reflect new names in matplotlib, which now expose the | |
635 | matlab-compatible interface via a pylab module instead of the |
|
671 | matlab-compatible interface via a pylab module instead of the | |
636 | 'matlab' name. The new code is backwards compatible, so users of |
|
672 | 'matlab' name. The new code is backwards compatible, so users of | |
637 | all matplotlib versions are OK. Patch by J. Hunter. |
|
673 | all matplotlib versions are OK. Patch by J. Hunter. | |
638 |
|
674 | |||
639 | * IPython/OInspect.py (Inspector.pinfo): Add to object? printing |
|
675 | * IPython/OInspect.py (Inspector.pinfo): Add to object? printing | |
640 | of __init__ docstrings for instances (class docstrings are already |
|
676 | of __init__ docstrings for instances (class docstrings are already | |
641 | automatically printed). Instances with customized docstrings |
|
677 | automatically printed). Instances with customized docstrings | |
642 | (indep. of the class) are also recognized and all 3 separate |
|
678 | (indep. of the class) are also recognized and all 3 separate | |
643 | docstrings are printed (instance, class, constructor). After some |
|
679 | docstrings are printed (instance, class, constructor). After some | |
644 | comments/suggestions by J. Hunter. |
|
680 | comments/suggestions by J. Hunter. | |
645 |
|
681 | |||
646 | 2004-12-05 Fernando Perez <fperez@colorado.edu> |
|
682 | 2004-12-05 Fernando Perez <fperez@colorado.edu> | |
647 |
|
683 | |||
648 | * IPython/iplib.py (MagicCompleter.complete): Remove annoying |
|
684 | * IPython/iplib.py (MagicCompleter.complete): Remove annoying | |
649 | warnings when tab-completion fails and triggers an exception. |
|
685 | warnings when tab-completion fails and triggers an exception. | |
650 |
|
686 | |||
651 | 2004-12-03 Fernando Perez <fperez@colorado.edu> |
|
687 | 2004-12-03 Fernando Perez <fperez@colorado.edu> | |
652 |
|
688 | |||
653 | * IPython/Magic.py (magic_prun): Fix bug where an exception would |
|
689 | * IPython/Magic.py (magic_prun): Fix bug where an exception would | |
654 | be triggered when using 'run -p'. An incorrect option flag was |
|
690 | be triggered when using 'run -p'. An incorrect option flag was | |
655 | being set ('d' instead of 'D'). |
|
691 | being set ('d' instead of 'D'). | |
656 | (manpage): fix missing escaped \- sign. |
|
692 | (manpage): fix missing escaped \- sign. | |
657 |
|
693 | |||
658 | 2004-11-30 *** Released version 0.6.5 |
|
694 | 2004-11-30 *** Released version 0.6.5 | |
659 |
|
695 | |||
660 | 2004-11-30 Fernando Perez <fperez@colorado.edu> |
|
696 | 2004-11-30 Fernando Perez <fperez@colorado.edu> | |
661 |
|
697 | |||
662 | * IPython/Magic.py (Magic.magic_run): Fix bug in breakpoint |
|
698 | * IPython/Magic.py (Magic.magic_run): Fix bug in breakpoint | |
663 | setting with -d option. |
|
699 | setting with -d option. | |
664 |
|
700 | |||
665 | * setup.py (docfiles): Fix problem where the doc glob I was using |
|
701 | * setup.py (docfiles): Fix problem where the doc glob I was using | |
666 | was COMPLETELY BROKEN. It was giving the right files by pure |
|
702 | was COMPLETELY BROKEN. It was giving the right files by pure | |
667 | accident, but failed once I tried to include ipython.el. Note: |
|
703 | accident, but failed once I tried to include ipython.el. Note: | |
668 | glob() does NOT allow you to do exclusion on multiple endings! |
|
704 | glob() does NOT allow you to do exclusion on multiple endings! | |
669 |
|
705 | |||
670 | 2004-11-29 Fernando Perez <fperez@colorado.edu> |
|
706 | 2004-11-29 Fernando Perez <fperez@colorado.edu> | |
671 |
|
707 | |||
672 | * IPython/usage.py (__doc__): cleaned up usage docstring, by using |
|
708 | * IPython/usage.py (__doc__): cleaned up usage docstring, by using | |
673 | the manpage as the source. Better formatting & consistency. |
|
709 | the manpage as the source. Better formatting & consistency. | |
674 |
|
710 | |||
675 | * IPython/Magic.py (magic_run): Added new -d option, to run |
|
711 | * IPython/Magic.py (magic_run): Added new -d option, to run | |
676 | scripts under the control of the python pdb debugger. Note that |
|
712 | scripts under the control of the python pdb debugger. Note that | |
677 | this required changing the %prun option -d to -D, to avoid a clash |
|
713 | this required changing the %prun option -d to -D, to avoid a clash | |
678 | (since %run must pass options to %prun, and getopt is too dumb to |
|
714 | (since %run must pass options to %prun, and getopt is too dumb to | |
679 | handle options with string values with embedded spaces). Thanks |
|
715 | handle options with string values with embedded spaces). Thanks | |
680 | to a suggestion by Matthew Arnison <maffew-AT-cat.org.au>. |
|
716 | to a suggestion by Matthew Arnison <maffew-AT-cat.org.au>. | |
681 | (magic_who_ls): added type matching to %who and %whos, so that one |
|
717 | (magic_who_ls): added type matching to %who and %whos, so that one | |
682 | can filter their output to only include variables of certain |
|
718 | can filter their output to only include variables of certain | |
683 | types. Another suggestion by Matthew. |
|
719 | types. Another suggestion by Matthew. | |
684 | (magic_whos): Added memory summaries in kb and Mb for arrays. |
|
720 | (magic_whos): Added memory summaries in kb and Mb for arrays. | |
685 | (magic_who): Improve formatting (break lines every 9 vars). |
|
721 | (magic_who): Improve formatting (break lines every 9 vars). | |
686 |
|
722 | |||
687 | 2004-11-28 Fernando Perez <fperez@colorado.edu> |
|
723 | 2004-11-28 Fernando Perez <fperez@colorado.edu> | |
688 |
|
724 | |||
689 | * IPython/Logger.py (Logger.log): Fix bug in syncing the input |
|
725 | * IPython/Logger.py (Logger.log): Fix bug in syncing the input | |
690 | cache when empty lines were present. |
|
726 | cache when empty lines were present. | |
691 |
|
727 | |||
692 | 2004-11-24 Fernando Perez <fperez@colorado.edu> |
|
728 | 2004-11-24 Fernando Perez <fperez@colorado.edu> | |
693 |
|
729 | |||
694 | * IPython/usage.py (__doc__): document the re-activated threading |
|
730 | * IPython/usage.py (__doc__): document the re-activated threading | |
695 | options for WX and GTK. |
|
731 | options for WX and GTK. | |
696 |
|
732 | |||
697 | 2004-11-23 Fernando Perez <fperez@colorado.edu> |
|
733 | 2004-11-23 Fernando Perez <fperez@colorado.edu> | |
698 |
|
734 | |||
699 | * IPython/Shell.py (start): Added Prabhu's big patch to reactivate |
|
735 | * IPython/Shell.py (start): Added Prabhu's big patch to reactivate | |
700 | the -wthread and -gthread options, along with a new -tk one to try |
|
736 | the -wthread and -gthread options, along with a new -tk one to try | |
701 | and coordinate Tk threading with wx/gtk. The tk support is very |
|
737 | and coordinate Tk threading with wx/gtk. The tk support is very | |
702 | platform dependent, since it seems to require Tcl and Tk to be |
|
738 | platform dependent, since it seems to require Tcl and Tk to be | |
703 | built with threads (Fedora1/2 appears NOT to have it, but in |
|
739 | built with threads (Fedora1/2 appears NOT to have it, but in | |
704 | Prabhu's Debian boxes it works OK). But even with some Tk |
|
740 | Prabhu's Debian boxes it works OK). But even with some Tk | |
705 | limitations, this is a great improvement. |
|
741 | limitations, this is a great improvement. | |
706 |
|
742 | |||
707 | * IPython/Prompts.py (prompt_specials_color): Added \t for time |
|
743 | * IPython/Prompts.py (prompt_specials_color): Added \t for time | |
708 | info in user prompts. Patch by Prabhu. |
|
744 | info in user prompts. Patch by Prabhu. | |
709 |
|
745 | |||
710 | 2004-11-18 Fernando Perez <fperez@colorado.edu> |
|
746 | 2004-11-18 Fernando Perez <fperez@colorado.edu> | |
711 |
|
747 | |||
712 | * IPython/genutils.py (ask_yes_no): Add check for a max of 20 |
|
748 | * IPython/genutils.py (ask_yes_no): Add check for a max of 20 | |
713 | EOFErrors and bail, to avoid infinite loops if a non-terminating |
|
749 | EOFErrors and bail, to avoid infinite loops if a non-terminating | |
714 | file is fed into ipython. Patch submitted in issue 19 by user, |
|
750 | file is fed into ipython. Patch submitted in issue 19 by user, | |
715 | many thanks. |
|
751 | many thanks. | |
716 |
|
752 | |||
717 | * IPython/iplib.py (InteractiveShell.handle_auto): do NOT trigger |
|
753 | * IPython/iplib.py (InteractiveShell.handle_auto): do NOT trigger | |
718 | autoquote/parens in continuation prompts, which can cause lots of |
|
754 | autoquote/parens in continuation prompts, which can cause lots of | |
719 | problems. Closes roundup issue 20. |
|
755 | problems. Closes roundup issue 20. | |
720 |
|
756 | |||
721 | 2004-11-17 Fernando Perez <fperez@colorado.edu> |
|
757 | 2004-11-17 Fernando Perez <fperez@colorado.edu> | |
722 |
|
758 | |||
723 | * debian/control (Build-Depends-Indep): Fix dpatch dependency, |
|
759 | * debian/control (Build-Depends-Indep): Fix dpatch dependency, | |
724 | reported as debian bug #280505. I'm not sure my local changelog |
|
760 | reported as debian bug #280505. I'm not sure my local changelog | |
725 | entry has the proper debian format (Jack?). |
|
761 | entry has the proper debian format (Jack?). | |
726 |
|
762 | |||
727 | 2004-11-08 *** Released version 0.6.4 |
|
763 | 2004-11-08 *** Released version 0.6.4 | |
728 |
|
764 | |||
729 | 2004-11-08 Fernando Perez <fperez@colorado.edu> |
|
765 | 2004-11-08 Fernando Perez <fperez@colorado.edu> | |
730 |
|
766 | |||
731 | * IPython/iplib.py (init_readline): Fix exit message for Windows |
|
767 | * IPython/iplib.py (init_readline): Fix exit message for Windows | |
732 | when readline is active. Thanks to a report by Eric Jones |
|
768 | when readline is active. Thanks to a report by Eric Jones | |
733 | <eric-AT-enthought.com>. |
|
769 | <eric-AT-enthought.com>. | |
734 |
|
770 | |||
735 | 2004-11-07 Fernando Perez <fperez@colorado.edu> |
|
771 | 2004-11-07 Fernando Perez <fperez@colorado.edu> | |
736 |
|
772 | |||
737 | * IPython/genutils.py (page): Add a trap for OSError exceptions, |
|
773 | * IPython/genutils.py (page): Add a trap for OSError exceptions, | |
738 | sometimes seen by win2k/cygwin users. |
|
774 | sometimes seen by win2k/cygwin users. | |
739 |
|
775 | |||
740 | 2004-11-06 Fernando Perez <fperez@colorado.edu> |
|
776 | 2004-11-06 Fernando Perez <fperez@colorado.edu> | |
741 |
|
777 | |||
742 | * IPython/iplib.py (interact): Change the handling of %Exit from |
|
778 | * IPython/iplib.py (interact): Change the handling of %Exit from | |
743 | trying to propagate a SystemExit to an internal ipython flag. |
|
779 | trying to propagate a SystemExit to an internal ipython flag. | |
744 | This is less elegant than using Python's exception mechanism, but |
|
780 | This is less elegant than using Python's exception mechanism, but | |
745 | I can't get that to work reliably with threads, so under -pylab |
|
781 | I can't get that to work reliably with threads, so under -pylab | |
746 | %Exit was hanging IPython. Cross-thread exception handling is |
|
782 | %Exit was hanging IPython. Cross-thread exception handling is | |
747 | really a bitch. Thaks to a bug report by Stephen Walton |
|
783 | really a bitch. Thaks to a bug report by Stephen Walton | |
748 | <stephen.walton-AT-csun.edu>. |
|
784 | <stephen.walton-AT-csun.edu>. | |
749 |
|
785 | |||
750 | 2004-11-04 Fernando Perez <fperez@colorado.edu> |
|
786 | 2004-11-04 Fernando Perez <fperez@colorado.edu> | |
751 |
|
787 | |||
752 | * IPython/iplib.py (raw_input_original): store a pointer to the |
|
788 | * IPython/iplib.py (raw_input_original): store a pointer to the | |
753 | true raw_input to harden against code which can modify it |
|
789 | true raw_input to harden against code which can modify it | |
754 | (wx.py.PyShell does this and would otherwise crash ipython). |
|
790 | (wx.py.PyShell does this and would otherwise crash ipython). | |
755 | Thanks to a bug report by Jim Flowers <james.flowers-AT-lgx.com>. |
|
791 | Thanks to a bug report by Jim Flowers <james.flowers-AT-lgx.com>. | |
756 |
|
792 | |||
757 | * IPython/Shell.py (MTInteractiveShell.runsource): Cleaner fix for |
|
793 | * IPython/Shell.py (MTInteractiveShell.runsource): Cleaner fix for | |
758 | Ctrl-C problem, which does not mess up the input line. |
|
794 | Ctrl-C problem, which does not mess up the input line. | |
759 |
|
795 | |||
760 | 2004-11-03 Fernando Perez <fperez@colorado.edu> |
|
796 | 2004-11-03 Fernando Perez <fperez@colorado.edu> | |
761 |
|
797 | |||
762 | * IPython/Release.py: Changed licensing to BSD, in all files. |
|
798 | * IPython/Release.py: Changed licensing to BSD, in all files. | |
763 | (name): lowercase name for tarball/RPM release. |
|
799 | (name): lowercase name for tarball/RPM release. | |
764 |
|
800 | |||
765 | * IPython/OInspect.py (getdoc): wrap inspect.getdoc() safely for |
|
801 | * IPython/OInspect.py (getdoc): wrap inspect.getdoc() safely for | |
766 | use throughout ipython. |
|
802 | use throughout ipython. | |
767 |
|
803 | |||
768 | * IPython/Magic.py (Magic._ofind): Switch to using the new |
|
804 | * IPython/Magic.py (Magic._ofind): Switch to using the new | |
769 | OInspect.getdoc() function. |
|
805 | OInspect.getdoc() function. | |
770 |
|
806 | |||
771 | * IPython/Shell.py (sigint_handler): Hack to ignore the execution |
|
807 | * IPython/Shell.py (sigint_handler): Hack to ignore the execution | |
772 | of the line currently being canceled via Ctrl-C. It's extremely |
|
808 | of the line currently being canceled via Ctrl-C. It's extremely | |
773 | ugly, but I don't know how to do it better (the problem is one of |
|
809 | ugly, but I don't know how to do it better (the problem is one of | |
774 | handling cross-thread exceptions). |
|
810 | handling cross-thread exceptions). | |
775 |
|
811 | |||
776 | 2004-10-28 Fernando Perez <fperez@colorado.edu> |
|
812 | 2004-10-28 Fernando Perez <fperez@colorado.edu> | |
777 |
|
813 | |||
778 | * IPython/Shell.py (signal_handler): add signal handlers to trap |
|
814 | * IPython/Shell.py (signal_handler): add signal handlers to trap | |
779 | SIGINT and SIGSEGV in threaded code properly. Thanks to a bug |
|
815 | SIGINT and SIGSEGV in threaded code properly. Thanks to a bug | |
780 | report by Francesc Alted. |
|
816 | report by Francesc Alted. | |
781 |
|
817 | |||
782 | 2004-10-21 Fernando Perez <fperez@colorado.edu> |
|
818 | 2004-10-21 Fernando Perez <fperez@colorado.edu> | |
783 |
|
819 | |||
784 | * IPython/Extensions/InterpreterExec.py (prefilter_shell): Fix @ |
|
820 | * IPython/Extensions/InterpreterExec.py (prefilter_shell): Fix @ | |
785 | to % for pysh syntax extensions. |
|
821 | to % for pysh syntax extensions. | |
786 |
|
822 | |||
787 | 2004-10-09 Fernando Perez <fperez@colorado.edu> |
|
823 | 2004-10-09 Fernando Perez <fperez@colorado.edu> | |
788 |
|
824 | |||
789 | * IPython/Magic.py (Magic.magic_whos): modify output of Numeric |
|
825 | * IPython/Magic.py (Magic.magic_whos): modify output of Numeric | |
790 | arrays to print a more useful summary, without calling str(arr). |
|
826 | arrays to print a more useful summary, without calling str(arr). | |
791 | This avoids the problem of extremely lengthy computations which |
|
827 | This avoids the problem of extremely lengthy computations which | |
792 | occur if arr is large, and appear to the user as a system lockup |
|
828 | occur if arr is large, and appear to the user as a system lockup | |
793 | with 100% cpu activity. After a suggestion by Kristian Sandberg |
|
829 | with 100% cpu activity. After a suggestion by Kristian Sandberg | |
794 | <Kristian.Sandberg@colorado.edu>. |
|
830 | <Kristian.Sandberg@colorado.edu>. | |
795 | (Magic.__init__): fix bug in global magic escapes not being |
|
831 | (Magic.__init__): fix bug in global magic escapes not being | |
796 | correctly set. |
|
832 | correctly set. | |
797 |
|
833 | |||
798 | 2004-10-08 Fernando Perez <fperez@colorado.edu> |
|
834 | 2004-10-08 Fernando Perez <fperez@colorado.edu> | |
799 |
|
835 | |||
800 | * IPython/Magic.py (__license__): change to absolute imports of |
|
836 | * IPython/Magic.py (__license__): change to absolute imports of | |
801 | ipython's own internal packages, to start adapting to the absolute |
|
837 | ipython's own internal packages, to start adapting to the absolute | |
802 | import requirement of PEP-328. |
|
838 | import requirement of PEP-328. | |
803 |
|
839 | |||
804 | * IPython/genutils.py (__author__): Fix coding to utf-8 on all |
|
840 | * IPython/genutils.py (__author__): Fix coding to utf-8 on all | |
805 | files, and standardize author/license marks through the Release |
|
841 | files, and standardize author/license marks through the Release | |
806 | module instead of having per/file stuff (except for files with |
|
842 | module instead of having per/file stuff (except for files with | |
807 | particular licenses, like the MIT/PSF-licensed codes). |
|
843 | particular licenses, like the MIT/PSF-licensed codes). | |
808 |
|
844 | |||
809 | * IPython/Debugger.py: remove dead code for python 2.1 |
|
845 | * IPython/Debugger.py: remove dead code for python 2.1 | |
810 |
|
846 | |||
811 | 2004-10-04 Fernando Perez <fperez@colorado.edu> |
|
847 | 2004-10-04 Fernando Perez <fperez@colorado.edu> | |
812 |
|
848 | |||
813 | * IPython/iplib.py (ipmagic): New function for accessing magics |
|
849 | * IPython/iplib.py (ipmagic): New function for accessing magics | |
814 | via a normal python function call. |
|
850 | via a normal python function call. | |
815 |
|
851 | |||
816 | * IPython/Magic.py (Magic.magic_magic): Change the magic escape |
|
852 | * IPython/Magic.py (Magic.magic_magic): Change the magic escape | |
817 | from '@' to '%', to accomodate the new @decorator syntax of python |
|
853 | from '@' to '%', to accomodate the new @decorator syntax of python | |
818 | 2.4. |
|
854 | 2.4. | |
819 |
|
855 | |||
820 | 2004-09-29 Fernando Perez <fperez@colorado.edu> |
|
856 | 2004-09-29 Fernando Perez <fperez@colorado.edu> | |
821 |
|
857 | |||
822 | * IPython/Shell.py (MatplotlibShellBase.use): Added a wrapper to |
|
858 | * IPython/Shell.py (MatplotlibShellBase.use): Added a wrapper to | |
823 | matplotlib.use to prevent running scripts which try to switch |
|
859 | matplotlib.use to prevent running scripts which try to switch | |
824 | interactive backends from within ipython. This will just crash |
|
860 | interactive backends from within ipython. This will just crash | |
825 | the python interpreter, so we can't allow it (but a detailed error |
|
861 | the python interpreter, so we can't allow it (but a detailed error | |
826 | is given to the user). |
|
862 | is given to the user). | |
827 |
|
863 | |||
828 | 2004-09-28 Fernando Perez <fperez@colorado.edu> |
|
864 | 2004-09-28 Fernando Perez <fperez@colorado.edu> | |
829 |
|
865 | |||
830 | * IPython/Shell.py (MatplotlibShellBase.mplot_exec): |
|
866 | * IPython/Shell.py (MatplotlibShellBase.mplot_exec): | |
831 | matplotlib-related fixes so that using @run with non-matplotlib |
|
867 | matplotlib-related fixes so that using @run with non-matplotlib | |
832 | scripts doesn't pop up spurious plot windows. This requires |
|
868 | scripts doesn't pop up spurious plot windows. This requires | |
833 | matplotlib >= 0.63, where I had to make some changes as well. |
|
869 | matplotlib >= 0.63, where I had to make some changes as well. | |
834 |
|
870 | |||
835 | * IPython/ipmaker.py (make_IPython): update version requirement to |
|
871 | * IPython/ipmaker.py (make_IPython): update version requirement to | |
836 | python 2.2. |
|
872 | python 2.2. | |
837 |
|
873 | |||
838 | * IPython/iplib.py (InteractiveShell.mainloop): Add an optional |
|
874 | * IPython/iplib.py (InteractiveShell.mainloop): Add an optional | |
839 | banner arg for embedded customization. |
|
875 | banner arg for embedded customization. | |
840 |
|
876 | |||
841 | * IPython/Magic.py (Magic.__init__): big cleanup to remove all |
|
877 | * IPython/Magic.py (Magic.__init__): big cleanup to remove all | |
842 | explicit uses of __IP as the IPython's instance name. Now things |
|
878 | explicit uses of __IP as the IPython's instance name. Now things | |
843 | are properly handled via the shell.name value. The actual code |
|
879 | are properly handled via the shell.name value. The actual code | |
844 | is a bit ugly b/c I'm doing it via a global in Magic.py, but this |
|
880 | is a bit ugly b/c I'm doing it via a global in Magic.py, but this | |
845 | is much better than before. I'll clean things completely when the |
|
881 | is much better than before. I'll clean things completely when the | |
846 | magic stuff gets a real overhaul. |
|
882 | magic stuff gets a real overhaul. | |
847 |
|
883 | |||
848 | * ipython.1: small fixes, sent in by Jack Moffit. He also sent in |
|
884 | * ipython.1: small fixes, sent in by Jack Moffit. He also sent in | |
849 | minor changes to debian dir. |
|
885 | minor changes to debian dir. | |
850 |
|
886 | |||
851 | * IPython/iplib.py (InteractiveShell.__init__): Fix adding a |
|
887 | * IPython/iplib.py (InteractiveShell.__init__): Fix adding a | |
852 | pointer to the shell itself in the interactive namespace even when |
|
888 | pointer to the shell itself in the interactive namespace even when | |
853 | a user-supplied dict is provided. This is needed for embedding |
|
889 | a user-supplied dict is provided. This is needed for embedding | |
854 | purposes (found by tests with Michel Sanner). |
|
890 | purposes (found by tests with Michel Sanner). | |
855 |
|
891 | |||
856 | 2004-09-27 Fernando Perez <fperez@colorado.edu> |
|
892 | 2004-09-27 Fernando Perez <fperez@colorado.edu> | |
857 |
|
893 | |||
858 | * IPython/UserConfig/ipythonrc: remove []{} from |
|
894 | * IPython/UserConfig/ipythonrc: remove []{} from | |
859 | readline_remove_delims, so that things like [modname.<TAB> do |
|
895 | readline_remove_delims, so that things like [modname.<TAB> do | |
860 | proper completion. This disables [].TAB, but that's a less common |
|
896 | proper completion. This disables [].TAB, but that's a less common | |
861 | case than module names in list comprehensions, for example. |
|
897 | case than module names in list comprehensions, for example. | |
862 | Thanks to a report by Andrea Riciputi. |
|
898 | Thanks to a report by Andrea Riciputi. | |
863 |
|
899 | |||
864 | 2004-09-09 Fernando Perez <fperez@colorado.edu> |
|
900 | 2004-09-09 Fernando Perez <fperez@colorado.edu> | |
865 |
|
901 | |||
866 | * IPython/Shell.py (IPShellGTK.mainloop): reorder to avoid |
|
902 | * IPython/Shell.py (IPShellGTK.mainloop): reorder to avoid | |
867 | blocking problems in win32 and osx. Fix by John. |
|
903 | blocking problems in win32 and osx. Fix by John. | |
868 |
|
904 | |||
869 | 2004-09-08 Fernando Perez <fperez@colorado.edu> |
|
905 | 2004-09-08 Fernando Perez <fperez@colorado.edu> | |
870 |
|
906 | |||
871 | * IPython/Shell.py (IPShellWX.OnInit): Fix output redirection bug |
|
907 | * IPython/Shell.py (IPShellWX.OnInit): Fix output redirection bug | |
872 | for Win32 and OSX. Fix by John Hunter. |
|
908 | for Win32 and OSX. Fix by John Hunter. | |
873 |
|
909 | |||
874 | 2004-08-30 *** Released version 0.6.3 |
|
910 | 2004-08-30 *** Released version 0.6.3 | |
875 |
|
911 | |||
876 | 2004-08-30 Fernando Perez <fperez@colorado.edu> |
|
912 | 2004-08-30 Fernando Perez <fperez@colorado.edu> | |
877 |
|
913 | |||
878 | * setup.py (isfile): Add manpages to list of dependent files to be |
|
914 | * setup.py (isfile): Add manpages to list of dependent files to be | |
879 | updated. |
|
915 | updated. | |
880 |
|
916 | |||
881 | 2004-08-27 Fernando Perez <fperez@colorado.edu> |
|
917 | 2004-08-27 Fernando Perez <fperez@colorado.edu> | |
882 |
|
918 | |||
883 | * IPython/Shell.py (start): I've disabled -wthread and -gthread |
|
919 | * IPython/Shell.py (start): I've disabled -wthread and -gthread | |
884 | for now. They don't really work with standalone WX/GTK code |
|
920 | for now. They don't really work with standalone WX/GTK code | |
885 | (though matplotlib IS working fine with both of those backends). |
|
921 | (though matplotlib IS working fine with both of those backends). | |
886 | This will neeed much more testing. I disabled most things with |
|
922 | This will neeed much more testing. I disabled most things with | |
887 | comments, so turning it back on later should be pretty easy. |
|
923 | comments, so turning it back on later should be pretty easy. | |
888 |
|
924 | |||
889 | * IPython/iplib.py (InteractiveShell.__init__): Fix accidental |
|
925 | * IPython/iplib.py (InteractiveShell.__init__): Fix accidental | |
890 | autocalling of expressions like r'foo', by modifying the line |
|
926 | autocalling of expressions like r'foo', by modifying the line | |
891 | split regexp. Closes |
|
927 | split regexp. Closes | |
892 | http://www.scipy.net/roundup/ipython/issue18, reported by Nicholas |
|
928 | http://www.scipy.net/roundup/ipython/issue18, reported by Nicholas | |
893 | Riley <ipythonbugs-AT-sabi.net>. |
|
929 | Riley <ipythonbugs-AT-sabi.net>. | |
894 | (InteractiveShell.mainloop): honor --nobanner with banner |
|
930 | (InteractiveShell.mainloop): honor --nobanner with banner | |
895 | extensions. |
|
931 | extensions. | |
896 |
|
932 | |||
897 | * IPython/Shell.py: Significant refactoring of all classes, so |
|
933 | * IPython/Shell.py: Significant refactoring of all classes, so | |
898 | that we can really support ALL matplotlib backends and threading |
|
934 | that we can really support ALL matplotlib backends and threading | |
899 | models (John spotted a bug with Tk which required this). Now we |
|
935 | models (John spotted a bug with Tk which required this). Now we | |
900 | should support single-threaded, WX-threads and GTK-threads, both |
|
936 | should support single-threaded, WX-threads and GTK-threads, both | |
901 | for generic code and for matplotlib. |
|
937 | for generic code and for matplotlib. | |
902 |
|
938 | |||
903 | * IPython/ipmaker.py (__call__): Changed -mpthread option to |
|
939 | * IPython/ipmaker.py (__call__): Changed -mpthread option to | |
904 | -pylab, to simplify things for users. Will also remove the pylab |
|
940 | -pylab, to simplify things for users. Will also remove the pylab | |
905 | profile, since now all of matplotlib configuration is directly |
|
941 | profile, since now all of matplotlib configuration is directly | |
906 | handled here. This also reduces startup time. |
|
942 | handled here. This also reduces startup time. | |
907 |
|
943 | |||
908 | * IPython/Shell.py (IPShellGTK.run): Fixed bug where mainloop() of |
|
944 | * IPython/Shell.py (IPShellGTK.run): Fixed bug where mainloop() of | |
909 | shell wasn't being correctly called. Also in IPShellWX. |
|
945 | shell wasn't being correctly called. Also in IPShellWX. | |
910 |
|
946 | |||
911 | * IPython/iplib.py (InteractiveShell.__init__): Added option to |
|
947 | * IPython/iplib.py (InteractiveShell.__init__): Added option to | |
912 | fine-tune banner. |
|
948 | fine-tune banner. | |
913 |
|
949 | |||
914 | * IPython/numutils.py (spike): Deprecate these spike functions, |
|
950 | * IPython/numutils.py (spike): Deprecate these spike functions, | |
915 | delete (long deprecated) gnuplot_exec handler. |
|
951 | delete (long deprecated) gnuplot_exec handler. | |
916 |
|
952 | |||
917 | 2004-08-26 Fernando Perez <fperez@colorado.edu> |
|
953 | 2004-08-26 Fernando Perez <fperez@colorado.edu> | |
918 |
|
954 | |||
919 | * ipython.1: Update for threading options, plus some others which |
|
955 | * ipython.1: Update for threading options, plus some others which | |
920 | were missing. |
|
956 | were missing. | |
921 |
|
957 | |||
922 | * IPython/ipmaker.py (__call__): Added -wthread option for |
|
958 | * IPython/ipmaker.py (__call__): Added -wthread option for | |
923 | wxpython thread handling. Make sure threading options are only |
|
959 | wxpython thread handling. Make sure threading options are only | |
924 | valid at the command line. |
|
960 | valid at the command line. | |
925 |
|
961 | |||
926 | * scripts/ipython: moved shell selection into a factory function |
|
962 | * scripts/ipython: moved shell selection into a factory function | |
927 | in Shell.py, to keep the starter script to a minimum. |
|
963 | in Shell.py, to keep the starter script to a minimum. | |
928 |
|
964 | |||
929 | 2004-08-25 Fernando Perez <fperez@colorado.edu> |
|
965 | 2004-08-25 Fernando Perez <fperez@colorado.edu> | |
930 |
|
966 | |||
931 | * IPython/Shell.py (IPShellWX.wxexit): fixes to WX threading, by |
|
967 | * IPython/Shell.py (IPShellWX.wxexit): fixes to WX threading, by | |
932 | John. Along with some recent changes he made to matplotlib, the |
|
968 | John. Along with some recent changes he made to matplotlib, the | |
933 | next versions of both systems should work very well together. |
|
969 | next versions of both systems should work very well together. | |
934 |
|
970 | |||
935 | 2004-08-24 Fernando Perez <fperez@colorado.edu> |
|
971 | 2004-08-24 Fernando Perez <fperez@colorado.edu> | |
936 |
|
972 | |||
937 | * IPython/Magic.py (Magic.magic_prun): cleanup some dead code. I |
|
973 | * IPython/Magic.py (Magic.magic_prun): cleanup some dead code. I | |
938 | tried to switch the profiling to using hotshot, but I'm getting |
|
974 | tried to switch the profiling to using hotshot, but I'm getting | |
939 | strange errors from prof.runctx() there. I may be misreading the |
|
975 | strange errors from prof.runctx() there. I may be misreading the | |
940 | docs, but it looks weird. For now the profiling code will |
|
976 | docs, but it looks weird. For now the profiling code will | |
941 | continue to use the standard profiler. |
|
977 | continue to use the standard profiler. | |
942 |
|
978 | |||
943 | 2004-08-23 Fernando Perez <fperez@colorado.edu> |
|
979 | 2004-08-23 Fernando Perez <fperez@colorado.edu> | |
944 |
|
980 | |||
945 | * IPython/Shell.py (IPShellWX.__init__): Improvements to the WX |
|
981 | * IPython/Shell.py (IPShellWX.__init__): Improvements to the WX | |
946 | threaded shell, by John Hunter. It's not quite ready yet, but |
|
982 | threaded shell, by John Hunter. It's not quite ready yet, but | |
947 | close. |
|
983 | close. | |
948 |
|
984 | |||
949 | 2004-08-22 Fernando Perez <fperez@colorado.edu> |
|
985 | 2004-08-22 Fernando Perez <fperez@colorado.edu> | |
950 |
|
986 | |||
951 | * IPython/iplib.py (InteractiveShell.interact): tab cleanups, also |
|
987 | * IPython/iplib.py (InteractiveShell.interact): tab cleanups, also | |
952 | in Magic and ultraTB. |
|
988 | in Magic and ultraTB. | |
953 |
|
989 | |||
954 | * ipython.1: document threading options in manpage. |
|
990 | * ipython.1: document threading options in manpage. | |
955 |
|
991 | |||
956 | * scripts/ipython: Changed name of -thread option to -gthread, |
|
992 | * scripts/ipython: Changed name of -thread option to -gthread, | |
957 | since this is GTK specific. I want to leave the door open for a |
|
993 | since this is GTK specific. I want to leave the door open for a | |
958 | -wthread option for WX, which will most likely be necessary. This |
|
994 | -wthread option for WX, which will most likely be necessary. This | |
959 | change affects usage and ipmaker as well. |
|
995 | change affects usage and ipmaker as well. | |
960 |
|
996 | |||
961 | * IPython/Shell.py (matplotlib_shell): Add a factory function to |
|
997 | * IPython/Shell.py (matplotlib_shell): Add a factory function to | |
962 | handle the matplotlib shell issues. Code by John Hunter |
|
998 | handle the matplotlib shell issues. Code by John Hunter | |
963 | <jdhunter-AT-nitace.bsd.uchicago.edu>. |
|
999 | <jdhunter-AT-nitace.bsd.uchicago.edu>. | |
964 | (IPShellMatplotlibWX.__init__): Rudimentary WX support. It's |
|
1000 | (IPShellMatplotlibWX.__init__): Rudimentary WX support. It's | |
965 | broken (and disabled for end users) for now, but it puts the |
|
1001 | broken (and disabled for end users) for now, but it puts the | |
966 | infrastructure in place. |
|
1002 | infrastructure in place. | |
967 |
|
1003 | |||
968 | 2004-08-21 Fernando Perez <fperez@colorado.edu> |
|
1004 | 2004-08-21 Fernando Perez <fperez@colorado.edu> | |
969 |
|
1005 | |||
970 | * ipythonrc-pylab: Add matplotlib support. |
|
1006 | * ipythonrc-pylab: Add matplotlib support. | |
971 |
|
1007 | |||
972 | * matplotlib_config.py: new files for matplotlib support, part of |
|
1008 | * matplotlib_config.py: new files for matplotlib support, part of | |
973 | the pylab profile. |
|
1009 | the pylab profile. | |
974 |
|
1010 | |||
975 | * IPython/usage.py (__doc__): documented the threading options. |
|
1011 | * IPython/usage.py (__doc__): documented the threading options. | |
976 |
|
1012 | |||
977 | 2004-08-20 Fernando Perez <fperez@colorado.edu> |
|
1013 | 2004-08-20 Fernando Perez <fperez@colorado.edu> | |
978 |
|
1014 | |||
979 | * ipython: Modified the main calling routine to handle the -thread |
|
1015 | * ipython: Modified the main calling routine to handle the -thread | |
980 | and -mpthread options. This needs to be done as a top-level hack, |
|
1016 | and -mpthread options. This needs to be done as a top-level hack, | |
981 | because it determines which class to instantiate for IPython |
|
1017 | because it determines which class to instantiate for IPython | |
982 | itself. |
|
1018 | itself. | |
983 |
|
1019 | |||
984 | * IPython/Shell.py (MTInteractiveShell.__init__): New set of |
|
1020 | * IPython/Shell.py (MTInteractiveShell.__init__): New set of | |
985 | classes to support multithreaded GTK operation without blocking, |
|
1021 | classes to support multithreaded GTK operation without blocking, | |
986 | and matplotlib with all backends. This is a lot of still very |
|
1022 | and matplotlib with all backends. This is a lot of still very | |
987 | experimental code, and threads are tricky. So it may still have a |
|
1023 | experimental code, and threads are tricky. So it may still have a | |
988 | few rough edges... This code owes a lot to |
|
1024 | few rough edges... This code owes a lot to | |
989 | http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65109, by |
|
1025 | http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65109, by | |
990 | Brian # McErlean and John Finlay, to Antoon Pardon for fixes, and |
|
1026 | Brian # McErlean and John Finlay, to Antoon Pardon for fixes, and | |
991 | to John Hunter for all the matplotlib work. |
|
1027 | to John Hunter for all the matplotlib work. | |
992 |
|
1028 | |||
993 | * IPython/ipmaker.py (__call__): Added -thread and -mpthread |
|
1029 | * IPython/ipmaker.py (__call__): Added -thread and -mpthread | |
994 | options for gtk thread and matplotlib support. |
|
1030 | options for gtk thread and matplotlib support. | |
995 |
|
1031 | |||
996 | 2004-08-16 Fernando Perez <fperez@colorado.edu> |
|
1032 | 2004-08-16 Fernando Perez <fperez@colorado.edu> | |
997 |
|
1033 | |||
998 | * IPython/iplib.py (InteractiveShell.__init__): don't trigger |
|
1034 | * IPython/iplib.py (InteractiveShell.__init__): don't trigger | |
999 | autocall for things like p*q,p/q,p+q,p-q, when p is callable. Bug |
|
1035 | autocall for things like p*q,p/q,p+q,p-q, when p is callable. Bug | |
1000 | reported by Stephen Walton <stephen.walton-AT-csun.edu>. |
|
1036 | reported by Stephen Walton <stephen.walton-AT-csun.edu>. | |
1001 |
|
1037 | |||
1002 | 2004-08-11 Fernando Perez <fperez@colorado.edu> |
|
1038 | 2004-08-11 Fernando Perez <fperez@colorado.edu> | |
1003 |
|
1039 | |||
1004 | * setup.py (isfile): Fix build so documentation gets updated for |
|
1040 | * setup.py (isfile): Fix build so documentation gets updated for | |
1005 | rpms (it was only done for .tgz builds). |
|
1041 | rpms (it was only done for .tgz builds). | |
1006 |
|
1042 | |||
1007 | 2004-08-10 Fernando Perez <fperez@colorado.edu> |
|
1043 | 2004-08-10 Fernando Perez <fperez@colorado.edu> | |
1008 |
|
1044 | |||
1009 | * genutils.py (Term): Fix misspell of stdin stream (sin->cin). |
|
1045 | * genutils.py (Term): Fix misspell of stdin stream (sin->cin). | |
1010 |
|
1046 | |||
1011 | * iplib.py : Silence syntax error exceptions in tab-completion. |
|
1047 | * iplib.py : Silence syntax error exceptions in tab-completion. | |
1012 |
|
1048 | |||
1013 | 2004-08-05 Fernando Perez <fperez@colorado.edu> |
|
1049 | 2004-08-05 Fernando Perez <fperez@colorado.edu> | |
1014 |
|
1050 | |||
1015 | * IPython/Prompts.py (Prompt2.set_colors): Fix incorrectly set |
|
1051 | * IPython/Prompts.py (Prompt2.set_colors): Fix incorrectly set | |
1016 | 'color off' mark for continuation prompts. This was causing long |
|
1052 | 'color off' mark for continuation prompts. This was causing long | |
1017 | continuation lines to mis-wrap. |
|
1053 | continuation lines to mis-wrap. | |
1018 |
|
1054 | |||
1019 | 2004-08-01 Fernando Perez <fperez@colorado.edu> |
|
1055 | 2004-08-01 Fernando Perez <fperez@colorado.edu> | |
1020 |
|
1056 | |||
1021 | * IPython/ipmaker.py (make_IPython): Allow the shell class used |
|
1057 | * IPython/ipmaker.py (make_IPython): Allow the shell class used | |
1022 | for building ipython to be a parameter. All this is necessary |
|
1058 | for building ipython to be a parameter. All this is necessary | |
1023 | right now to have a multithreaded version, but this insane |
|
1059 | right now to have a multithreaded version, but this insane | |
1024 | non-design will be cleaned up soon. For now, it's a hack that |
|
1060 | non-design will be cleaned up soon. For now, it's a hack that | |
1025 | works. |
|
1061 | works. | |
1026 |
|
1062 | |||
1027 | * IPython/Shell.py (IPShell.__init__): Stop using mutable default |
|
1063 | * IPython/Shell.py (IPShell.__init__): Stop using mutable default | |
1028 | args in various places. No bugs so far, but it's a dangerous |
|
1064 | args in various places. No bugs so far, but it's a dangerous | |
1029 | practice. |
|
1065 | practice. | |
1030 |
|
1066 | |||
1031 | 2004-07-31 Fernando Perez <fperez@colorado.edu> |
|
1067 | 2004-07-31 Fernando Perez <fperez@colorado.edu> | |
1032 |
|
1068 | |||
1033 | * IPython/iplib.py (complete): ignore SyntaxError exceptions to |
|
1069 | * IPython/iplib.py (complete): ignore SyntaxError exceptions to | |
1034 | fix completion of files with dots in their names under most |
|
1070 | fix completion of files with dots in their names under most | |
1035 | profiles (pysh was OK because the completion order is different). |
|
1071 | profiles (pysh was OK because the completion order is different). | |
1036 |
|
1072 | |||
1037 | 2004-07-27 Fernando Perez <fperez@colorado.edu> |
|
1073 | 2004-07-27 Fernando Perez <fperez@colorado.edu> | |
1038 |
|
1074 | |||
1039 | * IPython/iplib.py (InteractiveShell.__init__): build dict of |
|
1075 | * IPython/iplib.py (InteractiveShell.__init__): build dict of | |
1040 | keywords manually, b/c the one in keyword.py was removed in python |
|
1076 | keywords manually, b/c the one in keyword.py was removed in python | |
1041 | 2.4. Patch by Anakim Border <aborder-AT-users.sourceforge.net>. |
|
1077 | 2.4. Patch by Anakim Border <aborder-AT-users.sourceforge.net>. | |
1042 | This is NOT a bug under python 2.3 and earlier. |
|
1078 | This is NOT a bug under python 2.3 and earlier. | |
1043 |
|
1079 | |||
1044 | 2004-07-26 Fernando Perez <fperez@colorado.edu> |
|
1080 | 2004-07-26 Fernando Perez <fperez@colorado.edu> | |
1045 |
|
1081 | |||
1046 | * IPython/ultraTB.py (VerboseTB.text): Add another |
|
1082 | * IPython/ultraTB.py (VerboseTB.text): Add another | |
1047 | linecache.checkcache() call to try to prevent inspect.py from |
|
1083 | linecache.checkcache() call to try to prevent inspect.py from | |
1048 | crashing under python 2.3. I think this fixes |
|
1084 | crashing under python 2.3. I think this fixes | |
1049 | http://www.scipy.net/roundup/ipython/issue17. |
|
1085 | http://www.scipy.net/roundup/ipython/issue17. | |
1050 |
|
1086 | |||
1051 | 2004-07-26 *** Released version 0.6.2 |
|
1087 | 2004-07-26 *** Released version 0.6.2 | |
1052 |
|
1088 | |||
1053 | 2004-07-26 Fernando Perez <fperez@colorado.edu> |
|
1089 | 2004-07-26 Fernando Perez <fperez@colorado.edu> | |
1054 |
|
1090 | |||
1055 | * IPython/Magic.py (Magic.magic_cd): Fix bug where 'cd -N' would |
|
1091 | * IPython/Magic.py (Magic.magic_cd): Fix bug where 'cd -N' would | |
1056 | fail for any number. |
|
1092 | fail for any number. | |
1057 | (Magic.magic_bookmark): Fix bug where 'bookmark -l' would fail for |
|
1093 | (Magic.magic_bookmark): Fix bug where 'bookmark -l' would fail for | |
1058 | empty bookmarks. |
|
1094 | empty bookmarks. | |
1059 |
|
1095 | |||
1060 | 2004-07-26 *** Released version 0.6.1 |
|
1096 | 2004-07-26 *** Released version 0.6.1 | |
1061 |
|
1097 | |||
1062 | 2004-07-26 Fernando Perez <fperez@colorado.edu> |
|
1098 | 2004-07-26 Fernando Perez <fperez@colorado.edu> | |
1063 |
|
1099 | |||
1064 | * ipython_win_post_install.py (run): Added pysh shortcut for Windows. |
|
1100 | * ipython_win_post_install.py (run): Added pysh shortcut for Windows. | |
1065 |
|
1101 | |||
1066 | * IPython/iplib.py (protect_filename): Applied Ville's patch for |
|
1102 | * IPython/iplib.py (protect_filename): Applied Ville's patch for | |
1067 | escaping '()[]{}' in filenames. |
|
1103 | escaping '()[]{}' in filenames. | |
1068 |
|
1104 | |||
1069 | * IPython/Magic.py (shlex_split): Fix handling of '*' and '?' for |
|
1105 | * IPython/Magic.py (shlex_split): Fix handling of '*' and '?' for | |
1070 | Python 2.2 users who lack a proper shlex.split. |
|
1106 | Python 2.2 users who lack a proper shlex.split. | |
1071 |
|
1107 | |||
1072 | 2004-07-19 Fernando Perez <fperez@colorado.edu> |
|
1108 | 2004-07-19 Fernando Perez <fperez@colorado.edu> | |
1073 |
|
1109 | |||
1074 | * IPython/iplib.py (InteractiveShell.init_readline): Add support |
|
1110 | * IPython/iplib.py (InteractiveShell.init_readline): Add support | |
1075 | for reading readline's init file. I follow the normal chain: |
|
1111 | for reading readline's init file. I follow the normal chain: | |
1076 | $INPUTRC is honored, otherwise ~/.inputrc is used. Thanks to a |
|
1112 | $INPUTRC is honored, otherwise ~/.inputrc is used. Thanks to a | |
1077 | report by Mike Heeter. This closes |
|
1113 | report by Mike Heeter. This closes | |
1078 | http://www.scipy.net/roundup/ipython/issue16. |
|
1114 | http://www.scipy.net/roundup/ipython/issue16. | |
1079 |
|
1115 | |||
1080 | 2004-07-18 Fernando Perez <fperez@colorado.edu> |
|
1116 | 2004-07-18 Fernando Perez <fperez@colorado.edu> | |
1081 |
|
1117 | |||
1082 | * IPython/iplib.py (__init__): Add better handling of '\' under |
|
1118 | * IPython/iplib.py (__init__): Add better handling of '\' under | |
1083 | Win32 for filenames. After a patch by Ville. |
|
1119 | Win32 for filenames. After a patch by Ville. | |
1084 |
|
1120 | |||
1085 | 2004-07-17 Fernando Perez <fperez@colorado.edu> |
|
1121 | 2004-07-17 Fernando Perez <fperez@colorado.edu> | |
1086 |
|
1122 | |||
1087 | * IPython/iplib.py (InteractiveShell._prefilter): fix bug where |
|
1123 | * IPython/iplib.py (InteractiveShell._prefilter): fix bug where | |
1088 | autocalling would be triggered for 'foo is bar' if foo is |
|
1124 | autocalling would be triggered for 'foo is bar' if foo is | |
1089 | callable. I also cleaned up the autocall detection code to use a |
|
1125 | callable. I also cleaned up the autocall detection code to use a | |
1090 | regexp, which is faster. Bug reported by Alexander Schmolck. |
|
1126 | regexp, which is faster. Bug reported by Alexander Schmolck. | |
1091 |
|
1127 | |||
1092 | * IPython/Magic.py (Magic.magic_pinfo): Fix bug where strings with |
|
1128 | * IPython/Magic.py (Magic.magic_pinfo): Fix bug where strings with | |
1093 | '?' in them would confuse the help system. Reported by Alex |
|
1129 | '?' in them would confuse the help system. Reported by Alex | |
1094 | Schmolck. |
|
1130 | Schmolck. | |
1095 |
|
1131 | |||
1096 | 2004-07-16 Fernando Perez <fperez@colorado.edu> |
|
1132 | 2004-07-16 Fernando Perez <fperez@colorado.edu> | |
1097 |
|
1133 | |||
1098 | * IPython/GnuplotInteractive.py (__all__): added plot2. |
|
1134 | * IPython/GnuplotInteractive.py (__all__): added plot2. | |
1099 |
|
1135 | |||
1100 | * IPython/Gnuplot2.py (Gnuplot.plot2): added new function for |
|
1136 | * IPython/Gnuplot2.py (Gnuplot.plot2): added new function for | |
1101 | plotting dictionaries, lists or tuples of 1d arrays. |
|
1137 | plotting dictionaries, lists or tuples of 1d arrays. | |
1102 |
|
1138 | |||
1103 | * IPython/Magic.py (Magic.magic_hist): small clenaups and |
|
1139 | * IPython/Magic.py (Magic.magic_hist): small clenaups and | |
1104 | optimizations. |
|
1140 | optimizations. | |
1105 |
|
1141 | |||
1106 | * IPython/iplib.py:Remove old Changelog info for cleanup. This is |
|
1142 | * IPython/iplib.py:Remove old Changelog info for cleanup. This is | |
1107 | the information which was there from Janko's original IPP code: |
|
1143 | the information which was there from Janko's original IPP code: | |
1108 |
|
1144 | |||
1109 | 03.05.99 20:53 porto.ifm.uni-kiel.de |
|
1145 | 03.05.99 20:53 porto.ifm.uni-kiel.de | |
1110 | --Started changelog. |
|
1146 | --Started changelog. | |
1111 | --make clear do what it say it does |
|
1147 | --make clear do what it say it does | |
1112 | --added pretty output of lines from inputcache |
|
1148 | --added pretty output of lines from inputcache | |
1113 | --Made Logger a mixin class, simplifies handling of switches |
|
1149 | --Made Logger a mixin class, simplifies handling of switches | |
1114 | --Added own completer class. .string<TAB> expands to last history |
|
1150 | --Added own completer class. .string<TAB> expands to last history | |
1115 | line which starts with string. The new expansion is also present |
|
1151 | line which starts with string. The new expansion is also present | |
1116 | with Ctrl-r from the readline library. But this shows, who this |
|
1152 | with Ctrl-r from the readline library. But this shows, who this | |
1117 | can be done for other cases. |
|
1153 | can be done for other cases. | |
1118 | --Added convention that all shell functions should accept a |
|
1154 | --Added convention that all shell functions should accept a | |
1119 | parameter_string This opens the door for different behaviour for |
|
1155 | parameter_string This opens the door for different behaviour for | |
1120 | each function. @cd is a good example of this. |
|
1156 | each function. @cd is a good example of this. | |
1121 |
|
1157 | |||
1122 | 04.05.99 12:12 porto.ifm.uni-kiel.de |
|
1158 | 04.05.99 12:12 porto.ifm.uni-kiel.de | |
1123 | --added logfile rotation |
|
1159 | --added logfile rotation | |
1124 | --added new mainloop method which freezes first the namespace |
|
1160 | --added new mainloop method which freezes first the namespace | |
1125 |
|
1161 | |||
1126 | 07.05.99 21:24 porto.ifm.uni-kiel.de |
|
1162 | 07.05.99 21:24 porto.ifm.uni-kiel.de | |
1127 | --added the docreader classes. Now there is a help system. |
|
1163 | --added the docreader classes. Now there is a help system. | |
1128 | -This is only a first try. Currently it's not easy to put new |
|
1164 | -This is only a first try. Currently it's not easy to put new | |
1129 | stuff in the indices. But this is the way to go. Info would be |
|
1165 | stuff in the indices. But this is the way to go. Info would be | |
1130 | better, but HTML is every where and not everybody has an info |
|
1166 | better, but HTML is every where and not everybody has an info | |
1131 | system installed and it's not so easy to change html-docs to info. |
|
1167 | system installed and it's not so easy to change html-docs to info. | |
1132 | --added global logfile option |
|
1168 | --added global logfile option | |
1133 | --there is now a hook for object inspection method pinfo needs to |
|
1169 | --there is now a hook for object inspection method pinfo needs to | |
1134 | be provided for this. Can be reached by two '??'. |
|
1170 | be provided for this. Can be reached by two '??'. | |
1135 |
|
1171 | |||
1136 | 08.05.99 20:51 porto.ifm.uni-kiel.de |
|
1172 | 08.05.99 20:51 porto.ifm.uni-kiel.de | |
1137 | --added a README |
|
1173 | --added a README | |
1138 | --bug in rc file. Something has changed so functions in the rc |
|
1174 | --bug in rc file. Something has changed so functions in the rc | |
1139 | file need to reference the shell and not self. Not clear if it's a |
|
1175 | file need to reference the shell and not self. Not clear if it's a | |
1140 | bug or feature. |
|
1176 | bug or feature. | |
1141 | --changed rc file for new behavior |
|
1177 | --changed rc file for new behavior | |
1142 |
|
1178 | |||
1143 | 2004-07-15 Fernando Perez <fperez@colorado.edu> |
|
1179 | 2004-07-15 Fernando Perez <fperez@colorado.edu> | |
1144 |
|
1180 | |||
1145 | * IPython/Logger.py (Logger.log): fixed recent bug where the input |
|
1181 | * IPython/Logger.py (Logger.log): fixed recent bug where the input | |
1146 | cache was falling out of sync in bizarre manners when multi-line |
|
1182 | cache was falling out of sync in bizarre manners when multi-line | |
1147 | input was present. Minor optimizations and cleanup. |
|
1183 | input was present. Minor optimizations and cleanup. | |
1148 |
|
1184 | |||
1149 | (Logger): Remove old Changelog info for cleanup. This is the |
|
1185 | (Logger): Remove old Changelog info for cleanup. This is the | |
1150 | information which was there from Janko's original code: |
|
1186 | information which was there from Janko's original code: | |
1151 |
|
1187 | |||
1152 | Changes to Logger: - made the default log filename a parameter |
|
1188 | Changes to Logger: - made the default log filename a parameter | |
1153 |
|
1189 | |||
1154 | - put a check for lines beginning with !@? in log(). Needed |
|
1190 | - put a check for lines beginning with !@? in log(). Needed | |
1155 | (even if the handlers properly log their lines) for mid-session |
|
1191 | (even if the handlers properly log their lines) for mid-session | |
1156 | logging activation to work properly. Without this, lines logged |
|
1192 | logging activation to work properly. Without this, lines logged | |
1157 | in mid session, which get read from the cache, would end up |
|
1193 | in mid session, which get read from the cache, would end up | |
1158 | 'bare' (with !@? in the open) in the log. Now they are caught |
|
1194 | 'bare' (with !@? in the open) in the log. Now they are caught | |
1159 | and prepended with a #. |
|
1195 | and prepended with a #. | |
1160 |
|
1196 | |||
1161 | * IPython/iplib.py (InteractiveShell.init_readline): added check |
|
1197 | * IPython/iplib.py (InteractiveShell.init_readline): added check | |
1162 | in case MagicCompleter fails to be defined, so we don't crash. |
|
1198 | in case MagicCompleter fails to be defined, so we don't crash. | |
1163 |
|
1199 | |||
1164 | 2004-07-13 Fernando Perez <fperez@colorado.edu> |
|
1200 | 2004-07-13 Fernando Perez <fperez@colorado.edu> | |
1165 |
|
1201 | |||
1166 | * IPython/Gnuplot2.py (Gnuplot.hardcopy): add automatic generation |
|
1202 | * IPython/Gnuplot2.py (Gnuplot.hardcopy): add automatic generation | |
1167 | of EPS if the requested filename ends in '.eps'. |
|
1203 | of EPS if the requested filename ends in '.eps'. | |
1168 |
|
1204 | |||
1169 | 2004-07-04 Fernando Perez <fperez@colorado.edu> |
|
1205 | 2004-07-04 Fernando Perez <fperez@colorado.edu> | |
1170 |
|
1206 | |||
1171 | * IPython/iplib.py (InteractiveShell.handle_shell_escape): Fix |
|
1207 | * IPython/iplib.py (InteractiveShell.handle_shell_escape): Fix | |
1172 | escaping of quotes when calling the shell. |
|
1208 | escaping of quotes when calling the shell. | |
1173 |
|
1209 | |||
1174 | 2004-07-02 Fernando Perez <fperez@colorado.edu> |
|
1210 | 2004-07-02 Fernando Perez <fperez@colorado.edu> | |
1175 |
|
1211 | |||
1176 | * IPython/Prompts.py (CachedOutput.update): Fix problem with |
|
1212 | * IPython/Prompts.py (CachedOutput.update): Fix problem with | |
1177 | gettext not working because we were clobbering '_'. Fixes |
|
1213 | gettext not working because we were clobbering '_'. Fixes | |
1178 | http://www.scipy.net/roundup/ipython/issue6. |
|
1214 | http://www.scipy.net/roundup/ipython/issue6. | |
1179 |
|
1215 | |||
1180 | 2004-07-01 Fernando Perez <fperez@colorado.edu> |
|
1216 | 2004-07-01 Fernando Perez <fperez@colorado.edu> | |
1181 |
|
1217 | |||
1182 | * IPython/Magic.py (Magic.magic_cd): integrated bookmark handling |
|
1218 | * IPython/Magic.py (Magic.magic_cd): integrated bookmark handling | |
1183 | into @cd. Patch by Ville. |
|
1219 | into @cd. Patch by Ville. | |
1184 |
|
1220 | |||
1185 | * IPython/iplib.py (InteractiveShell.post_config_initialization): |
|
1221 | * IPython/iplib.py (InteractiveShell.post_config_initialization): | |
1186 | new function to store things after ipmaker runs. Patch by Ville. |
|
1222 | new function to store things after ipmaker runs. Patch by Ville. | |
1187 | Eventually this will go away once ipmaker is removed and the class |
|
1223 | Eventually this will go away once ipmaker is removed and the class | |
1188 | gets cleaned up, but for now it's ok. Key functionality here is |
|
1224 | gets cleaned up, but for now it's ok. Key functionality here is | |
1189 | the addition of the persistent storage mechanism, a dict for |
|
1225 | the addition of the persistent storage mechanism, a dict for | |
1190 | keeping data across sessions (for now just bookmarks, but more can |
|
1226 | keeping data across sessions (for now just bookmarks, but more can | |
1191 | be implemented later). |
|
1227 | be implemented later). | |
1192 |
|
1228 | |||
1193 | * IPython/Magic.py (Magic.magic_bookmark): New bookmark system, |
|
1229 | * IPython/Magic.py (Magic.magic_bookmark): New bookmark system, | |
1194 | persistent across sections. Patch by Ville, I modified it |
|
1230 | persistent across sections. Patch by Ville, I modified it | |
1195 | soemwhat to allow bookmarking arbitrary dirs other than CWD. Also |
|
1231 | soemwhat to allow bookmarking arbitrary dirs other than CWD. Also | |
1196 | added a '-l' option to list all bookmarks. |
|
1232 | added a '-l' option to list all bookmarks. | |
1197 |
|
1233 | |||
1198 | * IPython/iplib.py (InteractiveShell.atexit_operations): new |
|
1234 | * IPython/iplib.py (InteractiveShell.atexit_operations): new | |
1199 | center for cleanup. Registered with atexit.register(). I moved |
|
1235 | center for cleanup. Registered with atexit.register(). I moved | |
1200 | here the old exit_cleanup(). After a patch by Ville. |
|
1236 | here the old exit_cleanup(). After a patch by Ville. | |
1201 |
|
1237 | |||
1202 | * IPython/Magic.py (get_py_filename): added '~' to the accepted |
|
1238 | * IPython/Magic.py (get_py_filename): added '~' to the accepted | |
1203 | characters in the hacked shlex_split for python 2.2. |
|
1239 | characters in the hacked shlex_split for python 2.2. | |
1204 |
|
1240 | |||
1205 | * IPython/iplib.py (file_matches): more fixes to filenames with |
|
1241 | * IPython/iplib.py (file_matches): more fixes to filenames with | |
1206 | whitespace in them. It's not perfect, but limitations in python's |
|
1242 | whitespace in them. It's not perfect, but limitations in python's | |
1207 | readline make it impossible to go further. |
|
1243 | readline make it impossible to go further. | |
1208 |
|
1244 | |||
1209 | 2004-06-29 Fernando Perez <fperez@colorado.edu> |
|
1245 | 2004-06-29 Fernando Perez <fperez@colorado.edu> | |
1210 |
|
1246 | |||
1211 | * IPython/iplib.py (file_matches): escape whitespace correctly in |
|
1247 | * IPython/iplib.py (file_matches): escape whitespace correctly in | |
1212 | filename completions. Bug reported by Ville. |
|
1248 | filename completions. Bug reported by Ville. | |
1213 |
|
1249 | |||
1214 | 2004-06-28 Fernando Perez <fperez@colorado.edu> |
|
1250 | 2004-06-28 Fernando Perez <fperez@colorado.edu> | |
1215 |
|
1251 | |||
1216 | * IPython/ipmaker.py (__call__): Added per-profile histories. Now |
|
1252 | * IPython/ipmaker.py (__call__): Added per-profile histories. Now | |
1217 | the history file will be called 'history-PROFNAME' (or just |
|
1253 | the history file will be called 'history-PROFNAME' (or just | |
1218 | 'history' if no profile is loaded). I was getting annoyed at |
|
1254 | 'history' if no profile is loaded). I was getting annoyed at | |
1219 | getting my Numerical work history clobbered by pysh sessions. |
|
1255 | getting my Numerical work history clobbered by pysh sessions. | |
1220 |
|
1256 | |||
1221 | * IPython/iplib.py (InteractiveShell.__init__): Internal |
|
1257 | * IPython/iplib.py (InteractiveShell.__init__): Internal | |
1222 | getoutputerror() function so that we can honor the system_verbose |
|
1258 | getoutputerror() function so that we can honor the system_verbose | |
1223 | flag for _all_ system calls. I also added escaping of # |
|
1259 | flag for _all_ system calls. I also added escaping of # | |
1224 | characters here to avoid confusing Itpl. |
|
1260 | characters here to avoid confusing Itpl. | |
1225 |
|
1261 | |||
1226 | * IPython/Magic.py (shlex_split): removed call to shell in |
|
1262 | * IPython/Magic.py (shlex_split): removed call to shell in | |
1227 | parse_options and replaced it with shlex.split(). The annoying |
|
1263 | parse_options and replaced it with shlex.split(). The annoying | |
1228 | part was that in Python 2.2, shlex.split() doesn't exist, so I had |
|
1264 | part was that in Python 2.2, shlex.split() doesn't exist, so I had | |
1229 | to backport it from 2.3, with several frail hacks (the shlex |
|
1265 | to backport it from 2.3, with several frail hacks (the shlex | |
1230 | module is rather limited in 2.2). Thanks to a suggestion by Ville |
|
1266 | module is rather limited in 2.2). Thanks to a suggestion by Ville | |
1231 | Vainio <vivainio@kolumbus.fi>. For Python 2.3 there should be no |
|
1267 | Vainio <vivainio@kolumbus.fi>. For Python 2.3 there should be no | |
1232 | problem. |
|
1268 | problem. | |
1233 |
|
1269 | |||
1234 | (Magic.magic_system_verbose): new toggle to print the actual |
|
1270 | (Magic.magic_system_verbose): new toggle to print the actual | |
1235 | system calls made by ipython. Mainly for debugging purposes. |
|
1271 | system calls made by ipython. Mainly for debugging purposes. | |
1236 |
|
1272 | |||
1237 | * IPython/GnuplotRuntime.py (gnu_out): fix bug for cygwin, which |
|
1273 | * IPython/GnuplotRuntime.py (gnu_out): fix bug for cygwin, which | |
1238 | doesn't support persistence. Reported (and fix suggested) by |
|
1274 | doesn't support persistence. Reported (and fix suggested) by | |
1239 | Travis Caldwell <travis_caldwell2000@yahoo.com>. |
|
1275 | Travis Caldwell <travis_caldwell2000@yahoo.com>. | |
1240 |
|
1276 | |||
1241 | 2004-06-26 Fernando Perez <fperez@colorado.edu> |
|
1277 | 2004-06-26 Fernando Perez <fperez@colorado.edu> | |
1242 |
|
1278 | |||
1243 | * IPython/Logger.py (Logger.log): fix to handle correctly empty |
|
1279 | * IPython/Logger.py (Logger.log): fix to handle correctly empty | |
1244 | continue prompts. |
|
1280 | continue prompts. | |
1245 |
|
1281 | |||
1246 | * IPython/Extensions/InterpreterExec.py (pysh): moved the pysh() |
|
1282 | * IPython/Extensions/InterpreterExec.py (pysh): moved the pysh() | |
1247 | function (basically a big docstring) and a few more things here to |
|
1283 | function (basically a big docstring) and a few more things here to | |
1248 | speedup startup. pysh.py is now very lightweight. We want because |
|
1284 | speedup startup. pysh.py is now very lightweight. We want because | |
1249 | it gets execfile'd, while InterpreterExec gets imported, so |
|
1285 | it gets execfile'd, while InterpreterExec gets imported, so | |
1250 | byte-compilation saves time. |
|
1286 | byte-compilation saves time. | |
1251 |
|
1287 | |||
1252 | 2004-06-25 Fernando Perez <fperez@colorado.edu> |
|
1288 | 2004-06-25 Fernando Perez <fperez@colorado.edu> | |
1253 |
|
1289 | |||
1254 | * IPython/Magic.py (Magic.magic_cd): Fixed to restore usage of 'cd |
|
1290 | * IPython/Magic.py (Magic.magic_cd): Fixed to restore usage of 'cd | |
1255 | -NUM', which was recently broken. |
|
1291 | -NUM', which was recently broken. | |
1256 |
|
1292 | |||
1257 | * IPython/iplib.py (InteractiveShell.handle_shell_escape): allow ! |
|
1293 | * IPython/iplib.py (InteractiveShell.handle_shell_escape): allow ! | |
1258 | in multi-line input (but not !!, which doesn't make sense there). |
|
1294 | in multi-line input (but not !!, which doesn't make sense there). | |
1259 |
|
1295 | |||
1260 | * IPython/UserConfig/ipythonrc: made autoindent on by default. |
|
1296 | * IPython/UserConfig/ipythonrc: made autoindent on by default. | |
1261 | It's just too useful, and people can turn it off in the less |
|
1297 | It's just too useful, and people can turn it off in the less | |
1262 | common cases where it's a problem. |
|
1298 | common cases where it's a problem. | |
1263 |
|
1299 | |||
1264 | 2004-06-24 Fernando Perez <fperez@colorado.edu> |
|
1300 | 2004-06-24 Fernando Perez <fperez@colorado.edu> | |
1265 |
|
1301 | |||
1266 | * IPython/iplib.py (InteractiveShell._prefilter): big change - |
|
1302 | * IPython/iplib.py (InteractiveShell._prefilter): big change - | |
1267 | special syntaxes (like alias calling) is now allied in multi-line |
|
1303 | special syntaxes (like alias calling) is now allied in multi-line | |
1268 | input. This is still _very_ experimental, but it's necessary for |
|
1304 | input. This is still _very_ experimental, but it's necessary for | |
1269 | efficient shell usage combining python looping syntax with system |
|
1305 | efficient shell usage combining python looping syntax with system | |
1270 | calls. For now it's restricted to aliases, I don't think it |
|
1306 | calls. For now it's restricted to aliases, I don't think it | |
1271 | really even makes sense to have this for magics. |
|
1307 | really even makes sense to have this for magics. | |
1272 |
|
1308 | |||
1273 | 2004-06-23 Fernando Perez <fperez@colorado.edu> |
|
1309 | 2004-06-23 Fernando Perez <fperez@colorado.edu> | |
1274 |
|
1310 | |||
1275 | * IPython/Extensions/InterpreterExec.py (prefilter_shell): Added |
|
1311 | * IPython/Extensions/InterpreterExec.py (prefilter_shell): Added | |
1276 | $var=cmd <=> @sc var=cmd and $$var=cmd <=> @sc -l var=cmd. |
|
1312 | $var=cmd <=> @sc var=cmd and $$var=cmd <=> @sc -l var=cmd. | |
1277 |
|
1313 | |||
1278 | * IPython/Magic.py (Magic.magic_rehashx): modified to handle |
|
1314 | * IPython/Magic.py (Magic.magic_rehashx): modified to handle | |
1279 | extensions under Windows (after code sent by Gary Bishop). The |
|
1315 | extensions under Windows (after code sent by Gary Bishop). The | |
1280 | extensions considered 'executable' are stored in IPython's rc |
|
1316 | extensions considered 'executable' are stored in IPython's rc | |
1281 | structure as win_exec_ext. |
|
1317 | structure as win_exec_ext. | |
1282 |
|
1318 | |||
1283 | * IPython/genutils.py (shell): new function, like system() but |
|
1319 | * IPython/genutils.py (shell): new function, like system() but | |
1284 | without return value. Very useful for interactive shell work. |
|
1320 | without return value. Very useful for interactive shell work. | |
1285 |
|
1321 | |||
1286 | * IPython/Magic.py (Magic.magic_unalias): New @unalias function to |
|
1322 | * IPython/Magic.py (Magic.magic_unalias): New @unalias function to | |
1287 | delete aliases. |
|
1323 | delete aliases. | |
1288 |
|
1324 | |||
1289 | * IPython/iplib.py (InteractiveShell.alias_table_update): make |
|
1325 | * IPython/iplib.py (InteractiveShell.alias_table_update): make | |
1290 | sure that the alias table doesn't contain python keywords. |
|
1326 | sure that the alias table doesn't contain python keywords. | |
1291 |
|
1327 | |||
1292 | 2004-06-21 Fernando Perez <fperez@colorado.edu> |
|
1328 | 2004-06-21 Fernando Perez <fperez@colorado.edu> | |
1293 |
|
1329 | |||
1294 | * IPython/Magic.py (Magic.magic_rehash): Fix crash when |
|
1330 | * IPython/Magic.py (Magic.magic_rehash): Fix crash when | |
1295 | non-existent items are found in $PATH. Reported by Thorsten. |
|
1331 | non-existent items are found in $PATH. Reported by Thorsten. | |
1296 |
|
1332 | |||
1297 | 2004-06-20 Fernando Perez <fperez@colorado.edu> |
|
1333 | 2004-06-20 Fernando Perez <fperez@colorado.edu> | |
1298 |
|
1334 | |||
1299 | * IPython/iplib.py (complete): modified the completer so that the |
|
1335 | * IPython/iplib.py (complete): modified the completer so that the | |
1300 | order of priorities can be easily changed at runtime. |
|
1336 | order of priorities can be easily changed at runtime. | |
1301 |
|
1337 | |||
1302 | * IPython/Extensions/InterpreterExec.py (prefilter_shell): |
|
1338 | * IPython/Extensions/InterpreterExec.py (prefilter_shell): | |
1303 | Modified to auto-execute all lines beginning with '~', '/' or '.'. |
|
1339 | Modified to auto-execute all lines beginning with '~', '/' or '.'. | |
1304 |
|
1340 | |||
1305 | * IPython/Magic.py (Magic.magic_sx): modified @sc and @sx to |
|
1341 | * IPython/Magic.py (Magic.magic_sx): modified @sc and @sx to | |
1306 | expand Python variables prepended with $ in all system calls. The |
|
1342 | expand Python variables prepended with $ in all system calls. The | |
1307 | same was done to InteractiveShell.handle_shell_escape. Now all |
|
1343 | same was done to InteractiveShell.handle_shell_escape. Now all | |
1308 | system access mechanisms (!, !!, @sc, @sx and aliases) allow the |
|
1344 | system access mechanisms (!, !!, @sc, @sx and aliases) allow the | |
1309 | expansion of python variables and expressions according to the |
|
1345 | expansion of python variables and expressions according to the | |
1310 | syntax of PEP-215 - http://www.python.org/peps/pep-0215.html. |
|
1346 | syntax of PEP-215 - http://www.python.org/peps/pep-0215.html. | |
1311 |
|
1347 | |||
1312 | Though PEP-215 has been rejected, a similar (but simpler) one |
|
1348 | Though PEP-215 has been rejected, a similar (but simpler) one | |
1313 | seems like it will go into Python 2.4, PEP-292 - |
|
1349 | seems like it will go into Python 2.4, PEP-292 - | |
1314 | http://www.python.org/peps/pep-0292.html. |
|
1350 | http://www.python.org/peps/pep-0292.html. | |
1315 |
|
1351 | |||
1316 | I'll keep the full syntax of PEP-215, since IPython has since the |
|
1352 | I'll keep the full syntax of PEP-215, since IPython has since the | |
1317 | start used Ka-Ping Yee's reference implementation discussed there |
|
1353 | start used Ka-Ping Yee's reference implementation discussed there | |
1318 | (Itpl), and I actually like the powerful semantics it offers. |
|
1354 | (Itpl), and I actually like the powerful semantics it offers. | |
1319 |
|
1355 | |||
1320 | In order to access normal shell variables, the $ has to be escaped |
|
1356 | In order to access normal shell variables, the $ has to be escaped | |
1321 | via an extra $. For example: |
|
1357 | via an extra $. For example: | |
1322 |
|
1358 | |||
1323 | In [7]: PATH='a python variable' |
|
1359 | In [7]: PATH='a python variable' | |
1324 |
|
1360 | |||
1325 | In [8]: !echo $PATH |
|
1361 | In [8]: !echo $PATH | |
1326 | a python variable |
|
1362 | a python variable | |
1327 |
|
1363 | |||
1328 | In [9]: !echo $$PATH |
|
1364 | In [9]: !echo $$PATH | |
1329 | /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:... |
|
1365 | /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:... | |
1330 |
|
1366 | |||
1331 | (Magic.parse_options): escape $ so the shell doesn't evaluate |
|
1367 | (Magic.parse_options): escape $ so the shell doesn't evaluate | |
1332 | things prematurely. |
|
1368 | things prematurely. | |
1333 |
|
1369 | |||
1334 | * IPython/iplib.py (InteractiveShell.call_alias): added the |
|
1370 | * IPython/iplib.py (InteractiveShell.call_alias): added the | |
1335 | ability for aliases to expand python variables via $. |
|
1371 | ability for aliases to expand python variables via $. | |
1336 |
|
1372 | |||
1337 | * IPython/Magic.py (Magic.magic_rehash): based on the new alias |
|
1373 | * IPython/Magic.py (Magic.magic_rehash): based on the new alias | |
1338 | system, now there's a @rehash/@rehashx pair of magics. These work |
|
1374 | system, now there's a @rehash/@rehashx pair of magics. These work | |
1339 | like the csh rehash command, and can be invoked at any time. They |
|
1375 | like the csh rehash command, and can be invoked at any time. They | |
1340 | build a table of aliases to everything in the user's $PATH |
|
1376 | build a table of aliases to everything in the user's $PATH | |
1341 | (@rehash uses everything, @rehashx is slower but only adds |
|
1377 | (@rehash uses everything, @rehashx is slower but only adds | |
1342 | executable files). With this, the pysh.py-based shell profile can |
|
1378 | executable files). With this, the pysh.py-based shell profile can | |
1343 | now simply call rehash upon startup, and full access to all |
|
1379 | now simply call rehash upon startup, and full access to all | |
1344 | programs in the user's path is obtained. |
|
1380 | programs in the user's path is obtained. | |
1345 |
|
1381 | |||
1346 | * IPython/iplib.py (InteractiveShell.call_alias): The new alias |
|
1382 | * IPython/iplib.py (InteractiveShell.call_alias): The new alias | |
1347 | functionality is now fully in place. I removed the old dynamic |
|
1383 | functionality is now fully in place. I removed the old dynamic | |
1348 | code generation based approach, in favor of a much lighter one |
|
1384 | code generation based approach, in favor of a much lighter one | |
1349 | based on a simple dict. The advantage is that this allows me to |
|
1385 | based on a simple dict. The advantage is that this allows me to | |
1350 | now have thousands of aliases with negligible cost (unthinkable |
|
1386 | now have thousands of aliases with negligible cost (unthinkable | |
1351 | with the old system). |
|
1387 | with the old system). | |
1352 |
|
1388 | |||
1353 | 2004-06-19 Fernando Perez <fperez@colorado.edu> |
|
1389 | 2004-06-19 Fernando Perez <fperez@colorado.edu> | |
1354 |
|
1390 | |||
1355 | * IPython/iplib.py (__init__): extended MagicCompleter class to |
|
1391 | * IPython/iplib.py (__init__): extended MagicCompleter class to | |
1356 | also complete (last in priority) on user aliases. |
|
1392 | also complete (last in priority) on user aliases. | |
1357 |
|
1393 | |||
1358 | * IPython/Itpl.py (Itpl.__str__): fixed order of globals/locals in |
|
1394 | * IPython/Itpl.py (Itpl.__str__): fixed order of globals/locals in | |
1359 | call to eval. |
|
1395 | call to eval. | |
1360 | (ItplNS.__init__): Added a new class which functions like Itpl, |
|
1396 | (ItplNS.__init__): Added a new class which functions like Itpl, | |
1361 | but allows configuring the namespace for the evaluation to occur |
|
1397 | but allows configuring the namespace for the evaluation to occur | |
1362 | in. |
|
1398 | in. | |
1363 |
|
1399 | |||
1364 | 2004-06-18 Fernando Perez <fperez@colorado.edu> |
|
1400 | 2004-06-18 Fernando Perez <fperez@colorado.edu> | |
1365 |
|
1401 | |||
1366 | * IPython/iplib.py (InteractiveShell.runcode): modify to print a |
|
1402 | * IPython/iplib.py (InteractiveShell.runcode): modify to print a | |
1367 | better message when 'exit' or 'quit' are typed (a common newbie |
|
1403 | better message when 'exit' or 'quit' are typed (a common newbie | |
1368 | confusion). |
|
1404 | confusion). | |
1369 |
|
1405 | |||
1370 | * IPython/Magic.py (Magic.magic_colors): Added the runtime color |
|
1406 | * IPython/Magic.py (Magic.magic_colors): Added the runtime color | |
1371 | check for Windows users. |
|
1407 | check for Windows users. | |
1372 |
|
1408 | |||
1373 | * IPython/iplib.py (InteractiveShell.user_setup): removed |
|
1409 | * IPython/iplib.py (InteractiveShell.user_setup): removed | |
1374 | disabling of colors for Windows. I'll test at runtime and issue a |
|
1410 | disabling of colors for Windows. I'll test at runtime and issue a | |
1375 | warning if Gary's readline isn't found, as to nudge users to |
|
1411 | warning if Gary's readline isn't found, as to nudge users to | |
1376 | download it. |
|
1412 | download it. | |
1377 |
|
1413 | |||
1378 | 2004-06-16 Fernando Perez <fperez@colorado.edu> |
|
1414 | 2004-06-16 Fernando Perez <fperez@colorado.edu> | |
1379 |
|
1415 | |||
1380 | * IPython/genutils.py (Stream.__init__): changed to print errors |
|
1416 | * IPython/genutils.py (Stream.__init__): changed to print errors | |
1381 | to sys.stderr. I had a circular dependency here. Now it's |
|
1417 | to sys.stderr. I had a circular dependency here. Now it's | |
1382 | possible to run ipython as IDLE's shell (consider this pre-alpha, |
|
1418 | possible to run ipython as IDLE's shell (consider this pre-alpha, | |
1383 | since true stdout things end up in the starting terminal instead |
|
1419 | since true stdout things end up in the starting terminal instead | |
1384 | of IDLE's out). |
|
1420 | of IDLE's out). | |
1385 |
|
1421 | |||
1386 | * IPython/Prompts.py (Prompt2.set_colors): prevent crashes for |
|
1422 | * IPython/Prompts.py (Prompt2.set_colors): prevent crashes for | |
1387 | users who haven't # updated their prompt_in2 definitions. Remove |
|
1423 | users who haven't # updated their prompt_in2 definitions. Remove | |
1388 | eventually. |
|
1424 | eventually. | |
1389 | (multiple_replace): added credit to original ASPN recipe. |
|
1425 | (multiple_replace): added credit to original ASPN recipe. | |
1390 |
|
1426 | |||
1391 | 2004-06-15 Fernando Perez <fperez@colorado.edu> |
|
1427 | 2004-06-15 Fernando Perez <fperez@colorado.edu> | |
1392 |
|
1428 | |||
1393 | * IPython/iplib.py (InteractiveShell.__init__): add 'cp' to the |
|
1429 | * IPython/iplib.py (InteractiveShell.__init__): add 'cp' to the | |
1394 | list of auto-defined aliases. |
|
1430 | list of auto-defined aliases. | |
1395 |
|
1431 | |||
1396 | 2004-06-13 Fernando Perez <fperez@colorado.edu> |
|
1432 | 2004-06-13 Fernando Perez <fperez@colorado.edu> | |
1397 |
|
1433 | |||
1398 | * setup.py (scriptfiles): Don't trigger win_post_install unless an |
|
1434 | * setup.py (scriptfiles): Don't trigger win_post_install unless an | |
1399 | install was really requested (so setup.py can be used for other |
|
1435 | install was really requested (so setup.py can be used for other | |
1400 | things under Windows). |
|
1436 | things under Windows). | |
1401 |
|
1437 | |||
1402 | 2004-06-10 Fernando Perez <fperez@colorado.edu> |
|
1438 | 2004-06-10 Fernando Perez <fperez@colorado.edu> | |
1403 |
|
1439 | |||
1404 | * IPython/Logger.py (Logger.create_log): Manually remove any old |
|
1440 | * IPython/Logger.py (Logger.create_log): Manually remove any old | |
1405 | backup, since os.remove may fail under Windows. Fixes bug |
|
1441 | backup, since os.remove may fail under Windows. Fixes bug | |
1406 | reported by Thorsten. |
|
1442 | reported by Thorsten. | |
1407 |
|
1443 | |||
1408 | 2004-06-09 Fernando Perez <fperez@colorado.edu> |
|
1444 | 2004-06-09 Fernando Perez <fperez@colorado.edu> | |
1409 |
|
1445 | |||
1410 | * examples/example-embed.py: fixed all references to %n (replaced |
|
1446 | * examples/example-embed.py: fixed all references to %n (replaced | |
1411 | with \\# for ps1/out prompts and with \\D for ps2 prompts). Done |
|
1447 | with \\# for ps1/out prompts and with \\D for ps2 prompts). Done | |
1412 | for all examples and the manual as well. |
|
1448 | for all examples and the manual as well. | |
1413 |
|
1449 | |||
1414 | 2004-06-08 Fernando Perez <fperez@colorado.edu> |
|
1450 | 2004-06-08 Fernando Perez <fperez@colorado.edu> | |
1415 |
|
1451 | |||
1416 | * IPython/Prompts.py (Prompt2.set_p_str): fixed all prompt |
|
1452 | * IPython/Prompts.py (Prompt2.set_p_str): fixed all prompt | |
1417 | alignment and color management. All 3 prompt subsystems now |
|
1453 | alignment and color management. All 3 prompt subsystems now | |
1418 | inherit from BasePrompt. |
|
1454 | inherit from BasePrompt. | |
1419 |
|
1455 | |||
1420 | * tools/release: updates for windows installer build and tag rpms |
|
1456 | * tools/release: updates for windows installer build and tag rpms | |
1421 | with python version (since paths are fixed). |
|
1457 | with python version (since paths are fixed). | |
1422 |
|
1458 | |||
1423 | * IPython/UserConfig/ipythonrc: modified to use \# instead of %n, |
|
1459 | * IPython/UserConfig/ipythonrc: modified to use \# instead of %n, | |
1424 | which will become eventually obsolete. Also fixed the default |
|
1460 | which will become eventually obsolete. Also fixed the default | |
1425 | prompt_in2 to use \D, so at least new users start with the correct |
|
1461 | prompt_in2 to use \D, so at least new users start with the correct | |
1426 | defaults. |
|
1462 | defaults. | |
1427 | WARNING: Users with existing ipythonrc files will need to apply |
|
1463 | WARNING: Users with existing ipythonrc files will need to apply | |
1428 | this fix manually! |
|
1464 | this fix manually! | |
1429 |
|
1465 | |||
1430 | * setup.py: make windows installer (.exe). This is finally the |
|
1466 | * setup.py: make windows installer (.exe). This is finally the | |
1431 | integration of an old patch by Cory Dodt <dodt-AT-fcoe.k12.ca.us>, |
|
1467 | integration of an old patch by Cory Dodt <dodt-AT-fcoe.k12.ca.us>, | |
1432 | which I hadn't included because it required Python 2.3 (or recent |
|
1468 | which I hadn't included because it required Python 2.3 (or recent | |
1433 | distutils). |
|
1469 | distutils). | |
1434 |
|
1470 | |||
1435 | * IPython/usage.py (__doc__): update docs (and manpage) to reflect |
|
1471 | * IPython/usage.py (__doc__): update docs (and manpage) to reflect | |
1436 | usage of new '\D' escape. |
|
1472 | usage of new '\D' escape. | |
1437 |
|
1473 | |||
1438 | * IPython/Prompts.py (ROOT_SYMBOL): Small fix for Windows (which |
|
1474 | * IPython/Prompts.py (ROOT_SYMBOL): Small fix for Windows (which | |
1439 | lacks os.getuid()) |
|
1475 | lacks os.getuid()) | |
1440 | (CachedOutput.set_colors): Added the ability to turn coloring |
|
1476 | (CachedOutput.set_colors): Added the ability to turn coloring | |
1441 | on/off with @colors even for manually defined prompt colors. It |
|
1477 | on/off with @colors even for manually defined prompt colors. It | |
1442 | uses a nasty global, but it works safely and via the generic color |
|
1478 | uses a nasty global, but it works safely and via the generic color | |
1443 | handling mechanism. |
|
1479 | handling mechanism. | |
1444 | (Prompt2.__init__): Introduced new escape '\D' for continuation |
|
1480 | (Prompt2.__init__): Introduced new escape '\D' for continuation | |
1445 | prompts. It represents the counter ('\#') as dots. |
|
1481 | prompts. It represents the counter ('\#') as dots. | |
1446 | *** NOTE *** THIS IS A BACKWARDS-INCOMPATIBLE CHANGE. Users will |
|
1482 | *** NOTE *** THIS IS A BACKWARDS-INCOMPATIBLE CHANGE. Users will | |
1447 | need to update their ipythonrc files and replace '%n' with '\D' in |
|
1483 | need to update their ipythonrc files and replace '%n' with '\D' in | |
1448 | their prompt_in2 settings everywhere. Sorry, but there's |
|
1484 | their prompt_in2 settings everywhere. Sorry, but there's | |
1449 | otherwise no clean way to get all prompts to properly align. The |
|
1485 | otherwise no clean way to get all prompts to properly align. The | |
1450 | ipythonrc shipped with IPython has been updated. |
|
1486 | ipythonrc shipped with IPython has been updated. | |
1451 |
|
1487 | |||
1452 | 2004-06-07 Fernando Perez <fperez@colorado.edu> |
|
1488 | 2004-06-07 Fernando Perez <fperez@colorado.edu> | |
1453 |
|
1489 | |||
1454 | * setup.py (isfile): Pass local_icons option to latex2html, so the |
|
1490 | * setup.py (isfile): Pass local_icons option to latex2html, so the | |
1455 | resulting HTML file is self-contained. Thanks to |
|
1491 | resulting HTML file is self-contained. Thanks to | |
1456 | dryice-AT-liu.com.cn for the tip. |
|
1492 | dryice-AT-liu.com.cn for the tip. | |
1457 |
|
1493 | |||
1458 | * pysh.py: I created a new profile 'shell', which implements a |
|
1494 | * pysh.py: I created a new profile 'shell', which implements a | |
1459 | _rudimentary_ IPython-based shell. This is in NO WAY a realy |
|
1495 | _rudimentary_ IPython-based shell. This is in NO WAY a realy | |
1460 | system shell, nor will it become one anytime soon. It's mainly |
|
1496 | system shell, nor will it become one anytime soon. It's mainly | |
1461 | meant to illustrate the use of the new flexible bash-like prompts. |
|
1497 | meant to illustrate the use of the new flexible bash-like prompts. | |
1462 | I guess it could be used by hardy souls for true shell management, |
|
1498 | I guess it could be used by hardy souls for true shell management, | |
1463 | but it's no tcsh/bash... pysh.py is loaded by the 'shell' |
|
1499 | but it's no tcsh/bash... pysh.py is loaded by the 'shell' | |
1464 | profile. This uses the InterpreterExec extension provided by |
|
1500 | profile. This uses the InterpreterExec extension provided by | |
1465 | W.J. van der Laan <gnufnork-AT-hetdigitalegat.nl> |
|
1501 | W.J. van der Laan <gnufnork-AT-hetdigitalegat.nl> | |
1466 |
|
1502 | |||
1467 | * IPython/Prompts.py (PromptOut.__str__): now it will correctly |
|
1503 | * IPython/Prompts.py (PromptOut.__str__): now it will correctly | |
1468 | auto-align itself with the length of the previous input prompt |
|
1504 | auto-align itself with the length of the previous input prompt | |
1469 | (taking into account the invisible color escapes). |
|
1505 | (taking into account the invisible color escapes). | |
1470 | (CachedOutput.__init__): Large restructuring of this class. Now |
|
1506 | (CachedOutput.__init__): Large restructuring of this class. Now | |
1471 | all three prompts (primary1, primary2, output) are proper objects, |
|
1507 | all three prompts (primary1, primary2, output) are proper objects, | |
1472 | managed by the 'parent' CachedOutput class. The code is still a |
|
1508 | managed by the 'parent' CachedOutput class. The code is still a | |
1473 | bit hackish (all prompts share state via a pointer to the cache), |
|
1509 | bit hackish (all prompts share state via a pointer to the cache), | |
1474 | but it's overall far cleaner than before. |
|
1510 | but it's overall far cleaner than before. | |
1475 |
|
1511 | |||
1476 | * IPython/genutils.py (getoutputerror): modified to add verbose, |
|
1512 | * IPython/genutils.py (getoutputerror): modified to add verbose, | |
1477 | debug and header options. This makes the interface of all getout* |
|
1513 | debug and header options. This makes the interface of all getout* | |
1478 | functions uniform. |
|
1514 | functions uniform. | |
1479 | (SystemExec.getoutputerror): added getoutputerror to SystemExec. |
|
1515 | (SystemExec.getoutputerror): added getoutputerror to SystemExec. | |
1480 |
|
1516 | |||
1481 | * IPython/Magic.py (Magic.default_option): added a function to |
|
1517 | * IPython/Magic.py (Magic.default_option): added a function to | |
1482 | allow registering default options for any magic command. This |
|
1518 | allow registering default options for any magic command. This | |
1483 | makes it easy to have profiles which customize the magics globally |
|
1519 | makes it easy to have profiles which customize the magics globally | |
1484 | for a certain use. The values set through this function are |
|
1520 | for a certain use. The values set through this function are | |
1485 | picked up by the parse_options() method, which all magics should |
|
1521 | picked up by the parse_options() method, which all magics should | |
1486 | use to parse their options. |
|
1522 | use to parse their options. | |
1487 |
|
1523 | |||
1488 | * IPython/genutils.py (warn): modified the warnings framework to |
|
1524 | * IPython/genutils.py (warn): modified the warnings framework to | |
1489 | use the Term I/O class. I'm trying to slowly unify all of |
|
1525 | use the Term I/O class. I'm trying to slowly unify all of | |
1490 | IPython's I/O operations to pass through Term. |
|
1526 | IPython's I/O operations to pass through Term. | |
1491 |
|
1527 | |||
1492 | * IPython/Prompts.py (Prompt2._str_other): Added functionality in |
|
1528 | * IPython/Prompts.py (Prompt2._str_other): Added functionality in | |
1493 | the secondary prompt to correctly match the length of the primary |
|
1529 | the secondary prompt to correctly match the length of the primary | |
1494 | one for any prompt. Now multi-line code will properly line up |
|
1530 | one for any prompt. Now multi-line code will properly line up | |
1495 | even for path dependent prompts, such as the new ones available |
|
1531 | even for path dependent prompts, such as the new ones available | |
1496 | via the prompt_specials. |
|
1532 | via the prompt_specials. | |
1497 |
|
1533 | |||
1498 | 2004-06-06 Fernando Perez <fperez@colorado.edu> |
|
1534 | 2004-06-06 Fernando Perez <fperez@colorado.edu> | |
1499 |
|
1535 | |||
1500 | * IPython/Prompts.py (prompt_specials): Added the ability to have |
|
1536 | * IPython/Prompts.py (prompt_specials): Added the ability to have | |
1501 | bash-like special sequences in the prompts, which get |
|
1537 | bash-like special sequences in the prompts, which get | |
1502 | automatically expanded. Things like hostname, current working |
|
1538 | automatically expanded. Things like hostname, current working | |
1503 | directory and username are implemented already, but it's easy to |
|
1539 | directory and username are implemented already, but it's easy to | |
1504 | add more in the future. Thanks to a patch by W.J. van der Laan |
|
1540 | add more in the future. Thanks to a patch by W.J. van der Laan | |
1505 | <gnufnork-AT-hetdigitalegat.nl> |
|
1541 | <gnufnork-AT-hetdigitalegat.nl> | |
1506 | (prompt_specials): Added color support for prompt strings, so |
|
1542 | (prompt_specials): Added color support for prompt strings, so | |
1507 | users can define arbitrary color setups for their prompts. |
|
1543 | users can define arbitrary color setups for their prompts. | |
1508 |
|
1544 | |||
1509 | 2004-06-05 Fernando Perez <fperez@colorado.edu> |
|
1545 | 2004-06-05 Fernando Perez <fperez@colorado.edu> | |
1510 |
|
1546 | |||
1511 | * IPython/genutils.py (Term.reopen_all): Added Windows-specific |
|
1547 | * IPython/genutils.py (Term.reopen_all): Added Windows-specific | |
1512 | code to load Gary Bishop's readline and configure it |
|
1548 | code to load Gary Bishop's readline and configure it | |
1513 | automatically. Thanks to Gary for help on this. |
|
1549 | automatically. Thanks to Gary for help on this. | |
1514 |
|
1550 | |||
1515 | 2004-06-01 Fernando Perez <fperez@colorado.edu> |
|
1551 | 2004-06-01 Fernando Perez <fperez@colorado.edu> | |
1516 |
|
1552 | |||
1517 | * IPython/Logger.py (Logger.create_log): fix bug for logging |
|
1553 | * IPython/Logger.py (Logger.create_log): fix bug for logging | |
1518 | with no filename (previous fix was incomplete). |
|
1554 | with no filename (previous fix was incomplete). | |
1519 |
|
1555 | |||
1520 | 2004-05-25 Fernando Perez <fperez@colorado.edu> |
|
1556 | 2004-05-25 Fernando Perez <fperez@colorado.edu> | |
1521 |
|
1557 | |||
1522 | * IPython/Magic.py (Magic.parse_options): fix bug where naked |
|
1558 | * IPython/Magic.py (Magic.parse_options): fix bug where naked | |
1523 | parens would get passed to the shell. |
|
1559 | parens would get passed to the shell. | |
1524 |
|
1560 | |||
1525 | 2004-05-20 Fernando Perez <fperez@colorado.edu> |
|
1561 | 2004-05-20 Fernando Perez <fperez@colorado.edu> | |
1526 |
|
1562 | |||
1527 | * IPython/Magic.py (Magic.magic_prun): changed default profile |
|
1563 | * IPython/Magic.py (Magic.magic_prun): changed default profile | |
1528 | sort order to 'time' (the more common profiling need). |
|
1564 | sort order to 'time' (the more common profiling need). | |
1529 |
|
1565 | |||
1530 | * IPython/OInspect.py (Inspector.pinfo): flush the inspect cache |
|
1566 | * IPython/OInspect.py (Inspector.pinfo): flush the inspect cache | |
1531 | so that source code shown is guaranteed in sync with the file on |
|
1567 | so that source code shown is guaranteed in sync with the file on | |
1532 | disk (also changed in psource). Similar fix to the one for |
|
1568 | disk (also changed in psource). Similar fix to the one for | |
1533 | ultraTB on 2004-05-06. Thanks to a bug report by Yann Le Du |
|
1569 | ultraTB on 2004-05-06. Thanks to a bug report by Yann Le Du | |
1534 | <yann.ledu-AT-noos.fr>. |
|
1570 | <yann.ledu-AT-noos.fr>. | |
1535 |
|
1571 | |||
1536 | * IPython/Magic.py (Magic.parse_options): Fixed bug where commands |
|
1572 | * IPython/Magic.py (Magic.parse_options): Fixed bug where commands | |
1537 | with a single option would not be correctly parsed. Closes |
|
1573 | with a single option would not be correctly parsed. Closes | |
1538 | http://www.scipy.net/roundup/ipython/issue14. This bug had been |
|
1574 | http://www.scipy.net/roundup/ipython/issue14. This bug had been | |
1539 | introduced in 0.6.0 (on 2004-05-06). |
|
1575 | introduced in 0.6.0 (on 2004-05-06). | |
1540 |
|
1576 | |||
1541 | 2004-05-13 *** Released version 0.6.0 |
|
1577 | 2004-05-13 *** Released version 0.6.0 | |
1542 |
|
1578 | |||
1543 | 2004-05-13 Fernando Perez <fperez@colorado.edu> |
|
1579 | 2004-05-13 Fernando Perez <fperez@colorado.edu> | |
1544 |
|
1580 | |||
1545 | * debian/: Added debian/ directory to CVS, so that debian support |
|
1581 | * debian/: Added debian/ directory to CVS, so that debian support | |
1546 | is publicly accessible. The debian package is maintained by Jack |
|
1582 | is publicly accessible. The debian package is maintained by Jack | |
1547 | Moffit <jack-AT-xiph.org>. |
|
1583 | Moffit <jack-AT-xiph.org>. | |
1548 |
|
1584 | |||
1549 | * Documentation: included the notes about an ipython-based system |
|
1585 | * Documentation: included the notes about an ipython-based system | |
1550 | shell (the hypothetical 'pysh') into the new_design.pdf document, |
|
1586 | shell (the hypothetical 'pysh') into the new_design.pdf document, | |
1551 | so that these ideas get distributed to users along with the |
|
1587 | so that these ideas get distributed to users along with the | |
1552 | official documentation. |
|
1588 | official documentation. | |
1553 |
|
1589 | |||
1554 | 2004-05-10 Fernando Perez <fperez@colorado.edu> |
|
1590 | 2004-05-10 Fernando Perez <fperez@colorado.edu> | |
1555 |
|
1591 | |||
1556 | * IPython/Logger.py (Logger.create_log): fix recently introduced |
|
1592 | * IPython/Logger.py (Logger.create_log): fix recently introduced | |
1557 | bug (misindented line) where logstart would fail when not given an |
|
1593 | bug (misindented line) where logstart would fail when not given an | |
1558 | explicit filename. |
|
1594 | explicit filename. | |
1559 |
|
1595 | |||
1560 | 2004-05-09 Fernando Perez <fperez@colorado.edu> |
|
1596 | 2004-05-09 Fernando Perez <fperez@colorado.edu> | |
1561 |
|
1597 | |||
1562 | * IPython/Magic.py (Magic.parse_options): skip system call when |
|
1598 | * IPython/Magic.py (Magic.parse_options): skip system call when | |
1563 | there are no options to look for. Faster, cleaner for the common |
|
1599 | there are no options to look for. Faster, cleaner for the common | |
1564 | case. |
|
1600 | case. | |
1565 |
|
1601 | |||
1566 | * Documentation: many updates to the manual: describing Windows |
|
1602 | * Documentation: many updates to the manual: describing Windows | |
1567 | support better, Gnuplot updates, credits, misc small stuff. Also |
|
1603 | support better, Gnuplot updates, credits, misc small stuff. Also | |
1568 | updated the new_design doc a bit. |
|
1604 | updated the new_design doc a bit. | |
1569 |
|
1605 | |||
1570 | 2004-05-06 *** Released version 0.6.0.rc1 |
|
1606 | 2004-05-06 *** Released version 0.6.0.rc1 | |
1571 |
|
1607 | |||
1572 | 2004-05-06 Fernando Perez <fperez@colorado.edu> |
|
1608 | 2004-05-06 Fernando Perez <fperez@colorado.edu> | |
1573 |
|
1609 | |||
1574 | * IPython/ultraTB.py (ListTB.text): modified a ton of string += |
|
1610 | * IPython/ultraTB.py (ListTB.text): modified a ton of string += | |
1575 | operations to use the vastly more efficient list/''.join() method. |
|
1611 | operations to use the vastly more efficient list/''.join() method. | |
1576 | (FormattedTB.text): Fix |
|
1612 | (FormattedTB.text): Fix | |
1577 | http://www.scipy.net/roundup/ipython/issue12 - exception source |
|
1613 | http://www.scipy.net/roundup/ipython/issue12 - exception source | |
1578 | extract not updated after reload. Thanks to Mike Salib |
|
1614 | extract not updated after reload. Thanks to Mike Salib | |
1579 | <msalib-AT-mit.edu> for pinning the source of the problem. |
|
1615 | <msalib-AT-mit.edu> for pinning the source of the problem. | |
1580 | Fortunately, the solution works inside ipython and doesn't require |
|
1616 | Fortunately, the solution works inside ipython and doesn't require | |
1581 | any changes to python proper. |
|
1617 | any changes to python proper. | |
1582 |
|
1618 | |||
1583 | * IPython/Magic.py (Magic.parse_options): Improved to process the |
|
1619 | * IPython/Magic.py (Magic.parse_options): Improved to process the | |
1584 | argument list as a true shell would (by actually using the |
|
1620 | argument list as a true shell would (by actually using the | |
1585 | underlying system shell). This way, all @magics automatically get |
|
1621 | underlying system shell). This way, all @magics automatically get | |
1586 | shell expansion for variables. Thanks to a comment by Alex |
|
1622 | shell expansion for variables. Thanks to a comment by Alex | |
1587 | Schmolck. |
|
1623 | Schmolck. | |
1588 |
|
1624 | |||
1589 | 2004-04-04 Fernando Perez <fperez@colorado.edu> |
|
1625 | 2004-04-04 Fernando Perez <fperez@colorado.edu> | |
1590 |
|
1626 | |||
1591 | * IPython/iplib.py (InteractiveShell.interact): Added a special |
|
1627 | * IPython/iplib.py (InteractiveShell.interact): Added a special | |
1592 | trap for a debugger quit exception, which is basically impossible |
|
1628 | trap for a debugger quit exception, which is basically impossible | |
1593 | to handle by normal mechanisms, given what pdb does to the stack. |
|
1629 | to handle by normal mechanisms, given what pdb does to the stack. | |
1594 | This fixes a crash reported by <fgibbons-AT-llama.med.harvard.edu>. |
|
1630 | This fixes a crash reported by <fgibbons-AT-llama.med.harvard.edu>. | |
1595 |
|
1631 | |||
1596 | 2004-04-03 Fernando Perez <fperez@colorado.edu> |
|
1632 | 2004-04-03 Fernando Perez <fperez@colorado.edu> | |
1597 |
|
1633 | |||
1598 | * IPython/genutils.py (Term): Standardized the names of the Term |
|
1634 | * IPython/genutils.py (Term): Standardized the names of the Term | |
1599 | class streams to cin/cout/cerr, following C++ naming conventions |
|
1635 | class streams to cin/cout/cerr, following C++ naming conventions | |
1600 | (I can't use in/out/err because 'in' is not a valid attribute |
|
1636 | (I can't use in/out/err because 'in' is not a valid attribute | |
1601 | name). |
|
1637 | name). | |
1602 |
|
1638 | |||
1603 | * IPython/iplib.py (InteractiveShell.interact): don't increment |
|
1639 | * IPython/iplib.py (InteractiveShell.interact): don't increment | |
1604 | the prompt if there's no user input. By Daniel 'Dang' Griffith |
|
1640 | the prompt if there's no user input. By Daniel 'Dang' Griffith | |
1605 | <pythondev-dang-AT-lazytwinacres.net>, after a suggestion from |
|
1641 | <pythondev-dang-AT-lazytwinacres.net>, after a suggestion from | |
1606 | Francois Pinard. |
|
1642 | Francois Pinard. | |
1607 |
|
1643 | |||
1608 | 2004-04-02 Fernando Perez <fperez@colorado.edu> |
|
1644 | 2004-04-02 Fernando Perez <fperez@colorado.edu> | |
1609 |
|
1645 | |||
1610 | * IPython/genutils.py (Stream.__init__): Modified to survive at |
|
1646 | * IPython/genutils.py (Stream.__init__): Modified to survive at | |
1611 | least importing in contexts where stdin/out/err aren't true file |
|
1647 | least importing in contexts where stdin/out/err aren't true file | |
1612 | objects, such as PyCrust (they lack fileno() and mode). However, |
|
1648 | objects, such as PyCrust (they lack fileno() and mode). However, | |
1613 | the recovery facilities which rely on these things existing will |
|
1649 | the recovery facilities which rely on these things existing will | |
1614 | not work. |
|
1650 | not work. | |
1615 |
|
1651 | |||
1616 | 2004-04-01 Fernando Perez <fperez@colorado.edu> |
|
1652 | 2004-04-01 Fernando Perez <fperez@colorado.edu> | |
1617 |
|
1653 | |||
1618 | * IPython/Magic.py (Magic.magic_sx): modified (as well as @sc) to |
|
1654 | * IPython/Magic.py (Magic.magic_sx): modified (as well as @sc) to | |
1619 | use the new getoutputerror() function, so it properly |
|
1655 | use the new getoutputerror() function, so it properly | |
1620 | distinguishes stdout/err. |
|
1656 | distinguishes stdout/err. | |
1621 |
|
1657 | |||
1622 | * IPython/genutils.py (getoutputerror): added a function to |
|
1658 | * IPython/genutils.py (getoutputerror): added a function to | |
1623 | capture separately the standard output and error of a command. |
|
1659 | capture separately the standard output and error of a command. | |
1624 | After a comment from dang on the mailing lists. This code is |
|
1660 | After a comment from dang on the mailing lists. This code is | |
1625 | basically a modified version of commands.getstatusoutput(), from |
|
1661 | basically a modified version of commands.getstatusoutput(), from | |
1626 | the standard library. |
|
1662 | the standard library. | |
1627 |
|
1663 | |||
1628 | * IPython/iplib.py (InteractiveShell.handle_shell_escape): added |
|
1664 | * IPython/iplib.py (InteractiveShell.handle_shell_escape): added | |
1629 | '!!' as a special syntax (shorthand) to access @sx. |
|
1665 | '!!' as a special syntax (shorthand) to access @sx. | |
1630 |
|
1666 | |||
1631 | * IPython/Magic.py (Magic.magic_sx): new magic, to execute a shell |
|
1667 | * IPython/Magic.py (Magic.magic_sx): new magic, to execute a shell | |
1632 | command and return its output as a list split on '\n'. |
|
1668 | command and return its output as a list split on '\n'. | |
1633 |
|
1669 | |||
1634 | 2004-03-31 Fernando Perez <fperez@colorado.edu> |
|
1670 | 2004-03-31 Fernando Perez <fperez@colorado.edu> | |
1635 |
|
1671 | |||
1636 | * IPython/FakeModule.py (FakeModule.__init__): added __nonzero__ |
|
1672 | * IPython/FakeModule.py (FakeModule.__init__): added __nonzero__ | |
1637 | method to dictionaries used as FakeModule instances if they lack |
|
1673 | method to dictionaries used as FakeModule instances if they lack | |
1638 | it. At least pydoc in python2.3 breaks for runtime-defined |
|
1674 | it. At least pydoc in python2.3 breaks for runtime-defined | |
1639 | functions without this hack. At some point I need to _really_ |
|
1675 | functions without this hack. At some point I need to _really_ | |
1640 | understand what FakeModule is doing, because it's a gross hack. |
|
1676 | understand what FakeModule is doing, because it's a gross hack. | |
1641 | But it solves Arnd's problem for now... |
|
1677 | But it solves Arnd's problem for now... | |
1642 |
|
1678 | |||
1643 | 2004-02-27 Fernando Perez <fperez@colorado.edu> |
|
1679 | 2004-02-27 Fernando Perez <fperez@colorado.edu> | |
1644 |
|
1680 | |||
1645 | * IPython/Logger.py (Logger.create_log): Fix bug where 'rotate' |
|
1681 | * IPython/Logger.py (Logger.create_log): Fix bug where 'rotate' | |
1646 | mode would behave erratically. Also increased the number of |
|
1682 | mode would behave erratically. Also increased the number of | |
1647 | possible logs in rotate mod to 999. Thanks to Rod Holland |
|
1683 | possible logs in rotate mod to 999. Thanks to Rod Holland | |
1648 | <rhh@StructureLABS.com> for the report and fixes. |
|
1684 | <rhh@StructureLABS.com> for the report and fixes. | |
1649 |
|
1685 | |||
1650 | 2004-02-26 Fernando Perez <fperez@colorado.edu> |
|
1686 | 2004-02-26 Fernando Perez <fperez@colorado.edu> | |
1651 |
|
1687 | |||
1652 | * IPython/genutils.py (page): Check that the curses module really |
|
1688 | * IPython/genutils.py (page): Check that the curses module really | |
1653 | has the initscr attribute before trying to use it. For some |
|
1689 | has the initscr attribute before trying to use it. For some | |
1654 | reason, the Solaris curses module is missing this. I think this |
|
1690 | reason, the Solaris curses module is missing this. I think this | |
1655 | should be considered a Solaris python bug, but I'm not sure. |
|
1691 | should be considered a Solaris python bug, but I'm not sure. | |
1656 |
|
1692 | |||
1657 | 2004-01-17 Fernando Perez <fperez@colorado.edu> |
|
1693 | 2004-01-17 Fernando Perez <fperez@colorado.edu> | |
1658 |
|
1694 | |||
1659 | * IPython/genutils.py (Stream.__init__): Changes to try to make |
|
1695 | * IPython/genutils.py (Stream.__init__): Changes to try to make | |
1660 | ipython robust against stdin/out/err being closed by the user. |
|
1696 | ipython robust against stdin/out/err being closed by the user. | |
1661 | This is 'user error' (and blocks a normal python session, at least |
|
1697 | This is 'user error' (and blocks a normal python session, at least | |
1662 | the stdout case). However, Ipython should be able to survive such |
|
1698 | the stdout case). However, Ipython should be able to survive such | |
1663 | instances of abuse as gracefully as possible. To simplify the |
|
1699 | instances of abuse as gracefully as possible. To simplify the | |
1664 | coding and maintain compatibility with Gary Bishop's Term |
|
1700 | coding and maintain compatibility with Gary Bishop's Term | |
1665 | contributions, I've made use of classmethods for this. I think |
|
1701 | contributions, I've made use of classmethods for this. I think | |
1666 | this introduces a dependency on python 2.2. |
|
1702 | this introduces a dependency on python 2.2. | |
1667 |
|
1703 | |||
1668 | 2004-01-13 Fernando Perez <fperez@colorado.edu> |
|
1704 | 2004-01-13 Fernando Perez <fperez@colorado.edu> | |
1669 |
|
1705 | |||
1670 | * IPython/numutils.py (exp_safe): simplified the code a bit and |
|
1706 | * IPython/numutils.py (exp_safe): simplified the code a bit and | |
1671 | removed the need for importing the kinds module altogether. |
|
1707 | removed the need for importing the kinds module altogether. | |
1672 |
|
1708 | |||
1673 | 2004-01-06 Fernando Perez <fperez@colorado.edu> |
|
1709 | 2004-01-06 Fernando Perez <fperez@colorado.edu> | |
1674 |
|
1710 | |||
1675 | * IPython/Magic.py (Magic.magic_sc): Made the shell capture system |
|
1711 | * IPython/Magic.py (Magic.magic_sc): Made the shell capture system | |
1676 | a magic function instead, after some community feedback. No |
|
1712 | a magic function instead, after some community feedback. No | |
1677 | special syntax will exist for it, but its name is deliberately |
|
1713 | special syntax will exist for it, but its name is deliberately | |
1678 | very short. |
|
1714 | very short. | |
1679 |
|
1715 | |||
1680 | 2003-12-20 Fernando Perez <fperez@colorado.edu> |
|
1716 | 2003-12-20 Fernando Perez <fperez@colorado.edu> | |
1681 |
|
1717 | |||
1682 | * IPython/iplib.py (InteractiveShell.handle_shell_assign): Added |
|
1718 | * IPython/iplib.py (InteractiveShell.handle_shell_assign): Added | |
1683 | new functionality, to automagically assign the result of a shell |
|
1719 | new functionality, to automagically assign the result of a shell | |
1684 | command to a variable. I'll solicit some community feedback on |
|
1720 | command to a variable. I'll solicit some community feedback on | |
1685 | this before making it permanent. |
|
1721 | this before making it permanent. | |
1686 |
|
1722 | |||
1687 | * IPython/OInspect.py (Inspector.pinfo): Fix crash when info was |
|
1723 | * IPython/OInspect.py (Inspector.pinfo): Fix crash when info was | |
1688 | requested about callables for which inspect couldn't obtain a |
|
1724 | requested about callables for which inspect couldn't obtain a | |
1689 | proper argspec. Thanks to a crash report sent by Etienne |
|
1725 | proper argspec. Thanks to a crash report sent by Etienne | |
1690 | Posthumus <etienne-AT-apple01.cs.vu.nl>. |
|
1726 | Posthumus <etienne-AT-apple01.cs.vu.nl>. | |
1691 |
|
1727 | |||
1692 | 2003-12-09 Fernando Perez <fperez@colorado.edu> |
|
1728 | 2003-12-09 Fernando Perez <fperez@colorado.edu> | |
1693 |
|
1729 | |||
1694 | * IPython/genutils.py (page): patch for the pager to work across |
|
1730 | * IPython/genutils.py (page): patch for the pager to work across | |
1695 | various versions of Windows. By Gary Bishop. |
|
1731 | various versions of Windows. By Gary Bishop. | |
1696 |
|
1732 | |||
1697 | 2003-12-04 Fernando Perez <fperez@colorado.edu> |
|
1733 | 2003-12-04 Fernando Perez <fperez@colorado.edu> | |
1698 |
|
1734 | |||
1699 | * IPython/Gnuplot2.py (PlotItems): Fixes for working with |
|
1735 | * IPython/Gnuplot2.py (PlotItems): Fixes for working with | |
1700 | Gnuplot.py version 1.7, whose internal names changed quite a bit. |
|
1736 | Gnuplot.py version 1.7, whose internal names changed quite a bit. | |
1701 | While I tested this and it looks ok, there may still be corner |
|
1737 | While I tested this and it looks ok, there may still be corner | |
1702 | cases I've missed. |
|
1738 | cases I've missed. | |
1703 |
|
1739 | |||
1704 | 2003-12-01 Fernando Perez <fperez@colorado.edu> |
|
1740 | 2003-12-01 Fernando Perez <fperez@colorado.edu> | |
1705 |
|
1741 | |||
1706 | * IPython/iplib.py (InteractiveShell._prefilter): Fixed a bug |
|
1742 | * IPython/iplib.py (InteractiveShell._prefilter): Fixed a bug | |
1707 | where a line like 'p,q=1,2' would fail because the automagic |
|
1743 | where a line like 'p,q=1,2' would fail because the automagic | |
1708 | system would be triggered for @p. |
|
1744 | system would be triggered for @p. | |
1709 |
|
1745 | |||
1710 | * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): Tab-related |
|
1746 | * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): Tab-related | |
1711 | cleanups, code unmodified. |
|
1747 | cleanups, code unmodified. | |
1712 |
|
1748 | |||
1713 | * IPython/genutils.py (Term): added a class for IPython to handle |
|
1749 | * IPython/genutils.py (Term): added a class for IPython to handle | |
1714 | output. In most cases it will just be a proxy for stdout/err, but |
|
1750 | output. In most cases it will just be a proxy for stdout/err, but | |
1715 | having this allows modifications to be made for some platforms, |
|
1751 | having this allows modifications to be made for some platforms, | |
1716 | such as handling color escapes under Windows. All of this code |
|
1752 | such as handling color escapes under Windows. All of this code | |
1717 | was contributed by Gary Bishop, with minor modifications by me. |
|
1753 | was contributed by Gary Bishop, with minor modifications by me. | |
1718 | The actual changes affect many files. |
|
1754 | The actual changes affect many files. | |
1719 |
|
1755 | |||
1720 | 2003-11-30 Fernando Perez <fperez@colorado.edu> |
|
1756 | 2003-11-30 Fernando Perez <fperez@colorado.edu> | |
1721 |
|
1757 | |||
1722 | * IPython/iplib.py (file_matches): new completion code, courtesy |
|
1758 | * IPython/iplib.py (file_matches): new completion code, courtesy | |
1723 | of Jeff Collins. This enables filename completion again under |
|
1759 | of Jeff Collins. This enables filename completion again under | |
1724 | python 2.3, which disabled it at the C level. |
|
1760 | python 2.3, which disabled it at the C level. | |
1725 |
|
1761 | |||
1726 | 2003-11-11 Fernando Perez <fperez@colorado.edu> |
|
1762 | 2003-11-11 Fernando Perez <fperez@colorado.edu> | |
1727 |
|
1763 | |||
1728 | * IPython/numutils.py (amap): Added amap() fn. Simple shorthand |
|
1764 | * IPython/numutils.py (amap): Added amap() fn. Simple shorthand | |
1729 | for Numeric.array(map(...)), but often convenient. |
|
1765 | for Numeric.array(map(...)), but often convenient. | |
1730 |
|
1766 | |||
1731 | 2003-11-05 Fernando Perez <fperez@colorado.edu> |
|
1767 | 2003-11-05 Fernando Perez <fperez@colorado.edu> | |
1732 |
|
1768 | |||
1733 | * IPython/numutils.py (frange): Changed a call from int() to |
|
1769 | * IPython/numutils.py (frange): Changed a call from int() to | |
1734 | int(round()) to prevent a problem reported with arange() in the |
|
1770 | int(round()) to prevent a problem reported with arange() in the | |
1735 | numpy list. |
|
1771 | numpy list. | |
1736 |
|
1772 | |||
1737 | 2003-10-06 Fernando Perez <fperez@colorado.edu> |
|
1773 | 2003-10-06 Fernando Perez <fperez@colorado.edu> | |
1738 |
|
1774 | |||
1739 | * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): changed to |
|
1775 | * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): changed to | |
1740 | prevent crashes if sys lacks an argv attribute (it happens with |
|
1776 | prevent crashes if sys lacks an argv attribute (it happens with | |
1741 | embedded interpreters which build a bare-bones sys module). |
|
1777 | embedded interpreters which build a bare-bones sys module). | |
1742 | Thanks to a report/bugfix by Adam Hupp <hupp-AT-cs.wisc.edu>. |
|
1778 | Thanks to a report/bugfix by Adam Hupp <hupp-AT-cs.wisc.edu>. | |
1743 |
|
1779 | |||
1744 | 2003-09-24 Fernando Perez <fperez@colorado.edu> |
|
1780 | 2003-09-24 Fernando Perez <fperez@colorado.edu> | |
1745 |
|
1781 | |||
1746 | * IPython/Magic.py (Magic._ofind): blanket except around getattr() |
|
1782 | * IPython/Magic.py (Magic._ofind): blanket except around getattr() | |
1747 | to protect against poorly written user objects where __getattr__ |
|
1783 | to protect against poorly written user objects where __getattr__ | |
1748 | raises exceptions other than AttributeError. Thanks to a bug |
|
1784 | raises exceptions other than AttributeError. Thanks to a bug | |
1749 | report by Oliver Sander <osander-AT-gmx.de>. |
|
1785 | report by Oliver Sander <osander-AT-gmx.de>. | |
1750 |
|
1786 | |||
1751 | * IPython/FakeModule.py (FakeModule.__repr__): this method was |
|
1787 | * IPython/FakeModule.py (FakeModule.__repr__): this method was | |
1752 | missing. Thanks to bug report by Ralf Schmitt <ralf-AT-brainbot.com>. |
|
1788 | missing. Thanks to bug report by Ralf Schmitt <ralf-AT-brainbot.com>. | |
1753 |
|
1789 | |||
1754 | 2003-09-09 Fernando Perez <fperez@colorado.edu> |
|
1790 | 2003-09-09 Fernando Perez <fperez@colorado.edu> | |
1755 |
|
1791 | |||
1756 | * IPython/iplib.py (InteractiveShell._prefilter): fix bug where |
|
1792 | * IPython/iplib.py (InteractiveShell._prefilter): fix bug where | |
1757 | unpacking a list whith a callable as first element would |
|
1793 | unpacking a list whith a callable as first element would | |
1758 | mistakenly trigger autocalling. Thanks to a bug report by Jeffery |
|
1794 | mistakenly trigger autocalling. Thanks to a bug report by Jeffery | |
1759 | Collins. |
|
1795 | Collins. | |
1760 |
|
1796 | |||
1761 | 2003-08-25 *** Released version 0.5.0 |
|
1797 | 2003-08-25 *** Released version 0.5.0 | |
1762 |
|
1798 | |||
1763 | 2003-08-22 Fernando Perez <fperez@colorado.edu> |
|
1799 | 2003-08-22 Fernando Perez <fperez@colorado.edu> | |
1764 |
|
1800 | |||
1765 | * IPython/ultraTB.py (VerboseTB.linereader): Improved handling of |
|
1801 | * IPython/ultraTB.py (VerboseTB.linereader): Improved handling of | |
1766 | improperly defined user exceptions. Thanks to feedback from Mark |
|
1802 | improperly defined user exceptions. Thanks to feedback from Mark | |
1767 | Russell <mrussell-AT-verio.net>. |
|
1803 | Russell <mrussell-AT-verio.net>. | |
1768 |
|
1804 | |||
1769 | 2003-08-20 Fernando Perez <fperez@colorado.edu> |
|
1805 | 2003-08-20 Fernando Perez <fperez@colorado.edu> | |
1770 |
|
1806 | |||
1771 | * IPython/OInspect.py (Inspector.pinfo): changed String Form |
|
1807 | * IPython/OInspect.py (Inspector.pinfo): changed String Form | |
1772 | printing so that it would print multi-line string forms starting |
|
1808 | printing so that it would print multi-line string forms starting | |
1773 | with a new line. This way the formatting is better respected for |
|
1809 | with a new line. This way the formatting is better respected for | |
1774 | objects which work hard to make nice string forms. |
|
1810 | objects which work hard to make nice string forms. | |
1775 |
|
1811 | |||
1776 | * IPython/iplib.py (InteractiveShell.handle_auto): Fix bug where |
|
1812 | * IPython/iplib.py (InteractiveShell.handle_auto): Fix bug where | |
1777 | autocall would overtake data access for objects with both |
|
1813 | autocall would overtake data access for objects with both | |
1778 | __getitem__ and __call__. |
|
1814 | __getitem__ and __call__. | |
1779 |
|
1815 | |||
1780 | 2003-08-19 *** Released version 0.5.0-rc1 |
|
1816 | 2003-08-19 *** Released version 0.5.0-rc1 | |
1781 |
|
1817 | |||
1782 | 2003-08-19 Fernando Perez <fperez@colorado.edu> |
|
1818 | 2003-08-19 Fernando Perez <fperez@colorado.edu> | |
1783 |
|
1819 | |||
1784 | * IPython/deep_reload.py (load_tail): single tiny change here |
|
1820 | * IPython/deep_reload.py (load_tail): single tiny change here | |
1785 | seems to fix the long-standing bug of dreload() failing to work |
|
1821 | seems to fix the long-standing bug of dreload() failing to work | |
1786 | for dotted names. But this module is pretty tricky, so I may have |
|
1822 | for dotted names. But this module is pretty tricky, so I may have | |
1787 | missed some subtlety. Needs more testing!. |
|
1823 | missed some subtlety. Needs more testing!. | |
1788 |
|
1824 | |||
1789 | * IPython/ultraTB.py (VerboseTB.linereader): harden against user |
|
1825 | * IPython/ultraTB.py (VerboseTB.linereader): harden against user | |
1790 | exceptions which have badly implemented __str__ methods. |
|
1826 | exceptions which have badly implemented __str__ methods. | |
1791 | (VerboseTB.text): harden against inspect.getinnerframes crashing, |
|
1827 | (VerboseTB.text): harden against inspect.getinnerframes crashing, | |
1792 | which I've been getting reports about from Python 2.3 users. I |
|
1828 | which I've been getting reports about from Python 2.3 users. I | |
1793 | wish I had a simple test case to reproduce the problem, so I could |
|
1829 | wish I had a simple test case to reproduce the problem, so I could | |
1794 | either write a cleaner workaround or file a bug report if |
|
1830 | either write a cleaner workaround or file a bug report if | |
1795 | necessary. |
|
1831 | necessary. | |
1796 |
|
1832 | |||
1797 | * IPython/Magic.py (Magic.magic_edit): fixed bug where after |
|
1833 | * IPython/Magic.py (Magic.magic_edit): fixed bug where after | |
1798 | making a class 'foo', file 'foo.py' couldn't be edited. Thanks to |
|
1834 | making a class 'foo', file 'foo.py' couldn't be edited. Thanks to | |
1799 | a bug report by Tjabo Kloppenburg. |
|
1835 | a bug report by Tjabo Kloppenburg. | |
1800 |
|
1836 | |||
1801 | * IPython/ultraTB.py (VerboseTB.debugger): hardened against pdb |
|
1837 | * IPython/ultraTB.py (VerboseTB.debugger): hardened against pdb | |
1802 | crashes. Wrapped the pdb call in a blanket try/except, since pdb |
|
1838 | crashes. Wrapped the pdb call in a blanket try/except, since pdb | |
1803 | seems rather unstable. Thanks to a bug report by Tjabo |
|
1839 | seems rather unstable. Thanks to a bug report by Tjabo | |
1804 | Kloppenburg <tjabo.kloppenburg-AT-unix-ag.uni-siegen.de>. |
|
1840 | Kloppenburg <tjabo.kloppenburg-AT-unix-ag.uni-siegen.de>. | |
1805 |
|
1841 | |||
1806 | * IPython/Release.py (version): release 0.5.0-rc1. I want to put |
|
1842 | * IPython/Release.py (version): release 0.5.0-rc1. I want to put | |
1807 | this out soon because of the critical fixes in the inner loop for |
|
1843 | this out soon because of the critical fixes in the inner loop for | |
1808 | generators. |
|
1844 | generators. | |
1809 |
|
1845 | |||
1810 | * IPython/Magic.py (Magic.getargspec): removed. This (and |
|
1846 | * IPython/Magic.py (Magic.getargspec): removed. This (and | |
1811 | _get_def) have been obsoleted by OInspect for a long time, I |
|
1847 | _get_def) have been obsoleted by OInspect for a long time, I | |
1812 | hadn't noticed that they were dead code. |
|
1848 | hadn't noticed that they were dead code. | |
1813 | (Magic._ofind): restored _ofind functionality for a few literals |
|
1849 | (Magic._ofind): restored _ofind functionality for a few literals | |
1814 | (those in ["''",'""','[]','{}','()']). But it won't work anymore |
|
1850 | (those in ["''",'""','[]','{}','()']). But it won't work anymore | |
1815 | for things like "hello".capitalize?, since that would require a |
|
1851 | for things like "hello".capitalize?, since that would require a | |
1816 | potentially dangerous eval() again. |
|
1852 | potentially dangerous eval() again. | |
1817 |
|
1853 | |||
1818 | * IPython/iplib.py (InteractiveShell._prefilter): reorganized the |
|
1854 | * IPython/iplib.py (InteractiveShell._prefilter): reorganized the | |
1819 | logic a bit more to clean up the escapes handling and minimize the |
|
1855 | logic a bit more to clean up the escapes handling and minimize the | |
1820 | use of _ofind to only necessary cases. The interactive 'feel' of |
|
1856 | use of _ofind to only necessary cases. The interactive 'feel' of | |
1821 | IPython should have improved quite a bit with the changes in |
|
1857 | IPython should have improved quite a bit with the changes in | |
1822 | _prefilter and _ofind (besides being far safer than before). |
|
1858 | _prefilter and _ofind (besides being far safer than before). | |
1823 |
|
1859 | |||
1824 | * IPython/Magic.py (Magic.magic_edit): Fixed old bug (but rather |
|
1860 | * IPython/Magic.py (Magic.magic_edit): Fixed old bug (but rather | |
1825 | obscure, never reported). Edit would fail to find the object to |
|
1861 | obscure, never reported). Edit would fail to find the object to | |
1826 | edit under some circumstances. |
|
1862 | edit under some circumstances. | |
1827 | (Magic._ofind): CRITICAL FIX. Finally removed the eval() calls |
|
1863 | (Magic._ofind): CRITICAL FIX. Finally removed the eval() calls | |
1828 | which were causing double-calling of generators. Those eval calls |
|
1864 | which were causing double-calling of generators. Those eval calls | |
1829 | were _very_ dangerous, since code with side effects could be |
|
1865 | were _very_ dangerous, since code with side effects could be | |
1830 | triggered. As they say, 'eval is evil'... These were the |
|
1866 | triggered. As they say, 'eval is evil'... These were the | |
1831 | nastiest evals in IPython. Besides, _ofind is now far simpler, |
|
1867 | nastiest evals in IPython. Besides, _ofind is now far simpler, | |
1832 | and it should also be quite a bit faster. Its use of inspect is |
|
1868 | and it should also be quite a bit faster. Its use of inspect is | |
1833 | also safer, so perhaps some of the inspect-related crashes I've |
|
1869 | also safer, so perhaps some of the inspect-related crashes I've | |
1834 | seen lately with Python 2.3 might be taken care of. That will |
|
1870 | seen lately with Python 2.3 might be taken care of. That will | |
1835 | need more testing. |
|
1871 | need more testing. | |
1836 |
|
1872 | |||
1837 | 2003-08-17 Fernando Perez <fperez@colorado.edu> |
|
1873 | 2003-08-17 Fernando Perez <fperez@colorado.edu> | |
1838 |
|
1874 | |||
1839 | * IPython/iplib.py (InteractiveShell._prefilter): significant |
|
1875 | * IPython/iplib.py (InteractiveShell._prefilter): significant | |
1840 | simplifications to the logic for handling user escapes. Faster |
|
1876 | simplifications to the logic for handling user escapes. Faster | |
1841 | and simpler code. |
|
1877 | and simpler code. | |
1842 |
|
1878 | |||
1843 | 2003-08-14 Fernando Perez <fperez@colorado.edu> |
|
1879 | 2003-08-14 Fernando Perez <fperez@colorado.edu> | |
1844 |
|
1880 | |||
1845 | * IPython/numutils.py (sum_flat): rewrote to be non-recursive. |
|
1881 | * IPython/numutils.py (sum_flat): rewrote to be non-recursive. | |
1846 | Now it requires O(N) storage (N=size(a)) for non-contiguous input, |
|
1882 | Now it requires O(N) storage (N=size(a)) for non-contiguous input, | |
1847 | but it should be quite a bit faster. And the recursive version |
|
1883 | but it should be quite a bit faster. And the recursive version | |
1848 | generated O(log N) intermediate storage for all rank>1 arrays, |
|
1884 | generated O(log N) intermediate storage for all rank>1 arrays, | |
1849 | even if they were contiguous. |
|
1885 | even if they were contiguous. | |
1850 | (l1norm): Added this function. |
|
1886 | (l1norm): Added this function. | |
1851 | (norm): Added this function for arbitrary norms (including |
|
1887 | (norm): Added this function for arbitrary norms (including | |
1852 | l-infinity). l1 and l2 are still special cases for convenience |
|
1888 | l-infinity). l1 and l2 are still special cases for convenience | |
1853 | and speed. |
|
1889 | and speed. | |
1854 |
|
1890 | |||
1855 | 2003-08-03 Fernando Perez <fperez@colorado.edu> |
|
1891 | 2003-08-03 Fernando Perez <fperez@colorado.edu> | |
1856 |
|
1892 | |||
1857 | * IPython/Magic.py (Magic.magic_edit): Removed all remaining string |
|
1893 | * IPython/Magic.py (Magic.magic_edit): Removed all remaining string | |
1858 | exceptions, which now raise PendingDeprecationWarnings in Python |
|
1894 | exceptions, which now raise PendingDeprecationWarnings in Python | |
1859 | 2.3. There were some in Magic and some in Gnuplot2. |
|
1895 | 2.3. There were some in Magic and some in Gnuplot2. | |
1860 |
|
1896 | |||
1861 | 2003-06-30 Fernando Perez <fperez@colorado.edu> |
|
1897 | 2003-06-30 Fernando Perez <fperez@colorado.edu> | |
1862 |
|
1898 | |||
1863 | * IPython/genutils.py (page): modified to call curses only for |
|
1899 | * IPython/genutils.py (page): modified to call curses only for | |
1864 | terminals where TERM=='xterm'. After problems under many other |
|
1900 | terminals where TERM=='xterm'. After problems under many other | |
1865 | terminals were reported by Keith Beattie <KSBeattie-AT-lbl.gov>. |
|
1901 | terminals were reported by Keith Beattie <KSBeattie-AT-lbl.gov>. | |
1866 |
|
1902 | |||
1867 | * IPython/iplib.py (complete): removed spurious 'print "IE"' which |
|
1903 | * IPython/iplib.py (complete): removed spurious 'print "IE"' which | |
1868 | would be triggered when readline was absent. This was just an old |
|
1904 | would be triggered when readline was absent. This was just an old | |
1869 | debugging statement I'd forgotten to take out. |
|
1905 | debugging statement I'd forgotten to take out. | |
1870 |
|
1906 | |||
1871 | 2003-06-20 Fernando Perez <fperez@colorado.edu> |
|
1907 | 2003-06-20 Fernando Perez <fperez@colorado.edu> | |
1872 |
|
1908 | |||
1873 | * IPython/genutils.py (clock): modified to return only user time |
|
1909 | * IPython/genutils.py (clock): modified to return only user time | |
1874 | (not counting system time), after a discussion on scipy. While |
|
1910 | (not counting system time), after a discussion on scipy. While | |
1875 | system time may be a useful quantity occasionally, it may much |
|
1911 | system time may be a useful quantity occasionally, it may much | |
1876 | more easily be skewed by occasional swapping or other similar |
|
1912 | more easily be skewed by occasional swapping or other similar | |
1877 | activity. |
|
1913 | activity. | |
1878 |
|
1914 | |||
1879 | 2003-06-05 Fernando Perez <fperez@colorado.edu> |
|
1915 | 2003-06-05 Fernando Perez <fperez@colorado.edu> | |
1880 |
|
1916 | |||
1881 | * IPython/numutils.py (identity): new function, for building |
|
1917 | * IPython/numutils.py (identity): new function, for building | |
1882 | arbitrary rank Kronecker deltas (mostly backwards compatible with |
|
1918 | arbitrary rank Kronecker deltas (mostly backwards compatible with | |
1883 | Numeric.identity) |
|
1919 | Numeric.identity) | |
1884 |
|
1920 | |||
1885 | 2003-06-03 Fernando Perez <fperez@colorado.edu> |
|
1921 | 2003-06-03 Fernando Perez <fperez@colorado.edu> | |
1886 |
|
1922 | |||
1887 | * IPython/iplib.py (InteractiveShell.handle_magic): protect |
|
1923 | * IPython/iplib.py (InteractiveShell.handle_magic): protect | |
1888 | arguments passed to magics with spaces, to allow trailing '\' to |
|
1924 | arguments passed to magics with spaces, to allow trailing '\' to | |
1889 | work normally (mainly for Windows users). |
|
1925 | work normally (mainly for Windows users). | |
1890 |
|
1926 | |||
1891 | 2003-05-29 Fernando Perez <fperez@colorado.edu> |
|
1927 | 2003-05-29 Fernando Perez <fperez@colorado.edu> | |
1892 |
|
1928 | |||
1893 | * IPython/ipmaker.py (make_IPython): Load site._Helper() as help |
|
1929 | * IPython/ipmaker.py (make_IPython): Load site._Helper() as help | |
1894 | instead of pydoc.help. This fixes a bizarre behavior where |
|
1930 | instead of pydoc.help. This fixes a bizarre behavior where | |
1895 | printing '%s' % locals() would trigger the help system. Now |
|
1931 | printing '%s' % locals() would trigger the help system. Now | |
1896 | ipython behaves like normal python does. |
|
1932 | ipython behaves like normal python does. | |
1897 |
|
1933 | |||
1898 | Note that if one does 'from pydoc import help', the bizarre |
|
1934 | Note that if one does 'from pydoc import help', the bizarre | |
1899 | behavior returns, but this will also happen in normal python, so |
|
1935 | behavior returns, but this will also happen in normal python, so | |
1900 | it's not an ipython bug anymore (it has to do with how pydoc.help |
|
1936 | it's not an ipython bug anymore (it has to do with how pydoc.help | |
1901 | is implemented). |
|
1937 | is implemented). | |
1902 |
|
1938 | |||
1903 | 2003-05-22 Fernando Perez <fperez@colorado.edu> |
|
1939 | 2003-05-22 Fernando Perez <fperez@colorado.edu> | |
1904 |
|
1940 | |||
1905 | * IPython/FlexCompleter.py (Completer.attr_matches): fixed to |
|
1941 | * IPython/FlexCompleter.py (Completer.attr_matches): fixed to | |
1906 | return [] instead of None when nothing matches, also match to end |
|
1942 | return [] instead of None when nothing matches, also match to end | |
1907 | of line. Patch by Gary Bishop. |
|
1943 | of line. Patch by Gary Bishop. | |
1908 |
|
1944 | |||
1909 | * IPython/ipmaker.py (make_IPython): Added same sys.excepthook |
|
1945 | * IPython/ipmaker.py (make_IPython): Added same sys.excepthook | |
1910 | protection as before, for files passed on the command line. This |
|
1946 | protection as before, for files passed on the command line. This | |
1911 | prevents the CrashHandler from kicking in if user files call into |
|
1947 | prevents the CrashHandler from kicking in if user files call into | |
1912 | sys.excepthook (such as PyQt and WxWindows have a nasty habit of |
|
1948 | sys.excepthook (such as PyQt and WxWindows have a nasty habit of | |
1913 | doing). After a report by Kasper Souren <Kasper.Souren-AT-ircam.fr> |
|
1949 | doing). After a report by Kasper Souren <Kasper.Souren-AT-ircam.fr> | |
1914 |
|
1950 | |||
1915 | 2003-05-20 *** Released version 0.4.0 |
|
1951 | 2003-05-20 *** Released version 0.4.0 | |
1916 |
|
1952 | |||
1917 | 2003-05-20 Fernando Perez <fperez@colorado.edu> |
|
1953 | 2003-05-20 Fernando Perez <fperez@colorado.edu> | |
1918 |
|
1954 | |||
1919 | * setup.py: added support for manpages. It's a bit hackish b/c of |
|
1955 | * setup.py: added support for manpages. It's a bit hackish b/c of | |
1920 | a bug in the way the bdist_rpm distutils target handles gzipped |
|
1956 | a bug in the way the bdist_rpm distutils target handles gzipped | |
1921 | manpages, but it works. After a patch by Jack. |
|
1957 | manpages, but it works. After a patch by Jack. | |
1922 |
|
1958 | |||
1923 | 2003-05-19 Fernando Perez <fperez@colorado.edu> |
|
1959 | 2003-05-19 Fernando Perez <fperez@colorado.edu> | |
1924 |
|
1960 | |||
1925 | * IPython/numutils.py: added a mockup of the kinds module, since |
|
1961 | * IPython/numutils.py: added a mockup of the kinds module, since | |
1926 | it was recently removed from Numeric. This way, numutils will |
|
1962 | it was recently removed from Numeric. This way, numutils will | |
1927 | work for all users even if they are missing kinds. |
|
1963 | work for all users even if they are missing kinds. | |
1928 |
|
1964 | |||
1929 | * IPython/Magic.py (Magic._ofind): Harden against an inspect |
|
1965 | * IPython/Magic.py (Magic._ofind): Harden against an inspect | |
1930 | failure, which can occur with SWIG-wrapped extensions. After a |
|
1966 | failure, which can occur with SWIG-wrapped extensions. After a | |
1931 | crash report from Prabhu. |
|
1967 | crash report from Prabhu. | |
1932 |
|
1968 | |||
1933 | 2003-05-16 Fernando Perez <fperez@colorado.edu> |
|
1969 | 2003-05-16 Fernando Perez <fperez@colorado.edu> | |
1934 |
|
1970 | |||
1935 | * IPython/iplib.py (InteractiveShell.excepthook): New method to |
|
1971 | * IPython/iplib.py (InteractiveShell.excepthook): New method to | |
1936 | protect ipython from user code which may call directly |
|
1972 | protect ipython from user code which may call directly | |
1937 | sys.excepthook (this looks like an ipython crash to the user, even |
|
1973 | sys.excepthook (this looks like an ipython crash to the user, even | |
1938 | when it isn't). After a patch by Gary Bishop <gb-AT-cs.unc.edu>. |
|
1974 | when it isn't). After a patch by Gary Bishop <gb-AT-cs.unc.edu>. | |
1939 | This is especially important to help users of WxWindows, but may |
|
1975 | This is especially important to help users of WxWindows, but may | |
1940 | also be useful in other cases. |
|
1976 | also be useful in other cases. | |
1941 |
|
1977 | |||
1942 | * IPython/ultraTB.py (AutoFormattedTB.__call__): Changed to allow |
|
1978 | * IPython/ultraTB.py (AutoFormattedTB.__call__): Changed to allow | |
1943 | an optional tb_offset to be specified, and to preserve exception |
|
1979 | an optional tb_offset to be specified, and to preserve exception | |
1944 | info if given. After a patch by Gary Bishop <gb-AT-cs.unc.edu>. |
|
1980 | info if given. After a patch by Gary Bishop <gb-AT-cs.unc.edu>. | |
1945 |
|
1981 | |||
1946 | * ipython.1 (Default): Thanks to Jack's work, we now have manpages! |
|
1982 | * ipython.1 (Default): Thanks to Jack's work, we now have manpages! | |
1947 |
|
1983 | |||
1948 | 2003-05-15 Fernando Perez <fperez@colorado.edu> |
|
1984 | 2003-05-15 Fernando Perez <fperez@colorado.edu> | |
1949 |
|
1985 | |||
1950 | * IPython/iplib.py (InteractiveShell.user_setup): Fix crash when |
|
1986 | * IPython/iplib.py (InteractiveShell.user_setup): Fix crash when | |
1951 | installing for a new user under Windows. |
|
1987 | installing for a new user under Windows. | |
1952 |
|
1988 | |||
1953 | 2003-05-12 Fernando Perez <fperez@colorado.edu> |
|
1989 | 2003-05-12 Fernando Perez <fperez@colorado.edu> | |
1954 |
|
1990 | |||
1955 | * IPython/iplib.py (InteractiveShell.handle_emacs): New line |
|
1991 | * IPython/iplib.py (InteractiveShell.handle_emacs): New line | |
1956 | handler for Emacs comint-based lines. Currently it doesn't do |
|
1992 | handler for Emacs comint-based lines. Currently it doesn't do | |
1957 | much (but importantly, it doesn't update the history cache). In |
|
1993 | much (but importantly, it doesn't update the history cache). In | |
1958 | the future it may be expanded if Alex needs more functionality |
|
1994 | the future it may be expanded if Alex needs more functionality | |
1959 | there. |
|
1995 | there. | |
1960 |
|
1996 | |||
1961 | * IPython/CrashHandler.py (CrashHandler.__call__): Added platform |
|
1997 | * IPython/CrashHandler.py (CrashHandler.__call__): Added platform | |
1962 | info to crash reports. |
|
1998 | info to crash reports. | |
1963 |
|
1999 | |||
1964 | * IPython/iplib.py (InteractiveShell.mainloop): Added -c option, |
|
2000 | * IPython/iplib.py (InteractiveShell.mainloop): Added -c option, | |
1965 | just like Python's -c. Also fixed crash with invalid -color |
|
2001 | just like Python's -c. Also fixed crash with invalid -color | |
1966 | option value at startup. Thanks to Will French |
|
2002 | option value at startup. Thanks to Will French | |
1967 | <wfrench-AT-bestweb.net> for the bug report. |
|
2003 | <wfrench-AT-bestweb.net> for the bug report. | |
1968 |
|
2004 | |||
1969 | 2003-05-09 Fernando Perez <fperez@colorado.edu> |
|
2005 | 2003-05-09 Fernando Perez <fperez@colorado.edu> | |
1970 |
|
2006 | |||
1971 | * IPython/genutils.py (EvalDict.__getitem__): Renamed EvalString |
|
2007 | * IPython/genutils.py (EvalDict.__getitem__): Renamed EvalString | |
1972 | to EvalDict (it's a mapping, after all) and simplified its code |
|
2008 | to EvalDict (it's a mapping, after all) and simplified its code | |
1973 | quite a bit, after a nice discussion on c.l.py where Gustavo |
|
2009 | quite a bit, after a nice discussion on c.l.py where Gustavo | |
1974 | CΓ³rdova <gcordova-AT-sismex.com> suggested the new version. |
|
2010 | CΓ³rdova <gcordova-AT-sismex.com> suggested the new version. | |
1975 |
|
2011 | |||
1976 | 2003-04-30 Fernando Perez <fperez@colorado.edu> |
|
2012 | 2003-04-30 Fernando Perez <fperez@colorado.edu> | |
1977 |
|
2013 | |||
1978 | * IPython/genutils.py (timings_out): modified it to reduce its |
|
2014 | * IPython/genutils.py (timings_out): modified it to reduce its | |
1979 | overhead in the common reps==1 case. |
|
2015 | overhead in the common reps==1 case. | |
1980 |
|
2016 | |||
1981 | 2003-04-29 Fernando Perez <fperez@colorado.edu> |
|
2017 | 2003-04-29 Fernando Perez <fperez@colorado.edu> | |
1982 |
|
2018 | |||
1983 | * IPython/genutils.py (timings_out): Modified to use the resource |
|
2019 | * IPython/genutils.py (timings_out): Modified to use the resource | |
1984 | module, which avoids the wraparound problems of time.clock(). |
|
2020 | module, which avoids the wraparound problems of time.clock(). | |
1985 |
|
2021 | |||
1986 | 2003-04-17 *** Released version 0.2.15pre4 |
|
2022 | 2003-04-17 *** Released version 0.2.15pre4 | |
1987 |
|
2023 | |||
1988 | 2003-04-17 Fernando Perez <fperez@colorado.edu> |
|
2024 | 2003-04-17 Fernando Perez <fperez@colorado.edu> | |
1989 |
|
2025 | |||
1990 | * setup.py (scriptfiles): Split windows-specific stuff over to a |
|
2026 | * setup.py (scriptfiles): Split windows-specific stuff over to a | |
1991 | separate file, in an attempt to have a Windows GUI installer. |
|
2027 | separate file, in an attempt to have a Windows GUI installer. | |
1992 | That didn't work, but part of the groundwork is done. |
|
2028 | That didn't work, but part of the groundwork is done. | |
1993 |
|
2029 | |||
1994 | * IPython/UserConfig/ipythonrc: Added M-i, M-o and M-I for |
|
2030 | * IPython/UserConfig/ipythonrc: Added M-i, M-o and M-I for | |
1995 | indent/unindent with 4 spaces. Particularly useful in combination |
|
2031 | indent/unindent with 4 spaces. Particularly useful in combination | |
1996 | with the new auto-indent option. |
|
2032 | with the new auto-indent option. | |
1997 |
|
2033 | |||
1998 | 2003-04-16 Fernando Perez <fperez@colorado.edu> |
|
2034 | 2003-04-16 Fernando Perez <fperez@colorado.edu> | |
1999 |
|
2035 | |||
2000 | * IPython/Magic.py: various replacements of self.rc for |
|
2036 | * IPython/Magic.py: various replacements of self.rc for | |
2001 | self.shell.rc. A lot more remains to be done to fully disentangle |
|
2037 | self.shell.rc. A lot more remains to be done to fully disentangle | |
2002 | this class from the main Shell class. |
|
2038 | this class from the main Shell class. | |
2003 |
|
2039 | |||
2004 | * IPython/GnuplotRuntime.py: added checks for mouse support so |
|
2040 | * IPython/GnuplotRuntime.py: added checks for mouse support so | |
2005 | that we don't try to enable it if the current gnuplot doesn't |
|
2041 | that we don't try to enable it if the current gnuplot doesn't | |
2006 | really support it. Also added checks so that we don't try to |
|
2042 | really support it. Also added checks so that we don't try to | |
2007 | enable persist under Windows (where Gnuplot doesn't recognize the |
|
2043 | enable persist under Windows (where Gnuplot doesn't recognize the | |
2008 | option). |
|
2044 | option). | |
2009 |
|
2045 | |||
2010 | * IPython/iplib.py (InteractiveShell.interact): Added optional |
|
2046 | * IPython/iplib.py (InteractiveShell.interact): Added optional | |
2011 | auto-indenting code, after a patch by King C. Shu |
|
2047 | auto-indenting code, after a patch by King C. Shu | |
2012 | <kingshu-AT-myrealbox.com>. It's off by default because it doesn't |
|
2048 | <kingshu-AT-myrealbox.com>. It's off by default because it doesn't | |
2013 | get along well with pasting indented code. If I ever figure out |
|
2049 | get along well with pasting indented code. If I ever figure out | |
2014 | how to make that part go well, it will become on by default. |
|
2050 | how to make that part go well, it will become on by default. | |
2015 |
|
2051 | |||
2016 | * IPython/Prompts.py (Prompt1.auto_rewrite): Fixed bug which would |
|
2052 | * IPython/Prompts.py (Prompt1.auto_rewrite): Fixed bug which would | |
2017 | crash ipython if there was an unmatched '%' in the user's prompt |
|
2053 | crash ipython if there was an unmatched '%' in the user's prompt | |
2018 | string. Reported by Thorsten Kampe <thorsten-AT-thorstenkampe.de>. |
|
2054 | string. Reported by Thorsten Kampe <thorsten-AT-thorstenkampe.de>. | |
2019 |
|
2055 | |||
2020 | * IPython/iplib.py (InteractiveShell.interact): removed the |
|
2056 | * IPython/iplib.py (InteractiveShell.interact): removed the | |
2021 | ability to ask the user whether he wants to crash or not at the |
|
2057 | ability to ask the user whether he wants to crash or not at the | |
2022 | 'last line' exception handler. Calling functions at that point |
|
2058 | 'last line' exception handler. Calling functions at that point | |
2023 | changes the stack, and the error reports would have incorrect |
|
2059 | changes the stack, and the error reports would have incorrect | |
2024 | tracebacks. |
|
2060 | tracebacks. | |
2025 |
|
2061 | |||
2026 | * IPython/Magic.py (Magic.magic_page): Added new @page magic, to |
|
2062 | * IPython/Magic.py (Magic.magic_page): Added new @page magic, to | |
2027 | pass through a peger a pretty-printed form of any object. After a |
|
2063 | pass through a peger a pretty-printed form of any object. After a | |
2028 | contribution by Olivier Aubert <oaubert-AT-bat710.univ-lyon1.fr> |
|
2064 | contribution by Olivier Aubert <oaubert-AT-bat710.univ-lyon1.fr> | |
2029 |
|
2065 | |||
2030 | 2003-04-14 Fernando Perez <fperez@colorado.edu> |
|
2066 | 2003-04-14 Fernando Perez <fperez@colorado.edu> | |
2031 |
|
2067 | |||
2032 | * IPython/iplib.py (InteractiveShell.user_setup): Fixed bug where |
|
2068 | * IPython/iplib.py (InteractiveShell.user_setup): Fixed bug where | |
2033 | all files in ~ would be modified at first install (instead of |
|
2069 | all files in ~ would be modified at first install (instead of | |
2034 | ~/.ipython). This could be potentially disastrous, as the |
|
2070 | ~/.ipython). This could be potentially disastrous, as the | |
2035 | modification (make line-endings native) could damage binary files. |
|
2071 | modification (make line-endings native) could damage binary files. | |
2036 |
|
2072 | |||
2037 | 2003-04-10 Fernando Perez <fperez@colorado.edu> |
|
2073 | 2003-04-10 Fernando Perez <fperez@colorado.edu> | |
2038 |
|
2074 | |||
2039 | * IPython/iplib.py (InteractiveShell.handle_help): Modified to |
|
2075 | * IPython/iplib.py (InteractiveShell.handle_help): Modified to | |
2040 | handle only lines which are invalid python. This now means that |
|
2076 | handle only lines which are invalid python. This now means that | |
2041 | lines like 'x=1 #?' execute properly. Thanks to Jeffery Collins |
|
2077 | lines like 'x=1 #?' execute properly. Thanks to Jeffery Collins | |
2042 | for the bug report. |
|
2078 | for the bug report. | |
2043 |
|
2079 | |||
2044 | 2003-04-01 Fernando Perez <fperez@colorado.edu> |
|
2080 | 2003-04-01 Fernando Perez <fperez@colorado.edu> | |
2045 |
|
2081 | |||
2046 | * IPython/iplib.py (InteractiveShell.showtraceback): Fixed bug |
|
2082 | * IPython/iplib.py (InteractiveShell.showtraceback): Fixed bug | |
2047 | where failing to set sys.last_traceback would crash pdb.pm(). |
|
2083 | where failing to set sys.last_traceback would crash pdb.pm(). | |
2048 | Thanks to Jeffery D. Collins <Jeff.Collins-AT-vexcel.com> for the bug |
|
2084 | Thanks to Jeffery D. Collins <Jeff.Collins-AT-vexcel.com> for the bug | |
2049 | report. |
|
2085 | report. | |
2050 |
|
2086 | |||
2051 | 2003-03-25 Fernando Perez <fperez@colorado.edu> |
|
2087 | 2003-03-25 Fernando Perez <fperez@colorado.edu> | |
2052 |
|
2088 | |||
2053 | * IPython/Magic.py (Magic.magic_prun): rstrip() output of profiler |
|
2089 | * IPython/Magic.py (Magic.magic_prun): rstrip() output of profiler | |
2054 | before printing it (it had a lot of spurious blank lines at the |
|
2090 | before printing it (it had a lot of spurious blank lines at the | |
2055 | end). |
|
2091 | end). | |
2056 |
|
2092 | |||
2057 | * IPython/Gnuplot2.py (Gnuplot.hardcopy): fixed bug where lpr |
|
2093 | * IPython/Gnuplot2.py (Gnuplot.hardcopy): fixed bug where lpr | |
2058 | output would be sent 21 times! Obviously people don't use this |
|
2094 | output would be sent 21 times! Obviously people don't use this | |
2059 | too often, or I would have heard about it. |
|
2095 | too often, or I would have heard about it. | |
2060 |
|
2096 | |||
2061 | 2003-03-24 Fernando Perez <fperez@colorado.edu> |
|
2097 | 2003-03-24 Fernando Perez <fperez@colorado.edu> | |
2062 |
|
2098 | |||
2063 | * setup.py (scriptfiles): renamed the data_files parameter from |
|
2099 | * setup.py (scriptfiles): renamed the data_files parameter from | |
2064 | 'base' to 'data' to fix rpm build issues. Thanks to Ralf Ahlbrink |
|
2100 | 'base' to 'data' to fix rpm build issues. Thanks to Ralf Ahlbrink | |
2065 | for the patch. |
|
2101 | for the patch. | |
2066 |
|
2102 | |||
2067 | 2003-03-20 Fernando Perez <fperez@colorado.edu> |
|
2103 | 2003-03-20 Fernando Perez <fperez@colorado.edu> | |
2068 |
|
2104 | |||
2069 | * IPython/genutils.py (error): added error() and fatal() |
|
2105 | * IPython/genutils.py (error): added error() and fatal() | |
2070 | functions. |
|
2106 | functions. | |
2071 |
|
2107 | |||
2072 | 2003-03-18 *** Released version 0.2.15pre3 |
|
2108 | 2003-03-18 *** Released version 0.2.15pre3 | |
2073 |
|
2109 | |||
2074 | 2003-03-18 Fernando Perez <fperez@colorado.edu> |
|
2110 | 2003-03-18 Fernando Perez <fperez@colorado.edu> | |
2075 |
|
2111 | |||
2076 | * setupext/install_data_ext.py |
|
2112 | * setupext/install_data_ext.py | |
2077 | (install_data_ext.initialize_options): Class contributed by Jack |
|
2113 | (install_data_ext.initialize_options): Class contributed by Jack | |
2078 | Moffit for fixing the old distutils hack. He is sending this to |
|
2114 | Moffit for fixing the old distutils hack. He is sending this to | |
2079 | the distutils folks so in the future we may not need it as a |
|
2115 | the distutils folks so in the future we may not need it as a | |
2080 | private fix. |
|
2116 | private fix. | |
2081 |
|
2117 | |||
2082 | * MANIFEST.in: Extensive reorganization, based on Jack Moffit's |
|
2118 | * MANIFEST.in: Extensive reorganization, based on Jack Moffit's | |
2083 | changes for Debian packaging. See his patch for full details. |
|
2119 | changes for Debian packaging. See his patch for full details. | |
2084 | The old distutils hack of making the ipythonrc* files carry a |
|
2120 | The old distutils hack of making the ipythonrc* files carry a | |
2085 | bogus .py extension is gone, at last. Examples were moved to a |
|
2121 | bogus .py extension is gone, at last. Examples were moved to a | |
2086 | separate subdir under doc/, and the separate executable scripts |
|
2122 | separate subdir under doc/, and the separate executable scripts | |
2087 | now live in their own directory. Overall a great cleanup. The |
|
2123 | now live in their own directory. Overall a great cleanup. The | |
2088 | manual was updated to use the new files, and setup.py has been |
|
2124 | manual was updated to use the new files, and setup.py has been | |
2089 | fixed for this setup. |
|
2125 | fixed for this setup. | |
2090 |
|
2126 | |||
2091 | * IPython/PyColorize.py (Parser.usage): made non-executable and |
|
2127 | * IPython/PyColorize.py (Parser.usage): made non-executable and | |
2092 | created a pycolor wrapper around it to be included as a script. |
|
2128 | created a pycolor wrapper around it to be included as a script. | |
2093 |
|
2129 | |||
2094 | 2003-03-12 *** Released version 0.2.15pre2 |
|
2130 | 2003-03-12 *** Released version 0.2.15pre2 | |
2095 |
|
2131 | |||
2096 | 2003-03-12 Fernando Perez <fperez@colorado.edu> |
|
2132 | 2003-03-12 Fernando Perez <fperez@colorado.edu> | |
2097 |
|
2133 | |||
2098 | * IPython/ColorANSI.py (make_color_table): Finally fixed the |
|
2134 | * IPython/ColorANSI.py (make_color_table): Finally fixed the | |
2099 | long-standing problem with garbage characters in some terminals. |
|
2135 | long-standing problem with garbage characters in some terminals. | |
2100 | The issue was really that the \001 and \002 escapes must _only_ be |
|
2136 | The issue was really that the \001 and \002 escapes must _only_ be | |
2101 | passed to input prompts (which call readline), but _never_ to |
|
2137 | passed to input prompts (which call readline), but _never_ to | |
2102 | normal text to be printed on screen. I changed ColorANSI to have |
|
2138 | normal text to be printed on screen. I changed ColorANSI to have | |
2103 | two classes: TermColors and InputTermColors, each with the |
|
2139 | two classes: TermColors and InputTermColors, each with the | |
2104 | appropriate escapes for input prompts or normal text. The code in |
|
2140 | appropriate escapes for input prompts or normal text. The code in | |
2105 | Prompts.py got slightly more complicated, but this very old and |
|
2141 | Prompts.py got slightly more complicated, but this very old and | |
2106 | annoying bug is finally fixed. |
|
2142 | annoying bug is finally fixed. | |
2107 |
|
2143 | |||
2108 | All the credit for nailing down the real origin of this problem |
|
2144 | All the credit for nailing down the real origin of this problem | |
2109 | and the correct solution goes to Jack Moffit <jack-AT-xiph.org>. |
|
2145 | and the correct solution goes to Jack Moffit <jack-AT-xiph.org>. | |
2110 | *Many* thanks to him for spending quite a bit of effort on this. |
|
2146 | *Many* thanks to him for spending quite a bit of effort on this. | |
2111 |
|
2147 | |||
2112 | 2003-03-05 *** Released version 0.2.15pre1 |
|
2148 | 2003-03-05 *** Released version 0.2.15pre1 | |
2113 |
|
2149 | |||
2114 | 2003-03-03 Fernando Perez <fperez@colorado.edu> |
|
2150 | 2003-03-03 Fernando Perez <fperez@colorado.edu> | |
2115 |
|
2151 | |||
2116 | * IPython/FakeModule.py: Moved the former _FakeModule to a |
|
2152 | * IPython/FakeModule.py: Moved the former _FakeModule to a | |
2117 | separate file, because it's also needed by Magic (to fix a similar |
|
2153 | separate file, because it's also needed by Magic (to fix a similar | |
2118 | pickle-related issue in @run). |
|
2154 | pickle-related issue in @run). | |
2119 |
|
2155 | |||
2120 | 2003-03-02 Fernando Perez <fperez@colorado.edu> |
|
2156 | 2003-03-02 Fernando Perez <fperez@colorado.edu> | |
2121 |
|
2157 | |||
2122 | * IPython/Magic.py (Magic.magic_autocall): new magic to control |
|
2158 | * IPython/Magic.py (Magic.magic_autocall): new magic to control | |
2123 | the autocall option at runtime. |
|
2159 | the autocall option at runtime. | |
2124 | (Magic.magic_dhist): changed self.user_ns to self.shell.user_ns |
|
2160 | (Magic.magic_dhist): changed self.user_ns to self.shell.user_ns | |
2125 | across Magic.py to start separating Magic from InteractiveShell. |
|
2161 | across Magic.py to start separating Magic from InteractiveShell. | |
2126 | (Magic._ofind): Fixed to return proper namespace for dotted |
|
2162 | (Magic._ofind): Fixed to return proper namespace for dotted | |
2127 | names. Before, a dotted name would always return 'not currently |
|
2163 | names. Before, a dotted name would always return 'not currently | |
2128 | defined', because it would find the 'parent'. s.x would be found, |
|
2164 | defined', because it would find the 'parent'. s.x would be found, | |
2129 | but since 'x' isn't defined by itself, it would get confused. |
|
2165 | but since 'x' isn't defined by itself, it would get confused. | |
2130 | (Magic.magic_run): Fixed pickling problems reported by Ralf |
|
2166 | (Magic.magic_run): Fixed pickling problems reported by Ralf | |
2131 | Ahlbrink <RAhlbrink-AT-RosenInspection.net>. The fix was similar to |
|
2167 | Ahlbrink <RAhlbrink-AT-RosenInspection.net>. The fix was similar to | |
2132 | that I'd used when Mike Heeter reported similar issues at the |
|
2168 | that I'd used when Mike Heeter reported similar issues at the | |
2133 | top-level, but now for @run. It boils down to injecting the |
|
2169 | top-level, but now for @run. It boils down to injecting the | |
2134 | namespace where code is being executed with something that looks |
|
2170 | namespace where code is being executed with something that looks | |
2135 | enough like a module to fool pickle.dump(). Since a pickle stores |
|
2171 | enough like a module to fool pickle.dump(). Since a pickle stores | |
2136 | a named reference to the importing module, we need this for |
|
2172 | a named reference to the importing module, we need this for | |
2137 | pickles to save something sensible. |
|
2173 | pickles to save something sensible. | |
2138 |
|
2174 | |||
2139 | * IPython/ipmaker.py (make_IPython): added an autocall option. |
|
2175 | * IPython/ipmaker.py (make_IPython): added an autocall option. | |
2140 |
|
2176 | |||
2141 | * IPython/iplib.py (InteractiveShell._prefilter): reordered all of |
|
2177 | * IPython/iplib.py (InteractiveShell._prefilter): reordered all of | |
2142 | the auto-eval code. Now autocalling is an option, and the code is |
|
2178 | the auto-eval code. Now autocalling is an option, and the code is | |
2143 | also vastly safer. There is no more eval() involved at all. |
|
2179 | also vastly safer. There is no more eval() involved at all. | |
2144 |
|
2180 | |||
2145 | 2003-03-01 Fernando Perez <fperez@colorado.edu> |
|
2181 | 2003-03-01 Fernando Perez <fperez@colorado.edu> | |
2146 |
|
2182 | |||
2147 | * IPython/Magic.py (Magic._ofind): Changed interface to return a |
|
2183 | * IPython/Magic.py (Magic._ofind): Changed interface to return a | |
2148 | dict with named keys instead of a tuple. |
|
2184 | dict with named keys instead of a tuple. | |
2149 |
|
2185 | |||
2150 | * IPython: Started using CVS for IPython as of 0.2.15pre1. |
|
2186 | * IPython: Started using CVS for IPython as of 0.2.15pre1. | |
2151 |
|
2187 | |||
2152 | * setup.py (make_shortcut): Fixed message about directories |
|
2188 | * setup.py (make_shortcut): Fixed message about directories | |
2153 | created during Windows installation (the directories were ok, just |
|
2189 | created during Windows installation (the directories were ok, just | |
2154 | the printed message was misleading). Thanks to Chris Liechti |
|
2190 | the printed message was misleading). Thanks to Chris Liechti | |
2155 | <cliechti-AT-gmx.net> for the heads up. |
|
2191 | <cliechti-AT-gmx.net> for the heads up. | |
2156 |
|
2192 | |||
2157 | 2003-02-21 Fernando Perez <fperez@colorado.edu> |
|
2193 | 2003-02-21 Fernando Perez <fperez@colorado.edu> | |
2158 |
|
2194 | |||
2159 | * IPython/iplib.py (InteractiveShell._prefilter): Fixed catching |
|
2195 | * IPython/iplib.py (InteractiveShell._prefilter): Fixed catching | |
2160 | of ValueError exception when checking for auto-execution. This |
|
2196 | of ValueError exception when checking for auto-execution. This | |
2161 | one is raised by things like Numeric arrays arr.flat when the |
|
2197 | one is raised by things like Numeric arrays arr.flat when the | |
2162 | array is non-contiguous. |
|
2198 | array is non-contiguous. | |
2163 |
|
2199 | |||
2164 | 2003-01-31 Fernando Perez <fperez@colorado.edu> |
|
2200 | 2003-01-31 Fernando Perez <fperez@colorado.edu> | |
2165 |
|
2201 | |||
2166 | * IPython/genutils.py (SystemExec.bq): Fixed bug where bq would |
|
2202 | * IPython/genutils.py (SystemExec.bq): Fixed bug where bq would | |
2167 | not return any value at all (even though the command would get |
|
2203 | not return any value at all (even though the command would get | |
2168 | executed). |
|
2204 | executed). | |
2169 | (xsys): Flush stdout right after printing the command to ensure |
|
2205 | (xsys): Flush stdout right after printing the command to ensure | |
2170 | proper ordering of commands and command output in the total |
|
2206 | proper ordering of commands and command output in the total | |
2171 | output. |
|
2207 | output. | |
2172 | (SystemExec/xsys/bq): Switched the names of xsys/bq and |
|
2208 | (SystemExec/xsys/bq): Switched the names of xsys/bq and | |
2173 | system/getoutput as defaults. The old ones are kept for |
|
2209 | system/getoutput as defaults. The old ones are kept for | |
2174 | compatibility reasons, so no code which uses this library needs |
|
2210 | compatibility reasons, so no code which uses this library needs | |
2175 | changing. |
|
2211 | changing. | |
2176 |
|
2212 | |||
2177 | 2003-01-27 *** Released version 0.2.14 |
|
2213 | 2003-01-27 *** Released version 0.2.14 | |
2178 |
|
2214 | |||
2179 | 2003-01-25 Fernando Perez <fperez@colorado.edu> |
|
2215 | 2003-01-25 Fernando Perez <fperez@colorado.edu> | |
2180 |
|
2216 | |||
2181 | * IPython/Magic.py (Magic.magic_edit): Fixed problem where |
|
2217 | * IPython/Magic.py (Magic.magic_edit): Fixed problem where | |
2182 | functions defined in previous edit sessions could not be re-edited |
|
2218 | functions defined in previous edit sessions could not be re-edited | |
2183 | (because the temp files were immediately removed). Now temp files |
|
2219 | (because the temp files were immediately removed). Now temp files | |
2184 | are removed only at IPython's exit. |
|
2220 | are removed only at IPython's exit. | |
2185 | (Magic.magic_run): Improved @run to perform shell-like expansions |
|
2221 | (Magic.magic_run): Improved @run to perform shell-like expansions | |
2186 | on its arguments (~users and $VARS). With this, @run becomes more |
|
2222 | on its arguments (~users and $VARS). With this, @run becomes more | |
2187 | like a normal command-line. |
|
2223 | like a normal command-line. | |
2188 |
|
2224 | |||
2189 | * IPython/Shell.py (IPShellEmbed.__call__): Fixed a bunch of small |
|
2225 | * IPython/Shell.py (IPShellEmbed.__call__): Fixed a bunch of small | |
2190 | bugs related to embedding and cleaned up that code. A fairly |
|
2226 | bugs related to embedding and cleaned up that code. A fairly | |
2191 | important one was the impossibility to access the global namespace |
|
2227 | important one was the impossibility to access the global namespace | |
2192 | through the embedded IPython (only local variables were visible). |
|
2228 | through the embedded IPython (only local variables were visible). | |
2193 |
|
2229 | |||
2194 | 2003-01-14 Fernando Perez <fperez@colorado.edu> |
|
2230 | 2003-01-14 Fernando Perez <fperez@colorado.edu> | |
2195 |
|
2231 | |||
2196 | * IPython/iplib.py (InteractiveShell._prefilter): Fixed |
|
2232 | * IPython/iplib.py (InteractiveShell._prefilter): Fixed | |
2197 | auto-calling to be a bit more conservative. Now it doesn't get |
|
2233 | auto-calling to be a bit more conservative. Now it doesn't get | |
2198 | triggered if any of '!=()<>' are in the rest of the input line, to |
|
2234 | triggered if any of '!=()<>' are in the rest of the input line, to | |
2199 | allow comparing callables. Thanks to Alex for the heads up. |
|
2235 | allow comparing callables. Thanks to Alex for the heads up. | |
2200 |
|
2236 | |||
2201 | 2003-01-07 Fernando Perez <fperez@colorado.edu> |
|
2237 | 2003-01-07 Fernando Perez <fperez@colorado.edu> | |
2202 |
|
2238 | |||
2203 | * IPython/genutils.py (page): fixed estimation of the number of |
|
2239 | * IPython/genutils.py (page): fixed estimation of the number of | |
2204 | lines in a string to be paged to simply count newlines. This |
|
2240 | lines in a string to be paged to simply count newlines. This | |
2205 | prevents over-guessing due to embedded escape sequences. A better |
|
2241 | prevents over-guessing due to embedded escape sequences. A better | |
2206 | long-term solution would involve stripping out the control chars |
|
2242 | long-term solution would involve stripping out the control chars | |
2207 | for the count, but it's potentially so expensive I just don't |
|
2243 | for the count, but it's potentially so expensive I just don't | |
2208 | think it's worth doing. |
|
2244 | think it's worth doing. | |
2209 |
|
2245 | |||
2210 | 2002-12-19 *** Released version 0.2.14pre50 |
|
2246 | 2002-12-19 *** Released version 0.2.14pre50 | |
2211 |
|
2247 | |||
2212 | 2002-12-19 Fernando Perez <fperez@colorado.edu> |
|
2248 | 2002-12-19 Fernando Perez <fperez@colorado.edu> | |
2213 |
|
2249 | |||
2214 | * tools/release (version): Changed release scripts to inform |
|
2250 | * tools/release (version): Changed release scripts to inform | |
2215 | Andrea and build a NEWS file with a list of recent changes. |
|
2251 | Andrea and build a NEWS file with a list of recent changes. | |
2216 |
|
2252 | |||
2217 | * IPython/ColorANSI.py (__all__): changed terminal detection |
|
2253 | * IPython/ColorANSI.py (__all__): changed terminal detection | |
2218 | code. Seems to work better for xterms without breaking |
|
2254 | code. Seems to work better for xterms without breaking | |
2219 | konsole. Will need more testing to determine if WinXP and Mac OSX |
|
2255 | konsole. Will need more testing to determine if WinXP and Mac OSX | |
2220 | also work ok. |
|
2256 | also work ok. | |
2221 |
|
2257 | |||
2222 | 2002-12-18 *** Released version 0.2.14pre49 |
|
2258 | 2002-12-18 *** Released version 0.2.14pre49 | |
2223 |
|
2259 | |||
2224 | 2002-12-18 Fernando Perez <fperez@colorado.edu> |
|
2260 | 2002-12-18 Fernando Perez <fperez@colorado.edu> | |
2225 |
|
2261 | |||
2226 | * Docs: added new info about Mac OSX, from Andrea. |
|
2262 | * Docs: added new info about Mac OSX, from Andrea. | |
2227 |
|
2263 | |||
2228 | * IPython/Gnuplot2.py (String): Added a String PlotItem class to |
|
2264 | * IPython/Gnuplot2.py (String): Added a String PlotItem class to | |
2229 | allow direct plotting of python strings whose format is the same |
|
2265 | allow direct plotting of python strings whose format is the same | |
2230 | of gnuplot data files. |
|
2266 | of gnuplot data files. | |
2231 |
|
2267 | |||
2232 | 2002-12-16 Fernando Perez <fperez@colorado.edu> |
|
2268 | 2002-12-16 Fernando Perez <fperez@colorado.edu> | |
2233 |
|
2269 | |||
2234 | * IPython/iplib.py (InteractiveShell.interact): fixed default (y) |
|
2270 | * IPython/iplib.py (InteractiveShell.interact): fixed default (y) | |
2235 | value of exit question to be acknowledged. |
|
2271 | value of exit question to be acknowledged. | |
2236 |
|
2272 | |||
2237 | 2002-12-03 Fernando Perez <fperez@colorado.edu> |
|
2273 | 2002-12-03 Fernando Perez <fperez@colorado.edu> | |
2238 |
|
2274 | |||
2239 | * IPython/ipmaker.py: removed generators, which had been added |
|
2275 | * IPython/ipmaker.py: removed generators, which had been added | |
2240 | by mistake in an earlier debugging run. This was causing trouble |
|
2276 | by mistake in an earlier debugging run. This was causing trouble | |
2241 | to users of python 2.1.x. Thanks to Abel Daniel <abli-AT-freemail.hu> |
|
2277 | to users of python 2.1.x. Thanks to Abel Daniel <abli-AT-freemail.hu> | |
2242 | for pointing this out. |
|
2278 | for pointing this out. | |
2243 |
|
2279 | |||
2244 | 2002-11-17 Fernando Perez <fperez@colorado.edu> |
|
2280 | 2002-11-17 Fernando Perez <fperez@colorado.edu> | |
2245 |
|
2281 | |||
2246 | * Manual: updated the Gnuplot section. |
|
2282 | * Manual: updated the Gnuplot section. | |
2247 |
|
2283 | |||
2248 | * IPython/GnuplotRuntime.py: refactored a lot all this code, with |
|
2284 | * IPython/GnuplotRuntime.py: refactored a lot all this code, with | |
2249 | a much better split of what goes in Runtime and what goes in |
|
2285 | a much better split of what goes in Runtime and what goes in | |
2250 | Interactive. |
|
2286 | Interactive. | |
2251 |
|
2287 | |||
2252 | * IPython/ipmaker.py: fixed bug where import_fail_info wasn't |
|
2288 | * IPython/ipmaker.py: fixed bug where import_fail_info wasn't | |
2253 | being imported from iplib. |
|
2289 | being imported from iplib. | |
2254 |
|
2290 | |||
2255 | * IPython/GnuplotInteractive.py (magic_gpc): renamed @gp to @gpc |
|
2291 | * IPython/GnuplotInteractive.py (magic_gpc): renamed @gp to @gpc | |
2256 | for command-passing. Now the global Gnuplot instance is called |
|
2292 | for command-passing. Now the global Gnuplot instance is called | |
2257 | 'gp' instead of 'g', which was really a far too fragile and |
|
2293 | 'gp' instead of 'g', which was really a far too fragile and | |
2258 | common name. |
|
2294 | common name. | |
2259 |
|
2295 | |||
2260 | * IPython/Gnuplot2.py (eps_fix_bbox): added this to fix broken |
|
2296 | * IPython/Gnuplot2.py (eps_fix_bbox): added this to fix broken | |
2261 | bounding boxes generated by Gnuplot for square plots. |
|
2297 | bounding boxes generated by Gnuplot for square plots. | |
2262 |
|
2298 | |||
2263 | * IPython/genutils.py (popkey): new function added. I should |
|
2299 | * IPython/genutils.py (popkey): new function added. I should | |
2264 | suggest this on c.l.py as a dict method, it seems useful. |
|
2300 | suggest this on c.l.py as a dict method, it seems useful. | |
2265 |
|
2301 | |||
2266 | * IPython/Gnuplot2.py (Gnuplot.plot): Overhauled plot and replot |
|
2302 | * IPython/Gnuplot2.py (Gnuplot.plot): Overhauled plot and replot | |
2267 | to transparently handle PostScript generation. MUCH better than |
|
2303 | to transparently handle PostScript generation. MUCH better than | |
2268 | the previous plot_eps/replot_eps (which I removed now). The code |
|
2304 | the previous plot_eps/replot_eps (which I removed now). The code | |
2269 | is also fairly clean and well documented now (including |
|
2305 | is also fairly clean and well documented now (including | |
2270 | docstrings). |
|
2306 | docstrings). | |
2271 |
|
2307 | |||
2272 | 2002-11-13 Fernando Perez <fperez@colorado.edu> |
|
2308 | 2002-11-13 Fernando Perez <fperez@colorado.edu> | |
2273 |
|
2309 | |||
2274 | * IPython/Magic.py (Magic.magic_edit): fixed docstring |
|
2310 | * IPython/Magic.py (Magic.magic_edit): fixed docstring | |
2275 | (inconsistent with options). |
|
2311 | (inconsistent with options). | |
2276 |
|
2312 | |||
2277 | * IPython/Gnuplot2.py (Gnuplot.hardcopy): hardcopy had been |
|
2313 | * IPython/Gnuplot2.py (Gnuplot.hardcopy): hardcopy had been | |
2278 | manually disabled, I don't know why. Fixed it. |
|
2314 | manually disabled, I don't know why. Fixed it. | |
2279 | (Gnuplot._plot_eps): added new plot_eps/replot_eps to get directly |
|
2315 | (Gnuplot._plot_eps): added new plot_eps/replot_eps to get directly | |
2280 | eps output. |
|
2316 | eps output. | |
2281 |
|
2317 | |||
2282 | 2002-11-12 Fernando Perez <fperez@colorado.edu> |
|
2318 | 2002-11-12 Fernando Perez <fperez@colorado.edu> | |
2283 |
|
2319 | |||
2284 | * IPython/genutils.py (ask_yes_no): trap EOF and ^C so that they |
|
2320 | * IPython/genutils.py (ask_yes_no): trap EOF and ^C so that they | |
2285 | don't propagate up to caller. Fixes crash reported by François |
|
2321 | don't propagate up to caller. Fixes crash reported by François | |
2286 | Pinard. |
|
2322 | Pinard. | |
2287 |
|
2323 | |||
2288 | 2002-11-09 Fernando Perez <fperez@colorado.edu> |
|
2324 | 2002-11-09 Fernando Perez <fperez@colorado.edu> | |
2289 |
|
2325 | |||
2290 | * IPython/ipmaker.py (make_IPython): fixed problem with writing |
|
2326 | * IPython/ipmaker.py (make_IPython): fixed problem with writing | |
2291 | history file for new users. |
|
2327 | history file for new users. | |
2292 | (make_IPython): fixed bug where initial install would leave the |
|
2328 | (make_IPython): fixed bug where initial install would leave the | |
2293 | user running in the .ipython dir. |
|
2329 | user running in the .ipython dir. | |
2294 | (make_IPython): fixed bug where config dir .ipython would be |
|
2330 | (make_IPython): fixed bug where config dir .ipython would be | |
2295 | created regardless of the given -ipythondir option. Thanks to Cory |
|
2331 | created regardless of the given -ipythondir option. Thanks to Cory | |
2296 | Dodt <cdodt-AT-fcoe.k12.ca.us> for the bug report. |
|
2332 | Dodt <cdodt-AT-fcoe.k12.ca.us> for the bug report. | |
2297 |
|
2333 | |||
2298 | * IPython/genutils.py (ask_yes_no): new function for asking yes/no |
|
2334 | * IPython/genutils.py (ask_yes_no): new function for asking yes/no | |
2299 | type confirmations. Will need to use it in all of IPython's code |
|
2335 | type confirmations. Will need to use it in all of IPython's code | |
2300 | consistently. |
|
2336 | consistently. | |
2301 |
|
2337 | |||
2302 | * IPython/CrashHandler.py (CrashHandler.__call__): changed the |
|
2338 | * IPython/CrashHandler.py (CrashHandler.__call__): changed the | |
2303 | context to print 31 lines instead of the default 5. This will make |
|
2339 | context to print 31 lines instead of the default 5. This will make | |
2304 | the crash reports extremely detailed in case the problem is in |
|
2340 | the crash reports extremely detailed in case the problem is in | |
2305 | libraries I don't have access to. |
|
2341 | libraries I don't have access to. | |
2306 |
|
2342 | |||
2307 | * IPython/iplib.py (InteractiveShell.interact): changed the 'last |
|
2343 | * IPython/iplib.py (InteractiveShell.interact): changed the 'last | |
2308 | line of defense' code to still crash, but giving users fair |
|
2344 | line of defense' code to still crash, but giving users fair | |
2309 | warning. I don't want internal errors to go unreported: if there's |
|
2345 | warning. I don't want internal errors to go unreported: if there's | |
2310 | an internal problem, IPython should crash and generate a full |
|
2346 | an internal problem, IPython should crash and generate a full | |
2311 | report. |
|
2347 | report. | |
2312 |
|
2348 | |||
2313 | 2002-11-08 Fernando Perez <fperez@colorado.edu> |
|
2349 | 2002-11-08 Fernando Perez <fperez@colorado.edu> | |
2314 |
|
2350 | |||
2315 | * IPython/iplib.py (InteractiveShell.interact): added code to trap |
|
2351 | * IPython/iplib.py (InteractiveShell.interact): added code to trap | |
2316 | otherwise uncaught exceptions which can appear if people set |
|
2352 | otherwise uncaught exceptions which can appear if people set | |
2317 | sys.stdout to something badly broken. Thanks to a crash report |
|
2353 | sys.stdout to something badly broken. Thanks to a crash report | |
2318 | from henni-AT-mail.brainbot.com. |
|
2354 | from henni-AT-mail.brainbot.com. | |
2319 |
|
2355 | |||
2320 | 2002-11-04 Fernando Perez <fperez@colorado.edu> |
|
2356 | 2002-11-04 Fernando Perez <fperez@colorado.edu> | |
2321 |
|
2357 | |||
2322 | * IPython/iplib.py (InteractiveShell.interact): added |
|
2358 | * IPython/iplib.py (InteractiveShell.interact): added | |
2323 | __IPYTHON__active to the builtins. It's a flag which goes on when |
|
2359 | __IPYTHON__active to the builtins. It's a flag which goes on when | |
2324 | the interaction starts and goes off again when it stops. This |
|
2360 | the interaction starts and goes off again when it stops. This | |
2325 | allows embedding code to detect being inside IPython. Before this |
|
2361 | allows embedding code to detect being inside IPython. Before this | |
2326 | was done via __IPYTHON__, but that only shows that an IPython |
|
2362 | was done via __IPYTHON__, but that only shows that an IPython | |
2327 | instance has been created. |
|
2363 | instance has been created. | |
2328 |
|
2364 | |||
2329 | * IPython/Magic.py (Magic.magic_env): I realized that in a |
|
2365 | * IPython/Magic.py (Magic.magic_env): I realized that in a | |
2330 | UserDict, instance.data holds the data as a normal dict. So I |
|
2366 | UserDict, instance.data holds the data as a normal dict. So I | |
2331 | modified @env to return os.environ.data instead of rebuilding a |
|
2367 | modified @env to return os.environ.data instead of rebuilding a | |
2332 | dict by hand. |
|
2368 | dict by hand. | |
2333 |
|
2369 | |||
2334 | 2002-11-02 Fernando Perez <fperez@colorado.edu> |
|
2370 | 2002-11-02 Fernando Perez <fperez@colorado.edu> | |
2335 |
|
2371 | |||
2336 | * IPython/genutils.py (warn): changed so that level 1 prints no |
|
2372 | * IPython/genutils.py (warn): changed so that level 1 prints no | |
2337 | header. Level 2 is now the default (with 'WARNING' header, as |
|
2373 | header. Level 2 is now the default (with 'WARNING' header, as | |
2338 | before). I think I tracked all places where changes were needed in |
|
2374 | before). I think I tracked all places where changes were needed in | |
2339 | IPython, but outside code using the old level numbering may have |
|
2375 | IPython, but outside code using the old level numbering may have | |
2340 | broken. |
|
2376 | broken. | |
2341 |
|
2377 | |||
2342 | * IPython/iplib.py (InteractiveShell.runcode): added this to |
|
2378 | * IPython/iplib.py (InteractiveShell.runcode): added this to | |
2343 | handle the tracebacks in SystemExit traps correctly. The previous |
|
2379 | handle the tracebacks in SystemExit traps correctly. The previous | |
2344 | code (through interact) was printing more of the stack than |
|
2380 | code (through interact) was printing more of the stack than | |
2345 | necessary, showing IPython internal code to the user. |
|
2381 | necessary, showing IPython internal code to the user. | |
2346 |
|
2382 | |||
2347 | * IPython/UserConfig/ipythonrc.py: Made confirm_exit 1 by |
|
2383 | * IPython/UserConfig/ipythonrc.py: Made confirm_exit 1 by | |
2348 | default. Now that the default at the confirmation prompt is yes, |
|
2384 | default. Now that the default at the confirmation prompt is yes, | |
2349 | it's not so intrusive. François' argument that ipython sessions |
|
2385 | it's not so intrusive. François' argument that ipython sessions | |
2350 | tend to be complex enough not to lose them from an accidental C-d, |
|
2386 | tend to be complex enough not to lose them from an accidental C-d, | |
2351 | is a valid one. |
|
2387 | is a valid one. | |
2352 |
|
2388 | |||
2353 | * IPython/iplib.py (InteractiveShell.interact): added a |
|
2389 | * IPython/iplib.py (InteractiveShell.interact): added a | |
2354 | showtraceback() call to the SystemExit trap, and modified the exit |
|
2390 | showtraceback() call to the SystemExit trap, and modified the exit | |
2355 | confirmation to have yes as the default. |
|
2391 | confirmation to have yes as the default. | |
2356 |
|
2392 | |||
2357 | * IPython/UserConfig/ipythonrc.py: removed 'session' option from |
|
2393 | * IPython/UserConfig/ipythonrc.py: removed 'session' option from | |
2358 | this file. It's been gone from the code for a long time, this was |
|
2394 | this file. It's been gone from the code for a long time, this was | |
2359 | simply leftover junk. |
|
2395 | simply leftover junk. | |
2360 |
|
2396 | |||
2361 | 2002-11-01 Fernando Perez <fperez@colorado.edu> |
|
2397 | 2002-11-01 Fernando Perez <fperez@colorado.edu> | |
2362 |
|
2398 | |||
2363 | * IPython/UserConfig/ipythonrc.py: new confirm_exit option |
|
2399 | * IPython/UserConfig/ipythonrc.py: new confirm_exit option | |
2364 | added. If set, IPython now traps EOF and asks for |
|
2400 | added. If set, IPython now traps EOF and asks for | |
2365 | confirmation. After a request by François Pinard. |
|
2401 | confirmation. After a request by François Pinard. | |
2366 |
|
2402 | |||
2367 | * IPython/Magic.py (Magic.magic_Exit): New @Exit and @Quit instead |
|
2403 | * IPython/Magic.py (Magic.magic_Exit): New @Exit and @Quit instead | |
2368 | of @abort, and with a new (better) mechanism for handling the |
|
2404 | of @abort, and with a new (better) mechanism for handling the | |
2369 | exceptions. |
|
2405 | exceptions. | |
2370 |
|
2406 | |||
2371 | 2002-10-27 Fernando Perez <fperez@colorado.edu> |
|
2407 | 2002-10-27 Fernando Perez <fperez@colorado.edu> | |
2372 |
|
2408 | |||
2373 | * IPython/usage.py (__doc__): updated the --help information and |
|
2409 | * IPython/usage.py (__doc__): updated the --help information and | |
2374 | the ipythonrc file to indicate that -log generates |
|
2410 | the ipythonrc file to indicate that -log generates | |
2375 | ./ipython.log. Also fixed the corresponding info in @logstart. |
|
2411 | ./ipython.log. Also fixed the corresponding info in @logstart. | |
2376 | This and several other fixes in the manuals thanks to reports by |
|
2412 | This and several other fixes in the manuals thanks to reports by | |
2377 | François Pinard <pinard-AT-iro.umontreal.ca>. |
|
2413 | François Pinard <pinard-AT-iro.umontreal.ca>. | |
2378 |
|
2414 | |||
2379 | * IPython/Logger.py (Logger.switch_log): Fixed error message to |
|
2415 | * IPython/Logger.py (Logger.switch_log): Fixed error message to | |
2380 | refer to @logstart (instead of @log, which doesn't exist). |
|
2416 | refer to @logstart (instead of @log, which doesn't exist). | |
2381 |
|
2417 | |||
2382 | * IPython/iplib.py (InteractiveShell._prefilter): fixed |
|
2418 | * IPython/iplib.py (InteractiveShell._prefilter): fixed | |
2383 | AttributeError crash. Thanks to Christopher Armstrong |
|
2419 | AttributeError crash. Thanks to Christopher Armstrong | |
2384 | <radix-AT-twistedmatrix.com> for the report/fix. This bug had been |
|
2420 | <radix-AT-twistedmatrix.com> for the report/fix. This bug had been | |
2385 | introduced recently (in 0.2.14pre37) with the fix to the eval |
|
2421 | introduced recently (in 0.2.14pre37) with the fix to the eval | |
2386 | problem mentioned below. |
|
2422 | problem mentioned below. | |
2387 |
|
2423 | |||
2388 | 2002-10-17 Fernando Perez <fperez@colorado.edu> |
|
2424 | 2002-10-17 Fernando Perez <fperez@colorado.edu> | |
2389 |
|
2425 | |||
2390 | * IPython/ConfigLoader.py (ConfigLoader.load): Fixes for Windows |
|
2426 | * IPython/ConfigLoader.py (ConfigLoader.load): Fixes for Windows | |
2391 | installation. Thanks to Leonardo Santagada <retype-AT-terra.com.br>. |
|
2427 | installation. Thanks to Leonardo Santagada <retype-AT-terra.com.br>. | |
2392 |
|
2428 | |||
2393 | * IPython/iplib.py (InteractiveShell._prefilter): Many changes to |
|
2429 | * IPython/iplib.py (InteractiveShell._prefilter): Many changes to | |
2394 | this function to fix a problem reported by Alex Schmolck. He saw |
|
2430 | this function to fix a problem reported by Alex Schmolck. He saw | |
2395 | it with list comprehensions and generators, which were getting |
|
2431 | it with list comprehensions and generators, which were getting | |
2396 | called twice. The real problem was an 'eval' call in testing for |
|
2432 | called twice. The real problem was an 'eval' call in testing for | |
2397 | automagic which was evaluating the input line silently. |
|
2433 | automagic which was evaluating the input line silently. | |
2398 |
|
2434 | |||
2399 | This is a potentially very nasty bug, if the input has side |
|
2435 | This is a potentially very nasty bug, if the input has side | |
2400 | effects which must not be repeated. The code is much cleaner now, |
|
2436 | effects which must not be repeated. The code is much cleaner now, | |
2401 | without any blanket 'except' left and with a regexp test for |
|
2437 | without any blanket 'except' left and with a regexp test for | |
2402 | actual function names. |
|
2438 | actual function names. | |
2403 |
|
2439 | |||
2404 | But an eval remains, which I'm not fully comfortable with. I just |
|
2440 | But an eval remains, which I'm not fully comfortable with. I just | |
2405 | don't know how to find out if an expression could be a callable in |
|
2441 | don't know how to find out if an expression could be a callable in | |
2406 | the user's namespace without doing an eval on the string. However |
|
2442 | the user's namespace without doing an eval on the string. However | |
2407 | that string is now much more strictly checked so that no code |
|
2443 | that string is now much more strictly checked so that no code | |
2408 | slips by, so the eval should only happen for things that can |
|
2444 | slips by, so the eval should only happen for things that can | |
2409 | really be only function/method names. |
|
2445 | really be only function/method names. | |
2410 |
|
2446 | |||
2411 | 2002-10-15 Fernando Perez <fperez@colorado.edu> |
|
2447 | 2002-10-15 Fernando Perez <fperez@colorado.edu> | |
2412 |
|
2448 | |||
2413 | * Updated LyX to 1.2.1 so I can work on the docs again. Added Mac |
|
2449 | * Updated LyX to 1.2.1 so I can work on the docs again. Added Mac | |
2414 | OSX information to main manual, removed README_Mac_OSX file from |
|
2450 | OSX information to main manual, removed README_Mac_OSX file from | |
2415 | distribution. Also updated credits for recent additions. |
|
2451 | distribution. Also updated credits for recent additions. | |
2416 |
|
2452 | |||
2417 | 2002-10-10 Fernando Perez <fperez@colorado.edu> |
|
2453 | 2002-10-10 Fernando Perez <fperez@colorado.edu> | |
2418 |
|
2454 | |||
2419 | * README_Mac_OSX: Added a README for Mac OSX users for fixing |
|
2455 | * README_Mac_OSX: Added a README for Mac OSX users for fixing | |
2420 | terminal-related issues. Many thanks to Andrea Riciputi |
|
2456 | terminal-related issues. Many thanks to Andrea Riciputi | |
2421 | <andrea.riciputi-AT-libero.it> for writing it. |
|
2457 | <andrea.riciputi-AT-libero.it> for writing it. | |
2422 |
|
2458 | |||
2423 | * IPython/UserConfig/ipythonrc.py: Fixes to various small issues, |
|
2459 | * IPython/UserConfig/ipythonrc.py: Fixes to various small issues, | |
2424 | thanks to Thorsten Kampe <thorsten-AT-thorstenkampe.de>. |
|
2460 | thanks to Thorsten Kampe <thorsten-AT-thorstenkampe.de>. | |
2425 |
|
2461 | |||
2426 | * setup.py (make_shortcut): Fixes for Windows installation. Thanks |
|
2462 | * setup.py (make_shortcut): Fixes for Windows installation. Thanks | |
2427 | to Fredrik Kant <fredrik.kant-AT-front.com> and Syver Enstad |
|
2463 | to Fredrik Kant <fredrik.kant-AT-front.com> and Syver Enstad | |
2428 | <syver-en-AT-online.no> who both submitted patches for this problem. |
|
2464 | <syver-en-AT-online.no> who both submitted patches for this problem. | |
2429 |
|
2465 | |||
2430 | * IPython/iplib.py (InteractiveShell.embed_mainloop): Patch for |
|
2466 | * IPython/iplib.py (InteractiveShell.embed_mainloop): Patch for | |
2431 | global embedding to make sure that things don't overwrite user |
|
2467 | global embedding to make sure that things don't overwrite user | |
2432 | globals accidentally. Thanks to Richard <rxe-AT-renre-europe.com> |
|
2468 | globals accidentally. Thanks to Richard <rxe-AT-renre-europe.com> | |
2433 |
|
2469 | |||
2434 | * IPython/Gnuplot2.py (gp): Patch for Gnuplot.py 1.6 |
|
2470 | * IPython/Gnuplot2.py (gp): Patch for Gnuplot.py 1.6 | |
2435 | compatibility. Thanks to Hayden Callow |
|
2471 | compatibility. Thanks to Hayden Callow | |
2436 | <h.callow-AT-elec.canterbury.ac.nz> |
|
2472 | <h.callow-AT-elec.canterbury.ac.nz> | |
2437 |
|
2473 | |||
2438 | 2002-10-04 Fernando Perez <fperez@colorado.edu> |
|
2474 | 2002-10-04 Fernando Perez <fperez@colorado.edu> | |
2439 |
|
2475 | |||
2440 | * IPython/Gnuplot2.py (PlotItem): Added 'index' option for |
|
2476 | * IPython/Gnuplot2.py (PlotItem): Added 'index' option for | |
2441 | Gnuplot.File objects. |
|
2477 | Gnuplot.File objects. | |
2442 |
|
2478 | |||
2443 | 2002-07-23 Fernando Perez <fperez@colorado.edu> |
|
2479 | 2002-07-23 Fernando Perez <fperez@colorado.edu> | |
2444 |
|
2480 | |||
2445 | * IPython/genutils.py (timing): Added timings() and timing() for |
|
2481 | * IPython/genutils.py (timing): Added timings() and timing() for | |
2446 | quick access to the most commonly needed data, the execution |
|
2482 | quick access to the most commonly needed data, the execution | |
2447 | times. Old timing() renamed to timings_out(). |
|
2483 | times. Old timing() renamed to timings_out(). | |
2448 |
|
2484 | |||
2449 | 2002-07-18 Fernando Perez <fperez@colorado.edu> |
|
2485 | 2002-07-18 Fernando Perez <fperez@colorado.edu> | |
2450 |
|
2486 | |||
2451 | * IPython/Shell.py (IPShellEmbed.restore_system_completer): fixed |
|
2487 | * IPython/Shell.py (IPShellEmbed.restore_system_completer): fixed | |
2452 | bug with nested instances disrupting the parent's tab completion. |
|
2488 | bug with nested instances disrupting the parent's tab completion. | |
2453 |
|
2489 | |||
2454 | * IPython/iplib.py (all_completions): Added Alex Schmolck's |
|
2490 | * IPython/iplib.py (all_completions): Added Alex Schmolck's | |
2455 | all_completions code to begin the emacs integration. |
|
2491 | all_completions code to begin the emacs integration. | |
2456 |
|
2492 | |||
2457 | * IPython/Gnuplot2.py (zip_items): Added optional 'titles' |
|
2493 | * IPython/Gnuplot2.py (zip_items): Added optional 'titles' | |
2458 | argument to allow titling individual arrays when plotting. |
|
2494 | argument to allow titling individual arrays when plotting. | |
2459 |
|
2495 | |||
2460 | 2002-07-15 Fernando Perez <fperez@colorado.edu> |
|
2496 | 2002-07-15 Fernando Perez <fperez@colorado.edu> | |
2461 |
|
2497 | |||
2462 | * setup.py (make_shortcut): changed to retrieve the value of |
|
2498 | * setup.py (make_shortcut): changed to retrieve the value of | |
2463 | 'Program Files' directory from the registry (this value changes in |
|
2499 | 'Program Files' directory from the registry (this value changes in | |
2464 | non-english versions of Windows). Thanks to Thomas Fanslau |
|
2500 | non-english versions of Windows). Thanks to Thomas Fanslau | |
2465 | <tfanslau-AT-gmx.de> for the report. |
|
2501 | <tfanslau-AT-gmx.de> for the report. | |
2466 |
|
2502 | |||
2467 | 2002-07-10 Fernando Perez <fperez@colorado.edu> |
|
2503 | 2002-07-10 Fernando Perez <fperez@colorado.edu> | |
2468 |
|
2504 | |||
2469 | * IPython/ultraTB.py (VerboseTB.debugger): enabled workaround for |
|
2505 | * IPython/ultraTB.py (VerboseTB.debugger): enabled workaround for | |
2470 | a bug in pdb, which crashes if a line with only whitespace is |
|
2506 | a bug in pdb, which crashes if a line with only whitespace is | |
2471 | entered. Bug report submitted to sourceforge. |
|
2507 | entered. Bug report submitted to sourceforge. | |
2472 |
|
2508 | |||
2473 | 2002-07-09 Fernando Perez <fperez@colorado.edu> |
|
2509 | 2002-07-09 Fernando Perez <fperez@colorado.edu> | |
2474 |
|
2510 | |||
2475 | * IPython/ultraTB.py (VerboseTB.nullrepr): fixed rare crash when |
|
2511 | * IPython/ultraTB.py (VerboseTB.nullrepr): fixed rare crash when | |
2476 | reporting exceptions (it's a bug in inspect.py, I just set a |
|
2512 | reporting exceptions (it's a bug in inspect.py, I just set a | |
2477 | workaround). |
|
2513 | workaround). | |
2478 |
|
2514 | |||
2479 | 2002-07-08 Fernando Perez <fperez@colorado.edu> |
|
2515 | 2002-07-08 Fernando Perez <fperez@colorado.edu> | |
2480 |
|
2516 | |||
2481 | * IPython/iplib.py (InteractiveShell.__init__): fixed reference to |
|
2517 | * IPython/iplib.py (InteractiveShell.__init__): fixed reference to | |
2482 | __IPYTHON__ in __builtins__ to show up in user_ns. |
|
2518 | __IPYTHON__ in __builtins__ to show up in user_ns. | |
2483 |
|
2519 | |||
2484 | 2002-07-03 Fernando Perez <fperez@colorado.edu> |
|
2520 | 2002-07-03 Fernando Perez <fperez@colorado.edu> | |
2485 |
|
2521 | |||
2486 | * IPython/GnuplotInteractive.py (magic_gp_set_default): changed |
|
2522 | * IPython/GnuplotInteractive.py (magic_gp_set_default): changed | |
2487 | name from @gp_set_instance to @gp_set_default. |
|
2523 | name from @gp_set_instance to @gp_set_default. | |
2488 |
|
2524 | |||
2489 | * IPython/ipmaker.py (make_IPython): default editor value set to |
|
2525 | * IPython/ipmaker.py (make_IPython): default editor value set to | |
2490 | '0' (a string), to match the rc file. Otherwise will crash when |
|
2526 | '0' (a string), to match the rc file. Otherwise will crash when | |
2491 | .strip() is called on it. |
|
2527 | .strip() is called on it. | |
2492 |
|
2528 | |||
2493 |
|
2529 | |||
2494 | 2002-06-28 Fernando Perez <fperez@colorado.edu> |
|
2530 | 2002-06-28 Fernando Perez <fperez@colorado.edu> | |
2495 |
|
2531 | |||
2496 | * IPython/iplib.py (InteractiveShell.safe_execfile): fix importing |
|
2532 | * IPython/iplib.py (InteractiveShell.safe_execfile): fix importing | |
2497 | of files in current directory when a file is executed via |
|
2533 | of files in current directory when a file is executed via | |
2498 | @run. Patch also by RA <ralf_ahlbrink-AT-web.de>. |
|
2534 | @run. Patch also by RA <ralf_ahlbrink-AT-web.de>. | |
2499 |
|
2535 | |||
2500 | * setup.py (manfiles): fix for rpm builds, submitted by RA |
|
2536 | * setup.py (manfiles): fix for rpm builds, submitted by RA | |
2501 | <ralf_ahlbrink-AT-web.de>. Now we have RPMs! |
|
2537 | <ralf_ahlbrink-AT-web.de>. Now we have RPMs! | |
2502 |
|
2538 | |||
2503 | * IPython/ipmaker.py (make_IPython): fixed lookup of default |
|
2539 | * IPython/ipmaker.py (make_IPython): fixed lookup of default | |
2504 | editor when set to '0'. Problem was, '0' evaluates to True (it's a |
|
2540 | editor when set to '0'. Problem was, '0' evaluates to True (it's a | |
2505 | string!). A. Schmolck caught this one. |
|
2541 | string!). A. Schmolck caught this one. | |
2506 |
|
2542 | |||
2507 | 2002-06-27 Fernando Perez <fperez@colorado.edu> |
|
2543 | 2002-06-27 Fernando Perez <fperez@colorado.edu> | |
2508 |
|
2544 | |||
2509 | * IPython/ipmaker.py (make_IPython): fixed bug when running user |
|
2545 | * IPython/ipmaker.py (make_IPython): fixed bug when running user | |
2510 | defined files at the cmd line. __name__ wasn't being set to |
|
2546 | defined files at the cmd line. __name__ wasn't being set to | |
2511 | __main__. |
|
2547 | __main__. | |
2512 |
|
2548 | |||
2513 | * IPython/Gnuplot2.py (zip_items): improved it so it can plot also |
|
2549 | * IPython/Gnuplot2.py (zip_items): improved it so it can plot also | |
2514 | regular lists and tuples besides Numeric arrays. |
|
2550 | regular lists and tuples besides Numeric arrays. | |
2515 |
|
2551 | |||
2516 | * IPython/Prompts.py (CachedOutput.__call__): Added output |
|
2552 | * IPython/Prompts.py (CachedOutput.__call__): Added output | |
2517 | supression for input ending with ';'. Similar to Mathematica and |
|
2553 | supression for input ending with ';'. Similar to Mathematica and | |
2518 | Matlab. The _* vars and Out[] list are still updated, just like |
|
2554 | Matlab. The _* vars and Out[] list are still updated, just like | |
2519 | Mathematica behaves. |
|
2555 | Mathematica behaves. | |
2520 |
|
2556 | |||
2521 | 2002-06-25 Fernando Perez <fperez@colorado.edu> |
|
2557 | 2002-06-25 Fernando Perez <fperez@colorado.edu> | |
2522 |
|
2558 | |||
2523 | * IPython/ConfigLoader.py (ConfigLoader.load): fixed checking of |
|
2559 | * IPython/ConfigLoader.py (ConfigLoader.load): fixed checking of | |
2524 | .ini extensions for profiels under Windows. |
|
2560 | .ini extensions for profiels under Windows. | |
2525 |
|
2561 | |||
2526 | * IPython/OInspect.py (Inspector.pinfo): improved alignment of |
|
2562 | * IPython/OInspect.py (Inspector.pinfo): improved alignment of | |
2527 | string form. Fix contributed by Alexander Schmolck |
|
2563 | string form. Fix contributed by Alexander Schmolck | |
2528 | <a.schmolck-AT-gmx.net> |
|
2564 | <a.schmolck-AT-gmx.net> | |
2529 |
|
2565 | |||
2530 | * IPython/GnuplotRuntime.py (gp_new): new function. Returns a |
|
2566 | * IPython/GnuplotRuntime.py (gp_new): new function. Returns a | |
2531 | pre-configured Gnuplot instance. |
|
2567 | pre-configured Gnuplot instance. | |
2532 |
|
2568 | |||
2533 | 2002-06-21 Fernando Perez <fperez@colorado.edu> |
|
2569 | 2002-06-21 Fernando Perez <fperez@colorado.edu> | |
2534 |
|
2570 | |||
2535 | * IPython/numutils.py (exp_safe): new function, works around the |
|
2571 | * IPython/numutils.py (exp_safe): new function, works around the | |
2536 | underflow problems in Numeric. |
|
2572 | underflow problems in Numeric. | |
2537 | (log2): New fn. Safe log in base 2: returns exact integer answer |
|
2573 | (log2): New fn. Safe log in base 2: returns exact integer answer | |
2538 | for exact integer powers of 2. |
|
2574 | for exact integer powers of 2. | |
2539 |
|
2575 | |||
2540 | * IPython/Magic.py (get_py_filename): fixed it not expanding '~' |
|
2576 | * IPython/Magic.py (get_py_filename): fixed it not expanding '~' | |
2541 | properly. |
|
2577 | properly. | |
2542 |
|
2578 | |||
2543 | 2002-06-20 Fernando Perez <fperez@colorado.edu> |
|
2579 | 2002-06-20 Fernando Perez <fperez@colorado.edu> | |
2544 |
|
2580 | |||
2545 | * IPython/genutils.py (timing): new function like |
|
2581 | * IPython/genutils.py (timing): new function like | |
2546 | Mathematica's. Similar to time_test, but returns more info. |
|
2582 | Mathematica's. Similar to time_test, but returns more info. | |
2547 |
|
2583 | |||
2548 | 2002-06-18 Fernando Perez <fperez@colorado.edu> |
|
2584 | 2002-06-18 Fernando Perez <fperez@colorado.edu> | |
2549 |
|
2585 | |||
2550 | * IPython/Magic.py (Magic.magic_save): modified @save and @r |
|
2586 | * IPython/Magic.py (Magic.magic_save): modified @save and @r | |
2551 | according to Mike Heeter's suggestions. |
|
2587 | according to Mike Heeter's suggestions. | |
2552 |
|
2588 | |||
2553 | 2002-06-16 Fernando Perez <fperez@colorado.edu> |
|
2589 | 2002-06-16 Fernando Perez <fperez@colorado.edu> | |
2554 |
|
2590 | |||
2555 | * IPython/GnuplotRuntime.py: Massive overhaul to the Gnuplot |
|
2591 | * IPython/GnuplotRuntime.py: Massive overhaul to the Gnuplot | |
2556 | system. GnuplotMagic is gone as a user-directory option. New files |
|
2592 | system. GnuplotMagic is gone as a user-directory option. New files | |
2557 | make it easier to use all the gnuplot stuff both from external |
|
2593 | make it easier to use all the gnuplot stuff both from external | |
2558 | programs as well as from IPython. Had to rewrite part of |
|
2594 | programs as well as from IPython. Had to rewrite part of | |
2559 | hardcopy() b/c of a strange bug: often the ps files simply don't |
|
2595 | hardcopy() b/c of a strange bug: often the ps files simply don't | |
2560 | get created, and require a repeat of the command (often several |
|
2596 | get created, and require a repeat of the command (often several | |
2561 | times). |
|
2597 | times). | |
2562 |
|
2598 | |||
2563 | * IPython/ultraTB.py (AutoFormattedTB.__call__): changed to |
|
2599 | * IPython/ultraTB.py (AutoFormattedTB.__call__): changed to | |
2564 | resolve output channel at call time, so that if sys.stderr has |
|
2600 | resolve output channel at call time, so that if sys.stderr has | |
2565 | been redirected by user this gets honored. |
|
2601 | been redirected by user this gets honored. | |
2566 |
|
2602 | |||
2567 | 2002-06-13 Fernando Perez <fperez@colorado.edu> |
|
2603 | 2002-06-13 Fernando Perez <fperez@colorado.edu> | |
2568 |
|
2604 | |||
2569 | * IPython/Shell.py (IPShell.__init__): Changed IPythonShell to |
|
2605 | * IPython/Shell.py (IPShell.__init__): Changed IPythonShell to | |
2570 | IPShell. Kept a copy with the old names to avoid breaking people's |
|
2606 | IPShell. Kept a copy with the old names to avoid breaking people's | |
2571 | embedded code. |
|
2607 | embedded code. | |
2572 |
|
2608 | |||
2573 | * IPython/ipython: simplified it to the bare minimum after |
|
2609 | * IPython/ipython: simplified it to the bare minimum after | |
2574 | Holger's suggestions. Added info about how to use it in |
|
2610 | Holger's suggestions. Added info about how to use it in | |
2575 | PYTHONSTARTUP. |
|
2611 | PYTHONSTARTUP. | |
2576 |
|
2612 | |||
2577 | * IPython/Shell.py (IPythonShell): changed the options passing |
|
2613 | * IPython/Shell.py (IPythonShell): changed the options passing | |
2578 | from a string with funky %s replacements to a straight list. Maybe |
|
2614 | from a string with funky %s replacements to a straight list. Maybe | |
2579 | a bit more typing, but it follows sys.argv conventions, so there's |
|
2615 | a bit more typing, but it follows sys.argv conventions, so there's | |
2580 | less special-casing to remember. |
|
2616 | less special-casing to remember. | |
2581 |
|
2617 | |||
2582 | 2002-06-12 Fernando Perez <fperez@colorado.edu> |
|
2618 | 2002-06-12 Fernando Perez <fperez@colorado.edu> | |
2583 |
|
2619 | |||
2584 | * IPython/Magic.py (Magic.magic_r): new magic auto-repeat |
|
2620 | * IPython/Magic.py (Magic.magic_r): new magic auto-repeat | |
2585 | command. Thanks to a suggestion by Mike Heeter. |
|
2621 | command. Thanks to a suggestion by Mike Heeter. | |
2586 | (Magic.magic_pfile): added behavior to look at filenames if given |
|
2622 | (Magic.magic_pfile): added behavior to look at filenames if given | |
2587 | arg is not a defined object. |
|
2623 | arg is not a defined object. | |
2588 | (Magic.magic_save): New @save function to save code snippets. Also |
|
2624 | (Magic.magic_save): New @save function to save code snippets. Also | |
2589 | a Mike Heeter idea. |
|
2625 | a Mike Heeter idea. | |
2590 |
|
2626 | |||
2591 | * IPython/UserConfig/GnuplotMagic.py (plot): Improvements to |
|
2627 | * IPython/UserConfig/GnuplotMagic.py (plot): Improvements to | |
2592 | plot() and replot(). Much more convenient now, especially for |
|
2628 | plot() and replot(). Much more convenient now, especially for | |
2593 | interactive use. |
|
2629 | interactive use. | |
2594 |
|
2630 | |||
2595 | * IPython/Magic.py (Magic.magic_run): Added .py automatically to |
|
2631 | * IPython/Magic.py (Magic.magic_run): Added .py automatically to | |
2596 | filenames. |
|
2632 | filenames. | |
2597 |
|
2633 | |||
2598 | 2002-06-02 Fernando Perez <fperez@colorado.edu> |
|
2634 | 2002-06-02 Fernando Perez <fperez@colorado.edu> | |
2599 |
|
2635 | |||
2600 | * IPython/Struct.py (Struct.__init__): modified to admit |
|
2636 | * IPython/Struct.py (Struct.__init__): modified to admit | |
2601 | initialization via another struct. |
|
2637 | initialization via another struct. | |
2602 |
|
2638 | |||
2603 | * IPython/genutils.py (SystemExec.__init__): New stateful |
|
2639 | * IPython/genutils.py (SystemExec.__init__): New stateful | |
2604 | interface to xsys and bq. Useful for writing system scripts. |
|
2640 | interface to xsys and bq. Useful for writing system scripts. | |
2605 |
|
2641 | |||
2606 | 2002-05-30 Fernando Perez <fperez@colorado.edu> |
|
2642 | 2002-05-30 Fernando Perez <fperez@colorado.edu> | |
2607 |
|
2643 | |||
2608 | * MANIFEST.in: Changed docfile selection to exclude all the lyx |
|
2644 | * MANIFEST.in: Changed docfile selection to exclude all the lyx | |
2609 | documents. This will make the user download smaller (it's getting |
|
2645 | documents. This will make the user download smaller (it's getting | |
2610 | too big). |
|
2646 | too big). | |
2611 |
|
2647 | |||
2612 | 2002-05-29 Fernando Perez <fperez@colorado.edu> |
|
2648 | 2002-05-29 Fernando Perez <fperez@colorado.edu> | |
2613 |
|
2649 | |||
2614 | * IPython/iplib.py (_FakeModule.__init__): New class introduced to |
|
2650 | * IPython/iplib.py (_FakeModule.__init__): New class introduced to | |
2615 | fix problems with shelve and pickle. Seems to work, but I don't |
|
2651 | fix problems with shelve and pickle. Seems to work, but I don't | |
2616 | know if corner cases break it. Thanks to Mike Heeter |
|
2652 | know if corner cases break it. Thanks to Mike Heeter | |
2617 | <korora-AT-SDF.LONESTAR.ORG> for the bug reports and test cases. |
|
2653 | <korora-AT-SDF.LONESTAR.ORG> for the bug reports and test cases. | |
2618 |
|
2654 | |||
2619 | 2002-05-24 Fernando Perez <fperez@colorado.edu> |
|
2655 | 2002-05-24 Fernando Perez <fperez@colorado.edu> | |
2620 |
|
2656 | |||
2621 | * IPython/Magic.py (Macro.__init__): fixed magics embedded in |
|
2657 | * IPython/Magic.py (Macro.__init__): fixed magics embedded in | |
2622 | macros having broken. |
|
2658 | macros having broken. | |
2623 |
|
2659 | |||
2624 | 2002-05-21 Fernando Perez <fperez@colorado.edu> |
|
2660 | 2002-05-21 Fernando Perez <fperez@colorado.edu> | |
2625 |
|
2661 | |||
2626 | * IPython/Magic.py (Magic.magic_logstart): fixed recently |
|
2662 | * IPython/Magic.py (Magic.magic_logstart): fixed recently | |
2627 | introduced logging bug: all history before logging started was |
|
2663 | introduced logging bug: all history before logging started was | |
2628 | being written one character per line! This came from the redesign |
|
2664 | being written one character per line! This came from the redesign | |
2629 | of the input history as a special list which slices to strings, |
|
2665 | of the input history as a special list which slices to strings, | |
2630 | not to lists. |
|
2666 | not to lists. | |
2631 |
|
2667 | |||
2632 | 2002-05-20 Fernando Perez <fperez@colorado.edu> |
|
2668 | 2002-05-20 Fernando Perez <fperez@colorado.edu> | |
2633 |
|
2669 | |||
2634 | * IPython/Prompts.py (CachedOutput.__init__): made the color table |
|
2670 | * IPython/Prompts.py (CachedOutput.__init__): made the color table | |
2635 | be an attribute of all classes in this module. The design of these |
|
2671 | be an attribute of all classes in this module. The design of these | |
2636 | classes needs some serious overhauling. |
|
2672 | classes needs some serious overhauling. | |
2637 |
|
2673 | |||
2638 | * IPython/DPyGetOpt.py (DPyGetOpt.setPosixCompliance): fixed bug |
|
2674 | * IPython/DPyGetOpt.py (DPyGetOpt.setPosixCompliance): fixed bug | |
2639 | which was ignoring '_' in option names. |
|
2675 | which was ignoring '_' in option names. | |
2640 |
|
2676 | |||
2641 | * IPython/ultraTB.py (FormattedTB.__init__): Changed |
|
2677 | * IPython/ultraTB.py (FormattedTB.__init__): Changed | |
2642 | 'Verbose_novars' to 'Context' and made it the new default. It's a |
|
2678 | 'Verbose_novars' to 'Context' and made it the new default. It's a | |
2643 | bit more readable and also safer than verbose. |
|
2679 | bit more readable and also safer than verbose. | |
2644 |
|
2680 | |||
2645 | * IPython/PyColorize.py (Parser.__call__): Fixed coloring of |
|
2681 | * IPython/PyColorize.py (Parser.__call__): Fixed coloring of | |
2646 | triple-quoted strings. |
|
2682 | triple-quoted strings. | |
2647 |
|
2683 | |||
2648 | * IPython/OInspect.py (__all__): new module exposing the object |
|
2684 | * IPython/OInspect.py (__all__): new module exposing the object | |
2649 | introspection facilities. Now the corresponding magics are dummy |
|
2685 | introspection facilities. Now the corresponding magics are dummy | |
2650 | wrappers around this. Having this module will make it much easier |
|
2686 | wrappers around this. Having this module will make it much easier | |
2651 | to put these functions into our modified pdb. |
|
2687 | to put these functions into our modified pdb. | |
2652 | This new object inspector system uses the new colorizing module, |
|
2688 | This new object inspector system uses the new colorizing module, | |
2653 | so source code and other things are nicely syntax highlighted. |
|
2689 | so source code and other things are nicely syntax highlighted. | |
2654 |
|
2690 | |||
2655 | 2002-05-18 Fernando Perez <fperez@colorado.edu> |
|
2691 | 2002-05-18 Fernando Perez <fperez@colorado.edu> | |
2656 |
|
2692 | |||
2657 | * IPython/ColorANSI.py: Split the coloring tools into a separate |
|
2693 | * IPython/ColorANSI.py: Split the coloring tools into a separate | |
2658 | module so I can use them in other code easier (they were part of |
|
2694 | module so I can use them in other code easier (they were part of | |
2659 | ultraTB). |
|
2695 | ultraTB). | |
2660 |
|
2696 | |||
2661 | 2002-05-17 Fernando Perez <fperez@colorado.edu> |
|
2697 | 2002-05-17 Fernando Perez <fperez@colorado.edu> | |
2662 |
|
2698 | |||
2663 | * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance): |
|
2699 | * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance): | |
2664 | fixed it to set the global 'g' also to the called instance, as |
|
2700 | fixed it to set the global 'g' also to the called instance, as | |
2665 | long as 'g' was still a gnuplot instance (so it doesn't overwrite |
|
2701 | long as 'g' was still a gnuplot instance (so it doesn't overwrite | |
2666 | user's 'g' variables). |
|
2702 | user's 'g' variables). | |
2667 |
|
2703 | |||
2668 | * IPython/iplib.py (InteractiveShell.__init__): Added In/Out |
|
2704 | * IPython/iplib.py (InteractiveShell.__init__): Added In/Out | |
2669 | global variables (aliases to _ih,_oh) so that users which expect |
|
2705 | global variables (aliases to _ih,_oh) so that users which expect | |
2670 | In[5] or Out[7] to work aren't unpleasantly surprised. |
|
2706 | In[5] or Out[7] to work aren't unpleasantly surprised. | |
2671 | (InputList.__getslice__): new class to allow executing slices of |
|
2707 | (InputList.__getslice__): new class to allow executing slices of | |
2672 | input history directly. Very simple class, complements the use of |
|
2708 | input history directly. Very simple class, complements the use of | |
2673 | macros. |
|
2709 | macros. | |
2674 |
|
2710 | |||
2675 | 2002-05-16 Fernando Perez <fperez@colorado.edu> |
|
2711 | 2002-05-16 Fernando Perez <fperez@colorado.edu> | |
2676 |
|
2712 | |||
2677 | * setup.py (docdirbase): make doc directory be just doc/IPython |
|
2713 | * setup.py (docdirbase): make doc directory be just doc/IPython | |
2678 | without version numbers, it will reduce clutter for users. |
|
2714 | without version numbers, it will reduce clutter for users. | |
2679 |
|
2715 | |||
2680 | * IPython/Magic.py (Magic.magic_run): Add explicit local dict to |
|
2716 | * IPython/Magic.py (Magic.magic_run): Add explicit local dict to | |
2681 | execfile call to prevent possible memory leak. See for details: |
|
2717 | execfile call to prevent possible memory leak. See for details: | |
2682 | http://mail.python.org/pipermail/python-list/2002-February/088476.html |
|
2718 | http://mail.python.org/pipermail/python-list/2002-February/088476.html | |
2683 |
|
2719 | |||
2684 | 2002-05-15 Fernando Perez <fperez@colorado.edu> |
|
2720 | 2002-05-15 Fernando Perez <fperez@colorado.edu> | |
2685 |
|
2721 | |||
2686 | * IPython/Magic.py (Magic.magic_psource): made the object |
|
2722 | * IPython/Magic.py (Magic.magic_psource): made the object | |
2687 | introspection names be more standard: pdoc, pdef, pfile and |
|
2723 | introspection names be more standard: pdoc, pdef, pfile and | |
2688 | psource. They all print/page their output, and it makes |
|
2724 | psource. They all print/page their output, and it makes | |
2689 | remembering them easier. Kept old names for compatibility as |
|
2725 | remembering them easier. Kept old names for compatibility as | |
2690 | aliases. |
|
2726 | aliases. | |
2691 |
|
2727 | |||
2692 | 2002-05-14 Fernando Perez <fperez@colorado.edu> |
|
2728 | 2002-05-14 Fernando Perez <fperez@colorado.edu> | |
2693 |
|
2729 | |||
2694 | * IPython/UserConfig/GnuplotMagic.py: I think I finally understood |
|
2730 | * IPython/UserConfig/GnuplotMagic.py: I think I finally understood | |
2695 | what the mouse problem was. The trick is to use gnuplot with temp |
|
2731 | what the mouse problem was. The trick is to use gnuplot with temp | |
2696 | files and NOT with pipes (for data communication), because having |
|
2732 | files and NOT with pipes (for data communication), because having | |
2697 | both pipes and the mouse on is bad news. |
|
2733 | both pipes and the mouse on is bad news. | |
2698 |
|
2734 | |||
2699 | 2002-05-13 Fernando Perez <fperez@colorado.edu> |
|
2735 | 2002-05-13 Fernando Perez <fperez@colorado.edu> | |
2700 |
|
2736 | |||
2701 | * IPython/Magic.py (Magic._ofind): fixed namespace order search |
|
2737 | * IPython/Magic.py (Magic._ofind): fixed namespace order search | |
2702 | bug. Information would be reported about builtins even when |
|
2738 | bug. Information would be reported about builtins even when | |
2703 | user-defined functions overrode them. |
|
2739 | user-defined functions overrode them. | |
2704 |
|
2740 | |||
2705 | 2002-05-11 Fernando Perez <fperez@colorado.edu> |
|
2741 | 2002-05-11 Fernando Perez <fperez@colorado.edu> | |
2706 |
|
2742 | |||
2707 | * IPython/__init__.py (__all__): removed FlexCompleter from |
|
2743 | * IPython/__init__.py (__all__): removed FlexCompleter from | |
2708 | __all__ so that things don't fail in platforms without readline. |
|
2744 | __all__ so that things don't fail in platforms without readline. | |
2709 |
|
2745 | |||
2710 | 2002-05-10 Fernando Perez <fperez@colorado.edu> |
|
2746 | 2002-05-10 Fernando Perez <fperez@colorado.edu> | |
2711 |
|
2747 | |||
2712 | * IPython/__init__.py (__all__): removed numutils from __all__ b/c |
|
2748 | * IPython/__init__.py (__all__): removed numutils from __all__ b/c | |
2713 | it requires Numeric, effectively making Numeric a dependency for |
|
2749 | it requires Numeric, effectively making Numeric a dependency for | |
2714 | IPython. |
|
2750 | IPython. | |
2715 |
|
2751 | |||
2716 | * Released 0.2.13 |
|
2752 | * Released 0.2.13 | |
2717 |
|
2753 | |||
2718 | * IPython/Magic.py (Magic.magic_prun): big overhaul to the |
|
2754 | * IPython/Magic.py (Magic.magic_prun): big overhaul to the | |
2719 | profiler interface. Now all the major options from the profiler |
|
2755 | profiler interface. Now all the major options from the profiler | |
2720 | module are directly supported in IPython, both for single |
|
2756 | module are directly supported in IPython, both for single | |
2721 | expressions (@prun) and for full programs (@run -p). |
|
2757 | expressions (@prun) and for full programs (@run -p). | |
2722 |
|
2758 | |||
2723 | 2002-05-09 Fernando Perez <fperez@colorado.edu> |
|
2759 | 2002-05-09 Fernando Perez <fperez@colorado.edu> | |
2724 |
|
2760 | |||
2725 | * IPython/Magic.py (Magic.magic_doc): fixed to show docstrings of |
|
2761 | * IPython/Magic.py (Magic.magic_doc): fixed to show docstrings of | |
2726 | magic properly formatted for screen. |
|
2762 | magic properly formatted for screen. | |
2727 |
|
2763 | |||
2728 | * setup.py (make_shortcut): Changed things to put pdf version in |
|
2764 | * setup.py (make_shortcut): Changed things to put pdf version in | |
2729 | doc/ instead of doc/manual (had to change lyxport a bit). |
|
2765 | doc/ instead of doc/manual (had to change lyxport a bit). | |
2730 |
|
2766 | |||
2731 | * IPython/Magic.py (Profile.string_stats): made profile runs go |
|
2767 | * IPython/Magic.py (Profile.string_stats): made profile runs go | |
2732 | through pager (they are long and a pager allows searching, saving, |
|
2768 | through pager (they are long and a pager allows searching, saving, | |
2733 | etc.) |
|
2769 | etc.) | |
2734 |
|
2770 | |||
2735 | 2002-05-08 Fernando Perez <fperez@colorado.edu> |
|
2771 | 2002-05-08 Fernando Perez <fperez@colorado.edu> | |
2736 |
|
2772 | |||
2737 | * Released 0.2.12 |
|
2773 | * Released 0.2.12 | |
2738 |
|
2774 | |||
2739 | 2002-05-06 Fernando Perez <fperez@colorado.edu> |
|
2775 | 2002-05-06 Fernando Perez <fperez@colorado.edu> | |
2740 |
|
2776 | |||
2741 | * IPython/Magic.py (Magic.magic_hist): small bug fixed (recently |
|
2777 | * IPython/Magic.py (Magic.magic_hist): small bug fixed (recently | |
2742 | introduced); 'hist n1 n2' was broken. |
|
2778 | introduced); 'hist n1 n2' was broken. | |
2743 | (Magic.magic_pdb): added optional on/off arguments to @pdb |
|
2779 | (Magic.magic_pdb): added optional on/off arguments to @pdb | |
2744 | (Magic.magic_run): added option -i to @run, which executes code in |
|
2780 | (Magic.magic_run): added option -i to @run, which executes code in | |
2745 | the IPython namespace instead of a clean one. Also added @irun as |
|
2781 | the IPython namespace instead of a clean one. Also added @irun as | |
2746 | an alias to @run -i. |
|
2782 | an alias to @run -i. | |
2747 |
|
2783 | |||
2748 | * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance): |
|
2784 | * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance): | |
2749 | fixed (it didn't really do anything, the namespaces were wrong). |
|
2785 | fixed (it didn't really do anything, the namespaces were wrong). | |
2750 |
|
2786 | |||
2751 | * IPython/Debugger.py (__init__): Added workaround for python 2.1 |
|
2787 | * IPython/Debugger.py (__init__): Added workaround for python 2.1 | |
2752 |
|
2788 | |||
2753 | * IPython/__init__.py (__all__): Fixed package namespace, now |
|
2789 | * IPython/__init__.py (__all__): Fixed package namespace, now | |
2754 | 'import IPython' does give access to IPython.<all> as |
|
2790 | 'import IPython' does give access to IPython.<all> as | |
2755 | expected. Also renamed __release__ to Release. |
|
2791 | expected. Also renamed __release__ to Release. | |
2756 |
|
2792 | |||
2757 | * IPython/Debugger.py (__license__): created new Pdb class which |
|
2793 | * IPython/Debugger.py (__license__): created new Pdb class which | |
2758 | functions like a drop-in for the normal pdb.Pdb but does NOT |
|
2794 | functions like a drop-in for the normal pdb.Pdb but does NOT | |
2759 | import readline by default. This way it doesn't muck up IPython's |
|
2795 | import readline by default. This way it doesn't muck up IPython's | |
2760 | readline handling, and now tab-completion finally works in the |
|
2796 | readline handling, and now tab-completion finally works in the | |
2761 | debugger -- sort of. It completes things globally visible, but the |
|
2797 | debugger -- sort of. It completes things globally visible, but the | |
2762 | completer doesn't track the stack as pdb walks it. That's a bit |
|
2798 | completer doesn't track the stack as pdb walks it. That's a bit | |
2763 | tricky, and I'll have to implement it later. |
|
2799 | tricky, and I'll have to implement it later. | |
2764 |
|
2800 | |||
2765 | 2002-05-05 Fernando Perez <fperez@colorado.edu> |
|
2801 | 2002-05-05 Fernando Perez <fperez@colorado.edu> | |
2766 |
|
2802 | |||
2767 | * IPython/Magic.py (Magic.magic_oinfo): fixed formatting bug for |
|
2803 | * IPython/Magic.py (Magic.magic_oinfo): fixed formatting bug for | |
2768 | magic docstrings when printed via ? (explicit \'s were being |
|
2804 | magic docstrings when printed via ? (explicit \'s were being | |
2769 | printed). |
|
2805 | printed). | |
2770 |
|
2806 | |||
2771 | * IPython/ipmaker.py (make_IPython): fixed namespace |
|
2807 | * IPython/ipmaker.py (make_IPython): fixed namespace | |
2772 | identification bug. Now variables loaded via logs or command-line |
|
2808 | identification bug. Now variables loaded via logs or command-line | |
2773 | files are recognized in the interactive namespace by @who. |
|
2809 | files are recognized in the interactive namespace by @who. | |
2774 |
|
2810 | |||
2775 | * IPython/iplib.py (InteractiveShell.safe_execfile): Fixed bug in |
|
2811 | * IPython/iplib.py (InteractiveShell.safe_execfile): Fixed bug in | |
2776 | log replay system stemming from the string form of Structs. |
|
2812 | log replay system stemming from the string form of Structs. | |
2777 |
|
2813 | |||
2778 | * IPython/Magic.py (Macro.__init__): improved macros to properly |
|
2814 | * IPython/Magic.py (Macro.__init__): improved macros to properly | |
2779 | handle magic commands in them. |
|
2815 | handle magic commands in them. | |
2780 | (Magic.magic_logstart): usernames are now expanded so 'logstart |
|
2816 | (Magic.magic_logstart): usernames are now expanded so 'logstart | |
2781 | ~/mylog' now works. |
|
2817 | ~/mylog' now works. | |
2782 |
|
2818 | |||
2783 | * IPython/iplib.py (complete): fixed bug where paths starting with |
|
2819 | * IPython/iplib.py (complete): fixed bug where paths starting with | |
2784 | '/' would be completed as magic names. |
|
2820 | '/' would be completed as magic names. | |
2785 |
|
2821 | |||
2786 | 2002-05-04 Fernando Perez <fperez@colorado.edu> |
|
2822 | 2002-05-04 Fernando Perez <fperez@colorado.edu> | |
2787 |
|
2823 | |||
2788 | * IPython/Magic.py (Magic.magic_run): added options -p and -f to |
|
2824 | * IPython/Magic.py (Magic.magic_run): added options -p and -f to | |
2789 | allow running full programs under the profiler's control. |
|
2825 | allow running full programs under the profiler's control. | |
2790 |
|
2826 | |||
2791 | * IPython/ultraTB.py (FormattedTB.__init__): Added Verbose_novars |
|
2827 | * IPython/ultraTB.py (FormattedTB.__init__): Added Verbose_novars | |
2792 | mode to report exceptions verbosely but without formatting |
|
2828 | mode to report exceptions verbosely but without formatting | |
2793 | variables. This addresses the issue of ipython 'freezing' (it's |
|
2829 | variables. This addresses the issue of ipython 'freezing' (it's | |
2794 | not frozen, but caught in an expensive formatting loop) when huge |
|
2830 | not frozen, but caught in an expensive formatting loop) when huge | |
2795 | variables are in the context of an exception. |
|
2831 | variables are in the context of an exception. | |
2796 | (VerboseTB.text): Added '--->' markers at line where exception was |
|
2832 | (VerboseTB.text): Added '--->' markers at line where exception was | |
2797 | triggered. Much clearer to read, especially in NoColor modes. |
|
2833 | triggered. Much clearer to read, especially in NoColor modes. | |
2798 |
|
2834 | |||
2799 | * IPython/Magic.py (Magic.magic_run): bugfix: -n option had been |
|
2835 | * IPython/Magic.py (Magic.magic_run): bugfix: -n option had been | |
2800 | implemented in reverse when changing to the new parse_options(). |
|
2836 | implemented in reverse when changing to the new parse_options(). | |
2801 |
|
2837 | |||
2802 | 2002-05-03 Fernando Perez <fperez@colorado.edu> |
|
2838 | 2002-05-03 Fernando Perez <fperez@colorado.edu> | |
2803 |
|
2839 | |||
2804 | * IPython/Magic.py (Magic.parse_options): new function so that |
|
2840 | * IPython/Magic.py (Magic.parse_options): new function so that | |
2805 | magics can parse options easier. |
|
2841 | magics can parse options easier. | |
2806 | (Magic.magic_prun): new function similar to profile.run(), |
|
2842 | (Magic.magic_prun): new function similar to profile.run(), | |
2807 | suggested by Chris Hart. |
|
2843 | suggested by Chris Hart. | |
2808 | (Magic.magic_cd): fixed behavior so that it only changes if |
|
2844 | (Magic.magic_cd): fixed behavior so that it only changes if | |
2809 | directory actually is in history. |
|
2845 | directory actually is in history. | |
2810 |
|
2846 | |||
2811 | * IPython/usage.py (__doc__): added information about potential |
|
2847 | * IPython/usage.py (__doc__): added information about potential | |
2812 | slowness of Verbose exception mode when there are huge data |
|
2848 | slowness of Verbose exception mode when there are huge data | |
2813 | structures to be formatted (thanks to Archie Paulson). |
|
2849 | structures to be formatted (thanks to Archie Paulson). | |
2814 |
|
2850 | |||
2815 | * IPython/ipmaker.py (make_IPython): Changed default logging |
|
2851 | * IPython/ipmaker.py (make_IPython): Changed default logging | |
2816 | (when simply called with -log) to use curr_dir/ipython.log in |
|
2852 | (when simply called with -log) to use curr_dir/ipython.log in | |
2817 | rotate mode. Fixed crash which was occuring with -log before |
|
2853 | rotate mode. Fixed crash which was occuring with -log before | |
2818 | (thanks to Jim Boyle). |
|
2854 | (thanks to Jim Boyle). | |
2819 |
|
2855 | |||
2820 | 2002-05-01 Fernando Perez <fperez@colorado.edu> |
|
2856 | 2002-05-01 Fernando Perez <fperez@colorado.edu> | |
2821 |
|
2857 | |||
2822 | * Released 0.2.11 for these fixes (mainly the ultraTB one which |
|
2858 | * Released 0.2.11 for these fixes (mainly the ultraTB one which | |
2823 | was nasty -- though somewhat of a corner case). |
|
2859 | was nasty -- though somewhat of a corner case). | |
2824 |
|
2860 | |||
2825 | * IPython/ultraTB.py (AutoFormattedTB.text): renamed __text to |
|
2861 | * IPython/ultraTB.py (AutoFormattedTB.text): renamed __text to | |
2826 | text (was a bug). |
|
2862 | text (was a bug). | |
2827 |
|
2863 | |||
2828 | 2002-04-30 Fernando Perez <fperez@colorado.edu> |
|
2864 | 2002-04-30 Fernando Perez <fperez@colorado.edu> | |
2829 |
|
2865 | |||
2830 | * IPython/UserConfig/GnuplotMagic.py (magic_gp): Minor fix to add |
|
2866 | * IPython/UserConfig/GnuplotMagic.py (magic_gp): Minor fix to add | |
2831 | a print after ^D or ^C from the user so that the In[] prompt |
|
2867 | a print after ^D or ^C from the user so that the In[] prompt | |
2832 | doesn't over-run the gnuplot one. |
|
2868 | doesn't over-run the gnuplot one. | |
2833 |
|
2869 | |||
2834 | 2002-04-29 Fernando Perez <fperez@colorado.edu> |
|
2870 | 2002-04-29 Fernando Perez <fperez@colorado.edu> | |
2835 |
|
2871 | |||
2836 | * Released 0.2.10 |
|
2872 | * Released 0.2.10 | |
2837 |
|
2873 | |||
2838 | * IPython/__release__.py (version): get date dynamically. |
|
2874 | * IPython/__release__.py (version): get date dynamically. | |
2839 |
|
2875 | |||
2840 | * Misc. documentation updates thanks to Arnd's comments. Also ran |
|
2876 | * Misc. documentation updates thanks to Arnd's comments. Also ran | |
2841 | a full spellcheck on the manual (hadn't been done in a while). |
|
2877 | a full spellcheck on the manual (hadn't been done in a while). | |
2842 |
|
2878 | |||
2843 | 2002-04-27 Fernando Perez <fperez@colorado.edu> |
|
2879 | 2002-04-27 Fernando Perez <fperez@colorado.edu> | |
2844 |
|
2880 | |||
2845 | * IPython/Magic.py (Magic.magic_logstart): Fixed bug where |
|
2881 | * IPython/Magic.py (Magic.magic_logstart): Fixed bug where | |
2846 | starting a log in mid-session would reset the input history list. |
|
2882 | starting a log in mid-session would reset the input history list. | |
2847 |
|
2883 | |||
2848 | 2002-04-26 Fernando Perez <fperez@colorado.edu> |
|
2884 | 2002-04-26 Fernando Perez <fperez@colorado.edu> | |
2849 |
|
2885 | |||
2850 | * IPython/iplib.py (InteractiveShell.wait): Fixed bug where not |
|
2886 | * IPython/iplib.py (InteractiveShell.wait): Fixed bug where not | |
2851 | all files were being included in an update. Now anything in |
|
2887 | all files were being included in an update. Now anything in | |
2852 | UserConfig that matches [A-Za-z]*.py will go (this excludes |
|
2888 | UserConfig that matches [A-Za-z]*.py will go (this excludes | |
2853 | __init__.py) |
|
2889 | __init__.py) | |
2854 |
|
2890 | |||
2855 | 2002-04-25 Fernando Perez <fperez@colorado.edu> |
|
2891 | 2002-04-25 Fernando Perez <fperez@colorado.edu> | |
2856 |
|
2892 | |||
2857 | * IPython/iplib.py (InteractiveShell.__init__): Added __IPYTHON__ |
|
2893 | * IPython/iplib.py (InteractiveShell.__init__): Added __IPYTHON__ | |
2858 | to __builtins__ so that any form of embedded or imported code can |
|
2894 | to __builtins__ so that any form of embedded or imported code can | |
2859 | test for being inside IPython. |
|
2895 | test for being inside IPython. | |
2860 |
|
2896 | |||
2861 | * IPython/UserConfig/GnuplotMagic.py: (magic_gp_set_instance): |
|
2897 | * IPython/UserConfig/GnuplotMagic.py: (magic_gp_set_instance): | |
2862 | changed to GnuplotMagic because it's now an importable module, |
|
2898 | changed to GnuplotMagic because it's now an importable module, | |
2863 | this makes the name follow that of the standard Gnuplot module. |
|
2899 | this makes the name follow that of the standard Gnuplot module. | |
2864 | GnuplotMagic can now be loaded at any time in mid-session. |
|
2900 | GnuplotMagic can now be loaded at any time in mid-session. | |
2865 |
|
2901 | |||
2866 | 2002-04-24 Fernando Perez <fperez@colorado.edu> |
|
2902 | 2002-04-24 Fernando Perez <fperez@colorado.edu> | |
2867 |
|
2903 | |||
2868 | * IPython/numutils.py: removed SIUnits. It doesn't properly set |
|
2904 | * IPython/numutils.py: removed SIUnits. It doesn't properly set | |
2869 | the globals (IPython has its own namespace) and the |
|
2905 | the globals (IPython has its own namespace) and the | |
2870 | PhysicalQuantity stuff is much better anyway. |
|
2906 | PhysicalQuantity stuff is much better anyway. | |
2871 |
|
2907 | |||
2872 | * IPython/UserConfig/example-gnuplot.py (g2): Added gnuplot |
|
2908 | * IPython/UserConfig/example-gnuplot.py (g2): Added gnuplot | |
2873 | embedding example to standard user directory for |
|
2909 | embedding example to standard user directory for | |
2874 | distribution. Also put it in the manual. |
|
2910 | distribution. Also put it in the manual. | |
2875 |
|
2911 | |||
2876 | * IPython/numutils.py (gnuplot_exec): Changed to take a gnuplot |
|
2912 | * IPython/numutils.py (gnuplot_exec): Changed to take a gnuplot | |
2877 | instance as first argument (so it doesn't rely on some obscure |
|
2913 | instance as first argument (so it doesn't rely on some obscure | |
2878 | hidden global). |
|
2914 | hidden global). | |
2879 |
|
2915 | |||
2880 | * IPython/UserConfig/ipythonrc.py: put () back in accepted |
|
2916 | * IPython/UserConfig/ipythonrc.py: put () back in accepted | |
2881 | delimiters. While it prevents ().TAB from working, it allows |
|
2917 | delimiters. While it prevents ().TAB from working, it allows | |
2882 | completions in open (... expressions. This is by far a more common |
|
2918 | completions in open (... expressions. This is by far a more common | |
2883 | case. |
|
2919 | case. | |
2884 |
|
2920 | |||
2885 | 2002-04-23 Fernando Perez <fperez@colorado.edu> |
|
2921 | 2002-04-23 Fernando Perez <fperez@colorado.edu> | |
2886 |
|
2922 | |||
2887 | * IPython/Extensions/InterpreterPasteInput.py: new |
|
2923 | * IPython/Extensions/InterpreterPasteInput.py: new | |
2888 | syntax-processing module for pasting lines with >>> or ... at the |
|
2924 | syntax-processing module for pasting lines with >>> or ... at the | |
2889 | start. |
|
2925 | start. | |
2890 |
|
2926 | |||
2891 | * IPython/Extensions/PhysicalQ_Interactive.py |
|
2927 | * IPython/Extensions/PhysicalQ_Interactive.py | |
2892 | (PhysicalQuantityInteractive.__int__): fixed to work with either |
|
2928 | (PhysicalQuantityInteractive.__int__): fixed to work with either | |
2893 | Numeric or math. |
|
2929 | Numeric or math. | |
2894 |
|
2930 | |||
2895 | * IPython/UserConfig/ipythonrc-numeric.py: reorganized the |
|
2931 | * IPython/UserConfig/ipythonrc-numeric.py: reorganized the | |
2896 | provided profiles. Now we have: |
|
2932 | provided profiles. Now we have: | |
2897 | -math -> math module as * and cmath with its own namespace. |
|
2933 | -math -> math module as * and cmath with its own namespace. | |
2898 | -numeric -> Numeric as *, plus gnuplot & grace |
|
2934 | -numeric -> Numeric as *, plus gnuplot & grace | |
2899 | -physics -> same as before |
|
2935 | -physics -> same as before | |
2900 |
|
2936 | |||
2901 | * IPython/Magic.py (Magic.magic_magic): Fixed bug where |
|
2937 | * IPython/Magic.py (Magic.magic_magic): Fixed bug where | |
2902 | user-defined magics wouldn't be found by @magic if they were |
|
2938 | user-defined magics wouldn't be found by @magic if they were | |
2903 | defined as class methods. Also cleaned up the namespace search |
|
2939 | defined as class methods. Also cleaned up the namespace search | |
2904 | logic and the string building (to use %s instead of many repeated |
|
2940 | logic and the string building (to use %s instead of many repeated | |
2905 | string adds). |
|
2941 | string adds). | |
2906 |
|
2942 | |||
2907 | * IPython/UserConfig/example-magic.py (magic_foo): updated example |
|
2943 | * IPython/UserConfig/example-magic.py (magic_foo): updated example | |
2908 | of user-defined magics to operate with class methods (cleaner, in |
|
2944 | of user-defined magics to operate with class methods (cleaner, in | |
2909 | line with the gnuplot code). |
|
2945 | line with the gnuplot code). | |
2910 |
|
2946 | |||
2911 | 2002-04-22 Fernando Perez <fperez@colorado.edu> |
|
2947 | 2002-04-22 Fernando Perez <fperez@colorado.edu> | |
2912 |
|
2948 | |||
2913 | * setup.py: updated dependency list so that manual is updated when |
|
2949 | * setup.py: updated dependency list so that manual is updated when | |
2914 | all included files change. |
|
2950 | all included files change. | |
2915 |
|
2951 | |||
2916 | * IPython/ipmaker.py (make_IPython): Fixed bug which was ignoring |
|
2952 | * IPython/ipmaker.py (make_IPython): Fixed bug which was ignoring | |
2917 | the delimiter removal option (the fix is ugly right now). |
|
2953 | the delimiter removal option (the fix is ugly right now). | |
2918 |
|
2954 | |||
2919 | * IPython/UserConfig/ipythonrc-physics.py: simplified not to load |
|
2955 | * IPython/UserConfig/ipythonrc-physics.py: simplified not to load | |
2920 | all of the math profile (quicker loading, no conflict between |
|
2956 | all of the math profile (quicker loading, no conflict between | |
2921 | g-9.8 and g-gnuplot). |
|
2957 | g-9.8 and g-gnuplot). | |
2922 |
|
2958 | |||
2923 | * IPython/CrashHandler.py (CrashHandler.__call__): changed default |
|
2959 | * IPython/CrashHandler.py (CrashHandler.__call__): changed default | |
2924 | name of post-mortem files to IPython_crash_report.txt. |
|
2960 | name of post-mortem files to IPython_crash_report.txt. | |
2925 |
|
2961 | |||
2926 | * Cleanup/update of the docs. Added all the new readline info and |
|
2962 | * Cleanup/update of the docs. Added all the new readline info and | |
2927 | formatted all lists as 'real lists'. |
|
2963 | formatted all lists as 'real lists'. | |
2928 |
|
2964 | |||
2929 | * IPython/ipmaker.py (make_IPython): removed now-obsolete |
|
2965 | * IPython/ipmaker.py (make_IPython): removed now-obsolete | |
2930 | tab-completion options, since the full readline parse_and_bind is |
|
2966 | tab-completion options, since the full readline parse_and_bind is | |
2931 | now accessible. |
|
2967 | now accessible. | |
2932 |
|
2968 | |||
2933 | * IPython/iplib.py (InteractiveShell.init_readline): Changed |
|
2969 | * IPython/iplib.py (InteractiveShell.init_readline): Changed | |
2934 | handling of readline options. Now users can specify any string to |
|
2970 | handling of readline options. Now users can specify any string to | |
2935 | be passed to parse_and_bind(), as well as the delimiters to be |
|
2971 | be passed to parse_and_bind(), as well as the delimiters to be | |
2936 | removed. |
|
2972 | removed. | |
2937 | (InteractiveShell.__init__): Added __name__ to the global |
|
2973 | (InteractiveShell.__init__): Added __name__ to the global | |
2938 | namespace so that things like Itpl which rely on its existence |
|
2974 | namespace so that things like Itpl which rely on its existence | |
2939 | don't crash. |
|
2975 | don't crash. | |
2940 | (InteractiveShell._prefilter): Defined the default with a _ so |
|
2976 | (InteractiveShell._prefilter): Defined the default with a _ so | |
2941 | that prefilter() is easier to override, while the default one |
|
2977 | that prefilter() is easier to override, while the default one | |
2942 | remains available. |
|
2978 | remains available. | |
2943 |
|
2979 | |||
2944 | 2002-04-18 Fernando Perez <fperez@colorado.edu> |
|
2980 | 2002-04-18 Fernando Perez <fperez@colorado.edu> | |
2945 |
|
2981 | |||
2946 | * Added information about pdb in the docs. |
|
2982 | * Added information about pdb in the docs. | |
2947 |
|
2983 | |||
2948 | 2002-04-17 Fernando Perez <fperez@colorado.edu> |
|
2984 | 2002-04-17 Fernando Perez <fperez@colorado.edu> | |
2949 |
|
2985 | |||
2950 | * IPython/ipmaker.py (make_IPython): added rc_override option to |
|
2986 | * IPython/ipmaker.py (make_IPython): added rc_override option to | |
2951 | allow passing config options at creation time which may override |
|
2987 | allow passing config options at creation time which may override | |
2952 | anything set in the config files or command line. This is |
|
2988 | anything set in the config files or command line. This is | |
2953 | particularly useful for configuring embedded instances. |
|
2989 | particularly useful for configuring embedded instances. | |
2954 |
|
2990 | |||
2955 | 2002-04-15 Fernando Perez <fperez@colorado.edu> |
|
2991 | 2002-04-15 Fernando Perez <fperez@colorado.edu> | |
2956 |
|
2992 | |||
2957 | * IPython/Logger.py (Logger.log): Fixed a nasty bug which could |
|
2993 | * IPython/Logger.py (Logger.log): Fixed a nasty bug which could | |
2958 | crash embedded instances because of the input cache falling out of |
|
2994 | crash embedded instances because of the input cache falling out of | |
2959 | sync with the output counter. |
|
2995 | sync with the output counter. | |
2960 |
|
2996 | |||
2961 | * IPython/Shell.py (IPythonShellEmbed.__init__): added a debug |
|
2997 | * IPython/Shell.py (IPythonShellEmbed.__init__): added a debug | |
2962 | mode which calls pdb after an uncaught exception in IPython itself. |
|
2998 | mode which calls pdb after an uncaught exception in IPython itself. | |
2963 |
|
2999 | |||
2964 | 2002-04-14 Fernando Perez <fperez@colorado.edu> |
|
3000 | 2002-04-14 Fernando Perez <fperez@colorado.edu> | |
2965 |
|
3001 | |||
2966 | * IPython/iplib.py (InteractiveShell.showtraceback): pdb mucks up |
|
3002 | * IPython/iplib.py (InteractiveShell.showtraceback): pdb mucks up | |
2967 | readline, fix it back after each call. |
|
3003 | readline, fix it back after each call. | |
2968 |
|
3004 | |||
2969 | * IPython/ultraTB.py (AutoFormattedTB.__text): made text a private |
|
3005 | * IPython/ultraTB.py (AutoFormattedTB.__text): made text a private | |
2970 | method to force all access via __call__(), which guarantees that |
|
3006 | method to force all access via __call__(), which guarantees that | |
2971 | traceback references are properly deleted. |
|
3007 | traceback references are properly deleted. | |
2972 |
|
3008 | |||
2973 | * IPython/Prompts.py (CachedOutput._display): minor fixes to |
|
3009 | * IPython/Prompts.py (CachedOutput._display): minor fixes to | |
2974 | improve printing when pprint is in use. |
|
3010 | improve printing when pprint is in use. | |
2975 |
|
3011 | |||
2976 | 2002-04-13 Fernando Perez <fperez@colorado.edu> |
|
3012 | 2002-04-13 Fernando Perez <fperez@colorado.edu> | |
2977 |
|
3013 | |||
2978 | * IPython/Shell.py (IPythonShellEmbed.__call__): SystemExit |
|
3014 | * IPython/Shell.py (IPythonShellEmbed.__call__): SystemExit | |
2979 | exceptions aren't caught anymore. If the user triggers one, he |
|
3015 | exceptions aren't caught anymore. If the user triggers one, he | |
2980 | should know why he's doing it and it should go all the way up, |
|
3016 | should know why he's doing it and it should go all the way up, | |
2981 | just like any other exception. So now @abort will fully kill the |
|
3017 | just like any other exception. So now @abort will fully kill the | |
2982 | embedded interpreter and the embedding code (unless that happens |
|
3018 | embedded interpreter and the embedding code (unless that happens | |
2983 | to catch SystemExit). |
|
3019 | to catch SystemExit). | |
2984 |
|
3020 | |||
2985 | * IPython/ultraTB.py (VerboseTB.__init__): added a call_pdb flag |
|
3021 | * IPython/ultraTB.py (VerboseTB.__init__): added a call_pdb flag | |
2986 | and a debugger() method to invoke the interactive pdb debugger |
|
3022 | and a debugger() method to invoke the interactive pdb debugger | |
2987 | after printing exception information. Also added the corresponding |
|
3023 | after printing exception information. Also added the corresponding | |
2988 | -pdb option and @pdb magic to control this feature, and updated |
|
3024 | -pdb option and @pdb magic to control this feature, and updated | |
2989 | the docs. After a suggestion from Christopher Hart |
|
3025 | the docs. After a suggestion from Christopher Hart | |
2990 | (hart-AT-caltech.edu). |
|
3026 | (hart-AT-caltech.edu). | |
2991 |
|
3027 | |||
2992 | 2002-04-12 Fernando Perez <fperez@colorado.edu> |
|
3028 | 2002-04-12 Fernando Perez <fperez@colorado.edu> | |
2993 |
|
3029 | |||
2994 | * IPython/Shell.py (IPythonShellEmbed.__init__): modified to use |
|
3030 | * IPython/Shell.py (IPythonShellEmbed.__init__): modified to use | |
2995 | the exception handlers defined by the user (not the CrashHandler) |
|
3031 | the exception handlers defined by the user (not the CrashHandler) | |
2996 | so that user exceptions don't trigger an ipython bug report. |
|
3032 | so that user exceptions don't trigger an ipython bug report. | |
2997 |
|
3033 | |||
2998 | * IPython/ultraTB.py (ColorTB.__init__): made the color scheme |
|
3034 | * IPython/ultraTB.py (ColorTB.__init__): made the color scheme | |
2999 | configurable (it should have always been so). |
|
3035 | configurable (it should have always been so). | |
3000 |
|
3036 | |||
3001 | 2002-03-26 Fernando Perez <fperez@colorado.edu> |
|
3037 | 2002-03-26 Fernando Perez <fperez@colorado.edu> | |
3002 |
|
3038 | |||
3003 | * IPython/Shell.py (IPythonShellEmbed.__call__): many changes here |
|
3039 | * IPython/Shell.py (IPythonShellEmbed.__call__): many changes here | |
3004 | and there to fix embedding namespace issues. This should all be |
|
3040 | and there to fix embedding namespace issues. This should all be | |
3005 | done in a more elegant way. |
|
3041 | done in a more elegant way. | |
3006 |
|
3042 | |||
3007 | 2002-03-25 Fernando Perez <fperez@colorado.edu> |
|
3043 | 2002-03-25 Fernando Perez <fperez@colorado.edu> | |
3008 |
|
3044 | |||
3009 | * IPython/genutils.py (get_home_dir): Try to make it work under |
|
3045 | * IPython/genutils.py (get_home_dir): Try to make it work under | |
3010 | win9x also. |
|
3046 | win9x also. | |
3011 |
|
3047 | |||
3012 | 2002-03-20 Fernando Perez <fperez@colorado.edu> |
|
3048 | 2002-03-20 Fernando Perez <fperez@colorado.edu> | |
3013 |
|
3049 | |||
3014 | * IPython/Shell.py (IPythonShellEmbed.__init__): leave |
|
3050 | * IPython/Shell.py (IPythonShellEmbed.__init__): leave | |
3015 | sys.displayhook untouched upon __init__. |
|
3051 | sys.displayhook untouched upon __init__. | |
3016 |
|
3052 | |||
3017 | 2002-03-19 Fernando Perez <fperez@colorado.edu> |
|
3053 | 2002-03-19 Fernando Perez <fperez@colorado.edu> | |
3018 |
|
3054 | |||
3019 | * Released 0.2.9 (for embedding bug, basically). |
|
3055 | * Released 0.2.9 (for embedding bug, basically). | |
3020 |
|
3056 | |||
3021 | * IPython/Shell.py (IPythonShellEmbed.__call__): Trap SystemExit |
|
3057 | * IPython/Shell.py (IPythonShellEmbed.__call__): Trap SystemExit | |
3022 | exceptions so that enclosing shell's state can be restored. |
|
3058 | exceptions so that enclosing shell's state can be restored. | |
3023 |
|
3059 | |||
3024 | * Changed magic_gnuplot.py to magic-gnuplot.py to standardize |
|
3060 | * Changed magic_gnuplot.py to magic-gnuplot.py to standardize | |
3025 | naming conventions in the .ipython/ dir. |
|
3061 | naming conventions in the .ipython/ dir. | |
3026 |
|
3062 | |||
3027 | * IPython/iplib.py (InteractiveShell.init_readline): removed '-' |
|
3063 | * IPython/iplib.py (InteractiveShell.init_readline): removed '-' | |
3028 | from delimiters list so filenames with - in them get expanded. |
|
3064 | from delimiters list so filenames with - in them get expanded. | |
3029 |
|
3065 | |||
3030 | * IPython/Shell.py (IPythonShellEmbed.__call__): fixed bug with |
|
3066 | * IPython/Shell.py (IPythonShellEmbed.__call__): fixed bug with | |
3031 | sys.displayhook not being properly restored after an embedded call. |
|
3067 | sys.displayhook not being properly restored after an embedded call. | |
3032 |
|
3068 | |||
3033 | 2002-03-18 Fernando Perez <fperez@colorado.edu> |
|
3069 | 2002-03-18 Fernando Perez <fperez@colorado.edu> | |
3034 |
|
3070 | |||
3035 | * Released 0.2.8 |
|
3071 | * Released 0.2.8 | |
3036 |
|
3072 | |||
3037 | * IPython/iplib.py (InteractiveShell.user_setup): fixed bug where |
|
3073 | * IPython/iplib.py (InteractiveShell.user_setup): fixed bug where | |
3038 | some files weren't being included in a -upgrade. |
|
3074 | some files weren't being included in a -upgrade. | |
3039 | (InteractiveShell.init_readline): Added 'set show-all-if-ambiguous |
|
3075 | (InteractiveShell.init_readline): Added 'set show-all-if-ambiguous | |
3040 | on' so that the first tab completes. |
|
3076 | on' so that the first tab completes. | |
3041 | (InteractiveShell.handle_magic): fixed bug with spaces around |
|
3077 | (InteractiveShell.handle_magic): fixed bug with spaces around | |
3042 | quotes breaking many magic commands. |
|
3078 | quotes breaking many magic commands. | |
3043 |
|
3079 | |||
3044 | * setup.py: added note about ignoring the syntax error messages at |
|
3080 | * setup.py: added note about ignoring the syntax error messages at | |
3045 | installation. |
|
3081 | installation. | |
3046 |
|
3082 | |||
3047 | * IPython/UserConfig/magic_gnuplot.py (magic_gp): finished |
|
3083 | * IPython/UserConfig/magic_gnuplot.py (magic_gp): finished | |
3048 | streamlining the gnuplot interface, now there's only one magic @gp. |
|
3084 | streamlining the gnuplot interface, now there's only one magic @gp. | |
3049 |
|
3085 | |||
3050 | 2002-03-17 Fernando Perez <fperez@colorado.edu> |
|
3086 | 2002-03-17 Fernando Perez <fperez@colorado.edu> | |
3051 |
|
3087 | |||
3052 | * IPython/UserConfig/magic_gnuplot.py: new name for the |
|
3088 | * IPython/UserConfig/magic_gnuplot.py: new name for the | |
3053 | example-magic_pm.py file. Much enhanced system, now with a shell |
|
3089 | example-magic_pm.py file. Much enhanced system, now with a shell | |
3054 | for communicating directly with gnuplot, one command at a time. |
|
3090 | for communicating directly with gnuplot, one command at a time. | |
3055 |
|
3091 | |||
3056 | * IPython/Magic.py (Magic.magic_run): added option -n to prevent |
|
3092 | * IPython/Magic.py (Magic.magic_run): added option -n to prevent | |
3057 | setting __name__=='__main__'. |
|
3093 | setting __name__=='__main__'. | |
3058 |
|
3094 | |||
3059 | * IPython/UserConfig/example-magic_pm.py (magic_pm): Added |
|
3095 | * IPython/UserConfig/example-magic_pm.py (magic_pm): Added | |
3060 | mini-shell for accessing gnuplot from inside ipython. Should |
|
3096 | mini-shell for accessing gnuplot from inside ipython. Should | |
3061 | extend it later for grace access too. Inspired by Arnd's |
|
3097 | extend it later for grace access too. Inspired by Arnd's | |
3062 | suggestion. |
|
3098 | suggestion. | |
3063 |
|
3099 | |||
3064 | * IPython/iplib.py (InteractiveShell.handle_magic): fixed bug when |
|
3100 | * IPython/iplib.py (InteractiveShell.handle_magic): fixed bug when | |
3065 | calling magic functions with () in their arguments. Thanks to Arnd |
|
3101 | calling magic functions with () in their arguments. Thanks to Arnd | |
3066 | Baecker for pointing this to me. |
|
3102 | Baecker for pointing this to me. | |
3067 |
|
3103 | |||
3068 | * IPython/numutils.py (sum_flat): fixed bug. Would recurse |
|
3104 | * IPython/numutils.py (sum_flat): fixed bug. Would recurse | |
3069 | infinitely for integer or complex arrays (only worked with floats). |
|
3105 | infinitely for integer or complex arrays (only worked with floats). | |
3070 |
|
3106 | |||
3071 | 2002-03-16 Fernando Perez <fperez@colorado.edu> |
|
3107 | 2002-03-16 Fernando Perez <fperez@colorado.edu> | |
3072 |
|
3108 | |||
3073 | * setup.py: Merged setup and setup_windows into a single script |
|
3109 | * setup.py: Merged setup and setup_windows into a single script | |
3074 | which properly handles things for windows users. |
|
3110 | which properly handles things for windows users. | |
3075 |
|
3111 | |||
3076 | 2002-03-15 Fernando Perez <fperez@colorado.edu> |
|
3112 | 2002-03-15 Fernando Perez <fperez@colorado.edu> | |
3077 |
|
3113 | |||
3078 | * Big change to the manual: now the magics are all automatically |
|
3114 | * Big change to the manual: now the magics are all automatically | |
3079 | documented. This information is generated from their docstrings |
|
3115 | documented. This information is generated from their docstrings | |
3080 | and put in a latex file included by the manual lyx file. This way |
|
3116 | and put in a latex file included by the manual lyx file. This way | |
3081 | we get always up to date information for the magics. The manual |
|
3117 | we get always up to date information for the magics. The manual | |
3082 | now also has proper version information, also auto-synced. |
|
3118 | now also has proper version information, also auto-synced. | |
3083 |
|
3119 | |||
3084 | For this to work, an undocumented --magic_docstrings option was added. |
|
3120 | For this to work, an undocumented --magic_docstrings option was added. | |
3085 |
|
3121 | |||
3086 | 2002-03-13 Fernando Perez <fperez@colorado.edu> |
|
3122 | 2002-03-13 Fernando Perez <fperez@colorado.edu> | |
3087 |
|
3123 | |||
3088 | * IPython/ultraTB.py (TermColors): fixed problem with dark colors |
|
3124 | * IPython/ultraTB.py (TermColors): fixed problem with dark colors | |
3089 | under CDE terminals. An explicit ;2 color reset is needed in the escapes. |
|
3125 | under CDE terminals. An explicit ;2 color reset is needed in the escapes. | |
3090 |
|
3126 | |||
3091 | 2002-03-12 Fernando Perez <fperez@colorado.edu> |
|
3127 | 2002-03-12 Fernando Perez <fperez@colorado.edu> | |
3092 |
|
3128 | |||
3093 | * IPython/ultraTB.py (TermColors): changed color escapes again to |
|
3129 | * IPython/ultraTB.py (TermColors): changed color escapes again to | |
3094 | fix the (old, reintroduced) line-wrapping bug. Basically, if |
|
3130 | fix the (old, reintroduced) line-wrapping bug. Basically, if | |
3095 | \001..\002 aren't given in the color escapes, lines get wrapped |
|
3131 | \001..\002 aren't given in the color escapes, lines get wrapped | |
3096 | weirdly. But giving those screws up old xterms and emacs terms. So |
|
3132 | weirdly. But giving those screws up old xterms and emacs terms. So | |
3097 | I added some logic for emacs terms to be ok, but I can't identify old |
|
3133 | I added some logic for emacs terms to be ok, but I can't identify old | |
3098 | xterms separately ($TERM=='xterm' for many terminals, like konsole). |
|
3134 | xterms separately ($TERM=='xterm' for many terminals, like konsole). | |
3099 |
|
3135 | |||
3100 | 2002-03-10 Fernando Perez <fperez@colorado.edu> |
|
3136 | 2002-03-10 Fernando Perez <fperez@colorado.edu> | |
3101 |
|
3137 | |||
3102 | * IPython/usage.py (__doc__): Various documentation cleanups and |
|
3138 | * IPython/usage.py (__doc__): Various documentation cleanups and | |
3103 | updates, both in usage docstrings and in the manual. |
|
3139 | updates, both in usage docstrings and in the manual. | |
3104 |
|
3140 | |||
3105 | * IPython/Prompts.py (CachedOutput.set_colors): cleanups for |
|
3141 | * IPython/Prompts.py (CachedOutput.set_colors): cleanups for | |
3106 | handling of caching. Set minimum acceptabe value for having a |
|
3142 | handling of caching. Set minimum acceptabe value for having a | |
3107 | cache at 20 values. |
|
3143 | cache at 20 values. | |
3108 |
|
3144 | |||
3109 | * IPython/iplib.py (InteractiveShell.user_setup): moved the |
|
3145 | * IPython/iplib.py (InteractiveShell.user_setup): moved the | |
3110 | install_first_time function to a method, renamed it and added an |
|
3146 | install_first_time function to a method, renamed it and added an | |
3111 | 'upgrade' mode. Now people can update their config directory with |
|
3147 | 'upgrade' mode. Now people can update their config directory with | |
3112 | a simple command line switch (-upgrade, also new). |
|
3148 | a simple command line switch (-upgrade, also new). | |
3113 |
|
3149 | |||
3114 | * IPython/Magic.py (Magic.magic_pfile): Made @pfile an alias to |
|
3150 | * IPython/Magic.py (Magic.magic_pfile): Made @pfile an alias to | |
3115 | @file (convenient for automagic users under Python >= 2.2). |
|
3151 | @file (convenient for automagic users under Python >= 2.2). | |
3116 | Removed @files (it seemed more like a plural than an abbrev. of |
|
3152 | Removed @files (it seemed more like a plural than an abbrev. of | |
3117 | 'file show'). |
|
3153 | 'file show'). | |
3118 |
|
3154 | |||
3119 | * IPython/iplib.py (install_first_time): Fixed crash if there were |
|
3155 | * IPython/iplib.py (install_first_time): Fixed crash if there were | |
3120 | backup files ('~') in .ipython/ install directory. |
|
3156 | backup files ('~') in .ipython/ install directory. | |
3121 |
|
3157 | |||
3122 | * IPython/ipmaker.py (make_IPython): fixes for new prompt |
|
3158 | * IPython/ipmaker.py (make_IPython): fixes for new prompt | |
3123 | system. Things look fine, but these changes are fairly |
|
3159 | system. Things look fine, but these changes are fairly | |
3124 | intrusive. Test them for a few days. |
|
3160 | intrusive. Test them for a few days. | |
3125 |
|
3161 | |||
3126 | * IPython/Prompts.py (CachedOutput.__init__): Massive rewrite of |
|
3162 | * IPython/Prompts.py (CachedOutput.__init__): Massive rewrite of | |
3127 | the prompts system. Now all in/out prompt strings are user |
|
3163 | the prompts system. Now all in/out prompt strings are user | |
3128 | controllable. This is particularly useful for embedding, as one |
|
3164 | controllable. This is particularly useful for embedding, as one | |
3129 | can tag embedded instances with particular prompts. |
|
3165 | can tag embedded instances with particular prompts. | |
3130 |
|
3166 | |||
3131 | Also removed global use of sys.ps1/2, which now allows nested |
|
3167 | Also removed global use of sys.ps1/2, which now allows nested | |
3132 | embeddings without any problems. Added command-line options for |
|
3168 | embeddings without any problems. Added command-line options for | |
3133 | the prompt strings. |
|
3169 | the prompt strings. | |
3134 |
|
3170 | |||
3135 | 2002-03-08 Fernando Perez <fperez@colorado.edu> |
|
3171 | 2002-03-08 Fernando Perez <fperez@colorado.edu> | |
3136 |
|
3172 | |||
3137 | * IPython/UserConfig/example-embed-short.py (ipshell): added |
|
3173 | * IPython/UserConfig/example-embed-short.py (ipshell): added | |
3138 | example file with the bare minimum code for embedding. |
|
3174 | example file with the bare minimum code for embedding. | |
3139 |
|
3175 | |||
3140 | * IPython/Shell.py (IPythonShellEmbed.set_dummy_mode): added |
|
3176 | * IPython/Shell.py (IPythonShellEmbed.set_dummy_mode): added | |
3141 | functionality for the embeddable shell to be activated/deactivated |
|
3177 | functionality for the embeddable shell to be activated/deactivated | |
3142 | either globally or at each call. |
|
3178 | either globally or at each call. | |
3143 |
|
3179 | |||
3144 | * IPython/Prompts.py (Prompt1.auto_rewrite): Fixes the problem of |
|
3180 | * IPython/Prompts.py (Prompt1.auto_rewrite): Fixes the problem of | |
3145 | rewriting the prompt with '--->' for auto-inputs with proper |
|
3181 | rewriting the prompt with '--->' for auto-inputs with proper | |
3146 | coloring. Now the previous UGLY hack in handle_auto() is gone, and |
|
3182 | coloring. Now the previous UGLY hack in handle_auto() is gone, and | |
3147 | this is handled by the prompts class itself, as it should. |
|
3183 | this is handled by the prompts class itself, as it should. | |
3148 |
|
3184 | |||
3149 | 2002-03-05 Fernando Perez <fperez@colorado.edu> |
|
3185 | 2002-03-05 Fernando Perez <fperez@colorado.edu> | |
3150 |
|
3186 | |||
3151 | * IPython/Magic.py (Magic.magic_logstart): Changed @log to |
|
3187 | * IPython/Magic.py (Magic.magic_logstart): Changed @log to | |
3152 | @logstart to avoid name clashes with the math log function. |
|
3188 | @logstart to avoid name clashes with the math log function. | |
3153 |
|
3189 | |||
3154 | * Big updates to X/Emacs section of the manual. |
|
3190 | * Big updates to X/Emacs section of the manual. | |
3155 |
|
3191 | |||
3156 | * Removed ipython_emacs. Milan explained to me how to pass |
|
3192 | * Removed ipython_emacs. Milan explained to me how to pass | |
3157 | arguments to ipython through Emacs. Some day I'm going to end up |
|
3193 | arguments to ipython through Emacs. Some day I'm going to end up | |
3158 | learning some lisp... |
|
3194 | learning some lisp... | |
3159 |
|
3195 | |||
3160 | 2002-03-04 Fernando Perez <fperez@colorado.edu> |
|
3196 | 2002-03-04 Fernando Perez <fperez@colorado.edu> | |
3161 |
|
3197 | |||
3162 | * IPython/ipython_emacs: Created script to be used as the |
|
3198 | * IPython/ipython_emacs: Created script to be used as the | |
3163 | py-python-command Emacs variable so we can pass IPython |
|
3199 | py-python-command Emacs variable so we can pass IPython | |
3164 | parameters. I can't figure out how to tell Emacs directly to pass |
|
3200 | parameters. I can't figure out how to tell Emacs directly to pass | |
3165 | parameters to IPython, so a dummy shell script will do it. |
|
3201 | parameters to IPython, so a dummy shell script will do it. | |
3166 |
|
3202 | |||
3167 | Other enhancements made for things to work better under Emacs' |
|
3203 | Other enhancements made for things to work better under Emacs' | |
3168 | various types of terminals. Many thanks to Milan Zamazal |
|
3204 | various types of terminals. Many thanks to Milan Zamazal | |
3169 | <pdm-AT-zamazal.org> for all the suggestions and pointers. |
|
3205 | <pdm-AT-zamazal.org> for all the suggestions and pointers. | |
3170 |
|
3206 | |||
3171 | 2002-03-01 Fernando Perez <fperez@colorado.edu> |
|
3207 | 2002-03-01 Fernando Perez <fperez@colorado.edu> | |
3172 |
|
3208 | |||
3173 | * IPython/ipmaker.py (make_IPython): added a --readline! option so |
|
3209 | * IPython/ipmaker.py (make_IPython): added a --readline! option so | |
3174 | that loading of readline is now optional. This gives better |
|
3210 | that loading of readline is now optional. This gives better | |
3175 | control to emacs users. |
|
3211 | control to emacs users. | |
3176 |
|
3212 | |||
3177 | * IPython/ultraTB.py (__date__): Modified color escape sequences |
|
3213 | * IPython/ultraTB.py (__date__): Modified color escape sequences | |
3178 | and now things work fine under xterm and in Emacs' term buffers |
|
3214 | and now things work fine under xterm and in Emacs' term buffers | |
3179 | (though not shell ones). Well, in emacs you get colors, but all |
|
3215 | (though not shell ones). Well, in emacs you get colors, but all | |
3180 | seem to be 'light' colors (no difference between dark and light |
|
3216 | seem to be 'light' colors (no difference between dark and light | |
3181 | ones). But the garbage chars are gone, and also in xterms. It |
|
3217 | ones). But the garbage chars are gone, and also in xterms. It | |
3182 | seems that now I'm using 'cleaner' ansi sequences. |
|
3218 | seems that now I'm using 'cleaner' ansi sequences. | |
3183 |
|
3219 | |||
3184 | 2002-02-21 Fernando Perez <fperez@colorado.edu> |
|
3220 | 2002-02-21 Fernando Perez <fperez@colorado.edu> | |
3185 |
|
3221 | |||
3186 | * Released 0.2.7 (mainly to publish the scoping fix). |
|
3222 | * Released 0.2.7 (mainly to publish the scoping fix). | |
3187 |
|
3223 | |||
3188 | * IPython/Logger.py (Logger.logstate): added. A corresponding |
|
3224 | * IPython/Logger.py (Logger.logstate): added. A corresponding | |
3189 | @logstate magic was created. |
|
3225 | @logstate magic was created. | |
3190 |
|
3226 | |||
3191 | * IPython/Magic.py: fixed nested scoping problem under Python |
|
3227 | * IPython/Magic.py: fixed nested scoping problem under Python | |
3192 | 2.1.x (automagic wasn't working). |
|
3228 | 2.1.x (automagic wasn't working). | |
3193 |
|
3229 | |||
3194 | 2002-02-20 Fernando Perez <fperez@colorado.edu> |
|
3230 | 2002-02-20 Fernando Perez <fperez@colorado.edu> | |
3195 |
|
3231 | |||
3196 | * Released 0.2.6. |
|
3232 | * Released 0.2.6. | |
3197 |
|
3233 | |||
3198 | * IPython/OutputTrap.py (OutputTrap.__init__): added a 'quiet' |
|
3234 | * IPython/OutputTrap.py (OutputTrap.__init__): added a 'quiet' | |
3199 | option so that logs can come out without any headers at all. |
|
3235 | option so that logs can come out without any headers at all. | |
3200 |
|
3236 | |||
3201 | * IPython/UserConfig/ipythonrc-scipy.py: created a profile for |
|
3237 | * IPython/UserConfig/ipythonrc-scipy.py: created a profile for | |
3202 | SciPy. |
|
3238 | SciPy. | |
3203 |
|
3239 | |||
3204 | * IPython/iplib.py (InteractiveShell.embed_mainloop): Changed so |
|
3240 | * IPython/iplib.py (InteractiveShell.embed_mainloop): Changed so | |
3205 | that embedded IPython calls don't require vars() to be explicitly |
|
3241 | that embedded IPython calls don't require vars() to be explicitly | |
3206 | passed. Now they are extracted from the caller's frame (code |
|
3242 | passed. Now they are extracted from the caller's frame (code | |
3207 | snatched from Eric Jones' weave). Added better documentation to |
|
3243 | snatched from Eric Jones' weave). Added better documentation to | |
3208 | the section on embedding and the example file. |
|
3244 | the section on embedding and the example file. | |
3209 |
|
3245 | |||
3210 | * IPython/genutils.py (page): Changed so that under emacs, it just |
|
3246 | * IPython/genutils.py (page): Changed so that under emacs, it just | |
3211 | prints the string. You can then page up and down in the emacs |
|
3247 | prints the string. You can then page up and down in the emacs | |
3212 | buffer itself. This is how the builtin help() works. |
|
3248 | buffer itself. This is how the builtin help() works. | |
3213 |
|
3249 | |||
3214 | * IPython/Prompts.py (CachedOutput.__call__): Fixed issue with |
|
3250 | * IPython/Prompts.py (CachedOutput.__call__): Fixed issue with | |
3215 | macro scoping: macros need to be executed in the user's namespace |
|
3251 | macro scoping: macros need to be executed in the user's namespace | |
3216 | to work as if they had been typed by the user. |
|
3252 | to work as if they had been typed by the user. | |
3217 |
|
3253 | |||
3218 | * IPython/Magic.py (Magic.magic_macro): Changed macros so they |
|
3254 | * IPython/Magic.py (Magic.magic_macro): Changed macros so they | |
3219 | execute automatically (no need to type 'exec...'). They then |
|
3255 | execute automatically (no need to type 'exec...'). They then | |
3220 | behave like 'true macros'. The printing system was also modified |
|
3256 | behave like 'true macros'. The printing system was also modified | |
3221 | for this to work. |
|
3257 | for this to work. | |
3222 |
|
3258 | |||
3223 | 2002-02-19 Fernando Perez <fperez@colorado.edu> |
|
3259 | 2002-02-19 Fernando Perez <fperez@colorado.edu> | |
3224 |
|
3260 | |||
3225 | * IPython/genutils.py (page_file): new function for paging files |
|
3261 | * IPython/genutils.py (page_file): new function for paging files | |
3226 | in an OS-independent way. Also necessary for file viewing to work |
|
3262 | in an OS-independent way. Also necessary for file viewing to work | |
3227 | well inside Emacs buffers. |
|
3263 | well inside Emacs buffers. | |
3228 | (page): Added checks for being in an emacs buffer. |
|
3264 | (page): Added checks for being in an emacs buffer. | |
3229 | (page): fixed bug for Windows ($TERM isn't set in Windows). Fixed |
|
3265 | (page): fixed bug for Windows ($TERM isn't set in Windows). Fixed | |
3230 | same bug in iplib. |
|
3266 | same bug in iplib. | |
3231 |
|
3267 | |||
3232 | 2002-02-18 Fernando Perez <fperez@colorado.edu> |
|
3268 | 2002-02-18 Fernando Perez <fperez@colorado.edu> | |
3233 |
|
3269 | |||
3234 | * IPython/iplib.py (InteractiveShell.init_readline): modified use |
|
3270 | * IPython/iplib.py (InteractiveShell.init_readline): modified use | |
3235 | of readline so that IPython can work inside an Emacs buffer. |
|
3271 | of readline so that IPython can work inside an Emacs buffer. | |
3236 |
|
3272 | |||
3237 | * IPython/ultraTB.py (AutoFormattedTB.__call__): some fixes to |
|
3273 | * IPython/ultraTB.py (AutoFormattedTB.__call__): some fixes to | |
3238 | method signatures (they weren't really bugs, but it looks cleaner |
|
3274 | method signatures (they weren't really bugs, but it looks cleaner | |
3239 | and keeps PyChecker happy). |
|
3275 | and keeps PyChecker happy). | |
3240 |
|
3276 | |||
3241 | * IPython/ipmaker.py (make_IPython): added hooks Struct to __IP |
|
3277 | * IPython/ipmaker.py (make_IPython): added hooks Struct to __IP | |
3242 | for implementing various user-defined hooks. Currently only |
|
3278 | for implementing various user-defined hooks. Currently only | |
3243 | display is done. |
|
3279 | display is done. | |
3244 |
|
3280 | |||
3245 | * IPython/Prompts.py (CachedOutput._display): changed display |
|
3281 | * IPython/Prompts.py (CachedOutput._display): changed display | |
3246 | functions so that they can be dynamically changed by users easily. |
|
3282 | functions so that they can be dynamically changed by users easily. | |
3247 |
|
3283 | |||
3248 | * IPython/Extensions/numeric_formats.py (num_display): added an |
|
3284 | * IPython/Extensions/numeric_formats.py (num_display): added an | |
3249 | extension for printing NumPy arrays in flexible manners. It |
|
3285 | extension for printing NumPy arrays in flexible manners. It | |
3250 | doesn't do anything yet, but all the structure is in |
|
3286 | doesn't do anything yet, but all the structure is in | |
3251 | place. Ultimately the plan is to implement output format control |
|
3287 | place. Ultimately the plan is to implement output format control | |
3252 | like in Octave. |
|
3288 | like in Octave. | |
3253 |
|
3289 | |||
3254 | * IPython/Magic.py (Magic.lsmagic): changed so that bound magic |
|
3290 | * IPython/Magic.py (Magic.lsmagic): changed so that bound magic | |
3255 | methods are found at run-time by all the automatic machinery. |
|
3291 | methods are found at run-time by all the automatic machinery. | |
3256 |
|
3292 | |||
3257 | 2002-02-17 Fernando Perez <fperez@colorado.edu> |
|
3293 | 2002-02-17 Fernando Perez <fperez@colorado.edu> | |
3258 |
|
3294 | |||
3259 | * setup_Windows.py (make_shortcut): documented. Cleaned up the |
|
3295 | * setup_Windows.py (make_shortcut): documented. Cleaned up the | |
3260 | whole file a little. |
|
3296 | whole file a little. | |
3261 |
|
3297 | |||
3262 | * ToDo: closed this document. Now there's a new_design.lyx |
|
3298 | * ToDo: closed this document. Now there's a new_design.lyx | |
3263 | document for all new ideas. Added making a pdf of it for the |
|
3299 | document for all new ideas. Added making a pdf of it for the | |
3264 | end-user distro. |
|
3300 | end-user distro. | |
3265 |
|
3301 | |||
3266 | * IPython/Logger.py (Logger.switch_log): Created this to replace |
|
3302 | * IPython/Logger.py (Logger.switch_log): Created this to replace | |
3267 | logon() and logoff(). It also fixes a nasty crash reported by |
|
3303 | logon() and logoff(). It also fixes a nasty crash reported by | |
3268 | Philip Hisley <compsys-AT-starpower.net>. Many thanks to him. |
|
3304 | Philip Hisley <compsys-AT-starpower.net>. Many thanks to him. | |
3269 |
|
3305 | |||
3270 | * IPython/iplib.py (complete): got auto-completion to work with |
|
3306 | * IPython/iplib.py (complete): got auto-completion to work with | |
3271 | automagic (I had wanted this for a long time). |
|
3307 | automagic (I had wanted this for a long time). | |
3272 |
|
3308 | |||
3273 | * IPython/Magic.py (Magic.magic_files): Added @files as an alias |
|
3309 | * IPython/Magic.py (Magic.magic_files): Added @files as an alias | |
3274 | to @file, since file() is now a builtin and clashes with automagic |
|
3310 | to @file, since file() is now a builtin and clashes with automagic | |
3275 | for @file. |
|
3311 | for @file. | |
3276 |
|
3312 | |||
3277 | * Made some new files: Prompts, CrashHandler, Magic, Logger. All |
|
3313 | * Made some new files: Prompts, CrashHandler, Magic, Logger. All | |
3278 | of this was previously in iplib, which had grown to more than 2000 |
|
3314 | of this was previously in iplib, which had grown to more than 2000 | |
3279 | lines, way too long. No new functionality, but it makes managing |
|
3315 | lines, way too long. No new functionality, but it makes managing | |
3280 | the code a bit easier. |
|
3316 | the code a bit easier. | |
3281 |
|
3317 | |||
3282 | * IPython/iplib.py (IPythonCrashHandler.__call__): Added version |
|
3318 | * IPython/iplib.py (IPythonCrashHandler.__call__): Added version | |
3283 | information to crash reports. |
|
3319 | information to crash reports. | |
3284 |
|
3320 | |||
3285 | 2002-02-12 Fernando Perez <fperez@colorado.edu> |
|
3321 | 2002-02-12 Fernando Perez <fperez@colorado.edu> | |
3286 |
|
3322 | |||
3287 | * Released 0.2.5. |
|
3323 | * Released 0.2.5. | |
3288 |
|
3324 | |||
3289 | 2002-02-11 Fernando Perez <fperez@colorado.edu> |
|
3325 | 2002-02-11 Fernando Perez <fperez@colorado.edu> | |
3290 |
|
3326 | |||
3291 | * Wrote a relatively complete Windows installer. It puts |
|
3327 | * Wrote a relatively complete Windows installer. It puts | |
3292 | everything in place, creates Start Menu entries and fixes the |
|
3328 | everything in place, creates Start Menu entries and fixes the | |
3293 | color issues. Nothing fancy, but it works. |
|
3329 | color issues. Nothing fancy, but it works. | |
3294 |
|
3330 | |||
3295 | 2002-02-10 Fernando Perez <fperez@colorado.edu> |
|
3331 | 2002-02-10 Fernando Perez <fperez@colorado.edu> | |
3296 |
|
3332 | |||
3297 | * IPython/iplib.py (InteractiveShell.safe_execfile): added an |
|
3333 | * IPython/iplib.py (InteractiveShell.safe_execfile): added an | |
3298 | os.path.expanduser() call so that we can type @run ~/myfile.py and |
|
3334 | os.path.expanduser() call so that we can type @run ~/myfile.py and | |
3299 | have thigs work as expected. |
|
3335 | have thigs work as expected. | |
3300 |
|
3336 | |||
3301 | * IPython/genutils.py (page): fixed exception handling so things |
|
3337 | * IPython/genutils.py (page): fixed exception handling so things | |
3302 | work both in Unix and Windows correctly. Quitting a pager triggers |
|
3338 | work both in Unix and Windows correctly. Quitting a pager triggers | |
3303 | an IOError/broken pipe in Unix, and in windows not finding a pager |
|
3339 | an IOError/broken pipe in Unix, and in windows not finding a pager | |
3304 | is also an IOError, so I had to actually look at the return value |
|
3340 | is also an IOError, so I had to actually look at the return value | |
3305 | of the exception, not just the exception itself. Should be ok now. |
|
3341 | of the exception, not just the exception itself. Should be ok now. | |
3306 |
|
3342 | |||
3307 | * IPython/ultraTB.py (ColorSchemeTable.set_active_scheme): |
|
3343 | * IPython/ultraTB.py (ColorSchemeTable.set_active_scheme): | |
3308 | modified to allow case-insensitive color scheme changes. |
|
3344 | modified to allow case-insensitive color scheme changes. | |
3309 |
|
3345 | |||
3310 | 2002-02-09 Fernando Perez <fperez@colorado.edu> |
|
3346 | 2002-02-09 Fernando Perez <fperez@colorado.edu> | |
3311 |
|
3347 | |||
3312 | * IPython/genutils.py (native_line_ends): new function to leave |
|
3348 | * IPython/genutils.py (native_line_ends): new function to leave | |
3313 | user config files with os-native line-endings. |
|
3349 | user config files with os-native line-endings. | |
3314 |
|
3350 | |||
3315 | * README and manual updates. |
|
3351 | * README and manual updates. | |
3316 |
|
3352 | |||
3317 | * IPython/genutils.py: fixed unicode bug: use types.StringTypes |
|
3353 | * IPython/genutils.py: fixed unicode bug: use types.StringTypes | |
3318 | instead of StringType to catch Unicode strings. |
|
3354 | instead of StringType to catch Unicode strings. | |
3319 |
|
3355 | |||
3320 | * IPython/genutils.py (filefind): fixed bug for paths with |
|
3356 | * IPython/genutils.py (filefind): fixed bug for paths with | |
3321 | embedded spaces (very common in Windows). |
|
3357 | embedded spaces (very common in Windows). | |
3322 |
|
3358 | |||
3323 | * IPython/ipmaker.py (make_IPython): added a '.ini' to the rc |
|
3359 | * IPython/ipmaker.py (make_IPython): added a '.ini' to the rc | |
3324 | files under Windows, so that they get automatically associated |
|
3360 | files under Windows, so that they get automatically associated | |
3325 | with a text editor. Windows makes it a pain to handle |
|
3361 | with a text editor. Windows makes it a pain to handle | |
3326 | extension-less files. |
|
3362 | extension-less files. | |
3327 |
|
3363 | |||
3328 | * IPython/iplib.py (InteractiveShell.init_readline): Made the |
|
3364 | * IPython/iplib.py (InteractiveShell.init_readline): Made the | |
3329 | warning about readline only occur for Posix. In Windows there's no |
|
3365 | warning about readline only occur for Posix. In Windows there's no | |
3330 | way to get readline, so why bother with the warning. |
|
3366 | way to get readline, so why bother with the warning. | |
3331 |
|
3367 | |||
3332 | * IPython/Struct.py (Struct.__str__): fixed to use self.__dict__ |
|
3368 | * IPython/Struct.py (Struct.__str__): fixed to use self.__dict__ | |
3333 | for __str__ instead of dir(self), since dir() changed in 2.2. |
|
3369 | for __str__ instead of dir(self), since dir() changed in 2.2. | |
3334 |
|
3370 | |||
3335 | * Ported to Windows! Tested on XP, I suspect it should work fine |
|
3371 | * Ported to Windows! Tested on XP, I suspect it should work fine | |
3336 | on NT/2000, but I don't think it will work on 98 et al. That |
|
3372 | on NT/2000, but I don't think it will work on 98 et al. That | |
3337 | series of Windows is such a piece of junk anyway that I won't try |
|
3373 | series of Windows is such a piece of junk anyway that I won't try | |
3338 | porting it there. The XP port was straightforward, showed a few |
|
3374 | porting it there. The XP port was straightforward, showed a few | |
3339 | bugs here and there (fixed all), in particular some string |
|
3375 | bugs here and there (fixed all), in particular some string | |
3340 | handling stuff which required considering Unicode strings (which |
|
3376 | handling stuff which required considering Unicode strings (which | |
3341 | Windows uses). This is good, but hasn't been too tested :) No |
|
3377 | Windows uses). This is good, but hasn't been too tested :) No | |
3342 | fancy installer yet, I'll put a note in the manual so people at |
|
3378 | fancy installer yet, I'll put a note in the manual so people at | |
3343 | least make manually a shortcut. |
|
3379 | least make manually a shortcut. | |
3344 |
|
3380 | |||
3345 | * IPython/iplib.py (Magic.magic_colors): Unified the color options |
|
3381 | * IPython/iplib.py (Magic.magic_colors): Unified the color options | |
3346 | into a single one, "colors". This now controls both prompt and |
|
3382 | into a single one, "colors". This now controls both prompt and | |
3347 | exception color schemes, and can be changed both at startup |
|
3383 | exception color schemes, and can be changed both at startup | |
3348 | (either via command-line switches or via ipythonrc files) and at |
|
3384 | (either via command-line switches or via ipythonrc files) and at | |
3349 | runtime, with @colors. |
|
3385 | runtime, with @colors. | |
3350 | (Magic.magic_run): renamed @prun to @run and removed the old |
|
3386 | (Magic.magic_run): renamed @prun to @run and removed the old | |
3351 | @run. The two were too similar to warrant keeping both. |
|
3387 | @run. The two were too similar to warrant keeping both. | |
3352 |
|
3388 | |||
3353 | 2002-02-03 Fernando Perez <fperez@colorado.edu> |
|
3389 | 2002-02-03 Fernando Perez <fperez@colorado.edu> | |
3354 |
|
3390 | |||
3355 | * IPython/iplib.py (install_first_time): Added comment on how to |
|
3391 | * IPython/iplib.py (install_first_time): Added comment on how to | |
3356 | configure the color options for first-time users. Put a <return> |
|
3392 | configure the color options for first-time users. Put a <return> | |
3357 | request at the end so that small-terminal users get a chance to |
|
3393 | request at the end so that small-terminal users get a chance to | |
3358 | read the startup info. |
|
3394 | read the startup info. | |
3359 |
|
3395 | |||
3360 | 2002-01-23 Fernando Perez <fperez@colorado.edu> |
|
3396 | 2002-01-23 Fernando Perez <fperez@colorado.edu> | |
3361 |
|
3397 | |||
3362 | * IPython/iplib.py (CachedOutput.update): Changed output memory |
|
3398 | * IPython/iplib.py (CachedOutput.update): Changed output memory | |
3363 | variable names from _o,_oo,_ooo,_o<n> to simply _,__,___,_<n>. For |
|
3399 | variable names from _o,_oo,_ooo,_o<n> to simply _,__,___,_<n>. For | |
3364 | input history we still use _i. Did this b/c these variable are |
|
3400 | input history we still use _i. Did this b/c these variable are | |
3365 | very commonly used in interactive work, so the less we need to |
|
3401 | very commonly used in interactive work, so the less we need to | |
3366 | type the better off we are. |
|
3402 | type the better off we are. | |
3367 | (Magic.magic_prun): updated @prun to better handle the namespaces |
|
3403 | (Magic.magic_prun): updated @prun to better handle the namespaces | |
3368 | the file will run in, including a fix for __name__ not being set |
|
3404 | the file will run in, including a fix for __name__ not being set | |
3369 | before. |
|
3405 | before. | |
3370 |
|
3406 | |||
3371 | 2002-01-20 Fernando Perez <fperez@colorado.edu> |
|
3407 | 2002-01-20 Fernando Perez <fperez@colorado.edu> | |
3372 |
|
3408 | |||
3373 | * IPython/ultraTB.py (VerboseTB.linereader): Fixed printing of |
|
3409 | * IPython/ultraTB.py (VerboseTB.linereader): Fixed printing of | |
3374 | extra garbage for Python 2.2. Need to look more carefully into |
|
3410 | extra garbage for Python 2.2. Need to look more carefully into | |
3375 | this later. |
|
3411 | this later. | |
3376 |
|
3412 | |||
3377 | 2002-01-19 Fernando Perez <fperez@colorado.edu> |
|
3413 | 2002-01-19 Fernando Perez <fperez@colorado.edu> | |
3378 |
|
3414 | |||
3379 | * IPython/iplib.py (InteractiveShell.showtraceback): fixed to |
|
3415 | * IPython/iplib.py (InteractiveShell.showtraceback): fixed to | |
3380 | display SyntaxError exceptions properly formatted when they occur |
|
3416 | display SyntaxError exceptions properly formatted when they occur | |
3381 | (they can be triggered by imported code). |
|
3417 | (they can be triggered by imported code). | |
3382 |
|
3418 | |||
3383 | 2002-01-18 Fernando Perez <fperez@colorado.edu> |
|
3419 | 2002-01-18 Fernando Perez <fperez@colorado.edu> | |
3384 |
|
3420 | |||
3385 | * IPython/iplib.py (InteractiveShell.safe_execfile): now |
|
3421 | * IPython/iplib.py (InteractiveShell.safe_execfile): now | |
3386 | SyntaxError exceptions are reported nicely formatted, instead of |
|
3422 | SyntaxError exceptions are reported nicely formatted, instead of | |
3387 | spitting out only offset information as before. |
|
3423 | spitting out only offset information as before. | |
3388 | (Magic.magic_prun): Added the @prun function for executing |
|
3424 | (Magic.magic_prun): Added the @prun function for executing | |
3389 | programs with command line args inside IPython. |
|
3425 | programs with command line args inside IPython. | |
3390 |
|
3426 | |||
3391 | 2002-01-16 Fernando Perez <fperez@colorado.edu> |
|
3427 | 2002-01-16 Fernando Perez <fperez@colorado.edu> | |
3392 |
|
3428 | |||
3393 | * IPython/iplib.py (Magic.magic_hist): Changed @hist and @dhist |
|
3429 | * IPython/iplib.py (Magic.magic_hist): Changed @hist and @dhist | |
3394 | to *not* include the last item given in a range. This brings their |
|
3430 | to *not* include the last item given in a range. This brings their | |
3395 | behavior in line with Python's slicing: |
|
3431 | behavior in line with Python's slicing: | |
3396 | a[n1:n2] -> a[n1]...a[n2-1] |
|
3432 | a[n1:n2] -> a[n1]...a[n2-1] | |
3397 | It may be a bit less convenient, but I prefer to stick to Python's |
|
3433 | It may be a bit less convenient, but I prefer to stick to Python's | |
3398 | conventions *everywhere*, so users never have to wonder. |
|
3434 | conventions *everywhere*, so users never have to wonder. | |
3399 | (Magic.magic_macro): Added @macro function to ease the creation of |
|
3435 | (Magic.magic_macro): Added @macro function to ease the creation of | |
3400 | macros. |
|
3436 | macros. | |
3401 |
|
3437 | |||
3402 | 2002-01-05 Fernando Perez <fperez@colorado.edu> |
|
3438 | 2002-01-05 Fernando Perez <fperez@colorado.edu> | |
3403 |
|
3439 | |||
3404 | * Released 0.2.4. |
|
3440 | * Released 0.2.4. | |
3405 |
|
3441 | |||
3406 | * IPython/iplib.py (Magic.magic_pdef): |
|
3442 | * IPython/iplib.py (Magic.magic_pdef): | |
3407 | (InteractiveShell.safe_execfile): report magic lines and error |
|
3443 | (InteractiveShell.safe_execfile): report magic lines and error | |
3408 | lines without line numbers so one can easily copy/paste them for |
|
3444 | lines without line numbers so one can easily copy/paste them for | |
3409 | re-execution. |
|
3445 | re-execution. | |
3410 |
|
3446 | |||
3411 | * Updated manual with recent changes. |
|
3447 | * Updated manual with recent changes. | |
3412 |
|
3448 | |||
3413 | * IPython/iplib.py (Magic.magic_oinfo): added constructor |
|
3449 | * IPython/iplib.py (Magic.magic_oinfo): added constructor | |
3414 | docstring printing when class? is called. Very handy for knowing |
|
3450 | docstring printing when class? is called. Very handy for knowing | |
3415 | how to create class instances (as long as __init__ is well |
|
3451 | how to create class instances (as long as __init__ is well | |
3416 | documented, of course :) |
|
3452 | documented, of course :) | |
3417 | (Magic.magic_doc): print both class and constructor docstrings. |
|
3453 | (Magic.magic_doc): print both class and constructor docstrings. | |
3418 | (Magic.magic_pdef): give constructor info if passed a class and |
|
3454 | (Magic.magic_pdef): give constructor info if passed a class and | |
3419 | __call__ info for callable object instances. |
|
3455 | __call__ info for callable object instances. | |
3420 |
|
3456 | |||
3421 | 2002-01-04 Fernando Perez <fperez@colorado.edu> |
|
3457 | 2002-01-04 Fernando Perez <fperez@colorado.edu> | |
3422 |
|
3458 | |||
3423 | * Made deep_reload() off by default. It doesn't always work |
|
3459 | * Made deep_reload() off by default. It doesn't always work | |
3424 | exactly as intended, so it's probably safer to have it off. It's |
|
3460 | exactly as intended, so it's probably safer to have it off. It's | |
3425 | still available as dreload() anyway, so nothing is lost. |
|
3461 | still available as dreload() anyway, so nothing is lost. | |
3426 |
|
3462 | |||
3427 | 2002-01-02 Fernando Perez <fperez@colorado.edu> |
|
3463 | 2002-01-02 Fernando Perez <fperez@colorado.edu> | |
3428 |
|
3464 | |||
3429 | * Released 0.2.3 (contacted R.Singh at CU about biopython course, |
|
3465 | * Released 0.2.3 (contacted R.Singh at CU about biopython course, | |
3430 | so I wanted an updated release). |
|
3466 | so I wanted an updated release). | |
3431 |
|
3467 | |||
3432 | 2001-12-27 Fernando Perez <fperez@colorado.edu> |
|
3468 | 2001-12-27 Fernando Perez <fperez@colorado.edu> | |
3433 |
|
3469 | |||
3434 | * IPython/iplib.py (InteractiveShell.interact): Added the original |
|
3470 | * IPython/iplib.py (InteractiveShell.interact): Added the original | |
3435 | code from 'code.py' for this module in order to change the |
|
3471 | code from 'code.py' for this module in order to change the | |
3436 | handling of a KeyboardInterrupt. This was necessary b/c otherwise |
|
3472 | handling of a KeyboardInterrupt. This was necessary b/c otherwise | |
3437 | the history cache would break when the user hit Ctrl-C, and |
|
3473 | the history cache would break when the user hit Ctrl-C, and | |
3438 | interact() offers no way to add any hooks to it. |
|
3474 | interact() offers no way to add any hooks to it. | |
3439 |
|
3475 | |||
3440 | 2001-12-23 Fernando Perez <fperez@colorado.edu> |
|
3476 | 2001-12-23 Fernando Perez <fperez@colorado.edu> | |
3441 |
|
3477 | |||
3442 | * setup.py: added check for 'MANIFEST' before trying to remove |
|
3478 | * setup.py: added check for 'MANIFEST' before trying to remove | |
3443 | it. Thanks to Sean Reifschneider. |
|
3479 | it. Thanks to Sean Reifschneider. | |
3444 |
|
3480 | |||
3445 | 2001-12-22 Fernando Perez <fperez@colorado.edu> |
|
3481 | 2001-12-22 Fernando Perez <fperez@colorado.edu> | |
3446 |
|
3482 | |||
3447 | * Released 0.2.2. |
|
3483 | * Released 0.2.2. | |
3448 |
|
3484 | |||
3449 | * Finished (reasonably) writing the manual. Later will add the |
|
3485 | * Finished (reasonably) writing the manual. Later will add the | |
3450 | python-standard navigation stylesheets, but for the time being |
|
3486 | python-standard navigation stylesheets, but for the time being | |
3451 | it's fairly complete. Distribution will include html and pdf |
|
3487 | it's fairly complete. Distribution will include html and pdf | |
3452 | versions. |
|
3488 | versions. | |
3453 |
|
3489 | |||
3454 | * Bugfix: '.' wasn't being added to sys.path. Thanks to Prabhu |
|
3490 | * Bugfix: '.' wasn't being added to sys.path. Thanks to Prabhu | |
3455 | (MayaVi author). |
|
3491 | (MayaVi author). | |
3456 |
|
3492 | |||
3457 | 2001-12-21 Fernando Perez <fperez@colorado.edu> |
|
3493 | 2001-12-21 Fernando Perez <fperez@colorado.edu> | |
3458 |
|
3494 | |||
3459 | * Released 0.2.1. Barring any nasty bugs, this is it as far as a |
|
3495 | * Released 0.2.1. Barring any nasty bugs, this is it as far as a | |
3460 | good public release, I think (with the manual and the distutils |
|
3496 | good public release, I think (with the manual and the distutils | |
3461 | installer). The manual can use some work, but that can go |
|
3497 | installer). The manual can use some work, but that can go | |
3462 | slowly. Otherwise I think it's quite nice for end users. Next |
|
3498 | slowly. Otherwise I think it's quite nice for end users. Next | |
3463 | summer, rewrite the guts of it... |
|
3499 | summer, rewrite the guts of it... | |
3464 |
|
3500 | |||
3465 | * Changed format of ipythonrc files to use whitespace as the |
|
3501 | * Changed format of ipythonrc files to use whitespace as the | |
3466 | separator instead of an explicit '='. Cleaner. |
|
3502 | separator instead of an explicit '='. Cleaner. | |
3467 |
|
3503 | |||
3468 | 2001-12-20 Fernando Perez <fperez@colorado.edu> |
|
3504 | 2001-12-20 Fernando Perez <fperez@colorado.edu> | |
3469 |
|
3505 | |||
3470 | * Started a manual in LyX. For now it's just a quick merge of the |
|
3506 | * Started a manual in LyX. For now it's just a quick merge of the | |
3471 | various internal docstrings and READMEs. Later it may grow into a |
|
3507 | various internal docstrings and READMEs. Later it may grow into a | |
3472 | nice, full-blown manual. |
|
3508 | nice, full-blown manual. | |
3473 |
|
3509 | |||
3474 | * Set up a distutils based installer. Installation should now be |
|
3510 | * Set up a distutils based installer. Installation should now be | |
3475 | trivially simple for end-users. |
|
3511 | trivially simple for end-users. | |
3476 |
|
3512 | |||
3477 | 2001-12-11 Fernando Perez <fperez@colorado.edu> |
|
3513 | 2001-12-11 Fernando Perez <fperez@colorado.edu> | |
3478 |
|
3514 | |||
3479 | * Released 0.2.0. First public release, announced it at |
|
3515 | * Released 0.2.0. First public release, announced it at | |
3480 | comp.lang.python. From now on, just bugfixes... |
|
3516 | comp.lang.python. From now on, just bugfixes... | |
3481 |
|
3517 | |||
3482 | * Went through all the files, set copyright/license notices and |
|
3518 | * Went through all the files, set copyright/license notices and | |
3483 | cleaned up things. Ready for release. |
|
3519 | cleaned up things. Ready for release. | |
3484 |
|
3520 | |||
3485 | 2001-12-10 Fernando Perez <fperez@colorado.edu> |
|
3521 | 2001-12-10 Fernando Perez <fperez@colorado.edu> | |
3486 |
|
3522 | |||
3487 | * Changed the first-time installer not to use tarfiles. It's more |
|
3523 | * Changed the first-time installer not to use tarfiles. It's more | |
3488 | robust now and less unix-dependent. Also makes it easier for |
|
3524 | robust now and less unix-dependent. Also makes it easier for | |
3489 | people to later upgrade versions. |
|
3525 | people to later upgrade versions. | |
3490 |
|
3526 | |||
3491 | * Changed @exit to @abort to reflect the fact that it's pretty |
|
3527 | * Changed @exit to @abort to reflect the fact that it's pretty | |
3492 | brutal (a sys.exit()). The difference between @abort and Ctrl-D |
|
3528 | brutal (a sys.exit()). The difference between @abort and Ctrl-D | |
3493 | becomes significant only when IPyhton is embedded: in that case, |
|
3529 | becomes significant only when IPyhton is embedded: in that case, | |
3494 | C-D closes IPython only, but @abort kills the enclosing program |
|
3530 | C-D closes IPython only, but @abort kills the enclosing program | |
3495 | too (unless it had called IPython inside a try catching |
|
3531 | too (unless it had called IPython inside a try catching | |
3496 | SystemExit). |
|
3532 | SystemExit). | |
3497 |
|
3533 | |||
3498 | * Created Shell module which exposes the actuall IPython Shell |
|
3534 | * Created Shell module which exposes the actuall IPython Shell | |
3499 | classes, currently the normal and the embeddable one. This at |
|
3535 | classes, currently the normal and the embeddable one. This at | |
3500 | least offers a stable interface we won't need to change when |
|
3536 | least offers a stable interface we won't need to change when | |
3501 | (later) the internals are rewritten. That rewrite will be confined |
|
3537 | (later) the internals are rewritten. That rewrite will be confined | |
3502 | to iplib and ipmaker, but the Shell interface should remain as is. |
|
3538 | to iplib and ipmaker, but the Shell interface should remain as is. | |
3503 |
|
3539 | |||
3504 | * Added embed module which offers an embeddable IPShell object, |
|
3540 | * Added embed module which offers an embeddable IPShell object, | |
3505 | useful to fire up IPython *inside* a running program. Great for |
|
3541 | useful to fire up IPython *inside* a running program. Great for | |
3506 | debugging or dynamical data analysis. |
|
3542 | debugging or dynamical data analysis. | |
3507 |
|
3543 | |||
3508 | 2001-12-08 Fernando Perez <fperez@colorado.edu> |
|
3544 | 2001-12-08 Fernando Perez <fperez@colorado.edu> | |
3509 |
|
3545 | |||
3510 | * Fixed small bug preventing seeing info from methods of defined |
|
3546 | * Fixed small bug preventing seeing info from methods of defined | |
3511 | objects (incorrect namespace in _ofind()). |
|
3547 | objects (incorrect namespace in _ofind()). | |
3512 |
|
3548 | |||
3513 | * Documentation cleanup. Moved the main usage docstrings to a |
|
3549 | * Documentation cleanup. Moved the main usage docstrings to a | |
3514 | separate file, usage.py (cleaner to maintain, and hopefully in the |
|
3550 | separate file, usage.py (cleaner to maintain, and hopefully in the | |
3515 | future some perlpod-like way of producing interactive, man and |
|
3551 | future some perlpod-like way of producing interactive, man and | |
3516 | html docs out of it will be found). |
|
3552 | html docs out of it will be found). | |
3517 |
|
3553 | |||
3518 | * Added @profile to see your profile at any time. |
|
3554 | * Added @profile to see your profile at any time. | |
3519 |
|
3555 | |||
3520 | * Added @p as an alias for 'print'. It's especially convenient if |
|
3556 | * Added @p as an alias for 'print'. It's especially convenient if | |
3521 | using automagic ('p x' prints x). |
|
3557 | using automagic ('p x' prints x). | |
3522 |
|
3558 | |||
3523 | * Small cleanups and fixes after a pychecker run. |
|
3559 | * Small cleanups and fixes after a pychecker run. | |
3524 |
|
3560 | |||
3525 | * Changed the @cd command to handle @cd - and @cd -<n> for |
|
3561 | * Changed the @cd command to handle @cd - and @cd -<n> for | |
3526 | visiting any directory in _dh. |
|
3562 | visiting any directory in _dh. | |
3527 |
|
3563 | |||
3528 | * Introduced _dh, a history of visited directories. @dhist prints |
|
3564 | * Introduced _dh, a history of visited directories. @dhist prints | |
3529 | it out with numbers. |
|
3565 | it out with numbers. | |
3530 |
|
3566 | |||
3531 | 2001-12-07 Fernando Perez <fperez@colorado.edu> |
|
3567 | 2001-12-07 Fernando Perez <fperez@colorado.edu> | |
3532 |
|
3568 | |||
3533 | * Released 0.1.22 |
|
3569 | * Released 0.1.22 | |
3534 |
|
3570 | |||
3535 | * Made initialization a bit more robust against invalid color |
|
3571 | * Made initialization a bit more robust against invalid color | |
3536 | options in user input (exit, not traceback-crash). |
|
3572 | options in user input (exit, not traceback-crash). | |
3537 |
|
3573 | |||
3538 | * Changed the bug crash reporter to write the report only in the |
|
3574 | * Changed the bug crash reporter to write the report only in the | |
3539 | user's .ipython directory. That way IPython won't litter people's |
|
3575 | user's .ipython directory. That way IPython won't litter people's | |
3540 | hard disks with crash files all over the place. Also print on |
|
3576 | hard disks with crash files all over the place. Also print on | |
3541 | screen the necessary mail command. |
|
3577 | screen the necessary mail command. | |
3542 |
|
3578 | |||
3543 | * With the new ultraTB, implemented LightBG color scheme for light |
|
3579 | * With the new ultraTB, implemented LightBG color scheme for light | |
3544 | background terminals. A lot of people like white backgrounds, so I |
|
3580 | background terminals. A lot of people like white backgrounds, so I | |
3545 | guess we should at least give them something readable. |
|
3581 | guess we should at least give them something readable. | |
3546 |
|
3582 | |||
3547 | 2001-12-06 Fernando Perez <fperez@colorado.edu> |
|
3583 | 2001-12-06 Fernando Perez <fperez@colorado.edu> | |
3548 |
|
3584 | |||
3549 | * Modified the structure of ultraTB. Now there's a proper class |
|
3585 | * Modified the structure of ultraTB. Now there's a proper class | |
3550 | for tables of color schemes which allow adding schemes easily and |
|
3586 | for tables of color schemes which allow adding schemes easily and | |
3551 | switching the active scheme without creating a new instance every |
|
3587 | switching the active scheme without creating a new instance every | |
3552 | time (which was ridiculous). The syntax for creating new schemes |
|
3588 | time (which was ridiculous). The syntax for creating new schemes | |
3553 | is also cleaner. I think ultraTB is finally done, with a clean |
|
3589 | is also cleaner. I think ultraTB is finally done, with a clean | |
3554 | class structure. Names are also much cleaner (now there's proper |
|
3590 | class structure. Names are also much cleaner (now there's proper | |
3555 | color tables, no need for every variable to also have 'color' in |
|
3591 | color tables, no need for every variable to also have 'color' in | |
3556 | its name). |
|
3592 | its name). | |
3557 |
|
3593 | |||
3558 | * Broke down genutils into separate files. Now genutils only |
|
3594 | * Broke down genutils into separate files. Now genutils only | |
3559 | contains utility functions, and classes have been moved to their |
|
3595 | contains utility functions, and classes have been moved to their | |
3560 | own files (they had enough independent functionality to warrant |
|
3596 | own files (they had enough independent functionality to warrant | |
3561 | it): ConfigLoader, OutputTrap, Struct. |
|
3597 | it): ConfigLoader, OutputTrap, Struct. | |
3562 |
|
3598 | |||
3563 | 2001-12-05 Fernando Perez <fperez@colorado.edu> |
|
3599 | 2001-12-05 Fernando Perez <fperez@colorado.edu> | |
3564 |
|
3600 | |||
3565 | * IPython turns 21! Released version 0.1.21, as a candidate for |
|
3601 | * IPython turns 21! Released version 0.1.21, as a candidate for | |
3566 | public consumption. If all goes well, release in a few days. |
|
3602 | public consumption. If all goes well, release in a few days. | |
3567 |
|
3603 | |||
3568 | * Fixed path bug (files in Extensions/ directory wouldn't be found |
|
3604 | * Fixed path bug (files in Extensions/ directory wouldn't be found | |
3569 | unless IPython/ was explicitly in sys.path). |
|
3605 | unless IPython/ was explicitly in sys.path). | |
3570 |
|
3606 | |||
3571 | * Extended the FlexCompleter class as MagicCompleter to allow |
|
3607 | * Extended the FlexCompleter class as MagicCompleter to allow | |
3572 | completion of @-starting lines. |
|
3608 | completion of @-starting lines. | |
3573 |
|
3609 | |||
3574 | * Created __release__.py file as a central repository for release |
|
3610 | * Created __release__.py file as a central repository for release | |
3575 | info that other files can read from. |
|
3611 | info that other files can read from. | |
3576 |
|
3612 | |||
3577 | * Fixed small bug in logging: when logging was turned on in |
|
3613 | * Fixed small bug in logging: when logging was turned on in | |
3578 | mid-session, old lines with special meanings (!@?) were being |
|
3614 | mid-session, old lines with special meanings (!@?) were being | |
3579 | logged without the prepended comment, which is necessary since |
|
3615 | logged without the prepended comment, which is necessary since | |
3580 | they are not truly valid python syntax. This should make session |
|
3616 | they are not truly valid python syntax. This should make session | |
3581 | restores produce less errors. |
|
3617 | restores produce less errors. | |
3582 |
|
3618 | |||
3583 | * The namespace cleanup forced me to make a FlexCompleter class |
|
3619 | * The namespace cleanup forced me to make a FlexCompleter class | |
3584 | which is nothing but a ripoff of rlcompleter, but with selectable |
|
3620 | which is nothing but a ripoff of rlcompleter, but with selectable | |
3585 | namespace (rlcompleter only works in __main__.__dict__). I'll try |
|
3621 | namespace (rlcompleter only works in __main__.__dict__). I'll try | |
3586 | to submit a note to the authors to see if this change can be |
|
3622 | to submit a note to the authors to see if this change can be | |
3587 | incorporated in future rlcompleter releases (Dec.6: done) |
|
3623 | incorporated in future rlcompleter releases (Dec.6: done) | |
3588 |
|
3624 | |||
3589 | * More fixes to namespace handling. It was a mess! Now all |
|
3625 | * More fixes to namespace handling. It was a mess! Now all | |
3590 | explicit references to __main__.__dict__ are gone (except when |
|
3626 | explicit references to __main__.__dict__ are gone (except when | |
3591 | really needed) and everything is handled through the namespace |
|
3627 | really needed) and everything is handled through the namespace | |
3592 | dicts in the IPython instance. We seem to be getting somewhere |
|
3628 | dicts in the IPython instance. We seem to be getting somewhere | |
3593 | with this, finally... |
|
3629 | with this, finally... | |
3594 |
|
3630 | |||
3595 | * Small documentation updates. |
|
3631 | * Small documentation updates. | |
3596 |
|
3632 | |||
3597 | * Created the Extensions directory under IPython (with an |
|
3633 | * Created the Extensions directory under IPython (with an | |
3598 | __init__.py). Put the PhysicalQ stuff there. This directory should |
|
3634 | __init__.py). Put the PhysicalQ stuff there. This directory should | |
3599 | be used for all special-purpose extensions. |
|
3635 | be used for all special-purpose extensions. | |
3600 |
|
3636 | |||
3601 | * File renaming: |
|
3637 | * File renaming: | |
3602 | ipythonlib --> ipmaker |
|
3638 | ipythonlib --> ipmaker | |
3603 | ipplib --> iplib |
|
3639 | ipplib --> iplib | |
3604 | This makes a bit more sense in terms of what these files actually do. |
|
3640 | This makes a bit more sense in terms of what these files actually do. | |
3605 |
|
3641 | |||
3606 | * Moved all the classes and functions in ipythonlib to ipplib, so |
|
3642 | * Moved all the classes and functions in ipythonlib to ipplib, so | |
3607 | now ipythonlib only has make_IPython(). This will ease up its |
|
3643 | now ipythonlib only has make_IPython(). This will ease up its | |
3608 | splitting in smaller functional chunks later. |
|
3644 | splitting in smaller functional chunks later. | |
3609 |
|
3645 | |||
3610 | * Cleaned up (done, I think) output of @whos. Better column |
|
3646 | * Cleaned up (done, I think) output of @whos. Better column | |
3611 | formatting, and now shows str(var) for as much as it can, which is |
|
3647 | formatting, and now shows str(var) for as much as it can, which is | |
3612 | typically what one gets with a 'print var'. |
|
3648 | typically what one gets with a 'print var'. | |
3613 |
|
3649 | |||
3614 | 2001-12-04 Fernando Perez <fperez@colorado.edu> |
|
3650 | 2001-12-04 Fernando Perez <fperez@colorado.edu> | |
3615 |
|
3651 | |||
3616 | * Fixed namespace problems. Now builtin/IPyhton/user names get |
|
3652 | * Fixed namespace problems. Now builtin/IPyhton/user names get | |
3617 | properly reported in their namespace. Internal namespace handling |
|
3653 | properly reported in their namespace. Internal namespace handling | |
3618 | is finally getting decent (not perfect yet, but much better than |
|
3654 | is finally getting decent (not perfect yet, but much better than | |
3619 | the ad-hoc mess we had). |
|
3655 | the ad-hoc mess we had). | |
3620 |
|
3656 | |||
3621 | * Removed -exit option. If people just want to run a python |
|
3657 | * Removed -exit option. If people just want to run a python | |
3622 | script, that's what the normal interpreter is for. Less |
|
3658 | script, that's what the normal interpreter is for. Less | |
3623 | unnecessary options, less chances for bugs. |
|
3659 | unnecessary options, less chances for bugs. | |
3624 |
|
3660 | |||
3625 | * Added a crash handler which generates a complete post-mortem if |
|
3661 | * Added a crash handler which generates a complete post-mortem if | |
3626 | IPython crashes. This will help a lot in tracking bugs down the |
|
3662 | IPython crashes. This will help a lot in tracking bugs down the | |
3627 | road. |
|
3663 | road. | |
3628 |
|
3664 | |||
3629 | * Fixed nasty bug in auto-evaluation part of prefilter(). Names |
|
3665 | * Fixed nasty bug in auto-evaluation part of prefilter(). Names | |
3630 | which were boud to functions being reassigned would bypass the |
|
3666 | which were boud to functions being reassigned would bypass the | |
3631 | logger, breaking the sync of _il with the prompt counter. This |
|
3667 | logger, breaking the sync of _il with the prompt counter. This | |
3632 | would then crash IPython later when a new line was logged. |
|
3668 | would then crash IPython later when a new line was logged. | |
3633 |
|
3669 | |||
3634 | 2001-12-02 Fernando Perez <fperez@colorado.edu> |
|
3670 | 2001-12-02 Fernando Perez <fperez@colorado.edu> | |
3635 |
|
3671 | |||
3636 | * Made IPython a package. This means people don't have to clutter |
|
3672 | * Made IPython a package. This means people don't have to clutter | |
3637 | their sys.path with yet another directory. Changed the INSTALL |
|
3673 | their sys.path with yet another directory. Changed the INSTALL | |
3638 | file accordingly. |
|
3674 | file accordingly. | |
3639 |
|
3675 | |||
3640 | * Cleaned up the output of @who_ls, @who and @whos. @who_ls now |
|
3676 | * Cleaned up the output of @who_ls, @who and @whos. @who_ls now | |
3641 | sorts its output (so @who shows it sorted) and @whos formats the |
|
3677 | sorts its output (so @who shows it sorted) and @whos formats the | |
3642 | table according to the width of the first column. Nicer, easier to |
|
3678 | table according to the width of the first column. Nicer, easier to | |
3643 | read. Todo: write a generic table_format() which takes a list of |
|
3679 | read. Todo: write a generic table_format() which takes a list of | |
3644 | lists and prints it nicely formatted, with optional row/column |
|
3680 | lists and prints it nicely formatted, with optional row/column | |
3645 | separators and proper padding and justification. |
|
3681 | separators and proper padding and justification. | |
3646 |
|
3682 | |||
3647 | * Released 0.1.20 |
|
3683 | * Released 0.1.20 | |
3648 |
|
3684 | |||
3649 | * Fixed bug in @log which would reverse the inputcache list (a |
|
3685 | * Fixed bug in @log which would reverse the inputcache list (a | |
3650 | copy operation was missing). |
|
3686 | copy operation was missing). | |
3651 |
|
3687 | |||
3652 | * Code cleanup. @config was changed to use page(). Better, since |
|
3688 | * Code cleanup. @config was changed to use page(). Better, since | |
3653 | its output is always quite long. |
|
3689 | its output is always quite long. | |
3654 |
|
3690 | |||
3655 | * Itpl is back as a dependency. I was having too many problems |
|
3691 | * Itpl is back as a dependency. I was having too many problems | |
3656 | getting the parametric aliases to work reliably, and it's just |
|
3692 | getting the parametric aliases to work reliably, and it's just | |
3657 | easier to code weird string operations with it than playing %()s |
|
3693 | easier to code weird string operations with it than playing %()s | |
3658 | games. It's only ~6k, so I don't think it's too big a deal. |
|
3694 | games. It's only ~6k, so I don't think it's too big a deal. | |
3659 |
|
3695 | |||
3660 | * Found (and fixed) a very nasty bug with history. !lines weren't |
|
3696 | * Found (and fixed) a very nasty bug with history. !lines weren't | |
3661 | getting cached, and the out of sync caches would crash |
|
3697 | getting cached, and the out of sync caches would crash | |
3662 | IPython. Fixed it by reorganizing the prefilter/handlers/logger |
|
3698 | IPython. Fixed it by reorganizing the prefilter/handlers/logger | |
3663 | division of labor a bit better. Bug fixed, cleaner structure. |
|
3699 | division of labor a bit better. Bug fixed, cleaner structure. | |
3664 |
|
3700 | |||
3665 | 2001-12-01 Fernando Perez <fperez@colorado.edu> |
|
3701 | 2001-12-01 Fernando Perez <fperez@colorado.edu> | |
3666 |
|
3702 | |||
3667 | * Released 0.1.19 |
|
3703 | * Released 0.1.19 | |
3668 |
|
3704 | |||
3669 | * Added option -n to @hist to prevent line number printing. Much |
|
3705 | * Added option -n to @hist to prevent line number printing. Much | |
3670 | easier to copy/paste code this way. |
|
3706 | easier to copy/paste code this way. | |
3671 |
|
3707 | |||
3672 | * Created global _il to hold the input list. Allows easy |
|
3708 | * Created global _il to hold the input list. Allows easy | |
3673 | re-execution of blocks of code by slicing it (inspired by Janko's |
|
3709 | re-execution of blocks of code by slicing it (inspired by Janko's | |
3674 | comment on 'macros'). |
|
3710 | comment on 'macros'). | |
3675 |
|
3711 | |||
3676 | * Small fixes and doc updates. |
|
3712 | * Small fixes and doc updates. | |
3677 |
|
3713 | |||
3678 | * Rewrote @history function (was @h). Renamed it to @hist, @h is |
|
3714 | * Rewrote @history function (was @h). Renamed it to @hist, @h is | |
3679 | much too fragile with automagic. Handles properly multi-line |
|
3715 | much too fragile with automagic. Handles properly multi-line | |
3680 | statements and takes parameters. |
|
3716 | statements and takes parameters. | |
3681 |
|
3717 | |||
3682 | 2001-11-30 Fernando Perez <fperez@colorado.edu> |
|
3718 | 2001-11-30 Fernando Perez <fperez@colorado.edu> | |
3683 |
|
3719 | |||
3684 | * Version 0.1.18 released. |
|
3720 | * Version 0.1.18 released. | |
3685 |
|
3721 | |||
3686 | * Fixed nasty namespace bug in initial module imports. |
|
3722 | * Fixed nasty namespace bug in initial module imports. | |
3687 |
|
3723 | |||
3688 | * Added copyright/license notes to all code files (except |
|
3724 | * Added copyright/license notes to all code files (except | |
3689 | DPyGetOpt). For the time being, LGPL. That could change. |
|
3725 | DPyGetOpt). For the time being, LGPL. That could change. | |
3690 |
|
3726 | |||
3691 | * Rewrote a much nicer README, updated INSTALL, cleaned up |
|
3727 | * Rewrote a much nicer README, updated INSTALL, cleaned up | |
3692 | ipythonrc-* samples. |
|
3728 | ipythonrc-* samples. | |
3693 |
|
3729 | |||
3694 | * Overall code/documentation cleanup. Basically ready for |
|
3730 | * Overall code/documentation cleanup. Basically ready for | |
3695 | release. Only remaining thing: licence decision (LGPL?). |
|
3731 | release. Only remaining thing: licence decision (LGPL?). | |
3696 |
|
3732 | |||
3697 | * Converted load_config to a class, ConfigLoader. Now recursion |
|
3733 | * Converted load_config to a class, ConfigLoader. Now recursion | |
3698 | control is better organized. Doesn't include the same file twice. |
|
3734 | control is better organized. Doesn't include the same file twice. | |
3699 |
|
3735 | |||
3700 | 2001-11-29 Fernando Perez <fperez@colorado.edu> |
|
3736 | 2001-11-29 Fernando Perez <fperez@colorado.edu> | |
3701 |
|
3737 | |||
3702 | * Got input history working. Changed output history variables from |
|
3738 | * Got input history working. Changed output history variables from | |
3703 | _p to _o so that _i is for input and _o for output. Just cleaner |
|
3739 | _p to _o so that _i is for input and _o for output. Just cleaner | |
3704 | convention. |
|
3740 | convention. | |
3705 |
|
3741 | |||
3706 | * Implemented parametric aliases. This pretty much allows the |
|
3742 | * Implemented parametric aliases. This pretty much allows the | |
3707 | alias system to offer full-blown shell convenience, I think. |
|
3743 | alias system to offer full-blown shell convenience, I think. | |
3708 |
|
3744 | |||
3709 | * Version 0.1.17 released, 0.1.18 opened. |
|
3745 | * Version 0.1.17 released, 0.1.18 opened. | |
3710 |
|
3746 | |||
3711 | * dot_ipython/ipythonrc (alias): added documentation. |
|
3747 | * dot_ipython/ipythonrc (alias): added documentation. | |
3712 | (xcolor): Fixed small bug (xcolors -> xcolor) |
|
3748 | (xcolor): Fixed small bug (xcolors -> xcolor) | |
3713 |
|
3749 | |||
3714 | * Changed the alias system. Now alias is a magic command to define |
|
3750 | * Changed the alias system. Now alias is a magic command to define | |
3715 | aliases just like the shell. Rationale: the builtin magics should |
|
3751 | aliases just like the shell. Rationale: the builtin magics should | |
3716 | be there for things deeply connected to IPython's |
|
3752 | be there for things deeply connected to IPython's | |
3717 | architecture. And this is a much lighter system for what I think |
|
3753 | architecture. And this is a much lighter system for what I think | |
3718 | is the really important feature: allowing users to define quickly |
|
3754 | is the really important feature: allowing users to define quickly | |
3719 | magics that will do shell things for them, so they can customize |
|
3755 | magics that will do shell things for them, so they can customize | |
3720 | IPython easily to match their work habits. If someone is really |
|
3756 | IPython easily to match their work habits. If someone is really | |
3721 | desperate to have another name for a builtin alias, they can |
|
3757 | desperate to have another name for a builtin alias, they can | |
3722 | always use __IP.magic_newname = __IP.magic_oldname. Hackish but |
|
3758 | always use __IP.magic_newname = __IP.magic_oldname. Hackish but | |
3723 | works. |
|
3759 | works. | |
3724 |
|
3760 | |||
3725 | 2001-11-28 Fernando Perez <fperez@colorado.edu> |
|
3761 | 2001-11-28 Fernando Perez <fperez@colorado.edu> | |
3726 |
|
3762 | |||
3727 | * Changed @file so that it opens the source file at the proper |
|
3763 | * Changed @file so that it opens the source file at the proper | |
3728 | line. Since it uses less, if your EDITOR environment is |
|
3764 | line. Since it uses less, if your EDITOR environment is | |
3729 | configured, typing v will immediately open your editor of choice |
|
3765 | configured, typing v will immediately open your editor of choice | |
3730 | right at the line where the object is defined. Not as quick as |
|
3766 | right at the line where the object is defined. Not as quick as | |
3731 | having a direct @edit command, but for all intents and purposes it |
|
3767 | having a direct @edit command, but for all intents and purposes it | |
3732 | works. And I don't have to worry about writing @edit to deal with |
|
3768 | works. And I don't have to worry about writing @edit to deal with | |
3733 | all the editors, less does that. |
|
3769 | all the editors, less does that. | |
3734 |
|
3770 | |||
3735 | * Version 0.1.16 released, 0.1.17 opened. |
|
3771 | * Version 0.1.16 released, 0.1.17 opened. | |
3736 |
|
3772 | |||
3737 | * Fixed some nasty bugs in the page/page_dumb combo that could |
|
3773 | * Fixed some nasty bugs in the page/page_dumb combo that could | |
3738 | crash IPython. |
|
3774 | crash IPython. | |
3739 |
|
3775 | |||
3740 | 2001-11-27 Fernando Perez <fperez@colorado.edu> |
|
3776 | 2001-11-27 Fernando Perez <fperez@colorado.edu> | |
3741 |
|
3777 | |||
3742 | * Version 0.1.15 released, 0.1.16 opened. |
|
3778 | * Version 0.1.15 released, 0.1.16 opened. | |
3743 |
|
3779 | |||
3744 | * Finally got ? and ?? to work for undefined things: now it's |
|
3780 | * Finally got ? and ?? to work for undefined things: now it's | |
3745 | possible to type {}.get? and get information about the get method |
|
3781 | possible to type {}.get? and get information about the get method | |
3746 | of dicts, or os.path? even if only os is defined (so technically |
|
3782 | of dicts, or os.path? even if only os is defined (so technically | |
3747 | os.path isn't). Works at any level. For example, after import os, |
|
3783 | os.path isn't). Works at any level. For example, after import os, | |
3748 | os?, os.path?, os.path.abspath? all work. This is great, took some |
|
3784 | os?, os.path?, os.path.abspath? all work. This is great, took some | |
3749 | work in _ofind. |
|
3785 | work in _ofind. | |
3750 |
|
3786 | |||
3751 | * Fixed more bugs with logging. The sanest way to do it was to add |
|
3787 | * Fixed more bugs with logging. The sanest way to do it was to add | |
3752 | to @log a 'mode' parameter. Killed two in one shot (this mode |
|
3788 | to @log a 'mode' parameter. Killed two in one shot (this mode | |
3753 | option was a request of Janko's). I think it's finally clean |
|
3789 | option was a request of Janko's). I think it's finally clean | |
3754 | (famous last words). |
|
3790 | (famous last words). | |
3755 |
|
3791 | |||
3756 | * Added a page_dumb() pager which does a decent job of paging on |
|
3792 | * Added a page_dumb() pager which does a decent job of paging on | |
3757 | screen, if better things (like less) aren't available. One less |
|
3793 | screen, if better things (like less) aren't available. One less | |
3758 | unix dependency (someday maybe somebody will port this to |
|
3794 | unix dependency (someday maybe somebody will port this to | |
3759 | windows). |
|
3795 | windows). | |
3760 |
|
3796 | |||
3761 | * Fixed problem in magic_log: would lock of logging out if log |
|
3797 | * Fixed problem in magic_log: would lock of logging out if log | |
3762 | creation failed (because it would still think it had succeeded). |
|
3798 | creation failed (because it would still think it had succeeded). | |
3763 |
|
3799 | |||
3764 | * Improved the page() function using curses to auto-detect screen |
|
3800 | * Improved the page() function using curses to auto-detect screen | |
3765 | size. Now it can make a much better decision on whether to print |
|
3801 | size. Now it can make a much better decision on whether to print | |
3766 | or page a string. Option screen_length was modified: a value 0 |
|
3802 | or page a string. Option screen_length was modified: a value 0 | |
3767 | means auto-detect, and that's the default now. |
|
3803 | means auto-detect, and that's the default now. | |
3768 |
|
3804 | |||
3769 | * Version 0.1.14 released, 0.1.15 opened. I think this is ready to |
|
3805 | * Version 0.1.14 released, 0.1.15 opened. I think this is ready to | |
3770 | go out. I'll test it for a few days, then talk to Janko about |
|
3806 | go out. I'll test it for a few days, then talk to Janko about | |
3771 | licences and announce it. |
|
3807 | licences and announce it. | |
3772 |
|
3808 | |||
3773 | * Fixed the length of the auto-generated ---> prompt which appears |
|
3809 | * Fixed the length of the auto-generated ---> prompt which appears | |
3774 | for auto-parens and auto-quotes. Getting this right isn't trivial, |
|
3810 | for auto-parens and auto-quotes. Getting this right isn't trivial, | |
3775 | with all the color escapes, different prompt types and optional |
|
3811 | with all the color escapes, different prompt types and optional | |
3776 | separators. But it seems to be working in all the combinations. |
|
3812 | separators. But it seems to be working in all the combinations. | |
3777 |
|
3813 | |||
3778 | 2001-11-26 Fernando Perez <fperez@colorado.edu> |
|
3814 | 2001-11-26 Fernando Perez <fperez@colorado.edu> | |
3779 |
|
3815 | |||
3780 | * Wrote a regexp filter to get option types from the option names |
|
3816 | * Wrote a regexp filter to get option types from the option names | |
3781 | string. This eliminates the need to manually keep two duplicate |
|
3817 | string. This eliminates the need to manually keep two duplicate | |
3782 | lists. |
|
3818 | lists. | |
3783 |
|
3819 | |||
3784 | * Removed the unneeded check_option_names. Now options are handled |
|
3820 | * Removed the unneeded check_option_names. Now options are handled | |
3785 | in a much saner manner and it's easy to visually check that things |
|
3821 | in a much saner manner and it's easy to visually check that things | |
3786 | are ok. |
|
3822 | are ok. | |
3787 |
|
3823 | |||
3788 | * Updated version numbers on all files I modified to carry a |
|
3824 | * Updated version numbers on all files I modified to carry a | |
3789 | notice so Janko and Nathan have clear version markers. |
|
3825 | notice so Janko and Nathan have clear version markers. | |
3790 |
|
3826 | |||
3791 | * Updated docstring for ultraTB with my changes. I should send |
|
3827 | * Updated docstring for ultraTB with my changes. I should send | |
3792 | this to Nathan. |
|
3828 | this to Nathan. | |
3793 |
|
3829 | |||
3794 | * Lots of small fixes. Ran everything through pychecker again. |
|
3830 | * Lots of small fixes. Ran everything through pychecker again. | |
3795 |
|
3831 | |||
3796 | * Made loading of deep_reload an cmd line option. If it's not too |
|
3832 | * Made loading of deep_reload an cmd line option. If it's not too | |
3797 | kosher, now people can just disable it. With -nodeep_reload it's |
|
3833 | kosher, now people can just disable it. With -nodeep_reload it's | |
3798 | still available as dreload(), it just won't overwrite reload(). |
|
3834 | still available as dreload(), it just won't overwrite reload(). | |
3799 |
|
3835 | |||
3800 | * Moved many options to the no| form (-opt and -noopt |
|
3836 | * Moved many options to the no| form (-opt and -noopt | |
3801 | accepted). Cleaner. |
|
3837 | accepted). Cleaner. | |
3802 |
|
3838 | |||
3803 | * Changed magic_log so that if called with no parameters, it uses |
|
3839 | * Changed magic_log so that if called with no parameters, it uses | |
3804 | 'rotate' mode. That way auto-generated logs aren't automatically |
|
3840 | 'rotate' mode. That way auto-generated logs aren't automatically | |
3805 | over-written. For normal logs, now a backup is made if it exists |
|
3841 | over-written. For normal logs, now a backup is made if it exists | |
3806 | (only 1 level of backups). A new 'backup' mode was added to the |
|
3842 | (only 1 level of backups). A new 'backup' mode was added to the | |
3807 | Logger class to support this. This was a request by Janko. |
|
3843 | Logger class to support this. This was a request by Janko. | |
3808 |
|
3844 | |||
3809 | * Added @logoff/@logon to stop/restart an active log. |
|
3845 | * Added @logoff/@logon to stop/restart an active log. | |
3810 |
|
3846 | |||
3811 | * Fixed a lot of bugs in log saving/replay. It was pretty |
|
3847 | * Fixed a lot of bugs in log saving/replay. It was pretty | |
3812 | broken. Now special lines (!@,/) appear properly in the command |
|
3848 | broken. Now special lines (!@,/) appear properly in the command | |
3813 | history after a log replay. |
|
3849 | history after a log replay. | |
3814 |
|
3850 | |||
3815 | * Tried and failed to implement full session saving via pickle. My |
|
3851 | * Tried and failed to implement full session saving via pickle. My | |
3816 | idea was to pickle __main__.__dict__, but modules can't be |
|
3852 | idea was to pickle __main__.__dict__, but modules can't be | |
3817 | pickled. This would be a better alternative to replaying logs, but |
|
3853 | pickled. This would be a better alternative to replaying logs, but | |
3818 | seems quite tricky to get to work. Changed -session to be called |
|
3854 | seems quite tricky to get to work. Changed -session to be called | |
3819 | -logplay, which more accurately reflects what it does. And if we |
|
3855 | -logplay, which more accurately reflects what it does. And if we | |
3820 | ever get real session saving working, -session is now available. |
|
3856 | ever get real session saving working, -session is now available. | |
3821 |
|
3857 | |||
3822 | * Implemented color schemes for prompts also. As for tracebacks, |
|
3858 | * Implemented color schemes for prompts also. As for tracebacks, | |
3823 | currently only NoColor and Linux are supported. But now the |
|
3859 | currently only NoColor and Linux are supported. But now the | |
3824 | infrastructure is in place, based on a generic ColorScheme |
|
3860 | infrastructure is in place, based on a generic ColorScheme | |
3825 | class. So writing and activating new schemes both for the prompts |
|
3861 | class. So writing and activating new schemes both for the prompts | |
3826 | and the tracebacks should be straightforward. |
|
3862 | and the tracebacks should be straightforward. | |
3827 |
|
3863 | |||
3828 | * Version 0.1.13 released, 0.1.14 opened. |
|
3864 | * Version 0.1.13 released, 0.1.14 opened. | |
3829 |
|
3865 | |||
3830 | * Changed handling of options for output cache. Now counter is |
|
3866 | * Changed handling of options for output cache. Now counter is | |
3831 | hardwired starting at 1 and one specifies the maximum number of |
|
3867 | hardwired starting at 1 and one specifies the maximum number of | |
3832 | entries *in the outcache* (not the max prompt counter). This is |
|
3868 | entries *in the outcache* (not the max prompt counter). This is | |
3833 | much better, since many statements won't increase the cache |
|
3869 | much better, since many statements won't increase the cache | |
3834 | count. It also eliminated some confusing options, now there's only |
|
3870 | count. It also eliminated some confusing options, now there's only | |
3835 | one: cache_size. |
|
3871 | one: cache_size. | |
3836 |
|
3872 | |||
3837 | * Added 'alias' magic function and magic_alias option in the |
|
3873 | * Added 'alias' magic function and magic_alias option in the | |
3838 | ipythonrc file. Now the user can easily define whatever names he |
|
3874 | ipythonrc file. Now the user can easily define whatever names he | |
3839 | wants for the magic functions without having to play weird |
|
3875 | wants for the magic functions without having to play weird | |
3840 | namespace games. This gives IPython a real shell-like feel. |
|
3876 | namespace games. This gives IPython a real shell-like feel. | |
3841 |
|
3877 | |||
3842 | * Fixed doc/?/?? for magics. Now all work, in all forms (explicit |
|
3878 | * Fixed doc/?/?? for magics. Now all work, in all forms (explicit | |
3843 | @ or not). |
|
3879 | @ or not). | |
3844 |
|
3880 | |||
3845 | This was one of the last remaining 'visible' bugs (that I know |
|
3881 | This was one of the last remaining 'visible' bugs (that I know | |
3846 | of). I think if I can clean up the session loading so it works |
|
3882 | of). I think if I can clean up the session loading so it works | |
3847 | 100% I'll release a 0.2.0 version on c.p.l (talk to Janko first |
|
3883 | 100% I'll release a 0.2.0 version on c.p.l (talk to Janko first | |
3848 | about licensing). |
|
3884 | about licensing). | |
3849 |
|
3885 | |||
3850 | 2001-11-25 Fernando Perez <fperez@colorado.edu> |
|
3886 | 2001-11-25 Fernando Perez <fperez@colorado.edu> | |
3851 |
|
3887 | |||
3852 | * Rewrote somewhat oinfo (?/??). Nicer, now uses page() and |
|
3888 | * Rewrote somewhat oinfo (?/??). Nicer, now uses page() and | |
3853 | there's a cleaner distinction between what ? and ?? show. |
|
3889 | there's a cleaner distinction between what ? and ?? show. | |
3854 |
|
3890 | |||
3855 | * Added screen_length option. Now the user can define his own |
|
3891 | * Added screen_length option. Now the user can define his own | |
3856 | screen size for page() operations. |
|
3892 | screen size for page() operations. | |
3857 |
|
3893 | |||
3858 | * Implemented magic shell-like functions with automatic code |
|
3894 | * Implemented magic shell-like functions with automatic code | |
3859 | generation. Now adding another function is just a matter of adding |
|
3895 | generation. Now adding another function is just a matter of adding | |
3860 | an entry to a dict, and the function is dynamically generated at |
|
3896 | an entry to a dict, and the function is dynamically generated at | |
3861 | run-time. Python has some really cool features! |
|
3897 | run-time. Python has some really cool features! | |
3862 |
|
3898 | |||
3863 | * Renamed many options to cleanup conventions a little. Now all |
|
3899 | * Renamed many options to cleanup conventions a little. Now all | |
3864 | are lowercase, and only underscores where needed. Also in the code |
|
3900 | are lowercase, and only underscores where needed. Also in the code | |
3865 | option name tables are clearer. |
|
3901 | option name tables are clearer. | |
3866 |
|
3902 | |||
3867 | * Changed prompts a little. Now input is 'In [n]:' instead of |
|
3903 | * Changed prompts a little. Now input is 'In [n]:' instead of | |
3868 | 'In[n]:='. This allows it the numbers to be aligned with the |
|
3904 | 'In[n]:='. This allows it the numbers to be aligned with the | |
3869 | Out[n] numbers, and removes usage of ':=' which doesn't exist in |
|
3905 | Out[n] numbers, and removes usage of ':=' which doesn't exist in | |
3870 | Python (it was a Mathematica thing). The '...' continuation prompt |
|
3906 | Python (it was a Mathematica thing). The '...' continuation prompt | |
3871 | was also changed a little to align better. |
|
3907 | was also changed a little to align better. | |
3872 |
|
3908 | |||
3873 | * Fixed bug when flushing output cache. Not all _p<n> variables |
|
3909 | * Fixed bug when flushing output cache. Not all _p<n> variables | |
3874 | exist, so their deletion needs to be wrapped in a try: |
|
3910 | exist, so their deletion needs to be wrapped in a try: | |
3875 |
|
3911 | |||
3876 | * Figured out how to properly use inspect.formatargspec() (it |
|
3912 | * Figured out how to properly use inspect.formatargspec() (it | |
3877 | requires the args preceded by *). So I removed all the code from |
|
3913 | requires the args preceded by *). So I removed all the code from | |
3878 | _get_pdef in Magic, which was just replicating that. |
|
3914 | _get_pdef in Magic, which was just replicating that. | |
3879 |
|
3915 | |||
3880 | * Added test to prefilter to allow redefining magic function names |
|
3916 | * Added test to prefilter to allow redefining magic function names | |
3881 | as variables. This is ok, since the @ form is always available, |
|
3917 | as variables. This is ok, since the @ form is always available, | |
3882 | but whe should allow the user to define a variable called 'ls' if |
|
3918 | but whe should allow the user to define a variable called 'ls' if | |
3883 | he needs it. |
|
3919 | he needs it. | |
3884 |
|
3920 | |||
3885 | * Moved the ToDo information from README into a separate ToDo. |
|
3921 | * Moved the ToDo information from README into a separate ToDo. | |
3886 |
|
3922 | |||
3887 | * General code cleanup and small bugfixes. I think it's close to a |
|
3923 | * General code cleanup and small bugfixes. I think it's close to a | |
3888 | state where it can be released, obviously with a big 'beta' |
|
3924 | state where it can be released, obviously with a big 'beta' | |
3889 | warning on it. |
|
3925 | warning on it. | |
3890 |
|
3926 | |||
3891 | * Got the magic function split to work. Now all magics are defined |
|
3927 | * Got the magic function split to work. Now all magics are defined | |
3892 | in a separate class. It just organizes things a bit, and now |
|
3928 | in a separate class. It just organizes things a bit, and now | |
3893 | Xemacs behaves nicer (it was choking on InteractiveShell b/c it |
|
3929 | Xemacs behaves nicer (it was choking on InteractiveShell b/c it | |
3894 | was too long). |
|
3930 | was too long). | |
3895 |
|
3931 | |||
3896 | * Changed @clear to @reset to avoid potential confusions with |
|
3932 | * Changed @clear to @reset to avoid potential confusions with | |
3897 | the shell command clear. Also renamed @cl to @clear, which does |
|
3933 | the shell command clear. Also renamed @cl to @clear, which does | |
3898 | exactly what people expect it to from their shell experience. |
|
3934 | exactly what people expect it to from their shell experience. | |
3899 |
|
3935 | |||
3900 | Added a check to the @reset command (since it's so |
|
3936 | Added a check to the @reset command (since it's so | |
3901 | destructive, it's probably a good idea to ask for confirmation). |
|
3937 | destructive, it's probably a good idea to ask for confirmation). | |
3902 | But now reset only works for full namespace resetting. Since the |
|
3938 | But now reset only works for full namespace resetting. Since the | |
3903 | del keyword is already there for deleting a few specific |
|
3939 | del keyword is already there for deleting a few specific | |
3904 | variables, I don't see the point of having a redundant magic |
|
3940 | variables, I don't see the point of having a redundant magic | |
3905 | function for the same task. |
|
3941 | function for the same task. | |
3906 |
|
3942 | |||
3907 | 2001-11-24 Fernando Perez <fperez@colorado.edu> |
|
3943 | 2001-11-24 Fernando Perez <fperez@colorado.edu> | |
3908 |
|
3944 | |||
3909 | * Updated the builtin docs (esp. the ? ones). |
|
3945 | * Updated the builtin docs (esp. the ? ones). | |
3910 |
|
3946 | |||
3911 | * Ran all the code through pychecker. Not terribly impressed with |
|
3947 | * Ran all the code through pychecker. Not terribly impressed with | |
3912 | it: lots of spurious warnings and didn't really find anything of |
|
3948 | it: lots of spurious warnings and didn't really find anything of | |
3913 | substance (just a few modules being imported and not used). |
|
3949 | substance (just a few modules being imported and not used). | |
3914 |
|
3950 | |||
3915 | * Implemented the new ultraTB functionality into IPython. New |
|
3951 | * Implemented the new ultraTB functionality into IPython. New | |
3916 | option: xcolors. This chooses color scheme. xmode now only selects |
|
3952 | option: xcolors. This chooses color scheme. xmode now only selects | |
3917 | between Plain and Verbose. Better orthogonality. |
|
3953 | between Plain and Verbose. Better orthogonality. | |
3918 |
|
3954 | |||
3919 | * Large rewrite of ultraTB. Much cleaner now, with a separation of |
|
3955 | * Large rewrite of ultraTB. Much cleaner now, with a separation of | |
3920 | mode and color scheme for the exception handlers. Now it's |
|
3956 | mode and color scheme for the exception handlers. Now it's | |
3921 | possible to have the verbose traceback with no coloring. |
|
3957 | possible to have the verbose traceback with no coloring. | |
3922 |
|
3958 | |||
3923 | 2001-11-23 Fernando Perez <fperez@colorado.edu> |
|
3959 | 2001-11-23 Fernando Perez <fperez@colorado.edu> | |
3924 |
|
3960 | |||
3925 | * Version 0.1.12 released, 0.1.13 opened. |
|
3961 | * Version 0.1.12 released, 0.1.13 opened. | |
3926 |
|
3962 | |||
3927 | * Removed option to set auto-quote and auto-paren escapes by |
|
3963 | * Removed option to set auto-quote and auto-paren escapes by | |
3928 | user. The chances of breaking valid syntax are just too high. If |
|
3964 | user. The chances of breaking valid syntax are just too high. If | |
3929 | someone *really* wants, they can always dig into the code. |
|
3965 | someone *really* wants, they can always dig into the code. | |
3930 |
|
3966 | |||
3931 | * Made prompt separators configurable. |
|
3967 | * Made prompt separators configurable. | |
3932 |
|
3968 | |||
3933 | 2001-11-22 Fernando Perez <fperez@colorado.edu> |
|
3969 | 2001-11-22 Fernando Perez <fperez@colorado.edu> | |
3934 |
|
3970 | |||
3935 | * Small bugfixes in many places. |
|
3971 | * Small bugfixes in many places. | |
3936 |
|
3972 | |||
3937 | * Removed the MyCompleter class from ipplib. It seemed redundant |
|
3973 | * Removed the MyCompleter class from ipplib. It seemed redundant | |
3938 | with the C-p,C-n history search functionality. Less code to |
|
3974 | with the C-p,C-n history search functionality. Less code to | |
3939 | maintain. |
|
3975 | maintain. | |
3940 |
|
3976 | |||
3941 | * Moved all the original ipython.py code into ipythonlib.py. Right |
|
3977 | * Moved all the original ipython.py code into ipythonlib.py. Right | |
3942 | now it's just one big dump into a function called make_IPython, so |
|
3978 | now it's just one big dump into a function called make_IPython, so | |
3943 | no real modularity has been gained. But at least it makes the |
|
3979 | no real modularity has been gained. But at least it makes the | |
3944 | wrapper script tiny, and since ipythonlib is a module, it gets |
|
3980 | wrapper script tiny, and since ipythonlib is a module, it gets | |
3945 | compiled and startup is much faster. |
|
3981 | compiled and startup is much faster. | |
3946 |
|
3982 | |||
3947 | This is a reasobably 'deep' change, so we should test it for a |
|
3983 | This is a reasobably 'deep' change, so we should test it for a | |
3948 | while without messing too much more with the code. |
|
3984 | while without messing too much more with the code. | |
3949 |
|
3985 | |||
3950 | 2001-11-21 Fernando Perez <fperez@colorado.edu> |
|
3986 | 2001-11-21 Fernando Perez <fperez@colorado.edu> | |
3951 |
|
3987 | |||
3952 | * Version 0.1.11 released, 0.1.12 opened for further work. |
|
3988 | * Version 0.1.11 released, 0.1.12 opened for further work. | |
3953 |
|
3989 | |||
3954 | * Removed dependency on Itpl. It was only needed in one place. It |
|
3990 | * Removed dependency on Itpl. It was only needed in one place. It | |
3955 | would be nice if this became part of python, though. It makes life |
|
3991 | would be nice if this became part of python, though. It makes life | |
3956 | *a lot* easier in some cases. |
|
3992 | *a lot* easier in some cases. | |
3957 |
|
3993 | |||
3958 | * Simplified the prefilter code a bit. Now all handlers are |
|
3994 | * Simplified the prefilter code a bit. Now all handlers are | |
3959 | expected to explicitly return a value (at least a blank string). |
|
3995 | expected to explicitly return a value (at least a blank string). | |
3960 |
|
3996 | |||
3961 | * Heavy edits in ipplib. Removed the help system altogether. Now |
|
3997 | * Heavy edits in ipplib. Removed the help system altogether. Now | |
3962 | obj?/?? is used for inspecting objects, a magic @doc prints |
|
3998 | obj?/?? is used for inspecting objects, a magic @doc prints | |
3963 | docstrings, and full-blown Python help is accessed via the 'help' |
|
3999 | docstrings, and full-blown Python help is accessed via the 'help' | |
3964 | keyword. This cleans up a lot of code (less to maintain) and does |
|
4000 | keyword. This cleans up a lot of code (less to maintain) and does | |
3965 | the job. Since 'help' is now a standard Python component, might as |
|
4001 | the job. Since 'help' is now a standard Python component, might as | |
3966 | well use it and remove duplicate functionality. |
|
4002 | well use it and remove duplicate functionality. | |
3967 |
|
4003 | |||
3968 | Also removed the option to use ipplib as a standalone program. By |
|
4004 | Also removed the option to use ipplib as a standalone program. By | |
3969 | now it's too dependent on other parts of IPython to function alone. |
|
4005 | now it's too dependent on other parts of IPython to function alone. | |
3970 |
|
4006 | |||
3971 | * Fixed bug in genutils.pager. It would crash if the pager was |
|
4007 | * Fixed bug in genutils.pager. It would crash if the pager was | |
3972 | exited immediately after opening (broken pipe). |
|
4008 | exited immediately after opening (broken pipe). | |
3973 |
|
4009 | |||
3974 | * Trimmed down the VerboseTB reporting a little. The header is |
|
4010 | * Trimmed down the VerboseTB reporting a little. The header is | |
3975 | much shorter now and the repeated exception arguments at the end |
|
4011 | much shorter now and the repeated exception arguments at the end | |
3976 | have been removed. For interactive use the old header seemed a bit |
|
4012 | have been removed. For interactive use the old header seemed a bit | |
3977 | excessive. |
|
4013 | excessive. | |
3978 |
|
4014 | |||
3979 | * Fixed small bug in output of @whos for variables with multi-word |
|
4015 | * Fixed small bug in output of @whos for variables with multi-word | |
3980 | types (only first word was displayed). |
|
4016 | types (only first word was displayed). | |
3981 |
|
4017 | |||
3982 | 2001-11-17 Fernando Perez <fperez@colorado.edu> |
|
4018 | 2001-11-17 Fernando Perez <fperez@colorado.edu> | |
3983 |
|
4019 | |||
3984 | * Version 0.1.10 released, 0.1.11 opened for further work. |
|
4020 | * Version 0.1.10 released, 0.1.11 opened for further work. | |
3985 |
|
4021 | |||
3986 | * Modified dirs and friends. dirs now *returns* the stack (not |
|
4022 | * Modified dirs and friends. dirs now *returns* the stack (not | |
3987 | prints), so one can manipulate it as a variable. Convenient to |
|
4023 | prints), so one can manipulate it as a variable. Convenient to | |
3988 | travel along many directories. |
|
4024 | travel along many directories. | |
3989 |
|
4025 | |||
3990 | * Fixed bug in magic_pdef: would only work with functions with |
|
4026 | * Fixed bug in magic_pdef: would only work with functions with | |
3991 | arguments with default values. |
|
4027 | arguments with default values. | |
3992 |
|
4028 | |||
3993 | 2001-11-14 Fernando Perez <fperez@colorado.edu> |
|
4029 | 2001-11-14 Fernando Perez <fperez@colorado.edu> | |
3994 |
|
4030 | |||
3995 | * Added the PhysicsInput stuff to dot_ipython so it ships as an |
|
4031 | * Added the PhysicsInput stuff to dot_ipython so it ships as an | |
3996 | example with IPython. Various other minor fixes and cleanups. |
|
4032 | example with IPython. Various other minor fixes and cleanups. | |
3997 |
|
4033 | |||
3998 | * Version 0.1.9 released, 0.1.10 opened for further work. |
|
4034 | * Version 0.1.9 released, 0.1.10 opened for further work. | |
3999 |
|
4035 | |||
4000 | * Added sys.path to the list of directories searched in the |
|
4036 | * Added sys.path to the list of directories searched in the | |
4001 | execfile= option. It used to be the current directory and the |
|
4037 | execfile= option. It used to be the current directory and the | |
4002 | user's IPYTHONDIR only. |
|
4038 | user's IPYTHONDIR only. | |
4003 |
|
4039 | |||
4004 | 2001-11-13 Fernando Perez <fperez@colorado.edu> |
|
4040 | 2001-11-13 Fernando Perez <fperez@colorado.edu> | |
4005 |
|
4041 | |||
4006 | * Reinstated the raw_input/prefilter separation that Janko had |
|
4042 | * Reinstated the raw_input/prefilter separation that Janko had | |
4007 | initially. This gives a more convenient setup for extending the |
|
4043 | initially. This gives a more convenient setup for extending the | |
4008 | pre-processor from the outside: raw_input always gets a string, |
|
4044 | pre-processor from the outside: raw_input always gets a string, | |
4009 | and prefilter has to process it. We can then redefine prefilter |
|
4045 | and prefilter has to process it. We can then redefine prefilter | |
4010 | from the outside and implement extensions for special |
|
4046 | from the outside and implement extensions for special | |
4011 | purposes. |
|
4047 | purposes. | |
4012 |
|
4048 | |||
4013 | Today I got one for inputting PhysicalQuantity objects |
|
4049 | Today I got one for inputting PhysicalQuantity objects | |
4014 | (from Scientific) without needing any function calls at |
|
4050 | (from Scientific) without needing any function calls at | |
4015 | all. Extremely convenient, and it's all done as a user-level |
|
4051 | all. Extremely convenient, and it's all done as a user-level | |
4016 | extension (no IPython code was touched). Now instead of: |
|
4052 | extension (no IPython code was touched). Now instead of: | |
4017 | a = PhysicalQuantity(4.2,'m/s**2') |
|
4053 | a = PhysicalQuantity(4.2,'m/s**2') | |
4018 | one can simply say |
|
4054 | one can simply say | |
4019 | a = 4.2 m/s**2 |
|
4055 | a = 4.2 m/s**2 | |
4020 | or even |
|
4056 | or even | |
4021 | a = 4.2 m/s^2 |
|
4057 | a = 4.2 m/s^2 | |
4022 |
|
4058 | |||
4023 | I use this, but it's also a proof of concept: IPython really is |
|
4059 | I use this, but it's also a proof of concept: IPython really is | |
4024 | fully user-extensible, even at the level of the parsing of the |
|
4060 | fully user-extensible, even at the level of the parsing of the | |
4025 | command line. It's not trivial, but it's perfectly doable. |
|
4061 | command line. It's not trivial, but it's perfectly doable. | |
4026 |
|
4062 | |||
4027 | * Added 'add_flip' method to inclusion conflict resolver. Fixes |
|
4063 | * Added 'add_flip' method to inclusion conflict resolver. Fixes | |
4028 | the problem of modules being loaded in the inverse order in which |
|
4064 | the problem of modules being loaded in the inverse order in which | |
4029 | they were defined in |
|
4065 | they were defined in | |
4030 |
|
4066 | |||
4031 | * Version 0.1.8 released, 0.1.9 opened for further work. |
|
4067 | * Version 0.1.8 released, 0.1.9 opened for further work. | |
4032 |
|
4068 | |||
4033 | * Added magics pdef, source and file. They respectively show the |
|
4069 | * Added magics pdef, source and file. They respectively show the | |
4034 | definition line ('prototype' in C), source code and full python |
|
4070 | definition line ('prototype' in C), source code and full python | |
4035 | file for any callable object. The object inspector oinfo uses |
|
4071 | file for any callable object. The object inspector oinfo uses | |
4036 | these to show the same information. |
|
4072 | these to show the same information. | |
4037 |
|
4073 | |||
4038 | * Version 0.1.7 released, 0.1.8 opened for further work. |
|
4074 | * Version 0.1.7 released, 0.1.8 opened for further work. | |
4039 |
|
4075 | |||
4040 | * Separated all the magic functions into a class called Magic. The |
|
4076 | * Separated all the magic functions into a class called Magic. The | |
4041 | InteractiveShell class was becoming too big for Xemacs to handle |
|
4077 | InteractiveShell class was becoming too big for Xemacs to handle | |
4042 | (de-indenting a line would lock it up for 10 seconds while it |
|
4078 | (de-indenting a line would lock it up for 10 seconds while it | |
4043 | backtracked on the whole class!) |
|
4079 | backtracked on the whole class!) | |
4044 |
|
4080 | |||
4045 | FIXME: didn't work. It can be done, but right now namespaces are |
|
4081 | FIXME: didn't work. It can be done, but right now namespaces are | |
4046 | all messed up. Do it later (reverted it for now, so at least |
|
4082 | all messed up. Do it later (reverted it for now, so at least | |
4047 | everything works as before). |
|
4083 | everything works as before). | |
4048 |
|
4084 | |||
4049 | * Got the object introspection system (magic_oinfo) working! I |
|
4085 | * Got the object introspection system (magic_oinfo) working! I | |
4050 | think this is pretty much ready for release to Janko, so he can |
|
4086 | think this is pretty much ready for release to Janko, so he can | |
4051 | test it for a while and then announce it. Pretty much 100% of what |
|
4087 | test it for a while and then announce it. Pretty much 100% of what | |
4052 | I wanted for the 'phase 1' release is ready. Happy, tired. |
|
4088 | I wanted for the 'phase 1' release is ready. Happy, tired. | |
4053 |
|
4089 | |||
4054 | 2001-11-12 Fernando Perez <fperez@colorado.edu> |
|
4090 | 2001-11-12 Fernando Perez <fperez@colorado.edu> | |
4055 |
|
4091 | |||
4056 | * Version 0.1.6 released, 0.1.7 opened for further work. |
|
4092 | * Version 0.1.6 released, 0.1.7 opened for further work. | |
4057 |
|
4093 | |||
4058 | * Fixed bug in printing: it used to test for truth before |
|
4094 | * Fixed bug in printing: it used to test for truth before | |
4059 | printing, so 0 wouldn't print. Now checks for None. |
|
4095 | printing, so 0 wouldn't print. Now checks for None. | |
4060 |
|
4096 | |||
4061 | * Fixed bug where auto-execs increase the prompt counter by 2 (b/c |
|
4097 | * Fixed bug where auto-execs increase the prompt counter by 2 (b/c | |
4062 | they have to call len(str(sys.ps1)) ). But the fix is ugly, it |
|
4098 | they have to call len(str(sys.ps1)) ). But the fix is ugly, it | |
4063 | reaches by hand into the outputcache. Think of a better way to do |
|
4099 | reaches by hand into the outputcache. Think of a better way to do | |
4064 | this later. |
|
4100 | this later. | |
4065 |
|
4101 | |||
4066 | * Various small fixes thanks to Nathan's comments. |
|
4102 | * Various small fixes thanks to Nathan's comments. | |
4067 |
|
4103 | |||
4068 | * Changed magic_pprint to magic_Pprint. This way it doesn't |
|
4104 | * Changed magic_pprint to magic_Pprint. This way it doesn't | |
4069 | collide with pprint() and the name is consistent with the command |
|
4105 | collide with pprint() and the name is consistent with the command | |
4070 | line option. |
|
4106 | line option. | |
4071 |
|
4107 | |||
4072 | * Changed prompt counter behavior to be fully like |
|
4108 | * Changed prompt counter behavior to be fully like | |
4073 | Mathematica's. That is, even input that doesn't return a result |
|
4109 | Mathematica's. That is, even input that doesn't return a result | |
4074 | raises the prompt counter. The old behavior was kind of confusing |
|
4110 | raises the prompt counter. The old behavior was kind of confusing | |
4075 | (getting the same prompt number several times if the operation |
|
4111 | (getting the same prompt number several times if the operation | |
4076 | didn't return a result). |
|
4112 | didn't return a result). | |
4077 |
|
4113 | |||
4078 | * Fixed Nathan's last name in a couple of places (Gray, not Graham). |
|
4114 | * Fixed Nathan's last name in a couple of places (Gray, not Graham). | |
4079 |
|
4115 | |||
4080 | * Fixed -Classic mode (wasn't working anymore). |
|
4116 | * Fixed -Classic mode (wasn't working anymore). | |
4081 |
|
4117 | |||
4082 | * Added colored prompts using Nathan's new code. Colors are |
|
4118 | * Added colored prompts using Nathan's new code. Colors are | |
4083 | currently hardwired, they can be user-configurable. For |
|
4119 | currently hardwired, they can be user-configurable. For | |
4084 | developers, they can be chosen in file ipythonlib.py, at the |
|
4120 | developers, they can be chosen in file ipythonlib.py, at the | |
4085 | beginning of the CachedOutput class def. |
|
4121 | beginning of the CachedOutput class def. | |
4086 |
|
4122 | |||
4087 | 2001-11-11 Fernando Perez <fperez@colorado.edu> |
|
4123 | 2001-11-11 Fernando Perez <fperez@colorado.edu> | |
4088 |
|
4124 | |||
4089 | * Version 0.1.5 released, 0.1.6 opened for further work. |
|
4125 | * Version 0.1.5 released, 0.1.6 opened for further work. | |
4090 |
|
4126 | |||
4091 | * Changed magic_env to *return* the environment as a dict (not to |
|
4127 | * Changed magic_env to *return* the environment as a dict (not to | |
4092 | print it). This way it prints, but it can also be processed. |
|
4128 | print it). This way it prints, but it can also be processed. | |
4093 |
|
4129 | |||
4094 | * Added Verbose exception reporting to interactive |
|
4130 | * Added Verbose exception reporting to interactive | |
4095 | exceptions. Very nice, now even 1/0 at the prompt gives a verbose |
|
4131 | exceptions. Very nice, now even 1/0 at the prompt gives a verbose | |
4096 | traceback. Had to make some changes to the ultraTB file. This is |
|
4132 | traceback. Had to make some changes to the ultraTB file. This is | |
4097 | probably the last 'big' thing in my mental todo list. This ties |
|
4133 | probably the last 'big' thing in my mental todo list. This ties | |
4098 | in with the next entry: |
|
4134 | in with the next entry: | |
4099 |
|
4135 | |||
4100 | * Changed -Xi and -Xf to a single -xmode option. Now all the user |
|
4136 | * Changed -Xi and -Xf to a single -xmode option. Now all the user | |
4101 | has to specify is Plain, Color or Verbose for all exception |
|
4137 | has to specify is Plain, Color or Verbose for all exception | |
4102 | handling. |
|
4138 | handling. | |
4103 |
|
4139 | |||
4104 | * Removed ShellServices option. All this can really be done via |
|
4140 | * Removed ShellServices option. All this can really be done via | |
4105 | the magic system. It's easier to extend, cleaner and has automatic |
|
4141 | the magic system. It's easier to extend, cleaner and has automatic | |
4106 | namespace protection and documentation. |
|
4142 | namespace protection and documentation. | |
4107 |
|
4143 | |||
4108 | 2001-11-09 Fernando Perez <fperez@colorado.edu> |
|
4144 | 2001-11-09 Fernando Perez <fperez@colorado.edu> | |
4109 |
|
4145 | |||
4110 | * Fixed bug in output cache flushing (missing parameter to |
|
4146 | * Fixed bug in output cache flushing (missing parameter to | |
4111 | __init__). Other small bugs fixed (found using pychecker). |
|
4147 | __init__). Other small bugs fixed (found using pychecker). | |
4112 |
|
4148 | |||
4113 | * Version 0.1.4 opened for bugfixing. |
|
4149 | * Version 0.1.4 opened for bugfixing. | |
4114 |
|
4150 | |||
4115 | 2001-11-07 Fernando Perez <fperez@colorado.edu> |
|
4151 | 2001-11-07 Fernando Perez <fperez@colorado.edu> | |
4116 |
|
4152 | |||
4117 | * Version 0.1.3 released, mainly because of the raw_input bug. |
|
4153 | * Version 0.1.3 released, mainly because of the raw_input bug. | |
4118 |
|
4154 | |||
4119 | * Fixed NASTY bug in raw_input: input line wasn't properly parsed |
|
4155 | * Fixed NASTY bug in raw_input: input line wasn't properly parsed | |
4120 | and when testing for whether things were callable, a call could |
|
4156 | and when testing for whether things were callable, a call could | |
4121 | actually be made to certain functions. They would get called again |
|
4157 | actually be made to certain functions. They would get called again | |
4122 | once 'really' executed, with a resulting double call. A disaster |
|
4158 | once 'really' executed, with a resulting double call. A disaster | |
4123 | in many cases (list.reverse() would never work!). |
|
4159 | in many cases (list.reverse() would never work!). | |
4124 |
|
4160 | |||
4125 | * Removed prefilter() function, moved its code to raw_input (which |
|
4161 | * Removed prefilter() function, moved its code to raw_input (which | |
4126 | after all was just a near-empty caller for prefilter). This saves |
|
4162 | after all was just a near-empty caller for prefilter). This saves | |
4127 | a function call on every prompt, and simplifies the class a tiny bit. |
|
4163 | a function call on every prompt, and simplifies the class a tiny bit. | |
4128 |
|
4164 | |||
4129 | * Fix _ip to __ip name in magic example file. |
|
4165 | * Fix _ip to __ip name in magic example file. | |
4130 |
|
4166 | |||
4131 | * Changed 'tar -x -f' to 'tar xvf' in auto-installer. This should |
|
4167 | * Changed 'tar -x -f' to 'tar xvf' in auto-installer. This should | |
4132 | work with non-gnu versions of tar. |
|
4168 | work with non-gnu versions of tar. | |
4133 |
|
4169 | |||
4134 | 2001-11-06 Fernando Perez <fperez@colorado.edu> |
|
4170 | 2001-11-06 Fernando Perez <fperez@colorado.edu> | |
4135 |
|
4171 | |||
4136 | * Version 0.1.2. Just to keep track of the recent changes. |
|
4172 | * Version 0.1.2. Just to keep track of the recent changes. | |
4137 |
|
4173 | |||
4138 | * Fixed nasty bug in output prompt routine. It used to check 'if |
|
4174 | * Fixed nasty bug in output prompt routine. It used to check 'if | |
4139 | arg != None...'. Problem is, this fails if arg implements a |
|
4175 | arg != None...'. Problem is, this fails if arg implements a | |
4140 | special comparison (__cmp__) which disallows comparing to |
|
4176 | special comparison (__cmp__) which disallows comparing to | |
4141 | None. Found it when trying to use the PhysicalQuantity module from |
|
4177 | None. Found it when trying to use the PhysicalQuantity module from | |
4142 | ScientificPython. |
|
4178 | ScientificPython. | |
4143 |
|
4179 | |||
4144 | 2001-11-05 Fernando Perez <fperez@colorado.edu> |
|
4180 | 2001-11-05 Fernando Perez <fperez@colorado.edu> | |
4145 |
|
4181 | |||
4146 | * Also added dirs. Now the pushd/popd/dirs family functions |
|
4182 | * Also added dirs. Now the pushd/popd/dirs family functions | |
4147 | basically like the shell, with the added convenience of going home |
|
4183 | basically like the shell, with the added convenience of going home | |
4148 | when called with no args. |
|
4184 | when called with no args. | |
4149 |
|
4185 | |||
4150 | * pushd/popd slightly modified to mimic shell behavior more |
|
4186 | * pushd/popd slightly modified to mimic shell behavior more | |
4151 | closely. |
|
4187 | closely. | |
4152 |
|
4188 | |||
4153 | * Added env,pushd,popd from ShellServices as magic functions. I |
|
4189 | * Added env,pushd,popd from ShellServices as magic functions. I | |
4154 | think the cleanest will be to port all desired functions from |
|
4190 | think the cleanest will be to port all desired functions from | |
4155 | ShellServices as magics and remove ShellServices altogether. This |
|
4191 | ShellServices as magics and remove ShellServices altogether. This | |
4156 | will provide a single, clean way of adding functionality |
|
4192 | will provide a single, clean way of adding functionality | |
4157 | (shell-type or otherwise) to IP. |
|
4193 | (shell-type or otherwise) to IP. | |
4158 |
|
4194 | |||
4159 | 2001-11-04 Fernando Perez <fperez@colorado.edu> |
|
4195 | 2001-11-04 Fernando Perez <fperez@colorado.edu> | |
4160 |
|
4196 | |||
4161 | * Added .ipython/ directory to sys.path. This way users can keep |
|
4197 | * Added .ipython/ directory to sys.path. This way users can keep | |
4162 | customizations there and access them via import. |
|
4198 | customizations there and access them via import. | |
4163 |
|
4199 | |||
4164 | 2001-11-03 Fernando Perez <fperez@colorado.edu> |
|
4200 | 2001-11-03 Fernando Perez <fperez@colorado.edu> | |
4165 |
|
4201 | |||
4166 | * Opened version 0.1.1 for new changes. |
|
4202 | * Opened version 0.1.1 for new changes. | |
4167 |
|
4203 | |||
4168 | * Changed version number to 0.1.0: first 'public' release, sent to |
|
4204 | * Changed version number to 0.1.0: first 'public' release, sent to | |
4169 | Nathan and Janko. |
|
4205 | Nathan and Janko. | |
4170 |
|
4206 | |||
4171 | * Lots of small fixes and tweaks. |
|
4207 | * Lots of small fixes and tweaks. | |
4172 |
|
4208 | |||
4173 | * Minor changes to whos format. Now strings are shown, snipped if |
|
4209 | * Minor changes to whos format. Now strings are shown, snipped if | |
4174 | too long. |
|
4210 | too long. | |
4175 |
|
4211 | |||
4176 | * Changed ShellServices to work on __main__ so they show up in @who |
|
4212 | * Changed ShellServices to work on __main__ so they show up in @who | |
4177 |
|
4213 | |||
4178 | * Help also works with ? at the end of a line: |
|
4214 | * Help also works with ? at the end of a line: | |
4179 | ?sin and sin? |
|
4215 | ?sin and sin? | |
4180 | both produce the same effect. This is nice, as often I use the |
|
4216 | both produce the same effect. This is nice, as often I use the | |
4181 | tab-complete to find the name of a method, but I used to then have |
|
4217 | tab-complete to find the name of a method, but I used to then have | |
4182 | to go to the beginning of the line to put a ? if I wanted more |
|
4218 | to go to the beginning of the line to put a ? if I wanted more | |
4183 | info. Now I can just add the ? and hit return. Convenient. |
|
4219 | info. Now I can just add the ? and hit return. Convenient. | |
4184 |
|
4220 | |||
4185 | 2001-11-02 Fernando Perez <fperez@colorado.edu> |
|
4221 | 2001-11-02 Fernando Perez <fperez@colorado.edu> | |
4186 |
|
4222 | |||
4187 | * Python version check (>=2.1) added. |
|
4223 | * Python version check (>=2.1) added. | |
4188 |
|
4224 | |||
4189 | * Added LazyPython documentation. At this point the docs are quite |
|
4225 | * Added LazyPython documentation. At this point the docs are quite | |
4190 | a mess. A cleanup is in order. |
|
4226 | a mess. A cleanup is in order. | |
4191 |
|
4227 | |||
4192 | * Auto-installer created. For some bizarre reason, the zipfiles |
|
4228 | * Auto-installer created. For some bizarre reason, the zipfiles | |
4193 | module isn't working on my system. So I made a tar version |
|
4229 | module isn't working on my system. So I made a tar version | |
4194 | (hopefully the command line options in various systems won't kill |
|
4230 | (hopefully the command line options in various systems won't kill | |
4195 | me). |
|
4231 | me). | |
4196 |
|
4232 | |||
4197 | * Fixes to Struct in genutils. Now all dictionary-like methods are |
|
4233 | * Fixes to Struct in genutils. Now all dictionary-like methods are | |
4198 | protected (reasonably). |
|
4234 | protected (reasonably). | |
4199 |
|
4235 | |||
4200 | * Added pager function to genutils and changed ? to print usage |
|
4236 | * Added pager function to genutils and changed ? to print usage | |
4201 | note through it (it was too long). |
|
4237 | note through it (it was too long). | |
4202 |
|
4238 | |||
4203 | * Added the LazyPython functionality. Works great! I changed the |
|
4239 | * Added the LazyPython functionality. Works great! I changed the | |
4204 | auto-quote escape to ';', it's on home row and next to '. But |
|
4240 | auto-quote escape to ';', it's on home row and next to '. But | |
4205 | both auto-quote and auto-paren (still /) escapes are command-line |
|
4241 | both auto-quote and auto-paren (still /) escapes are command-line | |
4206 | parameters. |
|
4242 | parameters. | |
4207 |
|
4243 | |||
4208 |
|
4244 | |||
4209 | 2001-11-01 Fernando Perez <fperez@colorado.edu> |
|
4245 | 2001-11-01 Fernando Perez <fperez@colorado.edu> | |
4210 |
|
4246 | |||
4211 | * Version changed to 0.0.7. Fairly large change: configuration now |
|
4247 | * Version changed to 0.0.7. Fairly large change: configuration now | |
4212 | is all stored in a directory, by default .ipython. There, all |
|
4248 | is all stored in a directory, by default .ipython. There, all | |
4213 | config files have normal looking names (not .names) |
|
4249 | config files have normal looking names (not .names) | |
4214 |
|
4250 | |||
4215 | * Version 0.0.6 Released first to Lucas and Archie as a test |
|
4251 | * Version 0.0.6 Released first to Lucas and Archie as a test | |
4216 | run. Since it's the first 'semi-public' release, change version to |
|
4252 | run. Since it's the first 'semi-public' release, change version to | |
4217 | > 0.0.6 for any changes now. |
|
4253 | > 0.0.6 for any changes now. | |
4218 |
|
4254 | |||
4219 | * Stuff I had put in the ipplib.py changelog: |
|
4255 | * Stuff I had put in the ipplib.py changelog: | |
4220 |
|
4256 | |||
4221 | Changes to InteractiveShell: |
|
4257 | Changes to InteractiveShell: | |
4222 |
|
4258 | |||
4223 | - Made the usage message a parameter. |
|
4259 | - Made the usage message a parameter. | |
4224 |
|
4260 | |||
4225 | - Require the name of the shell variable to be given. It's a bit |
|
4261 | - Require the name of the shell variable to be given. It's a bit | |
4226 | of a hack, but allows the name 'shell' not to be hardwire in the |
|
4262 | of a hack, but allows the name 'shell' not to be hardwire in the | |
4227 | magic (@) handler, which is problematic b/c it requires |
|
4263 | magic (@) handler, which is problematic b/c it requires | |
4228 | polluting the global namespace with 'shell'. This in turn is |
|
4264 | polluting the global namespace with 'shell'. This in turn is | |
4229 | fragile: if a user redefines a variable called shell, things |
|
4265 | fragile: if a user redefines a variable called shell, things | |
4230 | break. |
|
4266 | break. | |
4231 |
|
4267 | |||
4232 | - magic @: all functions available through @ need to be defined |
|
4268 | - magic @: all functions available through @ need to be defined | |
4233 | as magic_<name>, even though they can be called simply as |
|
4269 | as magic_<name>, even though they can be called simply as | |
4234 | @<name>. This allows the special command @magic to gather |
|
4270 | @<name>. This allows the special command @magic to gather | |
4235 | information automatically about all existing magic functions, |
|
4271 | information automatically about all existing magic functions, | |
4236 | even if they are run-time user extensions, by parsing the shell |
|
4272 | even if they are run-time user extensions, by parsing the shell | |
4237 | instance __dict__ looking for special magic_ names. |
|
4273 | instance __dict__ looking for special magic_ names. | |
4238 |
|
4274 | |||
4239 | - mainloop: added *two* local namespace parameters. This allows |
|
4275 | - mainloop: added *two* local namespace parameters. This allows | |
4240 | the class to differentiate between parameters which were there |
|
4276 | the class to differentiate between parameters which were there | |
4241 | before and after command line initialization was processed. This |
|
4277 | before and after command line initialization was processed. This | |
4242 | way, later @who can show things loaded at startup by the |
|
4278 | way, later @who can show things loaded at startup by the | |
4243 | user. This trick was necessary to make session saving/reloading |
|
4279 | user. This trick was necessary to make session saving/reloading | |
4244 | really work: ideally after saving/exiting/reloading a session, |
|
4280 | really work: ideally after saving/exiting/reloading a session, | |
4245 | *everythin* should look the same, including the output of @who. I |
|
4281 | *everythin* should look the same, including the output of @who. I | |
4246 | was only able to make this work with this double namespace |
|
4282 | was only able to make this work with this double namespace | |
4247 | trick. |
|
4283 | trick. | |
4248 |
|
4284 | |||
4249 | - added a header to the logfile which allows (almost) full |
|
4285 | - added a header to the logfile which allows (almost) full | |
4250 | session restoring. |
|
4286 | session restoring. | |
4251 |
|
4287 | |||
4252 | - prepend lines beginning with @ or !, with a and log |
|
4288 | - prepend lines beginning with @ or !, with a and log | |
4253 | them. Why? !lines: may be useful to know what you did @lines: |
|
4289 | them. Why? !lines: may be useful to know what you did @lines: | |
4254 | they may affect session state. So when restoring a session, at |
|
4290 | they may affect session state. So when restoring a session, at | |
4255 | least inform the user of their presence. I couldn't quite get |
|
4291 | least inform the user of their presence. I couldn't quite get | |
4256 | them to properly re-execute, but at least the user is warned. |
|
4292 | them to properly re-execute, but at least the user is warned. | |
4257 |
|
4293 | |||
4258 | * Started ChangeLog. |
|
4294 | * Started ChangeLog. |
General Comments 0
You need to be logged in to leave comments.
Login now