Show More
@@ -1,270 +1,272 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """Modified input prompt for executing files. |
|
3 | 3 | |
|
4 | 4 | We define a special input line filter to allow typing lines which begin with |
|
5 | 5 | '~', '/' or '.'. If one of those strings is encountered, it is automatically |
|
6 | 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 | 11 | # Copyright (C) 2004 W.J. van der Laan <gnufnork@hetdigitalegat.nl> |
|
12 | 12 | # Copyright (C) 2004 Fernando Perez <fperez@colorado.edu> |
|
13 | 13 | # |
|
14 | 14 | # Distributed under the terms of the BSD License. The full license is in |
|
15 | 15 | # the file COPYING, distributed as part of this software. |
|
16 | 16 | #***************************************************************************** |
|
17 | 17 | |
|
18 | 18 | from IPython import Release |
|
19 | 19 | __author__ = 'W.J. van der Laan <gnufnork@hetdigitalegat.nl>, '\ |
|
20 | 20 | '%s <%s>' % Release.authors['Fernando'] |
|
21 | 21 | __license__ = Release.license |
|
22 | 22 | |
|
23 | 23 | def prefilter_shell(self,line,continuation): |
|
24 | 24 | """Alternate prefilter, modified for shell-like functionality. |
|
25 | 25 | |
|
26 | 26 | - Execute all lines beginning with '~', '/' or '.' |
|
27 | 27 | - $var=cmd <=> %sc var=cmd |
|
28 | 28 | - $$var=cmd <=> %sc -l var=cmd |
|
29 | 29 | """ |
|
30 | 30 | |
|
31 | 31 | if line: |
|
32 | 32 | l0 = line[0] |
|
33 | 33 | if l0 in '~/.': |
|
34 | 34 | return self._prefilter("!%s"%line,continuation) |
|
35 | 35 | elif l0=='$': |
|
36 | 36 | lrest = line[1:] |
|
37 | 37 | if lrest.startswith('$'): |
|
38 | 38 | # $$var=cmd <=> %sc -l var=cmd |
|
39 | 39 | return self._prefilter("%ssc -l %s" % (self.ESC_MAGIC,lrest[1:]), |
|
40 | 40 | continuation) |
|
41 | 41 | else: |
|
42 | 42 | # $var=cmd <=> %sc var=cmd |
|
43 | 43 | return self._prefilter("%ssc %s" % (self.ESC_MAGIC,lrest), |
|
44 | 44 | continuation) |
|
45 | 45 | else: |
|
46 | 46 | return self._prefilter(line,continuation) |
|
47 | 47 | else: |
|
48 | 48 | return self._prefilter(line,continuation) |
|
49 | 49 | |
|
50 | 50 | # Rebind this to be the new IPython prefilter: |
|
51 | 51 | from IPython.iplib import InteractiveShell |
|
52 | 52 | InteractiveShell.prefilter = prefilter_shell |
|
53 | 53 | # Clean up the namespace. |
|
54 | 54 | del InteractiveShell,prefilter_shell |
|
55 | 55 | |
|
56 | 56 | # Provide pysh and further shell-oriented services |
|
57 | 57 | import os,sys,shutil |
|
58 | 58 | from IPython.genutils import system,shell,getoutput,getoutputerror |
|
59 | 59 | |
|
60 | 60 | # Short aliases for getting shell output as a string and a list |
|
61 | 61 | sout = getoutput |
|
62 | 62 | lout = lambda cmd: getoutput(cmd,split=1) |
|
63 | 63 | |
|
64 | 64 | # Empty function, meant as a docstring holder so help(pysh) works. |
|
65 | 65 | def pysh(): |
|
66 | 66 | """Pysh is a set of modules and extensions to IPython which make shell-like |
|
67 | 67 | usage with Python syntax more convenient. Keep in mind that pysh is NOT a |
|
68 | 68 | full-blown shell, so don't try to make it your /etc/passwd entry! |
|
69 | 69 | |
|
70 | 70 | In particular, it has no job control, so if you type Ctrl-Z (under Unix), |
|
71 | 71 | you'll suspend pysh itself, not the process you just started. |
|
72 | 72 | |
|
73 | 73 | Since pysh is really nothing but a customized IPython, you should |
|
74 | 74 | familiarize yourself with IPython's features. This brief help mainly |
|
75 | 75 | documents areas in which pysh differs from the normal IPython. |
|
76 | 76 | |
|
77 | 77 | ALIASES |
|
78 | 78 | ------- |
|
79 | 79 | All of your $PATH has been loaded as IPython aliases, so you should be |
|
80 | 80 | able to type any normal system command and have it executed. See %alias? |
|
81 | 81 | and %unalias? for details on the alias facilities. |
|
82 | 82 | |
|
83 | 83 | SPECIAL SYNTAX |
|
84 | 84 | -------------- |
|
85 | 85 | Any lines which begin with '~', '/' and '.' will be executed as shell |
|
86 | 86 | commands instead of as Python code. The special escapes below are also |
|
87 | 87 | recognized. !cmd is valid in single or multi-line input, all others are |
|
88 | 88 | only valid in single-line input: |
|
89 | 89 | |
|
90 | 90 | !cmd - pass 'cmd' directly to the shell |
|
91 | 91 | !!cmd - execute 'cmd' and return output as a list (split on '\\n') |
|
92 | 92 | $var=cmd - capture output of cmd into var, as a string |
|
93 | 93 | $$var=cmd - capture output of cmd into var, as a list (split on '\\n') |
|
94 | 94 | |
|
95 | 95 | The $/$$ syntaxes make Python variables from system output, which you can |
|
96 | 96 | later use for further scripting. The converse is also possible: when |
|
97 | 97 | executing an alias or calling to the system via !/!!, you can expand any |
|
98 | 98 | python variable or expression by prepending it with $. Full details of |
|
99 | 99 | the allowed syntax can be found in Python's PEP 215. |
|
100 | 100 | |
|
101 | 101 | A few brief examples will illustrate these: |
|
102 | 102 | |
|
103 | 103 | fperez[~/test]|3> !ls *s.py |
|
104 | 104 | scopes.py strings.py |
|
105 | 105 | |
|
106 | 106 | ls is an internal alias, so there's no need to use !: |
|
107 | 107 | fperez[~/test]|4> ls *s.py |
|
108 | 108 | scopes.py* strings.py |
|
109 | 109 | |
|
110 | 110 | !!ls will return the output into a Python variable: |
|
111 | 111 | fperez[~/test]|5> !!ls *s.py |
|
112 | 112 | <5> ['scopes.py', 'strings.py'] |
|
113 | 113 | fperez[~/test]|6> print _5 |
|
114 | 114 | ['scopes.py', 'strings.py'] |
|
115 | 115 | |
|
116 | 116 | $ and $$ allow direct capture to named variables: |
|
117 | 117 | fperez[~/test]|7> $astr = ls *s.py |
|
118 | 118 | fperez[~/test]|8> astr |
|
119 | 119 | <8> 'scopes.py\\nstrings.py' |
|
120 | 120 | |
|
121 | 121 | fperez[~/test]|9> $$alist = ls *s.py |
|
122 | 122 | fperez[~/test]|10> alist |
|
123 | 123 | <10> ['scopes.py', 'strings.py'] |
|
124 | 124 | |
|
125 | 125 | alist is now a normal python list you can loop over. Using $ will expand |
|
126 | 126 | back the python values when alias calls are made: |
|
127 | 127 | fperez[~/test]|11> for f in alist: |
|
128 | 128 | |..> print 'file',f, |
|
129 | 129 | |..> wc -l $f |
|
130 | 130 | |..> |
|
131 | 131 | file scopes.py 13 scopes.py |
|
132 | 132 | file strings.py 4 strings.py |
|
133 | 133 | |
|
134 | 134 | Note that you may need to protect your variables with braces if you want |
|
135 | 135 | to append strings to their names. To copy all files in alist to .bak |
|
136 | 136 | extensions, you must use: |
|
137 | 137 | fperez[~/test]|12> for f in alist: |
|
138 | 138 | |..> cp $f ${f}.bak |
|
139 | 139 | |
|
140 | 140 | If you try using $f.bak, you'll get an AttributeError exception saying |
|
141 | 141 | that your string object doesn't have a .bak attribute. This is because |
|
142 | 142 | the $ expansion mechanism allows you to expand full Python expressions: |
|
143 | 143 | fperez[~/test]|13> echo "sys.platform is: $sys.platform" |
|
144 | 144 | sys.platform is: linux2 |
|
145 | 145 | |
|
146 | 146 | IPython's input history handling is still active, which allows you to |
|
147 | 147 | rerun a single block of multi-line input by simply using exec: |
|
148 | 148 | fperez[~/test]|14> $$alist = ls *.eps |
|
149 | 149 | fperez[~/test]|15> exec _i11 |
|
150 | 150 | file image2.eps 921 image2.eps |
|
151 | 151 | file image.eps 921 image.eps |
|
152 | 152 | |
|
153 | 153 | While these are new special-case syntaxes, they are designed to allow very |
|
154 | 154 | efficient use of the shell with minimal typing. At an interactive shell |
|
155 | 155 | prompt, conciseness of expression wins over readability. |
|
156 | 156 | |
|
157 | 157 | USEFUL FUNCTIONS AND MODULES |
|
158 | 158 | ---------------------------- |
|
159 | 159 | The os, sys and shutil modules from the Python standard library are |
|
160 | 160 | automatically loaded. Some additional functions, useful for shell usage, |
|
161 | 161 | are listed below. You can request more help about them with '?'. |
|
162 | 162 | |
|
163 | 163 | shell - execute a command in the underlying system shell |
|
164 | 164 | system - like shell(), but return the exit status of the command |
|
165 | 165 | sout - capture the output of a command as a string |
|
166 | 166 | lout - capture the output of a command as a list (split on '\\n') |
|
167 | 167 | getoutputerror - capture (output,error) of a shell command |
|
168 | 168 | |
|
169 | 169 | sout/lout are the functional equivalents of $/$$. They are provided to |
|
170 | 170 | allow you to capture system output in the middle of true python code, |
|
171 | 171 | function definitions, etc (where $ and $$ are invalid). |
|
172 | 172 | |
|
173 | 173 | DIRECTORY MANAGEMENT |
|
174 | 174 | -------------------- |
|
175 | 175 | Since each command passed by pysh to the underlying system is executed in |
|
176 | 176 | a subshell which exits immediately, you can NOT use !cd to navigate the |
|
177 | 177 | filesystem. |
|
178 | 178 | |
|
179 | 179 | Pysh provides its own builtin '%cd' magic command to move in the |
|
180 | 180 | filesystem (the % is not required with automagic on). It also maintains a |
|
181 | 181 | list of visited directories (use %dhist to see it) and allows direct |
|
182 | 182 | switching to any of them. Type 'cd?' for more details. |
|
183 | 183 | |
|
184 | 184 | %pushd, %popd and %dirs are provided for directory stack handling. |
|
185 | 185 | |
|
186 | 186 | PROMPT CUSTOMIZATION |
|
187 | 187 | -------------------- |
|
188 | 188 | |
|
189 | 189 | The supplied ipythonrc-pysh profile comes with an example of a very |
|
190 | 190 | colored and detailed prompt, mainly to serve as an illustration. The |
|
191 | 191 | valid escape sequences, besides color names, are: |
|
192 | 192 | |
|
193 | 193 | \\# - Prompt number. |
|
194 | 194 | \\D - Dots, as many as there are digits in \\# (so they align). |
|
195 | 195 | \\w - Current working directory (cwd). |
|
196 | 196 | \\W - Basename of current working directory. |
|
197 | 197 | \\XN - Where N=0..5. N terms of the cwd, with $HOME written as ~. |
|
198 | 198 | \\YN - Where N=0..5. Like XN, but if ~ is term N+1 it's also shown. |
|
199 | 199 | \\u - Username. |
|
200 | 200 | \\H - Full hostname. |
|
201 | 201 | \\h - Hostname up to first '.' |
|
202 | 202 | \\$ - Root symbol ($ or #). |
|
203 | 203 | \\t - Current time, in H:M:S format. |
|
204 | 204 | \\v - IPython release version. |
|
205 | 205 | \\n - Newline. |
|
206 | 206 | \\r - Carriage return. |
|
207 | 207 | \\\\ - An explicitly escaped '\\'. |
|
208 | 208 | |
|
209 | 209 | You can configure your prompt colors using any ANSI color escape. Each |
|
210 | 210 | color escape sets the color for any subsequent text, until another escape |
|
211 | 211 | comes in and changes things. The valid color escapes are: |
|
212 | 212 | |
|
213 | 213 | \\C_Black |
|
214 | 214 | \\C_Blue |
|
215 | 215 | \\C_Brown |
|
216 | 216 | \\C_Cyan |
|
217 | 217 | \\C_DarkGray |
|
218 | 218 | \\C_Green |
|
219 | 219 | \\C_LightBlue |
|
220 | 220 | \\C_LightCyan |
|
221 | 221 | \\C_LightGray |
|
222 | 222 | \\C_LightGreen |
|
223 | 223 | \\C_LightPurple |
|
224 | 224 | \\C_LightRed |
|
225 | 225 | \\C_Purple |
|
226 | 226 | \\C_Red |
|
227 | 227 | \\C_White |
|
228 | 228 | \\C_Yellow |
|
229 | 229 | \\C_Normal - Stop coloring, defaults to your terminal settings. |
|
230 | 230 | """ |
|
231 | 231 | pass |
|
232 | 232 | |
|
233 | 233 | # Configure a few things. Much of this is fairly hackish, since IPython |
|
234 | 234 | # doesn't really expose a clean API for it. Be careful if you start making |
|
235 | 235 | # many modifications here. |
|
236 | 236 | |
|
237 | 237 | print """\ |
|
238 | 238 | Welcome to pysh, a set of extensions to IPython for shell usage. |
|
239 | 239 | help(pysh) -> help on the installed shell extensions and syntax. |
|
240 | 240 | """ |
|
241 | 241 | |
|
242 | 242 | # Set the 'cd' command to quiet mode, a more shell-like behavior |
|
243 | 243 | __IPYTHON__.default_option('cd','-q') |
|
244 | 244 | |
|
245 | 245 | # Load all of $PATH as aliases |
|
246 | 246 | if os.name == 'posix': |
|
247 | 247 | # %rehash is very fast, but it doesn't check for executability, it simply |
|
248 | 248 | # dumps everything in $PATH as an alias. Use rehashx if you want more |
|
249 | 249 | # checks. |
|
250 | 250 | __IPYTHON__.magic_rehash() |
|
251 | 251 | else: |
|
252 | 252 | # Windows users: the list of extensions considered executable is read from |
|
253 | 253 | # the environment variable 'pathext'. If this is undefined, IPython |
|
254 | 254 | # defaults to EXE, COM and BAT. |
|
255 | 255 | # %rehashx is the one which does extension analysis, at the cost of |
|
256 | 256 | # being much slower than %rehash. |
|
257 | 257 | __IPYTHON__.magic_rehashx() |
|
258 | 258 | |
|
259 | 259 | # Remove %sc,%sx if present as aliases |
|
260 | 260 | __IPYTHON__.magic_unalias('sc') |
|
261 | 261 | __IPYTHON__.magic_unalias('sx') |
|
262 | 262 | |
|
263 | 263 | # We need different criteria for line-splitting, so that aliases such as |
|
264 | 264 | # 'gnome-terminal' are interpreted as a single alias instead of variable |
|
265 | 265 | # 'gnome' minus variable 'terminal'. |
|
266 | 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 | 271 | # Namespace cleanup |
|
270 | 272 | del re |
@@ -1,199 +1,192 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """Word completion for GNU readline 2.0. |
|
3 | 3 | |
|
4 | 4 | --------------------------------------------------------------------------- |
|
5 | 5 | NOTE: This version is a re-implementation of rlcompleter with selectable |
|
6 | 6 | namespace. |
|
7 | 7 | |
|
8 | 8 | The problem with rlcompleter is that it's hardwired to work with |
|
9 | 9 | __main__.__dict__, and in some cases one may have 'sandboxed' namespaces. So |
|
10 | 10 | this class is a ripoff of rlcompleter, with the namespace to work in as an |
|
11 | 11 | optional parameter. |
|
12 | 12 | |
|
13 | 13 | This class can be used just like rlcompleter, but the Completer class now has |
|
14 | 14 | a constructor with the optional 'namespace' parameter. |
|
15 | 15 | |
|
16 | 16 | A patch has been submitted to Python@sourceforge for these changes to go in |
|
17 | 17 | the standard Python distribution. |
|
18 | 18 | |
|
19 | 19 | The patch went in for Python 2.3. Once IPython drops support for Python 2.2, |
|
20 | 20 | this file can be significantly reduced. |
|
21 | 21 | --------------------------------------------------------------------------- |
|
22 | 22 | |
|
23 | 23 | Original rlcompleter documentation: |
|
24 | 24 | |
|
25 | 25 | This requires the latest extension to the readline module (the |
|
26 | 26 | completes keywords, built-ins and globals in __main__; when completing |
|
27 | 27 | NAME.NAME..., it evaluates (!) the expression up to the last dot and |
|
28 | 28 | completes its attributes. |
|
29 | 29 | |
|
30 | 30 | It's very cool to do "import string" type "string.", hit the |
|
31 | 31 | completion key (twice), and see the list of names defined by the |
|
32 | 32 | string module! |
|
33 | 33 | |
|
34 | 34 | Tip: to use the tab key as the completion key, call |
|
35 | 35 | |
|
36 | 36 | readline.parse_and_bind("tab: complete") |
|
37 | 37 | |
|
38 | 38 | Notes: |
|
39 | 39 | |
|
40 | 40 | - Exceptions raised by the completer function are *ignored* (and |
|
41 | 41 | generally cause the completion to fail). This is a feature -- since |
|
42 | 42 | readline sets the tty device in raw (or cbreak) mode, printing a |
|
43 | 43 | traceback wouldn't work well without some complicated hoopla to save, |
|
44 | 44 | reset and restore the tty state. |
|
45 | 45 | |
|
46 | 46 | - The evaluation of the NAME.NAME... form may cause arbitrary |
|
47 | 47 | application defined code to be executed if an object with a |
|
48 | 48 | __getattr__ hook is found. Since it is the responsibility of the |
|
49 | 49 | application (or the user) to enable this feature, I consider this an |
|
50 | 50 | acceptable risk. More complicated expressions (e.g. function calls or |
|
51 | 51 | indexing operations) are *not* evaluated. |
|
52 | 52 | |
|
53 | 53 | - GNU readline is also used by the built-in functions input() and |
|
54 | 54 | raw_input(), and thus these also benefit/suffer from the completer |
|
55 | 55 | features. Clearly an interactive application can benefit by |
|
56 | 56 | specifying its own completer function and using raw_input() for all |
|
57 | 57 | its input. |
|
58 | 58 | |
|
59 | 59 | - When the original stdin is not a tty device, GNU readline is never |
|
60 | 60 | used, and this module (and the readline module) are silently inactive. |
|
61 | 61 | |
|
62 | 62 | """ |
|
63 | 63 | |
|
64 | 64 | #***************************************************************************** |
|
65 | 65 | # |
|
66 | 66 | # Since this file is essentially a minimally modified copy of the rlcompleter |
|
67 | 67 | # module which is part of the standard Python distribution, I assume that the |
|
68 | 68 | # proper procedure is to maintain its copyright as belonging to the Python |
|
69 | 69 | # Software Foundation: |
|
70 | 70 | # |
|
71 | 71 | # Copyright (C) 2001 Python Software Foundation, www.python.org |
|
72 | 72 | # |
|
73 | 73 | # Distributed under the terms of the Python Software Foundation license. |
|
74 | 74 | # |
|
75 | 75 | # Full text available at: |
|
76 | 76 | # |
|
77 | 77 | # http://www.python.org/2.1/license.html |
|
78 | 78 | # |
|
79 | 79 | #***************************************************************************** |
|
80 | 80 | |
|
81 | 81 | import readline |
|
82 | 82 | import __builtin__ |
|
83 | 83 | import __main__ |
|
84 | 84 | |
|
85 | 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 | 87 | class Completer: |
|
95 | 88 | def __init__(self, namespace = None): |
|
96 | 89 | """Create a new completer for the command line. |
|
97 | 90 | |
|
98 | 91 | Completer([namespace]) -> completer instance. |
|
99 | 92 | |
|
100 | 93 | If unspecified, the default namespace where completions are performed |
|
101 | 94 | is __main__ (technically, __main__.__dict__). Namespaces should be |
|
102 | 95 | given as dictionaries. |
|
103 | 96 | |
|
104 | 97 | Completer instances should be used as the completion mechanism of |
|
105 | 98 | readline via the set_completer() call: |
|
106 | 99 | |
|
107 | 100 | readline.set_completer(Completer(my_namespace).complete) |
|
108 | 101 | """ |
|
109 | 102 | |
|
110 | 103 | if namespace and type(namespace) != type({}): |
|
111 | 104 | raise TypeError,'namespace must be a dictionary' |
|
112 | 105 | |
|
113 | 106 | # Don't bind to namespace quite yet, but flag whether the user wants a |
|
114 | 107 | # specific namespace or to use __main__.__dict__. This will allow us |
|
115 | 108 | # to bind to __main__.__dict__ at completion time, not now. |
|
116 | 109 | if namespace is None: |
|
117 | 110 | self.use_main_ns = 1 |
|
118 | 111 | else: |
|
119 | 112 | self.use_main_ns = 0 |
|
120 | 113 | self.namespace = namespace |
|
121 | 114 | |
|
122 | 115 | def complete(self, text, state): |
|
123 | 116 | """Return the next possible completion for 'text'. |
|
124 | 117 | |
|
125 | 118 | This is called successively with state == 0, 1, 2, ... until it |
|
126 | 119 | returns None. The completion should begin with 'text'. |
|
127 | 120 | |
|
128 | 121 | """ |
|
129 | 122 | if self.use_main_ns: |
|
130 | 123 | self.namespace = __main__.__dict__ |
|
131 | 124 | |
|
132 | 125 | if state == 0: |
|
133 | 126 | if "." in text: |
|
134 | 127 | self.matches = self.attr_matches(text) |
|
135 | 128 | else: |
|
136 | 129 | self.matches = self.global_matches(text) |
|
137 | 130 | try: |
|
138 | 131 | return self.matches[state] |
|
139 | 132 | except IndexError: |
|
140 | 133 | return None |
|
141 | 134 | |
|
142 | 135 | def global_matches(self, text): |
|
143 | 136 | """Compute matches when text is a simple name. |
|
144 | 137 | |
|
145 | 138 | Return a list of all keywords, built-in functions and names currently |
|
146 | 139 | defined in self.namespace that match. |
|
147 | 140 | |
|
148 | 141 | """ |
|
149 | 142 | import keyword |
|
150 | 143 | matches = [] |
|
151 | 144 | n = len(text) |
|
152 | 145 | for list in [keyword.kwlist, |
|
153 | 146 | __builtin__.__dict__.keys(), |
|
154 | 147 | self.namespace.keys()]: |
|
155 | 148 | for word in list: |
|
156 | 149 | if word[:n] == text and word != "__builtins__": |
|
157 | 150 | matches.append(word) |
|
158 | 151 | return matches |
|
159 | 152 | |
|
160 | 153 | def attr_matches(self, text): |
|
161 | 154 | """Compute matches when text contains a dot. |
|
162 | 155 | |
|
163 | 156 | Assuming the text is of the form NAME.NAME....[NAME], and is |
|
164 | 157 | evaluatable in self.namespace, it will be evaluated and its attributes |
|
165 | 158 | (as revealed by dir()) are used as possible completions. (For class |
|
166 | 159 | instances, class members are are also considered.) |
|
167 | 160 | |
|
168 | 161 | WARNING: this can still invoke arbitrary C code, if an object |
|
169 | 162 | with a __getattr__ hook is evaluated. |
|
170 | 163 | |
|
171 | 164 | """ |
|
172 | 165 | import re |
|
173 | 166 | |
|
174 | 167 | # Another option, seems to work great. Catches things like ''.<tab> |
|
175 | 168 | m = re.match(r"(\S+(\.\w+)*)\.(\w*)$", text) |
|
176 | 169 | |
|
177 | 170 | if not m: |
|
178 | 171 | return [] |
|
179 | 172 | expr, attr = m.group(1, 3) |
|
180 | 173 | object = eval(expr, self.namespace) |
|
181 | 174 | words = [w for w in dir(object) if isinstance(w, basestring)] |
|
182 | 175 | if hasattr(object,'__class__'): |
|
183 | 176 | words.append('__class__') |
|
184 | 177 | words.extend(get_class_members(object.__class__)) |
|
185 | 178 | n = len(attr) |
|
186 | 179 | matches = [] |
|
187 | 180 | for word in words: |
|
188 | 181 | if word[:n] == attr and word != "__builtins__": |
|
189 | 182 | matches.append("%s.%s" % (expr, word)) |
|
190 | 183 | return matches |
|
191 | 184 | |
|
192 | 185 | def get_class_members(klass): |
|
193 | 186 | ret = dir(klass) |
|
194 | 187 | if hasattr(klass,'__bases__'): |
|
195 | 188 | for base in klass.__bases__: |
|
196 | 189 | ret.extend(get_class_members(base)) |
|
197 | 190 | return ret |
|
198 | 191 | |
|
199 | 192 | readline.set_completer(Completer().complete) |
@@ -1,253 +1,277 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """String interpolation for Python (by Ka-Ping Yee, 14 Feb 2000). |
|
3 | 3 | |
|
4 | 4 | This module lets you quickly and conveniently interpolate values into |
|
5 | 5 | strings (in the flavour of Perl or Tcl, but with less extraneous |
|
6 | 6 | punctuation). You get a bit more power than in the other languages, |
|
7 | 7 | because this module allows subscripting, slicing, function calls, |
|
8 | 8 | attribute lookup, or arbitrary expressions. Variables and expressions |
|
9 | 9 | are evaluated in the namespace of the caller. |
|
10 | 10 | |
|
11 | 11 | The itpl() function returns the result of interpolating a string, and |
|
12 | 12 | printpl() prints out an interpolated string. Here are some examples: |
|
13 | 13 | |
|
14 | 14 | from Itpl import printpl |
|
15 | 15 | printpl("Here is a $string.") |
|
16 | 16 | printpl("Here is a $module.member.") |
|
17 | 17 | printpl("Here is an $object.member.") |
|
18 | 18 | printpl("Here is a $functioncall(with, arguments).") |
|
19 | 19 | printpl("Here is an ${arbitrary + expression}.") |
|
20 | 20 | printpl("Here is an $array[3] member.") |
|
21 | 21 | printpl("Here is a $dictionary['member'].") |
|
22 | 22 | |
|
23 | 23 | The filter() function filters a file object so that output through it |
|
24 | 24 | is interpolated. This lets you produce the illusion that Python knows |
|
25 | 25 | how to do interpolation: |
|
26 | 26 | |
|
27 | 27 | import Itpl |
|
28 | 28 | sys.stdout = Itpl.filter() |
|
29 | 29 | f = "fancy" |
|
30 | 30 | print "Isn't this $f?" |
|
31 | 31 | print "Standard output has been replaced with a $sys.stdout object." |
|
32 | 32 | sys.stdout = Itpl.unfilter() |
|
33 | 33 | print "Okay, back $to $normal." |
|
34 | 34 | |
|
35 | 35 | Under the hood, the Itpl class represents a string that knows how to |
|
36 | 36 | interpolate values. An instance of the class parses the string once |
|
37 | 37 | upon initialization; the evaluation and substitution can then be done |
|
38 | 38 | each time the instance is evaluated with str(instance). For example: |
|
39 | 39 | |
|
40 | 40 | from Itpl import Itpl |
|
41 | 41 | s = Itpl("Here is $foo.") |
|
42 | 42 | foo = 5 |
|
43 | 43 | print str(s) |
|
44 | 44 | foo = "bar" |
|
45 | 45 | print str(s) |
|
46 | 46 | |
|
47 |
$Id: Itpl.py |
|
|
47 | $Id: Itpl.py 638 2005-07-18 03:01:41Z fperez $ | |
|
48 | 48 | """ # ' -> close an open quote for stupid emacs |
|
49 | 49 | |
|
50 | 50 | #***************************************************************************** |
|
51 | 51 | # |
|
52 | 52 | # Copyright (c) 2001 Ka-Ping Yee <ping@lfw.org> |
|
53 | 53 | # |
|
54 | 54 | # |
|
55 | 55 | # Published under the terms of the MIT license, hereby reproduced: |
|
56 | 56 | # |
|
57 | 57 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
|
58 | 58 | # of this software and associated documentation files (the "Software"), to |
|
59 | 59 | # deal in the Software without restriction, including without limitation the |
|
60 | 60 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|
61 | 61 | # sell copies of the Software, and to permit persons to whom the Software is |
|
62 | 62 | # furnished to do so, subject to the following conditions: |
|
63 | 63 | # |
|
64 | 64 | # The above copyright notice and this permission notice shall be included in |
|
65 | 65 | # all copies or substantial portions of the Software. |
|
66 | 66 | # |
|
67 | 67 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
68 | 68 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
69 | 69 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
70 | 70 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
71 | 71 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
72 | 72 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
|
73 | 73 | # IN THE SOFTWARE. |
|
74 | 74 | # |
|
75 | 75 | #***************************************************************************** |
|
76 | 76 | |
|
77 | 77 | __author__ = 'Ka-Ping Yee <ping@lfw.org>' |
|
78 | 78 | __license__ = 'MIT' |
|
79 | 79 | |
|
80 | 80 | import sys, string |
|
81 | 81 | from types import StringType |
|
82 | 82 | from tokenize import tokenprog |
|
83 | 83 | |
|
84 | 84 | class ItplError(ValueError): |
|
85 | 85 | def __init__(self, text, pos): |
|
86 | 86 | self.text = text |
|
87 | 87 | self.pos = pos |
|
88 | 88 | def __str__(self): |
|
89 | 89 | return "unfinished expression in %s at char %d" % ( |
|
90 | 90 | repr(self.text), self.pos) |
|
91 | 91 | |
|
92 | 92 | def matchorfail(text, pos): |
|
93 | 93 | match = tokenprog.match(text, pos) |
|
94 | 94 | if match is None: |
|
95 | 95 | raise ItplError(text, pos) |
|
96 | 96 | return match, match.end() |
|
97 | 97 | |
|
98 | 98 | class Itpl: |
|
99 | 99 | """Class representing a string with interpolation abilities. |
|
100 | 100 | |
|
101 | 101 | Upon creation, an instance works out what parts of the format |
|
102 | 102 | string are literal and what parts need to be evaluated. The |
|
103 | 103 | evaluation and substitution happens in the namespace of the |
|
104 | 104 | caller when str(instance) is called.""" |
|
105 | 105 | |
|
106 | def __init__(self, format): | |
|
107 |
"""The single argument to this constructor is a format |
|
|
106 | def __init__(self, format,codec='utf_8',encoding_errors='backslashreplace'): | |
|
107 | """The single mandatory argument to this constructor is a format | |
|
108 | string. | |
|
108 | 109 | |
|
109 | 110 | The format string is parsed according to the following rules: |
|
110 | 111 | |
|
111 | 112 | 1. A dollar sign and a name, possibly followed by any of: |
|
112 | 113 | - an open-paren, and anything up to the matching paren |
|
113 | 114 | - an open-bracket, and anything up to the matching bracket |
|
114 | 115 | - a period and a name |
|
115 | 116 | any number of times, is evaluated as a Python expression. |
|
116 | 117 | |
|
117 | 118 | 2. A dollar sign immediately followed by an open-brace, and |
|
118 | 119 | anything up to the matching close-brace, is evaluated as |
|
119 | 120 | a Python expression. |
|
120 | 121 | |
|
121 | 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 | 137 | raise TypeError, "needs string initializer" |
|
126 | 138 | self.format = format |
|
127 | ||
|
139 | self.codec = codec | |
|
140 | self.encoding_errors = encoding_errors | |
|
141 | ||
|
128 | 142 | namechars = "abcdefghijklmnopqrstuvwxyz" \ |
|
129 | 143 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"; |
|
130 | 144 | chunks = [] |
|
131 | 145 | pos = 0 |
|
132 | 146 | |
|
133 | 147 | while 1: |
|
134 | 148 | dollar = string.find(format, "$", pos) |
|
135 | 149 | if dollar < 0: break |
|
136 | 150 | nextchar = format[dollar+1] |
|
137 | 151 | |
|
138 | 152 | if nextchar == "{": |
|
139 | 153 | chunks.append((0, format[pos:dollar])) |
|
140 | 154 | pos, level = dollar+2, 1 |
|
141 | 155 | while level: |
|
142 | 156 | match, pos = matchorfail(format, pos) |
|
143 | 157 | tstart, tend = match.regs[3] |
|
144 | 158 | token = format[tstart:tend] |
|
145 | 159 | if token == "{": level = level+1 |
|
146 | 160 | elif token == "}": level = level-1 |
|
147 | 161 | chunks.append((1, format[dollar+2:pos-1])) |
|
148 | 162 | |
|
149 | 163 | elif nextchar in namechars: |
|
150 | 164 | chunks.append((0, format[pos:dollar])) |
|
151 | 165 | match, pos = matchorfail(format, dollar+1) |
|
152 | 166 | while pos < len(format): |
|
153 | 167 | if format[pos] == "." and \ |
|
154 | 168 | pos+1 < len(format) and format[pos+1] in namechars: |
|
155 | 169 | match, pos = matchorfail(format, pos+1) |
|
156 | 170 | elif format[pos] in "([": |
|
157 | 171 | pos, level = pos+1, 1 |
|
158 | 172 | while level: |
|
159 | 173 | match, pos = matchorfail(format, pos) |
|
160 | 174 | tstart, tend = match.regs[3] |
|
161 | 175 | token = format[tstart:tend] |
|
162 | 176 | if token[0] in "([": level = level+1 |
|
163 | 177 | elif token[0] in ")]": level = level-1 |
|
164 | 178 | else: break |
|
165 | 179 | chunks.append((1, format[dollar+1:pos])) |
|
166 | 180 | |
|
167 | 181 | else: |
|
168 | 182 | chunks.append((0, format[pos:dollar+1])) |
|
169 | 183 | pos = dollar + 1 + (nextchar == "$") |
|
170 | 184 | |
|
171 | 185 | if pos < len(format): chunks.append((0, format[pos:])) |
|
172 | 186 | self.chunks = chunks |
|
173 | 187 | |
|
174 | 188 | def __repr__(self): |
|
175 | 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 | 208 | def __str__(self): |
|
178 | 209 | """Evaluate and substitute the appropriate parts of the string.""" |
|
179 | 210 | |
|
180 | 211 | # We need to skip enough frames to get to the actual caller outside of |
|
181 | 212 | # Itpl. |
|
182 | 213 | frame = sys._getframe(1) |
|
183 | 214 | while frame.f_globals["__name__"] == __name__: frame = frame.f_back |
|
184 | 215 | loc, glob = frame.f_locals, frame.f_globals |
|
185 | 216 | |
|
186 | result = [] | |
|
187 | for live, chunk in self.chunks: | |
|
188 | if live: result.append(str(eval(chunk,glob,loc))) | |
|
189 | else: result.append(chunk) | |
|
190 | ||
|
191 | return ''.join(result) | |
|
192 | ||
|
217 | return self._str(glob,loc) | |
|
218 | ||
|
193 | 219 | class ItplNS(Itpl): |
|
194 | 220 | """Class representing a string with interpolation abilities. |
|
195 | 221 | |
|
196 | 222 | This inherits from Itpl, but at creation time a namespace is provided |
|
197 | 223 | where the evaluation will occur. The interpolation becomes a bit more |
|
198 | 224 | efficient, as no traceback needs to be extracte. It also allows the |
|
199 | 225 | caller to supply a different namespace for the interpolation to occur than |
|
200 | 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 | 230 | """ItplNS(format,globals[,locals]) -> interpolating string instance. |
|
204 | 231 | |
|
205 | 232 | This constructor, besides a format string, takes a globals dictionary |
|
206 | 233 | and optionally a locals (which defaults to globals if not provided). |
|
207 | 234 | |
|
208 | 235 | For further details, see the Itpl constructor.""" |
|
209 | 236 | |
|
210 | 237 | if locals is None: |
|
211 | 238 | locals = globals |
|
212 | 239 | self.globals = globals |
|
213 | 240 | self.locals = locals |
|
214 | Itpl.__init__(self,format) | |
|
241 | Itpl.__init__(self,format,codec,encoding_errors) | |
|
215 | 242 | |
|
216 | 243 | def __str__(self): |
|
217 | 244 | """Evaluate and substitute the appropriate parts of the string.""" |
|
218 | glob = self.globals | |
|
219 | loc = self.locals | |
|
220 | result = [] | |
|
221 | for live, chunk in self.chunks: | |
|
222 | if live: result.append(str(eval(chunk,glob,loc))) | |
|
223 | else: result.append(chunk) | |
|
224 | return ''.join(result) | |
|
245 | return self._str(self.globals,self.locals) | |
|
246 | ||
|
247 | def __repr__(self): | |
|
248 | return "<ItplNS %s >" % repr(self.format) | |
|
225 | 249 | |
|
226 | 250 | # utilities for fast printing |
|
227 | 251 | def itpl(text): return str(Itpl(text)) |
|
228 | 252 | def printpl(text): print itpl(text) |
|
229 | 253 | # versions with namespace |
|
230 | 254 | def itplns(text,globals,locals=None): return str(ItplNS(text,globals,locals)) |
|
231 | 255 | def printplns(text,globals,locals=None): print itplns(text,globals,locals) |
|
232 | 256 | |
|
233 | 257 | class ItplFile: |
|
234 | 258 | """A file object that filters each write() through an interpolator.""" |
|
235 | 259 | def __init__(self, file): self.file = file |
|
236 | 260 | def __repr__(self): return "<interpolated " + repr(self.file) + ">" |
|
237 | 261 | def __getattr__(self, attr): return getattr(self.file, attr) |
|
238 | 262 | def write(self, text): self.file.write(str(Itpl(text))) |
|
239 | 263 | |
|
240 | 264 | def filter(file=sys.stdout): |
|
241 | 265 | """Return an ItplFile that filters writes to the given file object. |
|
242 | 266 | |
|
243 | 267 | 'file = filter(file)' replaces 'file' with a filtered object that |
|
244 | 268 | has a write() method. When called with no argument, this creates |
|
245 | 269 | a filter to sys.stdout.""" |
|
246 | 270 | return ItplFile(file) |
|
247 | 271 | |
|
248 | 272 | def unfilter(ifile=None): |
|
249 | 273 | """Return the original file that corresponds to the given ItplFile. |
|
250 | 274 | |
|
251 | 275 | 'file = unfilter(file)' undoes the effect of 'file = filter(file)'. |
|
252 | 276 | 'sys.stdout = unfilter()' undoes the effect of 'sys.stdout = filter()'.""" |
|
253 | 277 | return ifile and ifile.file or sys.stdout.file |
@@ -1,574 +1,572 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """ |
|
3 | 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 | 8 | # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu> |
|
9 | 9 | # |
|
10 | 10 | # Distributed under the terms of the BSD License. The full license is in |
|
11 | 11 | # the file COPYING, distributed as part of this software. |
|
12 | 12 | #***************************************************************************** |
|
13 | 13 | |
|
14 | 14 | from IPython import Release |
|
15 | 15 | __author__ = '%s <%s>' % Release.authors['Fernando'] |
|
16 | 16 | __license__ = Release.license |
|
17 | 17 | __version__ = Release.version |
|
18 | 18 | |
|
19 | 19 | #**************************************************************************** |
|
20 | 20 | # Required modules |
|
21 | 21 | import __builtin__ |
|
22 | 22 | import os,sys,socket |
|
23 | 23 | import time |
|
24 | 24 | from pprint import pprint,pformat |
|
25 | 25 | |
|
26 | 26 | # IPython's own |
|
27 | 27 | from IPython.genutils import * |
|
28 | 28 | from IPython.Struct import Struct |
|
29 | 29 | from IPython.Magic import Macro |
|
30 | 30 | from IPython.Itpl import ItplNS |
|
31 | 31 | from IPython import ColorANSI |
|
32 | 32 | |
|
33 | 33 | #**************************************************************************** |
|
34 | 34 | #Color schemes for Prompts. |
|
35 | 35 | |
|
36 | 36 | PromptColors = ColorANSI.ColorSchemeTable() |
|
37 | 37 | InputColors = ColorANSI.InputTermColors # just a shorthand |
|
38 | 38 | Colors = ColorANSI.TermColors # just a shorthand |
|
39 | 39 | |
|
40 | 40 | PromptColors.add_scheme(ColorANSI.ColorScheme( |
|
41 | 41 | 'NoColor', |
|
42 | 42 | in_prompt = InputColors.NoColor, # Input prompt |
|
43 | 43 | in_number = InputColors.NoColor, # Input prompt number |
|
44 | 44 | in_prompt2 = InputColors.NoColor, # Continuation prompt |
|
45 | 45 | in_normal = InputColors.NoColor, # color off (usu. Colors.Normal) |
|
46 | 46 | |
|
47 | 47 | out_prompt = Colors.NoColor, # Output prompt |
|
48 | 48 | out_number = Colors.NoColor, # Output prompt number |
|
49 | 49 | |
|
50 | 50 | normal = Colors.NoColor # color off (usu. Colors.Normal) |
|
51 | 51 | )) |
|
52 | 52 | # make some schemes as instances so we can copy them for modification easily: |
|
53 | 53 | __PColLinux = ColorANSI.ColorScheme( |
|
54 | 54 | 'Linux', |
|
55 | 55 | in_prompt = InputColors.Green, |
|
56 | 56 | in_number = InputColors.LightGreen, |
|
57 | 57 | in_prompt2 = InputColors.Green, |
|
58 | 58 | in_normal = InputColors.Normal, # color off (usu. Colors.Normal) |
|
59 | 59 | |
|
60 | 60 | out_prompt = Colors.Red, |
|
61 | 61 | out_number = Colors.LightRed, |
|
62 | 62 | |
|
63 | 63 | normal = Colors.Normal |
|
64 | 64 | ) |
|
65 | 65 | # Don't forget to enter it into the table! |
|
66 | 66 | PromptColors.add_scheme(__PColLinux) |
|
67 | 67 | # Slightly modified Linux for light backgrounds |
|
68 | 68 | __PColLightBG = ColorANSI.ColorScheme('LightBG',**__PColLinux.colors.dict().copy()) |
|
69 | 69 | |
|
70 | 70 | __PColLightBG.colors.update( |
|
71 | 71 | in_prompt = InputColors.Blue, |
|
72 | 72 | in_number = InputColors.LightBlue, |
|
73 | 73 | in_prompt2 = InputColors.Blue |
|
74 | 74 | ) |
|
75 | 75 | PromptColors.add_scheme(__PColLightBG) |
|
76 | 76 | |
|
77 | 77 | del Colors,InputColors |
|
78 | 78 | |
|
79 | 79 | #----------------------------------------------------------------------------- |
|
80 | 80 | def multiple_replace(dict, text): |
|
81 | 81 | """ Replace in 'text' all occurences of any key in the given |
|
82 | 82 | dictionary by its corresponding value. Returns the new string.""" |
|
83 | 83 | |
|
84 | 84 | # Function by Xavier Defrang, originally found at: |
|
85 | 85 | # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81330 |
|
86 | 86 | |
|
87 | 87 | # Create a regular expression from the dictionary keys |
|
88 | 88 | regex = re.compile("(%s)" % "|".join(map(re.escape, dict.keys()))) |
|
89 | 89 | # For each match, look-up corresponding value in dictionary |
|
90 | 90 | return regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], text) |
|
91 | 91 | |
|
92 | 92 | #----------------------------------------------------------------------------- |
|
93 | 93 | # Special characters that can be used in prompt templates, mainly bash-like |
|
94 | 94 | |
|
95 | 95 | # If $HOME isn't defined (Windows), make it an absurd string so that it can |
|
96 | 96 | # never be expanded out into '~'. Basically anything which can never be a |
|
97 | 97 | # reasonable directory name will do, we just want the $HOME -> '~' operation |
|
98 | 98 | # to become a no-op. We pre-compute $HOME here so it's not done on every |
|
99 | 99 | # prompt call. |
|
100 | 100 | |
|
101 | 101 | # FIXME: |
|
102 | 102 | |
|
103 | 103 | # - This should be turned into a class which does proper namespace management, |
|
104 | 104 | # since the prompt specials need to be evaluated in a certain namespace. |
|
105 | 105 | # Currently it's just globals, which need to be managed manually by code |
|
106 | 106 | # below. |
|
107 | 107 | |
|
108 | 108 | # - I also need to split up the color schemes from the prompt specials |
|
109 | 109 | # somehow. I don't have a clean design for that quite yet. |
|
110 | 110 | |
|
111 | 111 | HOME = os.environ.get("HOME","//////:::::ZZZZZ,,,~~~") |
|
112 | 112 | |
|
113 | 113 | # We precompute a few more strings here for the prompt_specials, which are |
|
114 | 114 | # fixed once ipython starts. This reduces the runtime overhead of computing |
|
115 | 115 | # prompt strings. |
|
116 | 116 | USER = os.environ.get("USER") |
|
117 | 117 | HOSTNAME = socket.gethostname() |
|
118 | 118 | HOSTNAME_SHORT = HOSTNAME.split(".")[0] |
|
119 | 119 | ROOT_SYMBOL = "$#"[os.name=='nt' or os.getuid()==0] |
|
120 | 120 | |
|
121 | 121 | prompt_specials_color = { |
|
122 | 122 | # Prompt/history count |
|
123 | 123 | '%n' : '${self.col_num}' '${self.cache.prompt_count}' '${self.col_p}', |
|
124 | 124 | '\\#': '${self.col_num}' '${self.cache.prompt_count}' '${self.col_p}', |
|
125 | 125 | # Prompt/history count, with the actual digits replaced by dots. Used |
|
126 | 126 | # mainly in continuation prompts (prompt_in2) |
|
127 | 127 | '\\D': '${"."*len(str(self.cache.prompt_count))}', |
|
128 | 128 | # Current working directory |
|
129 | 129 | '\\w': '${os.getcwd()}', |
|
130 | 130 | # Current time |
|
131 | 131 | '\\t' : '${time.strftime("%H:%M:%S")}', |
|
132 | 132 | # Basename of current working directory. |
|
133 | 133 | # (use os.sep to make this portable across OSes) |
|
134 | 134 | '\\W' : '${os.getcwd().split("%s")[-1]}' % os.sep, |
|
135 | 135 | # These X<N> are an extension to the normal bash prompts. They return |
|
136 | 136 | # N terms of the path, after replacing $HOME with '~' |
|
137 | 137 | '\\X0': '${os.getcwd().replace("%s","~")}' % HOME, |
|
138 | 138 | '\\X1': '${self.cwd_filt(1)}', |
|
139 | 139 | '\\X2': '${self.cwd_filt(2)}', |
|
140 | 140 | '\\X3': '${self.cwd_filt(3)}', |
|
141 | 141 | '\\X4': '${self.cwd_filt(4)}', |
|
142 | 142 | '\\X5': '${self.cwd_filt(5)}', |
|
143 | 143 | # Y<N> are similar to X<N>, but they show '~' if it's the directory |
|
144 | 144 | # N+1 in the list. Somewhat like %cN in tcsh. |
|
145 | 145 | '\\Y0': '${self.cwd_filt2(0)}', |
|
146 | 146 | '\\Y1': '${self.cwd_filt2(1)}', |
|
147 | 147 | '\\Y2': '${self.cwd_filt2(2)}', |
|
148 | 148 | '\\Y3': '${self.cwd_filt2(3)}', |
|
149 | 149 | '\\Y4': '${self.cwd_filt2(4)}', |
|
150 | 150 | '\\Y5': '${self.cwd_filt2(5)}', |
|
151 | 151 | # Hostname up to first . |
|
152 | 152 | '\\h': HOSTNAME_SHORT, |
|
153 | 153 | # Full hostname |
|
154 | 154 | '\\H': HOSTNAME, |
|
155 | 155 | # Username of current user |
|
156 | 156 | '\\u': USER, |
|
157 | 157 | # Escaped '\' |
|
158 | 158 | '\\\\': '\\', |
|
159 | 159 | # Newline |
|
160 | 160 | '\\n': '\n', |
|
161 | 161 | # Carriage return |
|
162 | 162 | '\\r': '\r', |
|
163 | 163 | # Release version |
|
164 | 164 | '\\v': __version__, |
|
165 | 165 | # Root symbol ($ or #) |
|
166 | 166 | '\\$': ROOT_SYMBOL, |
|
167 | 167 | } |
|
168 | 168 | |
|
169 | 169 | # A copy of the prompt_specials dictionary but with all color escapes removed, |
|
170 | 170 | # so we can correctly compute the prompt length for the auto_rewrite method. |
|
171 | 171 | prompt_specials_nocolor = prompt_specials_color.copy() |
|
172 | 172 | prompt_specials_nocolor['%n'] = '${self.cache.prompt_count}' |
|
173 | 173 | prompt_specials_nocolor['\\#'] = '${self.cache.prompt_count}' |
|
174 | 174 | |
|
175 | 175 | # Add in all the InputTermColors color escapes as valid prompt characters. |
|
176 | 176 | # They all get added as \\C_COLORNAME, so that we don't have any conflicts |
|
177 | 177 | # with a color name which may begin with a letter used by any other of the |
|
178 | 178 | # allowed specials. This of course means that \\C will never be allowed for |
|
179 | 179 | # anything else. |
|
180 | 180 | input_colors = ColorANSI.InputTermColors |
|
181 | 181 | for _color in dir(input_colors): |
|
182 | 182 | if _color[0] != '_': |
|
183 | 183 | c_name = '\\C_'+_color |
|
184 | 184 | prompt_specials_color[c_name] = getattr(input_colors,_color) |
|
185 | 185 | prompt_specials_nocolor[c_name] = '' |
|
186 | 186 | |
|
187 | 187 | # we default to no color for safety. Note that prompt_specials is a global |
|
188 | 188 | # variable used by all prompt objects. |
|
189 | 189 | prompt_specials = prompt_specials_nocolor |
|
190 | 190 | |
|
191 | 191 | #----------------------------------------------------------------------------- |
|
192 | 192 | def str_safe(arg): |
|
193 | 193 | """Convert to a string, without ever raising an exception. |
|
194 | 194 | |
|
195 | 195 | If str(arg) fails, <ERROR: ... > is returned, where ... is the exception |
|
196 | 196 | error message.""" |
|
197 | ||
|
197 | ||
|
198 | 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 | 207 | except Exception,msg: |
|
201 |
|
|
|
208 | out = '<ERROR: %s>' % msg | |
|
209 | return out | |
|
202 | 210 | |
|
203 | 211 | class BasePrompt: |
|
204 | 212 | """Interactive prompt similar to Mathematica's.""" |
|
205 | 213 | def __init__(self,cache,sep,prompt,pad_left=False): |
|
206 | 214 | |
|
207 | 215 | # Hack: we access information about the primary prompt through the |
|
208 | 216 | # cache argument. We need this, because we want the secondary prompt |
|
209 | 217 | # to be aligned with the primary one. Color table info is also shared |
|
210 | 218 | # by all prompt classes through the cache. Nice OO spaghetti code! |
|
211 | 219 | self.cache = cache |
|
212 | 220 | self.sep = sep |
|
213 | 221 | |
|
214 | 222 | # regexp to count the number of spaces at the end of a prompt |
|
215 | 223 | # expression, useful for prompt auto-rewriting |
|
216 | 224 | self.rspace = re.compile(r'(\s*)$') |
|
217 | 225 | # Flag to left-pad prompt strings to match the length of the primary |
|
218 | 226 | # prompt |
|
219 | 227 | self.pad_left = pad_left |
|
220 | 228 | # Set template to create each actual prompt (where numbers change) |
|
221 | 229 | self.p_template = prompt |
|
222 | 230 | self.set_p_str() |
|
223 | 231 | |
|
224 | 232 | def set_p_str(self): |
|
225 | 233 | """ Set the interpolating prompt strings. |
|
226 | 234 | |
|
227 | 235 | This must be called every time the color settings change, because the |
|
228 | 236 | prompt_specials global may have changed.""" |
|
229 | 237 | |
|
230 | 238 | import os,time # needed in locals for prompt string handling |
|
231 | 239 | loc = locals() |
|
232 | 240 | self.p_str = ItplNS('%s%s%s' % |
|
233 | 241 | ('${self.sep}${self.col_p}', |
|
234 | 242 | multiple_replace(prompt_specials, self.p_template), |
|
235 | 243 | '${self.col_norm}'),self.cache.user_ns,loc) |
|
236 | 244 | |
|
237 | 245 | self.p_str_nocolor = ItplNS(multiple_replace(prompt_specials_nocolor, |
|
238 | 246 | self.p_template), |
|
239 | 247 | self.cache.user_ns,loc) |
|
240 | 248 | |
|
241 | 249 | def write(self,msg): # dbg |
|
242 | 250 | sys.stdout.write(msg) |
|
243 | 251 | return '' |
|
244 | 252 | |
|
245 | 253 | def __str__(self): |
|
246 | 254 | """Return a string form of the prompt. |
|
247 | 255 | |
|
248 | 256 | This for is useful for continuation and output prompts, since it is |
|
249 | 257 | left-padded to match lengths with the primary one (if the |
|
250 | 258 | self.pad_left attribute is set).""" |
|
251 | 259 | |
|
252 | 260 | out_str = str_safe(self.p_str) |
|
253 | 261 | if self.pad_left: |
|
254 | 262 | # We must find the amount of padding required to match lengths, |
|
255 | 263 | # taking the color escapes (which are invisible on-screen) into |
|
256 | 264 | # account. |
|
257 | 265 | esc_pad = len(out_str) - len(str_safe(self.p_str_nocolor)) |
|
258 | 266 | format = '%%%ss' % (len(str(self.cache.last_prompt))+esc_pad) |
|
259 | 267 | return format % out_str |
|
260 | 268 | else: |
|
261 | 269 | return out_str |
|
262 | 270 | |
|
263 | 271 | # these path filters are put in as methods so that we can control the |
|
264 | 272 | # namespace where the prompt strings get evaluated |
|
265 | 273 | def cwd_filt(self,depth): |
|
266 | 274 | """Return the last depth elements of the current working directory. |
|
267 | 275 | |
|
268 | 276 | $HOME is always replaced with '~'. |
|
269 | 277 | If depth==0, the full path is returned.""" |
|
270 | 278 | |
|
271 | 279 | cwd = os.getcwd().replace(HOME,"~") |
|
272 | 280 | out = os.sep.join(cwd.split(os.sep)[-depth:]) |
|
273 | 281 | if out: |
|
274 | 282 | return out |
|
275 | 283 | else: |
|
276 | 284 | return os.sep |
|
277 | 285 | |
|
278 | 286 | def cwd_filt2(self,depth): |
|
279 | 287 | """Return the last depth elements of the current working directory. |
|
280 | 288 | |
|
281 | 289 | $HOME is always replaced with '~'. |
|
282 | 290 | If depth==0, the full path is returned.""" |
|
283 | 291 | |
|
284 | 292 | cwd = os.getcwd().replace(HOME,"~").split(os.sep) |
|
285 | 293 | if '~' in cwd and len(cwd) == depth+1: |
|
286 | 294 | depth += 1 |
|
287 | 295 | out = os.sep.join(cwd[-depth:]) |
|
288 | 296 | if out: |
|
289 | 297 | return out |
|
290 | 298 | else: |
|
291 | 299 | return os.sep |
|
292 | 300 | |
|
293 | 301 | class Prompt1(BasePrompt): |
|
294 | 302 | """Input interactive prompt similar to Mathematica's.""" |
|
295 | 303 | |
|
296 | 304 | def __init__(self,cache,sep='\n',prompt='In [\\#]: ',pad_left=True): |
|
297 | 305 | BasePrompt.__init__(self,cache,sep,prompt,pad_left) |
|
298 | 306 | |
|
299 | 307 | def set_colors(self): |
|
300 | 308 | self.set_p_str() |
|
301 | 309 | Colors = self.cache.color_table.active_colors # shorthand |
|
302 | 310 | self.col_p = Colors.in_prompt |
|
303 | 311 | self.col_num = Colors.in_number |
|
304 | 312 | self.col_norm = Colors.in_normal |
|
305 | 313 | # We need a non-input version of these escapes for the '--->' |
|
306 | 314 | # auto-call prompts used in the auto_rewrite() method. |
|
307 | 315 | self.col_p_ni = self.col_p.replace('\001','').replace('\002','') |
|
308 | 316 | self.col_norm_ni = Colors.normal |
|
309 | 317 | |
|
310 | 318 | def __str__(self): |
|
311 | 319 | self.cache.prompt_count += 1 |
|
312 | 320 | self.cache.last_prompt = str_safe(self.p_str_nocolor).split('\n')[-1] |
|
313 | 321 | return str_safe(self.p_str) |
|
314 | 322 | |
|
315 | 323 | def auto_rewrite(self): |
|
316 | 324 | """Print a string of the form '--->' which lines up with the previous |
|
317 | 325 | input string. Useful for systems which re-write the user input when |
|
318 | 326 | handling automatically special syntaxes.""" |
|
319 | 327 | |
|
320 | 328 | curr = str(self.cache.last_prompt) |
|
321 | 329 | nrspaces = len(self.rspace.search(curr).group()) |
|
322 | 330 | return '%s%s>%s%s' % (self.col_p_ni,'-'*(len(curr)-nrspaces-1), |
|
323 | 331 | ' '*nrspaces,self.col_norm_ni) |
|
324 | 332 | |
|
325 | 333 | class PromptOut(BasePrompt): |
|
326 | 334 | """Output interactive prompt similar to Mathematica's.""" |
|
327 | 335 | |
|
328 | 336 | def __init__(self,cache,sep='',prompt='Out[\\#]: ',pad_left=True): |
|
329 | 337 | BasePrompt.__init__(self,cache,sep,prompt,pad_left) |
|
330 | 338 | if not self.p_template: |
|
331 | 339 | self.__str__ = lambda: '' |
|
332 | 340 | |
|
333 | 341 | def set_colors(self): |
|
334 | 342 | self.set_p_str() |
|
335 | 343 | Colors = self.cache.color_table.active_colors # shorthand |
|
336 | 344 | self.col_p = Colors.out_prompt |
|
337 | 345 | self.col_num = Colors.out_number |
|
338 | 346 | self.col_norm = Colors.normal |
|
339 | 347 | |
|
340 | 348 | class Prompt2(BasePrompt): |
|
341 | 349 | """Interactive continuation prompt.""" |
|
342 | 350 | |
|
343 | 351 | def __init__(self,cache,prompt=' .\\D.: ',pad_left=True): |
|
344 | 352 | self.cache = cache |
|
345 | 353 | self.p_template = prompt |
|
346 | 354 | self.pad_left = pad_left |
|
347 | 355 | self.set_p_str() |
|
348 | 356 | |
|
349 | 357 | def set_p_str(self): |
|
350 | 358 | import os,time # needed in locals for prompt string handling |
|
351 | 359 | loc = locals() |
|
352 | 360 | self.p_str = ItplNS('%s%s%s' % |
|
353 | 361 | ('${self.col_p2}', |
|
354 | 362 | multiple_replace(prompt_specials, self.p_template), |
|
355 | 363 | '$self.col_norm'), |
|
356 | 364 | self.cache.user_ns,loc) |
|
357 | 365 | self.p_str_nocolor = ItplNS(multiple_replace(prompt_specials_nocolor, |
|
358 | 366 | self.p_template), |
|
359 | 367 | self.cache.user_ns,loc) |
|
360 | 368 | |
|
361 | 369 | def set_colors(self): |
|
362 | 370 | self.set_p_str() |
|
363 | 371 | Colors = self.cache.color_table.active_colors |
|
364 | 372 | self.col_p2 = Colors.in_prompt2 |
|
365 | 373 | self.col_norm = Colors.in_normal |
|
366 | 374 | # FIXME (2004-06-16) HACK: prevent crashes for users who haven't |
|
367 | 375 | # updated their prompt_in2 definitions. Remove eventually. |
|
368 | 376 | self.col_p = Colors.out_prompt |
|
369 | 377 | self.col_num = Colors.out_number |
|
370 | 378 | |
|
371 | 379 | #----------------------------------------------------------------------------- |
|
372 | 380 | class CachedOutput: |
|
373 | 381 | """Class for printing output from calculations while keeping a cache of |
|
374 | 382 | reults. It dynamically creates global variables prefixed with _ which |
|
375 | 383 | contain these results. |
|
376 | 384 | |
|
377 | 385 | Meant to be used as a sys.displayhook replacement, providing numbered |
|
378 | 386 | prompts and cache services. |
|
379 | 387 | |
|
380 | 388 | Initialize with initial and final values for cache counter (this defines |
|
381 | 389 | the maximum size of the cache.""" |
|
382 | 390 | |
|
383 | 391 | def __init__(self,cache_size,Pprint,colors='NoColor',input_sep='\n', |
|
384 | 392 | output_sep='\n',output_sep2='',user_ns={}, |
|
385 | 393 | ps1 = None, ps2 = None,ps_out = None, |
|
386 | 394 | input_hist = None,pad_left=True): |
|
387 | 395 | |
|
388 | 396 | cache_size_min = 20 |
|
389 | 397 | if cache_size <= 0: |
|
390 | 398 | self.do_full_cache = 0 |
|
391 | 399 | cache_size = 0 |
|
392 | 400 | elif cache_size < cache_size_min: |
|
393 | 401 | self.do_full_cache = 0 |
|
394 | 402 | cache_size = 0 |
|
395 | 403 | warn('caching was disabled (min value for cache size is %s).' % |
|
396 | 404 | cache_size_min,level=3) |
|
397 | 405 | else: |
|
398 | 406 | self.do_full_cache = 1 |
|
399 | 407 | |
|
400 | 408 | self.cache_size = cache_size |
|
401 | 409 | self.input_sep = input_sep |
|
402 | 410 | |
|
403 | 411 | # we need a reference to the user-level namespace |
|
404 | 412 | self.user_ns = user_ns |
|
405 | 413 | # and to the user's input |
|
406 | 414 | self.input_hist = input_hist |
|
407 | 415 | |
|
408 | 416 | # Set input prompt strings and colors |
|
409 | 417 | if cache_size == 0: |
|
410 | 418 | if ps1.find('%n') > -1 or ps1.find('\\#') > -1: ps1 = '>>> ' |
|
411 | 419 | if ps2.find('%n') > -1 or ps2.find('\\#') > -1: ps2 = '... ' |
|
412 | 420 | self.ps1_str = self._set_prompt_str(ps1,'In [\\#]: ','>>> ') |
|
413 | 421 | self.ps2_str = self._set_prompt_str(ps2,' .\\D.: ','... ') |
|
414 | 422 | self.ps_out_str = self._set_prompt_str(ps_out,'Out[\\#]: ','') |
|
415 | 423 | |
|
424 | self.color_table = PromptColors | |
|
416 | 425 | self.prompt1 = Prompt1(self,sep=input_sep,prompt=self.ps1_str, |
|
417 | 426 | pad_left=pad_left) |
|
418 | 427 | self.prompt2 = Prompt2(self,prompt=self.ps2_str,pad_left=pad_left) |
|
419 | 428 | self.prompt_out = PromptOut(self,sep='',prompt=self.ps_out_str, |
|
420 | 429 | pad_left=pad_left) |
|
421 | self.color_table = PromptColors | |
|
422 | 430 | self.set_colors(colors) |
|
423 | 431 | |
|
424 | 432 | # other more normal stuff |
|
425 | 433 | # b/c each call to the In[] prompt raises it by 1, even the first. |
|
426 | 434 | self.prompt_count = 0 |
|
427 | 435 | self.cache_count = 1 |
|
428 | 436 | # Store the last prompt string each time, we need it for aligning |
|
429 | 437 | # continuation and auto-rewrite prompts |
|
430 | 438 | self.last_prompt = '' |
|
431 | 439 | self.entries = [None] # output counter starts at 1 for the user |
|
432 | 440 | self.Pprint = Pprint |
|
433 | 441 | self.output_sep = output_sep |
|
434 | 442 | self.output_sep2 = output_sep2 |
|
435 | 443 | self._,self.__,self.___ = '','','' |
|
436 | 444 | self.pprint_types = map(type,[(),[],{}]) |
|
437 | 445 | |
|
438 | 446 | # these are deliberately global: |
|
439 | 447 | to_user_ns = {'_':self._,'__':self.__,'___':self.___} |
|
440 | 448 | self.user_ns.update(to_user_ns) |
|
441 | 449 | |
|
442 | 450 | def _set_prompt_str(self,p_str,cache_def,no_cache_def): |
|
443 | 451 | if p_str is None: |
|
444 | 452 | if self.do_full_cache: |
|
445 | 453 | return cache_def |
|
446 | 454 | else: |
|
447 | 455 | return no_cache_def |
|
448 | 456 | else: |
|
449 | 457 | return p_str |
|
450 | 458 | |
|
451 | 459 | def set_colors(self,colors): |
|
452 | 460 | """Set the active color scheme and configure colors for the three |
|
453 | 461 | prompt subsystems.""" |
|
454 | 462 | |
|
455 | 463 | # FIXME: the prompt_specials global should be gobbled inside this |
|
456 | 464 | # class instead. Do it when cleaning up the whole 3-prompt system. |
|
457 | 465 | global prompt_specials |
|
458 | 466 | if colors.lower()=='nocolor': |
|
459 | 467 | prompt_specials = prompt_specials_nocolor |
|
460 | 468 | else: |
|
461 | 469 | prompt_specials = prompt_specials_color |
|
462 | 470 | |
|
463 | 471 | self.color_table.set_active_scheme(colors) |
|
464 | 472 | self.prompt1.set_colors() |
|
465 | 473 | self.prompt2.set_colors() |
|
466 | 474 | self.prompt_out.set_colors() |
|
467 | 475 | |
|
468 | 476 | def __call__(self,arg=None): |
|
469 | 477 | """Printing with history cache management. |
|
470 | 478 | |
|
471 | 479 | This is invoked everytime the interpreter needs to print, and is |
|
472 | 480 | activated by setting the variable sys.displayhook to it.""" |
|
473 | 481 | |
|
474 | 482 | # If something injected a '_' variable in __builtin__, delete |
|
475 | 483 | # ipython's automatic one so we don't clobber that. gettext() in |
|
476 | 484 | # particular uses _, so we need to stay away from it. |
|
477 | 485 | if '_' in __builtin__.__dict__: |
|
478 | 486 | try: |
|
479 | 487 | del self.user_ns['_'] |
|
480 | 488 | except KeyError: |
|
481 | 489 | pass |
|
482 | 490 | if arg is not None: |
|
491 | cout_write = Term.cout.write # fast lookup | |
|
483 | 492 | # first handle the cache and counters |
|
484 | 493 | self.update(arg) |
|
485 | 494 | # do not print output if input ends in ';' |
|
486 | 495 | if self.input_hist[self.prompt_count].endswith(';\n'): |
|
487 | 496 | return |
|
488 | 497 | # don't use print, puts an extra space |
|
489 |
|
|
|
498 | cout_write(self.output_sep) | |
|
490 | 499 | if self.do_full_cache: |
|
491 |
|
|
|
500 | cout_write(str(self.prompt_out)) | |
|
492 | 501 | |
|
493 | 502 | if isinstance(arg,Macro): |
|
494 | 503 | print 'Executing Macro...' |
|
495 | 504 | # in case the macro takes a long time to execute |
|
496 | 505 | Term.cout.flush() |
|
497 | 506 | exec arg.value in self.user_ns |
|
498 | 507 | return None |
|
499 | 508 | |
|
500 | 509 | # and now call a possibly user-defined print mechanism |
|
501 | 510 | self.display(arg) |
|
502 |
|
|
|
511 | cout_write(self.output_sep2) | |
|
503 | 512 | Term.cout.flush() |
|
504 | 513 | |
|
505 | 514 | def _display(self,arg): |
|
506 | 515 | """Default printer method, uses pprint. |
|
507 | 516 | |
|
508 | 517 | This can be over-ridden by the users to implement special formatting |
|
509 | 518 | of certain types of output.""" |
|
510 | 519 | |
|
511 | 520 | if self.Pprint: |
|
512 | # The following is an UGLY kludge, b/c python fails to properly | |
|
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) | |
|
521 | out = pformat(arg) | |
|
524 | 522 | if '\n' in out: |
|
525 | 523 | # So that multi-line strings line up with the left column of |
|
526 | 524 | # the screen, instead of having the output prompt mess up |
|
527 | 525 | # their first line. |
|
528 | 526 | Term.cout.write('\n') |
|
529 | 527 | print >>Term.cout, out |
|
530 | 528 | else: |
|
531 | 529 | print >>Term.cout, arg |
|
532 | 530 | |
|
533 | 531 | # Assign the default display method: |
|
534 | 532 | display = _display |
|
535 | 533 | |
|
536 | 534 | def update(self,arg): |
|
537 | 535 | #print '***cache_count', self.cache_count # dbg |
|
538 | 536 | if self.cache_count >= self.cache_size and self.do_full_cache: |
|
539 | 537 | self.flush() |
|
540 | 538 | # Don't overwrite '_' and friends if '_' is in __builtin__ (otherwise |
|
541 | 539 | # we cause buggy behavior for things like gettext). |
|
542 | 540 | if '_' not in __builtin__.__dict__: |
|
543 | 541 | self.___ = self.__ |
|
544 | 542 | self.__ = self._ |
|
545 | 543 | self._ = arg |
|
546 | 544 | self.user_ns.update({'_':self._,'__':self.__,'___':self.___}) |
|
547 | 545 | |
|
548 | 546 | # hackish access to top-level namespace to create _1,_2... dynamically |
|
549 | 547 | to_main = {} |
|
550 | 548 | if self.do_full_cache: |
|
551 | 549 | self.cache_count += 1 |
|
552 | 550 | self.entries.append(arg) |
|
553 | 551 | new_result = '_'+`self.prompt_count` |
|
554 | 552 | to_main[new_result] = self.entries[-1] |
|
555 | 553 | self.user_ns.update(to_main) |
|
556 | 554 | self.user_ns['_oh'][self.prompt_count] = arg |
|
557 | 555 | |
|
558 | 556 | def flush(self): |
|
559 | 557 | if not self.do_full_cache: |
|
560 | 558 | raise ValueError,"You shouldn't have reached the cache flush "\ |
|
561 | 559 | "if full caching is not enabled!" |
|
562 | 560 | warn('Output cache limit (currently '+\ |
|
563 | 561 | `self.cache_count`+' entries) hit.\n' |
|
564 | 562 | 'Flushing cache and resetting history counter...\n' |
|
565 | 563 | 'The only history variables available will be _,__,___ and _1\n' |
|
566 | 564 | 'with the current result.') |
|
567 | 565 | # delete auto-generated vars from global namespace |
|
568 | 566 | for n in range(1,self.prompt_count + 1): |
|
569 | 567 | key = '_'+`n` |
|
570 | 568 | try: |
|
571 | 569 | del self.user_ns[key] |
|
572 | 570 | except: pass |
|
573 | 571 | self.prompt_count = 1 |
|
574 | 572 | self.cache_count = 1 |
@@ -1,376 +1,375 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 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 | 7 | # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu> |
|
8 | 8 | # |
|
9 | 9 | # Distributed under the terms of the BSD License. The full license is in |
|
10 | 10 | # the file COPYING, distributed as part of this software. |
|
11 | 11 | #***************************************************************************** |
|
12 | 12 | |
|
13 | 13 | from IPython import Release |
|
14 | 14 | __author__ = '%s <%s>' % Release.authors['Fernando'] |
|
15 | 15 | __license__ = Release.license |
|
16 | 16 | |
|
17 | 17 | __all__ = ['Struct'] |
|
18 | 18 | |
|
19 | 19 | import types |
|
20 | 20 | from IPython.genutils import list2dict2 |
|
21 | 21 | |
|
22 | 22 | class Struct: |
|
23 | 23 | """Class to mimic C structs but also provide convenient dictionary-like |
|
24 | 24 | functionality. |
|
25 | 25 | |
|
26 | 26 | Instances can be initialized with a dictionary, a list of key=value pairs |
|
27 | 27 | or both. If both are present, the dictionary must come first. |
|
28 | 28 | |
|
29 | 29 | Because Python classes provide direct assignment to their members, it's |
|
30 | 30 | easy to overwrite normal methods (S.copy = 1 would destroy access to |
|
31 | 31 | S.copy()). For this reason, all builtin method names are protected and |
|
32 | 32 | can't be assigned to. An attempt to do s.copy=1 or s['copy']=1 will raise |
|
33 | 33 | a KeyError exception. If you really want to, you can bypass this |
|
34 | 34 | protection by directly assigning to __dict__: s.__dict__['copy']=1 will |
|
35 | 35 | still work. Doing this will break functionality, though. As in most of |
|
36 | 36 | Python, namespace protection is weakly enforced, so feel free to shoot |
|
37 | 37 | yourself if you really want to. |
|
38 | 38 | |
|
39 | 39 | Note that this class uses more memory and is *much* slower than a regular |
|
40 | 40 | dictionary, so be careful in situations where memory or performance are |
|
41 | 41 | critical. But for day to day use it should behave fine. It is particularly |
|
42 | 42 | convenient for storing configuration data in programs. |
|
43 | 43 | |
|
44 | 44 | +,+=,- and -= are implemented. +/+= do merges (non-destructive updates), |
|
45 | 45 | -/-= remove keys from the original. See the method descripitions. |
|
46 | 46 | |
|
47 | 47 | This class allows a quick access syntax: both s.key and s['key'] are |
|
48 | 48 | valid. This syntax has a limitation: each 'key' has to be explicitly |
|
49 | 49 | accessed by its original name. The normal s.key syntax doesn't provide |
|
50 | 50 | access to the keys via variables whose values evaluate to the desired |
|
51 | 51 | keys. An example should clarify this: |
|
52 | 52 | |
|
53 | 53 | Define a dictionary and initialize both with dict and k=v pairs: |
|
54 | 54 | >>> d={'a':1,'b':2} |
|
55 | 55 | >>> s=Struct(d,hi=10,ho=20) |
|
56 | 56 | The return of __repr__ can be used to create a new instance: |
|
57 | 57 | >>> s |
|
58 | 58 | Struct({'ho': 20, 'b': 2, 'hi': 10, 'a': 1}) |
|
59 | 59 | __str__ (called by print) shows it's not quite a regular dictionary: |
|
60 | 60 | >>> print s |
|
61 | 61 | Struct {a: 1, b: 2, hi: 10, ho: 20} |
|
62 | 62 | Access by explicitly named key with dot notation: |
|
63 | 63 | >>> s.a |
|
64 | 64 | 1 |
|
65 | 65 | Or like a dictionary: |
|
66 | 66 | >>> s['a'] |
|
67 | 67 | 1 |
|
68 | 68 | If you want a variable to hold the key value, only dictionary access works: |
|
69 | 69 | >>> key='hi' |
|
70 | 70 | >>> s.key |
|
71 | 71 | Traceback (most recent call last): |
|
72 | 72 | File "<stdin>", line 1, in ? |
|
73 | 73 | AttributeError: Struct instance has no attribute 'key' |
|
74 | 74 | >>> s[key] |
|
75 | 75 | 10 |
|
76 | 76 | |
|
77 | 77 | Another limitation of the s.key syntax (and Struct(key=val) |
|
78 | 78 | initialization): keys can't be numbers. But numeric keys can be used and |
|
79 | 79 | accessed using the dictionary syntax. Again, an example: |
|
80 | 80 | |
|
81 | 81 | This doesn't work: |
|
82 | 82 | >>> s=Struct(4='hi') |
|
83 | 83 | SyntaxError: keyword can't be an expression |
|
84 | 84 | But this does: |
|
85 | 85 | >>> s=Struct() |
|
86 | 86 | >>> s[4]='hi' |
|
87 | 87 | >>> s |
|
88 | 88 | Struct({4: 'hi'}) |
|
89 | 89 | >>> s[4] |
|
90 | 90 | 'hi' |
|
91 | 91 | """ |
|
92 | 92 | |
|
93 | 93 | # Attributes to which __setitem__ and __setattr__ will block access. |
|
94 | 94 | # Note: much of this will be moot in Python 2.2 and will be done in a much |
|
95 | 95 | # cleaner way. |
|
96 | 96 | __protected = ('copy dict dictcopy get has_attr has_key items keys ' |
|
97 | 97 | 'merge popitem setdefault update values ' |
|
98 | 98 | '__make_dict __dict_invert ').split() |
|
99 | 99 | |
|
100 | 100 | def __init__(self,dict=None,**kw): |
|
101 | 101 | """Initialize with a dictionary, another Struct, or by giving |
|
102 | 102 | explicitly the list of attributes. |
|
103 | 103 | |
|
104 | 104 | Both can be used, but the dictionary must come first: |
|
105 | 105 | Struct(dict), Struct(k1=v1,k2=v2) or Struct(dict,k1=v1,k2=v2). |
|
106 | 106 | """ |
|
107 | 107 | if dict is None: |
|
108 | 108 | dict = {} |
|
109 | 109 | if isinstance(dict,Struct): |
|
110 | 110 | dict = dict.dict() |
|
111 | 111 | elif dict and type(dict) is not types.DictType: |
|
112 | 112 | raise TypeError,\ |
|
113 | 113 | 'Initialize with a dictionary or key=val pairs.' |
|
114 | 114 | dict.update(kw) |
|
115 | 115 | # do the updating by hand to guarantee that we go through the |
|
116 | 116 | # safety-checked __setitem__ |
|
117 | 117 | for k,v in dict.items(): |
|
118 | 118 | self[k] = v |
|
119 | 119 | |
|
120 | 120 | def __setitem__(self,key,value): |
|
121 | 121 | """Used when struct[key] = val calls are made.""" |
|
122 | 122 | if key in Struct.__protected: |
|
123 | 123 | raise KeyError,'Key '+`key`+' is a protected key of class Struct.' |
|
124 | 124 | self.__dict__[key] = value |
|
125 | 125 | |
|
126 | 126 | def __setattr__(self, key, value): |
|
127 | 127 | """Used when struct.key = val calls are made.""" |
|
128 | 128 | self.__setitem__(key,value) |
|
129 | 129 | |
|
130 | 130 | def __str__(self): |
|
131 | 131 | """Gets called by print.""" |
|
132 | 132 | |
|
133 | 133 | return 'Struct('+str(self.__dict__)+')' |
|
134 | 134 | |
|
135 | 135 | def __repr__(self): |
|
136 | 136 | """Gets called by repr. |
|
137 | 137 | |
|
138 | 138 | A Struct can be recreated with S_new=eval(repr(S_old)).""" |
|
139 | 139 | return 'Struct('+str(self.__dict__)+')' |
|
140 | 140 | |
|
141 | 141 | def __getitem__(self,key): |
|
142 | 142 | """Allows struct[key] access.""" |
|
143 | 143 | return self.__dict__[key] |
|
144 | 144 | |
|
145 | 145 | def __contains__(self,key): |
|
146 | 146 | """Allows use of the 'in' operator.""" |
|
147 | 147 | return self.__dict__.has_key(key) |
|
148 | 148 | |
|
149 | 149 | def __iadd__(self,other): |
|
150 | 150 | """S += S2 is a shorthand for S.merge(S2).""" |
|
151 | 151 | self.merge(other) |
|
152 | 152 | return self |
|
153 | 153 | |
|
154 | 154 | def __add__(self,other): |
|
155 | 155 | """S + S2 -> New Struct made form S and S.merge(S2)""" |
|
156 | 156 | Sout = self.copy() |
|
157 | 157 | Sout.merge(other) |
|
158 | 158 | return Sout |
|
159 | 159 | |
|
160 | 160 | def __sub__(self,other): |
|
161 | 161 | """Return S1-S2, where all keys in S2 have been deleted (if present) |
|
162 | 162 | from S1.""" |
|
163 | 163 | Sout = self.copy() |
|
164 | 164 | Sout -= other |
|
165 | 165 | return Sout |
|
166 | 166 | |
|
167 | 167 | def __isub__(self,other): |
|
168 | 168 | """Do in place S = S - S2, meaning all keys in S2 have been deleted |
|
169 | 169 | (if present) from S1.""" |
|
170 | 170 | |
|
171 | 171 | for k in other.keys(): |
|
172 | 172 | if self.has_key(k): |
|
173 | 173 | del self.__dict__[k] |
|
174 | 174 | |
|
175 | 175 | def __make_dict(self,__loc_data__,**kw): |
|
176 | 176 | "Helper function for update and merge. Return a dict from data." |
|
177 | 177 | |
|
178 | 178 | if __loc_data__ == None: |
|
179 | 179 | dict = {} |
|
180 | 180 | elif type(__loc_data__) is types.DictType: |
|
181 | 181 | dict = __loc_data__ |
|
182 | 182 | elif isinstance(__loc_data__,Struct): |
|
183 | 183 | dict = __loc_data__.__dict__ |
|
184 | 184 | else: |
|
185 | 185 | raise TypeError, 'Update with a dict, a Struct or key=val pairs.' |
|
186 | 186 | if kw: |
|
187 | 187 | dict.update(kw) |
|
188 | 188 | return dict |
|
189 | 189 | |
|
190 | 190 | def __dict_invert(self,dict): |
|
191 | 191 | """Helper function for merge. Takes a dictionary whose values are |
|
192 | 192 | lists and returns a dict. with the elements of each list as keys and |
|
193 | 193 | the original keys as values.""" |
|
194 | 194 | |
|
195 | 195 | outdict = {} |
|
196 | 196 | for k,lst in dict.items(): |
|
197 | 197 | if type(lst) is types.StringType: |
|
198 | 198 | lst = lst.split() |
|
199 | 199 | for entry in lst: |
|
200 | 200 | outdict[entry] = k |
|
201 | 201 | return outdict |
|
202 | 202 | |
|
203 | 203 | def clear(self): |
|
204 | 204 | """Clear all attributes.""" |
|
205 | 205 | self.__dict__.clear() |
|
206 | 206 | |
|
207 | 207 | def copy(self): |
|
208 | 208 | """Return a (shallow) copy of a Struct.""" |
|
209 | 209 | return Struct(self.__dict__.copy()) |
|
210 | 210 | |
|
211 | 211 | def dict(self): |
|
212 | 212 | """Return the Struct's dictionary.""" |
|
213 | 213 | return self.__dict__ |
|
214 | 214 | |
|
215 | 215 | def dictcopy(self): |
|
216 | 216 | """Return a (shallow) copy of the Struct's dictionary.""" |
|
217 | 217 | return self.__dict__.copy() |
|
218 | 218 | |
|
219 | 219 | def popitem(self): |
|
220 | 220 | """S.popitem() -> (k, v), remove and return some (key, value) pair as |
|
221 | 221 | a 2-tuple; but raise KeyError if S is empty.""" |
|
222 | 222 | return self.__dict__.popitem() |
|
223 | 223 | |
|
224 | 224 | def update(self,__loc_data__=None,**kw): |
|
225 | 225 | """Update (merge) with data from another Struct or from a dictionary. |
|
226 | 226 | Optionally, one or more key=value pairs can be given at the end for |
|
227 | 227 | direct update.""" |
|
228 | 228 | |
|
229 | 229 | # The funny name __loc_data__ is to prevent a common variable name which |
|
230 | 230 | # could be a fieled of a Struct to collide with this parameter. The problem |
|
231 | 231 | # would arise if the function is called with a keyword with this same name |
|
232 | 232 | # that a user means to add as a Struct field. |
|
233 | 233 | newdict = Struct.__make_dict(self,__loc_data__,**kw) |
|
234 | 234 | for k,v in newdict.items(): |
|
235 | 235 | self[k] = v |
|
236 | 236 | |
|
237 | 237 | def merge(self,__loc_data__=None,__conflict_solve=None,**kw): |
|
238 | 238 | """S.merge(data,conflict,k=v1,k=v2,...) -> merge data and k=v into S. |
|
239 | 239 | |
|
240 | 240 | This is similar to update(), but much more flexible. First, a dict is |
|
241 | 241 | made from data+key=value pairs. When merging this dict with the Struct |
|
242 | 242 | S, the optional dictionary 'conflict' is used to decide what to do. |
|
243 | 243 | |
|
244 | 244 | If conflict is not given, the default behavior is to preserve any keys |
|
245 | 245 | with their current value (the opposite of the update method's |
|
246 | 246 | behavior). |
|
247 | 247 | |
|
248 | 248 | conflict is a dictionary of binary functions which will be used to |
|
249 | 249 | solve key conflicts. It must have the following structure: |
|
250 | 250 | |
|
251 | 251 | conflict == { fn1 : [Skey1,Skey2,...], fn2 : [Skey3], etc } |
|
252 | 252 | |
|
253 | 253 | Values must be lists or whitespace separated strings which are |
|
254 | 254 | automatically converted to lists of strings by calling string.split(). |
|
255 | 255 | |
|
256 | 256 | Each key of conflict is a function which defines a policy for |
|
257 | 257 | resolving conflicts when merging with the input data. Each fn must be |
|
258 | 258 | a binary function which returns the desired outcome for a key |
|
259 | 259 | conflict. These functions will be called as fn(old,new). |
|
260 | 260 | |
|
261 | 261 | An example is probably in order. Suppose you are merging the struct S |
|
262 | 262 | with a dict D and the following conflict policy dict: |
|
263 | 263 | |
|
264 | 264 | S.merge(D,{fn1:['a','b',4], fn2:'key_c key_d'}) |
|
265 | 265 | |
|
266 | 266 | If the key 'a' is found in both S and D, the merge method will call: |
|
267 | 267 | |
|
268 | 268 | S['a'] = fn1(S['a'],D['a']) |
|
269 | 269 | |
|
270 | 270 | As a convenience, merge() provides five (the most commonly needed) |
|
271 | 271 | pre-defined policies: preserve, update, add, add_flip and add_s. The |
|
272 | 272 | easiest explanation is their implementation: |
|
273 | 273 | |
|
274 | 274 | preserve = lambda old,new: old |
|
275 | 275 | update = lambda old,new: new |
|
276 | 276 | add = lambda old,new: old + new |
|
277 | 277 | add_flip = lambda old,new: new + old # note change of order! |
|
278 | 278 | add_s = lambda old,new: old + ' ' + new # only works for strings! |
|
279 | 279 | |
|
280 | 280 | You can use those four words (as strings) as keys in conflict instead |
|
281 | 281 | of defining them as functions, and the merge method will substitute |
|
282 | 282 | the appropriate functions for you. That is, the call |
|
283 | 283 | |
|
284 | 284 | S.merge(D,{'preserve':'a b c','add':[4,5,'d'],my_function:[6]}) |
|
285 | 285 | |
|
286 | 286 | will automatically substitute the functions preserve and add for the |
|
287 | 287 | names 'preserve' and 'add' before making any function calls. |
|
288 | 288 | |
|
289 | 289 | For more complicated conflict resolution policies, you still need to |
|
290 | 290 | construct your own functions. """ |
|
291 | 291 | |
|
292 | 292 | data_dict = Struct.__make_dict(self,__loc_data__,**kw) |
|
293 | 293 | |
|
294 | 294 | # policies for conflict resolution: two argument functions which return |
|
295 | 295 | # the value that will go in the new struct |
|
296 | 296 | preserve = lambda old,new: old |
|
297 | 297 | update = lambda old,new: new |
|
298 | 298 | add = lambda old,new: old + new |
|
299 | 299 | add_flip = lambda old,new: new + old # note change of order! |
|
300 | 300 | add_s = lambda old,new: old + ' ' + new |
|
301 | 301 | |
|
302 | 302 | # default policy is to keep current keys when there's a conflict |
|
303 | 303 | conflict_solve = list2dict2(self.keys(),default = preserve) |
|
304 | 304 | |
|
305 | 305 | # the conflict_solve dictionary is given by the user 'inverted': we |
|
306 | 306 | # need a name-function mapping, it comes as a function -> names |
|
307 | 307 | # dict. Make a local copy (b/c we'll make changes), replace user |
|
308 | 308 | # strings for the three builtin policies and invert it. |
|
309 | 309 | if __conflict_solve: |
|
310 | 310 | inv_conflict_solve_user = __conflict_solve.copy() |
|
311 | 311 | for name, func in [('preserve',preserve), ('update',update), |
|
312 | 312 | ('add',add), ('add_flip',add_flip), ('add_s',add_s)]: |
|
313 | 313 | if name in inv_conflict_solve_user.keys(): |
|
314 | 314 | inv_conflict_solve_user[func] = inv_conflict_solve_user[name] |
|
315 | 315 | del inv_conflict_solve_user[name] |
|
316 | 316 | conflict_solve.update(Struct.__dict_invert(self,inv_conflict_solve_user)) |
|
317 | 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 | 318 | #print '*'*50,'in merger. conflict_solver:'; pprint(conflict_solve) |
|
320 |
for key in data_dict |
|
|
319 | for key in data_dict: | |
|
321 | 320 | if key not in self: |
|
322 | 321 | self[key] = data_dict[key] |
|
323 | 322 | else: |
|
324 | 323 | self[key] = conflict_solve[key](self[key],data_dict[key]) |
|
325 | 324 | |
|
326 | 325 | def has_key(self,key): |
|
327 | 326 | """Like has_key() dictionary method.""" |
|
328 | 327 | return self.__dict__.has_key(key) |
|
329 | 328 | |
|
330 | 329 | def hasattr(self,key): |
|
331 | 330 | """hasattr function available as a method. |
|
332 | 331 | |
|
333 | 332 | Implemented like has_key, to make sure that all available keys in the |
|
334 | 333 | internal dictionary of the Struct appear also as attributes (even |
|
335 | 334 | numeric keys).""" |
|
336 | 335 | return self.__dict__.has_key(key) |
|
337 | 336 | |
|
338 | 337 | def items(self): |
|
339 | 338 | """Return the items in the Struct's dictionary, in the same format |
|
340 | 339 | as a call to {}.items().""" |
|
341 | 340 | return self.__dict__.items() |
|
342 | 341 | |
|
343 | 342 | def keys(self): |
|
344 | 343 | """Return the keys in the Struct's dictionary, in the same format |
|
345 | 344 | as a call to {}.keys().""" |
|
346 | 345 | return self.__dict__.keys() |
|
347 | 346 | |
|
348 | 347 | def values(self,keys=None): |
|
349 | 348 | """Return the values in the Struct's dictionary, in the same format |
|
350 | 349 | as a call to {}.values(). |
|
351 | 350 | |
|
352 | 351 | Can be called with an optional argument keys, which must be a list or |
|
353 | 352 | tuple of keys. In this case it returns only the values corresponding |
|
354 | 353 | to those keys (allowing a form of 'slicing' for Structs).""" |
|
355 | 354 | if not keys: |
|
356 | 355 | return self.__dict__.values() |
|
357 | 356 | else: |
|
358 | 357 | ret=[] |
|
359 | 358 | for k in keys: |
|
360 | 359 | ret.append(self[k]) |
|
361 | 360 | return ret |
|
362 | 361 | |
|
363 | 362 | def get(self,attr,val=None): |
|
364 | 363 | """S.get(k[,d]) -> S[k] if S.has_key(k), else d. d defaults to None.""" |
|
365 | 364 | try: |
|
366 | 365 | return self[attr] |
|
367 | 366 | except KeyError: |
|
368 | 367 | return val |
|
369 | 368 | |
|
370 | 369 | def setdefault(self,attr,val=None): |
|
371 | 370 | """S.setdefault(k[,d]) -> S.get(k,d), also set S[k]=d if not S.has_key(k)""" |
|
372 | 371 | if not self.has_key(attr): |
|
373 | 372 | self[attr] = val |
|
374 | 373 | return self.get(attr,val) |
|
375 | 374 | # end class Struct |
|
376 | 375 |
@@ -1,504 +1,495 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """Manage background (threaded) jobs conveniently from an interactive shell. |
|
3 | 3 | |
|
4 | 4 | This module provides a BackgroundJobManager class. This is the main class |
|
5 | 5 | meant for public usage, it implements an object which can create and manage |
|
6 | 6 | new background jobs. |
|
7 | 7 | |
|
8 | 8 | It also provides the actual job classes managed by these BackgroundJobManager |
|
9 | 9 | objects, see their docstrings below. |
|
10 | 10 | |
|
11 | 11 | |
|
12 | 12 | This system was inspired by discussions with B. Granger and the |
|
13 | 13 | BackgroundCommand class described in the book Python Scripting for |
|
14 | 14 | Computational Science, by H. P. Langtangen: |
|
15 | 15 | |
|
16 | 16 | http://folk.uio.no/hpl/scripting |
|
17 | 17 | |
|
18 | 18 | (although ultimately no code from this text was used, as IPython's system is a |
|
19 | 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 | 25 | # Copyright (C) 2005 Fernando Perez <fperez@colorado.edu> |
|
26 | 26 | # |
|
27 | 27 | # Distributed under the terms of the BSD License. The full license is in |
|
28 | 28 | # the file COPYING, distributed as part of this software. |
|
29 | 29 | #***************************************************************************** |
|
30 | 30 | |
|
31 | 31 | from IPython import Release |
|
32 | 32 | __author__ = '%s <%s>' % Release.authors['Fernando'] |
|
33 | 33 | __license__ = Release.license |
|
34 | 34 | |
|
35 | 35 | # Code begins |
|
36 | 36 | import threading,sys |
|
37 | 37 | |
|
38 | 38 | from IPython.ultraTB import AutoFormattedTB |
|
39 | 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 | 41 | class BackgroundJobManager: |
|
51 | 42 | """Class to manage a pool of backgrounded threaded jobs. |
|
52 | 43 | |
|
53 | 44 | Below, we assume that 'jobs' is a BackgroundJobManager instance. |
|
54 | 45 | |
|
55 | 46 | Usage summary (see the method docstrings for details): |
|
56 | 47 | |
|
57 | 48 | jobs.new(...) -> start a new job |
|
58 | 49 | |
|
59 | 50 | jobs() or jobs.status() -> print status summary of all jobs |
|
60 | 51 | |
|
61 | 52 | jobs[N] -> returns job number N. |
|
62 | 53 | |
|
63 | 54 | foo = jobs[N].result -> assign to variable foo the result of job N |
|
64 | 55 | |
|
65 | 56 | jobs[N].traceback() -> print the traceback of dead job N |
|
66 | 57 | |
|
67 | 58 | jobs.remove(N) -> remove (finished) job N |
|
68 | 59 | |
|
69 | 60 | jobs.flush_finished() -> remove all finished jobs |
|
70 | 61 | |
|
71 | 62 | As a convenience feature, BackgroundJobManager instances provide the |
|
72 | 63 | utility result and traceback methods which retrieve the corresponding |
|
73 | 64 | information from the jobs list: |
|
74 | 65 | |
|
75 | 66 | jobs.result(N) <--> jobs[N].result |
|
76 | 67 | jobs.traceback(N) <--> jobs[N].traceback() |
|
77 | 68 | |
|
78 | 69 | While this appears minor, it allows you to use tab completion |
|
79 | 70 | interactively on the job manager instance. |
|
80 | 71 | |
|
81 | 72 | In interactive mode, IPython provides the magic fuction %bg for quick |
|
82 | 73 | creation of backgrounded expression-based jobs. Type bg? for details.""" |
|
83 | 74 | |
|
84 | 75 | def __init__(self): |
|
85 | 76 | # Lists for job management |
|
86 | 77 | self.jobs_run = [] |
|
87 | 78 | self.jobs_comp = [] |
|
88 | 79 | self.jobs_dead = [] |
|
89 | 80 | # A dict of all jobs, so users can easily access any of them |
|
90 | 81 | self.jobs_all = {} |
|
91 | 82 | # For reporting |
|
92 | 83 | self._comp_report = [] |
|
93 | 84 | self._dead_report = [] |
|
94 | 85 | # Store status codes locally for fast lookups |
|
95 | 86 | self._s_created = BackgroundJobBase.stat_created_c |
|
96 | 87 | self._s_running = BackgroundJobBase.stat_running_c |
|
97 | 88 | self._s_completed = BackgroundJobBase.stat_completed_c |
|
98 | 89 | self._s_dead = BackgroundJobBase.stat_dead_c |
|
99 | 90 | |
|
100 | 91 | def new(self,func_or_exp,*args,**kwargs): |
|
101 | 92 | """Add a new background job and start it in a separate thread. |
|
102 | 93 | |
|
103 | 94 | There are two types of jobs which can be created: |
|
104 | 95 | |
|
105 | 96 | 1. Jobs based on expressions which can be passed to an eval() call. |
|
106 | 97 | The expression must be given as a string. For example: |
|
107 | 98 | |
|
108 | 99 | job_manager.new('myfunc(x,y,z=1)'[,glob[,loc]]) |
|
109 | 100 | |
|
110 | 101 | The given expression is passed to eval(), along with the optional |
|
111 | 102 | global/local dicts provided. If no dicts are given, they are |
|
112 | 103 | extracted automatically from the caller's frame. |
|
113 | 104 | |
|
114 | 105 | A Python statement is NOT a valid eval() expression. Basically, you |
|
115 | 106 | can only use as an eval() argument something which can go on the right |
|
116 | 107 | of an '=' sign and be assigned to a variable. |
|
117 | 108 | |
|
118 | 109 | For example,"print 'hello'" is not valid, but '2+3' is. |
|
119 | 110 | |
|
120 | 111 | 2. Jobs given a function object, optionally passing additional |
|
121 | 112 | positional arguments: |
|
122 | 113 | |
|
123 | 114 | job_manager.new(myfunc,x,y) |
|
124 | 115 | |
|
125 | 116 | The function is called with the given arguments. |
|
126 | 117 | |
|
127 | 118 | If you need to pass keyword arguments to your function, you must |
|
128 | 119 | supply them as a dict named kw: |
|
129 | 120 | |
|
130 | 121 | job_manager.new(myfunc,x,y,kw=dict(z=1)) |
|
131 | 122 | |
|
132 | 123 | The reason for this assymmetry is that the new() method needs to |
|
133 | 124 | maintain access to its own keywords, and this prevents name collisions |
|
134 | 125 | between arguments to new() and arguments to your own functions. |
|
135 | 126 | |
|
136 | 127 | In both cases, the result is stored in the job.result field of the |
|
137 | 128 | background job object. |
|
138 | 129 | |
|
139 | 130 | |
|
140 | 131 | Notes and caveats: |
|
141 | 132 | |
|
142 | 133 | 1. All threads running share the same standard output. Thus, if your |
|
143 | 134 | background jobs generate output, it will come out on top of whatever |
|
144 | 135 | you are currently writing. For this reason, background jobs are best |
|
145 | 136 | used with silent functions which simply return their output. |
|
146 | 137 | |
|
147 | 138 | 2. Threads also all work within the same global namespace, and this |
|
148 | 139 | system does not lock interactive variables. So if you send job to the |
|
149 | 140 | background which operates on a mutable object for a long time, and |
|
150 | 141 | start modifying that same mutable object interactively (or in another |
|
151 | 142 | backgrounded job), all sorts of bizarre behaviour will occur. |
|
152 | 143 | |
|
153 | 144 | 3. If a background job is spending a lot of time inside a C extension |
|
154 | 145 | module which does not release the Python Global Interpreter Lock |
|
155 | 146 | (GIL), this will block the IPython prompt. This is simply because the |
|
156 | 147 | Python interpreter can only switch between threads at Python |
|
157 | 148 | bytecodes. While the execution is inside C code, the interpreter must |
|
158 | 149 | simply wait unless the extension module releases the GIL. |
|
159 | 150 | |
|
160 | 151 | 4. There is no way, due to limitations in the Python threads library, |
|
161 | 152 | to kill a thread once it has started.""" |
|
162 | 153 | |
|
163 | 154 | if callable(func_or_exp): |
|
164 | 155 | kw = kwargs.get('kw',{}) |
|
165 | 156 | job = BackgroundJobFunc(func_or_exp,*args,**kw) |
|
166 | 157 | elif isinstance(func_or_exp,basestring): |
|
167 | 158 | if not args: |
|
168 | 159 | frame = sys._getframe(1) |
|
169 | 160 | glob, loc = frame.f_globals, frame.f_locals |
|
170 | 161 | elif len(args)==1: |
|
171 | 162 | glob = loc = args[0] |
|
172 | 163 | elif len(args)==2: |
|
173 | 164 | glob,loc = args |
|
174 | 165 | else: |
|
175 | 166 | raise ValueError,\ |
|
176 | 167 | 'Expression jobs take at most 2 args (globals,locals)' |
|
177 | 168 | job = BackgroundJobExpr(func_or_exp,glob,loc) |
|
178 | 169 | else: |
|
179 | 170 | raise |
|
180 | 171 | jkeys = self.jobs_all.keys() |
|
181 | 172 | if jkeys: |
|
182 | 173 | job.num = max(jkeys)+1 |
|
183 | 174 | else: |
|
184 | 175 | job.num = 0 |
|
185 | 176 | self.jobs_run.append(job) |
|
186 | 177 | self.jobs_all[job.num] = job |
|
187 | 178 | print 'Starting job # %s in a separate thread.' % job.num |
|
188 | 179 | job.start() |
|
189 | 180 | return job |
|
190 | 181 | |
|
191 | 182 | def __getitem__(self,key): |
|
192 | 183 | return self.jobs_all[key] |
|
193 | 184 | |
|
194 | 185 | def __call__(self): |
|
195 | 186 | """An alias to self.status(), |
|
196 | 187 | |
|
197 | 188 | This allows you to simply call a job manager instance much like the |
|
198 | 189 | Unix jobs shell command.""" |
|
199 | 190 | |
|
200 | 191 | return self.status() |
|
201 | 192 | |
|
202 | 193 | def _update_status(self): |
|
203 | 194 | """Update the status of the job lists. |
|
204 | 195 | |
|
205 | 196 | This method moves finished jobs to one of two lists: |
|
206 | 197 | - self.jobs_comp: jobs which completed successfully |
|
207 | 198 | - self.jobs_dead: jobs which finished but died. |
|
208 | 199 | |
|
209 | 200 | It also copies those jobs to corresponding _report lists. These lists |
|
210 | 201 | are used to report jobs completed/dead since the last update, and are |
|
211 | 202 | then cleared by the reporting function after each call.""" |
|
212 | 203 | |
|
213 | 204 | run,comp,dead = self._s_running,self._s_completed,self._s_dead |
|
214 | 205 | jobs_run = self.jobs_run |
|
215 | 206 | for num in range(len(jobs_run)): |
|
216 | 207 | job = jobs_run[num] |
|
217 | 208 | stat = job.stat_code |
|
218 | 209 | if stat == run: |
|
219 | 210 | continue |
|
220 | 211 | elif stat == comp: |
|
221 | 212 | self.jobs_comp.append(job) |
|
222 | 213 | self._comp_report.append(job) |
|
223 | 214 | jobs_run[num] = False |
|
224 | 215 | elif stat == dead: |
|
225 | 216 | self.jobs_dead.append(job) |
|
226 | 217 | self._dead_report.append(job) |
|
227 | 218 | jobs_run[num] = False |
|
228 | 219 | self.jobs_run = filter(None,self.jobs_run) |
|
229 | 220 | |
|
230 | 221 | def _group_report(self,group,name): |
|
231 | 222 | """Report summary for a given job group. |
|
232 | 223 | |
|
233 | 224 | Return True if the group had any elements.""" |
|
234 | 225 | |
|
235 | 226 | if group: |
|
236 | 227 | print '%s jobs:' % name |
|
237 | 228 | for job in group: |
|
238 | 229 | print '%s : %s' % (job.num,job) |
|
239 | 230 | |
|
240 | 231 | return True |
|
241 | 232 | |
|
242 | 233 | def _group_flush(self,group,name): |
|
243 | 234 | """Flush a given job group |
|
244 | 235 | |
|
245 | 236 | Return True if the group had any elements.""" |
|
246 | 237 | |
|
247 | 238 | njobs = len(group) |
|
248 | 239 | if njobs: |
|
249 | 240 | plural = {1:''}.setdefault(njobs,'s') |
|
250 | 241 | print 'Flushing %s %s job%s.' % (njobs,name,plural) |
|
251 | 242 | group[:] = [] |
|
252 | 243 | return True |
|
253 | 244 | |
|
254 | 245 | def _status_new(self): |
|
255 | 246 | """Print the status of newly finished jobs. |
|
256 | 247 | |
|
257 | 248 | Return True if any new jobs are reported. |
|
258 | 249 | |
|
259 | 250 | This call resets its own state every time, so it only reports jobs |
|
260 | 251 | which have finished since the last time it was called.""" |
|
261 | 252 | |
|
262 | 253 | self._update_status() |
|
263 | 254 | new_comp = self._group_report(self._comp_report,'Completed') |
|
264 | 255 | new_dead = self._group_report(self._dead_report, |
|
265 | 256 | 'Dead, call job.traceback() for details') |
|
266 | 257 | self._comp_report[:] = [] |
|
267 | 258 | self._dead_report[:] = [] |
|
268 | 259 | return new_comp or new_dead |
|
269 | 260 | |
|
270 | 261 | def status(self,verbose=0): |
|
271 | 262 | """Print a status of all jobs currently being managed.""" |
|
272 | 263 | |
|
273 | 264 | self._update_status() |
|
274 | 265 | self._group_report(self.jobs_run,'Running') |
|
275 | 266 | self._group_report(self.jobs_comp,'Completed') |
|
276 | 267 | self._group_report(self.jobs_dead,'Dead') |
|
277 | 268 | # Also flush the report queues |
|
278 | 269 | self._comp_report[:] = [] |
|
279 | 270 | self._dead_report[:] = [] |
|
280 | 271 | |
|
281 | 272 | def remove(self,num): |
|
282 | 273 | """Remove a finished (completed or dead) job.""" |
|
283 | 274 | |
|
284 | 275 | try: |
|
285 | 276 | job = self.jobs_all[num] |
|
286 | 277 | except KeyError: |
|
287 | 278 | error('Job #%s not found' % num) |
|
288 | 279 | else: |
|
289 | 280 | stat_code = job.stat_code |
|
290 | 281 | if stat_code == self._s_running: |
|
291 | 282 | error('Job #%s is still running, it can not be removed.' % num) |
|
292 | 283 | return |
|
293 | 284 | elif stat_code == self._s_completed: |
|
294 | 285 | self.jobs_comp.remove(job) |
|
295 | 286 | elif stat_code == self._s_dead: |
|
296 | 287 | self.jobs_dead.remove(job) |
|
297 | 288 | |
|
298 | 289 | def flush_finished(self): |
|
299 | 290 | """Flush all jobs finished (completed and dead) from lists. |
|
300 | 291 | |
|
301 | 292 | Running jobs are never flushed. |
|
302 | 293 | |
|
303 | 294 | It first calls _status_new(), to update info. If any jobs have |
|
304 | 295 | completed since the last _status_new() call, the flush operation |
|
305 | 296 | aborts.""" |
|
306 | 297 | |
|
307 | 298 | if self._status_new(): |
|
308 | 299 | error('New jobs completed since last '\ |
|
309 | 300 | '_status_new(), aborting flush.') |
|
310 | 301 | return |
|
311 | 302 | |
|
312 | 303 | # Remove the finished jobs from the master dict |
|
313 | 304 | jobs_all = self.jobs_all |
|
314 | 305 | for job in self.jobs_comp+self.jobs_dead: |
|
315 | 306 | del(jobs_all[job.num]) |
|
316 | 307 | |
|
317 | 308 | # Now flush these lists completely |
|
318 | 309 | fl_comp = self._group_flush(self.jobs_comp,'Completed') |
|
319 | 310 | fl_dead = self._group_flush(self.jobs_dead,'Dead') |
|
320 | 311 | if not (fl_comp or fl_dead): |
|
321 | 312 | print 'No jobs to flush.' |
|
322 | 313 | |
|
323 | 314 | def result(self,num): |
|
324 | 315 | """result(N) -> return the result of job N.""" |
|
325 | 316 | try: |
|
326 | 317 | return self.jobs_all[num].result |
|
327 | 318 | except KeyError: |
|
328 | 319 | error('Job #%s not found' % num) |
|
329 | 320 | |
|
330 | 321 | def traceback(self,num): |
|
331 | 322 | try: |
|
332 | 323 | self.jobs_all[num].traceback() |
|
333 | 324 | except KeyError: |
|
334 | 325 | error('Job #%s not found' % num) |
|
335 | 326 | |
|
336 | 327 | |
|
337 | 328 | class BackgroundJobBase(threading.Thread): |
|
338 | 329 | """Base class to build BackgroundJob classes. |
|
339 | 330 | |
|
340 | 331 | The derived classes must implement: |
|
341 | 332 | |
|
342 | 333 | - Their own __init__, since the one here raises NotImplementedError. The |
|
343 | 334 | derived constructor must call self._init() at the end, to provide common |
|
344 | 335 | initialization. |
|
345 | 336 | |
|
346 | 337 | - A strform attribute used in calls to __str__. |
|
347 | 338 | |
|
348 | 339 | - A call() method, which will make the actual execution call and must |
|
349 | 340 | return a value to be held in the 'result' field of the job object.""" |
|
350 | 341 | |
|
351 | 342 | # Class constants for status, in string and as numerical codes (when |
|
352 | 343 | # updating jobs lists, we don't want to do string comparisons). This will |
|
353 | 344 | # be done at every user prompt, so it has to be as fast as possible |
|
354 | 345 | stat_created = 'Created'; stat_created_c = 0 |
|
355 | 346 | stat_running = 'Running'; stat_running_c = 1 |
|
356 | 347 | stat_completed = 'Completed'; stat_completed_c = 2 |
|
357 | 348 | stat_dead = 'Dead (Exception), call job.traceback() for details' |
|
358 | 349 | stat_dead_c = -1 |
|
359 | 350 | |
|
360 | 351 | def __init__(self): |
|
361 | 352 | raise NotImplementedError, \ |
|
362 | 353 | "This class can not be instantiated directly." |
|
363 | 354 | |
|
364 | 355 | def _init(self): |
|
365 | 356 | """Common initialization for all BackgroundJob objects""" |
|
366 | 357 | |
|
367 | 358 | for attr in ['call','strform']: |
|
368 | 359 | assert hasattr(self,attr), "Missing attribute <%s>" % attr |
|
369 | 360 | |
|
370 | 361 | # The num tag can be set by an external job manager |
|
371 | 362 | self.num = None |
|
372 | 363 | |
|
373 | 364 | self.status = BackgroundJobBase.stat_created |
|
374 | 365 | self.stat_code = BackgroundJobBase.stat_created_c |
|
375 | 366 | self.finished = False |
|
376 | 367 | self.result = '<BackgroundJob has not completed>' |
|
377 | 368 | # reuse the ipython traceback handler if we can get to it, otherwise |
|
378 | 369 | # make a new one |
|
379 | 370 | try: |
|
380 | 371 | self._make_tb = __IPYTHON__.InteractiveTB.text |
|
381 | 372 | except: |
|
382 | 373 | self._make_tb = AutoFormattedTB(mode = 'Context', |
|
383 | 374 | color_scheme='NoColor', |
|
384 | 375 | tb_offset = 1).text |
|
385 | 376 | # Hold a formatted traceback if one is generated. |
|
386 | 377 | self._tb = None |
|
387 | 378 | |
|
388 | 379 | threading.Thread.__init__(self) |
|
389 | 380 | |
|
390 | 381 | def __str__(self): |
|
391 | 382 | return self.strform |
|
392 | 383 | |
|
393 | 384 | def __repr__(self): |
|
394 | 385 | return '<BackgroundJob: %s>' % self.strform |
|
395 | 386 | |
|
396 | 387 | def traceback(self): |
|
397 | 388 | print self._tb |
|
398 | 389 | |
|
399 | 390 | def run(self): |
|
400 | 391 | try: |
|
401 | 392 | self.status = BackgroundJobBase.stat_running |
|
402 | 393 | self.stat_code = BackgroundJobBase.stat_running_c |
|
403 | 394 | self.result = self.call() |
|
404 | 395 | except: |
|
405 | 396 | self.status = BackgroundJobBase.stat_dead |
|
406 | 397 | self.stat_code = BackgroundJobBase.stat_dead_c |
|
407 | 398 | self.finished = None |
|
408 | 399 | self.result = ('<BackgroundJob died, call job.traceback() for details>') |
|
409 | 400 | self._tb = self._make_tb() |
|
410 | 401 | else: |
|
411 | 402 | self.status = BackgroundJobBase.stat_completed |
|
412 | 403 | self.stat_code = BackgroundJobBase.stat_completed_c |
|
413 | 404 | self.finished = True |
|
414 | 405 | |
|
415 | 406 | class BackgroundJobExpr(BackgroundJobBase): |
|
416 | 407 | """Evaluate an expression as a background job (uses a separate thread).""" |
|
417 | 408 | |
|
418 | 409 | def __init__(self,expression,glob=None,loc=None): |
|
419 | 410 | """Create a new job from a string which can be fed to eval(). |
|
420 | 411 | |
|
421 | 412 | global/locals dicts can be provided, which will be passed to the eval |
|
422 | 413 | call.""" |
|
423 | 414 | |
|
424 | 415 | # fail immediately if the given expression can't be compiled |
|
425 | 416 | self.code = compile(expression,'<BackgroundJob compilation>','eval') |
|
426 | 417 | |
|
427 | 418 | if glob is None: |
|
428 | 419 | glob = {} |
|
429 | 420 | if loc is None: |
|
430 | 421 | loc = {} |
|
431 | 422 | |
|
432 | 423 | self.expression = self.strform = expression |
|
433 | 424 | self.glob = glob |
|
434 | 425 | self.loc = loc |
|
435 | 426 | self._init() |
|
436 | 427 | |
|
437 | 428 | def call(self): |
|
438 | 429 | return eval(self.code,self.glob,self.loc) |
|
439 | 430 | |
|
440 | 431 | class BackgroundJobFunc(BackgroundJobBase): |
|
441 | 432 | """Run a function call as a background job (uses a separate thread).""" |
|
442 | 433 | |
|
443 | 434 | def __init__(self,func,*args,**kwargs): |
|
444 | 435 | """Create a new job from a callable object. |
|
445 | 436 | |
|
446 | 437 | Any positional arguments and keyword args given to this constructor |
|
447 | 438 | after the initial callable are passed directly to it.""" |
|
448 | 439 | |
|
449 | 440 | assert callable(func),'first argument must be callable' |
|
450 | 441 | |
|
451 | 442 | if args is None: |
|
452 | 443 | args = [] |
|
453 | 444 | if kwargs is None: |
|
454 | 445 | kwargs = {} |
|
455 | 446 | |
|
456 | 447 | self.func = func |
|
457 | 448 | self.args = args |
|
458 | 449 | self.kwargs = kwargs |
|
459 | 450 | # The string form will only include the function passed, because |
|
460 | 451 | # generating string representations of the arguments is a potentially |
|
461 | 452 | # _very_ expensive operation (e.g. with large arrays). |
|
462 | 453 | self.strform = str(func) |
|
463 | 454 | self._init() |
|
464 | 455 | |
|
465 | 456 | def call(self): |
|
466 | 457 | return self.func(*self.args,**self.kwargs) |
|
467 | 458 | |
|
468 | 459 | |
|
469 | 460 | if __name__=='__main__': |
|
470 | 461 | |
|
471 | 462 | import time |
|
472 | 463 | |
|
473 | 464 | def sleepfunc(interval=2,*a,**kw): |
|
474 | 465 | args = dict(interval=interval, |
|
475 | 466 | args=a, |
|
476 | 467 | kwargs=kw) |
|
477 | 468 | time.sleep(interval) |
|
478 | 469 | return args |
|
479 | 470 | |
|
480 | 471 | def diefunc(interval=2,*a,**kw): |
|
481 | 472 | time.sleep(interval) |
|
482 | 473 | die |
|
483 | 474 | |
|
484 | 475 | def printfunc(interval=1,reps=5): |
|
485 | 476 | for n in range(reps): |
|
486 | 477 | time.sleep(interval) |
|
487 | 478 | print 'In the background...' |
|
488 | 479 | |
|
489 | 480 | jobs = BackgroundJobManager() |
|
490 | 481 | # first job will have # 0 |
|
491 | 482 | jobs.new(sleepfunc,4) |
|
492 | 483 | jobs.new(sleepfunc,kw={'reps':2}) |
|
493 | 484 | # This makes a job which will die |
|
494 | 485 | jobs.new(diefunc,1) |
|
495 | 486 | jobs.new('printfunc(1,3)') |
|
496 | 487 | |
|
497 | 488 | # after a while, you can get the traceback of a dead job. Run the line |
|
498 | 489 | # below again interactively until it prints a traceback (check the status |
|
499 | 490 | # of the job): |
|
500 | 491 | print jobs[1].status |
|
501 | 492 | jobs[1].traceback() |
|
502 | 493 | |
|
503 | 494 | # Run this line again until the printed result changes |
|
504 | 495 | print "The result of job #0 is:",jobs[0].result |
@@ -1,1519 +1,1508 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """ |
|
3 | 3 | General purpose utilities. |
|
4 | 4 | |
|
5 | 5 | This is a grab-bag of stuff I find useful in most programs I write. Some of |
|
6 | 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 | 11 | # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu> |
|
12 | 12 | # |
|
13 | 13 | # Distributed under the terms of the BSD License. The full license is in |
|
14 | 14 | # the file COPYING, distributed as part of this software. |
|
15 | 15 | #***************************************************************************** |
|
16 | 16 | |
|
17 | 17 | from IPython import Release |
|
18 | 18 | __author__ = '%s <%s>' % Release.authors['Fernando'] |
|
19 | 19 | __license__ = Release.license |
|
20 | 20 | |
|
21 | 21 | #**************************************************************************** |
|
22 | 22 | # required modules |
|
23 | 23 | import __main__ |
|
24 | 24 | import types,commands,time,sys,os,re,shutil |
|
25 | 25 | import tempfile |
|
26 | import codecs | |
|
26 | 27 | from IPython.Itpl import Itpl,itpl,printpl |
|
27 | 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 | 54 | # Exceptions |
|
31 | 55 | class Error(Exception): |
|
32 | 56 | """Base class for exceptions in this module.""" |
|
33 | 57 | pass |
|
34 | 58 | |
|
35 | 59 | #---------------------------------------------------------------------------- |
|
36 | class Stream: | |
|
37 | """Simple class to hold the various I/O streams in Term""" | |
|
38 | ||
|
39 | def __init__(self,stream,name): | |
|
60 | class IOStream: | |
|
61 | def __init__(self,stream,fallback): | |
|
62 | if not hasattr(stream,'write') or not hasattr(stream,'flush'): | |
|
63 | stream = fallback | |
|
40 | 64 | self.stream = stream |
|
41 |
self. |
|
|
42 | try: | |
|
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 | |
|
65 | self._swrite = stream.write | |
|
66 | self.flush = stream.flush | |
|
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 | 83 | """ Term holds the file or file-like objects for handling I/O operations. |
|
57 | 84 | |
|
58 | 85 | These are normally just sys.stdin, sys.stdout and sys.stderr but for |
|
59 | 86 | Windows they can can replaced to allow editing the strings before they are |
|
60 | 87 | displayed.""" |
|
61 | 88 | |
|
62 | 89 | # In the future, having IPython channel all its I/O operations through |
|
63 | 90 | # this class will make it easier to embed it into other environments which |
|
64 | 91 | # are not a normal terminal (such as a GUI-based shell) |
|
65 | in_s = Stream(sys.stdin,'cin') | |
|
66 | out_s = Stream(sys.stdout,'cout') | |
|
67 | err_s = Stream(sys.stderr,'cerr') | |
|
68 | ||
|
69 | # Store the three streams in (err,out,in) order so that if we need to reopen | |
|
70 | # them, the error channel is reopened first to provide info. | |
|
71 | streams = [err_s,out_s,in_s] | |
|
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) | |
|
92 | def __init__(self,cin=None,cout=None,cerr=None): | |
|
93 | self.cin = IOStream(cin,sys.stdin) | |
|
94 | self.cout = IOStream(cout,sys.stdout) | |
|
95 | self.cerr = IOStream(cerr,sys.stderr) | |
|
96 | ||
|
97 | # Global variable to be used for all I/O | |
|
98 | Term = IOTerm() | |
|
110 | 99 | |
|
111 | 100 | # Windows-specific code to load Gary Bishop's readline and configure it |
|
112 | 101 | # automatically for the users |
|
113 | 102 | # Note: os.name on cygwin returns posix, so this should only pick up 'native' |
|
114 | 103 | # windows. Cygwin returns 'cygwin' for sys.platform. |
|
115 | 104 | if os.name == 'nt': |
|
116 | 105 | try: |
|
117 | 106 | import readline |
|
118 | 107 | except ImportError: |
|
119 | 108 | pass |
|
120 | 109 | else: |
|
121 | 110 | try: |
|
122 | 111 | _out = readline.GetOutputFile() |
|
123 | 112 | except AttributeError: |
|
124 | 113 | pass |
|
125 | 114 | else: |
|
126 | Term.set_stdout(_out) | |
|
127 |
Term |
|
|
115 | # Remake Term to use the readline i/o facilities | |
|
116 | Term = IOTerm(cout=_out,cerr=_out) | |
|
128 | 117 | del _out |
|
129 | 118 | |
|
130 | 119 | #**************************************************************************** |
|
131 | 120 | # Generic warning/error printer, used by everything else |
|
132 | 121 | def warn(msg,level=2,exit_val=1): |
|
133 | 122 | """Standard warning printer. Gives formatting consistency. |
|
134 | 123 | |
|
135 | 124 | Output is sent to Term.cerr (sys.stderr by default). |
|
136 | 125 | |
|
137 | 126 | Options: |
|
138 | 127 | |
|
139 | 128 | -level(2): allows finer control: |
|
140 | 129 | 0 -> Do nothing, dummy function. |
|
141 | 130 | 1 -> Print message. |
|
142 | 131 | 2 -> Print 'WARNING:' + message. (Default level). |
|
143 | 132 | 3 -> Print 'ERROR:' + message. |
|
144 | 133 | 4 -> Print 'FATAL ERROR:' + message and trigger a sys.exit(exit_val). |
|
145 | 134 | |
|
146 | 135 | -exit_val (1): exit value returned by sys.exit() for a level 4 |
|
147 | 136 | warning. Ignored for all other levels.""" |
|
148 | 137 | |
|
149 | 138 | if level>0: |
|
150 | 139 | header = ['','','WARNING: ','ERROR: ','FATAL ERROR: '] |
|
151 | 140 | print >> Term.cerr, '%s%s' % (header[level],msg) |
|
152 | 141 | if level == 4: |
|
153 | 142 | print >> Term.cerr,'Exiting.\n' |
|
154 | 143 | sys.exit(exit_val) |
|
155 | 144 | |
|
156 | 145 | def info(msg): |
|
157 | 146 | """Equivalent to warn(msg,level=1).""" |
|
158 | 147 | |
|
159 | 148 | warn(msg,level=1) |
|
160 | 149 | |
|
161 | 150 | def error(msg): |
|
162 | 151 | """Equivalent to warn(msg,level=3).""" |
|
163 | 152 | |
|
164 | 153 | warn(msg,level=3) |
|
165 | 154 | |
|
166 | 155 | def fatal(msg,exit_val=1): |
|
167 | 156 | """Equivalent to warn(msg,exit_val=exit_val,level=4).""" |
|
168 | 157 | |
|
169 | 158 | warn(msg,exit_val=exit_val,level=4) |
|
170 | 159 | |
|
171 | 160 | #---------------------------------------------------------------------------- |
|
172 | 161 | StringTypes = types.StringTypes |
|
173 | 162 | |
|
174 | 163 | # Basic timing functionality |
|
175 | 164 | |
|
176 | 165 | # If possible (Unix), use the resource module instead of time.clock() |
|
177 | 166 | try: |
|
178 | 167 | import resource |
|
179 | 168 | def clock(): |
|
180 | 169 | """clock() -> floating point number |
|
181 | 170 | |
|
182 | 171 | Return the CPU time in seconds (user time only, system time is |
|
183 | 172 | ignored) since the start of the process. This is done via a call to |
|
184 | 173 | resource.getrusage, so it avoids the wraparound problems in |
|
185 | 174 | time.clock().""" |
|
186 | 175 | |
|
187 | 176 | return resource.getrusage(resource.RUSAGE_SELF)[0] |
|
188 | 177 | |
|
189 | 178 | def clock2(): |
|
190 | 179 | """clock2() -> (t_user,t_system) |
|
191 | 180 | |
|
192 | 181 | Similar to clock(), but return a tuple of user/system times.""" |
|
193 | 182 | return resource.getrusage(resource.RUSAGE_SELF)[:2] |
|
194 | 183 | |
|
195 | 184 | except ImportError: |
|
196 | 185 | clock = time.clock |
|
197 | 186 | def clock2(): |
|
198 | 187 | """Under windows, system CPU time can't be measured. |
|
199 | 188 | |
|
200 | 189 | This just returns clock() and zero.""" |
|
201 | 190 | return time.clock(),0.0 |
|
202 | 191 | |
|
203 | 192 | def timings_out(reps,func,*args,**kw): |
|
204 | 193 | """timings_out(reps,func,*args,**kw) -> (t_total,t_per_call,output) |
|
205 | 194 | |
|
206 | 195 | Execute a function reps times, return a tuple with the elapsed total |
|
207 | 196 | CPU time in seconds, the time per call and the function's output. |
|
208 | 197 | |
|
209 | 198 | Under Unix, the return value is the sum of user+system time consumed by |
|
210 | 199 | the process, computed via the resource module. This prevents problems |
|
211 | 200 | related to the wraparound effect which the time.clock() function has. |
|
212 | 201 | |
|
213 | 202 | Under Windows the return value is in wall clock seconds. See the |
|
214 | 203 | documentation for the time module for more details.""" |
|
215 | 204 | |
|
216 | 205 | reps = int(reps) |
|
217 | 206 | assert reps >=1, 'reps must be >= 1' |
|
218 | 207 | if reps==1: |
|
219 | 208 | start = clock() |
|
220 | 209 | out = func(*args,**kw) |
|
221 | 210 | tot_time = clock()-start |
|
222 | 211 | else: |
|
223 | 212 | rng = xrange(reps-1) # the last time is executed separately to store output |
|
224 | 213 | start = clock() |
|
225 | 214 | for dummy in rng: func(*args,**kw) |
|
226 | 215 | out = func(*args,**kw) # one last time |
|
227 | 216 | tot_time = clock()-start |
|
228 | 217 | av_time = tot_time / reps |
|
229 | 218 | return tot_time,av_time,out |
|
230 | 219 | |
|
231 | 220 | def timings(reps,func,*args,**kw): |
|
232 | 221 | """timings(reps,func,*args,**kw) -> (t_total,t_per_call) |
|
233 | 222 | |
|
234 | 223 | Execute a function reps times, return a tuple with the elapsed total CPU |
|
235 | 224 | time in seconds and the time per call. These are just the first two values |
|
236 | 225 | in timings_out().""" |
|
237 | 226 | |
|
238 | 227 | return timings_out(reps,func,*args,**kw)[0:2] |
|
239 | 228 | |
|
240 | 229 | def timing(func,*args,**kw): |
|
241 | 230 | """timing(func,*args,**kw) -> t_total |
|
242 | 231 | |
|
243 | 232 | Execute a function once, return the elapsed total CPU time in |
|
244 | 233 | seconds. This is just the first value in timings_out().""" |
|
245 | 234 | |
|
246 | 235 | return timings_out(1,func,*args,**kw)[0] |
|
247 | 236 | |
|
248 | 237 | #**************************************************************************** |
|
249 | 238 | # file and system |
|
250 | 239 | |
|
251 | 240 | def system(cmd,verbose=0,debug=0,header=''): |
|
252 | 241 | """Execute a system command, return its exit status. |
|
253 | 242 | |
|
254 | 243 | Options: |
|
255 | 244 | |
|
256 | 245 | - verbose (0): print the command to be executed. |
|
257 | 246 | |
|
258 | 247 | - debug (0): only print, do not actually execute. |
|
259 | 248 | |
|
260 | 249 | - header (''): Header to print on screen prior to the executed command (it |
|
261 | 250 | is only prepended to the command, no newlines are added). |
|
262 | 251 | |
|
263 | 252 | Note: a stateful version of this function is available through the |
|
264 | 253 | SystemExec class.""" |
|
265 | 254 | |
|
266 | 255 | stat = 0 |
|
267 | 256 | if verbose or debug: print header+cmd |
|
268 | 257 | sys.stdout.flush() |
|
269 | 258 | if not debug: stat = os.system(cmd) |
|
270 | 259 | return stat |
|
271 | 260 | |
|
272 | 261 | def shell(cmd,verbose=0,debug=0,header=''): |
|
273 | 262 | """Execute a command in the system shell, always return None. |
|
274 | 263 | |
|
275 | 264 | Options: |
|
276 | 265 | |
|
277 | 266 | - verbose (0): print the command to be executed. |
|
278 | 267 | |
|
279 | 268 | - debug (0): only print, do not actually execute. |
|
280 | 269 | |
|
281 | 270 | - header (''): Header to print on screen prior to the executed command (it |
|
282 | 271 | is only prepended to the command, no newlines are added). |
|
283 | 272 | |
|
284 | 273 | Note: this is similar to genutils.system(), but it returns None so it can |
|
285 | 274 | be conveniently used in interactive loops without getting the return value |
|
286 | 275 | (typically 0) printed many times.""" |
|
287 | 276 | |
|
288 | 277 | stat = 0 |
|
289 | 278 | if verbose or debug: print header+cmd |
|
290 | 279 | # flush stdout so we don't mangle python's buffering |
|
291 | 280 | sys.stdout.flush() |
|
292 | 281 | if not debug: |
|
293 | 282 | os.system(cmd) |
|
294 | 283 | |
|
295 | 284 | def getoutput(cmd,verbose=0,debug=0,header='',split=0): |
|
296 | 285 | """Dummy substitute for perl's backquotes. |
|
297 | 286 | |
|
298 | 287 | Executes a command and returns the output. |
|
299 | 288 | |
|
300 | 289 | Accepts the same arguments as system(), plus: |
|
301 | 290 | |
|
302 | 291 | - split(0): if true, the output is returned as a list split on newlines. |
|
303 | 292 | |
|
304 | 293 | Note: a stateful version of this function is available through the |
|
305 | 294 | SystemExec class.""" |
|
306 | 295 | |
|
307 | 296 | if verbose or debug: print header+cmd |
|
308 | 297 | if not debug: |
|
309 | 298 | output = commands.getoutput(cmd) |
|
310 | 299 | if split: |
|
311 | 300 | return output.split('\n') |
|
312 | 301 | else: |
|
313 | 302 | return output |
|
314 | 303 | |
|
315 | 304 | def getoutputerror(cmd,verbose=0,debug=0,header='',split=0): |
|
316 | 305 | """Return (standard output,standard error) of executing cmd in a shell. |
|
317 | 306 | |
|
318 | 307 | Accepts the same arguments as system(), plus: |
|
319 | 308 | |
|
320 | 309 | - split(0): if true, each of stdout/err is returned as a list split on |
|
321 | 310 | newlines. |
|
322 | 311 | |
|
323 | 312 | Note: a stateful version of this function is available through the |
|
324 | 313 | SystemExec class.""" |
|
325 | 314 | |
|
326 | 315 | if verbose or debug: print header+cmd |
|
327 | 316 | if not cmd: |
|
328 | 317 | if split: |
|
329 | 318 | return [],[] |
|
330 | 319 | else: |
|
331 | 320 | return '','' |
|
332 | 321 | if not debug: |
|
333 | 322 | pin,pout,perr = os.popen3(cmd) |
|
334 | 323 | tout = pout.read().rstrip() |
|
335 | 324 | terr = perr.read().rstrip() |
|
336 | 325 | pin.close() |
|
337 | 326 | pout.close() |
|
338 | 327 | perr.close() |
|
339 | 328 | if split: |
|
340 | 329 | return tout.split('\n'),terr.split('\n') |
|
341 | 330 | else: |
|
342 | 331 | return tout,terr |
|
343 | 332 | |
|
344 | 333 | # for compatibility with older naming conventions |
|
345 | 334 | xsys = system |
|
346 | 335 | bq = getoutput |
|
347 | 336 | |
|
348 | 337 | class SystemExec: |
|
349 | 338 | """Access the system and getoutput functions through a stateful interface. |
|
350 | 339 | |
|
351 | 340 | Note: here we refer to the system and getoutput functions from this |
|
352 | 341 | library, not the ones from the standard python library. |
|
353 | 342 | |
|
354 | 343 | This class offers the system and getoutput functions as methods, but the |
|
355 | 344 | verbose, debug and header parameters can be set for the instance (at |
|
356 | 345 | creation time or later) so that they don't need to be specified on each |
|
357 | 346 | call. |
|
358 | 347 | |
|
359 | 348 | For efficiency reasons, there's no way to override the parameters on a |
|
360 | 349 | per-call basis other than by setting instance attributes. If you need |
|
361 | 350 | local overrides, it's best to directly call system() or getoutput(). |
|
362 | 351 | |
|
363 | 352 | The following names are provided as alternate options: |
|
364 | 353 | - xsys: alias to system |
|
365 | 354 | - bq: alias to getoutput |
|
366 | 355 | |
|
367 | 356 | An instance can then be created as: |
|
368 | 357 | >>> sysexec = SystemExec(verbose=1,debug=0,header='Calling: ') |
|
369 | 358 | |
|
370 | 359 | And used as: |
|
371 | 360 | >>> sysexec.xsys('pwd') |
|
372 | 361 | >>> dirlist = sysexec.bq('ls -l') |
|
373 | 362 | """ |
|
374 | 363 | |
|
375 | 364 | def __init__(self,verbose=0,debug=0,header='',split=0): |
|
376 | 365 | """Specify the instance's values for verbose, debug and header.""" |
|
377 | 366 | setattr_list(self,'verbose debug header split') |
|
378 | 367 | |
|
379 | 368 | def system(self,cmd): |
|
380 | 369 | """Stateful interface to system(), with the same keyword parameters.""" |
|
381 | 370 | |
|
382 | 371 | system(cmd,self.verbose,self.debug,self.header) |
|
383 | 372 | |
|
384 | 373 | def shell(self,cmd): |
|
385 | 374 | """Stateful interface to shell(), with the same keyword parameters.""" |
|
386 | 375 | |
|
387 | 376 | shell(cmd,self.verbose,self.debug,self.header) |
|
388 | 377 | |
|
389 | 378 | xsys = system # alias |
|
390 | 379 | |
|
391 | 380 | def getoutput(self,cmd): |
|
392 | 381 | """Stateful interface to getoutput().""" |
|
393 | 382 | |
|
394 | 383 | return getoutput(cmd,self.verbose,self.debug,self.header,self.split) |
|
395 | 384 | |
|
396 | 385 | def getoutputerror(self,cmd): |
|
397 | 386 | """Stateful interface to getoutputerror().""" |
|
398 | 387 | |
|
399 | 388 | return getoutputerror(cmd,self.verbose,self.debug,self.header,self.split) |
|
400 | 389 | |
|
401 | 390 | bq = getoutput # alias |
|
402 | 391 | |
|
403 | 392 | #----------------------------------------------------------------------------- |
|
404 | 393 | def mutex_opts(dict,ex_op): |
|
405 | 394 | """Check for presence of mutually exclusive keys in a dict. |
|
406 | 395 | |
|
407 | 396 | Call: mutex_opts(dict,[[op1a,op1b],[op2a,op2b]...]""" |
|
408 | 397 | for op1,op2 in ex_op: |
|
409 | 398 | if op1 in dict and op2 in dict: |
|
410 | 399 | raise ValueError,'\n*** ERROR in Arguments *** '\ |
|
411 | 400 | 'Options '+op1+' and '+op2+' are mutually exclusive.' |
|
412 | 401 | |
|
413 | 402 | #----------------------------------------------------------------------------- |
|
414 | 403 | def filefind(fname,alt_dirs = None): |
|
415 | 404 | """Return the given filename either in the current directory, if it |
|
416 | 405 | exists, or in a specified list of directories. |
|
417 | 406 | |
|
418 | 407 | ~ expansion is done on all file and directory names. |
|
419 | 408 | |
|
420 | 409 | Upon an unsuccessful search, raise an IOError exception.""" |
|
421 | 410 | |
|
422 | 411 | if alt_dirs is None: |
|
423 | 412 | try: |
|
424 | 413 | alt_dirs = get_home_dir() |
|
425 | 414 | except HomeDirError: |
|
426 | 415 | alt_dirs = os.getcwd() |
|
427 | 416 | search = [fname] + list_strings(alt_dirs) |
|
428 | 417 | search = map(os.path.expanduser,search) |
|
429 | 418 | #print 'search list for',fname,'list:',search # dbg |
|
430 | 419 | fname = search[0] |
|
431 | 420 | if os.path.isfile(fname): |
|
432 | 421 | return fname |
|
433 | 422 | for direc in search[1:]: |
|
434 | 423 | testname = os.path.join(direc,fname) |
|
435 | 424 | #print 'testname',testname # dbg |
|
436 | 425 | if os.path.isfile(testname): |
|
437 | 426 | return testname |
|
438 | 427 | raise IOError,'File' + `fname` + \ |
|
439 | 428 | ' not found in current or supplied directories:' + `alt_dirs` |
|
440 | 429 | |
|
441 | 430 | #---------------------------------------------------------------------------- |
|
442 | 431 | def target_outdated(target,deps): |
|
443 | 432 | """Determine whether a target is out of date. |
|
444 | 433 | |
|
445 | 434 | target_outdated(target,deps) -> 1/0 |
|
446 | 435 | |
|
447 | 436 | deps: list of filenames which MUST exist. |
|
448 | 437 | target: single filename which may or may not exist. |
|
449 | 438 | |
|
450 | 439 | If target doesn't exist or is older than any file listed in deps, return |
|
451 | 440 | true, otherwise return false. |
|
452 | 441 | """ |
|
453 | 442 | try: |
|
454 | 443 | target_time = os.path.getmtime(target) |
|
455 | 444 | except os.error: |
|
456 | 445 | return 1 |
|
457 | 446 | for dep in deps: |
|
458 | 447 | dep_time = os.path.getmtime(dep) |
|
459 | 448 | if dep_time > target_time: |
|
460 | 449 | #print "For target",target,"Dep failed:",dep # dbg |
|
461 | 450 | #print "times (dep,tar):",dep_time,target_time # dbg |
|
462 | 451 | return 1 |
|
463 | 452 | return 0 |
|
464 | 453 | |
|
465 | 454 | #----------------------------------------------------------------------------- |
|
466 | 455 | def target_update(target,deps,cmd): |
|
467 | 456 | """Update a target with a given command given a list of dependencies. |
|
468 | 457 | |
|
469 | 458 | target_update(target,deps,cmd) -> runs cmd if target is outdated. |
|
470 | 459 | |
|
471 | 460 | This is just a wrapper around target_outdated() which calls the given |
|
472 | 461 | command if target is outdated.""" |
|
473 | 462 | |
|
474 | 463 | if target_outdated(target,deps): |
|
475 | 464 | xsys(cmd) |
|
476 | 465 | |
|
477 | 466 | #---------------------------------------------------------------------------- |
|
478 | 467 | def unquote_ends(istr): |
|
479 | 468 | """Remove a single pair of quotes from the endpoints of a string.""" |
|
480 | 469 | |
|
481 | 470 | if not istr: |
|
482 | 471 | return istr |
|
483 | 472 | if (istr[0]=="'" and istr[-1]=="'") or \ |
|
484 | 473 | (istr[0]=='"' and istr[-1]=='"'): |
|
485 | 474 | return istr[1:-1] |
|
486 | 475 | else: |
|
487 | 476 | return istr |
|
488 | 477 | |
|
489 | 478 | #---------------------------------------------------------------------------- |
|
490 | 479 | def process_cmdline(argv,names=[],defaults={},usage=''): |
|
491 | 480 | """ Process command-line options and arguments. |
|
492 | 481 | |
|
493 | 482 | Arguments: |
|
494 | 483 | |
|
495 | 484 | - argv: list of arguments, typically sys.argv. |
|
496 | 485 | |
|
497 | 486 | - names: list of option names. See DPyGetOpt docs for details on options |
|
498 | 487 | syntax. |
|
499 | 488 | |
|
500 | 489 | - defaults: dict of default values. |
|
501 | 490 | |
|
502 | 491 | - usage: optional usage notice to print if a wrong argument is passed. |
|
503 | 492 | |
|
504 | 493 | Return a dict of options and a list of free arguments.""" |
|
505 | 494 | |
|
506 | 495 | getopt = DPyGetOpt.DPyGetOpt() |
|
507 | 496 | getopt.setIgnoreCase(0) |
|
508 | 497 | getopt.parseConfiguration(names) |
|
509 | 498 | |
|
510 | 499 | try: |
|
511 | 500 | getopt.processArguments(argv) |
|
512 | 501 | except: |
|
513 | 502 | print usage |
|
514 | 503 | warn(`sys.exc_value`,level=4) |
|
515 | 504 | |
|
516 | 505 | defaults.update(getopt.optionValues) |
|
517 | 506 | args = getopt.freeValues |
|
518 | 507 | |
|
519 | 508 | return defaults,args |
|
520 | 509 | |
|
521 | 510 | #---------------------------------------------------------------------------- |
|
522 | 511 | def optstr2types(ostr): |
|
523 | 512 | """Convert a string of option names to a dict of type mappings. |
|
524 | 513 | |
|
525 | 514 | optstr2types(str) -> {None:'string_opts',int:'int_opts',float:'float_opts'} |
|
526 | 515 | |
|
527 | 516 | This is used to get the types of all the options in a string formatted |
|
528 | 517 | with the conventions of DPyGetOpt. The 'type' None is used for options |
|
529 | 518 | which are strings (they need no further conversion). This function's main |
|
530 | 519 | use is to get a typemap for use with read_dict(). |
|
531 | 520 | """ |
|
532 | 521 | |
|
533 | 522 | typeconv = {None:'',int:'',float:''} |
|
534 | 523 | typemap = {'s':None,'i':int,'f':float} |
|
535 | 524 | opt_re = re.compile(r'([\w]*)([^:=]*:?=?)([sif]?)') |
|
536 | 525 | |
|
537 | 526 | for w in ostr.split(): |
|
538 | 527 | oname,alias,otype = opt_re.match(w).groups() |
|
539 | 528 | if otype == '' or alias == '!': # simple switches are integers too |
|
540 | 529 | otype = 'i' |
|
541 | 530 | typeconv[typemap[otype]] += oname + ' ' |
|
542 | 531 | return typeconv |
|
543 | 532 | |
|
544 | 533 | #---------------------------------------------------------------------------- |
|
545 | 534 | def read_dict(filename,type_conv=None,**opt): |
|
546 | 535 | |
|
547 | 536 | """Read a dictionary of key=value pairs from an input file, optionally |
|
548 | 537 | performing conversions on the resulting values. |
|
549 | 538 | |
|
550 | 539 | read_dict(filename,type_conv,**opt) -> dict |
|
551 | 540 | |
|
552 | 541 | Only one value per line is accepted, the format should be |
|
553 | 542 | # optional comments are ignored |
|
554 | 543 | key value\n |
|
555 | 544 | |
|
556 | 545 | Args: |
|
557 | 546 | |
|
558 | 547 | - type_conv: A dictionary specifying which keys need to be converted to |
|
559 | 548 | which types. By default all keys are read as strings. This dictionary |
|
560 | 549 | should have as its keys valid conversion functions for strings |
|
561 | 550 | (int,long,float,complex, or your own). The value for each key |
|
562 | 551 | (converter) should be a whitespace separated string containing the names |
|
563 | 552 | of all the entries in the file to be converted using that function. For |
|
564 | 553 | keys to be left alone, use None as the conversion function (only needed |
|
565 | 554 | with purge=1, see below). |
|
566 | 555 | |
|
567 | 556 | - opt: dictionary with extra options as below (default in parens) |
|
568 | 557 | |
|
569 | 558 | purge(0): if set to 1, all keys *not* listed in type_conv are purged out |
|
570 | 559 | of the dictionary to be returned. If purge is going to be used, the |
|
571 | 560 | set of keys to be left as strings also has to be explicitly specified |
|
572 | 561 | using the (non-existent) conversion function None. |
|
573 | 562 | |
|
574 | 563 | fs(None): field separator. This is the key/value separator to be used |
|
575 | 564 | when parsing the file. The None default means any whitespace [behavior |
|
576 | 565 | of string.split()]. |
|
577 | 566 | |
|
578 | 567 | strip(0): if 1, strip string values of leading/trailinig whitespace. |
|
579 | 568 | |
|
580 | 569 | warn(1): warning level if requested keys are not found in file. |
|
581 | 570 | - 0: silently ignore. |
|
582 | 571 | - 1: inform but proceed. |
|
583 | 572 | - 2: raise KeyError exception. |
|
584 | 573 | |
|
585 | 574 | no_empty(0): if 1, remove keys with whitespace strings as a value. |
|
586 | 575 | |
|
587 | 576 | unique([]): list of keys (or space separated string) which can't be |
|
588 | 577 | repeated. If one such key is found in the file, each new instance |
|
589 | 578 | overwrites the previous one. For keys not listed here, the behavior is |
|
590 | 579 | to make a list of all appearances. |
|
591 | 580 | |
|
592 | 581 | Example: |
|
593 | 582 | If the input file test.ini has: |
|
594 | 583 | i 3 |
|
595 | 584 | x 4.5 |
|
596 | 585 | y 5.5 |
|
597 | 586 | s hi ho |
|
598 | 587 | Then: |
|
599 | 588 | |
|
600 | 589 | >>> type_conv={int:'i',float:'x',None:'s'} |
|
601 | 590 | >>> read_dict('test.ini') |
|
602 | 591 | {'i': '3', 's': 'hi ho', 'x': '4.5', 'y': '5.5'} |
|
603 | 592 | >>> read_dict('test.ini',type_conv) |
|
604 | 593 | {'i': 3, 's': 'hi ho', 'x': 4.5, 'y': '5.5'} |
|
605 | 594 | >>> read_dict('test.ini',type_conv,purge=1) |
|
606 | 595 | {'i': 3, 's': 'hi ho', 'x': 4.5} |
|
607 | 596 | """ |
|
608 | 597 | |
|
609 | 598 | # starting config |
|
610 | 599 | opt.setdefault('purge',0) |
|
611 | 600 | opt.setdefault('fs',None) # field sep defaults to any whitespace |
|
612 | 601 | opt.setdefault('strip',0) |
|
613 | 602 | opt.setdefault('warn',1) |
|
614 | 603 | opt.setdefault('no_empty',0) |
|
615 | 604 | opt.setdefault('unique','') |
|
616 | 605 | if type(opt['unique']) in StringTypes: |
|
617 | 606 | unique_keys = qw(opt['unique']) |
|
618 | 607 | elif type(opt['unique']) in (types.TupleType,types.ListType): |
|
619 | 608 | unique_keys = opt['unique'] |
|
620 | 609 | else: |
|
621 | 610 | raise ValueError, 'Unique keys must be given as a string, List or Tuple' |
|
622 | 611 | |
|
623 | 612 | dict = {} |
|
624 | 613 | # first read in table of values as strings |
|
625 | 614 | file = open(filename,'r') |
|
626 | 615 | for line in file.readlines(): |
|
627 | 616 | line = line.strip() |
|
628 | 617 | if len(line) and line[0]=='#': continue |
|
629 | 618 | if len(line)>0: |
|
630 | 619 | lsplit = line.split(opt['fs'],1) |
|
631 | 620 | try: |
|
632 | 621 | key,val = lsplit |
|
633 | 622 | except ValueError: |
|
634 | 623 | key,val = lsplit[0],'' |
|
635 | 624 | key = key.strip() |
|
636 | 625 | if opt['strip']: val = val.strip() |
|
637 | 626 | if val == "''" or val == '""': val = '' |
|
638 | 627 | if opt['no_empty'] and (val=='' or val.isspace()): |
|
639 | 628 | continue |
|
640 | 629 | # if a key is found more than once in the file, build a list |
|
641 | 630 | # unless it's in the 'unique' list. In that case, last found in file |
|
642 | 631 | # takes precedence. User beware. |
|
643 | 632 | try: |
|
644 | 633 | if dict[key] and key in unique_keys: |
|
645 | 634 | dict[key] = val |
|
646 | 635 | elif type(dict[key]) is types.ListType: |
|
647 | 636 | dict[key].append(val) |
|
648 | 637 | else: |
|
649 | 638 | dict[key] = [dict[key],val] |
|
650 | 639 | except KeyError: |
|
651 | 640 | dict[key] = val |
|
652 | 641 | # purge if requested |
|
653 | 642 | if opt['purge']: |
|
654 | 643 | accepted_keys = qwflat(type_conv.values()) |
|
655 | 644 | for key in dict.keys(): |
|
656 | 645 | if key in accepted_keys: continue |
|
657 | 646 | del(dict[key]) |
|
658 | 647 | # now convert if requested |
|
659 | 648 | if type_conv==None: return dict |
|
660 | 649 | conversions = type_conv.keys() |
|
661 | 650 | try: conversions.remove(None) |
|
662 | 651 | except: pass |
|
663 | 652 | for convert in conversions: |
|
664 | 653 | for val in qw(type_conv[convert]): |
|
665 | 654 | try: |
|
666 | 655 | dict[val] = convert(dict[val]) |
|
667 | 656 | except KeyError,e: |
|
668 | 657 | if opt['warn'] == 0: |
|
669 | 658 | pass |
|
670 | 659 | elif opt['warn'] == 1: |
|
671 | 660 | print >>sys.stderr, 'Warning: key',val,\ |
|
672 | 661 | 'not found in file',filename |
|
673 | 662 | elif opt['warn'] == 2: |
|
674 | 663 | raise KeyError,e |
|
675 | 664 | else: |
|
676 | 665 | raise ValueError,'Warning level must be 0,1 or 2' |
|
677 | 666 | |
|
678 | 667 | return dict |
|
679 | 668 | |
|
680 | 669 | #---------------------------------------------------------------------------- |
|
681 | 670 | def flag_calls(func): |
|
682 | 671 | """Wrap a function to detect and flag when it gets called. |
|
683 | 672 | |
|
684 | 673 | This is a decorator which takes a function and wraps it in a function with |
|
685 | 674 | a 'called' attribute. wrapper.called is initialized to False. |
|
686 | 675 | |
|
687 | 676 | The wrapper.called attribute is set to False right before each call to the |
|
688 | 677 | wrapped function, so if the call fails it remains False. After the call |
|
689 | 678 | completes, wrapper.called is set to True and the output is returned. |
|
690 | 679 | |
|
691 | 680 | Testing for truth in wrapper.called allows you to determine if a call to |
|
692 | 681 | func() was attempted and succeeded.""" |
|
693 | 682 | |
|
694 | 683 | def wrapper(*args,**kw): |
|
695 | 684 | wrapper.called = False |
|
696 | 685 | out = func(*args,**kw) |
|
697 | 686 | wrapper.called = True |
|
698 | 687 | return out |
|
699 | 688 | |
|
700 | 689 | wrapper.called = False |
|
701 | 690 | wrapper.__doc__ = func.__doc__ |
|
702 | 691 | return wrapper |
|
703 | 692 | |
|
704 | 693 | #---------------------------------------------------------------------------- |
|
705 | 694 | class HomeDirError(Error): |
|
706 | 695 | pass |
|
707 | 696 | |
|
708 | 697 | def get_home_dir(): |
|
709 | 698 | """Return the closest possible equivalent to a 'home' directory. |
|
710 | 699 | |
|
711 | 700 | We first try $HOME. Absent that, on NT it's $HOMEDRIVE\$HOMEPATH. |
|
712 | 701 | |
|
713 | 702 | Currently only Posix and NT are implemented, a HomeDirError exception is |
|
714 | 703 | raised for all other OSes. """ |
|
715 | 704 | |
|
716 | 705 | try: |
|
717 | 706 | return os.environ['HOME'] |
|
718 | 707 | except KeyError: |
|
719 | 708 | if os.name == 'posix': |
|
720 | 709 | raise HomeDirError,'undefined $HOME, IPython can not proceed.' |
|
721 | 710 | elif os.name == 'nt': |
|
722 | 711 | # For some strange reason, win9x returns 'nt' for os.name. |
|
723 | 712 | try: |
|
724 | 713 | return os.path.join(os.environ['HOMEDRIVE'],os.environ['HOMEPATH']) |
|
725 | 714 | except: |
|
726 | 715 | try: |
|
727 | 716 | # Use the registry to get the 'My Documents' folder. |
|
728 | 717 | import _winreg as wreg |
|
729 | 718 | key = wreg.OpenKey(wreg.HKEY_CURRENT_USER, |
|
730 | 719 | "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders") |
|
731 | 720 | homedir = wreg.QueryValueEx(key,'Personal')[0] |
|
732 | 721 | key.Close() |
|
733 | 722 | return homedir |
|
734 | 723 | except: |
|
735 | 724 | return 'C:\\' |
|
736 | 725 | elif os.name == 'dos': |
|
737 | 726 | # Desperate, may do absurd things in classic MacOS. May work under DOS. |
|
738 | 727 | return 'C:\\' |
|
739 | 728 | else: |
|
740 | 729 | raise HomeDirError,'support for your operating system not implemented.' |
|
741 | 730 | |
|
742 | 731 | #**************************************************************************** |
|
743 | 732 | # strings and text |
|
744 | 733 | |
|
745 | 734 | class LSString(str): |
|
746 | 735 | """String derivative with a special access attributes. |
|
747 | 736 | |
|
748 | 737 | These are normal strings, but with the special attributes: |
|
749 | 738 | |
|
750 | 739 | .l (or .list) : value as list (split on newlines). |
|
751 | 740 | .n (or .nlstr): original value (the string itself). |
|
752 | 741 | .s (or .spstr): value as whitespace-separated string. |
|
753 | 742 | |
|
754 | 743 | Any values which require transformations are computed only once and |
|
755 | 744 | cached. |
|
756 | 745 | |
|
757 | 746 | Such strings are very useful to efficiently interact with the shell, which |
|
758 | 747 | typically only understands whitespace-separated options for commands.""" |
|
759 | 748 | |
|
760 | 749 | def get_list(self): |
|
761 | 750 | try: |
|
762 | 751 | return self.__list |
|
763 | 752 | except AttributeError: |
|
764 | 753 | self.__list = self.split('\n') |
|
765 | 754 | return self.__list |
|
766 | 755 | |
|
767 | 756 | l = list = property(get_list) |
|
768 | 757 | |
|
769 | 758 | def get_spstr(self): |
|
770 | 759 | try: |
|
771 | 760 | return self.__spstr |
|
772 | 761 | except AttributeError: |
|
773 | 762 | self.__spstr = self.replace('\n',' ') |
|
774 | 763 | return self.__spstr |
|
775 | 764 | |
|
776 | 765 | s = spstr = property(get_spstr) |
|
777 | 766 | |
|
778 | 767 | def get_nlstr(self): |
|
779 | 768 | return self |
|
780 | 769 | |
|
781 | 770 | n = nlstr = property(get_nlstr) |
|
782 | 771 | |
|
783 | 772 | class SList(list): |
|
784 | 773 | """List derivative with a special access attributes. |
|
785 | 774 | |
|
786 | 775 | These are normal lists, but with the special attributes: |
|
787 | 776 | |
|
788 | 777 | .l (or .list) : value as list (the list itself). |
|
789 | 778 | .n (or .nlstr): value as a string, joined on newlines. |
|
790 | 779 | .s (or .spstr): value as a string, joined on spaces. |
|
791 | 780 | |
|
792 | 781 | Any values which require transformations are computed only once and |
|
793 | 782 | cached.""" |
|
794 | 783 | |
|
795 | 784 | def get_list(self): |
|
796 | 785 | return self |
|
797 | 786 | |
|
798 | 787 | l = list = property(get_list) |
|
799 | 788 | |
|
800 | 789 | def get_spstr(self): |
|
801 | 790 | try: |
|
802 | 791 | return self.__spstr |
|
803 | 792 | except AttributeError: |
|
804 | 793 | self.__spstr = ' '.join(self) |
|
805 | 794 | return self.__spstr |
|
806 | 795 | |
|
807 | 796 | s = spstr = property(get_spstr) |
|
808 | 797 | |
|
809 | 798 | def get_nlstr(self): |
|
810 | 799 | try: |
|
811 | 800 | return self.__nlstr |
|
812 | 801 | except AttributeError: |
|
813 | 802 | self.__nlstr = '\n'.join(self) |
|
814 | 803 | return self.__nlstr |
|
815 | 804 | |
|
816 | 805 | n = nlstr = property(get_nlstr) |
|
817 | 806 | |
|
818 | 807 | def raw_input_multi(header='', ps1='==> ', ps2='..> ',terminate_str = '.'): |
|
819 | 808 | """Take multiple lines of input. |
|
820 | 809 | |
|
821 | 810 | A list with each line of input as a separate element is returned when a |
|
822 | 811 | termination string is entered (defaults to a single '.'). Input can also |
|
823 | 812 | terminate via EOF (^D in Unix, ^Z-RET in Windows). |
|
824 | 813 | |
|
825 | 814 | Lines of input which end in \\ are joined into single entries (and a |
|
826 | 815 | secondary continuation prompt is issued as long as the user terminates |
|
827 | 816 | lines with \\). This allows entering very long strings which are still |
|
828 | 817 | meant to be treated as single entities. |
|
829 | 818 | """ |
|
830 | 819 | |
|
831 | 820 | try: |
|
832 | 821 | if header: |
|
833 | 822 | header += '\n' |
|
834 | 823 | lines = [raw_input(header + ps1)] |
|
835 | 824 | except EOFError: |
|
836 | 825 | return [] |
|
837 | 826 | terminate = [terminate_str] |
|
838 | 827 | try: |
|
839 | 828 | while lines[-1:] != terminate: |
|
840 | 829 | new_line = raw_input(ps1) |
|
841 | 830 | while new_line.endswith('\\'): |
|
842 | 831 | new_line = new_line[:-1] + raw_input(ps2) |
|
843 | 832 | lines.append(new_line) |
|
844 | 833 | |
|
845 | 834 | return lines[:-1] # don't return the termination command |
|
846 | 835 | except EOFError: |
|
847 | 836 | |
|
848 | 837 | return lines |
|
849 | 838 | |
|
850 | 839 | #---------------------------------------------------------------------------- |
|
851 | 840 | def raw_input_ext(prompt='', ps2='... '): |
|
852 | 841 | """Similar to raw_input(), but accepts extended lines if input ends with \\.""" |
|
853 | 842 | |
|
854 | 843 | line = raw_input(prompt) |
|
855 | 844 | while line.endswith('\\'): |
|
856 | 845 | line = line[:-1] + raw_input(ps2) |
|
857 | 846 | return line |
|
858 | 847 | |
|
859 | 848 | #---------------------------------------------------------------------------- |
|
860 | 849 | def ask_yes_no(prompt,default=None): |
|
861 | 850 | """Asks a question and returns an integer 1/0 (y/n) answer. |
|
862 | 851 | |
|
863 | 852 | If default is given (one of 'y','n'), it is used if the user input is |
|
864 | 853 | empty. Otherwise the question is repeated until an answer is given. |
|
865 | 854 | If EOF occurs 20 times consecutively, the default answer is assumed, |
|
866 | 855 | or if there is no default, an exception is raised to prevent infinite |
|
867 | 856 | loops. |
|
868 | 857 | |
|
869 | 858 | Valid answers are: y/yes/n/no (match is not case sensitive).""" |
|
870 | 859 | |
|
871 | 860 | answers = {'y':1,'n':0,'yes':1,'no':0} |
|
872 | 861 | ans = None |
|
873 | 862 | eofs, max_eofs = 0, 20 |
|
874 | 863 | while ans not in answers.keys(): |
|
875 | 864 | try: |
|
876 | 865 | ans = raw_input(prompt+' ').lower() |
|
877 | 866 | if not ans: # response was an empty string |
|
878 | 867 | ans = default |
|
879 | 868 | eofs = 0 |
|
880 | 869 | except (EOFError,KeyboardInterrupt): |
|
881 | 870 | eofs = eofs + 1 |
|
882 | 871 | if eofs >= max_eofs: |
|
883 | 872 | if default in answers.keys(): |
|
884 | 873 | ans = default |
|
885 | 874 | else: |
|
886 | 875 | raise |
|
887 | 876 | |
|
888 | 877 | return answers[ans] |
|
889 | 878 | |
|
890 | 879 | #---------------------------------------------------------------------------- |
|
891 | 880 | class EvalDict: |
|
892 | 881 | """ |
|
893 | 882 | Emulate a dict which evaluates its contents in the caller's frame. |
|
894 | 883 | |
|
895 | 884 | Usage: |
|
896 | 885 | >>>number = 19 |
|
897 | 886 | >>>text = "python" |
|
898 | 887 | >>>print "%(text.capitalize())s %(number/9.0).1f rules!" % EvalDict() |
|
899 | 888 | """ |
|
900 | 889 | |
|
901 | 890 | # This version is due to sismex01@hebmex.com on c.l.py, and is basically a |
|
902 | 891 | # modified (shorter) version of: |
|
903 | 892 | # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66018 by |
|
904 | 893 | # Skip Montanaro (skip@pobox.com). |
|
905 | 894 | |
|
906 | 895 | def __getitem__(self, name): |
|
907 | 896 | frame = sys._getframe(1) |
|
908 | 897 | return eval(name, frame.f_globals, frame.f_locals) |
|
909 | 898 | |
|
910 | 899 | EvalString = EvalDict # for backwards compatibility |
|
911 | 900 | #---------------------------------------------------------------------------- |
|
912 | 901 | def qw(words,flat=0,sep=None,maxsplit=-1): |
|
913 | 902 | """Similar to Perl's qw() operator, but with some more options. |
|
914 | 903 | |
|
915 | 904 | qw(words,flat=0,sep=' ',maxsplit=-1) -> words.split(sep,maxsplit) |
|
916 | 905 | |
|
917 | 906 | words can also be a list itself, and with flat=1, the output will be |
|
918 | 907 | recursively flattened. Examples: |
|
919 | 908 | |
|
920 | 909 | >>> qw('1 2') |
|
921 | 910 | ['1', '2'] |
|
922 | 911 | >>> qw(['a b','1 2',['m n','p q']]) |
|
923 | 912 | [['a', 'b'], ['1', '2'], [['m', 'n'], ['p', 'q']]] |
|
924 | 913 | >>> qw(['a b','1 2',['m n','p q']],flat=1) |
|
925 | 914 | ['a', 'b', '1', '2', 'm', 'n', 'p', 'q'] """ |
|
926 | 915 | |
|
927 | 916 | if type(words) in StringTypes: |
|
928 | 917 | return [word.strip() for word in words.split(sep,maxsplit) |
|
929 | 918 | if word and not word.isspace() ] |
|
930 | 919 | if flat: |
|
931 | 920 | return flatten(map(qw,words,[1]*len(words))) |
|
932 | 921 | return map(qw,words) |
|
933 | 922 | |
|
934 | 923 | #---------------------------------------------------------------------------- |
|
935 | 924 | def qwflat(words,sep=None,maxsplit=-1): |
|
936 | 925 | """Calls qw(words) in flat mode. It's just a convenient shorthand.""" |
|
937 | 926 | return qw(words,1,sep,maxsplit) |
|
938 | 927 | |
|
939 | 928 | #----------------------------------------------------------------------------- |
|
940 | 929 | def list_strings(arg): |
|
941 | 930 | """Always return a list of strings, given a string or list of strings |
|
942 | 931 | as input.""" |
|
943 | 932 | |
|
944 | 933 | if type(arg) in StringTypes: return [arg] |
|
945 | 934 | else: return arg |
|
946 | 935 | |
|
947 | 936 | #---------------------------------------------------------------------------- |
|
948 | 937 | def grep(pat,list,case=1): |
|
949 | 938 | """Simple minded grep-like function. |
|
950 | 939 | grep(pat,list) returns occurrences of pat in list, None on failure. |
|
951 | 940 | |
|
952 | 941 | It only does simple string matching, with no support for regexps. Use the |
|
953 | 942 | option case=0 for case-insensitive matching.""" |
|
954 | 943 | |
|
955 | 944 | # This is pretty crude. At least it should implement copying only references |
|
956 | 945 | # to the original data in case it's big. Now it copies the data for output. |
|
957 | 946 | out=[] |
|
958 | 947 | if case: |
|
959 | 948 | for term in list: |
|
960 | 949 | if term.find(pat)>-1: out.append(term) |
|
961 | 950 | else: |
|
962 | 951 | lpat=pat.lower() |
|
963 | 952 | for term in list: |
|
964 | 953 | if term.lower().find(lpat)>-1: out.append(term) |
|
965 | 954 | |
|
966 | 955 | if len(out): return out |
|
967 | 956 | else: return None |
|
968 | 957 | |
|
969 | 958 | #---------------------------------------------------------------------------- |
|
970 | 959 | def dgrep(pat,*opts): |
|
971 | 960 | """Return grep() on dir()+dir(__builtins__). |
|
972 | 961 | |
|
973 | 962 | A very common use of grep() when working interactively.""" |
|
974 | 963 | |
|
975 | 964 | return grep(pat,dir(__main__)+dir(__main__.__builtins__),*opts) |
|
976 | 965 | |
|
977 | 966 | #---------------------------------------------------------------------------- |
|
978 | 967 | def idgrep(pat): |
|
979 | 968 | """Case-insensitive dgrep()""" |
|
980 | 969 | |
|
981 | 970 | return dgrep(pat,0) |
|
982 | 971 | |
|
983 | 972 | #---------------------------------------------------------------------------- |
|
984 | 973 | def igrep(pat,list): |
|
985 | 974 | """Synonym for case-insensitive grep.""" |
|
986 | 975 | |
|
987 | 976 | return grep(pat,list,case=0) |
|
988 | 977 | |
|
989 | 978 | #---------------------------------------------------------------------------- |
|
990 | 979 | def indent(str,nspaces=4,ntabs=0): |
|
991 | 980 | """Indent a string a given number of spaces or tabstops. |
|
992 | 981 | |
|
993 | 982 | indent(str,nspaces=4,ntabs=0) -> indent str by ntabs+nspaces. |
|
994 | 983 | """ |
|
995 | 984 | if str is None: |
|
996 | 985 | return |
|
997 | 986 | ind = '\t'*ntabs+' '*nspaces |
|
998 | 987 | outstr = '%s%s' % (ind,str.replace(os.linesep,os.linesep+ind)) |
|
999 | 988 | if outstr.endswith(os.linesep+ind): |
|
1000 | 989 | return outstr[:-len(ind)] |
|
1001 | 990 | else: |
|
1002 | 991 | return outstr |
|
1003 | 992 | |
|
1004 | 993 | #----------------------------------------------------------------------------- |
|
1005 | 994 | def native_line_ends(filename,backup=1): |
|
1006 | 995 | """Convert (in-place) a file to line-ends native to the current OS. |
|
1007 | 996 | |
|
1008 | 997 | If the optional backup argument is given as false, no backup of the |
|
1009 | 998 | original file is left. """ |
|
1010 | 999 | |
|
1011 | 1000 | backup_suffixes = {'posix':'~','dos':'.bak','nt':'.bak','mac':'.bak'} |
|
1012 | 1001 | |
|
1013 | 1002 | bak_filename = filename + backup_suffixes[os.name] |
|
1014 | 1003 | |
|
1015 | 1004 | original = open(filename).read() |
|
1016 | 1005 | shutil.copy2(filename,bak_filename) |
|
1017 | 1006 | try: |
|
1018 | 1007 | new = open(filename,'wb') |
|
1019 | 1008 | new.write(os.linesep.join(original.splitlines())) |
|
1020 | 1009 | new.write(os.linesep) # ALWAYS put an eol at the end of the file |
|
1021 | 1010 | new.close() |
|
1022 | 1011 | except: |
|
1023 | 1012 | os.rename(bak_filename,filename) |
|
1024 | 1013 | if not backup: |
|
1025 | 1014 | try: |
|
1026 | 1015 | os.remove(bak_filename) |
|
1027 | 1016 | except: |
|
1028 | 1017 | pass |
|
1029 | 1018 | |
|
1030 | 1019 | #---------------------------------------------------------------------------- |
|
1031 | 1020 | def get_pager_cmd(pager_cmd = None): |
|
1032 | 1021 | """Return a pager command. |
|
1033 | 1022 | |
|
1034 | 1023 | Makes some attempts at finding an OS-correct one.""" |
|
1035 | 1024 | |
|
1036 | 1025 | if os.name == 'posix': |
|
1037 | 1026 | default_pager_cmd = 'less -r' # -r for color control sequences |
|
1038 | 1027 | elif os.name in ['nt','dos']: |
|
1039 | 1028 | default_pager_cmd = 'type' |
|
1040 | 1029 | |
|
1041 | 1030 | if pager_cmd is None: |
|
1042 | 1031 | try: |
|
1043 | 1032 | pager_cmd = os.environ['PAGER'] |
|
1044 | 1033 | except: |
|
1045 | 1034 | pager_cmd = default_pager_cmd |
|
1046 | 1035 | return pager_cmd |
|
1047 | 1036 | |
|
1048 | 1037 | #----------------------------------------------------------------------------- |
|
1049 | 1038 | def get_pager_start(pager,start): |
|
1050 | 1039 | """Return the string for paging files with an offset. |
|
1051 | 1040 | |
|
1052 | 1041 | This is the '+N' argument which less and more (under Unix) accept. |
|
1053 | 1042 | """ |
|
1054 | 1043 | |
|
1055 | 1044 | if pager in ['less','more']: |
|
1056 | 1045 | if start: |
|
1057 | 1046 | start_string = '+' + str(start) |
|
1058 | 1047 | else: |
|
1059 | 1048 | start_string = '' |
|
1060 | 1049 | else: |
|
1061 | 1050 | start_string = '' |
|
1062 | 1051 | return start_string |
|
1063 | 1052 | |
|
1064 | 1053 | #---------------------------------------------------------------------------- |
|
1065 | 1054 | def page_dumb(strng,start=0,screen_lines=25): |
|
1066 | 1055 | """Very dumb 'pager' in Python, for when nothing else works. |
|
1067 | 1056 | |
|
1068 | 1057 | Only moves forward, same interface as page(), except for pager_cmd and |
|
1069 | 1058 | mode.""" |
|
1070 | 1059 | |
|
1071 | 1060 | out_ln = strng.splitlines()[start:] |
|
1072 | 1061 | screens = chop(out_ln,screen_lines-1) |
|
1073 | 1062 | if len(screens) == 1: |
|
1074 | 1063 | print >>Term.cout, os.linesep.join(screens[0]) |
|
1075 | 1064 | else: |
|
1076 | 1065 | for scr in screens[0:-1]: |
|
1077 | 1066 | print >>Term.cout, os.linesep.join(scr) |
|
1078 | 1067 | ans = raw_input('---Return to continue, q to quit--- ') |
|
1079 | 1068 | if ans.lower().startswith('q'): |
|
1080 | 1069 | return |
|
1081 | 1070 | print >>Term.cout, os.linesep.join(screens[-1]) |
|
1082 | 1071 | |
|
1083 | 1072 | #---------------------------------------------------------------------------- |
|
1084 | 1073 | def page(strng,start=0,screen_lines=0,pager_cmd = None): |
|
1085 | 1074 | """Print a string, piping through a pager after a certain length. |
|
1086 | 1075 | |
|
1087 | 1076 | The screen_lines parameter specifies the number of *usable* lines of your |
|
1088 | 1077 | terminal screen (total lines minus lines you need to reserve to show other |
|
1089 | 1078 | information). |
|
1090 | 1079 | |
|
1091 | 1080 | If you set screen_lines to a number <=0, page() will try to auto-determine |
|
1092 | 1081 | your screen size and will only use up to (screen_size+screen_lines) for |
|
1093 | 1082 | printing, paging after that. That is, if you want auto-detection but need |
|
1094 | 1083 | to reserve the bottom 3 lines of the screen, use screen_lines = -3, and for |
|
1095 | 1084 | auto-detection without any lines reserved simply use screen_lines = 0. |
|
1096 | 1085 | |
|
1097 | 1086 | If a string won't fit in the allowed lines, it is sent through the |
|
1098 | 1087 | specified pager command. If none given, look for PAGER in the environment, |
|
1099 | 1088 | and ultimately default to less. |
|
1100 | 1089 | |
|
1101 | 1090 | If no system pager works, the string is sent through a 'dumb pager' |
|
1102 | 1091 | written in python, very simplistic. |
|
1103 | 1092 | """ |
|
1104 | 1093 | |
|
1105 | 1094 | # Ugly kludge, but calling curses.initscr() flat out crashes in emacs |
|
1106 | 1095 | TERM = os.environ.get('TERM','dumb') |
|
1107 | 1096 | if TERM in ['dumb','emacs'] and os.name != 'nt': |
|
1108 | 1097 | print strng |
|
1109 | 1098 | return |
|
1110 | 1099 | # chop off the topmost part of the string we don't want to see |
|
1111 | 1100 | str_lines = strng.split(os.linesep)[start:] |
|
1112 | 1101 | str_toprint = os.linesep.join(str_lines) |
|
1113 | 1102 | num_newlines = len(str_lines) |
|
1114 | 1103 | len_str = len(str_toprint) |
|
1115 | 1104 | |
|
1116 | 1105 | # Dumb heuristics to guesstimate number of on-screen lines the string |
|
1117 | 1106 | # takes. Very basic, but good enough for docstrings in reasonable |
|
1118 | 1107 | # terminals. If someone later feels like refining it, it's not hard. |
|
1119 | 1108 | numlines = max(num_newlines,int(len_str/80)+1) |
|
1120 | 1109 | |
|
1121 | 1110 | screen_lines_def = 25 # default value if we can't auto-determine |
|
1122 | 1111 | |
|
1123 | 1112 | # auto-determine screen size |
|
1124 | 1113 | if screen_lines <= 0: |
|
1125 | 1114 | if TERM=='xterm': |
|
1126 | 1115 | try: |
|
1127 | 1116 | import curses |
|
1128 | 1117 | if hasattr(curses,'initscr'): |
|
1129 | 1118 | use_curses = 1 |
|
1130 | 1119 | else: |
|
1131 | 1120 | use_curses = 0 |
|
1132 | 1121 | except ImportError: |
|
1133 | 1122 | use_curses = 0 |
|
1134 | 1123 | else: |
|
1135 | 1124 | # curses causes problems on many terminals other than xterm. |
|
1136 | 1125 | use_curses = 0 |
|
1137 | 1126 | if use_curses: |
|
1138 | 1127 | scr = curses.initscr() |
|
1139 | 1128 | screen_lines_real,screen_cols = scr.getmaxyx() |
|
1140 | 1129 | curses.endwin() |
|
1141 | 1130 | screen_lines += screen_lines_real |
|
1142 | 1131 | #print '***Screen size:',screen_lines_real,'lines x',\ |
|
1143 | 1132 | #screen_cols,'columns.' # dbg |
|
1144 | 1133 | else: |
|
1145 | 1134 | screen_lines += screen_lines_def |
|
1146 | 1135 | |
|
1147 | 1136 | #print 'numlines',numlines,'screenlines',screen_lines # dbg |
|
1148 | 1137 | if numlines <= screen_lines : |
|
1149 | 1138 | #print '*** normal print' # dbg |
|
1150 | 1139 | print >>Term.cout, str_toprint |
|
1151 | 1140 | else: |
|
1152 | 1141 | # Try to open pager and default to internal one if that fails. |
|
1153 | 1142 | # All failure modes are tagged as 'retval=1', to match the return |
|
1154 | 1143 | # value of a failed system command. If any intermediate attempt |
|
1155 | 1144 | # sets retval to 1, at the end we resort to our own page_dumb() pager. |
|
1156 | 1145 | pager_cmd = get_pager_cmd(pager_cmd) |
|
1157 | 1146 | pager_cmd += ' ' + get_pager_start(pager_cmd,start) |
|
1158 | 1147 | if os.name == 'nt': |
|
1159 | 1148 | if pager_cmd.startswith('type'): |
|
1160 | 1149 | # The default WinXP 'type' command is failing on complex strings. |
|
1161 | 1150 | retval = 1 |
|
1162 | 1151 | else: |
|
1163 | 1152 | tmpname = tempfile.mktemp('.txt') |
|
1164 | 1153 | tmpfile = file(tmpname,'wt') |
|
1165 | 1154 | tmpfile.write(strng) |
|
1166 | 1155 | tmpfile.close() |
|
1167 | 1156 | cmd = "%s < %s" % (pager_cmd,tmpname) |
|
1168 | 1157 | if os.system(cmd): |
|
1169 | 1158 | retval = 1 |
|
1170 | 1159 | else: |
|
1171 | 1160 | retval = None |
|
1172 | 1161 | os.remove(tmpname) |
|
1173 | 1162 | else: |
|
1174 | 1163 | try: |
|
1175 | 1164 | retval = None |
|
1176 | 1165 | # if I use popen4, things hang. No idea why. |
|
1177 | 1166 | #pager,shell_out = os.popen4(pager_cmd) |
|
1178 | 1167 | pager = os.popen(pager_cmd,'w') |
|
1179 | 1168 | pager.write(strng) |
|
1180 | 1169 | pager.close() |
|
1181 | 1170 | retval = pager.close() # success returns None |
|
1182 | 1171 | except IOError,msg: # broken pipe when user quits |
|
1183 | 1172 | if msg.args == (32,'Broken pipe'): |
|
1184 | 1173 | retval = None |
|
1185 | 1174 | else: |
|
1186 | 1175 | retval = 1 |
|
1187 | 1176 | except OSError: |
|
1188 | 1177 | # Other strange problems, sometimes seen in Win2k/cygwin |
|
1189 | 1178 | retval = 1 |
|
1190 | 1179 | if retval is not None: |
|
1191 | 1180 | page_dumb(strng,screen_lines=screen_lines) |
|
1192 | 1181 | |
|
1193 | 1182 | #---------------------------------------------------------------------------- |
|
1194 | 1183 | def page_file(fname,start = 0, pager_cmd = None): |
|
1195 | 1184 | """Page a file, using an optional pager command and starting line. |
|
1196 | 1185 | """ |
|
1197 | 1186 | |
|
1198 | 1187 | pager_cmd = get_pager_cmd(pager_cmd) |
|
1199 | 1188 | pager_cmd += ' ' + get_pager_start(pager_cmd,start) |
|
1200 | 1189 | |
|
1201 | 1190 | try: |
|
1202 | 1191 | if os.environ['TERM'] in ['emacs','dumb']: |
|
1203 | 1192 | raise EnvironmentError |
|
1204 | 1193 | xsys(pager_cmd + ' ' + fname) |
|
1205 | 1194 | except: |
|
1206 | 1195 | try: |
|
1207 | 1196 | if start > 0: |
|
1208 | 1197 | start -= 1 |
|
1209 | 1198 | page(open(fname).read(),start) |
|
1210 | 1199 | except: |
|
1211 | 1200 | print 'Unable to show file',`fname` |
|
1212 | 1201 | |
|
1213 | 1202 | #---------------------------------------------------------------------------- |
|
1214 | 1203 | def snip_print(str,width = 75,print_full = 0,header = ''): |
|
1215 | 1204 | """Print a string snipping the midsection to fit in width. |
|
1216 | 1205 | |
|
1217 | 1206 | print_full: mode control: |
|
1218 | 1207 | - 0: only snip long strings |
|
1219 | 1208 | - 1: send to page() directly. |
|
1220 | 1209 | - 2: snip long strings and ask for full length viewing with page() |
|
1221 | 1210 | Return 1 if snipping was necessary, 0 otherwise.""" |
|
1222 | 1211 | |
|
1223 | 1212 | if print_full == 1: |
|
1224 | 1213 | page(header+str) |
|
1225 | 1214 | return 0 |
|
1226 | 1215 | |
|
1227 | 1216 | print header, |
|
1228 | 1217 | if len(str) < width: |
|
1229 | 1218 | print str |
|
1230 | 1219 | snip = 0 |
|
1231 | 1220 | else: |
|
1232 | 1221 | whalf = int((width -5)/2) |
|
1233 | 1222 | print str[:whalf] + ' <...> ' + str[-whalf:] |
|
1234 | 1223 | snip = 1 |
|
1235 | 1224 | if snip and print_full == 2: |
|
1236 | 1225 | if raw_input(header+' Snipped. View (y/n)? [N]').lower() == 'y': |
|
1237 | 1226 | page(str) |
|
1238 | 1227 | return snip |
|
1239 | 1228 | |
|
1240 | 1229 | #**************************************************************************** |
|
1241 | 1230 | # lists, dicts and structures |
|
1242 | 1231 | |
|
1243 | 1232 | def belong(candidates,checklist): |
|
1244 | 1233 | """Check whether a list of items appear in a given list of options. |
|
1245 | 1234 | |
|
1246 | 1235 | Returns a list of 1 and 0, one for each candidate given.""" |
|
1247 | 1236 | |
|
1248 | 1237 | return [x in checklist for x in candidates] |
|
1249 | 1238 | |
|
1250 | 1239 | #---------------------------------------------------------------------------- |
|
1251 | 1240 | def uniq_stable(elems): |
|
1252 | 1241 | """uniq_stable(elems) -> list |
|
1253 | 1242 | |
|
1254 | 1243 | Return from an iterable, a list of all the unique elements in the input, |
|
1255 | 1244 | but maintaining the order in which they first appear. |
|
1256 | 1245 | |
|
1257 | 1246 | A naive solution to this problem which just makes a dictionary with the |
|
1258 | 1247 | elements as keys fails to respect the stability condition, since |
|
1259 | 1248 | dictionaries are unsorted by nature. |
|
1260 | 1249 | |
|
1261 | 1250 | Note: All elements in the input must be valid dictionary keys for this |
|
1262 | 1251 | routine to work, as it internally uses a dictionary for efficiency |
|
1263 | 1252 | reasons.""" |
|
1264 | 1253 | |
|
1265 | 1254 | unique = [] |
|
1266 | 1255 | unique_dict = {} |
|
1267 | 1256 | for nn in elems: |
|
1268 | 1257 | if nn not in unique_dict: |
|
1269 | 1258 | unique.append(nn) |
|
1270 | 1259 | unique_dict[nn] = None |
|
1271 | 1260 | return unique |
|
1272 | 1261 | |
|
1273 | 1262 | #---------------------------------------------------------------------------- |
|
1274 | 1263 | class NLprinter: |
|
1275 | 1264 | """Print an arbitrarily nested list, indicating index numbers. |
|
1276 | 1265 | |
|
1277 | 1266 | An instance of this class called nlprint is available and callable as a |
|
1278 | 1267 | function. |
|
1279 | 1268 | |
|
1280 | 1269 | nlprint(list,indent=' ',sep=': ') -> prints indenting each level by 'indent' |
|
1281 | 1270 | and using 'sep' to separate the index from the value. """ |
|
1282 | 1271 | |
|
1283 | 1272 | def __init__(self): |
|
1284 | 1273 | self.depth = 0 |
|
1285 | 1274 | |
|
1286 | 1275 | def __call__(self,lst,pos='',**kw): |
|
1287 | 1276 | """Prints the nested list numbering levels.""" |
|
1288 | 1277 | kw.setdefault('indent',' ') |
|
1289 | 1278 | kw.setdefault('sep',': ') |
|
1290 | 1279 | kw.setdefault('start',0) |
|
1291 | 1280 | kw.setdefault('stop',len(lst)) |
|
1292 | 1281 | # we need to remove start and stop from kw so they don't propagate |
|
1293 | 1282 | # into a recursive call for a nested list. |
|
1294 | 1283 | start = kw['start']; del kw['start'] |
|
1295 | 1284 | stop = kw['stop']; del kw['stop'] |
|
1296 | 1285 | if self.depth == 0 and 'header' in kw.keys(): |
|
1297 | 1286 | print kw['header'] |
|
1298 | 1287 | |
|
1299 | 1288 | for idx in range(start,stop): |
|
1300 | 1289 | elem = lst[idx] |
|
1301 | 1290 | if type(elem)==type([]): |
|
1302 | 1291 | self.depth += 1 |
|
1303 | 1292 | self.__call__(elem,itpl('$pos$idx,'),**kw) |
|
1304 | 1293 | self.depth -= 1 |
|
1305 | 1294 | else: |
|
1306 | 1295 | printpl(kw['indent']*self.depth+'$pos$idx$kw["sep"]$elem') |
|
1307 | 1296 | |
|
1308 | 1297 | nlprint = NLprinter() |
|
1309 | 1298 | #---------------------------------------------------------------------------- |
|
1310 | 1299 | def all_belong(candidates,checklist): |
|
1311 | 1300 | """Check whether a list of items ALL appear in a given list of options. |
|
1312 | 1301 | |
|
1313 | 1302 | Returns a single 1 or 0 value.""" |
|
1314 | 1303 | |
|
1315 | 1304 | return 1-(0 in [x in checklist for x in candidates]) |
|
1316 | 1305 | |
|
1317 | 1306 | #---------------------------------------------------------------------------- |
|
1318 | 1307 | def sort_compare(lst1,lst2,inplace = 1): |
|
1319 | 1308 | """Sort and compare two lists. |
|
1320 | 1309 | |
|
1321 | 1310 | By default it does it in place, thus modifying the lists. Use inplace = 0 |
|
1322 | 1311 | to avoid that (at the cost of temporary copy creation).""" |
|
1323 | 1312 | if not inplace: |
|
1324 | 1313 | lst1 = lst1[:] |
|
1325 | 1314 | lst2 = lst2[:] |
|
1326 | 1315 | lst1.sort(); lst2.sort() |
|
1327 | 1316 | return lst1 == lst2 |
|
1328 | 1317 | |
|
1329 | 1318 | #---------------------------------------------------------------------------- |
|
1330 | 1319 | def mkdict(**kwargs): |
|
1331 | 1320 | """Return a dict from a keyword list. |
|
1332 | 1321 | |
|
1333 | 1322 | It's just syntactic sugar for making ditcionary creation more convenient: |
|
1334 | 1323 | # the standard way |
|
1335 | 1324 | >>>data = { 'red' : 1, 'green' : 2, 'blue' : 3 } |
|
1336 | 1325 | # a cleaner way |
|
1337 | 1326 | >>>data = dict(red=1, green=2, blue=3) |
|
1338 | 1327 | |
|
1339 | 1328 | If you need more than this, look at the Struct() class.""" |
|
1340 | 1329 | |
|
1341 | 1330 | return kwargs |
|
1342 | 1331 | |
|
1343 | 1332 | #---------------------------------------------------------------------------- |
|
1344 | 1333 | def list2dict(lst): |
|
1345 | 1334 | """Takes a list of (key,value) pairs and turns it into a dict.""" |
|
1346 | 1335 | |
|
1347 | 1336 | dic = {} |
|
1348 | 1337 | for k,v in lst: dic[k] = v |
|
1349 | 1338 | return dic |
|
1350 | 1339 | |
|
1351 | 1340 | #---------------------------------------------------------------------------- |
|
1352 | 1341 | def list2dict2(lst,default=''): |
|
1353 | 1342 | """Takes a list and turns it into a dict. |
|
1354 | 1343 | Much slower than list2dict, but more versatile. This version can take |
|
1355 | 1344 | lists with sublists of arbitrary length (including sclars).""" |
|
1356 | 1345 | |
|
1357 | 1346 | dic = {} |
|
1358 | 1347 | for elem in lst: |
|
1359 | 1348 | if type(elem) in (types.ListType,types.TupleType): |
|
1360 | 1349 | size = len(elem) |
|
1361 | 1350 | if size == 0: |
|
1362 | 1351 | pass |
|
1363 | 1352 | elif size == 1: |
|
1364 | 1353 | dic[elem] = default |
|
1365 | 1354 | else: |
|
1366 | 1355 | k,v = elem[0], elem[1:] |
|
1367 | 1356 | if len(v) == 1: v = v[0] |
|
1368 | 1357 | dic[k] = v |
|
1369 | 1358 | else: |
|
1370 | 1359 | dic[elem] = default |
|
1371 | 1360 | return dic |
|
1372 | 1361 | |
|
1373 | 1362 | #---------------------------------------------------------------------------- |
|
1374 | 1363 | def flatten(seq): |
|
1375 | 1364 | """Flatten a list of lists (NOT recursive, only works for 2d lists).""" |
|
1376 | 1365 | |
|
1377 | 1366 | # bug in python??? (YES. Fixed in 2.2, let's leave the kludgy fix in). |
|
1378 | 1367 | |
|
1379 | 1368 | # if the x=0 isn't made, a *global* variable x is left over after calling |
|
1380 | 1369 | # this function, with the value of the last element in the return |
|
1381 | 1370 | # list. This does seem like a bug big time to me. |
|
1382 | 1371 | |
|
1383 | 1372 | # the problem is fixed with the x=0, which seems to force the creation of |
|
1384 | 1373 | # a local name |
|
1385 | 1374 | |
|
1386 | 1375 | x = 0 |
|
1387 | 1376 | return [x for subseq in seq for x in subseq] |
|
1388 | 1377 | |
|
1389 | 1378 | #---------------------------------------------------------------------------- |
|
1390 | 1379 | def get_slice(seq,start=0,stop=None,step=1): |
|
1391 | 1380 | """Get a slice of a sequence with variable step. Specify start,stop,step.""" |
|
1392 | 1381 | if stop == None: |
|
1393 | 1382 | stop = len(seq) |
|
1394 | 1383 | item = lambda i: seq[i] |
|
1395 | 1384 | return map(item,xrange(start,stop,step)) |
|
1396 | 1385 | |
|
1397 | 1386 | #---------------------------------------------------------------------------- |
|
1398 | 1387 | def chop(seq,size): |
|
1399 | 1388 | """Chop a sequence into chunks of the given size.""" |
|
1400 | 1389 | chunk = lambda i: seq[i:i+size] |
|
1401 | 1390 | return map(chunk,xrange(0,len(seq),size)) |
|
1402 | 1391 | |
|
1403 | 1392 | #---------------------------------------------------------------------------- |
|
1404 | 1393 | def with(object, **args): |
|
1405 | 1394 | """Set multiple attributes for an object, similar to Pascal's with. |
|
1406 | 1395 | |
|
1407 | 1396 | Example: |
|
1408 | 1397 | with(jim, |
|
1409 | 1398 | born = 1960, |
|
1410 | 1399 | haircolour = 'Brown', |
|
1411 | 1400 | eyecolour = 'Green') |
|
1412 | 1401 | |
|
1413 | 1402 | Credit: Greg Ewing, in |
|
1414 | 1403 | http://mail.python.org/pipermail/python-list/2001-May/040703.html""" |
|
1415 | 1404 | |
|
1416 | 1405 | object.__dict__.update(args) |
|
1417 | 1406 | |
|
1418 | 1407 | #---------------------------------------------------------------------------- |
|
1419 | 1408 | def setattr_list(obj,alist,nspace = None): |
|
1420 | 1409 | """Set a list of attributes for an object taken from a namespace. |
|
1421 | 1410 | |
|
1422 | 1411 | setattr_list(obj,alist,nspace) -> sets in obj all the attributes listed in |
|
1423 | 1412 | alist with their values taken from nspace, which must be a dict (something |
|
1424 | 1413 | like locals() will often do) If nspace isn't given, locals() of the |
|
1425 | 1414 | *caller* is used, so in most cases you can omit it. |
|
1426 | 1415 | |
|
1427 | 1416 | Note that alist can be given as a string, which will be automatically |
|
1428 | 1417 | split into a list on whitespace. If given as a list, it must be a list of |
|
1429 | 1418 | *strings* (the variable names themselves), not of variables.""" |
|
1430 | 1419 | |
|
1431 | 1420 | # this grabs the local variables from the *previous* call frame -- that is |
|
1432 | 1421 | # the locals from the function that called setattr_list(). |
|
1433 | 1422 | # - snipped from weave.inline() |
|
1434 | 1423 | if nspace is None: |
|
1435 | 1424 | call_frame = sys._getframe().f_back |
|
1436 | 1425 | nspace = call_frame.f_locals |
|
1437 | 1426 | |
|
1438 | 1427 | if type(alist) in StringTypes: |
|
1439 | 1428 | alist = alist.split() |
|
1440 | 1429 | for attr in alist: |
|
1441 | 1430 | val = eval(attr,nspace) |
|
1442 | 1431 | setattr(obj,attr,val) |
|
1443 | 1432 | |
|
1444 | 1433 | #---------------------------------------------------------------------------- |
|
1445 | 1434 | def getattr_list(obj,alist,*args): |
|
1446 | 1435 | """getattr_list(obj,alist[, default]) -> attribute list. |
|
1447 | 1436 | |
|
1448 | 1437 | Get a list of named attributes for an object. When a default argument is |
|
1449 | 1438 | given, it is returned when the attribute doesn't exist; without it, an |
|
1450 | 1439 | exception is raised in that case. |
|
1451 | 1440 | |
|
1452 | 1441 | Note that alist can be given as a string, which will be automatically |
|
1453 | 1442 | split into a list on whitespace. If given as a list, it must be a list of |
|
1454 | 1443 | *strings* (the variable names themselves), not of variables.""" |
|
1455 | 1444 | |
|
1456 | 1445 | if type(alist) in StringTypes: |
|
1457 | 1446 | alist = alist.split() |
|
1458 | 1447 | if args: |
|
1459 | 1448 | if len(args)==1: |
|
1460 | 1449 | default = args[0] |
|
1461 | 1450 | return map(lambda attr: getattr(obj,attr,default),alist) |
|
1462 | 1451 | else: |
|
1463 | 1452 | raise ValueError,'getattr_list() takes only one optional argument' |
|
1464 | 1453 | else: |
|
1465 | 1454 | return map(lambda attr: getattr(obj,attr),alist) |
|
1466 | 1455 | |
|
1467 | 1456 | #---------------------------------------------------------------------------- |
|
1468 | 1457 | def map_method(method,object_list,*argseq,**kw): |
|
1469 | 1458 | """map_method(method,object_list,*args,**kw) -> list |
|
1470 | 1459 | |
|
1471 | 1460 | Return a list of the results of applying the methods to the items of the |
|
1472 | 1461 | argument sequence(s). If more than one sequence is given, the method is |
|
1473 | 1462 | called with an argument list consisting of the corresponding item of each |
|
1474 | 1463 | sequence. All sequences must be of the same length. |
|
1475 | 1464 | |
|
1476 | 1465 | Keyword arguments are passed verbatim to all objects called. |
|
1477 | 1466 | |
|
1478 | 1467 | This is Python code, so it's not nearly as fast as the builtin map().""" |
|
1479 | 1468 | |
|
1480 | 1469 | out_list = [] |
|
1481 | 1470 | idx = 0 |
|
1482 | 1471 | for object in object_list: |
|
1483 | 1472 | try: |
|
1484 | 1473 | handler = getattr(object, method) |
|
1485 | 1474 | except AttributeError: |
|
1486 | 1475 | out_list.append(None) |
|
1487 | 1476 | else: |
|
1488 | 1477 | if argseq: |
|
1489 | 1478 | args = map(lambda lst:lst[idx],argseq) |
|
1490 | 1479 | #print 'ob',object,'hand',handler,'ar',args # dbg |
|
1491 | 1480 | out_list.append(handler(args,**kw)) |
|
1492 | 1481 | else: |
|
1493 | 1482 | out_list.append(handler(**kw)) |
|
1494 | 1483 | idx += 1 |
|
1495 | 1484 | return out_list |
|
1496 | 1485 | |
|
1497 | 1486 | #---------------------------------------------------------------------------- |
|
1498 | 1487 | # Proposed popitem() extension, written as a method |
|
1499 | 1488 | |
|
1500 | 1489 | class NotGiven: pass |
|
1501 | 1490 | |
|
1502 | 1491 | def popkey(dct,key,default=NotGiven): |
|
1503 | 1492 | """Return dct[key] and delete dct[key]. |
|
1504 | 1493 | |
|
1505 | 1494 | If default is given, return it if dct[key] doesn't exist, otherwise raise |
|
1506 | 1495 | KeyError. """ |
|
1507 | 1496 | |
|
1508 | 1497 | try: |
|
1509 | 1498 | val = dct[key] |
|
1510 | 1499 | except KeyError: |
|
1511 | 1500 | if default is NotGiven: |
|
1512 | 1501 | raise |
|
1513 | 1502 | else: |
|
1514 | 1503 | return default |
|
1515 | 1504 | else: |
|
1516 | 1505 | del dct[key] |
|
1517 | 1506 | return val |
|
1518 | 1507 | #*************************** end of file <genutils.py> ********************** |
|
1519 | 1508 |
@@ -1,2084 +1,1999 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """ |
|
3 | 3 | IPython -- An enhanced Interactive Python |
|
4 | 4 | |
|
5 | 5 | Requires Python 2.1 or newer. |
|
6 | 6 | |
|
7 | 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 | 13 | # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and |
|
14 | 14 | # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu> |
|
15 | 15 | # |
|
16 | 16 | # Distributed under the terms of the BSD License. The full license is in |
|
17 | 17 | # the file COPYING, distributed as part of this software. |
|
18 | 18 | # |
|
19 | 19 | # Note: this code originally subclassed code.InteractiveConsole from the |
|
20 | 20 | # Python standard library. Over time, much of that class has been copied |
|
21 | 21 | # verbatim here for modifications which could not be accomplished by |
|
22 | 22 | # subclassing. The Python License (sec. 2) allows for this, but it's always |
|
23 | 23 | # nice to acknowledge credit where credit is due. |
|
24 | 24 | #***************************************************************************** |
|
25 | 25 | |
|
26 | 26 | #**************************************************************************** |
|
27 | 27 | # Modules and globals |
|
28 | 28 | |
|
29 | 29 | from __future__ import generators # for 2.2 backwards-compatibility |
|
30 | 30 | |
|
31 | 31 | from IPython import Release |
|
32 | 32 | __author__ = '%s <%s>\n%s <%s>' % \ |
|
33 | 33 | ( Release.authors['Janko'] + Release.authors['Fernando'] ) |
|
34 | 34 | __license__ = Release.license |
|
35 | 35 | __version__ = Release.version |
|
36 | 36 | |
|
37 | 37 | # Python standard modules |
|
38 | 38 | import __main__ |
|
39 | 39 | import __builtin__ |
|
40 | 40 | import exceptions |
|
41 | 41 | import keyword |
|
42 | 42 | import new |
|
43 | 43 | import os, sys, shutil |
|
44 | 44 | import code, glob, types, re |
|
45 | 45 | import string, StringIO |
|
46 | 46 | import inspect, pydoc |
|
47 | 47 | import bdb, pdb |
|
48 | 48 | import UserList # don't subclass list so this works with Python2.1 |
|
49 | 49 | from pprint import pprint, pformat |
|
50 | 50 | import cPickle as pickle |
|
51 | 51 | import traceback |
|
52 | 52 | |
|
53 | 53 | # IPython's own modules |
|
54 | 54 | import IPython |
|
55 | 55 | from IPython import OInspect,PyColorize,ultraTB |
|
56 | 56 | from IPython.ultraTB import ColorScheme,ColorSchemeTable # too long names |
|
57 | 57 | from IPython.Logger import Logger |
|
58 | 58 | from IPython.Magic import Magic,magic2python,shlex_split |
|
59 | 59 | from IPython.usage import cmd_line_usage,interactive_usage |
|
60 | 60 | from IPython.Struct import Struct |
|
61 | 61 | from IPython.Itpl import Itpl,itpl,printpl,ItplNS,itplns |
|
62 | 62 | from IPython.FakeModule import FakeModule |
|
63 | 63 | from IPython.background_jobs import BackgroundJobManager |
|
64 | 64 | from IPython.genutils import * |
|
65 | 65 | |
|
66 | 66 | # Global pointer to the running |
|
67 | 67 | |
|
68 | 68 | # store the builtin raw_input globally, and use this always, in case user code |
|
69 | 69 | # overwrites it (like wx.py.PyShell does) |
|
70 | 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 | 73 | # Some utility function definitions |
|
83 | 74 | |
|
84 | 75 | class Bunch: pass |
|
85 | 76 | |
|
86 | 77 | def esc_quotes(strng): |
|
87 | 78 | """Return the input string with single and double quotes escaped out""" |
|
88 | 79 | |
|
89 | 80 | return strng.replace('"','\\"').replace("'","\\'") |
|
90 | 81 | |
|
91 | 82 | def import_fail_info(mod_name,fns=None): |
|
92 | 83 | """Inform load failure for a module.""" |
|
93 | 84 | |
|
94 | 85 | if fns == None: |
|
95 | 86 | warn("Loading of %s failed.\n" % (mod_name,)) |
|
96 | 87 | else: |
|
97 | 88 | warn("Loading of %s from %s failed.\n" % (fns,mod_name)) |
|
98 | 89 | |
|
99 | 90 | def qw_lol(indata): |
|
100 | 91 | """qw_lol('a b') -> [['a','b']], |
|
101 | 92 | otherwise it's just a call to qw(). |
|
102 | 93 | |
|
103 | 94 | We need this to make sure the modules_some keys *always* end up as a |
|
104 | 95 | list of lists.""" |
|
105 | 96 | |
|
106 | 97 | if type(indata) in StringTypes: |
|
107 | 98 | return [qw(indata)] |
|
108 | 99 | else: |
|
109 | 100 | return qw(indata) |
|
110 | 101 | |
|
111 | 102 | def ipmagic(arg_s): |
|
112 | 103 | """Call a magic function by name. |
|
113 | 104 | |
|
114 | 105 | Input: a string containing the name of the magic function to call and any |
|
115 | 106 | additional arguments to be passed to the magic. |
|
116 | 107 | |
|
117 | 108 | ipmagic('name -opt foo bar') is equivalent to typing at the ipython |
|
118 | 109 | prompt: |
|
119 | 110 | |
|
120 | 111 | In[1]: %name -opt foo bar |
|
121 | 112 | |
|
122 | 113 | To call a magic without arguments, simply use ipmagic('name'). |
|
123 | 114 | |
|
124 | 115 | This provides a proper Python function to call IPython's magics in any |
|
125 | 116 | valid Python code you can type at the interpreter, including loops and |
|
126 | 117 | compound statements. It is added by IPython to the Python builtin |
|
127 | 118 | namespace upon initialization.""" |
|
128 | 119 | |
|
129 | 120 | args = arg_s.split(' ',1) |
|
130 | 121 | magic_name = args[0] |
|
131 | 122 | if magic_name.startswith(__IPYTHON__.ESC_MAGIC): |
|
132 | 123 | magic_name = magic_name[1:] |
|
133 | 124 | try: |
|
134 | 125 | magic_args = args[1] |
|
135 | 126 | except IndexError: |
|
136 | 127 | magic_args = '' |
|
137 | 128 | fn = getattr(__IPYTHON__,'magic_'+magic_name,None) |
|
138 | 129 | if fn is None: |
|
139 | 130 | error("Magic function `%s` not found." % magic_name) |
|
140 | 131 | else: |
|
141 | 132 | magic_args = __IPYTHON__.var_expand(magic_args) |
|
142 | 133 | return fn(magic_args) |
|
143 | 134 | |
|
144 | 135 | def ipalias(arg_s): |
|
145 | 136 | """Call an alias by name. |
|
146 | 137 | |
|
147 | 138 | Input: a string containing the name of the alias to call and any |
|
148 | 139 | additional arguments to be passed to the magic. |
|
149 | 140 | |
|
150 | 141 | ipalias('name -opt foo bar') is equivalent to typing at the ipython |
|
151 | 142 | prompt: |
|
152 | 143 | |
|
153 | 144 | In[1]: name -opt foo bar |
|
154 | 145 | |
|
155 | 146 | To call an alias without arguments, simply use ipalias('name'). |
|
156 | 147 | |
|
157 | 148 | This provides a proper Python function to call IPython's aliases in any |
|
158 | 149 | valid Python code you can type at the interpreter, including loops and |
|
159 | 150 | compound statements. It is added by IPython to the Python builtin |
|
160 | 151 | namespace upon initialization.""" |
|
161 | 152 | |
|
162 | 153 | args = arg_s.split(' ',1) |
|
163 | 154 | alias_name = args[0] |
|
164 | 155 | try: |
|
165 | 156 | alias_args = args[1] |
|
166 | 157 | except IndexError: |
|
167 | 158 | alias_args = '' |
|
168 | 159 | if alias_name in __IPYTHON__.alias_table: |
|
169 | 160 | __IPYTHON__.call_alias(alias_name,alias_args) |
|
170 | 161 | else: |
|
171 | 162 | error("Alias `%s` not found." % alias_name) |
|
172 | 163 | |
|
173 | 164 | #----------------------------------------------------------------------------- |
|
174 | 165 | # Local use classes |
|
175 | 166 | try: |
|
176 | 167 | from IPython import FlexCompleter |
|
177 | 168 | |
|
178 | 169 | class MagicCompleter(FlexCompleter.Completer): |
|
179 | 170 | """Extension of the completer class to work on %-prefixed lines.""" |
|
180 | 171 | |
|
181 | 172 | def __init__(self,shell,namespace=None,omit__names=0,alias_table=None): |
|
182 | 173 | """MagicCompleter() -> completer |
|
183 | 174 | |
|
184 | 175 | Return a completer object suitable for use by the readline library |
|
185 | 176 | via readline.set_completer(). |
|
186 | 177 | |
|
187 | 178 | Inputs: |
|
188 | 179 | |
|
189 | 180 | - shell: a pointer to the ipython shell itself. This is needed |
|
190 | 181 | because this completer knows about magic functions, and those can |
|
191 | 182 | only be accessed via the ipython instance. |
|
192 | 183 | |
|
193 | 184 | - namespace: an optional dict where completions are performed. |
|
194 | 185 | |
|
195 | 186 | - The optional omit__names parameter sets the completer to omit the |
|
196 | 187 | 'magic' names (__magicname__) for python objects unless the text |
|
197 | 188 | to be completed explicitly starts with one or more underscores. |
|
198 | 189 | |
|
199 | 190 | - If alias_table is supplied, it should be a dictionary of aliases |
|
200 | 191 | to complete. """ |
|
201 | 192 | |
|
202 | 193 | FlexCompleter.Completer.__init__(self,namespace) |
|
203 | 194 | self.magic_prefix = shell.name+'.magic_' |
|
204 | 195 | self.magic_escape = shell.ESC_MAGIC |
|
205 | 196 | self.readline = FlexCompleter.readline |
|
206 | 197 | delims = self.readline.get_completer_delims() |
|
207 | 198 | delims = delims.replace(self.magic_escape,'') |
|
208 | 199 | self.readline.set_completer_delims(delims) |
|
209 | 200 | self.get_line_buffer = self.readline.get_line_buffer |
|
210 | 201 | self.omit__names = omit__names |
|
211 | 202 | self.merge_completions = shell.rc.readline_merge_completions |
|
212 | 203 | |
|
213 | 204 | if alias_table is None: |
|
214 | 205 | alias_table = {} |
|
215 | 206 | self.alias_table = alias_table |
|
216 | 207 | # Regexp to split filenames with spaces in them |
|
217 | 208 | self.space_name_re = re.compile(r'([^\\] )') |
|
218 | 209 | # Hold a local ref. to glob.glob for speed |
|
219 | 210 | self.glob = glob.glob |
|
220 | 211 | # Special handling of backslashes needed in win32 platforms |
|
221 | 212 | if sys.platform == "win32": |
|
222 | 213 | self.clean_glob = self._clean_glob_win32 |
|
223 | 214 | else: |
|
224 | 215 | self.clean_glob = self._clean_glob |
|
225 | 216 | self.matchers = [self.python_matches, |
|
226 | 217 | self.file_matches, |
|
227 | 218 | self.alias_matches, |
|
228 | 219 | self.python_func_kw_matches] |
|
229 | 220 | |
|
230 | 221 | # Code contributed by Alex Schmolck, for ipython/emacs integration |
|
231 | 222 | def all_completions(self, text): |
|
232 | 223 | """Return all possible completions for the benefit of emacs.""" |
|
233 | 224 | |
|
234 | 225 | completions = [] |
|
235 | 226 | try: |
|
236 | 227 | for i in xrange(sys.maxint): |
|
237 | 228 | res = self.complete(text, i) |
|
238 | 229 | |
|
239 | 230 | if not res: break |
|
240 | 231 | |
|
241 | 232 | completions.append(res) |
|
242 | 233 | #XXX workaround for ``notDefined.<tab>`` |
|
243 | 234 | except NameError: |
|
244 | 235 | pass |
|
245 | 236 | return completions |
|
246 | 237 | # /end Alex Schmolck code. |
|
247 | 238 | |
|
248 | 239 | def _clean_glob(self,text): |
|
249 | 240 | return self.glob("%s*" % text) |
|
250 | 241 | |
|
251 | 242 | def _clean_glob_win32(self,text): |
|
252 | 243 | return [f.replace("\\","/") |
|
253 | 244 | for f in self.glob("%s*" % text)] |
|
254 | 245 | |
|
255 | 246 | def file_matches(self, text): |
|
256 | 247 | """Match filneames, expanding ~USER type strings. |
|
257 | 248 | |
|
258 | 249 | Most of the seemingly convoluted logic in this completer is an |
|
259 | 250 | attempt to handle filenames with spaces in them. And yet it's not |
|
260 | 251 | quite perfect, because Python's readline doesn't expose all of the |
|
261 | 252 | GNU readline details needed for this to be done correctly. |
|
262 | 253 | |
|
263 | 254 | For a filename with a space in it, the printed completions will be |
|
264 | 255 | only the parts after what's already been typed (instead of the |
|
265 | 256 | full completions, as is normally done). I don't think with the |
|
266 | 257 | current (as of Python 2.3) Python readline it's possible to do |
|
267 | 258 | better.""" |
|
268 | 259 | |
|
269 | 260 | #print 'Completer->file_matches: <%s>' % text # dbg |
|
270 | 261 | |
|
271 | 262 | # chars that require escaping with backslash - i.e. chars |
|
272 | 263 | # that readline treats incorrectly as delimiters, but we |
|
273 | 264 | # don't want to treat as delimiters in filename matching |
|
274 | 265 | # when escaped with backslash |
|
275 | 266 | |
|
276 | 267 | protectables = ' ()[]{}' |
|
277 | 268 | |
|
278 | 269 | def protect_filename(s): |
|
279 | 270 | return "".join([(ch in protectables and '\\' + ch or ch) |
|
280 | 271 | for ch in s]) |
|
281 | 272 | |
|
282 | 273 | lbuf = self.get_line_buffer()[:self.readline.get_endidx()] |
|
283 | 274 | open_quotes = 0 # track strings with open quotes |
|
284 | 275 | try: |
|
285 | 276 | lsplit = shlex_split(lbuf)[-1] |
|
286 | 277 | except ValueError: |
|
287 | 278 | # typically an unmatched ", or backslash without escaped char. |
|
288 | 279 | if lbuf.count('"')==1: |
|
289 | 280 | open_quotes = 1 |
|
290 | 281 | lsplit = lbuf.split('"')[-1] |
|
291 | 282 | elif lbuf.count("'")==1: |
|
292 | 283 | open_quotes = 1 |
|
293 | 284 | lsplit = lbuf.split("'")[-1] |
|
294 | 285 | else: |
|
295 | 286 | return None |
|
296 | 287 | except IndexError: |
|
297 | 288 | # tab pressed on empty line |
|
298 | 289 | lsplit = "" |
|
299 | 290 | |
|
300 | 291 | if lsplit != protect_filename(lsplit): |
|
301 | 292 | # if protectables are found, do matching on the whole escaped |
|
302 | 293 | # name |
|
303 | 294 | has_protectables = 1 |
|
304 | 295 | text0,text = text,lsplit |
|
305 | 296 | else: |
|
306 | 297 | has_protectables = 0 |
|
307 | 298 | text = os.path.expanduser(text) |
|
308 | 299 | |
|
309 | 300 | if text == "": |
|
310 | 301 | return [protect_filename(f) for f in self.glob("*")] |
|
311 | 302 | |
|
312 | 303 | m0 = self.clean_glob(text.replace('\\','')) |
|
313 | 304 | if has_protectables: |
|
314 | 305 | # If we had protectables, we need to revert our changes to the |
|
315 | 306 | # beginning of filename so that we don't double-write the part |
|
316 | 307 | # of the filename we have so far |
|
317 | 308 | len_lsplit = len(lsplit) |
|
318 | 309 | matches = [text0 + protect_filename(f[len_lsplit:]) for f in m0] |
|
319 | 310 | else: |
|
320 | 311 | if open_quotes: |
|
321 | 312 | # if we have a string with an open quote, we don't need to |
|
322 | 313 | # protect the names at all (and we _shouldn't_, as it |
|
323 | 314 | # would cause bugs when the filesystem call is made). |
|
324 | 315 | matches = m0 |
|
325 | 316 | else: |
|
326 | 317 | matches = [protect_filename(f) for f in m0] |
|
327 | 318 | if len(matches) == 1 and os.path.isdir(matches[0]): |
|
328 | 319 | # Takes care of links to directories also. Use '/' |
|
329 | 320 | # explicitly, even under Windows, so that name completions |
|
330 | 321 | # don't end up escaped. |
|
331 | 322 | matches[0] += '/' |
|
332 | 323 | return matches |
|
333 | 324 | |
|
334 | 325 | def alias_matches(self, text): |
|
335 | 326 | """Match internal system aliases""" |
|
336 | 327 | #print 'Completer->alias_matches:',text # dbg |
|
337 | 328 | text = os.path.expanduser(text) |
|
338 | 329 | aliases = self.alias_table.keys() |
|
339 | 330 | if text == "": |
|
340 | 331 | return aliases |
|
341 | 332 | else: |
|
342 | 333 | return [alias for alias in aliases if alias.startswith(text)] |
|
343 | 334 | |
|
344 | 335 | def python_matches(self,text): |
|
345 | 336 | """Match attributes or global python names""" |
|
346 | 337 | #print 'Completer->python_matches' # dbg |
|
347 | 338 | if "." in text: |
|
348 | 339 | try: |
|
349 | 340 | matches = self.attr_matches(text) |
|
350 | 341 | if text.endswith('.') and self.omit__names: |
|
351 | 342 | if self.omit__names == 1: |
|
352 | 343 | # true if txt is _not_ a __ name, false otherwise: |
|
353 | 344 | no__name = (lambda txt: |
|
354 | 345 | re.match(r'.*\.__.*?__',txt) is None) |
|
355 | 346 | else: |
|
356 | 347 | # true if txt is _not_ a _ name, false otherwise: |
|
357 | 348 | no__name = (lambda txt: |
|
358 | 349 | re.match(r'.*\._.*?',txt) is None) |
|
359 | 350 | matches = filter(no__name, matches) |
|
360 | 351 | except NameError: |
|
361 | 352 | # catches <undefined attributes>.<tab> |
|
362 | 353 | matches = [] |
|
363 | 354 | else: |
|
364 | 355 | matches = self.global_matches(text) |
|
365 | 356 | # this is so completion finds magics when automagic is on: |
|
366 | 357 | if matches == [] and not text.startswith(os.sep): |
|
367 | 358 | matches = self.attr_matches(self.magic_prefix+text) |
|
368 | 359 | return matches |
|
369 | 360 | |
|
370 | 361 | def _default_arguments(self, obj): |
|
371 | 362 | """Return the list of default arguments of obj if it is callable, |
|
372 | 363 | or empty list otherwise.""" |
|
373 | 364 | |
|
374 | 365 | if not (inspect.isfunction(obj) or inspect.ismethod(obj)): |
|
375 | 366 | # for classes, check for __init__,__new__ |
|
376 | 367 | if inspect.isclass(obj): |
|
377 | 368 | obj = (getattr(obj,'__init__',None) or |
|
378 | 369 | getattr(obj,'__new__',None)) |
|
379 | 370 | # for all others, check if they are __call__able |
|
380 | 371 | elif hasattr(obj, '__call__'): |
|
381 | 372 | obj = obj.__call__ |
|
382 | 373 | # XXX: is there a way to handle the builtins ? |
|
383 | 374 | try: |
|
384 | 375 | args,_,_1,defaults = inspect.getargspec(obj) |
|
385 | 376 | if defaults: |
|
386 | 377 | return args[-len(defaults):] |
|
387 | 378 | except TypeError: pass |
|
388 | 379 | return [] |
|
389 | 380 | |
|
390 | 381 | def python_func_kw_matches(self,text): |
|
391 | 382 | """Match named parameters (kwargs) of the last open function""" |
|
392 | 383 | |
|
393 | 384 | if "." in text: # a parameter cannot be dotted |
|
394 | 385 | return [] |
|
395 | 386 | try: regexp = self.__funcParamsRegex |
|
396 | 387 | except AttributeError: |
|
397 | 388 | regexp = self.__funcParamsRegex = re.compile(r''' |
|
398 | 389 | '.*?' | # single quoted strings or |
|
399 | 390 | ".*?" | # double quoted strings or |
|
400 | 391 | \w+ | # identifier |
|
401 | 392 | \S # other characters |
|
402 | 393 | ''', re.VERBOSE | re.DOTALL) |
|
403 | 394 | # 1. find the nearest identifier that comes before an unclosed |
|
404 | 395 | # parenthesis e.g. for "foo (1+bar(x), pa", the candidate is "foo" |
|
405 | 396 | tokens = regexp.findall(self.get_line_buffer()) |
|
406 | 397 | tokens.reverse() |
|
407 | 398 | iterTokens = iter(tokens); openPar = 0 |
|
408 | 399 | for token in iterTokens: |
|
409 | 400 | if token == ')': |
|
410 | 401 | openPar -= 1 |
|
411 | 402 | elif token == '(': |
|
412 | 403 | openPar += 1 |
|
413 | 404 | if openPar > 0: |
|
414 | 405 | # found the last unclosed parenthesis |
|
415 | 406 | break |
|
416 | 407 | else: |
|
417 | 408 | return [] |
|
418 | 409 | # 2. Concatenate any dotted names (e.g. "foo.bar" for "foo.bar(x, pa" ) |
|
419 | 410 | ids = [] |
|
420 | 411 | isId = re.compile(r'\w+$').match |
|
421 | 412 | while True: |
|
422 | 413 | try: |
|
423 | 414 | ids.append(iterTokens.next()) |
|
424 | 415 | if not isId(ids[-1]): |
|
425 | 416 | ids.pop(); break |
|
426 | 417 | if not iterTokens.next() == '.': |
|
427 | 418 | break |
|
428 | 419 | except StopIteration: |
|
429 | 420 | break |
|
430 | 421 | # lookup the candidate callable matches either using global_matches |
|
431 | 422 | # or attr_matches for dotted names |
|
432 | 423 | if len(ids) == 1: |
|
433 | 424 | callableMatches = self.global_matches(ids[0]) |
|
434 | 425 | else: |
|
435 | 426 | callableMatches = self.attr_matches('.'.join(ids[::-1])) |
|
436 | 427 | argMatches = [] |
|
437 | 428 | for callableMatch in callableMatches: |
|
438 | 429 | try: namedArgs = self._default_arguments(eval(callableMatch, |
|
439 | 430 | self.namespace)) |
|
440 | 431 | except: continue |
|
441 | 432 | for namedArg in namedArgs: |
|
442 | 433 | if namedArg.startswith(text): |
|
443 | 434 | argMatches.append("%s=" %namedArg) |
|
444 | 435 | return argMatches |
|
445 | 436 | |
|
446 | 437 | def complete(self, text, state): |
|
447 | 438 | """Return the next possible completion for 'text'. |
|
448 | 439 | |
|
449 | 440 | This is called successively with state == 0, 1, 2, ... until it |
|
450 | 441 | returns None. The completion should begin with 'text'. """ |
|
451 | 442 | |
|
452 | 443 | #print '\n*** COMPLETE: <%s> (%s)' % (text,state) # dbg |
|
453 | 444 | magic_escape = self.magic_escape |
|
454 | 445 | magic_prefix = self.magic_prefix |
|
455 | 446 | |
|
456 | 447 | try: |
|
457 | 448 | if text.startswith(magic_escape): |
|
458 | 449 | text = text.replace(magic_escape,magic_prefix) |
|
459 | 450 | elif text.startswith('~'): |
|
460 | 451 | text = os.path.expanduser(text) |
|
461 | 452 | if state == 0: |
|
462 | 453 | # Extend the list of completions with the results of each |
|
463 | 454 | # matcher, so we return results to the user from all |
|
464 | 455 | # namespaces. |
|
465 | 456 | if self.merge_completions: |
|
466 | 457 | self.matches = [] |
|
467 | 458 | for matcher in self.matchers: |
|
468 | 459 | self.matches.extend(matcher(text)) |
|
469 | 460 | else: |
|
470 | 461 | for matcher in self.matchers: |
|
471 | 462 | self.matches = matcher(text) |
|
472 | 463 | if self.matches: |
|
473 | 464 | break |
|
474 | 465 | |
|
475 | 466 | try: |
|
476 | 467 | return self.matches[state].replace(magic_prefix,magic_escape) |
|
477 | 468 | except IndexError: |
|
478 | 469 | return None |
|
479 | 470 | except: |
|
480 | 471 | # If completion fails, don't annoy the user. |
|
481 | 472 | pass |
|
482 | 473 | |
|
483 | 474 | except ImportError: |
|
484 | 475 | pass # no readline support |
|
485 | 476 | |
|
486 | 477 | except KeyError: |
|
487 | 478 | pass # Windows doesn't set TERM, it doesn't matter |
|
488 | 479 | |
|
489 | 480 | |
|
490 | 481 | class InputList(UserList.UserList): |
|
491 | 482 | """Class to store user input. |
|
492 | 483 | |
|
493 | 484 | It's basically a list, but slices return a string instead of a list, thus |
|
494 | 485 | allowing things like (assuming 'In' is an instance): |
|
495 | 486 | |
|
496 | 487 | exec In[4:7] |
|
497 | 488 | |
|
498 | 489 | or |
|
499 | 490 | |
|
500 | 491 | exec In[5:9] + In[14] + In[21:25]""" |
|
501 | 492 | |
|
502 | 493 | def __getslice__(self,i,j): |
|
503 | 494 | return ''.join(UserList.UserList.__getslice__(self,i,j)) |
|
504 | 495 | |
|
505 | 496 | #**************************************************************************** |
|
506 | 497 | # Local use exceptions |
|
507 | 498 | class SpaceInInput(exceptions.Exception): |
|
508 | 499 | pass |
|
509 | 500 | |
|
510 | 501 | #**************************************************************************** |
|
511 | 502 | # Main IPython class |
|
512 | 503 | |
|
513 | 504 | class InteractiveShell(code.InteractiveConsole, Logger, Magic): |
|
514 | 505 | """An enhanced console for Python.""" |
|
515 | 506 | |
|
516 | 507 | def __init__(self,name,usage=None,rc=Struct(opts=None,args=None), |
|
517 | 508 | user_ns = None,banner2='', |
|
518 | 509 | custom_exceptions=((),None)): |
|
519 | 510 | |
|
520 | 511 | # Put a reference to self in builtins so that any form of embedded or |
|
521 | 512 | # imported code can test for being inside IPython. |
|
522 | 513 | __builtin__.__IPYTHON__ = self |
|
523 | 514 | |
|
524 | 515 | # And load into builtins ipmagic/ipalias as well |
|
525 | 516 | __builtin__.ipmagic = ipmagic |
|
526 | 517 | __builtin__.ipalias = ipalias |
|
527 | 518 | |
|
528 | 519 | # Add to __builtin__ other parts of IPython's public API |
|
529 | 520 | __builtin__.ip_set_hook = self.set_hook |
|
530 | 521 | |
|
531 | 522 | # Keep in the builtins a flag for when IPython is active. We set it |
|
532 | 523 | # with setdefault so that multiple nested IPythons don't clobber one |
|
533 | 524 | # another. Each will increase its value by one upon being activated, |
|
534 | 525 | # which also gives us a way to determine the nesting level. |
|
535 | 526 | __builtin__.__dict__.setdefault('__IPYTHON__active',0) |
|
536 | 527 | |
|
537 | 528 | # Inform the user of ipython's fast exit magics. |
|
538 | 529 | _exit = ' Use %Exit or %Quit to exit without confirmation.' |
|
539 | 530 | __builtin__.exit += _exit |
|
540 | 531 | __builtin__.quit += _exit |
|
541 | 532 | |
|
542 | 533 | # Create the namespace where the user will operate: |
|
543 | 534 | |
|
544 | 535 | # FIXME. For some strange reason, __builtins__ is showing up at user |
|
545 | 536 | # level as a dict instead of a module. This is a manual fix, but I |
|
546 | 537 | # should really track down where the problem is coming from. Alex |
|
547 | 538 | # Schmolck reported this problem first. |
|
548 | 539 | |
|
549 | 540 | # A useful post by Alex Martelli on this topic: |
|
550 | 541 | # Re: inconsistent value from __builtins__ |
|
551 | 542 | # Von: Alex Martelli <aleaxit@yahoo.com> |
|
552 | 543 | # Datum: Freitag 01 Oktober 2004 04:45:34 nachmittags/abends |
|
553 | 544 | # Gruppen: comp.lang.python |
|
554 | 545 | # Referenzen: 1 |
|
555 | 546 | |
|
556 | 547 | # Michael Hohn <hohn@hooknose.lbl.gov> wrote: |
|
557 | 548 | # > >>> print type(builtin_check.get_global_binding('__builtins__')) |
|
558 | 549 | # > <type 'dict'> |
|
559 | 550 | # > >>> print type(__builtins__) |
|
560 | 551 | # > <type 'module'> |
|
561 | 552 | # > Is this difference in return value intentional? |
|
562 | 553 | |
|
563 | 554 | # Well, it's documented that '__builtins__' can be either a dictionary |
|
564 | 555 | # or a module, and it's been that way for a long time. Whether it's |
|
565 | 556 | # intentional (or sensible), I don't know. In any case, the idea is that |
|
566 | 557 | # if you need to access the built-in namespace directly, you should start |
|
567 | 558 | # with "import __builtin__" (note, no 's') which will definitely give you |
|
568 | 559 | # a module. Yeah, it's somewhatΒ confusing:-(. |
|
569 | 560 | |
|
570 | 561 | if user_ns is None: |
|
571 | 562 | # Set __name__ to __main__ to better match the behavior of the |
|
572 | 563 | # normal interpreter. |
|
573 | 564 | self.user_ns = {'__name__' :'__main__', |
|
574 | 565 | '__builtins__' : __builtin__, |
|
575 | 566 | } |
|
576 | 567 | else: |
|
577 | 568 | self.user_ns = user_ns |
|
578 | 569 | |
|
579 | 570 | # The user namespace MUST have a pointer to the shell itself. |
|
580 | 571 | self.user_ns[name] = self |
|
581 | 572 | |
|
582 | 573 | # We need to insert into sys.modules something that looks like a |
|
583 | 574 | # module but which accesses the IPython namespace, for shelve and |
|
584 | 575 | # pickle to work interactively. Normally they rely on getting |
|
585 | 576 | # everything out of __main__, but for embedding purposes each IPython |
|
586 | 577 | # instance has its own private namespace, so we can't go shoving |
|
587 | 578 | # everything into __main__. |
|
588 | 579 | |
|
589 | 580 | try: |
|
590 | 581 | main_name = self.user_ns['__name__'] |
|
591 | 582 | except KeyError: |
|
592 | 583 | raise KeyError,'user_ns dictionary MUST have a "__name__" key' |
|
593 | 584 | else: |
|
594 | 585 | #print "pickle hack in place" # dbg |
|
595 | 586 | sys.modules[main_name] = FakeModule(self.user_ns) |
|
596 | 587 | |
|
597 | 588 | # List of input with multi-line handling. |
|
598 | 589 | # Fill its zero entry, user counter starts at 1 |
|
599 | 590 | self.input_hist = InputList(['\n']) |
|
600 | 591 | |
|
601 | 592 | # list of visited directories |
|
602 | 593 | self.dir_hist = [os.getcwd()] |
|
603 | 594 | |
|
604 | 595 | # dict of output history |
|
605 | 596 | self.output_hist = {} |
|
606 | 597 | |
|
607 | 598 | # dict of names to be treated as system aliases. Each entry in the |
|
608 | 599 | # alias table must be a 2-tuple of the form (N,name), where N is the |
|
609 | 600 | # number of positional arguments of the alias. |
|
610 | 601 | self.alias_table = {} |
|
611 | 602 | |
|
612 | 603 | # dict of things NOT to alias (keywords and builtins) |
|
613 | 604 | self.no_alias = {} |
|
614 | 605 | for key in keyword.kwlist: |
|
615 | 606 | self.no_alias[key] = 1 |
|
616 | 607 | self.no_alias.update(__builtin__.__dict__) |
|
617 | 608 | |
|
618 | 609 | # make global variables for user access to these |
|
619 | 610 | self.user_ns['_ih'] = self.input_hist |
|
620 | 611 | self.user_ns['_oh'] = self.output_hist |
|
621 | 612 | self.user_ns['_dh'] = self.dir_hist |
|
622 | 613 | |
|
623 | 614 | # user aliases to input and output histories |
|
624 | 615 | self.user_ns['In'] = self.input_hist |
|
625 | 616 | self.user_ns['Out'] = self.output_hist |
|
626 | 617 | |
|
627 | 618 | # Store the actual shell's name |
|
628 | 619 | self.name = name |
|
629 | 620 | |
|
630 | 621 | # Object variable to store code object waiting execution. This is |
|
631 | 622 | # used mainly by the multithreaded shells, but it can come in handy in |
|
632 | 623 | # other situations. No need to use a Queue here, since it's a single |
|
633 | 624 | # item which gets cleared once run. |
|
634 | 625 | self.code_to_run = None |
|
635 | 626 | self.code_to_run_src = '' # corresponding source |
|
636 | 627 | |
|
637 | 628 | # Job manager (for jobs run as background threads) |
|
638 | 629 | self.jobs = BackgroundJobManager() |
|
639 | 630 | # Put the job manager into builtins so it's always there. |
|
640 | 631 | __builtin__.jobs = self.jobs |
|
641 | 632 | |
|
642 | 633 | # escapes for automatic behavior on the command line |
|
643 | 634 | self.ESC_SHELL = '!' |
|
644 | 635 | self.ESC_HELP = '?' |
|
645 | 636 | self.ESC_MAGIC = '%' |
|
646 | 637 | self.ESC_QUOTE = ',' |
|
647 | 638 | self.ESC_QUOTE2 = ';' |
|
648 | 639 | self.ESC_PAREN = '/' |
|
649 | 640 | |
|
650 | 641 | # And their associated handlers |
|
651 | 642 | self.esc_handlers = {self.ESC_PAREN:self.handle_auto, |
|
652 | 643 | self.ESC_QUOTE:self.handle_auto, |
|
653 | 644 | self.ESC_QUOTE2:self.handle_auto, |
|
654 | 645 | self.ESC_MAGIC:self.handle_magic, |
|
655 | 646 | self.ESC_HELP:self.handle_help, |
|
656 | 647 | self.ESC_SHELL:self.handle_shell_escape, |
|
657 | 648 | } |
|
658 | 649 | |
|
659 | 650 | # class initializations |
|
660 | 651 | code.InteractiveConsole.__init__(self,locals = self.user_ns) |
|
661 | 652 | Logger.__init__(self,log_ns = self.user_ns) |
|
662 | 653 | Magic.__init__(self,self) |
|
663 | 654 | |
|
664 | 655 | # an ugly hack to get a pointer to the shell, so I can start writing |
|
665 | 656 | # magic code via this pointer instead of the current mixin salad. |
|
666 | 657 | Magic.set_shell(self,self) |
|
667 | 658 | |
|
668 | 659 | # hooks holds pointers used for user-side customizations |
|
669 | 660 | self.hooks = Struct() |
|
670 | 661 | |
|
671 | 662 | # Set all default hooks, defined in the IPython.hooks module. |
|
672 | 663 | hooks = IPython.hooks |
|
673 | 664 | for hook_name in hooks.__all__: |
|
674 | 665 | self.set_hook(hook_name,getattr(hooks,hook_name)) |
|
675 | 666 | |
|
676 | 667 | # Flag to mark unconditional exit |
|
677 | 668 | self.exit_now = False |
|
678 | 669 | |
|
679 | 670 | self.usage_min = """\ |
|
680 | 671 | An enhanced console for Python. |
|
681 | 672 | Some of its features are: |
|
682 | 673 | - Readline support if the readline library is present. |
|
683 | 674 | - Tab completion in the local namespace. |
|
684 | 675 | - Logging of input, see command-line options. |
|
685 | 676 | - System shell escape via ! , eg !ls. |
|
686 | 677 | - Magic commands, starting with a % (like %ls, %pwd, %cd, etc.) |
|
687 | 678 | - Keeps track of locally defined variables via %who, %whos. |
|
688 | 679 | - Show object information with a ? eg ?x or x? (use ?? for more info). |
|
689 | 680 | """ |
|
690 | 681 | if usage: self.usage = usage |
|
691 | 682 | else: self.usage = self.usage_min |
|
692 | 683 | |
|
693 | 684 | # Storage |
|
694 | 685 | self.rc = rc # This will hold all configuration information |
|
695 | 686 | self.inputcache = [] |
|
696 | 687 | self._boundcache = [] |
|
697 | 688 | self.pager = 'less' |
|
698 | 689 | # temporary files used for various purposes. Deleted at exit. |
|
699 | 690 | self.tempfiles = [] |
|
700 | 691 | |
|
701 | 692 | # for pushd/popd management |
|
702 | 693 | try: |
|
703 | 694 | self.home_dir = get_home_dir() |
|
704 | 695 | except HomeDirError,msg: |
|
705 | 696 | fatal(msg) |
|
706 | 697 | |
|
707 | 698 | self.dir_stack = [os.getcwd().replace(self.home_dir,'~')] |
|
708 | 699 | |
|
709 | 700 | # Functions to call the underlying shell. |
|
710 | 701 | |
|
711 | 702 | # utility to expand user variables via Itpl |
|
712 | 703 | self.var_expand = lambda cmd: str(ItplNS(cmd.replace('#','\#'), |
|
713 | 704 | self.user_ns)) |
|
714 | 705 | # The first is similar to os.system, but it doesn't return a value, |
|
715 | 706 | # and it allows interpolation of variables in the user's namespace. |
|
716 | 707 | self.system = lambda cmd: shell(self.var_expand(cmd), |
|
717 | 708 | header='IPython system call: ', |
|
718 | 709 | verbose=self.rc.system_verbose) |
|
719 | 710 | # These are for getoutput and getoutputerror: |
|
720 | 711 | self.getoutput = lambda cmd: \ |
|
721 | 712 | getoutput(self.var_expand(cmd), |
|
722 | 713 | header='IPython system call: ', |
|
723 | 714 | verbose=self.rc.system_verbose) |
|
724 | 715 | self.getoutputerror = lambda cmd: \ |
|
725 | 716 | getoutputerror(str(ItplNS(cmd.replace('#','\#'), |
|
726 | 717 | self.user_ns)), |
|
727 | 718 | header='IPython system call: ', |
|
728 | 719 | verbose=self.rc.system_verbose) |
|
729 | 720 | |
|
730 | 721 | # RegExp for splitting line contents into pre-char//first |
|
731 | 722 | # word-method//rest. For clarity, each group in on one line. |
|
732 | 723 | |
|
733 | 724 | # WARNING: update the regexp if the above escapes are changed, as they |
|
734 | 725 | # are hardwired in. |
|
735 | 726 | |
|
736 | 727 | # Don't get carried away with trying to make the autocalling catch too |
|
737 | 728 | # much: it's better to be conservative rather than to trigger hidden |
|
738 | 729 | # evals() somewhere and end up causing side effects. |
|
739 | 730 | |
|
740 | 731 | self.line_split = re.compile(r'^([\s*,;/])' |
|
741 | 732 | r'([\?\w\.]+\w*\s*)' |
|
742 | 733 | r'(\(?.*$)') |
|
743 | 734 | |
|
744 | 735 | # Original re, keep around for a while in case changes break something |
|
745 | 736 | #self.line_split = re.compile(r'(^[\s*!\?%,/]?)' |
|
746 | 737 | # r'(\s*[\?\w\.]+\w*\s*)' |
|
747 | 738 | # r'(\(?.*$)') |
|
748 | 739 | |
|
749 | 740 | # RegExp to identify potential function names |
|
750 | 741 | self.re_fun_name = re.compile(r'[a-zA-Z_]([a-zA-Z0-9_.]*) *$') |
|
751 | 742 | # RegExp to exclude strings with this start from autocalling |
|
752 | 743 | self.re_exclude_auto = re.compile('^[!=()<>,\*/\+-]|^is ') |
|
753 | 744 | # try to catch also methods for stuff in lists/tuples/dicts: off |
|
754 | 745 | # (experimental). For this to work, the line_split regexp would need |
|
755 | 746 | # to be modified so it wouldn't break things at '['. That line is |
|
756 | 747 | # nasty enough that I shouldn't change it until I can test it _well_. |
|
757 | 748 | #self.re_fun_name = re.compile (r'[a-zA-Z_]([a-zA-Z0-9_.\[\]]*) ?$') |
|
758 | 749 | |
|
759 | 750 | # keep track of where we started running (mainly for crash post-mortem) |
|
760 | 751 | self.starting_dir = os.getcwd() |
|
761 | 752 | |
|
762 | 753 | # Attributes for Logger mixin class, make defaults here |
|
763 | 754 | self._dolog = 0 |
|
764 | 755 | self.LOG = '' |
|
765 | 756 | self.LOGDEF = '.InteractiveShell.log' |
|
766 | 757 | self.LOGMODE = 'over' |
|
767 | 758 | self.LOGHEAD = Itpl( |
|
768 | 759 | """#log# Automatic Logger file. *** THIS MUST BE THE FIRST LINE *** |
|
769 | 760 | #log# DO NOT CHANGE THIS LINE OR THE TWO BELOW |
|
770 | 761 | #log# opts = $self.rc.opts |
|
771 | 762 | #log# args = $self.rc.args |
|
772 | 763 | #log# It is safe to make manual edits below here. |
|
773 | 764 | #log#----------------------------------------------------------------------- |
|
774 | 765 | """) |
|
775 | 766 | # Various switches which can be set |
|
776 | 767 | self.CACHELENGTH = 5000 # this is cheap, it's just text |
|
777 | 768 | self.BANNER = "Python %(version)s on %(platform)s\n" % sys.__dict__ |
|
778 | 769 | self.banner2 = banner2 |
|
779 | 770 | |
|
780 | 771 | # TraceBack handlers: |
|
781 | 772 | # Need two, one for syntax errors and one for other exceptions. |
|
782 | 773 | self.SyntaxTB = ultraTB.ListTB(color_scheme='NoColor') |
|
783 | 774 | # This one is initialized with an offset, meaning we always want to |
|
784 | 775 | # remove the topmost item in the traceback, which is our own internal |
|
785 | 776 | # code. Valid modes: ['Plain','Context','Verbose'] |
|
786 | 777 | self.InteractiveTB = ultraTB.AutoFormattedTB(mode = 'Plain', |
|
787 | 778 | color_scheme='NoColor', |
|
788 | 779 | tb_offset = 1) |
|
789 | 780 | # and add any custom exception handlers the user may have specified |
|
790 | 781 | self.set_custom_exc(*custom_exceptions) |
|
791 | 782 | |
|
792 | 783 | # Object inspector |
|
793 | 784 | ins_colors = OInspect.InspectColors |
|
794 | 785 | code_colors = PyColorize.ANSICodeColors |
|
795 | 786 | self.inspector = OInspect.Inspector(ins_colors,code_colors,'NoColor') |
|
796 | 787 | self.autoindent = 0 |
|
797 | 788 | |
|
798 | 789 | # Make some aliases automatically |
|
799 | 790 | # Prepare list of shell aliases to auto-define |
|
800 | 791 | if os.name == 'posix': |
|
801 | 792 | auto_alias = ('mkdir mkdir', 'rmdir rmdir', |
|
802 | 793 | 'mv mv -i','rm rm -i','cp cp -i', |
|
803 | 794 | 'cat cat','less less','clear clear', |
|
804 | 795 | # a better ls |
|
805 | 796 | 'ls ls -F', |
|
806 | 797 | # long ls |
|
807 | 798 | 'll ls -lF', |
|
808 | 799 | # color ls |
|
809 | 800 | 'lc ls -F -o --color', |
|
810 | 801 | # ls normal files only |
|
811 | 802 | 'lf ls -F -o --color %l | grep ^-', |
|
812 | 803 | # ls symbolic links |
|
813 | 804 | 'lk ls -F -o --color %l | grep ^l', |
|
814 | 805 | # directories or links to directories, |
|
815 | 806 | 'ldir ls -F -o --color %l | grep /$', |
|
816 | 807 | # things which are executable |
|
817 | 808 | 'lx ls -F -o --color %l | grep ^-..x', |
|
818 | 809 | ) |
|
819 | 810 | elif os.name in ['nt','dos']: |
|
820 | 811 | auto_alias = ('dir dir /on', 'ls dir /on', |
|
821 | 812 | 'ddir dir /ad /on', 'ldir dir /ad /on', |
|
822 | 813 | 'mkdir mkdir','rmdir rmdir','echo echo', |
|
823 | 814 | 'ren ren','cls cls','copy copy') |
|
824 | 815 | else: |
|
825 | 816 | auto_alias = () |
|
826 | 817 | self.auto_alias = map(lambda s:s.split(None,1),auto_alias) |
|
827 | 818 | # Call the actual (public) initializer |
|
828 | 819 | self.init_auto_alias() |
|
829 | 820 | # end __init__ |
|
830 | 821 | |
|
831 | 822 | def set_hook(self,name,hook): |
|
832 | 823 | """set_hook(name,hook) -> sets an internal IPython hook. |
|
833 | 824 | |
|
834 | 825 | IPython exposes some of its internal API as user-modifiable hooks. By |
|
835 | 826 | resetting one of these hooks, you can modify IPython's behavior to |
|
836 | 827 | call at runtime your own routines.""" |
|
837 | 828 | |
|
838 | 829 | # At some point in the future, this should validate the hook before it |
|
839 | 830 | # accepts it. Probably at least check that the hook takes the number |
|
840 | 831 | # of args it's supposed to. |
|
841 | 832 | setattr(self.hooks,name,new.instancemethod(hook,self,self.__class__)) |
|
842 | 833 | |
|
843 | 834 | def set_custom_exc(self,exc_tuple,handler): |
|
844 | 835 | """set_custom_exc(exc_tuple,handler) |
|
845 | 836 | |
|
846 | 837 | Set a custom exception handler, which will be called if any of the |
|
847 | 838 | exceptions in exc_tuple occur in the mainloop (specifically, in the |
|
848 | 839 | runcode() method. |
|
849 | 840 | |
|
850 | 841 | Inputs: |
|
851 | 842 | |
|
852 | 843 | - exc_tuple: a *tuple* of valid exceptions to call the defined |
|
853 | 844 | handler for. It is very important that you use a tuple, and NOT A |
|
854 | 845 | LIST here, because of the way Python's except statement works. If |
|
855 | 846 | you only want to trap a single exception, use a singleton tuple: |
|
856 | 847 | |
|
857 | 848 | exc_tuple == (MyCustomException,) |
|
858 | 849 | |
|
859 | 850 | - handler: this must be defined as a function with the following |
|
860 | 851 | basic interface: def my_handler(self,etype,value,tb). |
|
861 | 852 | |
|
862 | 853 | This will be made into an instance method (via new.instancemethod) |
|
863 | 854 | of IPython itself, and it will be called if any of the exceptions |
|
864 | 855 | listed in the exc_tuple are caught. If the handler is None, an |
|
865 | 856 | internal basic one is used, which just prints basic info. |
|
866 | 857 | |
|
867 | 858 | WARNING: by putting in your own exception handler into IPython's main |
|
868 | 859 | execution loop, you run a very good chance of nasty crashes. This |
|
869 | 860 | facility should only be used if you really know what you are doing.""" |
|
870 | 861 | |
|
871 | 862 | assert type(exc_tuple)==type(()) , \ |
|
872 | 863 | "The custom exceptions must be given AS A TUPLE." |
|
873 | 864 | |
|
874 | 865 | def dummy_handler(self,etype,value,tb): |
|
875 | 866 | print '*** Simple custom exception handler ***' |
|
876 | 867 | print 'Exception type :',etype |
|
877 | 868 | print 'Exception value:',value |
|
878 | 869 | print 'Traceback :',tb |
|
879 | 870 | print 'Source code :',self.code_to_run_src |
|
880 | 871 | |
|
881 | 872 | if handler is None: handler = dummy_handler |
|
882 | 873 | |
|
883 | 874 | self.CustomTB = new.instancemethod(handler,self,self.__class__) |
|
884 | 875 | self.custom_exceptions = exc_tuple |
|
885 | 876 | |
|
886 | 877 | def set_custom_completer(self,completer,pos=0): |
|
887 | 878 | """set_custom_completer(completer,pos=0) |
|
888 | 879 | |
|
889 | 880 | Adds a new custom completer function. |
|
890 | 881 | |
|
891 | 882 | The position argument (defaults to 0) is the index in the completers |
|
892 | 883 | list where you want the completer to be inserted.""" |
|
893 | 884 | |
|
894 | 885 | newcomp = new.instancemethod(completer,self.Completer, |
|
895 | 886 | self.Completer.__class__) |
|
896 | 887 | self.Completer.matchers.insert(pos,newcomp) |
|
897 | 888 | |
|
898 | 889 | def post_config_initialization(self): |
|
899 | 890 | """Post configuration init method |
|
900 | 891 | |
|
901 | 892 | This is called after the configuration files have been processed to |
|
902 | 893 | 'finalize' the initialization.""" |
|
903 | 894 | |
|
904 | 895 | # dynamic data that survives through sessions |
|
905 | 896 | # XXX make the filename a config option? |
|
906 | 897 | persist_base = 'persist' |
|
907 | 898 | if self.rc.profile: |
|
908 | 899 | persist_base += '_%s' % self.rc.profile |
|
909 | 900 | self.persist_fname = os.path.join(self.rc.ipythondir,persist_base) |
|
910 | 901 | |
|
911 | 902 | try: |
|
912 | 903 | self.persist = pickle.load(file(self.persist_fname)) |
|
913 | 904 | except: |
|
914 | 905 | self.persist = {} |
|
915 | 906 | |
|
916 | 907 | def init_auto_alias(self): |
|
917 | 908 | """Define some aliases automatically. |
|
918 | 909 | |
|
919 | 910 | These are ALL parameter-less aliases""" |
|
920 | 911 | for alias,cmd in self.auto_alias: |
|
921 | 912 | self.alias_table[alias] = (0,cmd) |
|
922 | 913 | |
|
923 | 914 | def alias_table_validate(self,verbose=0): |
|
924 | 915 | """Update information about the alias table. |
|
925 | 916 | |
|
926 | 917 | In particular, make sure no Python keywords/builtins are in it.""" |
|
927 | 918 | |
|
928 | 919 | no_alias = self.no_alias |
|
929 | 920 | for k in self.alias_table.keys(): |
|
930 | 921 | if k in no_alias: |
|
931 | 922 | del self.alias_table[k] |
|
932 | 923 | if verbose: |
|
933 | 924 | print ("Deleting alias <%s>, it's a Python " |
|
934 | 925 | "keyword or builtin." % k) |
|
935 | 926 | |
|
936 | 927 | def set_autoindent(self,value=None): |
|
937 | 928 | """Set the autoindent flag, checking for readline support. |
|
938 | 929 | |
|
939 | 930 | If called with no arguments, it acts as a toggle.""" |
|
940 | 931 | |
|
941 | 932 | if not self.has_readline: |
|
942 | 933 | if os.name == 'posix': |
|
943 | 934 | warn("The auto-indent feature requires the readline library") |
|
944 | 935 | self.autoindent = 0 |
|
945 | 936 | return |
|
946 | 937 | if value is None: |
|
947 | 938 | self.autoindent = not self.autoindent |
|
948 | 939 | else: |
|
949 | 940 | self.autoindent = value |
|
950 | 941 | |
|
951 | 942 | def rc_set_toggle(self,rc_field,value=None): |
|
952 | 943 | """Set or toggle a field in IPython's rc config. structure. |
|
953 | 944 | |
|
954 | 945 | If called with no arguments, it acts as a toggle. |
|
955 | 946 | |
|
956 | 947 | If called with a non-existent field, the resulting AttributeError |
|
957 | 948 | exception will propagate out.""" |
|
958 | 949 | |
|
959 | 950 | rc_val = getattr(self.rc,rc_field) |
|
960 | 951 | if value is None: |
|
961 | 952 | value = not rc_val |
|
962 | 953 | setattr(self.rc,rc_field,value) |
|
963 | 954 | |
|
964 | 955 | def user_setup(self,ipythondir,rc_suffix,mode='install'): |
|
965 | 956 | """Install the user configuration directory. |
|
966 | 957 | |
|
967 | 958 | Can be called when running for the first time or to upgrade the user's |
|
968 | 959 | .ipython/ directory with the mode parameter. Valid modes are 'install' |
|
969 | 960 | and 'upgrade'.""" |
|
970 | 961 | |
|
971 | 962 | def wait(): |
|
972 | 963 | try: |
|
973 | 964 | raw_input("Please press <RETURN> to start IPython.") |
|
974 | 965 | except EOFError: |
|
975 | 966 | print >> Term.cout |
|
976 | 967 | print '*'*70 |
|
977 | 968 | |
|
978 | 969 | cwd = os.getcwd() # remember where we started |
|
979 | 970 | glb = glob.glob |
|
980 | 971 | print '*'*70 |
|
981 | 972 | if mode == 'install': |
|
982 | 973 | print \ |
|
983 | 974 | """Welcome to IPython. I will try to create a personal configuration directory |
|
984 | 975 | where you can customize many aspects of IPython's functionality in:\n""" |
|
985 | 976 | else: |
|
986 | 977 | print 'I am going to upgrade your configuration in:' |
|
987 | 978 | |
|
988 | 979 | print ipythondir |
|
989 | 980 | |
|
990 | 981 | rcdirend = os.path.join('IPython','UserConfig') |
|
991 | 982 | cfg = lambda d: os.path.join(d,rcdirend) |
|
992 | 983 | try: |
|
993 | 984 | rcdir = filter(os.path.isdir,map(cfg,sys.path))[0] |
|
994 | 985 | except IOError: |
|
995 | 986 | warning = """ |
|
996 | 987 | Installation error. IPython's directory was not found. |
|
997 | 988 | |
|
998 | 989 | Check the following: |
|
999 | 990 | |
|
1000 | 991 | The ipython/IPython directory should be in a directory belonging to your |
|
1001 | 992 | PYTHONPATH environment variable (that is, it should be in a directory |
|
1002 | 993 | belonging to sys.path). You can copy it explicitly there or just link to it. |
|
1003 | 994 | |
|
1004 | 995 | IPython will proceed with builtin defaults. |
|
1005 | 996 | """ |
|
1006 | 997 | warn(warning) |
|
1007 | 998 | wait() |
|
1008 | 999 | return |
|
1009 | 1000 | |
|
1010 | 1001 | if mode == 'install': |
|
1011 | 1002 | try: |
|
1012 | 1003 | shutil.copytree(rcdir,ipythondir) |
|
1013 | 1004 | os.chdir(ipythondir) |
|
1014 | 1005 | rc_files = glb("ipythonrc*") |
|
1015 | 1006 | for rc_file in rc_files: |
|
1016 | 1007 | os.rename(rc_file,rc_file+rc_suffix) |
|
1017 | 1008 | except: |
|
1018 | 1009 | warning = """ |
|
1019 | 1010 | |
|
1020 | 1011 | There was a problem with the installation: |
|
1021 | 1012 | %s |
|
1022 | 1013 | Try to correct it or contact the developers if you think it's a bug. |
|
1023 | 1014 | IPython will proceed with builtin defaults.""" % sys.exc_info()[1] |
|
1024 | 1015 | warn(warning) |
|
1025 | 1016 | wait() |
|
1026 | 1017 | return |
|
1027 | 1018 | |
|
1028 | 1019 | elif mode == 'upgrade': |
|
1029 | 1020 | try: |
|
1030 | 1021 | os.chdir(ipythondir) |
|
1031 | 1022 | except: |
|
1032 | 1023 | print """ |
|
1033 | 1024 | Can not upgrade: changing to directory %s failed. Details: |
|
1034 | 1025 | %s |
|
1035 | 1026 | """ % (ipythondir,sys.exc_info()[1]) |
|
1036 | 1027 | wait() |
|
1037 | 1028 | return |
|
1038 | 1029 | else: |
|
1039 | 1030 | sources = glb(os.path.join(rcdir,'[A-Za-z]*')) |
|
1040 | 1031 | for new_full_path in sources: |
|
1041 | 1032 | new_filename = os.path.basename(new_full_path) |
|
1042 | 1033 | if new_filename.startswith('ipythonrc'): |
|
1043 | 1034 | new_filename = new_filename + rc_suffix |
|
1044 | 1035 | # The config directory should only contain files, skip any |
|
1045 | 1036 | # directories which may be there (like CVS) |
|
1046 | 1037 | if os.path.isdir(new_full_path): |
|
1047 | 1038 | continue |
|
1048 | 1039 | if os.path.exists(new_filename): |
|
1049 | 1040 | old_file = new_filename+'.old' |
|
1050 | 1041 | if os.path.exists(old_file): |
|
1051 | 1042 | os.remove(old_file) |
|
1052 | 1043 | os.rename(new_filename,old_file) |
|
1053 | 1044 | shutil.copy(new_full_path,new_filename) |
|
1054 | 1045 | else: |
|
1055 | 1046 | raise ValueError,'unrecognized mode for install:',`mode` |
|
1056 | 1047 | |
|
1057 | 1048 | # Fix line-endings to those native to each platform in the config |
|
1058 | 1049 | # directory. |
|
1059 | 1050 | try: |
|
1060 | 1051 | os.chdir(ipythondir) |
|
1061 | 1052 | except: |
|
1062 | 1053 | print """ |
|
1063 | 1054 | Problem: changing to directory %s failed. |
|
1064 | 1055 | Details: |
|
1065 | 1056 | %s |
|
1066 | 1057 | |
|
1067 | 1058 | Some configuration files may have incorrect line endings. This should not |
|
1068 | 1059 | cause any problems during execution. """ % (ipythondir,sys.exc_info()[1]) |
|
1069 | 1060 | wait() |
|
1070 | 1061 | else: |
|
1071 | 1062 | for fname in glb('ipythonrc*'): |
|
1072 | 1063 | try: |
|
1073 | 1064 | native_line_ends(fname,backup=0) |
|
1074 | 1065 | except IOError: |
|
1075 | 1066 | pass |
|
1076 | 1067 | |
|
1077 | 1068 | if mode == 'install': |
|
1078 | 1069 | print """ |
|
1079 | 1070 | Successful installation! |
|
1080 | 1071 | |
|
1081 | 1072 | Please read the sections 'Initial Configuration' and 'Quick Tips' in the |
|
1082 | 1073 | IPython manual (there are both HTML and PDF versions supplied with the |
|
1083 | 1074 | distribution) to make sure that your system environment is properly configured |
|
1084 | 1075 | to take advantage of IPython's features.""" |
|
1085 | 1076 | else: |
|
1086 | 1077 | print """ |
|
1087 | 1078 | Successful upgrade! |
|
1088 | 1079 | |
|
1089 | 1080 | All files in your directory: |
|
1090 | 1081 | %(ipythondir)s |
|
1091 | 1082 | which would have been overwritten by the upgrade were backed up with a .old |
|
1092 | 1083 | extension. If you had made particular customizations in those files you may |
|
1093 | 1084 | want to merge them back into the new files.""" % locals() |
|
1094 | 1085 | wait() |
|
1095 | 1086 | os.chdir(cwd) |
|
1096 | 1087 | # end user_setup() |
|
1097 | 1088 | |
|
1098 | 1089 | def atexit_operations(self): |
|
1099 | 1090 | """This will be executed at the time of exit. |
|
1100 | 1091 | |
|
1101 | 1092 | Saving of persistent data should be performed here. """ |
|
1102 | 1093 | |
|
1103 | 1094 | # input history |
|
1104 | 1095 | self.savehist() |
|
1105 | 1096 | |
|
1106 | 1097 | # Cleanup all tempfiles left around |
|
1107 | 1098 | for tfile in self.tempfiles: |
|
1108 | 1099 | try: |
|
1109 | 1100 | os.unlink(tfile) |
|
1110 | 1101 | except OSError: |
|
1111 | 1102 | pass |
|
1112 | 1103 | |
|
1113 | 1104 | # save the "persistent data" catch-all dictionary |
|
1114 | 1105 | try: |
|
1115 | 1106 | pickle.dump(self.persist, open(self.persist_fname,"w")) |
|
1116 | 1107 | except: |
|
1117 | 1108 | print "*** ERROR *** persistent data saving failed." |
|
1118 | 1109 | |
|
1119 | 1110 | def savehist(self): |
|
1120 | 1111 | """Save input history to a file (via readline library).""" |
|
1121 | 1112 | try: |
|
1122 | 1113 | self.readline.write_history_file(self.histfile) |
|
1123 | 1114 | except: |
|
1124 | 1115 | print 'Unable to save IPython command history to file: ' + \ |
|
1125 | 1116 | `self.histfile` |
|
1126 | 1117 | |
|
1127 | 1118 | def pre_readline(self): |
|
1128 | 1119 | """readline hook to be used at the start of each line. |
|
1129 | 1120 | |
|
1130 | 1121 | Currently it handles auto-indent only.""" |
|
1131 | 1122 | |
|
1132 | 1123 | self.readline.insert_text(' '* self.readline_indent) |
|
1133 | 1124 | |
|
1134 | 1125 | def init_readline(self): |
|
1135 | 1126 | """Command history completion/saving/reloading.""" |
|
1136 | 1127 | try: |
|
1137 | 1128 | import readline |
|
1138 | 1129 | self.Completer = MagicCompleter(self, |
|
1139 | 1130 | self.user_ns, |
|
1140 | 1131 | self.rc.readline_omit__names, |
|
1141 | 1132 | self.alias_table) |
|
1142 | 1133 | except ImportError,NameError: |
|
1143 | 1134 | # If FlexCompleter failed to import, MagicCompleter won't be |
|
1144 | 1135 | # defined. This can happen because of a problem with readline |
|
1145 | 1136 | self.has_readline = 0 |
|
1146 | 1137 | # no point in bugging windows users with this every time: |
|
1147 | 1138 | if os.name == 'posix': |
|
1148 | 1139 | warn('Readline services not available on this platform.') |
|
1149 | 1140 | else: |
|
1150 | 1141 | import atexit |
|
1151 | 1142 | |
|
1152 | 1143 | # Platform-specific configuration |
|
1153 | 1144 | if os.name == 'nt': |
|
1154 | 1145 | # readline under Windows modifies the default exit behavior |
|
1155 | 1146 | # from being Ctrl-Z/Return to the Unix Ctrl-D one. |
|
1156 | 1147 | __builtin__.exit = __builtin__.quit = \ |
|
1157 | 1148 | ('Use Ctrl-D (i.e. EOF) to exit. ' |
|
1158 | 1149 | 'Use %Exit or %Quit to exit without confirmation.') |
|
1159 | 1150 | self.readline_startup_hook = readline.set_pre_input_hook |
|
1160 | 1151 | else: |
|
1161 | 1152 | self.readline_startup_hook = readline.set_startup_hook |
|
1162 | 1153 | |
|
1163 | 1154 | # Load user's initrc file (readline config) |
|
1164 | 1155 | inputrc_name = os.environ.get('INPUTRC') |
|
1165 | 1156 | if inputrc_name is None: |
|
1166 | 1157 | home_dir = get_home_dir() |
|
1167 | 1158 | if home_dir is not None: |
|
1168 | 1159 | inputrc_name = os.path.join(home_dir,'.inputrc') |
|
1169 | 1160 | if os.path.isfile(inputrc_name): |
|
1170 | 1161 | try: |
|
1171 | 1162 | readline.read_init_file(inputrc_name) |
|
1172 | 1163 | except: |
|
1173 | 1164 | warn('Problems reading readline initialization file <%s>' |
|
1174 | 1165 | % inputrc_name) |
|
1175 | 1166 | |
|
1176 | 1167 | self.has_readline = 1 |
|
1177 | 1168 | self.readline = readline |
|
1178 | 1169 | self.readline_indent = 0 # for auto-indenting via readline |
|
1179 | 1170 | # save this in sys so embedded copies can restore it properly |
|
1180 | 1171 | sys.ipcompleter = self.Completer.complete |
|
1181 | 1172 | readline.set_completer(self.Completer.complete) |
|
1182 | 1173 | |
|
1183 | 1174 | # Configure readline according to user's prefs |
|
1184 | 1175 | for rlcommand in self.rc.readline_parse_and_bind: |
|
1185 | 1176 | readline.parse_and_bind(rlcommand) |
|
1186 | 1177 | |
|
1187 | 1178 | # remove some chars from the delimiters list |
|
1188 | 1179 | delims = readline.get_completer_delims() |
|
1189 | 1180 | delims = delims.translate(string._idmap, |
|
1190 | 1181 | self.rc.readline_remove_delims) |
|
1191 | 1182 | readline.set_completer_delims(delims) |
|
1192 | 1183 | # otherwise we end up with a monster history after a while: |
|
1193 | 1184 | readline.set_history_length(1000) |
|
1194 | 1185 | try: |
|
1195 | 1186 | #print '*** Reading readline history' # dbg |
|
1196 | 1187 | readline.read_history_file(self.histfile) |
|
1197 | 1188 | except IOError: |
|
1198 | 1189 | pass # It doesn't exist yet. |
|
1199 | 1190 | |
|
1200 | 1191 | atexit.register(self.atexit_operations) |
|
1201 | 1192 | del atexit |
|
1202 | 1193 | |
|
1203 | 1194 | # Configure auto-indent for all platforms |
|
1204 | 1195 | self.set_autoindent(self.rc.autoindent) |
|
1205 | 1196 | |
|
1206 | 1197 | def showsyntaxerror(self, filename=None): |
|
1207 | 1198 | """Display the syntax error that just occurred. |
|
1208 | 1199 | |
|
1209 | 1200 | This doesn't display a stack trace because there isn't one. |
|
1210 | 1201 | |
|
1211 | 1202 | If a filename is given, it is stuffed in the exception instead |
|
1212 | 1203 | of what was there before (because Python's parser always uses |
|
1213 | 1204 | "<string>" when reading from a string). |
|
1214 | 1205 | """ |
|
1215 | 1206 | type, value, sys.last_traceback = sys.exc_info() |
|
1216 | 1207 | sys.last_type = type |
|
1217 | 1208 | sys.last_value = value |
|
1218 | 1209 | if filename and type is SyntaxError: |
|
1219 | 1210 | # Work hard to stuff the correct filename in the exception |
|
1220 | 1211 | try: |
|
1221 | 1212 | msg, (dummy_filename, lineno, offset, line) = value |
|
1222 | 1213 | except: |
|
1223 | 1214 | # Not the format we expect; leave it alone |
|
1224 | 1215 | pass |
|
1225 | 1216 | else: |
|
1226 | 1217 | # Stuff in the right filename |
|
1227 | 1218 | try: |
|
1228 | 1219 | # Assume SyntaxError is a class exception |
|
1229 | 1220 | value = SyntaxError(msg, (filename, lineno, offset, line)) |
|
1230 | 1221 | except: |
|
1231 | 1222 | # If that failed, assume SyntaxError is a string |
|
1232 | 1223 | value = msg, (filename, lineno, offset, line) |
|
1233 | 1224 | self.SyntaxTB(type,value,[]) |
|
1234 | 1225 | |
|
1235 | 1226 | def debugger(self): |
|
1236 | 1227 | """Call the pdb debugger.""" |
|
1237 | 1228 | |
|
1238 | 1229 | if not self.rc.pdb: |
|
1239 | 1230 | return |
|
1240 | 1231 | pdb.pm() |
|
1241 | 1232 | |
|
1242 | 1233 | def showtraceback(self,exc_tuple = None): |
|
1243 | 1234 | """Display the exception that just occurred.""" |
|
1244 | 1235 | |
|
1245 | 1236 | # Though this won't be called by syntax errors in the input line, |
|
1246 | 1237 | # there may be SyntaxError cases whith imported code. |
|
1247 | 1238 | if exc_tuple is None: |
|
1248 | 1239 | type, value, tb = sys.exc_info() |
|
1249 | 1240 | else: |
|
1250 | 1241 | type, value, tb = exc_tuple |
|
1251 | 1242 | if type is SyntaxError: |
|
1252 | 1243 | self.showsyntaxerror() |
|
1253 | 1244 | else: |
|
1254 | 1245 | sys.last_type = type |
|
1255 | 1246 | sys.last_value = value |
|
1256 | 1247 | sys.last_traceback = tb |
|
1257 | 1248 | self.InteractiveTB() |
|
1258 | 1249 | if self.InteractiveTB.call_pdb and self.has_readline: |
|
1259 | 1250 | # pdb mucks up readline, fix it back |
|
1260 | 1251 | self.readline.set_completer(self.Completer.complete) |
|
1261 | 1252 | |
|
1262 | 1253 | def update_cache(self, line): |
|
1263 | 1254 | """puts line into cache""" |
|
1264 | 1255 | self.inputcache.insert(0, line) # This copies the cache every time ... :-( |
|
1265 | 1256 | if len(self.inputcache) >= self.CACHELENGTH: |
|
1266 | 1257 | self.inputcache.pop() # This not :-) |
|
1267 | 1258 | |
|
1268 | 1259 | def name_space_init(self): |
|
1269 | 1260 | """Create local namespace.""" |
|
1270 | 1261 | # We want this to be a method to facilitate embedded initialization. |
|
1271 | 1262 | code.InteractiveConsole.__init__(self,self.user_ns) |
|
1272 | 1263 | |
|
1273 | 1264 | def mainloop(self,banner=None): |
|
1274 | 1265 | """Creates the local namespace and starts the mainloop. |
|
1275 | 1266 | |
|
1276 | 1267 | If an optional banner argument is given, it will override the |
|
1277 | 1268 | internally created default banner.""" |
|
1278 | 1269 | |
|
1279 | 1270 | self.name_space_init() |
|
1280 | 1271 | if self.rc.c: # Emulate Python's -c option |
|
1281 | 1272 | self.exec_init_cmd() |
|
1282 | 1273 | if banner is None: |
|
1283 | 1274 | if self.rc.banner: |
|
1284 | 1275 | banner = self.BANNER+self.banner2 |
|
1285 | 1276 | else: |
|
1286 | 1277 | banner = '' |
|
1287 | 1278 | self.interact(banner) |
|
1288 | 1279 | |
|
1289 | 1280 | def exec_init_cmd(self): |
|
1290 | 1281 | """Execute a command given at the command line. |
|
1291 | 1282 | |
|
1292 | 1283 | This emulates Python's -c option.""" |
|
1293 | 1284 | |
|
1294 | 1285 | sys.argv = ['-c'] |
|
1295 | 1286 | self.push(self.rc.c) |
|
1296 | 1287 | |
|
1297 | 1288 | def embed_mainloop(self,header='',local_ns=None,global_ns=None,stack_depth=0): |
|
1298 | 1289 | """Embeds IPython into a running python program. |
|
1299 | 1290 | |
|
1300 | 1291 | Input: |
|
1301 | 1292 | |
|
1302 | 1293 | - header: An optional header message can be specified. |
|
1303 | 1294 | |
|
1304 | 1295 | - local_ns, global_ns: working namespaces. If given as None, the |
|
1305 | 1296 | IPython-initialized one is updated with __main__.__dict__, so that |
|
1306 | 1297 | program variables become visible but user-specific configuration |
|
1307 | 1298 | remains possible. |
|
1308 | 1299 | |
|
1309 | 1300 | - stack_depth: specifies how many levels in the stack to go to |
|
1310 | 1301 | looking for namespaces (when local_ns and global_ns are None). This |
|
1311 | 1302 | allows an intermediate caller to make sure that this function gets |
|
1312 | 1303 | the namespace from the intended level in the stack. By default (0) |
|
1313 | 1304 | it will get its locals and globals from the immediate caller. |
|
1314 | 1305 | |
|
1315 | 1306 | Warning: it's possible to use this in a program which is being run by |
|
1316 | 1307 | IPython itself (via %run), but some funny things will happen (a few |
|
1317 | 1308 | globals get overwritten). In the future this will be cleaned up, as |
|
1318 | 1309 | there is no fundamental reason why it can't work perfectly.""" |
|
1319 | 1310 | |
|
1320 | 1311 | # Patch for global embedding to make sure that things don't overwrite |
|
1321 | 1312 | # user globals accidentally. Thanks to Richard <rxe@renre-europe.com> |
|
1322 | 1313 | # FIXME. Test this a bit more carefully (the if.. is new) |
|
1323 | 1314 | if local_ns is None and global_ns is None: |
|
1324 | 1315 | self.user_ns.update(__main__.__dict__) |
|
1325 | 1316 | |
|
1326 | 1317 | # Get locals and globals from caller |
|
1327 | 1318 | if local_ns is None or global_ns is None: |
|
1328 | 1319 | call_frame = sys._getframe(stack_depth).f_back |
|
1329 | 1320 | |
|
1330 | 1321 | if local_ns is None: |
|
1331 | 1322 | local_ns = call_frame.f_locals |
|
1332 | 1323 | if global_ns is None: |
|
1333 | 1324 | global_ns = call_frame.f_globals |
|
1334 | 1325 | |
|
1335 | 1326 | # Update namespaces and fire up interpreter |
|
1336 | 1327 | self.user_ns.update(local_ns) |
|
1337 | 1328 | self.interact(header) |
|
1338 | 1329 | |
|
1339 | 1330 | # Remove locals from namespace |
|
1340 |
for k in local_ns |
|
|
1331 | for k in local_ns: | |
|
1341 | 1332 | del self.user_ns[k] |
|
1342 | 1333 | |
|
1343 | 1334 | def interact(self, banner=None): |
|
1344 | 1335 | """Closely emulate the interactive Python console. |
|
1345 | 1336 | |
|
1346 | 1337 | The optional banner argument specify the banner to print |
|
1347 | 1338 | before the first interaction; by default it prints a banner |
|
1348 | 1339 | similar to the one printed by the real Python interpreter, |
|
1349 | 1340 | followed by the current class name in parentheses (so as not |
|
1350 | 1341 | to confuse this with the real interpreter -- since it's so |
|
1351 | 1342 | close!). |
|
1352 | 1343 | |
|
1353 | 1344 | """ |
|
1354 | 1345 | cprt = 'Type "copyright", "credits" or "license" for more information.' |
|
1355 | 1346 | if banner is None: |
|
1356 | 1347 | self.write("Python %s on %s\n%s\n(%s)\n" % |
|
1357 | 1348 | (sys.version, sys.platform, cprt, |
|
1358 | 1349 | self.__class__.__name__)) |
|
1359 | 1350 | else: |
|
1360 | 1351 | self.write(banner) |
|
1361 | 1352 | |
|
1362 | 1353 | more = 0 |
|
1363 | 1354 | |
|
1364 | 1355 | # Mark activity in the builtins |
|
1365 | 1356 | __builtin__.__dict__['__IPYTHON__active'] += 1 |
|
1366 | while 1: | |
|
1367 |
|
|
|
1368 |
|
|
|
1369 | break | |
|
1357 | ||
|
1358 | # exit_now is set by a call to %Exit or %Quit | |
|
1359 | while not self.exit_now: | |
|
1370 | 1360 | try: |
|
1371 | 1361 | if more: |
|
1372 | 1362 | prompt = self.outputcache.prompt2 |
|
1373 | 1363 | if self.autoindent: |
|
1374 | 1364 | self.readline_startup_hook(self.pre_readline) |
|
1375 | 1365 | else: |
|
1376 | 1366 | prompt = self.outputcache.prompt1 |
|
1377 | 1367 | try: |
|
1378 | 1368 | line = self.raw_input(prompt) |
|
1379 | 1369 | if self.autoindent: |
|
1380 | 1370 | self.readline_startup_hook(None) |
|
1381 | 1371 | except EOFError: |
|
1382 | 1372 | if self.autoindent: |
|
1383 | 1373 | self.readline_startup_hook(None) |
|
1384 | 1374 | self.write("\n") |
|
1385 | 1375 | if self.rc.confirm_exit: |
|
1386 | 1376 | if ask_yes_no('Do you really want to exit ([y]/n)?','y'): |
|
1387 | 1377 | break |
|
1388 | 1378 | else: |
|
1389 | 1379 | break |
|
1390 | 1380 | else: |
|
1391 | 1381 | more = self.push(line) |
|
1392 | 1382 | # Auto-indent management |
|
1393 | 1383 | if self.autoindent: |
|
1394 | 1384 | if line: |
|
1395 | 1385 | ini_spaces = re.match('^(\s+)',line) |
|
1396 | 1386 | if ini_spaces: |
|
1397 | 1387 | nspaces = ini_spaces.end() |
|
1398 | 1388 | else: |
|
1399 | 1389 | nspaces = 0 |
|
1400 | 1390 | self.readline_indent = nspaces |
|
1401 | 1391 | |
|
1402 | 1392 | if line[-1] == ':': |
|
1403 | 1393 | self.readline_indent += 4 |
|
1404 | 1394 | elif re.match(r'^\s+raise|^\s+return',line): |
|
1405 | 1395 | self.readline_indent -= 4 |
|
1406 | 1396 | else: |
|
1407 | 1397 | self.readline_indent = 0 |
|
1408 | 1398 | |
|
1409 | 1399 | except KeyboardInterrupt: |
|
1410 | 1400 | self.write("\nKeyboardInterrupt\n") |
|
1411 | 1401 | self.resetbuffer() |
|
1412 | 1402 | more = 0 |
|
1413 | 1403 | # keep cache in sync with the prompt counter: |
|
1414 | 1404 | self.outputcache.prompt_count -= 1 |
|
1415 | 1405 | |
|
1416 | 1406 | if self.autoindent: |
|
1417 | 1407 | self.readline_indent = 0 |
|
1418 | 1408 | |
|
1419 | 1409 | except bdb.BdbQuit: |
|
1420 | 1410 | warn("The Python debugger has exited with a BdbQuit exception.\n" |
|
1421 | 1411 | "Because of how pdb handles the stack, it is impossible\n" |
|
1422 | 1412 | "for IPython to properly format this particular exception.\n" |
|
1423 | 1413 | "IPython will resume normal operation.") |
|
1424 |
|
|
|
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 | ||
|
1414 | ||
|
1500 | 1415 | # We are off again... |
|
1501 | 1416 | __builtin__.__dict__['__IPYTHON__active'] -= 1 |
|
1502 | 1417 | |
|
1503 | 1418 | def excepthook(self, type, value, tb): |
|
1504 | 1419 | """One more defense for GUI apps that call sys.excepthook. |
|
1505 | 1420 | |
|
1506 | 1421 | GUI frameworks like wxPython trap exceptions and call |
|
1507 | 1422 | sys.excepthook themselves. I guess this is a feature that |
|
1508 | 1423 | enables them to keep running after exceptions that would |
|
1509 | 1424 | otherwise kill their mainloop. This is a bother for IPython |
|
1510 | 1425 | which excepts to catch all of the program exceptions with a try: |
|
1511 | 1426 | except: statement. |
|
1512 | 1427 | |
|
1513 | 1428 | Normally, IPython sets sys.excepthook to a CrashHandler instance, so if |
|
1514 | 1429 | any app directly invokes sys.excepthook, it will look to the user like |
|
1515 | 1430 | IPython crashed. In order to work around this, we can disable the |
|
1516 | 1431 | CrashHandler and replace it with this excepthook instead, which prints a |
|
1517 | 1432 | regular traceback using our InteractiveTB. In this fashion, apps which |
|
1518 | 1433 | call sys.excepthook will generate a regular-looking exception from |
|
1519 | 1434 | IPython, and the CrashHandler will only be triggered by real IPython |
|
1520 | 1435 | crashes. |
|
1521 | 1436 | |
|
1522 | 1437 | This hook should be used sparingly, only in places which are not likely |
|
1523 | 1438 | to be true IPython errors. |
|
1524 | 1439 | """ |
|
1525 | 1440 | |
|
1526 | 1441 | self.InteractiveTB(type, value, tb, tb_offset=0) |
|
1527 | 1442 | if self.InteractiveTB.call_pdb and self.has_readline: |
|
1528 | 1443 | self.readline.set_completer(self.Completer.complete) |
|
1529 | 1444 | |
|
1530 | 1445 | def call_alias(self,alias,rest=''): |
|
1531 | 1446 | """Call an alias given its name and the rest of the line. |
|
1532 | 1447 | |
|
1533 | 1448 | This function MUST be given a proper alias, because it doesn't make |
|
1534 | 1449 | any checks when looking up into the alias table. The caller is |
|
1535 | 1450 | responsible for invoking it only with a valid alias.""" |
|
1536 | 1451 | |
|
1537 | 1452 | #print 'ALIAS: <%s>+<%s>' % (alias,rest) # dbg |
|
1538 | 1453 | nargs,cmd = self.alias_table[alias] |
|
1539 | 1454 | # Expand the %l special to be the user's input line |
|
1540 | 1455 | if cmd.find('%l') >= 0: |
|
1541 | 1456 | cmd = cmd.replace('%l',rest) |
|
1542 | 1457 | rest = '' |
|
1543 | 1458 | if nargs==0: |
|
1544 | 1459 | # Simple, argument-less aliases |
|
1545 | 1460 | cmd = '%s %s' % (cmd,rest) |
|
1546 | 1461 | else: |
|
1547 | 1462 | # Handle aliases with positional arguments |
|
1548 | 1463 | args = rest.split(None,nargs) |
|
1549 | 1464 | if len(args)< nargs: |
|
1550 | 1465 | error('Alias <%s> requires %s arguments, %s given.' % |
|
1551 | 1466 | (alias,nargs,len(args))) |
|
1552 | 1467 | return |
|
1553 | 1468 | cmd = '%s %s' % (cmd % tuple(args[:nargs]),' '.join(args[nargs:])) |
|
1554 | 1469 | # Now call the macro, evaluating in the user's namespace |
|
1555 | 1470 | try: |
|
1556 | 1471 | self.system(cmd) |
|
1557 | 1472 | except: |
|
1558 | 1473 | self.showtraceback() |
|
1559 | 1474 | |
|
1560 | 1475 | def runlines(self,lines): |
|
1561 | 1476 | """Run a string of one or more lines of source. |
|
1562 | 1477 | |
|
1563 | 1478 | This method is capable of running a string containing multiple source |
|
1564 | 1479 | lines, as if they had been entered at the IPython prompt. Since it |
|
1565 | 1480 | exposes IPython's processing machinery, the given strings can contain |
|
1566 | 1481 | magic calls (%magic), special shell access (!cmd), etc.""" |
|
1567 | 1482 | |
|
1568 | 1483 | # We must start with a clean buffer, in case this is run from an |
|
1569 | 1484 | # interactive IPython session (via a magic, for example). |
|
1570 | 1485 | self.resetbuffer() |
|
1571 | 1486 | lines = lines.split('\n') |
|
1572 | 1487 | more = 0 |
|
1573 | 1488 | for line in lines: |
|
1574 | 1489 | # skip blank lines so we don't mess up the prompt counter, but do |
|
1575 | 1490 | # NOT skip even a blank line if we are in a code block (more is |
|
1576 | 1491 | # true) |
|
1577 | 1492 | if line or more: |
|
1578 | 1493 | more = self.push((self.prefilter(line,more))) |
|
1579 | 1494 | # IPython's runsource returns None if there was an error |
|
1580 | 1495 | # compiling the code. This allows us to stop processing right |
|
1581 | 1496 | # away, so the user gets the error message at the right place. |
|
1582 | 1497 | if more is None: |
|
1583 | 1498 | break |
|
1584 | 1499 | # final newline in case the input didn't have it, so that the code |
|
1585 | 1500 | # actually does get executed |
|
1586 | 1501 | if more: |
|
1587 | 1502 | self.push('\n') |
|
1588 | 1503 | |
|
1589 | 1504 | def runsource(self, source, filename="<input>", symbol="single"): |
|
1590 | 1505 | """Compile and run some source in the interpreter. |
|
1591 | 1506 | |
|
1592 | 1507 | Arguments are as for compile_command(). |
|
1593 | 1508 | |
|
1594 | 1509 | One several things can happen: |
|
1595 | 1510 | |
|
1596 | 1511 | 1) The input is incorrect; compile_command() raised an |
|
1597 | 1512 | exception (SyntaxError or OverflowError). A syntax traceback |
|
1598 | 1513 | will be printed by calling the showsyntaxerror() method. |
|
1599 | 1514 | |
|
1600 | 1515 | 2) The input is incomplete, and more input is required; |
|
1601 | 1516 | compile_command() returned None. Nothing happens. |
|
1602 | 1517 | |
|
1603 | 1518 | 3) The input is complete; compile_command() returned a code |
|
1604 | 1519 | object. The code is executed by calling self.runcode() (which |
|
1605 | 1520 | also handles run-time exceptions, except for SystemExit). |
|
1606 | 1521 | |
|
1607 | 1522 | The return value is: |
|
1608 | 1523 | |
|
1609 | 1524 | - True in case 2 |
|
1610 | 1525 | |
|
1611 | 1526 | - False in the other cases, unless an exception is raised, where |
|
1612 | 1527 | None is returned instead. This can be used by external callers to |
|
1613 | 1528 | know whether to continue feeding input or not. |
|
1614 | 1529 | |
|
1615 | 1530 | The return value can be used to decide whether to use sys.ps1 or |
|
1616 | 1531 | sys.ps2 to prompt the next line.""" |
|
1617 | 1532 | try: |
|
1618 | 1533 | code = self.compile(source, filename, symbol) |
|
1619 | 1534 | except (OverflowError, SyntaxError, ValueError): |
|
1620 | 1535 | # Case 1 |
|
1621 | 1536 | self.showsyntaxerror(filename) |
|
1622 | 1537 | return None |
|
1623 | 1538 | |
|
1624 | 1539 | if code is None: |
|
1625 | 1540 | # Case 2 |
|
1626 | 1541 | return True |
|
1627 | 1542 | |
|
1628 | 1543 | # Case 3 |
|
1629 | 1544 | # We store the code source and object so that threaded shells and |
|
1630 | 1545 | # custom exception handlers can access all this info if needed. |
|
1631 | 1546 | self.code_to_run_src = source |
|
1632 | 1547 | self.code_to_run = code |
|
1633 | 1548 | # now actually execute the code object |
|
1634 | 1549 | if self.runcode(code) == 0: |
|
1635 | 1550 | return False |
|
1636 | 1551 | else: |
|
1637 | 1552 | return None |
|
1638 | 1553 | |
|
1639 | 1554 | def runcode(self,code_obj): |
|
1640 | 1555 | """Execute a code object. |
|
1641 | 1556 | |
|
1642 | 1557 | When an exception occurs, self.showtraceback() is called to display a |
|
1643 | 1558 | traceback. |
|
1644 | 1559 | |
|
1645 | 1560 | Return value: a flag indicating whether the code to be run completed |
|
1646 | 1561 | successfully: |
|
1647 | 1562 | |
|
1648 | 1563 | - 0: successful execution. |
|
1649 | 1564 | - 1: an error occurred. |
|
1650 | 1565 | """ |
|
1651 | 1566 | |
|
1652 | 1567 | # Set our own excepthook in case the user code tries to call it |
|
1653 | 1568 | # directly, so that the IPython crash handler doesn't get triggered |
|
1654 | 1569 | old_excepthook,sys.excepthook = sys.excepthook, self.excepthook |
|
1655 | 1570 | outflag = 1 # happens in more places, so it's easier as default |
|
1656 | 1571 | try: |
|
1657 | 1572 | try: |
|
1658 | 1573 | exec code_obj in self.locals |
|
1659 | 1574 | finally: |
|
1660 | 1575 | # Reset our crash handler in place |
|
1661 | 1576 | sys.excepthook = old_excepthook |
|
1662 | 1577 | except SystemExit: |
|
1663 | 1578 | self.resetbuffer() |
|
1664 | 1579 | self.showtraceback() |
|
1665 | 1580 | warn( __builtin__.exit,level=1) |
|
1666 | 1581 | except self.custom_exceptions: |
|
1667 | 1582 | etype,value,tb = sys.exc_info() |
|
1668 | 1583 | self.CustomTB(etype,value,tb) |
|
1669 | 1584 | except: |
|
1670 | 1585 | self.showtraceback() |
|
1671 | 1586 | else: |
|
1672 | 1587 | outflag = 0 |
|
1673 | 1588 | if code.softspace(sys.stdout, 0): |
|
1674 | 1589 | |
|
1675 | 1590 | # Flush out code object which has been run (and source) |
|
1676 | 1591 | self.code_to_run = None |
|
1677 | 1592 | self.code_to_run_src = '' |
|
1678 | 1593 | return outflag |
|
1679 | 1594 | |
|
1680 | 1595 | def raw_input(self, prompt=""): |
|
1681 | 1596 | """Write a prompt and read a line. |
|
1682 | 1597 | |
|
1683 | 1598 | The returned line does not include the trailing newline. |
|
1684 | 1599 | When the user enters the EOF key sequence, EOFError is raised. |
|
1685 | 1600 | |
|
1686 | 1601 | The base implementation uses the built-in function |
|
1687 | 1602 | raw_input(); a subclass may replace this with a different |
|
1688 | 1603 | implementation. |
|
1689 | 1604 | """ |
|
1690 | 1605 | return self.prefilter(raw_input_original(prompt), |
|
1691 | 1606 | prompt==self.outputcache.prompt2) |
|
1692 | 1607 | |
|
1693 | 1608 | def split_user_input(self,line): |
|
1694 | 1609 | """Split user input into pre-char, function part and rest.""" |
|
1695 | 1610 | |
|
1696 | 1611 | lsplit = self.line_split.match(line) |
|
1697 | 1612 | if lsplit is None: # no regexp match returns None |
|
1698 | 1613 | try: |
|
1699 | 1614 | iFun,theRest = line.split(None,1) |
|
1700 | 1615 | except ValueError: |
|
1701 | 1616 | iFun,theRest = line,'' |
|
1702 | 1617 | pre = re.match('^(\s*)(.*)',line).groups()[0] |
|
1703 | 1618 | else: |
|
1704 | 1619 | pre,iFun,theRest = lsplit.groups() |
|
1705 | 1620 | |
|
1706 | 1621 | #print 'line:<%s>' % line # dbg |
|
1707 | 1622 | #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun.strip(),theRest) # dbg |
|
1708 | 1623 | return pre,iFun.strip(),theRest |
|
1709 | 1624 | |
|
1710 | 1625 | def _prefilter(self, line, continue_prompt): |
|
1711 | 1626 | """Calls different preprocessors, depending on the form of line.""" |
|
1712 | 1627 | |
|
1713 | 1628 | # All handlers *must* return a value, even if it's blank (''). |
|
1714 | 1629 | |
|
1715 | 1630 | # Lines are NOT logged here. Handlers should process the line as |
|
1716 | 1631 | # needed, update the cache AND log it (so that the input cache array |
|
1717 | 1632 | # stays synced). |
|
1718 | 1633 | |
|
1719 | 1634 | # This function is _very_ delicate, and since it's also the one which |
|
1720 | 1635 | # determines IPython's response to user input, it must be as efficient |
|
1721 | 1636 | # as possible. For this reason it has _many_ returns in it, trying |
|
1722 | 1637 | # always to exit as quickly as it can figure out what it needs to do. |
|
1723 | 1638 | |
|
1724 | 1639 | # This function is the main responsible for maintaining IPython's |
|
1725 | 1640 | # behavior respectful of Python's semantics. So be _very_ careful if |
|
1726 | 1641 | # making changes to anything here. |
|
1727 | 1642 | |
|
1728 | 1643 | #..................................................................... |
|
1729 | 1644 | # Code begins |
|
1730 | 1645 | |
|
1731 | 1646 | #if line.startswith('%crash'): raise RuntimeError,'Crash now!' # dbg |
|
1732 | 1647 | |
|
1733 | 1648 | # save the line away in case we crash, so the post-mortem handler can |
|
1734 | 1649 | # record it |
|
1735 | 1650 | self._last_input_line = line |
|
1736 | 1651 | |
|
1737 | 1652 | #print '***line: <%s>' % line # dbg |
|
1738 | 1653 | |
|
1739 | 1654 | # the input history needs to track even empty lines |
|
1740 | 1655 | if not line.strip(): |
|
1741 | 1656 | if not continue_prompt: |
|
1742 | 1657 | self.outputcache.prompt_count -= 1 |
|
1743 | 1658 | return self.handle_normal('',continue_prompt) |
|
1744 | 1659 | |
|
1745 | 1660 | # print '***cont',continue_prompt # dbg |
|
1746 | 1661 | # special handlers are only allowed for single line statements |
|
1747 | 1662 | if continue_prompt and not self.rc.multi_line_specials: |
|
1748 | 1663 | return self.handle_normal(line,continue_prompt) |
|
1749 | 1664 | |
|
1750 | 1665 | # For the rest, we need the structure of the input |
|
1751 | 1666 | pre,iFun,theRest = self.split_user_input(line) |
|
1752 | 1667 | #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg |
|
1753 | 1668 | |
|
1754 | 1669 | # First check for explicit escapes in the last/first character |
|
1755 | 1670 | handler = None |
|
1756 | 1671 | if line[-1] == self.ESC_HELP: |
|
1757 | 1672 | handler = self.esc_handlers.get(line[-1]) # the ? can be at the end |
|
1758 | 1673 | if handler is None: |
|
1759 | 1674 | # look at the first character of iFun, NOT of line, so we skip |
|
1760 | 1675 | # leading whitespace in multiline input |
|
1761 | 1676 | handler = self.esc_handlers.get(iFun[0:1]) |
|
1762 | 1677 | if handler is not None: |
|
1763 | 1678 | return handler(line,continue_prompt,pre,iFun,theRest) |
|
1764 | 1679 | # Emacs ipython-mode tags certain input lines |
|
1765 | 1680 | if line.endswith('# PYTHON-MODE'): |
|
1766 | 1681 | return self.handle_emacs(line,continue_prompt) |
|
1767 | 1682 | |
|
1768 | 1683 | # Next, check if we can automatically execute this thing |
|
1769 | 1684 | |
|
1770 | 1685 | # Allow ! in multi-line statements if multi_line_specials is on: |
|
1771 | 1686 | if continue_prompt and self.rc.multi_line_specials and \ |
|
1772 | 1687 | iFun.startswith(self.ESC_SHELL): |
|
1773 | 1688 | return self.handle_shell_escape(line,continue_prompt, |
|
1774 | 1689 | pre=pre,iFun=iFun, |
|
1775 | 1690 | theRest=theRest) |
|
1776 | 1691 | |
|
1777 | 1692 | # Let's try to find if the input line is a magic fn |
|
1778 | 1693 | oinfo = None |
|
1779 | 1694 | if hasattr(self,'magic_'+iFun): |
|
1780 | 1695 | oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic |
|
1781 | 1696 | if oinfo['ismagic']: |
|
1782 | 1697 | # Be careful not to call magics when a variable assignment is |
|
1783 | 1698 | # being made (ls='hi', for example) |
|
1784 | 1699 | if self.rc.automagic and \ |
|
1785 | 1700 | (len(theRest)==0 or theRest[0] not in '!=()<>,') and \ |
|
1786 | 1701 | (self.rc.multi_line_specials or not continue_prompt): |
|
1787 | 1702 | return self.handle_magic(line,continue_prompt, |
|
1788 | 1703 | pre,iFun,theRest) |
|
1789 | 1704 | else: |
|
1790 | 1705 | return self.handle_normal(line,continue_prompt) |
|
1791 | 1706 | |
|
1792 | 1707 | # If the rest of the line begins with an (in)equality, assginment or |
|
1793 | 1708 | # function call, we should not call _ofind but simply execute it. |
|
1794 | 1709 | # This avoids spurious geattr() accesses on objects upon assignment. |
|
1795 | 1710 | # |
|
1796 | 1711 | # It also allows users to assign to either alias or magic names true |
|
1797 | 1712 | # python variables (the magic/alias systems always take second seat to |
|
1798 | 1713 | # true python code). |
|
1799 | 1714 | if theRest and theRest[0] in '!=()': |
|
1800 | 1715 | return self.handle_normal(line,continue_prompt) |
|
1801 | 1716 | |
|
1802 | 1717 | if oinfo is None: |
|
1803 | 1718 | oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic |
|
1804 | 1719 | |
|
1805 | 1720 | if not oinfo['found']: |
|
1806 | 1721 | return self.handle_normal(line,continue_prompt) |
|
1807 | 1722 | else: |
|
1808 | 1723 | #print 'iFun <%s> rest <%s>' % (iFun,theRest) # dbg |
|
1809 | 1724 | if oinfo['isalias']: |
|
1810 | 1725 | return self.handle_alias(line,continue_prompt, |
|
1811 | 1726 | pre,iFun,theRest) |
|
1812 | 1727 | |
|
1813 | 1728 | if self.rc.autocall and \ |
|
1814 | 1729 | not self.re_exclude_auto.match(theRest) and \ |
|
1815 | 1730 | self.re_fun_name.match(iFun) and \ |
|
1816 | 1731 | callable(oinfo['obj']) : |
|
1817 | 1732 | #print 'going auto' # dbg |
|
1818 | 1733 | return self.handle_auto(line,continue_prompt,pre,iFun,theRest) |
|
1819 | 1734 | else: |
|
1820 | 1735 | #print 'was callable?', callable(oinfo['obj']) # dbg |
|
1821 | 1736 | return self.handle_normal(line,continue_prompt) |
|
1822 | 1737 | |
|
1823 | 1738 | # If we get here, we have a normal Python line. Log and return. |
|
1824 | 1739 | return self.handle_normal(line,continue_prompt) |
|
1825 | 1740 | |
|
1826 | 1741 | def _prefilter_dumb(self, line, continue_prompt): |
|
1827 | 1742 | """simple prefilter function, for debugging""" |
|
1828 | 1743 | return self.handle_normal(line,continue_prompt) |
|
1829 | 1744 | |
|
1830 | 1745 | # Set the default prefilter() function (this can be user-overridden) |
|
1831 | 1746 | prefilter = _prefilter |
|
1832 | 1747 | |
|
1833 | 1748 | def handle_normal(self,line,continue_prompt=None, |
|
1834 | 1749 | pre=None,iFun=None,theRest=None): |
|
1835 | 1750 | """Handle normal input lines. Use as a template for handlers.""" |
|
1836 | 1751 | |
|
1837 | 1752 | self.log(line,continue_prompt) |
|
1838 | 1753 | self.update_cache(line) |
|
1839 | 1754 | return line |
|
1840 | 1755 | |
|
1841 | 1756 | def handle_alias(self,line,continue_prompt=None, |
|
1842 | 1757 | pre=None,iFun=None,theRest=None): |
|
1843 | 1758 | """Handle alias input lines. """ |
|
1844 | 1759 | |
|
1845 | 1760 | theRest = esc_quotes(theRest) |
|
1846 | 1761 | line_out = "%s%s.call_alias('%s','%s')" % (pre,self.name,iFun,theRest) |
|
1847 | 1762 | self.log(line_out,continue_prompt) |
|
1848 | 1763 | self.update_cache(line_out) |
|
1849 | 1764 | return line_out |
|
1850 | 1765 | |
|
1851 | 1766 | def handle_shell_escape(self, line, continue_prompt=None, |
|
1852 | 1767 | pre=None,iFun=None,theRest=None): |
|
1853 | 1768 | """Execute the line in a shell, empty return value""" |
|
1854 | 1769 | |
|
1855 | 1770 | # Example of a special handler. Others follow a similar pattern. |
|
1856 | 1771 | if continue_prompt: # multi-line statements |
|
1857 | 1772 | if iFun.startswith('!!'): |
|
1858 | 1773 | print 'SyntaxError: !! is not allowed in multiline statements' |
|
1859 | 1774 | return pre |
|
1860 | 1775 | else: |
|
1861 | 1776 | cmd = ("%s %s" % (iFun[1:],theRest)).replace('"','\\"') |
|
1862 | 1777 | line_out = '%s%s.system("%s")' % (pre,self.name,cmd) |
|
1863 | 1778 | else: # single-line input |
|
1864 | 1779 | if line.startswith('!!'): |
|
1865 | 1780 | # rewrite iFun/theRest to properly hold the call to %sx and |
|
1866 | 1781 | # the actual command to be executed, so handle_magic can work |
|
1867 | 1782 | # correctly |
|
1868 | 1783 | theRest = '%s %s' % (iFun[2:],theRest) |
|
1869 | 1784 | iFun = 'sx' |
|
1870 | 1785 | return self.handle_magic('%ssx %s' % (self.ESC_MAGIC,line[2:]), |
|
1871 | 1786 | continue_prompt,pre,iFun,theRest) |
|
1872 | 1787 | else: |
|
1873 | 1788 | cmd = esc_quotes(line[1:]) |
|
1874 | 1789 | line_out = '%s.system("%s")' % (self.name,cmd) |
|
1875 | 1790 | # update cache/log and return |
|
1876 | 1791 | self.log(line_out,continue_prompt) |
|
1877 | 1792 | self.update_cache(line_out) # readline cache gets normal line |
|
1878 | 1793 | return line_out |
|
1879 | 1794 | |
|
1880 | 1795 | def handle_magic(self, line, continue_prompt=None, |
|
1881 | 1796 | pre=None,iFun=None,theRest=None): |
|
1882 | 1797 | """Execute magic functions. |
|
1883 | 1798 | |
|
1884 | 1799 | Also log them with a prepended # so the log is clean Python.""" |
|
1885 | 1800 | |
|
1886 | 1801 | cmd = '%sipmagic("%s")' % (pre,esc_quotes('%s %s' % (iFun,theRest))) |
|
1887 | 1802 | self.log(cmd,continue_prompt) |
|
1888 | 1803 | self.update_cache(line) |
|
1889 | 1804 | #print 'in handle_magic, cmd=<%s>' % cmd # dbg |
|
1890 | 1805 | return cmd |
|
1891 | 1806 | |
|
1892 | 1807 | def handle_auto(self, line, continue_prompt=None, |
|
1893 | 1808 | pre=None,iFun=None,theRest=None): |
|
1894 | 1809 | """Hande lines which can be auto-executed, quoting if requested.""" |
|
1895 | 1810 | |
|
1896 | 1811 | #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg |
|
1897 | 1812 | |
|
1898 | 1813 | # This should only be active for single-line input! |
|
1899 | 1814 | if continue_prompt: |
|
1900 | 1815 | return line |
|
1901 | 1816 | |
|
1902 | 1817 | if pre == self.ESC_QUOTE: |
|
1903 | 1818 | # Auto-quote splitting on whitespace |
|
1904 | 1819 | newcmd = '%s("%s")\n' % (iFun,'", "'.join(theRest.split()) ) |
|
1905 | 1820 | elif pre == self.ESC_QUOTE2: |
|
1906 | 1821 | # Auto-quote whole string |
|
1907 | 1822 | newcmd = '%s("%s")\n' % (iFun,theRest) |
|
1908 | 1823 | else: |
|
1909 | 1824 | # Auto-paren |
|
1910 | 1825 | if theRest[0:1] in ('=','['): |
|
1911 | 1826 | # Don't autocall in these cases. They can be either |
|
1912 | 1827 | # rebindings of an existing callable's name, or item access |
|
1913 | 1828 | # for an object which is BOTH callable and implements |
|
1914 | 1829 | # __getitem__. |
|
1915 | 1830 | return '%s %s\n' % (iFun,theRest) |
|
1916 | 1831 | if theRest.endswith(';'): |
|
1917 | 1832 | newcmd = '%s(%s);\n' % (iFun.rstrip(),theRest[:-1]) |
|
1918 | 1833 | else: |
|
1919 | 1834 | newcmd = '%s(%s)\n' % (iFun.rstrip(),theRest) |
|
1920 | 1835 | |
|
1921 | 1836 | print >>Term.cout, self.outputcache.prompt1.auto_rewrite() + newcmd, |
|
1922 | 1837 | # log what is now valid Python, not the actual user input (without the |
|
1923 | 1838 | # final newline) |
|
1924 | 1839 | self.log(newcmd.strip(),continue_prompt) |
|
1925 | 1840 | return newcmd |
|
1926 | 1841 | |
|
1927 | 1842 | def handle_help(self, line, continue_prompt=None, |
|
1928 | 1843 | pre=None,iFun=None,theRest=None): |
|
1929 | 1844 | """Try to get some help for the object. |
|
1930 | 1845 | |
|
1931 | 1846 | obj? or ?obj -> basic information. |
|
1932 | 1847 | obj?? or ??obj -> more details. |
|
1933 | 1848 | """ |
|
1934 | 1849 | |
|
1935 | 1850 | # We need to make sure that we don't process lines which would be |
|
1936 | 1851 | # otherwise valid python, such as "x=1 # what?" |
|
1937 | 1852 | try: |
|
1938 | 1853 | code.compile_command(line) |
|
1939 | 1854 | except SyntaxError: |
|
1940 | 1855 | # We should only handle as help stuff which is NOT valid syntax |
|
1941 | 1856 | if line[0]==self.ESC_HELP: |
|
1942 | 1857 | line = line[1:] |
|
1943 | 1858 | elif line[-1]==self.ESC_HELP: |
|
1944 | 1859 | line = line[:-1] |
|
1945 | 1860 | self.log('#?'+line) |
|
1946 | 1861 | self.update_cache(line) |
|
1947 | 1862 | if line: |
|
1948 | 1863 | self.magic_pinfo(line) |
|
1949 | 1864 | else: |
|
1950 | 1865 | page(self.usage,screen_lines=self.rc.screen_length) |
|
1951 | 1866 | return '' # Empty string is needed here! |
|
1952 | 1867 | except: |
|
1953 | 1868 | # Pass any other exceptions through to the normal handler |
|
1954 | 1869 | return self.handle_normal(line,continue_prompt) |
|
1955 | 1870 | else: |
|
1956 | 1871 | # If the code compiles ok, we should handle it normally |
|
1957 | 1872 | return self.handle_normal(line,continue_prompt) |
|
1958 | 1873 | |
|
1959 | 1874 | def handle_emacs(self,line,continue_prompt=None, |
|
1960 | 1875 | pre=None,iFun=None,theRest=None): |
|
1961 | 1876 | """Handle input lines marked by python-mode.""" |
|
1962 | 1877 | |
|
1963 | 1878 | # Currently, nothing is done. Later more functionality can be added |
|
1964 | 1879 | # here if needed. |
|
1965 | 1880 | |
|
1966 | 1881 | # The input cache shouldn't be updated |
|
1967 | 1882 | |
|
1968 | 1883 | return line |
|
1969 | 1884 | |
|
1970 | 1885 | def write(self,data): |
|
1971 | 1886 | """Write a string to the default output""" |
|
1972 | 1887 | Term.cout.write(data) |
|
1973 | 1888 | |
|
1974 | 1889 | def write_err(self,data): |
|
1975 | 1890 | """Write a string to the default error output""" |
|
1976 | 1891 | Term.cerr.write(data) |
|
1977 | 1892 | |
|
1978 | 1893 | def safe_execfile(self,fname,*where,**kw): |
|
1979 | 1894 | fname = os.path.expanduser(fname) |
|
1980 | 1895 | |
|
1981 | 1896 | # find things also in current directory |
|
1982 | 1897 | dname = os.path.dirname(fname) |
|
1983 | 1898 | if not sys.path.count(dname): |
|
1984 | 1899 | sys.path.append(dname) |
|
1985 | 1900 | |
|
1986 | 1901 | try: |
|
1987 | 1902 | xfile = open(fname) |
|
1988 | 1903 | except: |
|
1989 | 1904 | print >> Term.cerr, \ |
|
1990 | 1905 | 'Could not open file <%s> for safe execution.' % fname |
|
1991 | 1906 | return None |
|
1992 | 1907 | |
|
1993 | 1908 | kw.setdefault('islog',0) |
|
1994 | 1909 | kw.setdefault('quiet',1) |
|
1995 | 1910 | kw.setdefault('exit_ignore',0) |
|
1996 | 1911 | first = xfile.readline() |
|
1997 | 1912 | _LOGHEAD = str(self.LOGHEAD).split('\n',1)[0].strip() |
|
1998 | 1913 | xfile.close() |
|
1999 | 1914 | # line by line execution |
|
2000 | 1915 | if first.startswith(_LOGHEAD) or kw['islog']: |
|
2001 | 1916 | print 'Loading log file <%s> one line at a time...' % fname |
|
2002 | 1917 | if kw['quiet']: |
|
2003 | 1918 | stdout_save = sys.stdout |
|
2004 | 1919 | sys.stdout = StringIO.StringIO() |
|
2005 | 1920 | try: |
|
2006 | 1921 | globs,locs = where[0:2] |
|
2007 | 1922 | except: |
|
2008 | 1923 | try: |
|
2009 | 1924 | globs = locs = where[0] |
|
2010 | 1925 | except: |
|
2011 | 1926 | globs = locs = globals() |
|
2012 | 1927 | badblocks = [] |
|
2013 | 1928 | |
|
2014 | 1929 | # we also need to identify indented blocks of code when replaying |
|
2015 | 1930 | # logs and put them together before passing them to an exec |
|
2016 | 1931 | # statement. This takes a bit of regexp and look-ahead work in the |
|
2017 | 1932 | # file. It's easiest if we swallow the whole thing in memory |
|
2018 | 1933 | # first, and manually walk through the lines list moving the |
|
2019 | 1934 | # counter ourselves. |
|
2020 | 1935 | indent_re = re.compile('\s+\S') |
|
2021 | 1936 | xfile = open(fname) |
|
2022 | 1937 | filelines = xfile.readlines() |
|
2023 | 1938 | xfile.close() |
|
2024 | 1939 | nlines = len(filelines) |
|
2025 | 1940 | lnum = 0 |
|
2026 | 1941 | while lnum < nlines: |
|
2027 | 1942 | line = filelines[lnum] |
|
2028 | 1943 | lnum += 1 |
|
2029 | 1944 | # don't re-insert logger status info into cache |
|
2030 | 1945 | if line.startswith('#log#'): |
|
2031 | 1946 | continue |
|
2032 | 1947 | elif line.startswith('#%s'% self.ESC_MAGIC): |
|
2033 | 1948 | self.update_cache(line[1:]) |
|
2034 | 1949 | line = magic2python(line) |
|
2035 | 1950 | elif line.startswith('#!'): |
|
2036 | 1951 | self.update_cache(line[1:]) |
|
2037 | 1952 | else: |
|
2038 | 1953 | # build a block of code (maybe a single line) for execution |
|
2039 | 1954 | block = line |
|
2040 | 1955 | try: |
|
2041 | 1956 | next = filelines[lnum] # lnum has already incremented |
|
2042 | 1957 | except: |
|
2043 | 1958 | next = None |
|
2044 | 1959 | while next and indent_re.match(next): |
|
2045 | 1960 | block += next |
|
2046 | 1961 | lnum += 1 |
|
2047 | 1962 | try: |
|
2048 | 1963 | next = filelines[lnum] |
|
2049 | 1964 | except: |
|
2050 | 1965 | next = None |
|
2051 | 1966 | # now execute the block of one or more lines |
|
2052 | 1967 | try: |
|
2053 | 1968 | exec block in globs,locs |
|
2054 | 1969 | self.update_cache(block.rstrip()) |
|
2055 | 1970 | except SystemExit: |
|
2056 | 1971 | pass |
|
2057 | 1972 | except: |
|
2058 | 1973 | badblocks.append(block.rstrip()) |
|
2059 | 1974 | if kw['quiet']: # restore stdout |
|
2060 | 1975 | sys.stdout.close() |
|
2061 | 1976 | sys.stdout = stdout_save |
|
2062 | 1977 | print 'Finished replaying log file <%s>' % fname |
|
2063 | 1978 | if badblocks: |
|
2064 | 1979 | print >> sys.stderr, \ |
|
2065 | 1980 | '\nThe following lines/blocks in file <%s> reported errors:' \ |
|
2066 | 1981 | % fname |
|
2067 | 1982 | for badline in badblocks: |
|
2068 | 1983 | print >> sys.stderr, badline |
|
2069 | 1984 | else: # regular file execution |
|
2070 | 1985 | try: |
|
2071 | 1986 | execfile(fname,*where) |
|
2072 | 1987 | except SyntaxError: |
|
2073 | 1988 | etype, evalue = sys.exc_info()[0:2] |
|
2074 | 1989 | self.SyntaxTB(etype,evalue,[]) |
|
2075 | 1990 | warn('Failure executing file: <%s>' % fname) |
|
2076 | 1991 | except SystemExit,status: |
|
2077 | 1992 | if not kw['exit_ignore']: |
|
2078 | 1993 | self.InteractiveTB() |
|
2079 | 1994 | warn('Failure executing file: <%s>' % fname) |
|
2080 | 1995 | except: |
|
2081 | 1996 | self.InteractiveTB() |
|
2082 | 1997 | warn('Failure executing file: <%s>' % fname) |
|
2083 | 1998 | |
|
2084 | 1999 | #************************* end of file <iplib.py> ***************************** |
@@ -1,736 +1,725 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """ |
|
3 | 3 | IPython -- An enhanced Interactive Python |
|
4 | 4 | |
|
5 | 5 | Requires Python 2.1 or better. |
|
6 | 6 | |
|
7 | 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 | 12 | # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu> |
|
13 | 13 | # |
|
14 | 14 | # Distributed under the terms of the BSD License. The full license is in |
|
15 | 15 | # the file COPYING, distributed as part of this software. |
|
16 | 16 | #***************************************************************************** |
|
17 | 17 | |
|
18 | 18 | from IPython import Release |
|
19 | 19 | __author__ = '%s <%s>' % Release.authors['Fernando'] |
|
20 | 20 | __license__ = Release.license |
|
21 | 21 | __version__ = Release.version |
|
22 | 22 | |
|
23 | 23 | credits._Printer__data = """ |
|
24 | 24 | Python: %s |
|
25 | 25 | |
|
26 | 26 | IPython: Fernando Perez, Janko Hauser, Nathan Gray, and many users. |
|
27 | 27 | See http://ipython.scipy.org for more information.""" \ |
|
28 | 28 | % credits._Printer__data |
|
29 | 29 | |
|
30 | 30 | copyright._Printer__data += """ |
|
31 | 31 | |
|
32 | 32 | Copyright (c) 2001-2004 Fernando Perez, Janko Hauser, Nathan Gray. |
|
33 | 33 | All Rights Reserved.""" |
|
34 | 34 | |
|
35 | 35 | #**************************************************************************** |
|
36 | 36 | # Required modules |
|
37 | 37 | |
|
38 | 38 | # From the standard library |
|
39 | 39 | import __main__, __builtin__ |
|
40 | 40 | import os,sys,types,re |
|
41 | 41 | from pprint import pprint,pformat |
|
42 | 42 | |
|
43 | 43 | # Our own |
|
44 | 44 | from IPython import DPyGetOpt |
|
45 | 45 | from IPython.Struct import Struct |
|
46 | 46 | from IPython.OutputTrap import OutputTrap |
|
47 | 47 | from IPython.ConfigLoader import ConfigLoader |
|
48 | 48 | from IPython.iplib import InteractiveShell,qw_lol,import_fail_info |
|
49 | 49 | from IPython.usage import cmd_line_usage,interactive_usage |
|
50 | 50 | from IPython.Prompts import CachedOutput |
|
51 | 51 | from IPython.genutils import * |
|
52 | 52 | |
|
53 | 53 | #----------------------------------------------------------------------------- |
|
54 | 54 | def make_IPython(argv=None,user_ns=None,debug=1,rc_override=None, |
|
55 | 55 | shell_class=InteractiveShell,embedded=False,**kw): |
|
56 | 56 | """This is a dump of IPython into a single function. |
|
57 | 57 | |
|
58 | 58 | Later it will have to be broken up in a sensible manner. |
|
59 | 59 | |
|
60 | 60 | Arguments: |
|
61 | 61 | |
|
62 | 62 | - argv: a list similar to sys.argv[1:]. It should NOT contain the desired |
|
63 | 63 | script name, b/c DPyGetOpt strips the first argument only for the real |
|
64 | 64 | sys.argv. |
|
65 | 65 | |
|
66 | 66 | - user_ns: a dict to be used as the user's namespace.""" |
|
67 | 67 | |
|
68 | 68 | #---------------------------------------------------------------------- |
|
69 | 69 | # Defaults and initialization |
|
70 | 70 | |
|
71 | 71 | # For developer debugging, deactivates crash handler and uses pdb. |
|
72 | 72 | DEVDEBUG = False |
|
73 | 73 | |
|
74 | 74 | if argv is None: |
|
75 | 75 | argv = sys.argv |
|
76 | 76 | |
|
77 | 77 | # __IP is the main global that lives throughout and represents the whole |
|
78 | 78 | # application. If the user redefines it, all bets are off as to what |
|
79 | 79 | # happens. |
|
80 | 80 | |
|
81 | 81 | # __IP is the name of he global which the caller will have accessible as |
|
82 | 82 | # __IP.name. We set its name via the first parameter passed to |
|
83 | 83 | # InteractiveShell: |
|
84 | 84 | |
|
85 | 85 | IP = shell_class('__IP',user_ns=user_ns,**kw) |
|
86 | 86 | |
|
87 | 87 | # Put 'help' in the user namespace |
|
88 | try: | |
|
89 | from site import _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() | |
|
88 | from site import _Helper | |
|
89 | IP.user_ns['help'] = _Helper() | |
|
101 | 90 | |
|
102 | 91 | if DEVDEBUG: |
|
103 | 92 | # For developer debugging only (global flag) |
|
104 | 93 | from IPython import ultraTB |
|
105 | 94 | sys.excepthook = ultraTB.VerboseTB(call_pdb=1) |
|
106 | 95 | else: |
|
107 | 96 | # IPython itself shouldn't crash. This will produce a detailed |
|
108 | 97 | # post-mortem if it does |
|
109 | 98 | from IPython import CrashHandler |
|
110 | 99 | sys.excepthook = CrashHandler.CrashHandler(IP) |
|
111 | 100 | |
|
112 | 101 | IP.BANNER_PARTS = ['Python %s\n' |
|
113 | 102 | 'Type "copyright", "credits" or "license" ' |
|
114 | 103 | 'for more information.\n' |
|
115 | 104 | % (sys.version.split('\n')[0],), |
|
116 | 105 | "IPython %s -- An enhanced Interactive Python." |
|
117 | 106 | % (__version__,), |
|
118 | 107 | """? -> Introduction to IPython's features. |
|
119 | 108 | %magic -> Information about IPython's 'magic' % functions. |
|
120 | 109 | help -> Python's own help system. |
|
121 | 110 | object? -> Details about 'object'. ?object also works, ?? prints more. |
|
122 | 111 | """ ] |
|
123 | 112 | |
|
124 | 113 | IP.usage = interactive_usage |
|
125 | 114 | |
|
126 | 115 | # Platform-dependent suffix and directory names |
|
127 | 116 | if os.name == 'posix': |
|
128 | 117 | rc_suffix = '' |
|
129 | 118 | ipdir_def = '.ipython' |
|
130 | 119 | else: |
|
131 | 120 | rc_suffix = '.ini' |
|
132 | 121 | ipdir_def = '_ipython' |
|
133 | 122 | |
|
134 | 123 | # default directory for configuration |
|
135 | 124 | ipythondir = os.path.abspath(os.environ.get('IPYTHONDIR', |
|
136 | 125 | os.path.join(IP.home_dir,ipdir_def))) |
|
137 | 126 | |
|
138 | 127 | # we need the directory where IPython itself is installed |
|
139 | 128 | import IPython |
|
140 | 129 | IPython_dir = os.path.dirname(IPython.__file__) |
|
141 | 130 | del IPython |
|
142 | 131 | |
|
143 | 132 | #------------------------------------------------------------------------- |
|
144 | 133 | # Command line handling |
|
145 | 134 | |
|
146 | 135 | # Valid command line options (uses DPyGetOpt syntax, like Perl's |
|
147 | 136 | # GetOpt::Long) |
|
148 | 137 | |
|
149 | 138 | # Any key not listed here gets deleted even if in the file (like session |
|
150 | 139 | # or profile). That's deliberate, to maintain the rc namespace clean. |
|
151 | 140 | |
|
152 | 141 | # Each set of options appears twice: under _conv only the names are |
|
153 | 142 | # listed, indicating which type they must be converted to when reading the |
|
154 | 143 | # ipythonrc file. And under DPyGetOpt they are listed with the regular |
|
155 | 144 | # DPyGetOpt syntax (=s,=i,:f,etc). |
|
156 | 145 | |
|
157 | 146 | # Make sure there's a space before each end of line (they get auto-joined!) |
|
158 | 147 | cmdline_opts = ('autocall! autoindent! automagic! banner! cache_size|cs=i ' |
|
159 | 148 | 'c=s classic|cl color_info! colors=s confirm_exit! ' |
|
160 | 149 | 'debug! deep_reload! editor=s log|l messages! nosep pdb! ' |
|
161 | 150 | 'pprint! prompt_in1|pi1=s prompt_in2|pi2=s prompt_out|po=s ' |
|
162 | 151 | 'quick screen_length|sl=i prompts_pad_left=i ' |
|
163 | 152 | 'logfile|lf=s logplay|lp=s profile|p=s ' |
|
164 | 153 | 'readline! readline_merge_completions! ' |
|
165 | 154 | 'readline_omit__names! ' |
|
166 | 155 | 'rcfile=s separate_in|si=s separate_out|so=s ' |
|
167 | 156 | 'separate_out2|so2=s xmode=s ' |
|
168 | 157 | 'magic_docstrings system_verbose! ' |
|
169 | 158 | 'multi_line_specials!') |
|
170 | 159 | |
|
171 | 160 | # Options that can *only* appear at the cmd line (not in rcfiles). |
|
172 | 161 | |
|
173 | 162 | # The "ignore" option is a kludge so that Emacs buffers don't crash, since |
|
174 | 163 | # the 'C-c !' command in emacs automatically appends a -i option at the end. |
|
175 | 164 | cmdline_only = ('help ignore|i ipythondir=s Version upgrade ' |
|
176 | 165 | 'gthread! qthread! wthread! pylab! tk!') |
|
177 | 166 | |
|
178 | 167 | # Build the actual name list to be used by DPyGetOpt |
|
179 | 168 | opts_names = qw(cmdline_opts) + qw(cmdline_only) |
|
180 | 169 | |
|
181 | 170 | # Set sensible command line defaults. |
|
182 | 171 | # This should have everything from cmdline_opts and cmdline_only |
|
183 | 172 | opts_def = Struct(autocall = 1, |
|
184 | 173 | autoindent=0, |
|
185 | 174 | automagic = 1, |
|
186 | 175 | banner = 1, |
|
187 | 176 | cache_size = 1000, |
|
188 | 177 | c = '', |
|
189 | 178 | classic = 0, |
|
190 | 179 | colors = 'NoColor', |
|
191 | 180 | color_info = 0, |
|
192 | 181 | confirm_exit = 1, |
|
193 | 182 | debug = 0, |
|
194 | 183 | deep_reload = 0, |
|
195 | 184 | editor = '0', |
|
196 | 185 | help = 0, |
|
197 | 186 | ignore = 0, |
|
198 | 187 | ipythondir = ipythondir, |
|
199 | 188 | log = 0, |
|
200 | 189 | logfile = '', |
|
201 | 190 | logplay = '', |
|
202 | 191 | multi_line_specials = 1, |
|
203 | 192 | messages = 1, |
|
204 | 193 | nosep = 0, |
|
205 | 194 | pdb = 0, |
|
206 | 195 | pprint = 0, |
|
207 | 196 | profile = '', |
|
208 | 197 | prompt_in1 = 'In [\\#]:', |
|
209 | 198 | prompt_in2 = ' .\\D.:', |
|
210 | 199 | prompt_out = 'Out[\\#]:', |
|
211 | 200 | prompts_pad_left = 1, |
|
212 | 201 | quick = 0, |
|
213 | 202 | readline = 1, |
|
214 | 203 | readline_merge_completions = 1, |
|
215 | 204 | readline_omit__names = 0, |
|
216 | 205 | rcfile = 'ipythonrc' + rc_suffix, |
|
217 | 206 | screen_length = 0, |
|
218 | 207 | separate_in = '\n', |
|
219 | 208 | separate_out = '\n', |
|
220 | 209 | separate_out2 = '', |
|
221 | 210 | system_verbose = 0, |
|
222 | 211 | gthread = 0, |
|
223 | 212 | qthread = 0, |
|
224 | 213 | wthread = 0, |
|
225 | 214 | pylab = 0, |
|
226 | 215 | tk = 0, |
|
227 | 216 | upgrade = 0, |
|
228 | 217 | Version = 0, |
|
229 | 218 | xmode = 'Verbose', |
|
230 | 219 | magic_docstrings = 0, # undocumented, for doc generation |
|
231 | 220 | ) |
|
232 | 221 | |
|
233 | 222 | # Things that will *only* appear in rcfiles (not at the command line). |
|
234 | 223 | # Make sure there's a space before each end of line (they get auto-joined!) |
|
235 | 224 | rcfile_opts = { qwflat: 'include import_mod import_all execfile ', |
|
236 | 225 | qw_lol: 'import_some ', |
|
237 | 226 | # for things with embedded whitespace: |
|
238 | 227 | list_strings:'execute alias readline_parse_and_bind ', |
|
239 | 228 | # Regular strings need no conversion: |
|
240 | 229 | None:'readline_remove_delims ', |
|
241 | 230 | } |
|
242 | 231 | # Default values for these |
|
243 | 232 | rc_def = Struct(include = [], |
|
244 | 233 | import_mod = [], |
|
245 | 234 | import_all = [], |
|
246 | 235 | import_some = [[]], |
|
247 | 236 | execute = [], |
|
248 | 237 | execfile = [], |
|
249 | 238 | alias = [], |
|
250 | 239 | readline_parse_and_bind = [], |
|
251 | 240 | readline_remove_delims = '', |
|
252 | 241 | ) |
|
253 | 242 | |
|
254 | 243 | # Build the type conversion dictionary from the above tables: |
|
255 | 244 | typeconv = rcfile_opts.copy() |
|
256 | 245 | typeconv.update(optstr2types(cmdline_opts)) |
|
257 | 246 | |
|
258 | 247 | # FIXME: the None key appears in both, put that back together by hand. Ugly! |
|
259 | 248 | typeconv[None] += ' ' + rcfile_opts[None] |
|
260 | 249 | |
|
261 | 250 | # Remove quotes at ends of all strings (used to protect spaces) |
|
262 | 251 | typeconv[unquote_ends] = typeconv[None] |
|
263 | 252 | del typeconv[None] |
|
264 | 253 | |
|
265 | 254 | # Build the list we'll use to make all config decisions with defaults: |
|
266 | 255 | opts_all = opts_def.copy() |
|
267 | 256 | opts_all.update(rc_def) |
|
268 | 257 | |
|
269 | 258 | # Build conflict resolver for recursive loading of config files: |
|
270 | 259 | # - preserve means the outermost file maintains the value, it is not |
|
271 | 260 | # overwritten if an included file has the same key. |
|
272 | 261 | # - add_flip applies + to the two values, so it better make sense to add |
|
273 | 262 | # those types of keys. But it flips them first so that things loaded |
|
274 | 263 | # deeper in the inclusion chain have lower precedence. |
|
275 | 264 | conflict = {'preserve': ' '.join([ typeconv[int], |
|
276 | 265 | typeconv[unquote_ends] ]), |
|
277 | 266 | 'add_flip': ' '.join([ typeconv[qwflat], |
|
278 | 267 | typeconv[qw_lol], |
|
279 | 268 | typeconv[list_strings] ]) |
|
280 | 269 | } |
|
281 | 270 | |
|
282 | 271 | # Now actually process the command line |
|
283 | 272 | getopt = DPyGetOpt.DPyGetOpt() |
|
284 | 273 | getopt.setIgnoreCase(0) |
|
285 | 274 | |
|
286 | 275 | getopt.parseConfiguration(opts_names) |
|
287 | 276 | |
|
288 | 277 | try: |
|
289 | 278 | getopt.processArguments(argv) |
|
290 | 279 | except: |
|
291 | 280 | print cmd_line_usage |
|
292 | 281 | warn('\nError in Arguments: ' + `sys.exc_value`) |
|
293 | 282 | sys.exit() |
|
294 | 283 | |
|
295 | 284 | # convert the options dict to a struct for much lighter syntax later |
|
296 | 285 | opts = Struct(getopt.optionValues) |
|
297 | 286 | args = getopt.freeValues |
|
298 | 287 | |
|
299 | 288 | # this is the struct (which has default values at this point) with which |
|
300 | 289 | # we make all decisions: |
|
301 | 290 | opts_all.update(opts) |
|
302 | 291 | |
|
303 | 292 | # Options that force an immediate exit |
|
304 | 293 | if opts_all.help: |
|
305 | 294 | page(cmd_line_usage) |
|
306 | 295 | sys.exit() |
|
307 | 296 | |
|
308 | 297 | if opts_all.Version: |
|
309 | 298 | print __version__ |
|
310 | 299 | sys.exit() |
|
311 | 300 | |
|
312 | 301 | if opts_all.magic_docstrings: |
|
313 | 302 | IP.magic_magic('-latex') |
|
314 | 303 | sys.exit() |
|
315 | 304 | |
|
316 | 305 | # Create user config directory if it doesn't exist. This must be done |
|
317 | 306 | # *after* getting the cmd line options. |
|
318 | 307 | if not os.path.isdir(opts_all.ipythondir): |
|
319 | 308 | IP.user_setup(opts_all.ipythondir,rc_suffix,'install') |
|
320 | 309 | |
|
321 | 310 | # upgrade user config files while preserving a copy of the originals |
|
322 | 311 | if opts_all.upgrade: |
|
323 | 312 | IP.user_setup(opts_all.ipythondir,rc_suffix,'upgrade') |
|
324 | 313 | |
|
325 | 314 | # check mutually exclusive options in the *original* command line |
|
326 | 315 | mutex_opts(opts,[qw('log logfile'),qw('rcfile profile'), |
|
327 | 316 | qw('classic profile'),qw('classic rcfile')]) |
|
328 | 317 | |
|
329 | 318 | # default logfilename used when -log is called. |
|
330 | 319 | IP.LOGDEF = 'ipython.log' |
|
331 | 320 | |
|
332 | 321 | #--------------------------------------------------------------------------- |
|
333 | 322 | # Log replay |
|
334 | 323 | |
|
335 | 324 | # if -logplay, we need to 'become' the other session. That basically means |
|
336 | 325 | # replacing the current command line environment with that of the old |
|
337 | 326 | # session and moving on. |
|
338 | 327 | |
|
339 | 328 | # this is needed so that later we know we're in session reload mode, as |
|
340 | 329 | # opts_all will get overwritten: |
|
341 | 330 | load_logplay = 0 |
|
342 | 331 | |
|
343 | 332 | if opts_all.logplay: |
|
344 | 333 | load_logplay = opts_all.logplay |
|
345 | 334 | opts_debug_save = opts_all.debug |
|
346 | 335 | try: |
|
347 | 336 | logplay = open(opts_all.logplay) |
|
348 | 337 | except IOError: |
|
349 | 338 | if opts_all.debug: IP.InteractiveTB() |
|
350 | 339 | warn('Could not open logplay file '+`opts_all.logplay`) |
|
351 | 340 | # restore state as if nothing had happened and move on, but make |
|
352 | 341 | # sure that later we don't try to actually load the session file |
|
353 | 342 | logplay = None |
|
354 | 343 | load_logplay = 0 |
|
355 | 344 | del opts_all.logplay |
|
356 | 345 | else: |
|
357 | 346 | try: |
|
358 | 347 | logplay.readline() |
|
359 | 348 | logplay.readline(); |
|
360 | 349 | # this reloads that session's command line |
|
361 | 350 | cmd = logplay.readline()[6:] |
|
362 | 351 | exec cmd |
|
363 | 352 | # restore the true debug flag given so that the process of |
|
364 | 353 | # session loading itself can be monitored. |
|
365 | 354 | opts.debug = opts_debug_save |
|
366 | 355 | # save the logplay flag so later we don't overwrite the log |
|
367 | 356 | opts.logplay = load_logplay |
|
368 | 357 | # now we must update our own structure with defaults |
|
369 | 358 | opts_all.update(opts) |
|
370 | 359 | # now load args |
|
371 | 360 | cmd = logplay.readline()[6:] |
|
372 | 361 | exec cmd |
|
373 | 362 | logplay.close() |
|
374 | 363 | except: |
|
375 | 364 | logplay.close() |
|
376 | 365 | if opts_all.debug: IP.InteractiveTB() |
|
377 | 366 | warn("Logplay file lacking full configuration information.\n" |
|
378 | 367 | "I'll try to read it, but some things may not work.") |
|
379 | 368 | |
|
380 | 369 | #------------------------------------------------------------------------- |
|
381 | 370 | # set up output traps: catch all output from files, being run, modules |
|
382 | 371 | # loaded, etc. Then give it to the user in a clean form at the end. |
|
383 | 372 | |
|
384 | 373 | msg_out = 'Output messages. ' |
|
385 | 374 | msg_err = 'Error messages. ' |
|
386 | 375 | msg_sep = '\n' |
|
387 | 376 | msg = Struct(config = OutputTrap('Configuration Loader',msg_out, |
|
388 | 377 | msg_err,msg_sep,debug, |
|
389 | 378 | quiet_out=1), |
|
390 | 379 | user_exec = OutputTrap('User File Execution',msg_out, |
|
391 | 380 | msg_err,msg_sep,debug), |
|
392 | 381 | logplay = OutputTrap('Log Loader',msg_out, |
|
393 | 382 | msg_err,msg_sep,debug), |
|
394 | 383 | summary = '' |
|
395 | 384 | ) |
|
396 | 385 | |
|
397 | 386 | #------------------------------------------------------------------------- |
|
398 | 387 | # Process user ipythonrc-type configuration files |
|
399 | 388 | |
|
400 | 389 | # turn on output trapping and log to msg.config |
|
401 | 390 | # remember that with debug on, trapping is actually disabled |
|
402 | 391 | msg.config.trap_all() |
|
403 | 392 | |
|
404 | 393 | # look for rcfile in current or default directory |
|
405 | 394 | try: |
|
406 | 395 | opts_all.rcfile = filefind(opts_all.rcfile,opts_all.ipythondir) |
|
407 | 396 | except IOError: |
|
408 | 397 | if opts_all.debug: IP.InteractiveTB() |
|
409 | 398 | warn('Configuration file %s not found. Ignoring request.' |
|
410 | 399 | % (opts_all.rcfile) ) |
|
411 | 400 | |
|
412 | 401 | # 'profiles' are a shorthand notation for config filenames |
|
413 | 402 | if opts_all.profile: |
|
414 | 403 | try: |
|
415 | 404 | opts_all.rcfile = filefind('ipythonrc-' + opts_all.profile |
|
416 | 405 | + rc_suffix, |
|
417 | 406 | opts_all.ipythondir) |
|
418 | 407 | except IOError: |
|
419 | 408 | if opts_all.debug: IP.InteractiveTB() |
|
420 | 409 | opts.profile = '' # remove profile from options if invalid |
|
421 | 410 | warn('Profile configuration file %s not found. Ignoring request.' |
|
422 | 411 | % (opts_all.profile) ) |
|
423 | 412 | |
|
424 | 413 | # load the config file |
|
425 | 414 | rcfiledata = None |
|
426 | 415 | if opts_all.quick: |
|
427 | 416 | print 'Launching IPython in quick mode. No config file read.' |
|
428 | 417 | elif opts_all.classic: |
|
429 | 418 | print 'Launching IPython in classic mode. No config file read.' |
|
430 | 419 | elif opts_all.rcfile: |
|
431 | 420 | try: |
|
432 | 421 | cfg_loader = ConfigLoader(conflict) |
|
433 | 422 | rcfiledata = cfg_loader.load(opts_all.rcfile,typeconv, |
|
434 | 423 | 'include',opts_all.ipythondir, |
|
435 | 424 | purge = 1, |
|
436 | 425 | unique = conflict['preserve']) |
|
437 | 426 | except: |
|
438 | 427 | IP.InteractiveTB() |
|
439 | 428 | warn('Problems loading configuration file '+ |
|
440 | 429 | `opts_all.rcfile`+ |
|
441 | 430 | '\nStarting with default -bare bones- configuration.') |
|
442 | 431 | else: |
|
443 | 432 | warn('No valid configuration file found in either currrent directory\n'+ |
|
444 | 433 | 'or in the IPython config. directory: '+`opts_all.ipythondir`+ |
|
445 | 434 | '\nProceeding with internal defaults.') |
|
446 | 435 | |
|
447 | 436 | #------------------------------------------------------------------------ |
|
448 | 437 | # Set exception handlers in mode requested by user. |
|
449 | 438 | otrap = OutputTrap(trap_out=1) # trap messages from magic_xmode |
|
450 | 439 | IP.magic_xmode(opts_all.xmode) |
|
451 | 440 | otrap.release_out() |
|
452 | 441 | |
|
453 | 442 | #------------------------------------------------------------------------ |
|
454 | 443 | # Execute user config |
|
455 | 444 | |
|
456 | 445 | # first, create a valid config structure with the right precedence order: |
|
457 | 446 | # defaults < rcfile < command line |
|
458 | 447 | IP.rc = rc_def.copy() |
|
459 | 448 | IP.rc.update(opts_def) |
|
460 | 449 | if rcfiledata: |
|
461 | 450 | # now we can update |
|
462 | 451 | IP.rc.update(rcfiledata) |
|
463 | 452 | IP.rc.update(opts) |
|
464 | 453 | IP.rc.update(rc_override) |
|
465 | 454 | |
|
466 | 455 | # Store the original cmd line for reference: |
|
467 | 456 | IP.rc.opts = opts |
|
468 | 457 | IP.rc.args = args |
|
469 | 458 | |
|
470 | 459 | # create a *runtime* Struct like rc for holding parameters which may be |
|
471 | 460 | # created and/or modified by runtime user extensions. |
|
472 | 461 | IP.runtime_rc = Struct() |
|
473 | 462 | |
|
474 | 463 | # from this point on, all config should be handled through IP.rc, |
|
475 | 464 | # opts* shouldn't be used anymore. |
|
476 | 465 | |
|
477 | 466 | # add personal .ipython dir to sys.path so that users can put things in |
|
478 | 467 | # there for customization |
|
479 | 468 | sys.path.append(IP.rc.ipythondir) |
|
480 | 469 | sys.path.insert(0, '') # add . to sys.path. Fix from Prabhu Ramachandran |
|
481 | 470 | |
|
482 | 471 | # update IP.rc with some special things that need manual |
|
483 | 472 | # tweaks. Basically options which affect other options. I guess this |
|
484 | 473 | # should just be written so that options are fully orthogonal and we |
|
485 | 474 | # wouldn't worry about this stuff! |
|
486 | 475 | |
|
487 | 476 | if IP.rc.classic: |
|
488 | 477 | IP.rc.quick = 1 |
|
489 | 478 | IP.rc.cache_size = 0 |
|
490 | 479 | IP.rc.pprint = 0 |
|
491 | 480 | IP.rc.prompt_in1 = '>>> ' |
|
492 | 481 | IP.rc.prompt_in2 = '... ' |
|
493 | 482 | IP.rc.prompt_out = '' |
|
494 | 483 | IP.rc.separate_in = IP.rc.separate_out = IP.rc.separate_out2 = '0' |
|
495 | 484 | IP.rc.colors = 'NoColor' |
|
496 | 485 | IP.rc.xmode = 'Plain' |
|
497 | 486 | |
|
498 | 487 | # configure readline |
|
499 | 488 | # Define the history file for saving commands in between sessions |
|
500 | 489 | if IP.rc.profile: |
|
501 | 490 | histfname = 'history-%s' % IP.rc.profile |
|
502 | 491 | else: |
|
503 | 492 | histfname = 'history' |
|
504 | 493 | IP.histfile = os.path.join(opts_all.ipythondir,histfname) |
|
505 | 494 | # Load readline proper |
|
506 | 495 | if IP.rc.readline: |
|
507 | 496 | IP.init_readline() |
|
508 | 497 | |
|
509 | 498 | # update exception handlers with rc file status |
|
510 | 499 | otrap.trap_out() # I don't want these messages ever. |
|
511 | 500 | IP.magic_xmode(IP.rc.xmode) |
|
512 | 501 | otrap.release_out() |
|
513 | 502 | |
|
514 | 503 | # activate logging if requested and not reloading a log |
|
515 | 504 | if IP.rc.logplay: |
|
516 | 505 | IP.magic_logstart(IP.rc.logplay + ' append') |
|
517 | 506 | elif IP.rc.logfile: |
|
518 | 507 | IP.magic_logstart(IP.rc.logfile) |
|
519 | 508 | elif IP.rc.log: |
|
520 | 509 | IP.magic_logstart() |
|
521 | 510 | |
|
522 | 511 | # find user editor so that it we don't have to look it up constantly |
|
523 | 512 | if IP.rc.editor.strip()=='0': |
|
524 | 513 | try: |
|
525 | 514 | ed = os.environ['EDITOR'] |
|
526 | 515 | except KeyError: |
|
527 | 516 | if os.name == 'posix': |
|
528 | 517 | ed = 'vi' # the only one guaranteed to be there! |
|
529 | 518 | else: |
|
530 | 519 | ed = 'notepad' # same in Windows! |
|
531 | 520 | IP.rc.editor = ed |
|
532 | 521 | |
|
533 | 522 | # Recursive reload |
|
534 | 523 | try: |
|
535 | 524 | from IPython import deep_reload |
|
536 | 525 | if IP.rc.deep_reload: |
|
537 | 526 | __builtin__.reload = deep_reload.reload |
|
538 | 527 | else: |
|
539 | 528 | __builtin__.dreload = deep_reload.reload |
|
540 | 529 | del deep_reload |
|
541 | 530 | except ImportError: |
|
542 | 531 | pass |
|
543 | 532 | |
|
544 | 533 | # Save the current state of our namespace so that the interactive shell |
|
545 | 534 | # can later know which variables have been created by us from config files |
|
546 | 535 | # and loading. This way, loading a file (in any way) is treated just like |
|
547 | 536 | # defining things on the command line, and %who works as expected. |
|
548 | 537 | |
|
549 | 538 | # DON'T do anything that affects the namespace beyond this point! |
|
550 | 539 | IP.internal_ns = __main__.__dict__.copy() |
|
551 | 540 | |
|
552 | 541 | #IP.internal_ns.update(locals()) # so our stuff doesn't show up in %who |
|
553 | 542 | |
|
554 | 543 | # Now run through the different sections of the users's config |
|
555 | 544 | if IP.rc.debug: |
|
556 | 545 | print 'Trying to execute the following configuration structure:' |
|
557 | 546 | print '(Things listed first are deeper in the inclusion tree and get' |
|
558 | 547 | print 'loaded first).\n' |
|
559 | 548 | pprint(IP.rc.__dict__) |
|
560 | 549 | |
|
561 | 550 | for mod in IP.rc.import_mod: |
|
562 | 551 | try: |
|
563 | 552 | exec 'import '+mod in IP.user_ns |
|
564 | 553 | except : |
|
565 | 554 | IP.InteractiveTB() |
|
566 | 555 | import_fail_info(mod) |
|
567 | 556 | |
|
568 | 557 | for mod_fn in IP.rc.import_some: |
|
569 | 558 | if mod_fn == []: break |
|
570 | 559 | mod,fn = mod_fn[0],','.join(mod_fn[1:]) |
|
571 | 560 | try: |
|
572 | 561 | exec 'from '+mod+' import '+fn in IP.user_ns |
|
573 | 562 | except : |
|
574 | 563 | IP.InteractiveTB() |
|
575 | 564 | import_fail_info(mod,fn) |
|
576 | 565 | |
|
577 | 566 | for mod in IP.rc.import_all: |
|
578 | 567 | try: |
|
579 | 568 | exec 'from '+mod+' import *' in IP.user_ns |
|
580 | 569 | except : |
|
581 | 570 | IP.InteractiveTB() |
|
582 | 571 | import_fail_info(mod) |
|
583 | 572 | |
|
584 | 573 | for code in IP.rc.execute: |
|
585 | 574 | try: |
|
586 | 575 | exec code in IP.user_ns |
|
587 | 576 | except: |
|
588 | 577 | IP.InteractiveTB() |
|
589 | 578 | warn('Failure executing code: ' + `code`) |
|
590 | 579 | |
|
591 | 580 | # Execute the files the user wants in ipythonrc |
|
592 | 581 | for file in IP.rc.execfile: |
|
593 | 582 | try: |
|
594 | 583 | file = filefind(file,sys.path+[IPython_dir]) |
|
595 | 584 | except IOError: |
|
596 | 585 | warn(itpl('File $file not found. Skipping it.')) |
|
597 | 586 | else: |
|
598 | 587 | IP.safe_execfile(os.path.expanduser(file),IP.user_ns) |
|
599 | 588 | |
|
600 | 589 | # Load user aliases |
|
601 | 590 | for alias in IP.rc.alias: |
|
602 | 591 | IP.magic_alias(alias) |
|
603 | 592 | |
|
604 | 593 | # release stdout and stderr and save config log into a global summary |
|
605 | 594 | msg.config.release_all() |
|
606 | 595 | if IP.rc.messages: |
|
607 | 596 | msg.summary += msg.config.summary_all() |
|
608 | 597 | |
|
609 | 598 | #------------------------------------------------------------------------ |
|
610 | 599 | # Setup interactive session |
|
611 | 600 | |
|
612 | 601 | # Now we should be fully configured. We can then execute files or load |
|
613 | 602 | # things only needed for interactive use. Then we'll open the shell. |
|
614 | 603 | |
|
615 | 604 | # Take a snapshot of the user namespace before opening the shell. That way |
|
616 | 605 | # we'll be able to identify which things were interactively defined and |
|
617 | 606 | # which were defined through config files. |
|
618 | 607 | IP.user_config_ns = IP.user_ns.copy() |
|
619 | 608 | |
|
620 | 609 | # Force reading a file as if it were a session log. Slower but safer. |
|
621 | 610 | if load_logplay: |
|
622 | 611 | print 'Replaying log...' |
|
623 | 612 | try: |
|
624 | 613 | if IP.rc.debug: |
|
625 | 614 | logplay_quiet = 0 |
|
626 | 615 | else: |
|
627 | 616 | logplay_quiet = 1 |
|
628 | 617 | |
|
629 | 618 | msg.logplay.trap_all() |
|
630 | 619 | IP.safe_execfile(load_logplay,IP.user_ns, |
|
631 | 620 | islog = 1, quiet = logplay_quiet) |
|
632 | 621 | msg.logplay.release_all() |
|
633 | 622 | if IP.rc.messages: |
|
634 | 623 | msg.summary += msg.logplay.summary_all() |
|
635 | 624 | except: |
|
636 | 625 | warn('Problems replaying logfile %s.' % load_logplay) |
|
637 | 626 | IP.InteractiveTB() |
|
638 | 627 | |
|
639 | 628 | # Load remaining files in command line |
|
640 | 629 | msg.user_exec.trap_all() |
|
641 | 630 | |
|
642 | 631 | # Do NOT execute files named in the command line as scripts to be loaded |
|
643 | 632 | # by embedded instances. Doing so has the potential for an infinite |
|
644 | 633 | # recursion if there are exceptions thrown in the process. |
|
645 | 634 | |
|
646 | 635 | # XXX FIXME: the execution of user files should be moved out to after |
|
647 | 636 | # ipython is fully initialized, just as if they were run via %run at the |
|
648 | 637 | # ipython prompt. This would also give them the benefit of ipython's |
|
649 | 638 | # nice tracebacks. |
|
650 | 639 | |
|
651 | 640 | if not embedded and IP.rc.args: |
|
652 | 641 | name_save = IP.user_ns['__name__'] |
|
653 | 642 | IP.user_ns['__name__'] = '__main__' |
|
654 | 643 | try: |
|
655 | 644 | # Set our own excepthook in case the user code tries to call it |
|
656 | 645 | # directly. This prevents triggering the IPython crash handler. |
|
657 | 646 | old_excepthook,sys.excepthook = sys.excepthook, IP.excepthook |
|
658 | 647 | for run in args: |
|
659 | 648 | IP.safe_execfile(run,IP.user_ns) |
|
660 | 649 | finally: |
|
661 | 650 | # Reset our crash handler in place |
|
662 | 651 | sys.excepthook = old_excepthook |
|
663 | 652 | |
|
664 | 653 | IP.user_ns['__name__'] = name_save |
|
665 | 654 | |
|
666 | 655 | msg.user_exec.release_all() |
|
667 | 656 | if IP.rc.messages: |
|
668 | 657 | msg.summary += msg.user_exec.summary_all() |
|
669 | 658 | |
|
670 | 659 | # since we can't specify a null string on the cmd line, 0 is the equivalent: |
|
671 | 660 | if IP.rc.nosep: |
|
672 | 661 | IP.rc.separate_in = IP.rc.separate_out = IP.rc.separate_out2 = '0' |
|
673 | 662 | if IP.rc.separate_in == '0': IP.rc.separate_in = '' |
|
674 | 663 | if IP.rc.separate_out == '0': IP.rc.separate_out = '' |
|
675 | 664 | if IP.rc.separate_out2 == '0': IP.rc.separate_out2 = '' |
|
676 | 665 | IP.rc.separate_in = IP.rc.separate_in.replace('\\n','\n') |
|
677 | 666 | IP.rc.separate_out = IP.rc.separate_out.replace('\\n','\n') |
|
678 | 667 | IP.rc.separate_out2 = IP.rc.separate_out2.replace('\\n','\n') |
|
679 | 668 | |
|
680 | 669 | # Determine how many lines at the bottom of the screen are needed for |
|
681 | 670 | # showing prompts, so we can know wheter long strings are to be printed or |
|
682 | 671 | # paged: |
|
683 | 672 | num_lines_bot = IP.rc.separate_in.count('\n')+1 |
|
684 | 673 | IP.rc.screen_length = IP.rc.screen_length - num_lines_bot |
|
685 | 674 | # Initialize cache, set in/out prompts and printing system |
|
686 | 675 | IP.outputcache = CachedOutput(IP.rc.cache_size, |
|
687 | 676 | IP.rc.pprint, |
|
688 | 677 | input_sep = IP.rc.separate_in, |
|
689 | 678 | output_sep = IP.rc.separate_out, |
|
690 | 679 | output_sep2 = IP.rc.separate_out2, |
|
691 | 680 | ps1 = IP.rc.prompt_in1, |
|
692 | 681 | ps2 = IP.rc.prompt_in2, |
|
693 | 682 | ps_out = IP.rc.prompt_out, |
|
694 | 683 | user_ns = IP.user_ns, |
|
695 | 684 | input_hist = IP.input_hist, |
|
696 | 685 | pad_left = IP.rc.prompts_pad_left) |
|
697 | 686 | |
|
698 | 687 | # Set user colors (don't do it in the constructor above so that it doesn't |
|
699 | 688 | # crash if colors option is invalid) |
|
700 | 689 | IP.magic_colors(IP.rc.colors) |
|
701 | 690 | |
|
702 | 691 | # user may have over-ridden the default print hook: |
|
703 | 692 | try: |
|
704 | 693 | IP.outputcache.__class__.display = IP.hooks.display |
|
705 | 694 | except AttributeError: |
|
706 | 695 | pass |
|
707 | 696 | |
|
708 | 697 | # Set calling of pdb on exceptions |
|
709 | 698 | IP.InteractiveTB.call_pdb = IP.rc.pdb |
|
710 | 699 | |
|
711 | 700 | # I don't like assigning globally to sys, because it means when embedding |
|
712 | 701 | # instances, each embedded instance overrides the previous choice. But |
|
713 | 702 | # sys.displayhook seems to be called internally by exec, so I don't see a |
|
714 | 703 | # way around it. |
|
715 | 704 | sys.displayhook = IP.outputcache |
|
716 | 705 | |
|
717 | 706 | # we need to know globally if we're caching i/o or not |
|
718 | 707 | IP.do_full_cache = IP.outputcache.do_full_cache |
|
719 | 708 | |
|
720 | 709 | # configure startup banner |
|
721 | 710 | if IP.rc.c: # regular python doesn't print the banner with -c |
|
722 | 711 | IP.rc.banner = 0 |
|
723 | 712 | if IP.rc.banner: |
|
724 | 713 | IP.BANNER = '\n'.join(IP.BANNER_PARTS) |
|
725 | 714 | else: |
|
726 | 715 | IP.BANNER = '' |
|
727 | 716 | |
|
728 | 717 | if IP.rc.profile: IP.BANNER += '\nIPython profile: '+IP.rc.profile+'\n' |
|
729 | 718 | |
|
730 | 719 | # add message log (possibly empty) |
|
731 | 720 | IP.BANNER += msg.summary |
|
732 | 721 | |
|
733 | 722 | IP.post_config_initialization() |
|
734 | 723 | |
|
735 | 724 | return IP |
|
736 | 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 | 37 | 2005-07-16 Fernando Perez <fperez@colorado.edu> |
|
2 | 38 | |
|
3 | 39 | * IPython/ultraTB.py (ExceptionColors): Make a global variable |
|
4 | 40 | out of the color scheme table used for coloring exception |
|
5 | 41 | tracebacks. This allows user code to add new schemes at runtime. |
|
6 | 42 | This is a minimally modified version of the patch at |
|
7 | 43 | http://www.scipy.net/roundup/ipython/issue35, many thanks to pabw |
|
8 | 44 | for the contribution. |
|
9 | 45 | |
|
10 | 46 | * IPython/FlexCompleter.py (Completer.attr_matches): Add a |
|
11 | 47 | slightly modified version of the patch in |
|
12 | 48 | http://www.scipy.net/roundup/ipython/issue34, which also allows me |
|
13 | 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 | 52 | 2005-06-08 Fernando Perez <fperez@colorado.edu> |
|
17 | 53 | |
|
18 | 54 | * IPython/iplib.py (write/write_err): Add methods to abstract all |
|
19 | 55 | I/O a bit more. |
|
20 | 56 | |
|
21 | 57 | * IPython/Shell.py (IPShellGTK.mainloop): Fix GTK deprecation |
|
22 | 58 | warning, reported by Aric Hagberg, fix by JD Hunter. |
|
23 | 59 | |
|
24 | 60 | 2005-06-02 *** Released version 0.6.15 |
|
25 | 61 | |
|
26 | 62 | 2005-06-01 Fernando Perez <fperez@colorado.edu> |
|
27 | 63 | |
|
28 | 64 | * IPython/iplib.py (MagicCompleter.file_matches): Fix |
|
29 | 65 | tab-completion of filenames within open-quoted strings. Note that |
|
30 | 66 | this requires that in ~/.ipython/ipythonrc, users change the |
|
31 | 67 | readline delimiters configuration to read: |
|
32 | 68 | |
|
33 | 69 | readline_remove_delims -/~ |
|
34 | 70 | |
|
35 | 71 | |
|
36 | 72 | 2005-05-31 *** Released version 0.6.14 |
|
37 | 73 | |
|
38 | 74 | 2005-05-29 Fernando Perez <fperez@colorado.edu> |
|
39 | 75 | |
|
40 | 76 | * IPython/ultraTB.py (VerboseTB.text): Fix crash for tracebacks |
|
41 | 77 | with files not on the filesystem. Reported by Eliyahu Sandler |
|
42 | 78 | <eli@gondolin.net> |
|
43 | 79 | |
|
44 | 80 | 2005-05-22 Fernando Perez <fperez@colorado.edu> |
|
45 | 81 | |
|
46 | 82 | * IPython/iplib.py: Fix a few crashes in the --upgrade option. |
|
47 | 83 | After an initial report by LUK ShunTim <shuntim.luk@polyu.edu.hk>. |
|
48 | 84 | |
|
49 | 85 | 2005-05-19 Fernando Perez <fperez@colorado.edu> |
|
50 | 86 | |
|
51 | 87 | * IPython/iplib.py (safe_execfile): close a file which could be |
|
52 | 88 | left open (causing problems in win32, which locks open files). |
|
53 | 89 | Thanks to a bug report by D Brown <dbrown2@yahoo.com>. |
|
54 | 90 | |
|
55 | 91 | 2005-05-18 Fernando Perez <fperez@colorado.edu> |
|
56 | 92 | |
|
57 | 93 | * IPython/Shell.py (MatplotlibShellBase.mplot_exec): pass all |
|
58 | 94 | keyword arguments correctly to safe_execfile(). |
|
59 | 95 | |
|
60 | 96 | 2005-05-13 Fernando Perez <fperez@colorado.edu> |
|
61 | 97 | |
|
62 | 98 | * ipython.1: Added info about Qt to manpage, and threads warning |
|
63 | 99 | to usage page (invoked with --help). |
|
64 | 100 | |
|
65 | 101 | * IPython/iplib.py (MagicCompleter.python_func_kw_matches): Added |
|
66 | 102 | new matcher (it goes at the end of the priority list) to do |
|
67 | 103 | tab-completion on named function arguments. Submitted by George |
|
68 | 104 | Sakkis <gsakkis-AT-eden.rutgers.edu>. See the thread at |
|
69 | 105 | http://www.scipy.net/pipermail/ipython-dev/2005-April/000436.html |
|
70 | 106 | for more details. |
|
71 | 107 | |
|
72 | 108 | * IPython/Magic.py (magic_run): Added new -e flag to ignore |
|
73 | 109 | SystemExit exceptions in the script being run. Thanks to a report |
|
74 | 110 | by danny shevitz <danny_shevitz-AT-yahoo.com>, about this |
|
75 | 111 | producing very annoying behavior when running unit tests. |
|
76 | 112 | |
|
77 | 113 | 2005-05-12 Fernando Perez <fperez@colorado.edu> |
|
78 | 114 | |
|
79 | 115 | * IPython/iplib.py (handle_auto): fixed auto-quoting and parens, |
|
80 | 116 | which I'd broken (again) due to a changed regexp. In the process, |
|
81 | 117 | added ';' as an escape to auto-quote the whole line without |
|
82 | 118 | splitting its arguments. Thanks to a report by Jerry McRae |
|
83 | 119 | <qrs0xyc02-AT-sneakemail.com>. |
|
84 | 120 | |
|
85 | 121 | * IPython/ultraTB.py (VerboseTB.text): protect against rare but |
|
86 | 122 | possible crashes caused by a TokenError. Reported by Ed Schofield |
|
87 | 123 | <schofield-AT-ftw.at>. |
|
88 | 124 | |
|
89 | 125 | 2005-05-06 Fernando Perez <fperez@colorado.edu> |
|
90 | 126 | |
|
91 | 127 | * IPython/Shell.py (hijack_wx): Fix to work with WX v.2.6. |
|
92 | 128 | |
|
93 | 129 | 2005-04-29 Fernando Perez <fperez@colorado.edu> |
|
94 | 130 | |
|
95 | 131 | * IPython/Shell.py (IPShellQt): Thanks to Denis Rivière |
|
96 | 132 | <nudz-AT-free.fr>, Yann Cointepas <yann-AT-sapetnioc.org> and Benjamin |
|
97 | 133 | Thyreau <Benji2-AT-decideur.info>, we now have a -qthread option |
|
98 | 134 | which provides support for Qt interactive usage (similar to the |
|
99 | 135 | existing one for WX and GTK). This had been often requested. |
|
100 | 136 | |
|
101 | 137 | 2005-04-14 *** Released version 0.6.13 |
|
102 | 138 | |
|
103 | 139 | 2005-04-08 Fernando Perez <fperez@colorado.edu> |
|
104 | 140 | |
|
105 | 141 | * IPython/Magic.py (Magic._ofind): remove docstring evaluation |
|
106 | 142 | from _ofind, which gets called on almost every input line. Now, |
|
107 | 143 | we only try to get docstrings if they are actually going to be |
|
108 | 144 | used (the overhead of fetching unnecessary docstrings can be |
|
109 | 145 | noticeable for certain objects, such as Pyro proxies). |
|
110 | 146 | |
|
111 | 147 | * IPython/iplib.py (MagicCompleter.python_matches): Change the API |
|
112 | 148 | for completers. For some reason I had been passing them the state |
|
113 | 149 | variable, which completers never actually need, and was in |
|
114 | 150 | conflict with the rlcompleter API. Custom completers ONLY need to |
|
115 | 151 | take the text parameter. |
|
116 | 152 | |
|
117 | 153 | * IPython/Extensions/InterpreterExec.py: Fix regexp so that magics |
|
118 | 154 | work correctly in pysh. I've also moved all the logic which used |
|
119 | 155 | to be in pysh.py here, which will prevent problems with future |
|
120 | 156 | upgrades. However, this time I must warn users to update their |
|
121 | 157 | pysh profile to include the line |
|
122 | 158 | |
|
123 | 159 | import_all IPython.Extensions.InterpreterExec |
|
124 | 160 | |
|
125 | 161 | because otherwise things won't work for them. They MUST also |
|
126 | 162 | delete pysh.py and the line |
|
127 | 163 | |
|
128 | 164 | execfile pysh.py |
|
129 | 165 | |
|
130 | 166 | from their ipythonrc-pysh. |
|
131 | 167 | |
|
132 | 168 | * IPython/FlexCompleter.py (Completer.attr_matches): Make more |
|
133 | 169 | robust in the face of objects whose dir() returns non-strings |
|
134 | 170 | (which it shouldn't, but some broken libs like ITK do). Thanks to |
|
135 | 171 | a patch by John Hunter (implemented differently, though). Also |
|
136 | 172 | minor improvements by using .extend instead of + on lists. |
|
137 | 173 | |
|
138 | 174 | * pysh.py: |
|
139 | 175 | |
|
140 | 176 | 2005-04-06 Fernando Perez <fperez@colorado.edu> |
|
141 | 177 | |
|
142 | 178 | * IPython/ipmaker.py (make_IPython): Make multi_line_specials on |
|
143 | 179 | by default, so that all users benefit from it. Those who don't |
|
144 | 180 | want it can still turn it off. |
|
145 | 181 | |
|
146 | 182 | * IPython/UserConfig/ipythonrc: Add multi_line_specials to the |
|
147 | 183 | config file, I'd forgotten about this, so users were getting it |
|
148 | 184 | off by default. |
|
149 | 185 | |
|
150 | 186 | * IPython/iplib.py (ipmagic): big overhaul of the magic system for |
|
151 | 187 | consistency. Now magics can be called in multiline statements, |
|
152 | 188 | and python variables can be expanded in magic calls via $var. |
|
153 | 189 | This makes the magic system behave just like aliases or !system |
|
154 | 190 | calls. |
|
155 | 191 | |
|
156 | 192 | 2005-03-28 Fernando Perez <fperez@colorado.edu> |
|
157 | 193 | |
|
158 | 194 | * IPython/iplib.py (handle_auto): cleanup to use %s instead of |
|
159 | 195 | expensive string additions for building command. Add support for |
|
160 | 196 | trailing ';' when autocall is used. |
|
161 | 197 | |
|
162 | 198 | 2005-03-26 Fernando Perez <fperez@colorado.edu> |
|
163 | 199 | |
|
164 | 200 | * ipython.el: Fix http://www.scipy.net/roundup/ipython/issue31. |
|
165 | 201 | Bugfix by A. Schmolck, the ipython.el maintainer. Also make |
|
166 | 202 | ipython.el robust against prompts with any number of spaces |
|
167 | 203 | (including 0) after the ':' character. |
|
168 | 204 | |
|
169 | 205 | * IPython/Prompts.py (Prompt2.set_p_str): Fix spurious space in |
|
170 | 206 | continuation prompt, which misled users to think the line was |
|
171 | 207 | already indented. Closes debian Bug#300847, reported to me by |
|
172 | 208 | Norbert Tretkowski <tretkowski-AT-inittab.de>. |
|
173 | 209 | |
|
174 | 210 | 2005-03-23 Fernando Perez <fperez@colorado.edu> |
|
175 | 211 | |
|
176 | 212 | * IPython/Prompts.py (Prompt1.__str__): Make sure that prompts are |
|
177 | 213 | properly aligned if they have embedded newlines. |
|
178 | 214 | |
|
179 | 215 | * IPython/iplib.py (runlines): Add a public method to expose |
|
180 | 216 | IPython's code execution machinery, so that users can run strings |
|
181 | 217 | as if they had been typed at the prompt interactively. |
|
182 | 218 | (InteractiveShell.__init__): Added getoutput() to the __IPYTHON__ |
|
183 | 219 | methods which can call the system shell, but with python variable |
|
184 | 220 | expansion. The three such methods are: __IPYTHON__.system, |
|
185 | 221 | .getoutput and .getoutputerror. These need to be documented in a |
|
186 | 222 | 'public API' section (to be written) of the manual. |
|
187 | 223 | |
|
188 | 224 | 2005-03-20 Fernando Perez <fperez@colorado.edu> |
|
189 | 225 | |
|
190 | 226 | * IPython/iplib.py (InteractiveShell.set_custom_exc): new system |
|
191 | 227 | for custom exception handling. This is quite powerful, and it |
|
192 | 228 | allows for user-installable exception handlers which can trap |
|
193 | 229 | custom exceptions at runtime and treat them separately from |
|
194 | 230 | IPython's default mechanisms. At the request of FrΓ©dΓ©ric |
|
195 | 231 | Mantegazza <mantegazza-AT-ill.fr>. |
|
196 | 232 | (InteractiveShell.set_custom_completer): public API function to |
|
197 | 233 | add new completers at runtime. |
|
198 | 234 | |
|
199 | 235 | 2005-03-19 Fernando Perez <fperez@colorado.edu> |
|
200 | 236 | |
|
201 | 237 | * IPython/OInspect.py (getdoc): Add a call to obj.getdoc(), to |
|
202 | 238 | allow objects which provide their docstrings via non-standard |
|
203 | 239 | mechanisms (like Pyro proxies) to still be inspected by ipython's |
|
204 | 240 | ? system. |
|
205 | 241 | |
|
206 | 242 | * IPython/iplib.py (InteractiveShell.__init__): back off the _o/_e |
|
207 | 243 | automatic capture system. I tried quite hard to make it work |
|
208 | 244 | reliably, and simply failed. I tried many combinations with the |
|
209 | 245 | subprocess module, but eventually nothing worked in all needed |
|
210 | 246 | cases (not blocking stdin for the child, duplicating stdout |
|
211 | 247 | without blocking, etc). The new %sc/%sx still do capture to these |
|
212 | 248 | magical list/string objects which make shell use much more |
|
213 | 249 | conveninent, so not all is lost. |
|
214 | 250 | |
|
215 | 251 | XXX - FIX MANUAL for the change above! |
|
216 | 252 | |
|
217 | 253 | (runsource): I copied code.py's runsource() into ipython to modify |
|
218 | 254 | it a bit. Now the code object and source to be executed are |
|
219 | 255 | stored in ipython. This makes this info accessible to third-party |
|
220 | 256 | tools, like custom exception handlers. After a request by FrΓ©dΓ©ric |
|
221 | 257 | Mantegazza <mantegazza-AT-ill.fr>. |
|
222 | 258 | |
|
223 | 259 | * IPython/UserConfig/ipythonrc: Add up/down arrow keys to |
|
224 | 260 | history-search via readline (like C-p/C-n). I'd wanted this for a |
|
225 | 261 | long time, but only recently found out how to do it. For users |
|
226 | 262 | who already have their ipythonrc files made and want this, just |
|
227 | 263 | add: |
|
228 | 264 | |
|
229 | 265 | readline_parse_and_bind "\e[A": history-search-backward |
|
230 | 266 | readline_parse_and_bind "\e[B": history-search-forward |
|
231 | 267 | |
|
232 | 268 | 2005-03-18 Fernando Perez <fperez@colorado.edu> |
|
233 | 269 | |
|
234 | 270 | * IPython/Magic.py (magic_sc): %sc and %sx now use the fancy |
|
235 | 271 | LSString and SList classes which allow transparent conversions |
|
236 | 272 | between list mode and whitespace-separated string. |
|
237 | 273 | (magic_r): Fix recursion problem in %r. |
|
238 | 274 | |
|
239 | 275 | * IPython/genutils.py (LSString): New class to be used for |
|
240 | 276 | automatic storage of the results of all alias/system calls in _o |
|
241 | 277 | and _e (stdout/err). These provide a .l/.list attribute which |
|
242 | 278 | does automatic splitting on newlines. This means that for most |
|
243 | 279 | uses, you'll never need to do capturing of output with %sc/%sx |
|
244 | 280 | anymore, since ipython keeps this always done for you. Note that |
|
245 | 281 | only the LAST results are stored, the _o/e variables are |
|
246 | 282 | overwritten on each call. If you need to save their contents |
|
247 | 283 | further, simply bind them to any other name. |
|
248 | 284 | |
|
249 | 285 | 2005-03-17 Fernando Perez <fperez@colorado.edu> |
|
250 | 286 | |
|
251 | 287 | * IPython/Prompts.py (BasePrompt.cwd_filt): a few more fixes for |
|
252 | 288 | prompt namespace handling. |
|
253 | 289 | |
|
254 | 290 | 2005-03-16 Fernando Perez <fperez@colorado.edu> |
|
255 | 291 | |
|
256 | 292 | * IPython/Prompts.py (CachedOutput.__init__): Fix default and |
|
257 | 293 | classic prompts to be '>>> ' (final space was missing, and it |
|
258 | 294 | trips the emacs python mode). |
|
259 | 295 | (BasePrompt.__str__): Added safe support for dynamic prompt |
|
260 | 296 | strings. Now you can set your prompt string to be '$x', and the |
|
261 | 297 | value of x will be printed from your interactive namespace. The |
|
262 | 298 | interpolation syntax includes the full Itpl support, so |
|
263 | 299 | ${foo()+x+bar()} is a valid prompt string now, and the function |
|
264 | 300 | calls will be made at runtime. |
|
265 | 301 | |
|
266 | 302 | 2005-03-15 Fernando Perez <fperez@colorado.edu> |
|
267 | 303 | |
|
268 | 304 | * IPython/Magic.py (magic_history): renamed %hist to %history, to |
|
269 | 305 | avoid name clashes in pylab. %hist still works, it just forwards |
|
270 | 306 | the call to %history. |
|
271 | 307 | |
|
272 | 308 | 2005-03-02 *** Released version 0.6.12 |
|
273 | 309 | |
|
274 | 310 | 2005-03-02 Fernando Perez <fperez@colorado.edu> |
|
275 | 311 | |
|
276 | 312 | * IPython/iplib.py (handle_magic): log magic calls properly as |
|
277 | 313 | ipmagic() function calls. |
|
278 | 314 | |
|
279 | 315 | * IPython/Magic.py (magic_time): Improved %time to support |
|
280 | 316 | statements and provide wall-clock as well as CPU time. |
|
281 | 317 | |
|
282 | 318 | 2005-02-27 Fernando Perez <fperez@colorado.edu> |
|
283 | 319 | |
|
284 | 320 | * IPython/hooks.py: New hooks module, to expose user-modifiable |
|
285 | 321 | IPython functionality in a clean manner. For now only the editor |
|
286 | 322 | hook is actually written, and other thigns which I intend to turn |
|
287 | 323 | into proper hooks aren't yet there. The display and prefilter |
|
288 | 324 | stuff, for example, should be hooks. But at least now the |
|
289 | 325 | framework is in place, and the rest can be moved here with more |
|
290 | 326 | time later. IPython had had a .hooks variable for a long time for |
|
291 | 327 | this purpose, but I'd never actually used it for anything. |
|
292 | 328 | |
|
293 | 329 | 2005-02-26 Fernando Perez <fperez@colorado.edu> |
|
294 | 330 | |
|
295 | 331 | * IPython/ipmaker.py (make_IPython): make the default ipython |
|
296 | 332 | directory be called _ipython under win32, to follow more the |
|
297 | 333 | naming peculiarities of that platform (where buggy software like |
|
298 | 334 | Visual Sourcesafe breaks with .named directories). Reported by |
|
299 | 335 | Ville Vainio. |
|
300 | 336 | |
|
301 | 337 | 2005-02-23 Fernando Perez <fperez@colorado.edu> |
|
302 | 338 | |
|
303 | 339 | * IPython/iplib.py (InteractiveShell.__init__): removed a few |
|
304 | 340 | auto_aliases for win32 which were causing problems. Users can |
|
305 | 341 | define the ones they personally like. |
|
306 | 342 | |
|
307 | 343 | 2005-02-21 Fernando Perez <fperez@colorado.edu> |
|
308 | 344 | |
|
309 | 345 | * IPython/Magic.py (magic_time): new magic to time execution of |
|
310 | 346 | expressions. After a request by Charles Moad <cmoad-AT-indiana.edu>. |
|
311 | 347 | |
|
312 | 348 | 2005-02-19 Fernando Perez <fperez@colorado.edu> |
|
313 | 349 | |
|
314 | 350 | * IPython/ConfigLoader.py (ConfigLoader.load): Allow empty strings |
|
315 | 351 | into keys (for prompts, for example). |
|
316 | 352 | |
|
317 | 353 | * IPython/Prompts.py (BasePrompt.set_p_str): Fix to allow empty |
|
318 | 354 | prompts in case users want them. This introduces a small behavior |
|
319 | 355 | change: ipython does not automatically add a space to all prompts |
|
320 | 356 | anymore. To get the old prompts with a space, users should add it |
|
321 | 357 | manually to their ipythonrc file, so for example prompt_in1 should |
|
322 | 358 | now read 'In [\#]: ' instead of 'In [\#]:'. |
|
323 | 359 | (BasePrompt.__init__): New option prompts_pad_left (only in rc |
|
324 | 360 | file) to control left-padding of secondary prompts. |
|
325 | 361 | |
|
326 | 362 | * IPython/Magic.py (Magic.profile_missing_notice): Don't crash if |
|
327 | 363 | the profiler can't be imported. Fix for Debian, which removed |
|
328 | 364 | profile.py because of License issues. I applied a slightly |
|
329 | 365 | modified version of the original Debian patch at |
|
330 | 366 | http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=294500. |
|
331 | 367 | |
|
332 | 368 | 2005-02-17 Fernando Perez <fperez@colorado.edu> |
|
333 | 369 | |
|
334 | 370 | * IPython/genutils.py (native_line_ends): Fix bug which would |
|
335 | 371 | cause improper line-ends under win32 b/c I was not opening files |
|
336 | 372 | in binary mode. Bug report and fix thanks to Ville. |
|
337 | 373 | |
|
338 | 374 | * IPython/iplib.py (handle_auto): Fix bug which I introduced when |
|
339 | 375 | trying to catch spurious foo[1] autocalls. My fix actually broke |
|
340 | 376 | ',/' autoquote/call with explicit escape (bad regexp). |
|
341 | 377 | |
|
342 | 378 | 2005-02-15 *** Released version 0.6.11 |
|
343 | 379 | |
|
344 | 380 | 2005-02-14 Fernando Perez <fperez@colorado.edu> |
|
345 | 381 | |
|
346 | 382 | * IPython/background_jobs.py: New background job management |
|
347 | 383 | subsystem. This is implemented via a new set of classes, and |
|
348 | 384 | IPython now provides a builtin 'jobs' object for background job |
|
349 | 385 | execution. A convenience %bg magic serves as a lightweight |
|
350 | 386 | frontend for starting the more common type of calls. This was |
|
351 | 387 | inspired by discussions with B. Granger and the BackgroundCommand |
|
352 | 388 | class described in the book Python Scripting for Computational |
|
353 | 389 | Science, by H. P. Langtangen: http://folk.uio.no/hpl/scripting |
|
354 | 390 | (although ultimately no code from this text was used, as IPython's |
|
355 | 391 | system is a separate implementation). |
|
356 | 392 | |
|
357 | 393 | * IPython/iplib.py (MagicCompleter.python_matches): add new option |
|
358 | 394 | to control the completion of single/double underscore names |
|
359 | 395 | separately. As documented in the example ipytonrc file, the |
|
360 | 396 | readline_omit__names variable can now be set to 2, to omit even |
|
361 | 397 | single underscore names. Thanks to a patch by Brian Wong |
|
362 | 398 | <BrianWong-AT-AirgoNetworks.Com>. |
|
363 | 399 | (InteractiveShell.__init__): Fix bug which would cause foo[1] to |
|
364 | 400 | be autocalled as foo([1]) if foo were callable. A problem for |
|
365 | 401 | things which are both callable and implement __getitem__. |
|
366 | 402 | (init_readline): Fix autoindentation for win32. Thanks to a patch |
|
367 | 403 | by Vivian De Smedt <vivian-AT-vdesmedt.com>. |
|
368 | 404 | |
|
369 | 405 | 2005-02-12 Fernando Perez <fperez@colorado.edu> |
|
370 | 406 | |
|
371 | 407 | * IPython/ipmaker.py (make_IPython): Disabled the stout traps |
|
372 | 408 | which I had written long ago to sort out user error messages which |
|
373 | 409 | may occur during startup. This seemed like a good idea initially, |
|
374 | 410 | but it has proven a disaster in retrospect. I don't want to |
|
375 | 411 | change much code for now, so my fix is to set the internal 'debug' |
|
376 | 412 | flag to true everywhere, whose only job was precisely to control |
|
377 | 413 | this subsystem. This closes issue 28 (as well as avoiding all |
|
378 | 414 | sorts of strange hangups which occur from time to time). |
|
379 | 415 | |
|
380 | 416 | 2005-02-07 Fernando Perez <fperez@colorado.edu> |
|
381 | 417 | |
|
382 | 418 | * IPython/Magic.py (magic_edit): Fix 'ed -p' not working when the |
|
383 | 419 | previous call produced a syntax error. |
|
384 | 420 | |
|
385 | 421 | * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting |
|
386 | 422 | classes without constructor. |
|
387 | 423 | |
|
388 | 424 | 2005-02-06 Fernando Perez <fperez@colorado.edu> |
|
389 | 425 | |
|
390 | 426 | * IPython/iplib.py (MagicCompleter.complete): Extend the list of |
|
391 | 427 | completions with the results of each matcher, so we return results |
|
392 | 428 | to the user from all namespaces. This breaks with ipython |
|
393 | 429 | tradition, but I think it's a nicer behavior. Now you get all |
|
394 | 430 | possible completions listed, from all possible namespaces (python, |
|
395 | 431 | filesystem, magics...) After a request by John Hunter |
|
396 | 432 | <jdhunter-AT-nitace.bsd.uchicago.edu>. |
|
397 | 433 | |
|
398 | 434 | 2005-02-05 Fernando Perez <fperez@colorado.edu> |
|
399 | 435 | |
|
400 | 436 | * IPython/Magic.py (magic_prun): Fix bug where prun would fail if |
|
401 | 437 | the call had quote characters in it (the quotes were stripped). |
|
402 | 438 | |
|
403 | 439 | 2005-01-31 Fernando Perez <fperez@colorado.edu> |
|
404 | 440 | |
|
405 | 441 | * IPython/iplib.py (InteractiveShell.__init__): reduce reliance on |
|
406 | 442 | Itpl.itpl() to make the code more robust against psyco |
|
407 | 443 | optimizations. |
|
408 | 444 | |
|
409 | 445 | * IPython/Itpl.py (Itpl.__str__): Use a _getframe() call instead |
|
410 | 446 | of causing an exception. Quicker, cleaner. |
|
411 | 447 | |
|
412 | 448 | 2005-01-28 Fernando Perez <fperez@colorado.edu> |
|
413 | 449 | |
|
414 | 450 | * scripts/ipython_win_post_install.py (install): hardcode |
|
415 | 451 | sys.prefix+'python.exe' as the executable path. It turns out that |
|
416 | 452 | during the post-installation run, sys.executable resolves to the |
|
417 | 453 | name of the binary installer! I should report this as a distutils |
|
418 | 454 | bug, I think. I updated the .10 release with this tiny fix, to |
|
419 | 455 | avoid annoying the lists further. |
|
420 | 456 | |
|
421 | 457 | 2005-01-27 *** Released version 0.6.10 |
|
422 | 458 | |
|
423 | 459 | 2005-01-27 Fernando Perez <fperez@colorado.edu> |
|
424 | 460 | |
|
425 | 461 | * IPython/numutils.py (norm): Added 'inf' as optional name for |
|
426 | 462 | L-infinity norm, included references to mathworld.com for vector |
|
427 | 463 | norm definitions. |
|
428 | 464 | (amin/amax): added amin/amax for array min/max. Similar to what |
|
429 | 465 | pylab ships with after the recent reorganization of names. |
|
430 | 466 | (spike/spike_odd): removed deprecated spike/spike_odd functions. |
|
431 | 467 | |
|
432 | 468 | * ipython.el: committed Alex's recent fixes and improvements. |
|
433 | 469 | Tested with python-mode from CVS, and it looks excellent. Since |
|
434 | 470 | python-mode hasn't released anything in a while, I'm temporarily |
|
435 | 471 | putting a copy of today's CVS (v 4.70) of python-mode in: |
|
436 | 472 | http://ipython.scipy.org/tmp/python-mode.el |
|
437 | 473 | |
|
438 | 474 | * scripts/ipython_win_post_install.py (install): Win32 fix to use |
|
439 | 475 | sys.executable for the executable name, instead of assuming it's |
|
440 | 476 | called 'python.exe' (the post-installer would have produced broken |
|
441 | 477 | setups on systems with a differently named python binary). |
|
442 | 478 | |
|
443 | 479 | * IPython/PyColorize.py (Parser.__call__): change explicit '\n' |
|
444 | 480 | references to os.linesep, to make the code more |
|
445 | 481 | platform-independent. This is also part of the win32 coloring |
|
446 | 482 | fixes. |
|
447 | 483 | |
|
448 | 484 | * IPython/genutils.py (page_dumb): Remove attempts to chop long |
|
449 | 485 | lines, which actually cause coloring bugs because the length of |
|
450 | 486 | the line is very difficult to correctly compute with embedded |
|
451 | 487 | escapes. This was the source of all the coloring problems under |
|
452 | 488 | Win32. I think that _finally_, Win32 users have a properly |
|
453 | 489 | working ipython in all respects. This would never have happened |
|
454 | 490 | if not for Gary Bishop and Viktor Ransmayr's great help and work. |
|
455 | 491 | |
|
456 | 492 | 2005-01-26 *** Released version 0.6.9 |
|
457 | 493 | |
|
458 | 494 | 2005-01-25 Fernando Perez <fperez@colorado.edu> |
|
459 | 495 | |
|
460 | 496 | * setup.py: finally, we have a true Windows installer, thanks to |
|
461 | 497 | the excellent work of Viktor Ransmayr |
|
462 | 498 | <viktor.ransmayr-AT-t-online.de>. The docs have been updated for |
|
463 | 499 | Windows users. The setup routine is quite a bit cleaner thanks to |
|
464 | 500 | this, and the post-install script uses the proper functions to |
|
465 | 501 | allow a clean de-installation using the standard Windows Control |
|
466 | 502 | Panel. |
|
467 | 503 | |
|
468 | 504 | * IPython/genutils.py (get_home_dir): changed to use the $HOME |
|
469 | 505 | environment variable under all OSes (including win32) if |
|
470 | 506 | available. This will give consistency to win32 users who have set |
|
471 | 507 | this variable for any reason. If os.environ['HOME'] fails, the |
|
472 | 508 | previous policy of using HOMEDRIVE\HOMEPATH kicks in. |
|
473 | 509 | |
|
474 | 510 | 2005-01-24 Fernando Perez <fperez@colorado.edu> |
|
475 | 511 | |
|
476 | 512 | * IPython/numutils.py (empty_like): add empty_like(), similar to |
|
477 | 513 | zeros_like() but taking advantage of the new empty() Numeric routine. |
|
478 | 514 | |
|
479 | 515 | 2005-01-23 *** Released version 0.6.8 |
|
480 | 516 | |
|
481 | 517 | 2005-01-22 Fernando Perez <fperez@colorado.edu> |
|
482 | 518 | |
|
483 | 519 | * IPython/Shell.py (MatplotlibShellBase.mplot_exec): I removed the |
|
484 | 520 | automatic show() calls. After discussing things with JDH, it |
|
485 | 521 | turns out there are too many corner cases where this can go wrong. |
|
486 | 522 | It's best not to try to be 'too smart', and simply have ipython |
|
487 | 523 | reproduce as much as possible the default behavior of a normal |
|
488 | 524 | python shell. |
|
489 | 525 | |
|
490 | 526 | * IPython/iplib.py (InteractiveShell.__init__): Modified the |
|
491 | 527 | line-splitting regexp and _prefilter() to avoid calling getattr() |
|
492 | 528 | on assignments. This closes |
|
493 | 529 | http://www.scipy.net/roundup/ipython/issue24. Note that Python's |
|
494 | 530 | readline uses getattr(), so a simple <TAB> keypress is still |
|
495 | 531 | enough to trigger getattr() calls on an object. |
|
496 | 532 | |
|
497 | 533 | 2005-01-21 Fernando Perez <fperez@colorado.edu> |
|
498 | 534 | |
|
499 | 535 | * IPython/Shell.py (MatplotlibShellBase.magic_run): Fix the %run |
|
500 | 536 | docstring under pylab so it doesn't mask the original. |
|
501 | 537 | |
|
502 | 538 | 2005-01-21 *** Released version 0.6.7 |
|
503 | 539 | |
|
504 | 540 | 2005-01-21 Fernando Perez <fperez@colorado.edu> |
|
505 | 541 | |
|
506 | 542 | * IPython/Shell.py (MTInteractiveShell.runcode): Trap a crash with |
|
507 | 543 | signal handling for win32 users in multithreaded mode. |
|
508 | 544 | |
|
509 | 545 | 2005-01-17 Fernando Perez <fperez@colorado.edu> |
|
510 | 546 | |
|
511 | 547 | * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting |
|
512 | 548 | instances with no __init__. After a crash report by Norbert Nemec |
|
513 | 549 | <Norbert-AT-nemec-online.de>. |
|
514 | 550 | |
|
515 | 551 | 2005-01-14 Fernando Perez <fperez@colorado.edu> |
|
516 | 552 | |
|
517 | 553 | * IPython/ultraTB.py (VerboseTB.text): Fix bug in reporting of |
|
518 | 554 | names for verbose exceptions, when multiple dotted names and the |
|
519 | 555 | 'parent' object were present on the same line. |
|
520 | 556 | |
|
521 | 557 | 2005-01-11 Fernando Perez <fperez@colorado.edu> |
|
522 | 558 | |
|
523 | 559 | * IPython/genutils.py (flag_calls): new utility to trap and flag |
|
524 | 560 | calls in functions. I need it to clean up matplotlib support. |
|
525 | 561 | Also removed some deprecated code in genutils. |
|
526 | 562 | |
|
527 | 563 | * IPython/Shell.py (MatplotlibShellBase.mplot_exec): small fix so |
|
528 | 564 | that matplotlib scripts called with %run, which don't call show() |
|
529 | 565 | themselves, still have their plotting windows open. |
|
530 | 566 | |
|
531 | 567 | 2005-01-05 Fernando Perez <fperez@colorado.edu> |
|
532 | 568 | |
|
533 | 569 | * IPython/Shell.py (IPShellGTK.__init__): Patch by Andrew Straw |
|
534 | 570 | <astraw-AT-caltech.edu>, to fix gtk deprecation warnings. |
|
535 | 571 | |
|
536 | 572 | 2004-12-19 Fernando Perez <fperez@colorado.edu> |
|
537 | 573 | |
|
538 | 574 | * IPython/Shell.py (MTInteractiveShell.runcode): Get rid of |
|
539 | 575 | parent_runcode, which was an eyesore. The same result can be |
|
540 | 576 | obtained with Python's regular superclass mechanisms. |
|
541 | 577 | |
|
542 | 578 | 2004-12-17 Fernando Perez <fperez@colorado.edu> |
|
543 | 579 | |
|
544 | 580 | * IPython/Magic.py (Magic.magic_sc): Fix quote stripping problem |
|
545 | 581 | reported by Prabhu. |
|
546 | 582 | (Magic.magic_sx): direct all errors to Term.cerr (defaults to |
|
547 | 583 | sys.stderr) instead of explicitly calling sys.stderr. This helps |
|
548 | 584 | maintain our I/O abstractions clean, for future GUI embeddings. |
|
549 | 585 | |
|
550 | 586 | * IPython/genutils.py (info): added new utility for sys.stderr |
|
551 | 587 | unified info message handling (thin wrapper around warn()). |
|
552 | 588 | |
|
553 | 589 | * IPython/ultraTB.py (VerboseTB.text): Fix misreported global |
|
554 | 590 | composite (dotted) names on verbose exceptions. |
|
555 | 591 | (VerboseTB.nullrepr): harden against another kind of errors which |
|
556 | 592 | Python's inspect module can trigger, and which were crashing |
|
557 | 593 | IPython. Thanks to a report by Marco Lombardi |
|
558 | 594 | <mlombard-AT-ma010192.hq.eso.org>. |
|
559 | 595 | |
|
560 | 596 | 2004-12-13 *** Released version 0.6.6 |
|
561 | 597 | |
|
562 | 598 | 2004-12-12 Fernando Perez <fperez@colorado.edu> |
|
563 | 599 | |
|
564 | 600 | * IPython/Shell.py (IPShellGTK.mainloop): catch RuntimeErrors |
|
565 | 601 | generated by pygtk upon initialization if it was built without |
|
566 | 602 | threads (for matplotlib users). After a crash reported by |
|
567 | 603 | Leguijt, Jaap J SIEP-EPT-RES <Jaap.Leguijt-AT-shell.com>. |
|
568 | 604 | |
|
569 | 605 | * IPython/ipmaker.py (make_IPython): fix small bug in the |
|
570 | 606 | import_some parameter for multiple imports. |
|
571 | 607 | |
|
572 | 608 | * IPython/iplib.py (ipmagic): simplified the interface of |
|
573 | 609 | ipmagic() to take a single string argument, just as it would be |
|
574 | 610 | typed at the IPython cmd line. |
|
575 | 611 | (ipalias): Added new ipalias() with an interface identical to |
|
576 | 612 | ipmagic(). This completes exposing a pure python interface to the |
|
577 | 613 | alias and magic system, which can be used in loops or more complex |
|
578 | 614 | code where IPython's automatic line mangling is not active. |
|
579 | 615 | |
|
580 | 616 | * IPython/genutils.py (timing): changed interface of timing to |
|
581 | 617 | simply run code once, which is the most common case. timings() |
|
582 | 618 | remains unchanged, for the cases where you want multiple runs. |
|
583 | 619 | |
|
584 | 620 | * IPython/Shell.py (MatplotlibShellBase._matplotlib_config): Fix a |
|
585 | 621 | bug where Python2.2 crashes with exec'ing code which does not end |
|
586 | 622 | in a single newline. Python 2.3 is OK, so I hadn't noticed this |
|
587 | 623 | before. |
|
588 | 624 | |
|
589 | 625 | 2004-12-10 Fernando Perez <fperez@colorado.edu> |
|
590 | 626 | |
|
591 | 627 | * IPython/Magic.py (Magic.magic_prun): changed name of option from |
|
592 | 628 | -t to -T, to accomodate the new -t flag in %run (the %run and |
|
593 | 629 | %prun options are kind of intermixed, and it's not easy to change |
|
594 | 630 | this with the limitations of python's getopt). |
|
595 | 631 | |
|
596 | 632 | * IPython/Magic.py (Magic.magic_run): Added new -t option to time |
|
597 | 633 | the execution of scripts. It's not as fine-tuned as timeit.py, |
|
598 | 634 | but it works from inside ipython (and under 2.2, which lacks |
|
599 | 635 | timeit.py). Optionally a number of runs > 1 can be given for |
|
600 | 636 | timing very short-running code. |
|
601 | 637 | |
|
602 | 638 | * IPython/genutils.py (uniq_stable): new routine which returns a |
|
603 | 639 | list of unique elements in any iterable, but in stable order of |
|
604 | 640 | appearance. I needed this for the ultraTB fixes, and it's a handy |
|
605 | 641 | utility. |
|
606 | 642 | |
|
607 | 643 | * IPython/ultraTB.py (VerboseTB.text): Fix proper reporting of |
|
608 | 644 | dotted names in Verbose exceptions. This had been broken since |
|
609 | 645 | the very start, now x.y will properly be printed in a Verbose |
|
610 | 646 | traceback, instead of x being shown and y appearing always as an |
|
611 | 647 | 'undefined global'. Getting this to work was a bit tricky, |
|
612 | 648 | because by default python tokenizers are stateless. Saved by |
|
613 | 649 | python's ability to easily add a bit of state to an arbitrary |
|
614 | 650 | function (without needing to build a full-blown callable object). |
|
615 | 651 | |
|
616 | 652 | Also big cleanup of this code, which had horrendous runtime |
|
617 | 653 | lookups of zillions of attributes for colorization. Moved all |
|
618 | 654 | this code into a few templates, which make it cleaner and quicker. |
|
619 | 655 | |
|
620 | 656 | Printout quality was also improved for Verbose exceptions: one |
|
621 | 657 | variable per line, and memory addresses are printed (this can be |
|
622 | 658 | quite handy in nasty debugging situations, which is what Verbose |
|
623 | 659 | is for). |
|
624 | 660 | |
|
625 | 661 | * IPython/ipmaker.py (make_IPython): Do NOT execute files named in |
|
626 | 662 | the command line as scripts to be loaded by embedded instances. |
|
627 | 663 | Doing so has the potential for an infinite recursion if there are |
|
628 | 664 | exceptions thrown in the process. This fixes a strange crash |
|
629 | 665 | reported by Philippe MULLER <muller-AT-irit.fr>. |
|
630 | 666 | |
|
631 | 667 | 2004-12-09 Fernando Perez <fperez@colorado.edu> |
|
632 | 668 | |
|
633 | 669 | * IPython/Shell.py (MatplotlibShellBase.use): Change pylab support |
|
634 | 670 | to reflect new names in matplotlib, which now expose the |
|
635 | 671 | matlab-compatible interface via a pylab module instead of the |
|
636 | 672 | 'matlab' name. The new code is backwards compatible, so users of |
|
637 | 673 | all matplotlib versions are OK. Patch by J. Hunter. |
|
638 | 674 | |
|
639 | 675 | * IPython/OInspect.py (Inspector.pinfo): Add to object? printing |
|
640 | 676 | of __init__ docstrings for instances (class docstrings are already |
|
641 | 677 | automatically printed). Instances with customized docstrings |
|
642 | 678 | (indep. of the class) are also recognized and all 3 separate |
|
643 | 679 | docstrings are printed (instance, class, constructor). After some |
|
644 | 680 | comments/suggestions by J. Hunter. |
|
645 | 681 | |
|
646 | 682 | 2004-12-05 Fernando Perez <fperez@colorado.edu> |
|
647 | 683 | |
|
648 | 684 | * IPython/iplib.py (MagicCompleter.complete): Remove annoying |
|
649 | 685 | warnings when tab-completion fails and triggers an exception. |
|
650 | 686 | |
|
651 | 687 | 2004-12-03 Fernando Perez <fperez@colorado.edu> |
|
652 | 688 | |
|
653 | 689 | * IPython/Magic.py (magic_prun): Fix bug where an exception would |
|
654 | 690 | be triggered when using 'run -p'. An incorrect option flag was |
|
655 | 691 | being set ('d' instead of 'D'). |
|
656 | 692 | (manpage): fix missing escaped \- sign. |
|
657 | 693 | |
|
658 | 694 | 2004-11-30 *** Released version 0.6.5 |
|
659 | 695 | |
|
660 | 696 | 2004-11-30 Fernando Perez <fperez@colorado.edu> |
|
661 | 697 | |
|
662 | 698 | * IPython/Magic.py (Magic.magic_run): Fix bug in breakpoint |
|
663 | 699 | setting with -d option. |
|
664 | 700 | |
|
665 | 701 | * setup.py (docfiles): Fix problem where the doc glob I was using |
|
666 | 702 | was COMPLETELY BROKEN. It was giving the right files by pure |
|
667 | 703 | accident, but failed once I tried to include ipython.el. Note: |
|
668 | 704 | glob() does NOT allow you to do exclusion on multiple endings! |
|
669 | 705 | |
|
670 | 706 | 2004-11-29 Fernando Perez <fperez@colorado.edu> |
|
671 | 707 | |
|
672 | 708 | * IPython/usage.py (__doc__): cleaned up usage docstring, by using |
|
673 | 709 | the manpage as the source. Better formatting & consistency. |
|
674 | 710 | |
|
675 | 711 | * IPython/Magic.py (magic_run): Added new -d option, to run |
|
676 | 712 | scripts under the control of the python pdb debugger. Note that |
|
677 | 713 | this required changing the %prun option -d to -D, to avoid a clash |
|
678 | 714 | (since %run must pass options to %prun, and getopt is too dumb to |
|
679 | 715 | handle options with string values with embedded spaces). Thanks |
|
680 | 716 | to a suggestion by Matthew Arnison <maffew-AT-cat.org.au>. |
|
681 | 717 | (magic_who_ls): added type matching to %who and %whos, so that one |
|
682 | 718 | can filter their output to only include variables of certain |
|
683 | 719 | types. Another suggestion by Matthew. |
|
684 | 720 | (magic_whos): Added memory summaries in kb and Mb for arrays. |
|
685 | 721 | (magic_who): Improve formatting (break lines every 9 vars). |
|
686 | 722 | |
|
687 | 723 | 2004-11-28 Fernando Perez <fperez@colorado.edu> |
|
688 | 724 | |
|
689 | 725 | * IPython/Logger.py (Logger.log): Fix bug in syncing the input |
|
690 | 726 | cache when empty lines were present. |
|
691 | 727 | |
|
692 | 728 | 2004-11-24 Fernando Perez <fperez@colorado.edu> |
|
693 | 729 | |
|
694 | 730 | * IPython/usage.py (__doc__): document the re-activated threading |
|
695 | 731 | options for WX and GTK. |
|
696 | 732 | |
|
697 | 733 | 2004-11-23 Fernando Perez <fperez@colorado.edu> |
|
698 | 734 | |
|
699 | 735 | * IPython/Shell.py (start): Added Prabhu's big patch to reactivate |
|
700 | 736 | the -wthread and -gthread options, along with a new -tk one to try |
|
701 | 737 | and coordinate Tk threading with wx/gtk. The tk support is very |
|
702 | 738 | platform dependent, since it seems to require Tcl and Tk to be |
|
703 | 739 | built with threads (Fedora1/2 appears NOT to have it, but in |
|
704 | 740 | Prabhu's Debian boxes it works OK). But even with some Tk |
|
705 | 741 | limitations, this is a great improvement. |
|
706 | 742 | |
|
707 | 743 | * IPython/Prompts.py (prompt_specials_color): Added \t for time |
|
708 | 744 | info in user prompts. Patch by Prabhu. |
|
709 | 745 | |
|
710 | 746 | 2004-11-18 Fernando Perez <fperez@colorado.edu> |
|
711 | 747 | |
|
712 | 748 | * IPython/genutils.py (ask_yes_no): Add check for a max of 20 |
|
713 | 749 | EOFErrors and bail, to avoid infinite loops if a non-terminating |
|
714 | 750 | file is fed into ipython. Patch submitted in issue 19 by user, |
|
715 | 751 | many thanks. |
|
716 | 752 | |
|
717 | 753 | * IPython/iplib.py (InteractiveShell.handle_auto): do NOT trigger |
|
718 | 754 | autoquote/parens in continuation prompts, which can cause lots of |
|
719 | 755 | problems. Closes roundup issue 20. |
|
720 | 756 | |
|
721 | 757 | 2004-11-17 Fernando Perez <fperez@colorado.edu> |
|
722 | 758 | |
|
723 | 759 | * debian/control (Build-Depends-Indep): Fix dpatch dependency, |
|
724 | 760 | reported as debian bug #280505. I'm not sure my local changelog |
|
725 | 761 | entry has the proper debian format (Jack?). |
|
726 | 762 | |
|
727 | 763 | 2004-11-08 *** Released version 0.6.4 |
|
728 | 764 | |
|
729 | 765 | 2004-11-08 Fernando Perez <fperez@colorado.edu> |
|
730 | 766 | |
|
731 | 767 | * IPython/iplib.py (init_readline): Fix exit message for Windows |
|
732 | 768 | when readline is active. Thanks to a report by Eric Jones |
|
733 | 769 | <eric-AT-enthought.com>. |
|
734 | 770 | |
|
735 | 771 | 2004-11-07 Fernando Perez <fperez@colorado.edu> |
|
736 | 772 | |
|
737 | 773 | * IPython/genutils.py (page): Add a trap for OSError exceptions, |
|
738 | 774 | sometimes seen by win2k/cygwin users. |
|
739 | 775 | |
|
740 | 776 | 2004-11-06 Fernando Perez <fperez@colorado.edu> |
|
741 | 777 | |
|
742 | 778 | * IPython/iplib.py (interact): Change the handling of %Exit from |
|
743 | 779 | trying to propagate a SystemExit to an internal ipython flag. |
|
744 | 780 | This is less elegant than using Python's exception mechanism, but |
|
745 | 781 | I can't get that to work reliably with threads, so under -pylab |
|
746 | 782 | %Exit was hanging IPython. Cross-thread exception handling is |
|
747 | 783 | really a bitch. Thaks to a bug report by Stephen Walton |
|
748 | 784 | <stephen.walton-AT-csun.edu>. |
|
749 | 785 | |
|
750 | 786 | 2004-11-04 Fernando Perez <fperez@colorado.edu> |
|
751 | 787 | |
|
752 | 788 | * IPython/iplib.py (raw_input_original): store a pointer to the |
|
753 | 789 | true raw_input to harden against code which can modify it |
|
754 | 790 | (wx.py.PyShell does this and would otherwise crash ipython). |
|
755 | 791 | Thanks to a bug report by Jim Flowers <james.flowers-AT-lgx.com>. |
|
756 | 792 | |
|
757 | 793 | * IPython/Shell.py (MTInteractiveShell.runsource): Cleaner fix for |
|
758 | 794 | Ctrl-C problem, which does not mess up the input line. |
|
759 | 795 | |
|
760 | 796 | 2004-11-03 Fernando Perez <fperez@colorado.edu> |
|
761 | 797 | |
|
762 | 798 | * IPython/Release.py: Changed licensing to BSD, in all files. |
|
763 | 799 | (name): lowercase name for tarball/RPM release. |
|
764 | 800 | |
|
765 | 801 | * IPython/OInspect.py (getdoc): wrap inspect.getdoc() safely for |
|
766 | 802 | use throughout ipython. |
|
767 | 803 | |
|
768 | 804 | * IPython/Magic.py (Magic._ofind): Switch to using the new |
|
769 | 805 | OInspect.getdoc() function. |
|
770 | 806 | |
|
771 | 807 | * IPython/Shell.py (sigint_handler): Hack to ignore the execution |
|
772 | 808 | of the line currently being canceled via Ctrl-C. It's extremely |
|
773 | 809 | ugly, but I don't know how to do it better (the problem is one of |
|
774 | 810 | handling cross-thread exceptions). |
|
775 | 811 | |
|
776 | 812 | 2004-10-28 Fernando Perez <fperez@colorado.edu> |
|
777 | 813 | |
|
778 | 814 | * IPython/Shell.py (signal_handler): add signal handlers to trap |
|
779 | 815 | SIGINT and SIGSEGV in threaded code properly. Thanks to a bug |
|
780 | 816 | report by Francesc Alted. |
|
781 | 817 | |
|
782 | 818 | 2004-10-21 Fernando Perez <fperez@colorado.edu> |
|
783 | 819 | |
|
784 | 820 | * IPython/Extensions/InterpreterExec.py (prefilter_shell): Fix @ |
|
785 | 821 | to % for pysh syntax extensions. |
|
786 | 822 | |
|
787 | 823 | 2004-10-09 Fernando Perez <fperez@colorado.edu> |
|
788 | 824 | |
|
789 | 825 | * IPython/Magic.py (Magic.magic_whos): modify output of Numeric |
|
790 | 826 | arrays to print a more useful summary, without calling str(arr). |
|
791 | 827 | This avoids the problem of extremely lengthy computations which |
|
792 | 828 | occur if arr is large, and appear to the user as a system lockup |
|
793 | 829 | with 100% cpu activity. After a suggestion by Kristian Sandberg |
|
794 | 830 | <Kristian.Sandberg@colorado.edu>. |
|
795 | 831 | (Magic.__init__): fix bug in global magic escapes not being |
|
796 | 832 | correctly set. |
|
797 | 833 | |
|
798 | 834 | 2004-10-08 Fernando Perez <fperez@colorado.edu> |
|
799 | 835 | |
|
800 | 836 | * IPython/Magic.py (__license__): change to absolute imports of |
|
801 | 837 | ipython's own internal packages, to start adapting to the absolute |
|
802 | 838 | import requirement of PEP-328. |
|
803 | 839 | |
|
804 | 840 | * IPython/genutils.py (__author__): Fix coding to utf-8 on all |
|
805 | 841 | files, and standardize author/license marks through the Release |
|
806 | 842 | module instead of having per/file stuff (except for files with |
|
807 | 843 | particular licenses, like the MIT/PSF-licensed codes). |
|
808 | 844 | |
|
809 | 845 | * IPython/Debugger.py: remove dead code for python 2.1 |
|
810 | 846 | |
|
811 | 847 | 2004-10-04 Fernando Perez <fperez@colorado.edu> |
|
812 | 848 | |
|
813 | 849 | * IPython/iplib.py (ipmagic): New function for accessing magics |
|
814 | 850 | via a normal python function call. |
|
815 | 851 | |
|
816 | 852 | * IPython/Magic.py (Magic.magic_magic): Change the magic escape |
|
817 | 853 | from '@' to '%', to accomodate the new @decorator syntax of python |
|
818 | 854 | 2.4. |
|
819 | 855 | |
|
820 | 856 | 2004-09-29 Fernando Perez <fperez@colorado.edu> |
|
821 | 857 | |
|
822 | 858 | * IPython/Shell.py (MatplotlibShellBase.use): Added a wrapper to |
|
823 | 859 | matplotlib.use to prevent running scripts which try to switch |
|
824 | 860 | interactive backends from within ipython. This will just crash |
|
825 | 861 | the python interpreter, so we can't allow it (but a detailed error |
|
826 | 862 | is given to the user). |
|
827 | 863 | |
|
828 | 864 | 2004-09-28 Fernando Perez <fperez@colorado.edu> |
|
829 | 865 | |
|
830 | 866 | * IPython/Shell.py (MatplotlibShellBase.mplot_exec): |
|
831 | 867 | matplotlib-related fixes so that using @run with non-matplotlib |
|
832 | 868 | scripts doesn't pop up spurious plot windows. This requires |
|
833 | 869 | matplotlib >= 0.63, where I had to make some changes as well. |
|
834 | 870 | |
|
835 | 871 | * IPython/ipmaker.py (make_IPython): update version requirement to |
|
836 | 872 | python 2.2. |
|
837 | 873 | |
|
838 | 874 | * IPython/iplib.py (InteractiveShell.mainloop): Add an optional |
|
839 | 875 | banner arg for embedded customization. |
|
840 | 876 | |
|
841 | 877 | * IPython/Magic.py (Magic.__init__): big cleanup to remove all |
|
842 | 878 | explicit uses of __IP as the IPython's instance name. Now things |
|
843 | 879 | are properly handled via the shell.name value. The actual code |
|
844 | 880 | is a bit ugly b/c I'm doing it via a global in Magic.py, but this |
|
845 | 881 | is much better than before. I'll clean things completely when the |
|
846 | 882 | magic stuff gets a real overhaul. |
|
847 | 883 | |
|
848 | 884 | * ipython.1: small fixes, sent in by Jack Moffit. He also sent in |
|
849 | 885 | minor changes to debian dir. |
|
850 | 886 | |
|
851 | 887 | * IPython/iplib.py (InteractiveShell.__init__): Fix adding a |
|
852 | 888 | pointer to the shell itself in the interactive namespace even when |
|
853 | 889 | a user-supplied dict is provided. This is needed for embedding |
|
854 | 890 | purposes (found by tests with Michel Sanner). |
|
855 | 891 | |
|
856 | 892 | 2004-09-27 Fernando Perez <fperez@colorado.edu> |
|
857 | 893 | |
|
858 | 894 | * IPython/UserConfig/ipythonrc: remove []{} from |
|
859 | 895 | readline_remove_delims, so that things like [modname.<TAB> do |
|
860 | 896 | proper completion. This disables [].TAB, but that's a less common |
|
861 | 897 | case than module names in list comprehensions, for example. |
|
862 | 898 | Thanks to a report by Andrea Riciputi. |
|
863 | 899 | |
|
864 | 900 | 2004-09-09 Fernando Perez <fperez@colorado.edu> |
|
865 | 901 | |
|
866 | 902 | * IPython/Shell.py (IPShellGTK.mainloop): reorder to avoid |
|
867 | 903 | blocking problems in win32 and osx. Fix by John. |
|
868 | 904 | |
|
869 | 905 | 2004-09-08 Fernando Perez <fperez@colorado.edu> |
|
870 | 906 | |
|
871 | 907 | * IPython/Shell.py (IPShellWX.OnInit): Fix output redirection bug |
|
872 | 908 | for Win32 and OSX. Fix by John Hunter. |
|
873 | 909 | |
|
874 | 910 | 2004-08-30 *** Released version 0.6.3 |
|
875 | 911 | |
|
876 | 912 | 2004-08-30 Fernando Perez <fperez@colorado.edu> |
|
877 | 913 | |
|
878 | 914 | * setup.py (isfile): Add manpages to list of dependent files to be |
|
879 | 915 | updated. |
|
880 | 916 | |
|
881 | 917 | 2004-08-27 Fernando Perez <fperez@colorado.edu> |
|
882 | 918 | |
|
883 | 919 | * IPython/Shell.py (start): I've disabled -wthread and -gthread |
|
884 | 920 | for now. They don't really work with standalone WX/GTK code |
|
885 | 921 | (though matplotlib IS working fine with both of those backends). |
|
886 | 922 | This will neeed much more testing. I disabled most things with |
|
887 | 923 | comments, so turning it back on later should be pretty easy. |
|
888 | 924 | |
|
889 | 925 | * IPython/iplib.py (InteractiveShell.__init__): Fix accidental |
|
890 | 926 | autocalling of expressions like r'foo', by modifying the line |
|
891 | 927 | split regexp. Closes |
|
892 | 928 | http://www.scipy.net/roundup/ipython/issue18, reported by Nicholas |
|
893 | 929 | Riley <ipythonbugs-AT-sabi.net>. |
|
894 | 930 | (InteractiveShell.mainloop): honor --nobanner with banner |
|
895 | 931 | extensions. |
|
896 | 932 | |
|
897 | 933 | * IPython/Shell.py: Significant refactoring of all classes, so |
|
898 | 934 | that we can really support ALL matplotlib backends and threading |
|
899 | 935 | models (John spotted a bug with Tk which required this). Now we |
|
900 | 936 | should support single-threaded, WX-threads and GTK-threads, both |
|
901 | 937 | for generic code and for matplotlib. |
|
902 | 938 | |
|
903 | 939 | * IPython/ipmaker.py (__call__): Changed -mpthread option to |
|
904 | 940 | -pylab, to simplify things for users. Will also remove the pylab |
|
905 | 941 | profile, since now all of matplotlib configuration is directly |
|
906 | 942 | handled here. This also reduces startup time. |
|
907 | 943 | |
|
908 | 944 | * IPython/Shell.py (IPShellGTK.run): Fixed bug where mainloop() of |
|
909 | 945 | shell wasn't being correctly called. Also in IPShellWX. |
|
910 | 946 | |
|
911 | 947 | * IPython/iplib.py (InteractiveShell.__init__): Added option to |
|
912 | 948 | fine-tune banner. |
|
913 | 949 | |
|
914 | 950 | * IPython/numutils.py (spike): Deprecate these spike functions, |
|
915 | 951 | delete (long deprecated) gnuplot_exec handler. |
|
916 | 952 | |
|
917 | 953 | 2004-08-26 Fernando Perez <fperez@colorado.edu> |
|
918 | 954 | |
|
919 | 955 | * ipython.1: Update for threading options, plus some others which |
|
920 | 956 | were missing. |
|
921 | 957 | |
|
922 | 958 | * IPython/ipmaker.py (__call__): Added -wthread option for |
|
923 | 959 | wxpython thread handling. Make sure threading options are only |
|
924 | 960 | valid at the command line. |
|
925 | 961 | |
|
926 | 962 | * scripts/ipython: moved shell selection into a factory function |
|
927 | 963 | in Shell.py, to keep the starter script to a minimum. |
|
928 | 964 | |
|
929 | 965 | 2004-08-25 Fernando Perez <fperez@colorado.edu> |
|
930 | 966 | |
|
931 | 967 | * IPython/Shell.py (IPShellWX.wxexit): fixes to WX threading, by |
|
932 | 968 | John. Along with some recent changes he made to matplotlib, the |
|
933 | 969 | next versions of both systems should work very well together. |
|
934 | 970 | |
|
935 | 971 | 2004-08-24 Fernando Perez <fperez@colorado.edu> |
|
936 | 972 | |
|
937 | 973 | * IPython/Magic.py (Magic.magic_prun): cleanup some dead code. I |
|
938 | 974 | tried to switch the profiling to using hotshot, but I'm getting |
|
939 | 975 | strange errors from prof.runctx() there. I may be misreading the |
|
940 | 976 | docs, but it looks weird. For now the profiling code will |
|
941 | 977 | continue to use the standard profiler. |
|
942 | 978 | |
|
943 | 979 | 2004-08-23 Fernando Perez <fperez@colorado.edu> |
|
944 | 980 | |
|
945 | 981 | * IPython/Shell.py (IPShellWX.__init__): Improvements to the WX |
|
946 | 982 | threaded shell, by John Hunter. It's not quite ready yet, but |
|
947 | 983 | close. |
|
948 | 984 | |
|
949 | 985 | 2004-08-22 Fernando Perez <fperez@colorado.edu> |
|
950 | 986 | |
|
951 | 987 | * IPython/iplib.py (InteractiveShell.interact): tab cleanups, also |
|
952 | 988 | in Magic and ultraTB. |
|
953 | 989 | |
|
954 | 990 | * ipython.1: document threading options in manpage. |
|
955 | 991 | |
|
956 | 992 | * scripts/ipython: Changed name of -thread option to -gthread, |
|
957 | 993 | since this is GTK specific. I want to leave the door open for a |
|
958 | 994 | -wthread option for WX, which will most likely be necessary. This |
|
959 | 995 | change affects usage and ipmaker as well. |
|
960 | 996 | |
|
961 | 997 | * IPython/Shell.py (matplotlib_shell): Add a factory function to |
|
962 | 998 | handle the matplotlib shell issues. Code by John Hunter |
|
963 | 999 | <jdhunter-AT-nitace.bsd.uchicago.edu>. |
|
964 | 1000 | (IPShellMatplotlibWX.__init__): Rudimentary WX support. It's |
|
965 | 1001 | broken (and disabled for end users) for now, but it puts the |
|
966 | 1002 | infrastructure in place. |
|
967 | 1003 | |
|
968 | 1004 | 2004-08-21 Fernando Perez <fperez@colorado.edu> |
|
969 | 1005 | |
|
970 | 1006 | * ipythonrc-pylab: Add matplotlib support. |
|
971 | 1007 | |
|
972 | 1008 | * matplotlib_config.py: new files for matplotlib support, part of |
|
973 | 1009 | the pylab profile. |
|
974 | 1010 | |
|
975 | 1011 | * IPython/usage.py (__doc__): documented the threading options. |
|
976 | 1012 | |
|
977 | 1013 | 2004-08-20 Fernando Perez <fperez@colorado.edu> |
|
978 | 1014 | |
|
979 | 1015 | * ipython: Modified the main calling routine to handle the -thread |
|
980 | 1016 | and -mpthread options. This needs to be done as a top-level hack, |
|
981 | 1017 | because it determines which class to instantiate for IPython |
|
982 | 1018 | itself. |
|
983 | 1019 | |
|
984 | 1020 | * IPython/Shell.py (MTInteractiveShell.__init__): New set of |
|
985 | 1021 | classes to support multithreaded GTK operation without blocking, |
|
986 | 1022 | and matplotlib with all backends. This is a lot of still very |
|
987 | 1023 | experimental code, and threads are tricky. So it may still have a |
|
988 | 1024 | few rough edges... This code owes a lot to |
|
989 | 1025 | http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65109, by |
|
990 | 1026 | Brian # McErlean and John Finlay, to Antoon Pardon for fixes, and |
|
991 | 1027 | to John Hunter for all the matplotlib work. |
|
992 | 1028 | |
|
993 | 1029 | * IPython/ipmaker.py (__call__): Added -thread and -mpthread |
|
994 | 1030 | options for gtk thread and matplotlib support. |
|
995 | 1031 | |
|
996 | 1032 | 2004-08-16 Fernando Perez <fperez@colorado.edu> |
|
997 | 1033 | |
|
998 | 1034 | * IPython/iplib.py (InteractiveShell.__init__): don't trigger |
|
999 | 1035 | autocall for things like p*q,p/q,p+q,p-q, when p is callable. Bug |
|
1000 | 1036 | reported by Stephen Walton <stephen.walton-AT-csun.edu>. |
|
1001 | 1037 | |
|
1002 | 1038 | 2004-08-11 Fernando Perez <fperez@colorado.edu> |
|
1003 | 1039 | |
|
1004 | 1040 | * setup.py (isfile): Fix build so documentation gets updated for |
|
1005 | 1041 | rpms (it was only done for .tgz builds). |
|
1006 | 1042 | |
|
1007 | 1043 | 2004-08-10 Fernando Perez <fperez@colorado.edu> |
|
1008 | 1044 | |
|
1009 | 1045 | * genutils.py (Term): Fix misspell of stdin stream (sin->cin). |
|
1010 | 1046 | |
|
1011 | 1047 | * iplib.py : Silence syntax error exceptions in tab-completion. |
|
1012 | 1048 | |
|
1013 | 1049 | 2004-08-05 Fernando Perez <fperez@colorado.edu> |
|
1014 | 1050 | |
|
1015 | 1051 | * IPython/Prompts.py (Prompt2.set_colors): Fix incorrectly set |
|
1016 | 1052 | 'color off' mark for continuation prompts. This was causing long |
|
1017 | 1053 | continuation lines to mis-wrap. |
|
1018 | 1054 | |
|
1019 | 1055 | 2004-08-01 Fernando Perez <fperez@colorado.edu> |
|
1020 | 1056 | |
|
1021 | 1057 | * IPython/ipmaker.py (make_IPython): Allow the shell class used |
|
1022 | 1058 | for building ipython to be a parameter. All this is necessary |
|
1023 | 1059 | right now to have a multithreaded version, but this insane |
|
1024 | 1060 | non-design will be cleaned up soon. For now, it's a hack that |
|
1025 | 1061 | works. |
|
1026 | 1062 | |
|
1027 | 1063 | * IPython/Shell.py (IPShell.__init__): Stop using mutable default |
|
1028 | 1064 | args in various places. No bugs so far, but it's a dangerous |
|
1029 | 1065 | practice. |
|
1030 | 1066 | |
|
1031 | 1067 | 2004-07-31 Fernando Perez <fperez@colorado.edu> |
|
1032 | 1068 | |
|
1033 | 1069 | * IPython/iplib.py (complete): ignore SyntaxError exceptions to |
|
1034 | 1070 | fix completion of files with dots in their names under most |
|
1035 | 1071 | profiles (pysh was OK because the completion order is different). |
|
1036 | 1072 | |
|
1037 | 1073 | 2004-07-27 Fernando Perez <fperez@colorado.edu> |
|
1038 | 1074 | |
|
1039 | 1075 | * IPython/iplib.py (InteractiveShell.__init__): build dict of |
|
1040 | 1076 | keywords manually, b/c the one in keyword.py was removed in python |
|
1041 | 1077 | 2.4. Patch by Anakim Border <aborder-AT-users.sourceforge.net>. |
|
1042 | 1078 | This is NOT a bug under python 2.3 and earlier. |
|
1043 | 1079 | |
|
1044 | 1080 | 2004-07-26 Fernando Perez <fperez@colorado.edu> |
|
1045 | 1081 | |
|
1046 | 1082 | * IPython/ultraTB.py (VerboseTB.text): Add another |
|
1047 | 1083 | linecache.checkcache() call to try to prevent inspect.py from |
|
1048 | 1084 | crashing under python 2.3. I think this fixes |
|
1049 | 1085 | http://www.scipy.net/roundup/ipython/issue17. |
|
1050 | 1086 | |
|
1051 | 1087 | 2004-07-26 *** Released version 0.6.2 |
|
1052 | 1088 | |
|
1053 | 1089 | 2004-07-26 Fernando Perez <fperez@colorado.edu> |
|
1054 | 1090 | |
|
1055 | 1091 | * IPython/Magic.py (Magic.magic_cd): Fix bug where 'cd -N' would |
|
1056 | 1092 | fail for any number. |
|
1057 | 1093 | (Magic.magic_bookmark): Fix bug where 'bookmark -l' would fail for |
|
1058 | 1094 | empty bookmarks. |
|
1059 | 1095 | |
|
1060 | 1096 | 2004-07-26 *** Released version 0.6.1 |
|
1061 | 1097 | |
|
1062 | 1098 | 2004-07-26 Fernando Perez <fperez@colorado.edu> |
|
1063 | 1099 | |
|
1064 | 1100 | * ipython_win_post_install.py (run): Added pysh shortcut for Windows. |
|
1065 | 1101 | |
|
1066 | 1102 | * IPython/iplib.py (protect_filename): Applied Ville's patch for |
|
1067 | 1103 | escaping '()[]{}' in filenames. |
|
1068 | 1104 | |
|
1069 | 1105 | * IPython/Magic.py (shlex_split): Fix handling of '*' and '?' for |
|
1070 | 1106 | Python 2.2 users who lack a proper shlex.split. |
|
1071 | 1107 | |
|
1072 | 1108 | 2004-07-19 Fernando Perez <fperez@colorado.edu> |
|
1073 | 1109 | |
|
1074 | 1110 | * IPython/iplib.py (InteractiveShell.init_readline): Add support |
|
1075 | 1111 | for reading readline's init file. I follow the normal chain: |
|
1076 | 1112 | $INPUTRC is honored, otherwise ~/.inputrc is used. Thanks to a |
|
1077 | 1113 | report by Mike Heeter. This closes |
|
1078 | 1114 | http://www.scipy.net/roundup/ipython/issue16. |
|
1079 | 1115 | |
|
1080 | 1116 | 2004-07-18 Fernando Perez <fperez@colorado.edu> |
|
1081 | 1117 | |
|
1082 | 1118 | * IPython/iplib.py (__init__): Add better handling of '\' under |
|
1083 | 1119 | Win32 for filenames. After a patch by Ville. |
|
1084 | 1120 | |
|
1085 | 1121 | 2004-07-17 Fernando Perez <fperez@colorado.edu> |
|
1086 | 1122 | |
|
1087 | 1123 | * IPython/iplib.py (InteractiveShell._prefilter): fix bug where |
|
1088 | 1124 | autocalling would be triggered for 'foo is bar' if foo is |
|
1089 | 1125 | callable. I also cleaned up the autocall detection code to use a |
|
1090 | 1126 | regexp, which is faster. Bug reported by Alexander Schmolck. |
|
1091 | 1127 | |
|
1092 | 1128 | * IPython/Magic.py (Magic.magic_pinfo): Fix bug where strings with |
|
1093 | 1129 | '?' in them would confuse the help system. Reported by Alex |
|
1094 | 1130 | Schmolck. |
|
1095 | 1131 | |
|
1096 | 1132 | 2004-07-16 Fernando Perez <fperez@colorado.edu> |
|
1097 | 1133 | |
|
1098 | 1134 | * IPython/GnuplotInteractive.py (__all__): added plot2. |
|
1099 | 1135 | |
|
1100 | 1136 | * IPython/Gnuplot2.py (Gnuplot.plot2): added new function for |
|
1101 | 1137 | plotting dictionaries, lists or tuples of 1d arrays. |
|
1102 | 1138 | |
|
1103 | 1139 | * IPython/Magic.py (Magic.magic_hist): small clenaups and |
|
1104 | 1140 | optimizations. |
|
1105 | 1141 | |
|
1106 | 1142 | * IPython/iplib.py:Remove old Changelog info for cleanup. This is |
|
1107 | 1143 | the information which was there from Janko's original IPP code: |
|
1108 | 1144 | |
|
1109 | 1145 | 03.05.99 20:53 porto.ifm.uni-kiel.de |
|
1110 | 1146 | --Started changelog. |
|
1111 | 1147 | --make clear do what it say it does |
|
1112 | 1148 | --added pretty output of lines from inputcache |
|
1113 | 1149 | --Made Logger a mixin class, simplifies handling of switches |
|
1114 | 1150 | --Added own completer class. .string<TAB> expands to last history |
|
1115 | 1151 | line which starts with string. The new expansion is also present |
|
1116 | 1152 | with Ctrl-r from the readline library. But this shows, who this |
|
1117 | 1153 | can be done for other cases. |
|
1118 | 1154 | --Added convention that all shell functions should accept a |
|
1119 | 1155 | parameter_string This opens the door for different behaviour for |
|
1120 | 1156 | each function. @cd is a good example of this. |
|
1121 | 1157 | |
|
1122 | 1158 | 04.05.99 12:12 porto.ifm.uni-kiel.de |
|
1123 | 1159 | --added logfile rotation |
|
1124 | 1160 | --added new mainloop method which freezes first the namespace |
|
1125 | 1161 | |
|
1126 | 1162 | 07.05.99 21:24 porto.ifm.uni-kiel.de |
|
1127 | 1163 | --added the docreader classes. Now there is a help system. |
|
1128 | 1164 | -This is only a first try. Currently it's not easy to put new |
|
1129 | 1165 | stuff in the indices. But this is the way to go. Info would be |
|
1130 | 1166 | better, but HTML is every where and not everybody has an info |
|
1131 | 1167 | system installed and it's not so easy to change html-docs to info. |
|
1132 | 1168 | --added global logfile option |
|
1133 | 1169 | --there is now a hook for object inspection method pinfo needs to |
|
1134 | 1170 | be provided for this. Can be reached by two '??'. |
|
1135 | 1171 | |
|
1136 | 1172 | 08.05.99 20:51 porto.ifm.uni-kiel.de |
|
1137 | 1173 | --added a README |
|
1138 | 1174 | --bug in rc file. Something has changed so functions in the rc |
|
1139 | 1175 | file need to reference the shell and not self. Not clear if it's a |
|
1140 | 1176 | bug or feature. |
|
1141 | 1177 | --changed rc file for new behavior |
|
1142 | 1178 | |
|
1143 | 1179 | 2004-07-15 Fernando Perez <fperez@colorado.edu> |
|
1144 | 1180 | |
|
1145 | 1181 | * IPython/Logger.py (Logger.log): fixed recent bug where the input |
|
1146 | 1182 | cache was falling out of sync in bizarre manners when multi-line |
|
1147 | 1183 | input was present. Minor optimizations and cleanup. |
|
1148 | 1184 | |
|
1149 | 1185 | (Logger): Remove old Changelog info for cleanup. This is the |
|
1150 | 1186 | information which was there from Janko's original code: |
|
1151 | 1187 | |
|
1152 | 1188 | Changes to Logger: - made the default log filename a parameter |
|
1153 | 1189 | |
|
1154 | 1190 | - put a check for lines beginning with !@? in log(). Needed |
|
1155 | 1191 | (even if the handlers properly log their lines) for mid-session |
|
1156 | 1192 | logging activation to work properly. Without this, lines logged |
|
1157 | 1193 | in mid session, which get read from the cache, would end up |
|
1158 | 1194 | 'bare' (with !@? in the open) in the log. Now they are caught |
|
1159 | 1195 | and prepended with a #. |
|
1160 | 1196 | |
|
1161 | 1197 | * IPython/iplib.py (InteractiveShell.init_readline): added check |
|
1162 | 1198 | in case MagicCompleter fails to be defined, so we don't crash. |
|
1163 | 1199 | |
|
1164 | 1200 | 2004-07-13 Fernando Perez <fperez@colorado.edu> |
|
1165 | 1201 | |
|
1166 | 1202 | * IPython/Gnuplot2.py (Gnuplot.hardcopy): add automatic generation |
|
1167 | 1203 | of EPS if the requested filename ends in '.eps'. |
|
1168 | 1204 | |
|
1169 | 1205 | 2004-07-04 Fernando Perez <fperez@colorado.edu> |
|
1170 | 1206 | |
|
1171 | 1207 | * IPython/iplib.py (InteractiveShell.handle_shell_escape): Fix |
|
1172 | 1208 | escaping of quotes when calling the shell. |
|
1173 | 1209 | |
|
1174 | 1210 | 2004-07-02 Fernando Perez <fperez@colorado.edu> |
|
1175 | 1211 | |
|
1176 | 1212 | * IPython/Prompts.py (CachedOutput.update): Fix problem with |
|
1177 | 1213 | gettext not working because we were clobbering '_'. Fixes |
|
1178 | 1214 | http://www.scipy.net/roundup/ipython/issue6. |
|
1179 | 1215 | |
|
1180 | 1216 | 2004-07-01 Fernando Perez <fperez@colorado.edu> |
|
1181 | 1217 | |
|
1182 | 1218 | * IPython/Magic.py (Magic.magic_cd): integrated bookmark handling |
|
1183 | 1219 | into @cd. Patch by Ville. |
|
1184 | 1220 | |
|
1185 | 1221 | * IPython/iplib.py (InteractiveShell.post_config_initialization): |
|
1186 | 1222 | new function to store things after ipmaker runs. Patch by Ville. |
|
1187 | 1223 | Eventually this will go away once ipmaker is removed and the class |
|
1188 | 1224 | gets cleaned up, but for now it's ok. Key functionality here is |
|
1189 | 1225 | the addition of the persistent storage mechanism, a dict for |
|
1190 | 1226 | keeping data across sessions (for now just bookmarks, but more can |
|
1191 | 1227 | be implemented later). |
|
1192 | 1228 | |
|
1193 | 1229 | * IPython/Magic.py (Magic.magic_bookmark): New bookmark system, |
|
1194 | 1230 | persistent across sections. Patch by Ville, I modified it |
|
1195 | 1231 | soemwhat to allow bookmarking arbitrary dirs other than CWD. Also |
|
1196 | 1232 | added a '-l' option to list all bookmarks. |
|
1197 | 1233 | |
|
1198 | 1234 | * IPython/iplib.py (InteractiveShell.atexit_operations): new |
|
1199 | 1235 | center for cleanup. Registered with atexit.register(). I moved |
|
1200 | 1236 | here the old exit_cleanup(). After a patch by Ville. |
|
1201 | 1237 | |
|
1202 | 1238 | * IPython/Magic.py (get_py_filename): added '~' to the accepted |
|
1203 | 1239 | characters in the hacked shlex_split for python 2.2. |
|
1204 | 1240 | |
|
1205 | 1241 | * IPython/iplib.py (file_matches): more fixes to filenames with |
|
1206 | 1242 | whitespace in them. It's not perfect, but limitations in python's |
|
1207 | 1243 | readline make it impossible to go further. |
|
1208 | 1244 | |
|
1209 | 1245 | 2004-06-29 Fernando Perez <fperez@colorado.edu> |
|
1210 | 1246 | |
|
1211 | 1247 | * IPython/iplib.py (file_matches): escape whitespace correctly in |
|
1212 | 1248 | filename completions. Bug reported by Ville. |
|
1213 | 1249 | |
|
1214 | 1250 | 2004-06-28 Fernando Perez <fperez@colorado.edu> |
|
1215 | 1251 | |
|
1216 | 1252 | * IPython/ipmaker.py (__call__): Added per-profile histories. Now |
|
1217 | 1253 | the history file will be called 'history-PROFNAME' (or just |
|
1218 | 1254 | 'history' if no profile is loaded). I was getting annoyed at |
|
1219 | 1255 | getting my Numerical work history clobbered by pysh sessions. |
|
1220 | 1256 | |
|
1221 | 1257 | * IPython/iplib.py (InteractiveShell.__init__): Internal |
|
1222 | 1258 | getoutputerror() function so that we can honor the system_verbose |
|
1223 | 1259 | flag for _all_ system calls. I also added escaping of # |
|
1224 | 1260 | characters here to avoid confusing Itpl. |
|
1225 | 1261 | |
|
1226 | 1262 | * IPython/Magic.py (shlex_split): removed call to shell in |
|
1227 | 1263 | parse_options and replaced it with shlex.split(). The annoying |
|
1228 | 1264 | part was that in Python 2.2, shlex.split() doesn't exist, so I had |
|
1229 | 1265 | to backport it from 2.3, with several frail hacks (the shlex |
|
1230 | 1266 | module is rather limited in 2.2). Thanks to a suggestion by Ville |
|
1231 | 1267 | Vainio <vivainio@kolumbus.fi>. For Python 2.3 there should be no |
|
1232 | 1268 | problem. |
|
1233 | 1269 | |
|
1234 | 1270 | (Magic.magic_system_verbose): new toggle to print the actual |
|
1235 | 1271 | system calls made by ipython. Mainly for debugging purposes. |
|
1236 | 1272 | |
|
1237 | 1273 | * IPython/GnuplotRuntime.py (gnu_out): fix bug for cygwin, which |
|
1238 | 1274 | doesn't support persistence. Reported (and fix suggested) by |
|
1239 | 1275 | Travis Caldwell <travis_caldwell2000@yahoo.com>. |
|
1240 | 1276 | |
|
1241 | 1277 | 2004-06-26 Fernando Perez <fperez@colorado.edu> |
|
1242 | 1278 | |
|
1243 | 1279 | * IPython/Logger.py (Logger.log): fix to handle correctly empty |
|
1244 | 1280 | continue prompts. |
|
1245 | 1281 | |
|
1246 | 1282 | * IPython/Extensions/InterpreterExec.py (pysh): moved the pysh() |
|
1247 | 1283 | function (basically a big docstring) and a few more things here to |
|
1248 | 1284 | speedup startup. pysh.py is now very lightweight. We want because |
|
1249 | 1285 | it gets execfile'd, while InterpreterExec gets imported, so |
|
1250 | 1286 | byte-compilation saves time. |
|
1251 | 1287 | |
|
1252 | 1288 | 2004-06-25 Fernando Perez <fperez@colorado.edu> |
|
1253 | 1289 | |
|
1254 | 1290 | * IPython/Magic.py (Magic.magic_cd): Fixed to restore usage of 'cd |
|
1255 | 1291 | -NUM', which was recently broken. |
|
1256 | 1292 | |
|
1257 | 1293 | * IPython/iplib.py (InteractiveShell.handle_shell_escape): allow ! |
|
1258 | 1294 | in multi-line input (but not !!, which doesn't make sense there). |
|
1259 | 1295 | |
|
1260 | 1296 | * IPython/UserConfig/ipythonrc: made autoindent on by default. |
|
1261 | 1297 | It's just too useful, and people can turn it off in the less |
|
1262 | 1298 | common cases where it's a problem. |
|
1263 | 1299 | |
|
1264 | 1300 | 2004-06-24 Fernando Perez <fperez@colorado.edu> |
|
1265 | 1301 | |
|
1266 | 1302 | * IPython/iplib.py (InteractiveShell._prefilter): big change - |
|
1267 | 1303 | special syntaxes (like alias calling) is now allied in multi-line |
|
1268 | 1304 | input. This is still _very_ experimental, but it's necessary for |
|
1269 | 1305 | efficient shell usage combining python looping syntax with system |
|
1270 | 1306 | calls. For now it's restricted to aliases, I don't think it |
|
1271 | 1307 | really even makes sense to have this for magics. |
|
1272 | 1308 | |
|
1273 | 1309 | 2004-06-23 Fernando Perez <fperez@colorado.edu> |
|
1274 | 1310 | |
|
1275 | 1311 | * IPython/Extensions/InterpreterExec.py (prefilter_shell): Added |
|
1276 | 1312 | $var=cmd <=> @sc var=cmd and $$var=cmd <=> @sc -l var=cmd. |
|
1277 | 1313 | |
|
1278 | 1314 | * IPython/Magic.py (Magic.magic_rehashx): modified to handle |
|
1279 | 1315 | extensions under Windows (after code sent by Gary Bishop). The |
|
1280 | 1316 | extensions considered 'executable' are stored in IPython's rc |
|
1281 | 1317 | structure as win_exec_ext. |
|
1282 | 1318 | |
|
1283 | 1319 | * IPython/genutils.py (shell): new function, like system() but |
|
1284 | 1320 | without return value. Very useful for interactive shell work. |
|
1285 | 1321 | |
|
1286 | 1322 | * IPython/Magic.py (Magic.magic_unalias): New @unalias function to |
|
1287 | 1323 | delete aliases. |
|
1288 | 1324 | |
|
1289 | 1325 | * IPython/iplib.py (InteractiveShell.alias_table_update): make |
|
1290 | 1326 | sure that the alias table doesn't contain python keywords. |
|
1291 | 1327 | |
|
1292 | 1328 | 2004-06-21 Fernando Perez <fperez@colorado.edu> |
|
1293 | 1329 | |
|
1294 | 1330 | * IPython/Magic.py (Magic.magic_rehash): Fix crash when |
|
1295 | 1331 | non-existent items are found in $PATH. Reported by Thorsten. |
|
1296 | 1332 | |
|
1297 | 1333 | 2004-06-20 Fernando Perez <fperez@colorado.edu> |
|
1298 | 1334 | |
|
1299 | 1335 | * IPython/iplib.py (complete): modified the completer so that the |
|
1300 | 1336 | order of priorities can be easily changed at runtime. |
|
1301 | 1337 | |
|
1302 | 1338 | * IPython/Extensions/InterpreterExec.py (prefilter_shell): |
|
1303 | 1339 | Modified to auto-execute all lines beginning with '~', '/' or '.'. |
|
1304 | 1340 | |
|
1305 | 1341 | * IPython/Magic.py (Magic.magic_sx): modified @sc and @sx to |
|
1306 | 1342 | expand Python variables prepended with $ in all system calls. The |
|
1307 | 1343 | same was done to InteractiveShell.handle_shell_escape. Now all |
|
1308 | 1344 | system access mechanisms (!, !!, @sc, @sx and aliases) allow the |
|
1309 | 1345 | expansion of python variables and expressions according to the |
|
1310 | 1346 | syntax of PEP-215 - http://www.python.org/peps/pep-0215.html. |
|
1311 | 1347 | |
|
1312 | 1348 | Though PEP-215 has been rejected, a similar (but simpler) one |
|
1313 | 1349 | seems like it will go into Python 2.4, PEP-292 - |
|
1314 | 1350 | http://www.python.org/peps/pep-0292.html. |
|
1315 | 1351 | |
|
1316 | 1352 | I'll keep the full syntax of PEP-215, since IPython has since the |
|
1317 | 1353 | start used Ka-Ping Yee's reference implementation discussed there |
|
1318 | 1354 | (Itpl), and I actually like the powerful semantics it offers. |
|
1319 | 1355 | |
|
1320 | 1356 | In order to access normal shell variables, the $ has to be escaped |
|
1321 | 1357 | via an extra $. For example: |
|
1322 | 1358 | |
|
1323 | 1359 | In [7]: PATH='a python variable' |
|
1324 | 1360 | |
|
1325 | 1361 | In [8]: !echo $PATH |
|
1326 | 1362 | a python variable |
|
1327 | 1363 | |
|
1328 | 1364 | In [9]: !echo $$PATH |
|
1329 | 1365 | /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:... |
|
1330 | 1366 | |
|
1331 | 1367 | (Magic.parse_options): escape $ so the shell doesn't evaluate |
|
1332 | 1368 | things prematurely. |
|
1333 | 1369 | |
|
1334 | 1370 | * IPython/iplib.py (InteractiveShell.call_alias): added the |
|
1335 | 1371 | ability for aliases to expand python variables via $. |
|
1336 | 1372 | |
|
1337 | 1373 | * IPython/Magic.py (Magic.magic_rehash): based on the new alias |
|
1338 | 1374 | system, now there's a @rehash/@rehashx pair of magics. These work |
|
1339 | 1375 | like the csh rehash command, and can be invoked at any time. They |
|
1340 | 1376 | build a table of aliases to everything in the user's $PATH |
|
1341 | 1377 | (@rehash uses everything, @rehashx is slower but only adds |
|
1342 | 1378 | executable files). With this, the pysh.py-based shell profile can |
|
1343 | 1379 | now simply call rehash upon startup, and full access to all |
|
1344 | 1380 | programs in the user's path is obtained. |
|
1345 | 1381 | |
|
1346 | 1382 | * IPython/iplib.py (InteractiveShell.call_alias): The new alias |
|
1347 | 1383 | functionality is now fully in place. I removed the old dynamic |
|
1348 | 1384 | code generation based approach, in favor of a much lighter one |
|
1349 | 1385 | based on a simple dict. The advantage is that this allows me to |
|
1350 | 1386 | now have thousands of aliases with negligible cost (unthinkable |
|
1351 | 1387 | with the old system). |
|
1352 | 1388 | |
|
1353 | 1389 | 2004-06-19 Fernando Perez <fperez@colorado.edu> |
|
1354 | 1390 | |
|
1355 | 1391 | * IPython/iplib.py (__init__): extended MagicCompleter class to |
|
1356 | 1392 | also complete (last in priority) on user aliases. |
|
1357 | 1393 | |
|
1358 | 1394 | * IPython/Itpl.py (Itpl.__str__): fixed order of globals/locals in |
|
1359 | 1395 | call to eval. |
|
1360 | 1396 | (ItplNS.__init__): Added a new class which functions like Itpl, |
|
1361 | 1397 | but allows configuring the namespace for the evaluation to occur |
|
1362 | 1398 | in. |
|
1363 | 1399 | |
|
1364 | 1400 | 2004-06-18 Fernando Perez <fperez@colorado.edu> |
|
1365 | 1401 | |
|
1366 | 1402 | * IPython/iplib.py (InteractiveShell.runcode): modify to print a |
|
1367 | 1403 | better message when 'exit' or 'quit' are typed (a common newbie |
|
1368 | 1404 | confusion). |
|
1369 | 1405 | |
|
1370 | 1406 | * IPython/Magic.py (Magic.magic_colors): Added the runtime color |
|
1371 | 1407 | check for Windows users. |
|
1372 | 1408 | |
|
1373 | 1409 | * IPython/iplib.py (InteractiveShell.user_setup): removed |
|
1374 | 1410 | disabling of colors for Windows. I'll test at runtime and issue a |
|
1375 | 1411 | warning if Gary's readline isn't found, as to nudge users to |
|
1376 | 1412 | download it. |
|
1377 | 1413 | |
|
1378 | 1414 | 2004-06-16 Fernando Perez <fperez@colorado.edu> |
|
1379 | 1415 | |
|
1380 | 1416 | * IPython/genutils.py (Stream.__init__): changed to print errors |
|
1381 | 1417 | to sys.stderr. I had a circular dependency here. Now it's |
|
1382 | 1418 | possible to run ipython as IDLE's shell (consider this pre-alpha, |
|
1383 | 1419 | since true stdout things end up in the starting terminal instead |
|
1384 | 1420 | of IDLE's out). |
|
1385 | 1421 | |
|
1386 | 1422 | * IPython/Prompts.py (Prompt2.set_colors): prevent crashes for |
|
1387 | 1423 | users who haven't # updated their prompt_in2 definitions. Remove |
|
1388 | 1424 | eventually. |
|
1389 | 1425 | (multiple_replace): added credit to original ASPN recipe. |
|
1390 | 1426 | |
|
1391 | 1427 | 2004-06-15 Fernando Perez <fperez@colorado.edu> |
|
1392 | 1428 | |
|
1393 | 1429 | * IPython/iplib.py (InteractiveShell.__init__): add 'cp' to the |
|
1394 | 1430 | list of auto-defined aliases. |
|
1395 | 1431 | |
|
1396 | 1432 | 2004-06-13 Fernando Perez <fperez@colorado.edu> |
|
1397 | 1433 | |
|
1398 | 1434 | * setup.py (scriptfiles): Don't trigger win_post_install unless an |
|
1399 | 1435 | install was really requested (so setup.py can be used for other |
|
1400 | 1436 | things under Windows). |
|
1401 | 1437 | |
|
1402 | 1438 | 2004-06-10 Fernando Perez <fperez@colorado.edu> |
|
1403 | 1439 | |
|
1404 | 1440 | * IPython/Logger.py (Logger.create_log): Manually remove any old |
|
1405 | 1441 | backup, since os.remove may fail under Windows. Fixes bug |
|
1406 | 1442 | reported by Thorsten. |
|
1407 | 1443 | |
|
1408 | 1444 | 2004-06-09 Fernando Perez <fperez@colorado.edu> |
|
1409 | 1445 | |
|
1410 | 1446 | * examples/example-embed.py: fixed all references to %n (replaced |
|
1411 | 1447 | with \\# for ps1/out prompts and with \\D for ps2 prompts). Done |
|
1412 | 1448 | for all examples and the manual as well. |
|
1413 | 1449 | |
|
1414 | 1450 | 2004-06-08 Fernando Perez <fperez@colorado.edu> |
|
1415 | 1451 | |
|
1416 | 1452 | * IPython/Prompts.py (Prompt2.set_p_str): fixed all prompt |
|
1417 | 1453 | alignment and color management. All 3 prompt subsystems now |
|
1418 | 1454 | inherit from BasePrompt. |
|
1419 | 1455 | |
|
1420 | 1456 | * tools/release: updates for windows installer build and tag rpms |
|
1421 | 1457 | with python version (since paths are fixed). |
|
1422 | 1458 | |
|
1423 | 1459 | * IPython/UserConfig/ipythonrc: modified to use \# instead of %n, |
|
1424 | 1460 | which will become eventually obsolete. Also fixed the default |
|
1425 | 1461 | prompt_in2 to use \D, so at least new users start with the correct |
|
1426 | 1462 | defaults. |
|
1427 | 1463 | WARNING: Users with existing ipythonrc files will need to apply |
|
1428 | 1464 | this fix manually! |
|
1429 | 1465 | |
|
1430 | 1466 | * setup.py: make windows installer (.exe). This is finally the |
|
1431 | 1467 | integration of an old patch by Cory Dodt <dodt-AT-fcoe.k12.ca.us>, |
|
1432 | 1468 | which I hadn't included because it required Python 2.3 (or recent |
|
1433 | 1469 | distutils). |
|
1434 | 1470 | |
|
1435 | 1471 | * IPython/usage.py (__doc__): update docs (and manpage) to reflect |
|
1436 | 1472 | usage of new '\D' escape. |
|
1437 | 1473 | |
|
1438 | 1474 | * IPython/Prompts.py (ROOT_SYMBOL): Small fix for Windows (which |
|
1439 | 1475 | lacks os.getuid()) |
|
1440 | 1476 | (CachedOutput.set_colors): Added the ability to turn coloring |
|
1441 | 1477 | on/off with @colors even for manually defined prompt colors. It |
|
1442 | 1478 | uses a nasty global, but it works safely and via the generic color |
|
1443 | 1479 | handling mechanism. |
|
1444 | 1480 | (Prompt2.__init__): Introduced new escape '\D' for continuation |
|
1445 | 1481 | prompts. It represents the counter ('\#') as dots. |
|
1446 | 1482 | *** NOTE *** THIS IS A BACKWARDS-INCOMPATIBLE CHANGE. Users will |
|
1447 | 1483 | need to update their ipythonrc files and replace '%n' with '\D' in |
|
1448 | 1484 | their prompt_in2 settings everywhere. Sorry, but there's |
|
1449 | 1485 | otherwise no clean way to get all prompts to properly align. The |
|
1450 | 1486 | ipythonrc shipped with IPython has been updated. |
|
1451 | 1487 | |
|
1452 | 1488 | 2004-06-07 Fernando Perez <fperez@colorado.edu> |
|
1453 | 1489 | |
|
1454 | 1490 | * setup.py (isfile): Pass local_icons option to latex2html, so the |
|
1455 | 1491 | resulting HTML file is self-contained. Thanks to |
|
1456 | 1492 | dryice-AT-liu.com.cn for the tip. |
|
1457 | 1493 | |
|
1458 | 1494 | * pysh.py: I created a new profile 'shell', which implements a |
|
1459 | 1495 | _rudimentary_ IPython-based shell. This is in NO WAY a realy |
|
1460 | 1496 | system shell, nor will it become one anytime soon. It's mainly |
|
1461 | 1497 | meant to illustrate the use of the new flexible bash-like prompts. |
|
1462 | 1498 | I guess it could be used by hardy souls for true shell management, |
|
1463 | 1499 | but it's no tcsh/bash... pysh.py is loaded by the 'shell' |
|
1464 | 1500 | profile. This uses the InterpreterExec extension provided by |
|
1465 | 1501 | W.J. van der Laan <gnufnork-AT-hetdigitalegat.nl> |
|
1466 | 1502 | |
|
1467 | 1503 | * IPython/Prompts.py (PromptOut.__str__): now it will correctly |
|
1468 | 1504 | auto-align itself with the length of the previous input prompt |
|
1469 | 1505 | (taking into account the invisible color escapes). |
|
1470 | 1506 | (CachedOutput.__init__): Large restructuring of this class. Now |
|
1471 | 1507 | all three prompts (primary1, primary2, output) are proper objects, |
|
1472 | 1508 | managed by the 'parent' CachedOutput class. The code is still a |
|
1473 | 1509 | bit hackish (all prompts share state via a pointer to the cache), |
|
1474 | 1510 | but it's overall far cleaner than before. |
|
1475 | 1511 | |
|
1476 | 1512 | * IPython/genutils.py (getoutputerror): modified to add verbose, |
|
1477 | 1513 | debug and header options. This makes the interface of all getout* |
|
1478 | 1514 | functions uniform. |
|
1479 | 1515 | (SystemExec.getoutputerror): added getoutputerror to SystemExec. |
|
1480 | 1516 | |
|
1481 | 1517 | * IPython/Magic.py (Magic.default_option): added a function to |
|
1482 | 1518 | allow registering default options for any magic command. This |
|
1483 | 1519 | makes it easy to have profiles which customize the magics globally |
|
1484 | 1520 | for a certain use. The values set through this function are |
|
1485 | 1521 | picked up by the parse_options() method, which all magics should |
|
1486 | 1522 | use to parse their options. |
|
1487 | 1523 | |
|
1488 | 1524 | * IPython/genutils.py (warn): modified the warnings framework to |
|
1489 | 1525 | use the Term I/O class. I'm trying to slowly unify all of |
|
1490 | 1526 | IPython's I/O operations to pass through Term. |
|
1491 | 1527 | |
|
1492 | 1528 | * IPython/Prompts.py (Prompt2._str_other): Added functionality in |
|
1493 | 1529 | the secondary prompt to correctly match the length of the primary |
|
1494 | 1530 | one for any prompt. Now multi-line code will properly line up |
|
1495 | 1531 | even for path dependent prompts, such as the new ones available |
|
1496 | 1532 | via the prompt_specials. |
|
1497 | 1533 | |
|
1498 | 1534 | 2004-06-06 Fernando Perez <fperez@colorado.edu> |
|
1499 | 1535 | |
|
1500 | 1536 | * IPython/Prompts.py (prompt_specials): Added the ability to have |
|
1501 | 1537 | bash-like special sequences in the prompts, which get |
|
1502 | 1538 | automatically expanded. Things like hostname, current working |
|
1503 | 1539 | directory and username are implemented already, but it's easy to |
|
1504 | 1540 | add more in the future. Thanks to a patch by W.J. van der Laan |
|
1505 | 1541 | <gnufnork-AT-hetdigitalegat.nl> |
|
1506 | 1542 | (prompt_specials): Added color support for prompt strings, so |
|
1507 | 1543 | users can define arbitrary color setups for their prompts. |
|
1508 | 1544 | |
|
1509 | 1545 | 2004-06-05 Fernando Perez <fperez@colorado.edu> |
|
1510 | 1546 | |
|
1511 | 1547 | * IPython/genutils.py (Term.reopen_all): Added Windows-specific |
|
1512 | 1548 | code to load Gary Bishop's readline and configure it |
|
1513 | 1549 | automatically. Thanks to Gary for help on this. |
|
1514 | 1550 | |
|
1515 | 1551 | 2004-06-01 Fernando Perez <fperez@colorado.edu> |
|
1516 | 1552 | |
|
1517 | 1553 | * IPython/Logger.py (Logger.create_log): fix bug for logging |
|
1518 | 1554 | with no filename (previous fix was incomplete). |
|
1519 | 1555 | |
|
1520 | 1556 | 2004-05-25 Fernando Perez <fperez@colorado.edu> |
|
1521 | 1557 | |
|
1522 | 1558 | * IPython/Magic.py (Magic.parse_options): fix bug where naked |
|
1523 | 1559 | parens would get passed to the shell. |
|
1524 | 1560 | |
|
1525 | 1561 | 2004-05-20 Fernando Perez <fperez@colorado.edu> |
|
1526 | 1562 | |
|
1527 | 1563 | * IPython/Magic.py (Magic.magic_prun): changed default profile |
|
1528 | 1564 | sort order to 'time' (the more common profiling need). |
|
1529 | 1565 | |
|
1530 | 1566 | * IPython/OInspect.py (Inspector.pinfo): flush the inspect cache |
|
1531 | 1567 | so that source code shown is guaranteed in sync with the file on |
|
1532 | 1568 | disk (also changed in psource). Similar fix to the one for |
|
1533 | 1569 | ultraTB on 2004-05-06. Thanks to a bug report by Yann Le Du |
|
1534 | 1570 | <yann.ledu-AT-noos.fr>. |
|
1535 | 1571 | |
|
1536 | 1572 | * IPython/Magic.py (Magic.parse_options): Fixed bug where commands |
|
1537 | 1573 | with a single option would not be correctly parsed. Closes |
|
1538 | 1574 | http://www.scipy.net/roundup/ipython/issue14. This bug had been |
|
1539 | 1575 | introduced in 0.6.0 (on 2004-05-06). |
|
1540 | 1576 | |
|
1541 | 1577 | 2004-05-13 *** Released version 0.6.0 |
|
1542 | 1578 | |
|
1543 | 1579 | 2004-05-13 Fernando Perez <fperez@colorado.edu> |
|
1544 | 1580 | |
|
1545 | 1581 | * debian/: Added debian/ directory to CVS, so that debian support |
|
1546 | 1582 | is publicly accessible. The debian package is maintained by Jack |
|
1547 | 1583 | Moffit <jack-AT-xiph.org>. |
|
1548 | 1584 | |
|
1549 | 1585 | * Documentation: included the notes about an ipython-based system |
|
1550 | 1586 | shell (the hypothetical 'pysh') into the new_design.pdf document, |
|
1551 | 1587 | so that these ideas get distributed to users along with the |
|
1552 | 1588 | official documentation. |
|
1553 | 1589 | |
|
1554 | 1590 | 2004-05-10 Fernando Perez <fperez@colorado.edu> |
|
1555 | 1591 | |
|
1556 | 1592 | * IPython/Logger.py (Logger.create_log): fix recently introduced |
|
1557 | 1593 | bug (misindented line) where logstart would fail when not given an |
|
1558 | 1594 | explicit filename. |
|
1559 | 1595 | |
|
1560 | 1596 | 2004-05-09 Fernando Perez <fperez@colorado.edu> |
|
1561 | 1597 | |
|
1562 | 1598 | * IPython/Magic.py (Magic.parse_options): skip system call when |
|
1563 | 1599 | there are no options to look for. Faster, cleaner for the common |
|
1564 | 1600 | case. |
|
1565 | 1601 | |
|
1566 | 1602 | * Documentation: many updates to the manual: describing Windows |
|
1567 | 1603 | support better, Gnuplot updates, credits, misc small stuff. Also |
|
1568 | 1604 | updated the new_design doc a bit. |
|
1569 | 1605 | |
|
1570 | 1606 | 2004-05-06 *** Released version 0.6.0.rc1 |
|
1571 | 1607 | |
|
1572 | 1608 | 2004-05-06 Fernando Perez <fperez@colorado.edu> |
|
1573 | 1609 | |
|
1574 | 1610 | * IPython/ultraTB.py (ListTB.text): modified a ton of string += |
|
1575 | 1611 | operations to use the vastly more efficient list/''.join() method. |
|
1576 | 1612 | (FormattedTB.text): Fix |
|
1577 | 1613 | http://www.scipy.net/roundup/ipython/issue12 - exception source |
|
1578 | 1614 | extract not updated after reload. Thanks to Mike Salib |
|
1579 | 1615 | <msalib-AT-mit.edu> for pinning the source of the problem. |
|
1580 | 1616 | Fortunately, the solution works inside ipython and doesn't require |
|
1581 | 1617 | any changes to python proper. |
|
1582 | 1618 | |
|
1583 | 1619 | * IPython/Magic.py (Magic.parse_options): Improved to process the |
|
1584 | 1620 | argument list as a true shell would (by actually using the |
|
1585 | 1621 | underlying system shell). This way, all @magics automatically get |
|
1586 | 1622 | shell expansion for variables. Thanks to a comment by Alex |
|
1587 | 1623 | Schmolck. |
|
1588 | 1624 | |
|
1589 | 1625 | 2004-04-04 Fernando Perez <fperez@colorado.edu> |
|
1590 | 1626 | |
|
1591 | 1627 | * IPython/iplib.py (InteractiveShell.interact): Added a special |
|
1592 | 1628 | trap for a debugger quit exception, which is basically impossible |
|
1593 | 1629 | to handle by normal mechanisms, given what pdb does to the stack. |
|
1594 | 1630 | This fixes a crash reported by <fgibbons-AT-llama.med.harvard.edu>. |
|
1595 | 1631 | |
|
1596 | 1632 | 2004-04-03 Fernando Perez <fperez@colorado.edu> |
|
1597 | 1633 | |
|
1598 | 1634 | * IPython/genutils.py (Term): Standardized the names of the Term |
|
1599 | 1635 | class streams to cin/cout/cerr, following C++ naming conventions |
|
1600 | 1636 | (I can't use in/out/err because 'in' is not a valid attribute |
|
1601 | 1637 | name). |
|
1602 | 1638 | |
|
1603 | 1639 | * IPython/iplib.py (InteractiveShell.interact): don't increment |
|
1604 | 1640 | the prompt if there's no user input. By Daniel 'Dang' Griffith |
|
1605 | 1641 | <pythondev-dang-AT-lazytwinacres.net>, after a suggestion from |
|
1606 | 1642 | Francois Pinard. |
|
1607 | 1643 | |
|
1608 | 1644 | 2004-04-02 Fernando Perez <fperez@colorado.edu> |
|
1609 | 1645 | |
|
1610 | 1646 | * IPython/genutils.py (Stream.__init__): Modified to survive at |
|
1611 | 1647 | least importing in contexts where stdin/out/err aren't true file |
|
1612 | 1648 | objects, such as PyCrust (they lack fileno() and mode). However, |
|
1613 | 1649 | the recovery facilities which rely on these things existing will |
|
1614 | 1650 | not work. |
|
1615 | 1651 | |
|
1616 | 1652 | 2004-04-01 Fernando Perez <fperez@colorado.edu> |
|
1617 | 1653 | |
|
1618 | 1654 | * IPython/Magic.py (Magic.magic_sx): modified (as well as @sc) to |
|
1619 | 1655 | use the new getoutputerror() function, so it properly |
|
1620 | 1656 | distinguishes stdout/err. |
|
1621 | 1657 | |
|
1622 | 1658 | * IPython/genutils.py (getoutputerror): added a function to |
|
1623 | 1659 | capture separately the standard output and error of a command. |
|
1624 | 1660 | After a comment from dang on the mailing lists. This code is |
|
1625 | 1661 | basically a modified version of commands.getstatusoutput(), from |
|
1626 | 1662 | the standard library. |
|
1627 | 1663 | |
|
1628 | 1664 | * IPython/iplib.py (InteractiveShell.handle_shell_escape): added |
|
1629 | 1665 | '!!' as a special syntax (shorthand) to access @sx. |
|
1630 | 1666 | |
|
1631 | 1667 | * IPython/Magic.py (Magic.magic_sx): new magic, to execute a shell |
|
1632 | 1668 | command and return its output as a list split on '\n'. |
|
1633 | 1669 | |
|
1634 | 1670 | 2004-03-31 Fernando Perez <fperez@colorado.edu> |
|
1635 | 1671 | |
|
1636 | 1672 | * IPython/FakeModule.py (FakeModule.__init__): added __nonzero__ |
|
1637 | 1673 | method to dictionaries used as FakeModule instances if they lack |
|
1638 | 1674 | it. At least pydoc in python2.3 breaks for runtime-defined |
|
1639 | 1675 | functions without this hack. At some point I need to _really_ |
|
1640 | 1676 | understand what FakeModule is doing, because it's a gross hack. |
|
1641 | 1677 | But it solves Arnd's problem for now... |
|
1642 | 1678 | |
|
1643 | 1679 | 2004-02-27 Fernando Perez <fperez@colorado.edu> |
|
1644 | 1680 | |
|
1645 | 1681 | * IPython/Logger.py (Logger.create_log): Fix bug where 'rotate' |
|
1646 | 1682 | mode would behave erratically. Also increased the number of |
|
1647 | 1683 | possible logs in rotate mod to 999. Thanks to Rod Holland |
|
1648 | 1684 | <rhh@StructureLABS.com> for the report and fixes. |
|
1649 | 1685 | |
|
1650 | 1686 | 2004-02-26 Fernando Perez <fperez@colorado.edu> |
|
1651 | 1687 | |
|
1652 | 1688 | * IPython/genutils.py (page): Check that the curses module really |
|
1653 | 1689 | has the initscr attribute before trying to use it. For some |
|
1654 | 1690 | reason, the Solaris curses module is missing this. I think this |
|
1655 | 1691 | should be considered a Solaris python bug, but I'm not sure. |
|
1656 | 1692 | |
|
1657 | 1693 | 2004-01-17 Fernando Perez <fperez@colorado.edu> |
|
1658 | 1694 | |
|
1659 | 1695 | * IPython/genutils.py (Stream.__init__): Changes to try to make |
|
1660 | 1696 | ipython robust against stdin/out/err being closed by the user. |
|
1661 | 1697 | This is 'user error' (and blocks a normal python session, at least |
|
1662 | 1698 | the stdout case). However, Ipython should be able to survive such |
|
1663 | 1699 | instances of abuse as gracefully as possible. To simplify the |
|
1664 | 1700 | coding and maintain compatibility with Gary Bishop's Term |
|
1665 | 1701 | contributions, I've made use of classmethods for this. I think |
|
1666 | 1702 | this introduces a dependency on python 2.2. |
|
1667 | 1703 | |
|
1668 | 1704 | 2004-01-13 Fernando Perez <fperez@colorado.edu> |
|
1669 | 1705 | |
|
1670 | 1706 | * IPython/numutils.py (exp_safe): simplified the code a bit and |
|
1671 | 1707 | removed the need for importing the kinds module altogether. |
|
1672 | 1708 | |
|
1673 | 1709 | 2004-01-06 Fernando Perez <fperez@colorado.edu> |
|
1674 | 1710 | |
|
1675 | 1711 | * IPython/Magic.py (Magic.magic_sc): Made the shell capture system |
|
1676 | 1712 | a magic function instead, after some community feedback. No |
|
1677 | 1713 | special syntax will exist for it, but its name is deliberately |
|
1678 | 1714 | very short. |
|
1679 | 1715 | |
|
1680 | 1716 | 2003-12-20 Fernando Perez <fperez@colorado.edu> |
|
1681 | 1717 | |
|
1682 | 1718 | * IPython/iplib.py (InteractiveShell.handle_shell_assign): Added |
|
1683 | 1719 | new functionality, to automagically assign the result of a shell |
|
1684 | 1720 | command to a variable. I'll solicit some community feedback on |
|
1685 | 1721 | this before making it permanent. |
|
1686 | 1722 | |
|
1687 | 1723 | * IPython/OInspect.py (Inspector.pinfo): Fix crash when info was |
|
1688 | 1724 | requested about callables for which inspect couldn't obtain a |
|
1689 | 1725 | proper argspec. Thanks to a crash report sent by Etienne |
|
1690 | 1726 | Posthumus <etienne-AT-apple01.cs.vu.nl>. |
|
1691 | 1727 | |
|
1692 | 1728 | 2003-12-09 Fernando Perez <fperez@colorado.edu> |
|
1693 | 1729 | |
|
1694 | 1730 | * IPython/genutils.py (page): patch for the pager to work across |
|
1695 | 1731 | various versions of Windows. By Gary Bishop. |
|
1696 | 1732 | |
|
1697 | 1733 | 2003-12-04 Fernando Perez <fperez@colorado.edu> |
|
1698 | 1734 | |
|
1699 | 1735 | * IPython/Gnuplot2.py (PlotItems): Fixes for working with |
|
1700 | 1736 | Gnuplot.py version 1.7, whose internal names changed quite a bit. |
|
1701 | 1737 | While I tested this and it looks ok, there may still be corner |
|
1702 | 1738 | cases I've missed. |
|
1703 | 1739 | |
|
1704 | 1740 | 2003-12-01 Fernando Perez <fperez@colorado.edu> |
|
1705 | 1741 | |
|
1706 | 1742 | * IPython/iplib.py (InteractiveShell._prefilter): Fixed a bug |
|
1707 | 1743 | where a line like 'p,q=1,2' would fail because the automagic |
|
1708 | 1744 | system would be triggered for @p. |
|
1709 | 1745 | |
|
1710 | 1746 | * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): Tab-related |
|
1711 | 1747 | cleanups, code unmodified. |
|
1712 | 1748 | |
|
1713 | 1749 | * IPython/genutils.py (Term): added a class for IPython to handle |
|
1714 | 1750 | output. In most cases it will just be a proxy for stdout/err, but |
|
1715 | 1751 | having this allows modifications to be made for some platforms, |
|
1716 | 1752 | such as handling color escapes under Windows. All of this code |
|
1717 | 1753 | was contributed by Gary Bishop, with minor modifications by me. |
|
1718 | 1754 | The actual changes affect many files. |
|
1719 | 1755 | |
|
1720 | 1756 | 2003-11-30 Fernando Perez <fperez@colorado.edu> |
|
1721 | 1757 | |
|
1722 | 1758 | * IPython/iplib.py (file_matches): new completion code, courtesy |
|
1723 | 1759 | of Jeff Collins. This enables filename completion again under |
|
1724 | 1760 | python 2.3, which disabled it at the C level. |
|
1725 | 1761 | |
|
1726 | 1762 | 2003-11-11 Fernando Perez <fperez@colorado.edu> |
|
1727 | 1763 | |
|
1728 | 1764 | * IPython/numutils.py (amap): Added amap() fn. Simple shorthand |
|
1729 | 1765 | for Numeric.array(map(...)), but often convenient. |
|
1730 | 1766 | |
|
1731 | 1767 | 2003-11-05 Fernando Perez <fperez@colorado.edu> |
|
1732 | 1768 | |
|
1733 | 1769 | * IPython/numutils.py (frange): Changed a call from int() to |
|
1734 | 1770 | int(round()) to prevent a problem reported with arange() in the |
|
1735 | 1771 | numpy list. |
|
1736 | 1772 | |
|
1737 | 1773 | 2003-10-06 Fernando Perez <fperez@colorado.edu> |
|
1738 | 1774 | |
|
1739 | 1775 | * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): changed to |
|
1740 | 1776 | prevent crashes if sys lacks an argv attribute (it happens with |
|
1741 | 1777 | embedded interpreters which build a bare-bones sys module). |
|
1742 | 1778 | Thanks to a report/bugfix by Adam Hupp <hupp-AT-cs.wisc.edu>. |
|
1743 | 1779 | |
|
1744 | 1780 | 2003-09-24 Fernando Perez <fperez@colorado.edu> |
|
1745 | 1781 | |
|
1746 | 1782 | * IPython/Magic.py (Magic._ofind): blanket except around getattr() |
|
1747 | 1783 | to protect against poorly written user objects where __getattr__ |
|
1748 | 1784 | raises exceptions other than AttributeError. Thanks to a bug |
|
1749 | 1785 | report by Oliver Sander <osander-AT-gmx.de>. |
|
1750 | 1786 | |
|
1751 | 1787 | * IPython/FakeModule.py (FakeModule.__repr__): this method was |
|
1752 | 1788 | missing. Thanks to bug report by Ralf Schmitt <ralf-AT-brainbot.com>. |
|
1753 | 1789 | |
|
1754 | 1790 | 2003-09-09 Fernando Perez <fperez@colorado.edu> |
|
1755 | 1791 | |
|
1756 | 1792 | * IPython/iplib.py (InteractiveShell._prefilter): fix bug where |
|
1757 | 1793 | unpacking a list whith a callable as first element would |
|
1758 | 1794 | mistakenly trigger autocalling. Thanks to a bug report by Jeffery |
|
1759 | 1795 | Collins. |
|
1760 | 1796 | |
|
1761 | 1797 | 2003-08-25 *** Released version 0.5.0 |
|
1762 | 1798 | |
|
1763 | 1799 | 2003-08-22 Fernando Perez <fperez@colorado.edu> |
|
1764 | 1800 | |
|
1765 | 1801 | * IPython/ultraTB.py (VerboseTB.linereader): Improved handling of |
|
1766 | 1802 | improperly defined user exceptions. Thanks to feedback from Mark |
|
1767 | 1803 | Russell <mrussell-AT-verio.net>. |
|
1768 | 1804 | |
|
1769 | 1805 | 2003-08-20 Fernando Perez <fperez@colorado.edu> |
|
1770 | 1806 | |
|
1771 | 1807 | * IPython/OInspect.py (Inspector.pinfo): changed String Form |
|
1772 | 1808 | printing so that it would print multi-line string forms starting |
|
1773 | 1809 | with a new line. This way the formatting is better respected for |
|
1774 | 1810 | objects which work hard to make nice string forms. |
|
1775 | 1811 | |
|
1776 | 1812 | * IPython/iplib.py (InteractiveShell.handle_auto): Fix bug where |
|
1777 | 1813 | autocall would overtake data access for objects with both |
|
1778 | 1814 | __getitem__ and __call__. |
|
1779 | 1815 | |
|
1780 | 1816 | 2003-08-19 *** Released version 0.5.0-rc1 |
|
1781 | 1817 | |
|
1782 | 1818 | 2003-08-19 Fernando Perez <fperez@colorado.edu> |
|
1783 | 1819 | |
|
1784 | 1820 | * IPython/deep_reload.py (load_tail): single tiny change here |
|
1785 | 1821 | seems to fix the long-standing bug of dreload() failing to work |
|
1786 | 1822 | for dotted names. But this module is pretty tricky, so I may have |
|
1787 | 1823 | missed some subtlety. Needs more testing!. |
|
1788 | 1824 | |
|
1789 | 1825 | * IPython/ultraTB.py (VerboseTB.linereader): harden against user |
|
1790 | 1826 | exceptions which have badly implemented __str__ methods. |
|
1791 | 1827 | (VerboseTB.text): harden against inspect.getinnerframes crashing, |
|
1792 | 1828 | which I've been getting reports about from Python 2.3 users. I |
|
1793 | 1829 | wish I had a simple test case to reproduce the problem, so I could |
|
1794 | 1830 | either write a cleaner workaround or file a bug report if |
|
1795 | 1831 | necessary. |
|
1796 | 1832 | |
|
1797 | 1833 | * IPython/Magic.py (Magic.magic_edit): fixed bug where after |
|
1798 | 1834 | making a class 'foo', file 'foo.py' couldn't be edited. Thanks to |
|
1799 | 1835 | a bug report by Tjabo Kloppenburg. |
|
1800 | 1836 | |
|
1801 | 1837 | * IPython/ultraTB.py (VerboseTB.debugger): hardened against pdb |
|
1802 | 1838 | crashes. Wrapped the pdb call in a blanket try/except, since pdb |
|
1803 | 1839 | seems rather unstable. Thanks to a bug report by Tjabo |
|
1804 | 1840 | Kloppenburg <tjabo.kloppenburg-AT-unix-ag.uni-siegen.de>. |
|
1805 | 1841 | |
|
1806 | 1842 | * IPython/Release.py (version): release 0.5.0-rc1. I want to put |
|
1807 | 1843 | this out soon because of the critical fixes in the inner loop for |
|
1808 | 1844 | generators. |
|
1809 | 1845 | |
|
1810 | 1846 | * IPython/Magic.py (Magic.getargspec): removed. This (and |
|
1811 | 1847 | _get_def) have been obsoleted by OInspect for a long time, I |
|
1812 | 1848 | hadn't noticed that they were dead code. |
|
1813 | 1849 | (Magic._ofind): restored _ofind functionality for a few literals |
|
1814 | 1850 | (those in ["''",'""','[]','{}','()']). But it won't work anymore |
|
1815 | 1851 | for things like "hello".capitalize?, since that would require a |
|
1816 | 1852 | potentially dangerous eval() again. |
|
1817 | 1853 | |
|
1818 | 1854 | * IPython/iplib.py (InteractiveShell._prefilter): reorganized the |
|
1819 | 1855 | logic a bit more to clean up the escapes handling and minimize the |
|
1820 | 1856 | use of _ofind to only necessary cases. The interactive 'feel' of |
|
1821 | 1857 | IPython should have improved quite a bit with the changes in |
|
1822 | 1858 | _prefilter and _ofind (besides being far safer than before). |
|
1823 | 1859 | |
|
1824 | 1860 | * IPython/Magic.py (Magic.magic_edit): Fixed old bug (but rather |
|
1825 | 1861 | obscure, never reported). Edit would fail to find the object to |
|
1826 | 1862 | edit under some circumstances. |
|
1827 | 1863 | (Magic._ofind): CRITICAL FIX. Finally removed the eval() calls |
|
1828 | 1864 | which were causing double-calling of generators. Those eval calls |
|
1829 | 1865 | were _very_ dangerous, since code with side effects could be |
|
1830 | 1866 | triggered. As they say, 'eval is evil'... These were the |
|
1831 | 1867 | nastiest evals in IPython. Besides, _ofind is now far simpler, |
|
1832 | 1868 | and it should also be quite a bit faster. Its use of inspect is |
|
1833 | 1869 | also safer, so perhaps some of the inspect-related crashes I've |
|
1834 | 1870 | seen lately with Python 2.3 might be taken care of. That will |
|
1835 | 1871 | need more testing. |
|
1836 | 1872 | |
|
1837 | 1873 | 2003-08-17 Fernando Perez <fperez@colorado.edu> |
|
1838 | 1874 | |
|
1839 | 1875 | * IPython/iplib.py (InteractiveShell._prefilter): significant |
|
1840 | 1876 | simplifications to the logic for handling user escapes. Faster |
|
1841 | 1877 | and simpler code. |
|
1842 | 1878 | |
|
1843 | 1879 | 2003-08-14 Fernando Perez <fperez@colorado.edu> |
|
1844 | 1880 | |
|
1845 | 1881 | * IPython/numutils.py (sum_flat): rewrote to be non-recursive. |
|
1846 | 1882 | Now it requires O(N) storage (N=size(a)) for non-contiguous input, |
|
1847 | 1883 | but it should be quite a bit faster. And the recursive version |
|
1848 | 1884 | generated O(log N) intermediate storage for all rank>1 arrays, |
|
1849 | 1885 | even if they were contiguous. |
|
1850 | 1886 | (l1norm): Added this function. |
|
1851 | 1887 | (norm): Added this function for arbitrary norms (including |
|
1852 | 1888 | l-infinity). l1 and l2 are still special cases for convenience |
|
1853 | 1889 | and speed. |
|
1854 | 1890 | |
|
1855 | 1891 | 2003-08-03 Fernando Perez <fperez@colorado.edu> |
|
1856 | 1892 | |
|
1857 | 1893 | * IPython/Magic.py (Magic.magic_edit): Removed all remaining string |
|
1858 | 1894 | exceptions, which now raise PendingDeprecationWarnings in Python |
|
1859 | 1895 | 2.3. There were some in Magic and some in Gnuplot2. |
|
1860 | 1896 | |
|
1861 | 1897 | 2003-06-30 Fernando Perez <fperez@colorado.edu> |
|
1862 | 1898 | |
|
1863 | 1899 | * IPython/genutils.py (page): modified to call curses only for |
|
1864 | 1900 | terminals where TERM=='xterm'. After problems under many other |
|
1865 | 1901 | terminals were reported by Keith Beattie <KSBeattie-AT-lbl.gov>. |
|
1866 | 1902 | |
|
1867 | 1903 | * IPython/iplib.py (complete): removed spurious 'print "IE"' which |
|
1868 | 1904 | would be triggered when readline was absent. This was just an old |
|
1869 | 1905 | debugging statement I'd forgotten to take out. |
|
1870 | 1906 | |
|
1871 | 1907 | 2003-06-20 Fernando Perez <fperez@colorado.edu> |
|
1872 | 1908 | |
|
1873 | 1909 | * IPython/genutils.py (clock): modified to return only user time |
|
1874 | 1910 | (not counting system time), after a discussion on scipy. While |
|
1875 | 1911 | system time may be a useful quantity occasionally, it may much |
|
1876 | 1912 | more easily be skewed by occasional swapping or other similar |
|
1877 | 1913 | activity. |
|
1878 | 1914 | |
|
1879 | 1915 | 2003-06-05 Fernando Perez <fperez@colorado.edu> |
|
1880 | 1916 | |
|
1881 | 1917 | * IPython/numutils.py (identity): new function, for building |
|
1882 | 1918 | arbitrary rank Kronecker deltas (mostly backwards compatible with |
|
1883 | 1919 | Numeric.identity) |
|
1884 | 1920 | |
|
1885 | 1921 | 2003-06-03 Fernando Perez <fperez@colorado.edu> |
|
1886 | 1922 | |
|
1887 | 1923 | * IPython/iplib.py (InteractiveShell.handle_magic): protect |
|
1888 | 1924 | arguments passed to magics with spaces, to allow trailing '\' to |
|
1889 | 1925 | work normally (mainly for Windows users). |
|
1890 | 1926 | |
|
1891 | 1927 | 2003-05-29 Fernando Perez <fperez@colorado.edu> |
|
1892 | 1928 | |
|
1893 | 1929 | * IPython/ipmaker.py (make_IPython): Load site._Helper() as help |
|
1894 | 1930 | instead of pydoc.help. This fixes a bizarre behavior where |
|
1895 | 1931 | printing '%s' % locals() would trigger the help system. Now |
|
1896 | 1932 | ipython behaves like normal python does. |
|
1897 | 1933 | |
|
1898 | 1934 | Note that if one does 'from pydoc import help', the bizarre |
|
1899 | 1935 | behavior returns, but this will also happen in normal python, so |
|
1900 | 1936 | it's not an ipython bug anymore (it has to do with how pydoc.help |
|
1901 | 1937 | is implemented). |
|
1902 | 1938 | |
|
1903 | 1939 | 2003-05-22 Fernando Perez <fperez@colorado.edu> |
|
1904 | 1940 | |
|
1905 | 1941 | * IPython/FlexCompleter.py (Completer.attr_matches): fixed to |
|
1906 | 1942 | return [] instead of None when nothing matches, also match to end |
|
1907 | 1943 | of line. Patch by Gary Bishop. |
|
1908 | 1944 | |
|
1909 | 1945 | * IPython/ipmaker.py (make_IPython): Added same sys.excepthook |
|
1910 | 1946 | protection as before, for files passed on the command line. This |
|
1911 | 1947 | prevents the CrashHandler from kicking in if user files call into |
|
1912 | 1948 | sys.excepthook (such as PyQt and WxWindows have a nasty habit of |
|
1913 | 1949 | doing). After a report by Kasper Souren <Kasper.Souren-AT-ircam.fr> |
|
1914 | 1950 | |
|
1915 | 1951 | 2003-05-20 *** Released version 0.4.0 |
|
1916 | 1952 | |
|
1917 | 1953 | 2003-05-20 Fernando Perez <fperez@colorado.edu> |
|
1918 | 1954 | |
|
1919 | 1955 | * setup.py: added support for manpages. It's a bit hackish b/c of |
|
1920 | 1956 | a bug in the way the bdist_rpm distutils target handles gzipped |
|
1921 | 1957 | manpages, but it works. After a patch by Jack. |
|
1922 | 1958 | |
|
1923 | 1959 | 2003-05-19 Fernando Perez <fperez@colorado.edu> |
|
1924 | 1960 | |
|
1925 | 1961 | * IPython/numutils.py: added a mockup of the kinds module, since |
|
1926 | 1962 | it was recently removed from Numeric. This way, numutils will |
|
1927 | 1963 | work for all users even if they are missing kinds. |
|
1928 | 1964 | |
|
1929 | 1965 | * IPython/Magic.py (Magic._ofind): Harden against an inspect |
|
1930 | 1966 | failure, which can occur with SWIG-wrapped extensions. After a |
|
1931 | 1967 | crash report from Prabhu. |
|
1932 | 1968 | |
|
1933 | 1969 | 2003-05-16 Fernando Perez <fperez@colorado.edu> |
|
1934 | 1970 | |
|
1935 | 1971 | * IPython/iplib.py (InteractiveShell.excepthook): New method to |
|
1936 | 1972 | protect ipython from user code which may call directly |
|
1937 | 1973 | sys.excepthook (this looks like an ipython crash to the user, even |
|
1938 | 1974 | when it isn't). After a patch by Gary Bishop <gb-AT-cs.unc.edu>. |
|
1939 | 1975 | This is especially important to help users of WxWindows, but may |
|
1940 | 1976 | also be useful in other cases. |
|
1941 | 1977 | |
|
1942 | 1978 | * IPython/ultraTB.py (AutoFormattedTB.__call__): Changed to allow |
|
1943 | 1979 | an optional tb_offset to be specified, and to preserve exception |
|
1944 | 1980 | info if given. After a patch by Gary Bishop <gb-AT-cs.unc.edu>. |
|
1945 | 1981 | |
|
1946 | 1982 | * ipython.1 (Default): Thanks to Jack's work, we now have manpages! |
|
1947 | 1983 | |
|
1948 | 1984 | 2003-05-15 Fernando Perez <fperez@colorado.edu> |
|
1949 | 1985 | |
|
1950 | 1986 | * IPython/iplib.py (InteractiveShell.user_setup): Fix crash when |
|
1951 | 1987 | installing for a new user under Windows. |
|
1952 | 1988 | |
|
1953 | 1989 | 2003-05-12 Fernando Perez <fperez@colorado.edu> |
|
1954 | 1990 | |
|
1955 | 1991 | * IPython/iplib.py (InteractiveShell.handle_emacs): New line |
|
1956 | 1992 | handler for Emacs comint-based lines. Currently it doesn't do |
|
1957 | 1993 | much (but importantly, it doesn't update the history cache). In |
|
1958 | 1994 | the future it may be expanded if Alex needs more functionality |
|
1959 | 1995 | there. |
|
1960 | 1996 | |
|
1961 | 1997 | * IPython/CrashHandler.py (CrashHandler.__call__): Added platform |
|
1962 | 1998 | info to crash reports. |
|
1963 | 1999 | |
|
1964 | 2000 | * IPython/iplib.py (InteractiveShell.mainloop): Added -c option, |
|
1965 | 2001 | just like Python's -c. Also fixed crash with invalid -color |
|
1966 | 2002 | option value at startup. Thanks to Will French |
|
1967 | 2003 | <wfrench-AT-bestweb.net> for the bug report. |
|
1968 | 2004 | |
|
1969 | 2005 | 2003-05-09 Fernando Perez <fperez@colorado.edu> |
|
1970 | 2006 | |
|
1971 | 2007 | * IPython/genutils.py (EvalDict.__getitem__): Renamed EvalString |
|
1972 | 2008 | to EvalDict (it's a mapping, after all) and simplified its code |
|
1973 | 2009 | quite a bit, after a nice discussion on c.l.py where Gustavo |
|
1974 | 2010 | CΓ³rdova <gcordova-AT-sismex.com> suggested the new version. |
|
1975 | 2011 | |
|
1976 | 2012 | 2003-04-30 Fernando Perez <fperez@colorado.edu> |
|
1977 | 2013 | |
|
1978 | 2014 | * IPython/genutils.py (timings_out): modified it to reduce its |
|
1979 | 2015 | overhead in the common reps==1 case. |
|
1980 | 2016 | |
|
1981 | 2017 | 2003-04-29 Fernando Perez <fperez@colorado.edu> |
|
1982 | 2018 | |
|
1983 | 2019 | * IPython/genutils.py (timings_out): Modified to use the resource |
|
1984 | 2020 | module, which avoids the wraparound problems of time.clock(). |
|
1985 | 2021 | |
|
1986 | 2022 | 2003-04-17 *** Released version 0.2.15pre4 |
|
1987 | 2023 | |
|
1988 | 2024 | 2003-04-17 Fernando Perez <fperez@colorado.edu> |
|
1989 | 2025 | |
|
1990 | 2026 | * setup.py (scriptfiles): Split windows-specific stuff over to a |
|
1991 | 2027 | separate file, in an attempt to have a Windows GUI installer. |
|
1992 | 2028 | That didn't work, but part of the groundwork is done. |
|
1993 | 2029 | |
|
1994 | 2030 | * IPython/UserConfig/ipythonrc: Added M-i, M-o and M-I for |
|
1995 | 2031 | indent/unindent with 4 spaces. Particularly useful in combination |
|
1996 | 2032 | with the new auto-indent option. |
|
1997 | 2033 | |
|
1998 | 2034 | 2003-04-16 Fernando Perez <fperez@colorado.edu> |
|
1999 | 2035 | |
|
2000 | 2036 | * IPython/Magic.py: various replacements of self.rc for |
|
2001 | 2037 | self.shell.rc. A lot more remains to be done to fully disentangle |
|
2002 | 2038 | this class from the main Shell class. |
|
2003 | 2039 | |
|
2004 | 2040 | * IPython/GnuplotRuntime.py: added checks for mouse support so |
|
2005 | 2041 | that we don't try to enable it if the current gnuplot doesn't |
|
2006 | 2042 | really support it. Also added checks so that we don't try to |
|
2007 | 2043 | enable persist under Windows (where Gnuplot doesn't recognize the |
|
2008 | 2044 | option). |
|
2009 | 2045 | |
|
2010 | 2046 | * IPython/iplib.py (InteractiveShell.interact): Added optional |
|
2011 | 2047 | auto-indenting code, after a patch by King C. Shu |
|
2012 | 2048 | <kingshu-AT-myrealbox.com>. It's off by default because it doesn't |
|
2013 | 2049 | get along well with pasting indented code. If I ever figure out |
|
2014 | 2050 | how to make that part go well, it will become on by default. |
|
2015 | 2051 | |
|
2016 | 2052 | * IPython/Prompts.py (Prompt1.auto_rewrite): Fixed bug which would |
|
2017 | 2053 | crash ipython if there was an unmatched '%' in the user's prompt |
|
2018 | 2054 | string. Reported by Thorsten Kampe <thorsten-AT-thorstenkampe.de>. |
|
2019 | 2055 | |
|
2020 | 2056 | * IPython/iplib.py (InteractiveShell.interact): removed the |
|
2021 | 2057 | ability to ask the user whether he wants to crash or not at the |
|
2022 | 2058 | 'last line' exception handler. Calling functions at that point |
|
2023 | 2059 | changes the stack, and the error reports would have incorrect |
|
2024 | 2060 | tracebacks. |
|
2025 | 2061 | |
|
2026 | 2062 | * IPython/Magic.py (Magic.magic_page): Added new @page magic, to |
|
2027 | 2063 | pass through a peger a pretty-printed form of any object. After a |
|
2028 | 2064 | contribution by Olivier Aubert <oaubert-AT-bat710.univ-lyon1.fr> |
|
2029 | 2065 | |
|
2030 | 2066 | 2003-04-14 Fernando Perez <fperez@colorado.edu> |
|
2031 | 2067 | |
|
2032 | 2068 | * IPython/iplib.py (InteractiveShell.user_setup): Fixed bug where |
|
2033 | 2069 | all files in ~ would be modified at first install (instead of |
|
2034 | 2070 | ~/.ipython). This could be potentially disastrous, as the |
|
2035 | 2071 | modification (make line-endings native) could damage binary files. |
|
2036 | 2072 | |
|
2037 | 2073 | 2003-04-10 Fernando Perez <fperez@colorado.edu> |
|
2038 | 2074 | |
|
2039 | 2075 | * IPython/iplib.py (InteractiveShell.handle_help): Modified to |
|
2040 | 2076 | handle only lines which are invalid python. This now means that |
|
2041 | 2077 | lines like 'x=1 #?' execute properly. Thanks to Jeffery Collins |
|
2042 | 2078 | for the bug report. |
|
2043 | 2079 | |
|
2044 | 2080 | 2003-04-01 Fernando Perez <fperez@colorado.edu> |
|
2045 | 2081 | |
|
2046 | 2082 | * IPython/iplib.py (InteractiveShell.showtraceback): Fixed bug |
|
2047 | 2083 | where failing to set sys.last_traceback would crash pdb.pm(). |
|
2048 | 2084 | Thanks to Jeffery D. Collins <Jeff.Collins-AT-vexcel.com> for the bug |
|
2049 | 2085 | report. |
|
2050 | 2086 | |
|
2051 | 2087 | 2003-03-25 Fernando Perez <fperez@colorado.edu> |
|
2052 | 2088 | |
|
2053 | 2089 | * IPython/Magic.py (Magic.magic_prun): rstrip() output of profiler |
|
2054 | 2090 | before printing it (it had a lot of spurious blank lines at the |
|
2055 | 2091 | end). |
|
2056 | 2092 | |
|
2057 | 2093 | * IPython/Gnuplot2.py (Gnuplot.hardcopy): fixed bug where lpr |
|
2058 | 2094 | output would be sent 21 times! Obviously people don't use this |
|
2059 | 2095 | too often, or I would have heard about it. |
|
2060 | 2096 | |
|
2061 | 2097 | 2003-03-24 Fernando Perez <fperez@colorado.edu> |
|
2062 | 2098 | |
|
2063 | 2099 | * setup.py (scriptfiles): renamed the data_files parameter from |
|
2064 | 2100 | 'base' to 'data' to fix rpm build issues. Thanks to Ralf Ahlbrink |
|
2065 | 2101 | for the patch. |
|
2066 | 2102 | |
|
2067 | 2103 | 2003-03-20 Fernando Perez <fperez@colorado.edu> |
|
2068 | 2104 | |
|
2069 | 2105 | * IPython/genutils.py (error): added error() and fatal() |
|
2070 | 2106 | functions. |
|
2071 | 2107 | |
|
2072 | 2108 | 2003-03-18 *** Released version 0.2.15pre3 |
|
2073 | 2109 | |
|
2074 | 2110 | 2003-03-18 Fernando Perez <fperez@colorado.edu> |
|
2075 | 2111 | |
|
2076 | 2112 | * setupext/install_data_ext.py |
|
2077 | 2113 | (install_data_ext.initialize_options): Class contributed by Jack |
|
2078 | 2114 | Moffit for fixing the old distutils hack. He is sending this to |
|
2079 | 2115 | the distutils folks so in the future we may not need it as a |
|
2080 | 2116 | private fix. |
|
2081 | 2117 | |
|
2082 | 2118 | * MANIFEST.in: Extensive reorganization, based on Jack Moffit's |
|
2083 | 2119 | changes for Debian packaging. See his patch for full details. |
|
2084 | 2120 | The old distutils hack of making the ipythonrc* files carry a |
|
2085 | 2121 | bogus .py extension is gone, at last. Examples were moved to a |
|
2086 | 2122 | separate subdir under doc/, and the separate executable scripts |
|
2087 | 2123 | now live in their own directory. Overall a great cleanup. The |
|
2088 | 2124 | manual was updated to use the new files, and setup.py has been |
|
2089 | 2125 | fixed for this setup. |
|
2090 | 2126 | |
|
2091 | 2127 | * IPython/PyColorize.py (Parser.usage): made non-executable and |
|
2092 | 2128 | created a pycolor wrapper around it to be included as a script. |
|
2093 | 2129 | |
|
2094 | 2130 | 2003-03-12 *** Released version 0.2.15pre2 |
|
2095 | 2131 | |
|
2096 | 2132 | 2003-03-12 Fernando Perez <fperez@colorado.edu> |
|
2097 | 2133 | |
|
2098 | 2134 | * IPython/ColorANSI.py (make_color_table): Finally fixed the |
|
2099 | 2135 | long-standing problem with garbage characters in some terminals. |
|
2100 | 2136 | The issue was really that the \001 and \002 escapes must _only_ be |
|
2101 | 2137 | passed to input prompts (which call readline), but _never_ to |
|
2102 | 2138 | normal text to be printed on screen. I changed ColorANSI to have |
|
2103 | 2139 | two classes: TermColors and InputTermColors, each with the |
|
2104 | 2140 | appropriate escapes for input prompts or normal text. The code in |
|
2105 | 2141 | Prompts.py got slightly more complicated, but this very old and |
|
2106 | 2142 | annoying bug is finally fixed. |
|
2107 | 2143 | |
|
2108 | 2144 | All the credit for nailing down the real origin of this problem |
|
2109 | 2145 | and the correct solution goes to Jack Moffit <jack-AT-xiph.org>. |
|
2110 | 2146 | *Many* thanks to him for spending quite a bit of effort on this. |
|
2111 | 2147 | |
|
2112 | 2148 | 2003-03-05 *** Released version 0.2.15pre1 |
|
2113 | 2149 | |
|
2114 | 2150 | 2003-03-03 Fernando Perez <fperez@colorado.edu> |
|
2115 | 2151 | |
|
2116 | 2152 | * IPython/FakeModule.py: Moved the former _FakeModule to a |
|
2117 | 2153 | separate file, because it's also needed by Magic (to fix a similar |
|
2118 | 2154 | pickle-related issue in @run). |
|
2119 | 2155 | |
|
2120 | 2156 | 2003-03-02 Fernando Perez <fperez@colorado.edu> |
|
2121 | 2157 | |
|
2122 | 2158 | * IPython/Magic.py (Magic.magic_autocall): new magic to control |
|
2123 | 2159 | the autocall option at runtime. |
|
2124 | 2160 | (Magic.magic_dhist): changed self.user_ns to self.shell.user_ns |
|
2125 | 2161 | across Magic.py to start separating Magic from InteractiveShell. |
|
2126 | 2162 | (Magic._ofind): Fixed to return proper namespace for dotted |
|
2127 | 2163 | names. Before, a dotted name would always return 'not currently |
|
2128 | 2164 | defined', because it would find the 'parent'. s.x would be found, |
|
2129 | 2165 | but since 'x' isn't defined by itself, it would get confused. |
|
2130 | 2166 | (Magic.magic_run): Fixed pickling problems reported by Ralf |
|
2131 | 2167 | Ahlbrink <RAhlbrink-AT-RosenInspection.net>. The fix was similar to |
|
2132 | 2168 | that I'd used when Mike Heeter reported similar issues at the |
|
2133 | 2169 | top-level, but now for @run. It boils down to injecting the |
|
2134 | 2170 | namespace where code is being executed with something that looks |
|
2135 | 2171 | enough like a module to fool pickle.dump(). Since a pickle stores |
|
2136 | 2172 | a named reference to the importing module, we need this for |
|
2137 | 2173 | pickles to save something sensible. |
|
2138 | 2174 | |
|
2139 | 2175 | * IPython/ipmaker.py (make_IPython): added an autocall option. |
|
2140 | 2176 | |
|
2141 | 2177 | * IPython/iplib.py (InteractiveShell._prefilter): reordered all of |
|
2142 | 2178 | the auto-eval code. Now autocalling is an option, and the code is |
|
2143 | 2179 | also vastly safer. There is no more eval() involved at all. |
|
2144 | 2180 | |
|
2145 | 2181 | 2003-03-01 Fernando Perez <fperez@colorado.edu> |
|
2146 | 2182 | |
|
2147 | 2183 | * IPython/Magic.py (Magic._ofind): Changed interface to return a |
|
2148 | 2184 | dict with named keys instead of a tuple. |
|
2149 | 2185 | |
|
2150 | 2186 | * IPython: Started using CVS for IPython as of 0.2.15pre1. |
|
2151 | 2187 | |
|
2152 | 2188 | * setup.py (make_shortcut): Fixed message about directories |
|
2153 | 2189 | created during Windows installation (the directories were ok, just |
|
2154 | 2190 | the printed message was misleading). Thanks to Chris Liechti |
|
2155 | 2191 | <cliechti-AT-gmx.net> for the heads up. |
|
2156 | 2192 | |
|
2157 | 2193 | 2003-02-21 Fernando Perez <fperez@colorado.edu> |
|
2158 | 2194 | |
|
2159 | 2195 | * IPython/iplib.py (InteractiveShell._prefilter): Fixed catching |
|
2160 | 2196 | of ValueError exception when checking for auto-execution. This |
|
2161 | 2197 | one is raised by things like Numeric arrays arr.flat when the |
|
2162 | 2198 | array is non-contiguous. |
|
2163 | 2199 | |
|
2164 | 2200 | 2003-01-31 Fernando Perez <fperez@colorado.edu> |
|
2165 | 2201 | |
|
2166 | 2202 | * IPython/genutils.py (SystemExec.bq): Fixed bug where bq would |
|
2167 | 2203 | not return any value at all (even though the command would get |
|
2168 | 2204 | executed). |
|
2169 | 2205 | (xsys): Flush stdout right after printing the command to ensure |
|
2170 | 2206 | proper ordering of commands and command output in the total |
|
2171 | 2207 | output. |
|
2172 | 2208 | (SystemExec/xsys/bq): Switched the names of xsys/bq and |
|
2173 | 2209 | system/getoutput as defaults. The old ones are kept for |
|
2174 | 2210 | compatibility reasons, so no code which uses this library needs |
|
2175 | 2211 | changing. |
|
2176 | 2212 | |
|
2177 | 2213 | 2003-01-27 *** Released version 0.2.14 |
|
2178 | 2214 | |
|
2179 | 2215 | 2003-01-25 Fernando Perez <fperez@colorado.edu> |
|
2180 | 2216 | |
|
2181 | 2217 | * IPython/Magic.py (Magic.magic_edit): Fixed problem where |
|
2182 | 2218 | functions defined in previous edit sessions could not be re-edited |
|
2183 | 2219 | (because the temp files were immediately removed). Now temp files |
|
2184 | 2220 | are removed only at IPython's exit. |
|
2185 | 2221 | (Magic.magic_run): Improved @run to perform shell-like expansions |
|
2186 | 2222 | on its arguments (~users and $VARS). With this, @run becomes more |
|
2187 | 2223 | like a normal command-line. |
|
2188 | 2224 | |
|
2189 | 2225 | * IPython/Shell.py (IPShellEmbed.__call__): Fixed a bunch of small |
|
2190 | 2226 | bugs related to embedding and cleaned up that code. A fairly |
|
2191 | 2227 | important one was the impossibility to access the global namespace |
|
2192 | 2228 | through the embedded IPython (only local variables were visible). |
|
2193 | 2229 | |
|
2194 | 2230 | 2003-01-14 Fernando Perez <fperez@colorado.edu> |
|
2195 | 2231 | |
|
2196 | 2232 | * IPython/iplib.py (InteractiveShell._prefilter): Fixed |
|
2197 | 2233 | auto-calling to be a bit more conservative. Now it doesn't get |
|
2198 | 2234 | triggered if any of '!=()<>' are in the rest of the input line, to |
|
2199 | 2235 | allow comparing callables. Thanks to Alex for the heads up. |
|
2200 | 2236 | |
|
2201 | 2237 | 2003-01-07 Fernando Perez <fperez@colorado.edu> |
|
2202 | 2238 | |
|
2203 | 2239 | * IPython/genutils.py (page): fixed estimation of the number of |
|
2204 | 2240 | lines in a string to be paged to simply count newlines. This |
|
2205 | 2241 | prevents over-guessing due to embedded escape sequences. A better |
|
2206 | 2242 | long-term solution would involve stripping out the control chars |
|
2207 | 2243 | for the count, but it's potentially so expensive I just don't |
|
2208 | 2244 | think it's worth doing. |
|
2209 | 2245 | |
|
2210 | 2246 | 2002-12-19 *** Released version 0.2.14pre50 |
|
2211 | 2247 | |
|
2212 | 2248 | 2002-12-19 Fernando Perez <fperez@colorado.edu> |
|
2213 | 2249 | |
|
2214 | 2250 | * tools/release (version): Changed release scripts to inform |
|
2215 | 2251 | Andrea and build a NEWS file with a list of recent changes. |
|
2216 | 2252 | |
|
2217 | 2253 | * IPython/ColorANSI.py (__all__): changed terminal detection |
|
2218 | 2254 | code. Seems to work better for xterms without breaking |
|
2219 | 2255 | konsole. Will need more testing to determine if WinXP and Mac OSX |
|
2220 | 2256 | also work ok. |
|
2221 | 2257 | |
|
2222 | 2258 | 2002-12-18 *** Released version 0.2.14pre49 |
|
2223 | 2259 | |
|
2224 | 2260 | 2002-12-18 Fernando Perez <fperez@colorado.edu> |
|
2225 | 2261 | |
|
2226 | 2262 | * Docs: added new info about Mac OSX, from Andrea. |
|
2227 | 2263 | |
|
2228 | 2264 | * IPython/Gnuplot2.py (String): Added a String PlotItem class to |
|
2229 | 2265 | allow direct plotting of python strings whose format is the same |
|
2230 | 2266 | of gnuplot data files. |
|
2231 | 2267 | |
|
2232 | 2268 | 2002-12-16 Fernando Perez <fperez@colorado.edu> |
|
2233 | 2269 | |
|
2234 | 2270 | * IPython/iplib.py (InteractiveShell.interact): fixed default (y) |
|
2235 | 2271 | value of exit question to be acknowledged. |
|
2236 | 2272 | |
|
2237 | 2273 | 2002-12-03 Fernando Perez <fperez@colorado.edu> |
|
2238 | 2274 | |
|
2239 | 2275 | * IPython/ipmaker.py: removed generators, which had been added |
|
2240 | 2276 | by mistake in an earlier debugging run. This was causing trouble |
|
2241 | 2277 | to users of python 2.1.x. Thanks to Abel Daniel <abli-AT-freemail.hu> |
|
2242 | 2278 | for pointing this out. |
|
2243 | 2279 | |
|
2244 | 2280 | 2002-11-17 Fernando Perez <fperez@colorado.edu> |
|
2245 | 2281 | |
|
2246 | 2282 | * Manual: updated the Gnuplot section. |
|
2247 | 2283 | |
|
2248 | 2284 | * IPython/GnuplotRuntime.py: refactored a lot all this code, with |
|
2249 | 2285 | a much better split of what goes in Runtime and what goes in |
|
2250 | 2286 | Interactive. |
|
2251 | 2287 | |
|
2252 | 2288 | * IPython/ipmaker.py: fixed bug where import_fail_info wasn't |
|
2253 | 2289 | being imported from iplib. |
|
2254 | 2290 | |
|
2255 | 2291 | * IPython/GnuplotInteractive.py (magic_gpc): renamed @gp to @gpc |
|
2256 | 2292 | for command-passing. Now the global Gnuplot instance is called |
|
2257 | 2293 | 'gp' instead of 'g', which was really a far too fragile and |
|
2258 | 2294 | common name. |
|
2259 | 2295 | |
|
2260 | 2296 | * IPython/Gnuplot2.py (eps_fix_bbox): added this to fix broken |
|
2261 | 2297 | bounding boxes generated by Gnuplot for square plots. |
|
2262 | 2298 | |
|
2263 | 2299 | * IPython/genutils.py (popkey): new function added. I should |
|
2264 | 2300 | suggest this on c.l.py as a dict method, it seems useful. |
|
2265 | 2301 | |
|
2266 | 2302 | * IPython/Gnuplot2.py (Gnuplot.plot): Overhauled plot and replot |
|
2267 | 2303 | to transparently handle PostScript generation. MUCH better than |
|
2268 | 2304 | the previous plot_eps/replot_eps (which I removed now). The code |
|
2269 | 2305 | is also fairly clean and well documented now (including |
|
2270 | 2306 | docstrings). |
|
2271 | 2307 | |
|
2272 | 2308 | 2002-11-13 Fernando Perez <fperez@colorado.edu> |
|
2273 | 2309 | |
|
2274 | 2310 | * IPython/Magic.py (Magic.magic_edit): fixed docstring |
|
2275 | 2311 | (inconsistent with options). |
|
2276 | 2312 | |
|
2277 | 2313 | * IPython/Gnuplot2.py (Gnuplot.hardcopy): hardcopy had been |
|
2278 | 2314 | manually disabled, I don't know why. Fixed it. |
|
2279 | 2315 | (Gnuplot._plot_eps): added new plot_eps/replot_eps to get directly |
|
2280 | 2316 | eps output. |
|
2281 | 2317 | |
|
2282 | 2318 | 2002-11-12 Fernando Perez <fperez@colorado.edu> |
|
2283 | 2319 | |
|
2284 | 2320 | * IPython/genutils.py (ask_yes_no): trap EOF and ^C so that they |
|
2285 | 2321 | don't propagate up to caller. Fixes crash reported by François |
|
2286 | 2322 | Pinard. |
|
2287 | 2323 | |
|
2288 | 2324 | 2002-11-09 Fernando Perez <fperez@colorado.edu> |
|
2289 | 2325 | |
|
2290 | 2326 | * IPython/ipmaker.py (make_IPython): fixed problem with writing |
|
2291 | 2327 | history file for new users. |
|
2292 | 2328 | (make_IPython): fixed bug where initial install would leave the |
|
2293 | 2329 | user running in the .ipython dir. |
|
2294 | 2330 | (make_IPython): fixed bug where config dir .ipython would be |
|
2295 | 2331 | created regardless of the given -ipythondir option. Thanks to Cory |
|
2296 | 2332 | Dodt <cdodt-AT-fcoe.k12.ca.us> for the bug report. |
|
2297 | 2333 | |
|
2298 | 2334 | * IPython/genutils.py (ask_yes_no): new function for asking yes/no |
|
2299 | 2335 | type confirmations. Will need to use it in all of IPython's code |
|
2300 | 2336 | consistently. |
|
2301 | 2337 | |
|
2302 | 2338 | * IPython/CrashHandler.py (CrashHandler.__call__): changed the |
|
2303 | 2339 | context to print 31 lines instead of the default 5. This will make |
|
2304 | 2340 | the crash reports extremely detailed in case the problem is in |
|
2305 | 2341 | libraries I don't have access to. |
|
2306 | 2342 | |
|
2307 | 2343 | * IPython/iplib.py (InteractiveShell.interact): changed the 'last |
|
2308 | 2344 | line of defense' code to still crash, but giving users fair |
|
2309 | 2345 | warning. I don't want internal errors to go unreported: if there's |
|
2310 | 2346 | an internal problem, IPython should crash and generate a full |
|
2311 | 2347 | report. |
|
2312 | 2348 | |
|
2313 | 2349 | 2002-11-08 Fernando Perez <fperez@colorado.edu> |
|
2314 | 2350 | |
|
2315 | 2351 | * IPython/iplib.py (InteractiveShell.interact): added code to trap |
|
2316 | 2352 | otherwise uncaught exceptions which can appear if people set |
|
2317 | 2353 | sys.stdout to something badly broken. Thanks to a crash report |
|
2318 | 2354 | from henni-AT-mail.brainbot.com. |
|
2319 | 2355 | |
|
2320 | 2356 | 2002-11-04 Fernando Perez <fperez@colorado.edu> |
|
2321 | 2357 | |
|
2322 | 2358 | * IPython/iplib.py (InteractiveShell.interact): added |
|
2323 | 2359 | __IPYTHON__active to the builtins. It's a flag which goes on when |
|
2324 | 2360 | the interaction starts and goes off again when it stops. This |
|
2325 | 2361 | allows embedding code to detect being inside IPython. Before this |
|
2326 | 2362 | was done via __IPYTHON__, but that only shows that an IPython |
|
2327 | 2363 | instance has been created. |
|
2328 | 2364 | |
|
2329 | 2365 | * IPython/Magic.py (Magic.magic_env): I realized that in a |
|
2330 | 2366 | UserDict, instance.data holds the data as a normal dict. So I |
|
2331 | 2367 | modified @env to return os.environ.data instead of rebuilding a |
|
2332 | 2368 | dict by hand. |
|
2333 | 2369 | |
|
2334 | 2370 | 2002-11-02 Fernando Perez <fperez@colorado.edu> |
|
2335 | 2371 | |
|
2336 | 2372 | * IPython/genutils.py (warn): changed so that level 1 prints no |
|
2337 | 2373 | header. Level 2 is now the default (with 'WARNING' header, as |
|
2338 | 2374 | before). I think I tracked all places where changes were needed in |
|
2339 | 2375 | IPython, but outside code using the old level numbering may have |
|
2340 | 2376 | broken. |
|
2341 | 2377 | |
|
2342 | 2378 | * IPython/iplib.py (InteractiveShell.runcode): added this to |
|
2343 | 2379 | handle the tracebacks in SystemExit traps correctly. The previous |
|
2344 | 2380 | code (through interact) was printing more of the stack than |
|
2345 | 2381 | necessary, showing IPython internal code to the user. |
|
2346 | 2382 | |
|
2347 | 2383 | * IPython/UserConfig/ipythonrc.py: Made confirm_exit 1 by |
|
2348 | 2384 | default. Now that the default at the confirmation prompt is yes, |
|
2349 | 2385 | it's not so intrusive. François' argument that ipython sessions |
|
2350 | 2386 | tend to be complex enough not to lose them from an accidental C-d, |
|
2351 | 2387 | is a valid one. |
|
2352 | 2388 | |
|
2353 | 2389 | * IPython/iplib.py (InteractiveShell.interact): added a |
|
2354 | 2390 | showtraceback() call to the SystemExit trap, and modified the exit |
|
2355 | 2391 | confirmation to have yes as the default. |
|
2356 | 2392 | |
|
2357 | 2393 | * IPython/UserConfig/ipythonrc.py: removed 'session' option from |
|
2358 | 2394 | this file. It's been gone from the code for a long time, this was |
|
2359 | 2395 | simply leftover junk. |
|
2360 | 2396 | |
|
2361 | 2397 | 2002-11-01 Fernando Perez <fperez@colorado.edu> |
|
2362 | 2398 | |
|
2363 | 2399 | * IPython/UserConfig/ipythonrc.py: new confirm_exit option |
|
2364 | 2400 | added. If set, IPython now traps EOF and asks for |
|
2365 | 2401 | confirmation. After a request by François Pinard. |
|
2366 | 2402 | |
|
2367 | 2403 | * IPython/Magic.py (Magic.magic_Exit): New @Exit and @Quit instead |
|
2368 | 2404 | of @abort, and with a new (better) mechanism for handling the |
|
2369 | 2405 | exceptions. |
|
2370 | 2406 | |
|
2371 | 2407 | 2002-10-27 Fernando Perez <fperez@colorado.edu> |
|
2372 | 2408 | |
|
2373 | 2409 | * IPython/usage.py (__doc__): updated the --help information and |
|
2374 | 2410 | the ipythonrc file to indicate that -log generates |
|
2375 | 2411 | ./ipython.log. Also fixed the corresponding info in @logstart. |
|
2376 | 2412 | This and several other fixes in the manuals thanks to reports by |
|
2377 | 2413 | François Pinard <pinard-AT-iro.umontreal.ca>. |
|
2378 | 2414 | |
|
2379 | 2415 | * IPython/Logger.py (Logger.switch_log): Fixed error message to |
|
2380 | 2416 | refer to @logstart (instead of @log, which doesn't exist). |
|
2381 | 2417 | |
|
2382 | 2418 | * IPython/iplib.py (InteractiveShell._prefilter): fixed |
|
2383 | 2419 | AttributeError crash. Thanks to Christopher Armstrong |
|
2384 | 2420 | <radix-AT-twistedmatrix.com> for the report/fix. This bug had been |
|
2385 | 2421 | introduced recently (in 0.2.14pre37) with the fix to the eval |
|
2386 | 2422 | problem mentioned below. |
|
2387 | 2423 | |
|
2388 | 2424 | 2002-10-17 Fernando Perez <fperez@colorado.edu> |
|
2389 | 2425 | |
|
2390 | 2426 | * IPython/ConfigLoader.py (ConfigLoader.load): Fixes for Windows |
|
2391 | 2427 | installation. Thanks to Leonardo Santagada <retype-AT-terra.com.br>. |
|
2392 | 2428 | |
|
2393 | 2429 | * IPython/iplib.py (InteractiveShell._prefilter): Many changes to |
|
2394 | 2430 | this function to fix a problem reported by Alex Schmolck. He saw |
|
2395 | 2431 | it with list comprehensions and generators, which were getting |
|
2396 | 2432 | called twice. The real problem was an 'eval' call in testing for |
|
2397 | 2433 | automagic which was evaluating the input line silently. |
|
2398 | 2434 | |
|
2399 | 2435 | This is a potentially very nasty bug, if the input has side |
|
2400 | 2436 | effects which must not be repeated. The code is much cleaner now, |
|
2401 | 2437 | without any blanket 'except' left and with a regexp test for |
|
2402 | 2438 | actual function names. |
|
2403 | 2439 | |
|
2404 | 2440 | But an eval remains, which I'm not fully comfortable with. I just |
|
2405 | 2441 | don't know how to find out if an expression could be a callable in |
|
2406 | 2442 | the user's namespace without doing an eval on the string. However |
|
2407 | 2443 | that string is now much more strictly checked so that no code |
|
2408 | 2444 | slips by, so the eval should only happen for things that can |
|
2409 | 2445 | really be only function/method names. |
|
2410 | 2446 | |
|
2411 | 2447 | 2002-10-15 Fernando Perez <fperez@colorado.edu> |
|
2412 | 2448 | |
|
2413 | 2449 | * Updated LyX to 1.2.1 so I can work on the docs again. Added Mac |
|
2414 | 2450 | OSX information to main manual, removed README_Mac_OSX file from |
|
2415 | 2451 | distribution. Also updated credits for recent additions. |
|
2416 | 2452 | |
|
2417 | 2453 | 2002-10-10 Fernando Perez <fperez@colorado.edu> |
|
2418 | 2454 | |
|
2419 | 2455 | * README_Mac_OSX: Added a README for Mac OSX users for fixing |
|
2420 | 2456 | terminal-related issues. Many thanks to Andrea Riciputi |
|
2421 | 2457 | <andrea.riciputi-AT-libero.it> for writing it. |
|
2422 | 2458 | |
|
2423 | 2459 | * IPython/UserConfig/ipythonrc.py: Fixes to various small issues, |
|
2424 | 2460 | thanks to Thorsten Kampe <thorsten-AT-thorstenkampe.de>. |
|
2425 | 2461 | |
|
2426 | 2462 | * setup.py (make_shortcut): Fixes for Windows installation. Thanks |
|
2427 | 2463 | to Fredrik Kant <fredrik.kant-AT-front.com> and Syver Enstad |
|
2428 | 2464 | <syver-en-AT-online.no> who both submitted patches for this problem. |
|
2429 | 2465 | |
|
2430 | 2466 | * IPython/iplib.py (InteractiveShell.embed_mainloop): Patch for |
|
2431 | 2467 | global embedding to make sure that things don't overwrite user |
|
2432 | 2468 | globals accidentally. Thanks to Richard <rxe-AT-renre-europe.com> |
|
2433 | 2469 | |
|
2434 | 2470 | * IPython/Gnuplot2.py (gp): Patch for Gnuplot.py 1.6 |
|
2435 | 2471 | compatibility. Thanks to Hayden Callow |
|
2436 | 2472 | <h.callow-AT-elec.canterbury.ac.nz> |
|
2437 | 2473 | |
|
2438 | 2474 | 2002-10-04 Fernando Perez <fperez@colorado.edu> |
|
2439 | 2475 | |
|
2440 | 2476 | * IPython/Gnuplot2.py (PlotItem): Added 'index' option for |
|
2441 | 2477 | Gnuplot.File objects. |
|
2442 | 2478 | |
|
2443 | 2479 | 2002-07-23 Fernando Perez <fperez@colorado.edu> |
|
2444 | 2480 | |
|
2445 | 2481 | * IPython/genutils.py (timing): Added timings() and timing() for |
|
2446 | 2482 | quick access to the most commonly needed data, the execution |
|
2447 | 2483 | times. Old timing() renamed to timings_out(). |
|
2448 | 2484 | |
|
2449 | 2485 | 2002-07-18 Fernando Perez <fperez@colorado.edu> |
|
2450 | 2486 | |
|
2451 | 2487 | * IPython/Shell.py (IPShellEmbed.restore_system_completer): fixed |
|
2452 | 2488 | bug with nested instances disrupting the parent's tab completion. |
|
2453 | 2489 | |
|
2454 | 2490 | * IPython/iplib.py (all_completions): Added Alex Schmolck's |
|
2455 | 2491 | all_completions code to begin the emacs integration. |
|
2456 | 2492 | |
|
2457 | 2493 | * IPython/Gnuplot2.py (zip_items): Added optional 'titles' |
|
2458 | 2494 | argument to allow titling individual arrays when plotting. |
|
2459 | 2495 | |
|
2460 | 2496 | 2002-07-15 Fernando Perez <fperez@colorado.edu> |
|
2461 | 2497 | |
|
2462 | 2498 | * setup.py (make_shortcut): changed to retrieve the value of |
|
2463 | 2499 | 'Program Files' directory from the registry (this value changes in |
|
2464 | 2500 | non-english versions of Windows). Thanks to Thomas Fanslau |
|
2465 | 2501 | <tfanslau-AT-gmx.de> for the report. |
|
2466 | 2502 | |
|
2467 | 2503 | 2002-07-10 Fernando Perez <fperez@colorado.edu> |
|
2468 | 2504 | |
|
2469 | 2505 | * IPython/ultraTB.py (VerboseTB.debugger): enabled workaround for |
|
2470 | 2506 | a bug in pdb, which crashes if a line with only whitespace is |
|
2471 | 2507 | entered. Bug report submitted to sourceforge. |
|
2472 | 2508 | |
|
2473 | 2509 | 2002-07-09 Fernando Perez <fperez@colorado.edu> |
|
2474 | 2510 | |
|
2475 | 2511 | * IPython/ultraTB.py (VerboseTB.nullrepr): fixed rare crash when |
|
2476 | 2512 | reporting exceptions (it's a bug in inspect.py, I just set a |
|
2477 | 2513 | workaround). |
|
2478 | 2514 | |
|
2479 | 2515 | 2002-07-08 Fernando Perez <fperez@colorado.edu> |
|
2480 | 2516 | |
|
2481 | 2517 | * IPython/iplib.py (InteractiveShell.__init__): fixed reference to |
|
2482 | 2518 | __IPYTHON__ in __builtins__ to show up in user_ns. |
|
2483 | 2519 | |
|
2484 | 2520 | 2002-07-03 Fernando Perez <fperez@colorado.edu> |
|
2485 | 2521 | |
|
2486 | 2522 | * IPython/GnuplotInteractive.py (magic_gp_set_default): changed |
|
2487 | 2523 | name from @gp_set_instance to @gp_set_default. |
|
2488 | 2524 | |
|
2489 | 2525 | * IPython/ipmaker.py (make_IPython): default editor value set to |
|
2490 | 2526 | '0' (a string), to match the rc file. Otherwise will crash when |
|
2491 | 2527 | .strip() is called on it. |
|
2492 | 2528 | |
|
2493 | 2529 | |
|
2494 | 2530 | 2002-06-28 Fernando Perez <fperez@colorado.edu> |
|
2495 | 2531 | |
|
2496 | 2532 | * IPython/iplib.py (InteractiveShell.safe_execfile): fix importing |
|
2497 | 2533 | of files in current directory when a file is executed via |
|
2498 | 2534 | @run. Patch also by RA <ralf_ahlbrink-AT-web.de>. |
|
2499 | 2535 | |
|
2500 | 2536 | * setup.py (manfiles): fix for rpm builds, submitted by RA |
|
2501 | 2537 | <ralf_ahlbrink-AT-web.de>. Now we have RPMs! |
|
2502 | 2538 | |
|
2503 | 2539 | * IPython/ipmaker.py (make_IPython): fixed lookup of default |
|
2504 | 2540 | editor when set to '0'. Problem was, '0' evaluates to True (it's a |
|
2505 | 2541 | string!). A. Schmolck caught this one. |
|
2506 | 2542 | |
|
2507 | 2543 | 2002-06-27 Fernando Perez <fperez@colorado.edu> |
|
2508 | 2544 | |
|
2509 | 2545 | * IPython/ipmaker.py (make_IPython): fixed bug when running user |
|
2510 | 2546 | defined files at the cmd line. __name__ wasn't being set to |
|
2511 | 2547 | __main__. |
|
2512 | 2548 | |
|
2513 | 2549 | * IPython/Gnuplot2.py (zip_items): improved it so it can plot also |
|
2514 | 2550 | regular lists and tuples besides Numeric arrays. |
|
2515 | 2551 | |
|
2516 | 2552 | * IPython/Prompts.py (CachedOutput.__call__): Added output |
|
2517 | 2553 | supression for input ending with ';'. Similar to Mathematica and |
|
2518 | 2554 | Matlab. The _* vars and Out[] list are still updated, just like |
|
2519 | 2555 | Mathematica behaves. |
|
2520 | 2556 | |
|
2521 | 2557 | 2002-06-25 Fernando Perez <fperez@colorado.edu> |
|
2522 | 2558 | |
|
2523 | 2559 | * IPython/ConfigLoader.py (ConfigLoader.load): fixed checking of |
|
2524 | 2560 | .ini extensions for profiels under Windows. |
|
2525 | 2561 | |
|
2526 | 2562 | * IPython/OInspect.py (Inspector.pinfo): improved alignment of |
|
2527 | 2563 | string form. Fix contributed by Alexander Schmolck |
|
2528 | 2564 | <a.schmolck-AT-gmx.net> |
|
2529 | 2565 | |
|
2530 | 2566 | * IPython/GnuplotRuntime.py (gp_new): new function. Returns a |
|
2531 | 2567 | pre-configured Gnuplot instance. |
|
2532 | 2568 | |
|
2533 | 2569 | 2002-06-21 Fernando Perez <fperez@colorado.edu> |
|
2534 | 2570 | |
|
2535 | 2571 | * IPython/numutils.py (exp_safe): new function, works around the |
|
2536 | 2572 | underflow problems in Numeric. |
|
2537 | 2573 | (log2): New fn. Safe log in base 2: returns exact integer answer |
|
2538 | 2574 | for exact integer powers of 2. |
|
2539 | 2575 | |
|
2540 | 2576 | * IPython/Magic.py (get_py_filename): fixed it not expanding '~' |
|
2541 | 2577 | properly. |
|
2542 | 2578 | |
|
2543 | 2579 | 2002-06-20 Fernando Perez <fperez@colorado.edu> |
|
2544 | 2580 | |
|
2545 | 2581 | * IPython/genutils.py (timing): new function like |
|
2546 | 2582 | Mathematica's. Similar to time_test, but returns more info. |
|
2547 | 2583 | |
|
2548 | 2584 | 2002-06-18 Fernando Perez <fperez@colorado.edu> |
|
2549 | 2585 | |
|
2550 | 2586 | * IPython/Magic.py (Magic.magic_save): modified @save and @r |
|
2551 | 2587 | according to Mike Heeter's suggestions. |
|
2552 | 2588 | |
|
2553 | 2589 | 2002-06-16 Fernando Perez <fperez@colorado.edu> |
|
2554 | 2590 | |
|
2555 | 2591 | * IPython/GnuplotRuntime.py: Massive overhaul to the Gnuplot |
|
2556 | 2592 | system. GnuplotMagic is gone as a user-directory option. New files |
|
2557 | 2593 | make it easier to use all the gnuplot stuff both from external |
|
2558 | 2594 | programs as well as from IPython. Had to rewrite part of |
|
2559 | 2595 | hardcopy() b/c of a strange bug: often the ps files simply don't |
|
2560 | 2596 | get created, and require a repeat of the command (often several |
|
2561 | 2597 | times). |
|
2562 | 2598 | |
|
2563 | 2599 | * IPython/ultraTB.py (AutoFormattedTB.__call__): changed to |
|
2564 | 2600 | resolve output channel at call time, so that if sys.stderr has |
|
2565 | 2601 | been redirected by user this gets honored. |
|
2566 | 2602 | |
|
2567 | 2603 | 2002-06-13 Fernando Perez <fperez@colorado.edu> |
|
2568 | 2604 | |
|
2569 | 2605 | * IPython/Shell.py (IPShell.__init__): Changed IPythonShell to |
|
2570 | 2606 | IPShell. Kept a copy with the old names to avoid breaking people's |
|
2571 | 2607 | embedded code. |
|
2572 | 2608 | |
|
2573 | 2609 | * IPython/ipython: simplified it to the bare minimum after |
|
2574 | 2610 | Holger's suggestions. Added info about how to use it in |
|
2575 | 2611 | PYTHONSTARTUP. |
|
2576 | 2612 | |
|
2577 | 2613 | * IPython/Shell.py (IPythonShell): changed the options passing |
|
2578 | 2614 | from a string with funky %s replacements to a straight list. Maybe |
|
2579 | 2615 | a bit more typing, but it follows sys.argv conventions, so there's |
|
2580 | 2616 | less special-casing to remember. |
|
2581 | 2617 | |
|
2582 | 2618 | 2002-06-12 Fernando Perez <fperez@colorado.edu> |
|
2583 | 2619 | |
|
2584 | 2620 | * IPython/Magic.py (Magic.magic_r): new magic auto-repeat |
|
2585 | 2621 | command. Thanks to a suggestion by Mike Heeter. |
|
2586 | 2622 | (Magic.magic_pfile): added behavior to look at filenames if given |
|
2587 | 2623 | arg is not a defined object. |
|
2588 | 2624 | (Magic.magic_save): New @save function to save code snippets. Also |
|
2589 | 2625 | a Mike Heeter idea. |
|
2590 | 2626 | |
|
2591 | 2627 | * IPython/UserConfig/GnuplotMagic.py (plot): Improvements to |
|
2592 | 2628 | plot() and replot(). Much more convenient now, especially for |
|
2593 | 2629 | interactive use. |
|
2594 | 2630 | |
|
2595 | 2631 | * IPython/Magic.py (Magic.magic_run): Added .py automatically to |
|
2596 | 2632 | filenames. |
|
2597 | 2633 | |
|
2598 | 2634 | 2002-06-02 Fernando Perez <fperez@colorado.edu> |
|
2599 | 2635 | |
|
2600 | 2636 | * IPython/Struct.py (Struct.__init__): modified to admit |
|
2601 | 2637 | initialization via another struct. |
|
2602 | 2638 | |
|
2603 | 2639 | * IPython/genutils.py (SystemExec.__init__): New stateful |
|
2604 | 2640 | interface to xsys and bq. Useful for writing system scripts. |
|
2605 | 2641 | |
|
2606 | 2642 | 2002-05-30 Fernando Perez <fperez@colorado.edu> |
|
2607 | 2643 | |
|
2608 | 2644 | * MANIFEST.in: Changed docfile selection to exclude all the lyx |
|
2609 | 2645 | documents. This will make the user download smaller (it's getting |
|
2610 | 2646 | too big). |
|
2611 | 2647 | |
|
2612 | 2648 | 2002-05-29 Fernando Perez <fperez@colorado.edu> |
|
2613 | 2649 | |
|
2614 | 2650 | * IPython/iplib.py (_FakeModule.__init__): New class introduced to |
|
2615 | 2651 | fix problems with shelve and pickle. Seems to work, but I don't |
|
2616 | 2652 | know if corner cases break it. Thanks to Mike Heeter |
|
2617 | 2653 | <korora-AT-SDF.LONESTAR.ORG> for the bug reports and test cases. |
|
2618 | 2654 | |
|
2619 | 2655 | 2002-05-24 Fernando Perez <fperez@colorado.edu> |
|
2620 | 2656 | |
|
2621 | 2657 | * IPython/Magic.py (Macro.__init__): fixed magics embedded in |
|
2622 | 2658 | macros having broken. |
|
2623 | 2659 | |
|
2624 | 2660 | 2002-05-21 Fernando Perez <fperez@colorado.edu> |
|
2625 | 2661 | |
|
2626 | 2662 | * IPython/Magic.py (Magic.magic_logstart): fixed recently |
|
2627 | 2663 | introduced logging bug: all history before logging started was |
|
2628 | 2664 | being written one character per line! This came from the redesign |
|
2629 | 2665 | of the input history as a special list which slices to strings, |
|
2630 | 2666 | not to lists. |
|
2631 | 2667 | |
|
2632 | 2668 | 2002-05-20 Fernando Perez <fperez@colorado.edu> |
|
2633 | 2669 | |
|
2634 | 2670 | * IPython/Prompts.py (CachedOutput.__init__): made the color table |
|
2635 | 2671 | be an attribute of all classes in this module. The design of these |
|
2636 | 2672 | classes needs some serious overhauling. |
|
2637 | 2673 | |
|
2638 | 2674 | * IPython/DPyGetOpt.py (DPyGetOpt.setPosixCompliance): fixed bug |
|
2639 | 2675 | which was ignoring '_' in option names. |
|
2640 | 2676 | |
|
2641 | 2677 | * IPython/ultraTB.py (FormattedTB.__init__): Changed |
|
2642 | 2678 | 'Verbose_novars' to 'Context' and made it the new default. It's a |
|
2643 | 2679 | bit more readable and also safer than verbose. |
|
2644 | 2680 | |
|
2645 | 2681 | * IPython/PyColorize.py (Parser.__call__): Fixed coloring of |
|
2646 | 2682 | triple-quoted strings. |
|
2647 | 2683 | |
|
2648 | 2684 | * IPython/OInspect.py (__all__): new module exposing the object |
|
2649 | 2685 | introspection facilities. Now the corresponding magics are dummy |
|
2650 | 2686 | wrappers around this. Having this module will make it much easier |
|
2651 | 2687 | to put these functions into our modified pdb. |
|
2652 | 2688 | This new object inspector system uses the new colorizing module, |
|
2653 | 2689 | so source code and other things are nicely syntax highlighted. |
|
2654 | 2690 | |
|
2655 | 2691 | 2002-05-18 Fernando Perez <fperez@colorado.edu> |
|
2656 | 2692 | |
|
2657 | 2693 | * IPython/ColorANSI.py: Split the coloring tools into a separate |
|
2658 | 2694 | module so I can use them in other code easier (they were part of |
|
2659 | 2695 | ultraTB). |
|
2660 | 2696 | |
|
2661 | 2697 | 2002-05-17 Fernando Perez <fperez@colorado.edu> |
|
2662 | 2698 | |
|
2663 | 2699 | * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance): |
|
2664 | 2700 | fixed it to set the global 'g' also to the called instance, as |
|
2665 | 2701 | long as 'g' was still a gnuplot instance (so it doesn't overwrite |
|
2666 | 2702 | user's 'g' variables). |
|
2667 | 2703 | |
|
2668 | 2704 | * IPython/iplib.py (InteractiveShell.__init__): Added In/Out |
|
2669 | 2705 | global variables (aliases to _ih,_oh) so that users which expect |
|
2670 | 2706 | In[5] or Out[7] to work aren't unpleasantly surprised. |
|
2671 | 2707 | (InputList.__getslice__): new class to allow executing slices of |
|
2672 | 2708 | input history directly. Very simple class, complements the use of |
|
2673 | 2709 | macros. |
|
2674 | 2710 | |
|
2675 | 2711 | 2002-05-16 Fernando Perez <fperez@colorado.edu> |
|
2676 | 2712 | |
|
2677 | 2713 | * setup.py (docdirbase): make doc directory be just doc/IPython |
|
2678 | 2714 | without version numbers, it will reduce clutter for users. |
|
2679 | 2715 | |
|
2680 | 2716 | * IPython/Magic.py (Magic.magic_run): Add explicit local dict to |
|
2681 | 2717 | execfile call to prevent possible memory leak. See for details: |
|
2682 | 2718 | http://mail.python.org/pipermail/python-list/2002-February/088476.html |
|
2683 | 2719 | |
|
2684 | 2720 | 2002-05-15 Fernando Perez <fperez@colorado.edu> |
|
2685 | 2721 | |
|
2686 | 2722 | * IPython/Magic.py (Magic.magic_psource): made the object |
|
2687 | 2723 | introspection names be more standard: pdoc, pdef, pfile and |
|
2688 | 2724 | psource. They all print/page their output, and it makes |
|
2689 | 2725 | remembering them easier. Kept old names for compatibility as |
|
2690 | 2726 | aliases. |
|
2691 | 2727 | |
|
2692 | 2728 | 2002-05-14 Fernando Perez <fperez@colorado.edu> |
|
2693 | 2729 | |
|
2694 | 2730 | * IPython/UserConfig/GnuplotMagic.py: I think I finally understood |
|
2695 | 2731 | what the mouse problem was. The trick is to use gnuplot with temp |
|
2696 | 2732 | files and NOT with pipes (for data communication), because having |
|
2697 | 2733 | both pipes and the mouse on is bad news. |
|
2698 | 2734 | |
|
2699 | 2735 | 2002-05-13 Fernando Perez <fperez@colorado.edu> |
|
2700 | 2736 | |
|
2701 | 2737 | * IPython/Magic.py (Magic._ofind): fixed namespace order search |
|
2702 | 2738 | bug. Information would be reported about builtins even when |
|
2703 | 2739 | user-defined functions overrode them. |
|
2704 | 2740 | |
|
2705 | 2741 | 2002-05-11 Fernando Perez <fperez@colorado.edu> |
|
2706 | 2742 | |
|
2707 | 2743 | * IPython/__init__.py (__all__): removed FlexCompleter from |
|
2708 | 2744 | __all__ so that things don't fail in platforms without readline. |
|
2709 | 2745 | |
|
2710 | 2746 | 2002-05-10 Fernando Perez <fperez@colorado.edu> |
|
2711 | 2747 | |
|
2712 | 2748 | * IPython/__init__.py (__all__): removed numutils from __all__ b/c |
|
2713 | 2749 | it requires Numeric, effectively making Numeric a dependency for |
|
2714 | 2750 | IPython. |
|
2715 | 2751 | |
|
2716 | 2752 | * Released 0.2.13 |
|
2717 | 2753 | |
|
2718 | 2754 | * IPython/Magic.py (Magic.magic_prun): big overhaul to the |
|
2719 | 2755 | profiler interface. Now all the major options from the profiler |
|
2720 | 2756 | module are directly supported in IPython, both for single |
|
2721 | 2757 | expressions (@prun) and for full programs (@run -p). |
|
2722 | 2758 | |
|
2723 | 2759 | 2002-05-09 Fernando Perez <fperez@colorado.edu> |
|
2724 | 2760 | |
|
2725 | 2761 | * IPython/Magic.py (Magic.magic_doc): fixed to show docstrings of |
|
2726 | 2762 | magic properly formatted for screen. |
|
2727 | 2763 | |
|
2728 | 2764 | * setup.py (make_shortcut): Changed things to put pdf version in |
|
2729 | 2765 | doc/ instead of doc/manual (had to change lyxport a bit). |
|
2730 | 2766 | |
|
2731 | 2767 | * IPython/Magic.py (Profile.string_stats): made profile runs go |
|
2732 | 2768 | through pager (they are long and a pager allows searching, saving, |
|
2733 | 2769 | etc.) |
|
2734 | 2770 | |
|
2735 | 2771 | 2002-05-08 Fernando Perez <fperez@colorado.edu> |
|
2736 | 2772 | |
|
2737 | 2773 | * Released 0.2.12 |
|
2738 | 2774 | |
|
2739 | 2775 | 2002-05-06 Fernando Perez <fperez@colorado.edu> |
|
2740 | 2776 | |
|
2741 | 2777 | * IPython/Magic.py (Magic.magic_hist): small bug fixed (recently |
|
2742 | 2778 | introduced); 'hist n1 n2' was broken. |
|
2743 | 2779 | (Magic.magic_pdb): added optional on/off arguments to @pdb |
|
2744 | 2780 | (Magic.magic_run): added option -i to @run, which executes code in |
|
2745 | 2781 | the IPython namespace instead of a clean one. Also added @irun as |
|
2746 | 2782 | an alias to @run -i. |
|
2747 | 2783 | |
|
2748 | 2784 | * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance): |
|
2749 | 2785 | fixed (it didn't really do anything, the namespaces were wrong). |
|
2750 | 2786 | |
|
2751 | 2787 | * IPython/Debugger.py (__init__): Added workaround for python 2.1 |
|
2752 | 2788 | |
|
2753 | 2789 | * IPython/__init__.py (__all__): Fixed package namespace, now |
|
2754 | 2790 | 'import IPython' does give access to IPython.<all> as |
|
2755 | 2791 | expected. Also renamed __release__ to Release. |
|
2756 | 2792 | |
|
2757 | 2793 | * IPython/Debugger.py (__license__): created new Pdb class which |
|
2758 | 2794 | functions like a drop-in for the normal pdb.Pdb but does NOT |
|
2759 | 2795 | import readline by default. This way it doesn't muck up IPython's |
|
2760 | 2796 | readline handling, and now tab-completion finally works in the |
|
2761 | 2797 | debugger -- sort of. It completes things globally visible, but the |
|
2762 | 2798 | completer doesn't track the stack as pdb walks it. That's a bit |
|
2763 | 2799 | tricky, and I'll have to implement it later. |
|
2764 | 2800 | |
|
2765 | 2801 | 2002-05-05 Fernando Perez <fperez@colorado.edu> |
|
2766 | 2802 | |
|
2767 | 2803 | * IPython/Magic.py (Magic.magic_oinfo): fixed formatting bug for |
|
2768 | 2804 | magic docstrings when printed via ? (explicit \'s were being |
|
2769 | 2805 | printed). |
|
2770 | 2806 | |
|
2771 | 2807 | * IPython/ipmaker.py (make_IPython): fixed namespace |
|
2772 | 2808 | identification bug. Now variables loaded via logs or command-line |
|
2773 | 2809 | files are recognized in the interactive namespace by @who. |
|
2774 | 2810 | |
|
2775 | 2811 | * IPython/iplib.py (InteractiveShell.safe_execfile): Fixed bug in |
|
2776 | 2812 | log replay system stemming from the string form of Structs. |
|
2777 | 2813 | |
|
2778 | 2814 | * IPython/Magic.py (Macro.__init__): improved macros to properly |
|
2779 | 2815 | handle magic commands in them. |
|
2780 | 2816 | (Magic.magic_logstart): usernames are now expanded so 'logstart |
|
2781 | 2817 | ~/mylog' now works. |
|
2782 | 2818 | |
|
2783 | 2819 | * IPython/iplib.py (complete): fixed bug where paths starting with |
|
2784 | 2820 | '/' would be completed as magic names. |
|
2785 | 2821 | |
|
2786 | 2822 | 2002-05-04 Fernando Perez <fperez@colorado.edu> |
|
2787 | 2823 | |
|
2788 | 2824 | * IPython/Magic.py (Magic.magic_run): added options -p and -f to |
|
2789 | 2825 | allow running full programs under the profiler's control. |
|
2790 | 2826 | |
|
2791 | 2827 | * IPython/ultraTB.py (FormattedTB.__init__): Added Verbose_novars |
|
2792 | 2828 | mode to report exceptions verbosely but without formatting |
|
2793 | 2829 | variables. This addresses the issue of ipython 'freezing' (it's |
|
2794 | 2830 | not frozen, but caught in an expensive formatting loop) when huge |
|
2795 | 2831 | variables are in the context of an exception. |
|
2796 | 2832 | (VerboseTB.text): Added '--->' markers at line where exception was |
|
2797 | 2833 | triggered. Much clearer to read, especially in NoColor modes. |
|
2798 | 2834 | |
|
2799 | 2835 | * IPython/Magic.py (Magic.magic_run): bugfix: -n option had been |
|
2800 | 2836 | implemented in reverse when changing to the new parse_options(). |
|
2801 | 2837 | |
|
2802 | 2838 | 2002-05-03 Fernando Perez <fperez@colorado.edu> |
|
2803 | 2839 | |
|
2804 | 2840 | * IPython/Magic.py (Magic.parse_options): new function so that |
|
2805 | 2841 | magics can parse options easier. |
|
2806 | 2842 | (Magic.magic_prun): new function similar to profile.run(), |
|
2807 | 2843 | suggested by Chris Hart. |
|
2808 | 2844 | (Magic.magic_cd): fixed behavior so that it only changes if |
|
2809 | 2845 | directory actually is in history. |
|
2810 | 2846 | |
|
2811 | 2847 | * IPython/usage.py (__doc__): added information about potential |
|
2812 | 2848 | slowness of Verbose exception mode when there are huge data |
|
2813 | 2849 | structures to be formatted (thanks to Archie Paulson). |
|
2814 | 2850 | |
|
2815 | 2851 | * IPython/ipmaker.py (make_IPython): Changed default logging |
|
2816 | 2852 | (when simply called with -log) to use curr_dir/ipython.log in |
|
2817 | 2853 | rotate mode. Fixed crash which was occuring with -log before |
|
2818 | 2854 | (thanks to Jim Boyle). |
|
2819 | 2855 | |
|
2820 | 2856 | 2002-05-01 Fernando Perez <fperez@colorado.edu> |
|
2821 | 2857 | |
|
2822 | 2858 | * Released 0.2.11 for these fixes (mainly the ultraTB one which |
|
2823 | 2859 | was nasty -- though somewhat of a corner case). |
|
2824 | 2860 | |
|
2825 | 2861 | * IPython/ultraTB.py (AutoFormattedTB.text): renamed __text to |
|
2826 | 2862 | text (was a bug). |
|
2827 | 2863 | |
|
2828 | 2864 | 2002-04-30 Fernando Perez <fperez@colorado.edu> |
|
2829 | 2865 | |
|
2830 | 2866 | * IPython/UserConfig/GnuplotMagic.py (magic_gp): Minor fix to add |
|
2831 | 2867 | a print after ^D or ^C from the user so that the In[] prompt |
|
2832 | 2868 | doesn't over-run the gnuplot one. |
|
2833 | 2869 | |
|
2834 | 2870 | 2002-04-29 Fernando Perez <fperez@colorado.edu> |
|
2835 | 2871 | |
|
2836 | 2872 | * Released 0.2.10 |
|
2837 | 2873 | |
|
2838 | 2874 | * IPython/__release__.py (version): get date dynamically. |
|
2839 | 2875 | |
|
2840 | 2876 | * Misc. documentation updates thanks to Arnd's comments. Also ran |
|
2841 | 2877 | a full spellcheck on the manual (hadn't been done in a while). |
|
2842 | 2878 | |
|
2843 | 2879 | 2002-04-27 Fernando Perez <fperez@colorado.edu> |
|
2844 | 2880 | |
|
2845 | 2881 | * IPython/Magic.py (Magic.magic_logstart): Fixed bug where |
|
2846 | 2882 | starting a log in mid-session would reset the input history list. |
|
2847 | 2883 | |
|
2848 | 2884 | 2002-04-26 Fernando Perez <fperez@colorado.edu> |
|
2849 | 2885 | |
|
2850 | 2886 | * IPython/iplib.py (InteractiveShell.wait): Fixed bug where not |
|
2851 | 2887 | all files were being included in an update. Now anything in |
|
2852 | 2888 | UserConfig that matches [A-Za-z]*.py will go (this excludes |
|
2853 | 2889 | __init__.py) |
|
2854 | 2890 | |
|
2855 | 2891 | 2002-04-25 Fernando Perez <fperez@colorado.edu> |
|
2856 | 2892 | |
|
2857 | 2893 | * IPython/iplib.py (InteractiveShell.__init__): Added __IPYTHON__ |
|
2858 | 2894 | to __builtins__ so that any form of embedded or imported code can |
|
2859 | 2895 | test for being inside IPython. |
|
2860 | 2896 | |
|
2861 | 2897 | * IPython/UserConfig/GnuplotMagic.py: (magic_gp_set_instance): |
|
2862 | 2898 | changed to GnuplotMagic because it's now an importable module, |
|
2863 | 2899 | this makes the name follow that of the standard Gnuplot module. |
|
2864 | 2900 | GnuplotMagic can now be loaded at any time in mid-session. |
|
2865 | 2901 | |
|
2866 | 2902 | 2002-04-24 Fernando Perez <fperez@colorado.edu> |
|
2867 | 2903 | |
|
2868 | 2904 | * IPython/numutils.py: removed SIUnits. It doesn't properly set |
|
2869 | 2905 | the globals (IPython has its own namespace) and the |
|
2870 | 2906 | PhysicalQuantity stuff is much better anyway. |
|
2871 | 2907 | |
|
2872 | 2908 | * IPython/UserConfig/example-gnuplot.py (g2): Added gnuplot |
|
2873 | 2909 | embedding example to standard user directory for |
|
2874 | 2910 | distribution. Also put it in the manual. |
|
2875 | 2911 | |
|
2876 | 2912 | * IPython/numutils.py (gnuplot_exec): Changed to take a gnuplot |
|
2877 | 2913 | instance as first argument (so it doesn't rely on some obscure |
|
2878 | 2914 | hidden global). |
|
2879 | 2915 | |
|
2880 | 2916 | * IPython/UserConfig/ipythonrc.py: put () back in accepted |
|
2881 | 2917 | delimiters. While it prevents ().TAB from working, it allows |
|
2882 | 2918 | completions in open (... expressions. This is by far a more common |
|
2883 | 2919 | case. |
|
2884 | 2920 | |
|
2885 | 2921 | 2002-04-23 Fernando Perez <fperez@colorado.edu> |
|
2886 | 2922 | |
|
2887 | 2923 | * IPython/Extensions/InterpreterPasteInput.py: new |
|
2888 | 2924 | syntax-processing module for pasting lines with >>> or ... at the |
|
2889 | 2925 | start. |
|
2890 | 2926 | |
|
2891 | 2927 | * IPython/Extensions/PhysicalQ_Interactive.py |
|
2892 | 2928 | (PhysicalQuantityInteractive.__int__): fixed to work with either |
|
2893 | 2929 | Numeric or math. |
|
2894 | 2930 | |
|
2895 | 2931 | * IPython/UserConfig/ipythonrc-numeric.py: reorganized the |
|
2896 | 2932 | provided profiles. Now we have: |
|
2897 | 2933 | -math -> math module as * and cmath with its own namespace. |
|
2898 | 2934 | -numeric -> Numeric as *, plus gnuplot & grace |
|
2899 | 2935 | -physics -> same as before |
|
2900 | 2936 | |
|
2901 | 2937 | * IPython/Magic.py (Magic.magic_magic): Fixed bug where |
|
2902 | 2938 | user-defined magics wouldn't be found by @magic if they were |
|
2903 | 2939 | defined as class methods. Also cleaned up the namespace search |
|
2904 | 2940 | logic and the string building (to use %s instead of many repeated |
|
2905 | 2941 | string adds). |
|
2906 | 2942 | |
|
2907 | 2943 | * IPython/UserConfig/example-magic.py (magic_foo): updated example |
|
2908 | 2944 | of user-defined magics to operate with class methods (cleaner, in |
|
2909 | 2945 | line with the gnuplot code). |
|
2910 | 2946 | |
|
2911 | 2947 | 2002-04-22 Fernando Perez <fperez@colorado.edu> |
|
2912 | 2948 | |
|
2913 | 2949 | * setup.py: updated dependency list so that manual is updated when |
|
2914 | 2950 | all included files change. |
|
2915 | 2951 | |
|
2916 | 2952 | * IPython/ipmaker.py (make_IPython): Fixed bug which was ignoring |
|
2917 | 2953 | the delimiter removal option (the fix is ugly right now). |
|
2918 | 2954 | |
|
2919 | 2955 | * IPython/UserConfig/ipythonrc-physics.py: simplified not to load |
|
2920 | 2956 | all of the math profile (quicker loading, no conflict between |
|
2921 | 2957 | g-9.8 and g-gnuplot). |
|
2922 | 2958 | |
|
2923 | 2959 | * IPython/CrashHandler.py (CrashHandler.__call__): changed default |
|
2924 | 2960 | name of post-mortem files to IPython_crash_report.txt. |
|
2925 | 2961 | |
|
2926 | 2962 | * Cleanup/update of the docs. Added all the new readline info and |
|
2927 | 2963 | formatted all lists as 'real lists'. |
|
2928 | 2964 | |
|
2929 | 2965 | * IPython/ipmaker.py (make_IPython): removed now-obsolete |
|
2930 | 2966 | tab-completion options, since the full readline parse_and_bind is |
|
2931 | 2967 | now accessible. |
|
2932 | 2968 | |
|
2933 | 2969 | * IPython/iplib.py (InteractiveShell.init_readline): Changed |
|
2934 | 2970 | handling of readline options. Now users can specify any string to |
|
2935 | 2971 | be passed to parse_and_bind(), as well as the delimiters to be |
|
2936 | 2972 | removed. |
|
2937 | 2973 | (InteractiveShell.__init__): Added __name__ to the global |
|
2938 | 2974 | namespace so that things like Itpl which rely on its existence |
|
2939 | 2975 | don't crash. |
|
2940 | 2976 | (InteractiveShell._prefilter): Defined the default with a _ so |
|
2941 | 2977 | that prefilter() is easier to override, while the default one |
|
2942 | 2978 | remains available. |
|
2943 | 2979 | |
|
2944 | 2980 | 2002-04-18 Fernando Perez <fperez@colorado.edu> |
|
2945 | 2981 | |
|
2946 | 2982 | * Added information about pdb in the docs. |
|
2947 | 2983 | |
|
2948 | 2984 | 2002-04-17 Fernando Perez <fperez@colorado.edu> |
|
2949 | 2985 | |
|
2950 | 2986 | * IPython/ipmaker.py (make_IPython): added rc_override option to |
|
2951 | 2987 | allow passing config options at creation time which may override |
|
2952 | 2988 | anything set in the config files or command line. This is |
|
2953 | 2989 | particularly useful for configuring embedded instances. |
|
2954 | 2990 | |
|
2955 | 2991 | 2002-04-15 Fernando Perez <fperez@colorado.edu> |
|
2956 | 2992 | |
|
2957 | 2993 | * IPython/Logger.py (Logger.log): Fixed a nasty bug which could |
|
2958 | 2994 | crash embedded instances because of the input cache falling out of |
|
2959 | 2995 | sync with the output counter. |
|
2960 | 2996 | |
|
2961 | 2997 | * IPython/Shell.py (IPythonShellEmbed.__init__): added a debug |
|
2962 | 2998 | mode which calls pdb after an uncaught exception in IPython itself. |
|
2963 | 2999 | |
|
2964 | 3000 | 2002-04-14 Fernando Perez <fperez@colorado.edu> |
|
2965 | 3001 | |
|
2966 | 3002 | * IPython/iplib.py (InteractiveShell.showtraceback): pdb mucks up |
|
2967 | 3003 | readline, fix it back after each call. |
|
2968 | 3004 | |
|
2969 | 3005 | * IPython/ultraTB.py (AutoFormattedTB.__text): made text a private |
|
2970 | 3006 | method to force all access via __call__(), which guarantees that |
|
2971 | 3007 | traceback references are properly deleted. |
|
2972 | 3008 | |
|
2973 | 3009 | * IPython/Prompts.py (CachedOutput._display): minor fixes to |
|
2974 | 3010 | improve printing when pprint is in use. |
|
2975 | 3011 | |
|
2976 | 3012 | 2002-04-13 Fernando Perez <fperez@colorado.edu> |
|
2977 | 3013 | |
|
2978 | 3014 | * IPython/Shell.py (IPythonShellEmbed.__call__): SystemExit |
|
2979 | 3015 | exceptions aren't caught anymore. If the user triggers one, he |
|
2980 | 3016 | should know why he's doing it and it should go all the way up, |
|
2981 | 3017 | just like any other exception. So now @abort will fully kill the |
|
2982 | 3018 | embedded interpreter and the embedding code (unless that happens |
|
2983 | 3019 | to catch SystemExit). |
|
2984 | 3020 | |
|
2985 | 3021 | * IPython/ultraTB.py (VerboseTB.__init__): added a call_pdb flag |
|
2986 | 3022 | and a debugger() method to invoke the interactive pdb debugger |
|
2987 | 3023 | after printing exception information. Also added the corresponding |
|
2988 | 3024 | -pdb option and @pdb magic to control this feature, and updated |
|
2989 | 3025 | the docs. After a suggestion from Christopher Hart |
|
2990 | 3026 | (hart-AT-caltech.edu). |
|
2991 | 3027 | |
|
2992 | 3028 | 2002-04-12 Fernando Perez <fperez@colorado.edu> |
|
2993 | 3029 | |
|
2994 | 3030 | * IPython/Shell.py (IPythonShellEmbed.__init__): modified to use |
|
2995 | 3031 | the exception handlers defined by the user (not the CrashHandler) |
|
2996 | 3032 | so that user exceptions don't trigger an ipython bug report. |
|
2997 | 3033 | |
|
2998 | 3034 | * IPython/ultraTB.py (ColorTB.__init__): made the color scheme |
|
2999 | 3035 | configurable (it should have always been so). |
|
3000 | 3036 | |
|
3001 | 3037 | 2002-03-26 Fernando Perez <fperez@colorado.edu> |
|
3002 | 3038 | |
|
3003 | 3039 | * IPython/Shell.py (IPythonShellEmbed.__call__): many changes here |
|
3004 | 3040 | and there to fix embedding namespace issues. This should all be |
|
3005 | 3041 | done in a more elegant way. |
|
3006 | 3042 | |
|
3007 | 3043 | 2002-03-25 Fernando Perez <fperez@colorado.edu> |
|
3008 | 3044 | |
|
3009 | 3045 | * IPython/genutils.py (get_home_dir): Try to make it work under |
|
3010 | 3046 | win9x also. |
|
3011 | 3047 | |
|
3012 | 3048 | 2002-03-20 Fernando Perez <fperez@colorado.edu> |
|
3013 | 3049 | |
|
3014 | 3050 | * IPython/Shell.py (IPythonShellEmbed.__init__): leave |
|
3015 | 3051 | sys.displayhook untouched upon __init__. |
|
3016 | 3052 | |
|
3017 | 3053 | 2002-03-19 Fernando Perez <fperez@colorado.edu> |
|
3018 | 3054 | |
|
3019 | 3055 | * Released 0.2.9 (for embedding bug, basically). |
|
3020 | 3056 | |
|
3021 | 3057 | * IPython/Shell.py (IPythonShellEmbed.__call__): Trap SystemExit |
|
3022 | 3058 | exceptions so that enclosing shell's state can be restored. |
|
3023 | 3059 | |
|
3024 | 3060 | * Changed magic_gnuplot.py to magic-gnuplot.py to standardize |
|
3025 | 3061 | naming conventions in the .ipython/ dir. |
|
3026 | 3062 | |
|
3027 | 3063 | * IPython/iplib.py (InteractiveShell.init_readline): removed '-' |
|
3028 | 3064 | from delimiters list so filenames with - in them get expanded. |
|
3029 | 3065 | |
|
3030 | 3066 | * IPython/Shell.py (IPythonShellEmbed.__call__): fixed bug with |
|
3031 | 3067 | sys.displayhook not being properly restored after an embedded call. |
|
3032 | 3068 | |
|
3033 | 3069 | 2002-03-18 Fernando Perez <fperez@colorado.edu> |
|
3034 | 3070 | |
|
3035 | 3071 | * Released 0.2.8 |
|
3036 | 3072 | |
|
3037 | 3073 | * IPython/iplib.py (InteractiveShell.user_setup): fixed bug where |
|
3038 | 3074 | some files weren't being included in a -upgrade. |
|
3039 | 3075 | (InteractiveShell.init_readline): Added 'set show-all-if-ambiguous |
|
3040 | 3076 | on' so that the first tab completes. |
|
3041 | 3077 | (InteractiveShell.handle_magic): fixed bug with spaces around |
|
3042 | 3078 | quotes breaking many magic commands. |
|
3043 | 3079 | |
|
3044 | 3080 | * setup.py: added note about ignoring the syntax error messages at |
|
3045 | 3081 | installation. |
|
3046 | 3082 | |
|
3047 | 3083 | * IPython/UserConfig/magic_gnuplot.py (magic_gp): finished |
|
3048 | 3084 | streamlining the gnuplot interface, now there's only one magic @gp. |
|
3049 | 3085 | |
|
3050 | 3086 | 2002-03-17 Fernando Perez <fperez@colorado.edu> |
|
3051 | 3087 | |
|
3052 | 3088 | * IPython/UserConfig/magic_gnuplot.py: new name for the |
|
3053 | 3089 | example-magic_pm.py file. Much enhanced system, now with a shell |
|
3054 | 3090 | for communicating directly with gnuplot, one command at a time. |
|
3055 | 3091 | |
|
3056 | 3092 | * IPython/Magic.py (Magic.magic_run): added option -n to prevent |
|
3057 | 3093 | setting __name__=='__main__'. |
|
3058 | 3094 | |
|
3059 | 3095 | * IPython/UserConfig/example-magic_pm.py (magic_pm): Added |
|
3060 | 3096 | mini-shell for accessing gnuplot from inside ipython. Should |
|
3061 | 3097 | extend it later for grace access too. Inspired by Arnd's |
|
3062 | 3098 | suggestion. |
|
3063 | 3099 | |
|
3064 | 3100 | * IPython/iplib.py (InteractiveShell.handle_magic): fixed bug when |
|
3065 | 3101 | calling magic functions with () in their arguments. Thanks to Arnd |
|
3066 | 3102 | Baecker for pointing this to me. |
|
3067 | 3103 | |
|
3068 | 3104 | * IPython/numutils.py (sum_flat): fixed bug. Would recurse |
|
3069 | 3105 | infinitely for integer or complex arrays (only worked with floats). |
|
3070 | 3106 | |
|
3071 | 3107 | 2002-03-16 Fernando Perez <fperez@colorado.edu> |
|
3072 | 3108 | |
|
3073 | 3109 | * setup.py: Merged setup and setup_windows into a single script |
|
3074 | 3110 | which properly handles things for windows users. |
|
3075 | 3111 | |
|
3076 | 3112 | 2002-03-15 Fernando Perez <fperez@colorado.edu> |
|
3077 | 3113 | |
|
3078 | 3114 | * Big change to the manual: now the magics are all automatically |
|
3079 | 3115 | documented. This information is generated from their docstrings |
|
3080 | 3116 | and put in a latex file included by the manual lyx file. This way |
|
3081 | 3117 | we get always up to date information for the magics. The manual |
|
3082 | 3118 | now also has proper version information, also auto-synced. |
|
3083 | 3119 | |
|
3084 | 3120 | For this to work, an undocumented --magic_docstrings option was added. |
|
3085 | 3121 | |
|
3086 | 3122 | 2002-03-13 Fernando Perez <fperez@colorado.edu> |
|
3087 | 3123 | |
|
3088 | 3124 | * IPython/ultraTB.py (TermColors): fixed problem with dark colors |
|
3089 | 3125 | under CDE terminals. An explicit ;2 color reset is needed in the escapes. |
|
3090 | 3126 | |
|
3091 | 3127 | 2002-03-12 Fernando Perez <fperez@colorado.edu> |
|
3092 | 3128 | |
|
3093 | 3129 | * IPython/ultraTB.py (TermColors): changed color escapes again to |
|
3094 | 3130 | fix the (old, reintroduced) line-wrapping bug. Basically, if |
|
3095 | 3131 | \001..\002 aren't given in the color escapes, lines get wrapped |
|
3096 | 3132 | weirdly. But giving those screws up old xterms and emacs terms. So |
|
3097 | 3133 | I added some logic for emacs terms to be ok, but I can't identify old |
|
3098 | 3134 | xterms separately ($TERM=='xterm' for many terminals, like konsole). |
|
3099 | 3135 | |
|
3100 | 3136 | 2002-03-10 Fernando Perez <fperez@colorado.edu> |
|
3101 | 3137 | |
|
3102 | 3138 | * IPython/usage.py (__doc__): Various documentation cleanups and |
|
3103 | 3139 | updates, both in usage docstrings and in the manual. |
|
3104 | 3140 | |
|
3105 | 3141 | * IPython/Prompts.py (CachedOutput.set_colors): cleanups for |
|
3106 | 3142 | handling of caching. Set minimum acceptabe value for having a |
|
3107 | 3143 | cache at 20 values. |
|
3108 | 3144 | |
|
3109 | 3145 | * IPython/iplib.py (InteractiveShell.user_setup): moved the |
|
3110 | 3146 | install_first_time function to a method, renamed it and added an |
|
3111 | 3147 | 'upgrade' mode. Now people can update their config directory with |
|
3112 | 3148 | a simple command line switch (-upgrade, also new). |
|
3113 | 3149 | |
|
3114 | 3150 | * IPython/Magic.py (Magic.magic_pfile): Made @pfile an alias to |
|
3115 | 3151 | @file (convenient for automagic users under Python >= 2.2). |
|
3116 | 3152 | Removed @files (it seemed more like a plural than an abbrev. of |
|
3117 | 3153 | 'file show'). |
|
3118 | 3154 | |
|
3119 | 3155 | * IPython/iplib.py (install_first_time): Fixed crash if there were |
|
3120 | 3156 | backup files ('~') in .ipython/ install directory. |
|
3121 | 3157 | |
|
3122 | 3158 | * IPython/ipmaker.py (make_IPython): fixes for new prompt |
|
3123 | 3159 | system. Things look fine, but these changes are fairly |
|
3124 | 3160 | intrusive. Test them for a few days. |
|
3125 | 3161 | |
|
3126 | 3162 | * IPython/Prompts.py (CachedOutput.__init__): Massive rewrite of |
|
3127 | 3163 | the prompts system. Now all in/out prompt strings are user |
|
3128 | 3164 | controllable. This is particularly useful for embedding, as one |
|
3129 | 3165 | can tag embedded instances with particular prompts. |
|
3130 | 3166 | |
|
3131 | 3167 | Also removed global use of sys.ps1/2, which now allows nested |
|
3132 | 3168 | embeddings without any problems. Added command-line options for |
|
3133 | 3169 | the prompt strings. |
|
3134 | 3170 | |
|
3135 | 3171 | 2002-03-08 Fernando Perez <fperez@colorado.edu> |
|
3136 | 3172 | |
|
3137 | 3173 | * IPython/UserConfig/example-embed-short.py (ipshell): added |
|
3138 | 3174 | example file with the bare minimum code for embedding. |
|
3139 | 3175 | |
|
3140 | 3176 | * IPython/Shell.py (IPythonShellEmbed.set_dummy_mode): added |
|
3141 | 3177 | functionality for the embeddable shell to be activated/deactivated |
|
3142 | 3178 | either globally or at each call. |
|
3143 | 3179 | |
|
3144 | 3180 | * IPython/Prompts.py (Prompt1.auto_rewrite): Fixes the problem of |
|
3145 | 3181 | rewriting the prompt with '--->' for auto-inputs with proper |
|
3146 | 3182 | coloring. Now the previous UGLY hack in handle_auto() is gone, and |
|
3147 | 3183 | this is handled by the prompts class itself, as it should. |
|
3148 | 3184 | |
|
3149 | 3185 | 2002-03-05 Fernando Perez <fperez@colorado.edu> |
|
3150 | 3186 | |
|
3151 | 3187 | * IPython/Magic.py (Magic.magic_logstart): Changed @log to |
|
3152 | 3188 | @logstart to avoid name clashes with the math log function. |
|
3153 | 3189 | |
|
3154 | 3190 | * Big updates to X/Emacs section of the manual. |
|
3155 | 3191 | |
|
3156 | 3192 | * Removed ipython_emacs. Milan explained to me how to pass |
|
3157 | 3193 | arguments to ipython through Emacs. Some day I'm going to end up |
|
3158 | 3194 | learning some lisp... |
|
3159 | 3195 | |
|
3160 | 3196 | 2002-03-04 Fernando Perez <fperez@colorado.edu> |
|
3161 | 3197 | |
|
3162 | 3198 | * IPython/ipython_emacs: Created script to be used as the |
|
3163 | 3199 | py-python-command Emacs variable so we can pass IPython |
|
3164 | 3200 | parameters. I can't figure out how to tell Emacs directly to pass |
|
3165 | 3201 | parameters to IPython, so a dummy shell script will do it. |
|
3166 | 3202 | |
|
3167 | 3203 | Other enhancements made for things to work better under Emacs' |
|
3168 | 3204 | various types of terminals. Many thanks to Milan Zamazal |
|
3169 | 3205 | <pdm-AT-zamazal.org> for all the suggestions and pointers. |
|
3170 | 3206 | |
|
3171 | 3207 | 2002-03-01 Fernando Perez <fperez@colorado.edu> |
|
3172 | 3208 | |
|
3173 | 3209 | * IPython/ipmaker.py (make_IPython): added a --readline! option so |
|
3174 | 3210 | that loading of readline is now optional. This gives better |
|
3175 | 3211 | control to emacs users. |
|
3176 | 3212 | |
|
3177 | 3213 | * IPython/ultraTB.py (__date__): Modified color escape sequences |
|
3178 | 3214 | and now things work fine under xterm and in Emacs' term buffers |
|
3179 | 3215 | (though not shell ones). Well, in emacs you get colors, but all |
|
3180 | 3216 | seem to be 'light' colors (no difference between dark and light |
|
3181 | 3217 | ones). But the garbage chars are gone, and also in xterms. It |
|
3182 | 3218 | seems that now I'm using 'cleaner' ansi sequences. |
|
3183 | 3219 | |
|
3184 | 3220 | 2002-02-21 Fernando Perez <fperez@colorado.edu> |
|
3185 | 3221 | |
|
3186 | 3222 | * Released 0.2.7 (mainly to publish the scoping fix). |
|
3187 | 3223 | |
|
3188 | 3224 | * IPython/Logger.py (Logger.logstate): added. A corresponding |
|
3189 | 3225 | @logstate magic was created. |
|
3190 | 3226 | |
|
3191 | 3227 | * IPython/Magic.py: fixed nested scoping problem under Python |
|
3192 | 3228 | 2.1.x (automagic wasn't working). |
|
3193 | 3229 | |
|
3194 | 3230 | 2002-02-20 Fernando Perez <fperez@colorado.edu> |
|
3195 | 3231 | |
|
3196 | 3232 | * Released 0.2.6. |
|
3197 | 3233 | |
|
3198 | 3234 | * IPython/OutputTrap.py (OutputTrap.__init__): added a 'quiet' |
|
3199 | 3235 | option so that logs can come out without any headers at all. |
|
3200 | 3236 | |
|
3201 | 3237 | * IPython/UserConfig/ipythonrc-scipy.py: created a profile for |
|
3202 | 3238 | SciPy. |
|
3203 | 3239 | |
|
3204 | 3240 | * IPython/iplib.py (InteractiveShell.embed_mainloop): Changed so |
|
3205 | 3241 | that embedded IPython calls don't require vars() to be explicitly |
|
3206 | 3242 | passed. Now they are extracted from the caller's frame (code |
|
3207 | 3243 | snatched from Eric Jones' weave). Added better documentation to |
|
3208 | 3244 | the section on embedding and the example file. |
|
3209 | 3245 | |
|
3210 | 3246 | * IPython/genutils.py (page): Changed so that under emacs, it just |
|
3211 | 3247 | prints the string. You can then page up and down in the emacs |
|
3212 | 3248 | buffer itself. This is how the builtin help() works. |
|
3213 | 3249 | |
|
3214 | 3250 | * IPython/Prompts.py (CachedOutput.__call__): Fixed issue with |
|
3215 | 3251 | macro scoping: macros need to be executed in the user's namespace |
|
3216 | 3252 | to work as if they had been typed by the user. |
|
3217 | 3253 | |
|
3218 | 3254 | * IPython/Magic.py (Magic.magic_macro): Changed macros so they |
|
3219 | 3255 | execute automatically (no need to type 'exec...'). They then |
|
3220 | 3256 | behave like 'true macros'. The printing system was also modified |
|
3221 | 3257 | for this to work. |
|
3222 | 3258 | |
|
3223 | 3259 | 2002-02-19 Fernando Perez <fperez@colorado.edu> |
|
3224 | 3260 | |
|
3225 | 3261 | * IPython/genutils.py (page_file): new function for paging files |
|
3226 | 3262 | in an OS-independent way. Also necessary for file viewing to work |
|
3227 | 3263 | well inside Emacs buffers. |
|
3228 | 3264 | (page): Added checks for being in an emacs buffer. |
|
3229 | 3265 | (page): fixed bug for Windows ($TERM isn't set in Windows). Fixed |
|
3230 | 3266 | same bug in iplib. |
|
3231 | 3267 | |
|
3232 | 3268 | 2002-02-18 Fernando Perez <fperez@colorado.edu> |
|
3233 | 3269 | |
|
3234 | 3270 | * IPython/iplib.py (InteractiveShell.init_readline): modified use |
|
3235 | 3271 | of readline so that IPython can work inside an Emacs buffer. |
|
3236 | 3272 | |
|
3237 | 3273 | * IPython/ultraTB.py (AutoFormattedTB.__call__): some fixes to |
|
3238 | 3274 | method signatures (they weren't really bugs, but it looks cleaner |
|
3239 | 3275 | and keeps PyChecker happy). |
|
3240 | 3276 | |
|
3241 | 3277 | * IPython/ipmaker.py (make_IPython): added hooks Struct to __IP |
|
3242 | 3278 | for implementing various user-defined hooks. Currently only |
|
3243 | 3279 | display is done. |
|
3244 | 3280 | |
|
3245 | 3281 | * IPython/Prompts.py (CachedOutput._display): changed display |
|
3246 | 3282 | functions so that they can be dynamically changed by users easily. |
|
3247 | 3283 | |
|
3248 | 3284 | * IPython/Extensions/numeric_formats.py (num_display): added an |
|
3249 | 3285 | extension for printing NumPy arrays in flexible manners. It |
|
3250 | 3286 | doesn't do anything yet, but all the structure is in |
|
3251 | 3287 | place. Ultimately the plan is to implement output format control |
|
3252 | 3288 | like in Octave. |
|
3253 | 3289 | |
|
3254 | 3290 | * IPython/Magic.py (Magic.lsmagic): changed so that bound magic |
|
3255 | 3291 | methods are found at run-time by all the automatic machinery. |
|
3256 | 3292 | |
|
3257 | 3293 | 2002-02-17 Fernando Perez <fperez@colorado.edu> |
|
3258 | 3294 | |
|
3259 | 3295 | * setup_Windows.py (make_shortcut): documented. Cleaned up the |
|
3260 | 3296 | whole file a little. |
|
3261 | 3297 | |
|
3262 | 3298 | * ToDo: closed this document. Now there's a new_design.lyx |
|
3263 | 3299 | document for all new ideas. Added making a pdf of it for the |
|
3264 | 3300 | end-user distro. |
|
3265 | 3301 | |
|
3266 | 3302 | * IPython/Logger.py (Logger.switch_log): Created this to replace |
|
3267 | 3303 | logon() and logoff(). It also fixes a nasty crash reported by |
|
3268 | 3304 | Philip Hisley <compsys-AT-starpower.net>. Many thanks to him. |
|
3269 | 3305 | |
|
3270 | 3306 | * IPython/iplib.py (complete): got auto-completion to work with |
|
3271 | 3307 | automagic (I had wanted this for a long time). |
|
3272 | 3308 | |
|
3273 | 3309 | * IPython/Magic.py (Magic.magic_files): Added @files as an alias |
|
3274 | 3310 | to @file, since file() is now a builtin and clashes with automagic |
|
3275 | 3311 | for @file. |
|
3276 | 3312 | |
|
3277 | 3313 | * Made some new files: Prompts, CrashHandler, Magic, Logger. All |
|
3278 | 3314 | of this was previously in iplib, which had grown to more than 2000 |
|
3279 | 3315 | lines, way too long. No new functionality, but it makes managing |
|
3280 | 3316 | the code a bit easier. |
|
3281 | 3317 | |
|
3282 | 3318 | * IPython/iplib.py (IPythonCrashHandler.__call__): Added version |
|
3283 | 3319 | information to crash reports. |
|
3284 | 3320 | |
|
3285 | 3321 | 2002-02-12 Fernando Perez <fperez@colorado.edu> |
|
3286 | 3322 | |
|
3287 | 3323 | * Released 0.2.5. |
|
3288 | 3324 | |
|
3289 | 3325 | 2002-02-11 Fernando Perez <fperez@colorado.edu> |
|
3290 | 3326 | |
|
3291 | 3327 | * Wrote a relatively complete Windows installer. It puts |
|
3292 | 3328 | everything in place, creates Start Menu entries and fixes the |
|
3293 | 3329 | color issues. Nothing fancy, but it works. |
|
3294 | 3330 | |
|
3295 | 3331 | 2002-02-10 Fernando Perez <fperez@colorado.edu> |
|
3296 | 3332 | |
|
3297 | 3333 | * IPython/iplib.py (InteractiveShell.safe_execfile): added an |
|
3298 | 3334 | os.path.expanduser() call so that we can type @run ~/myfile.py and |
|
3299 | 3335 | have thigs work as expected. |
|
3300 | 3336 | |
|
3301 | 3337 | * IPython/genutils.py (page): fixed exception handling so things |
|
3302 | 3338 | work both in Unix and Windows correctly. Quitting a pager triggers |
|
3303 | 3339 | an IOError/broken pipe in Unix, and in windows not finding a pager |
|
3304 | 3340 | is also an IOError, so I had to actually look at the return value |
|
3305 | 3341 | of the exception, not just the exception itself. Should be ok now. |
|
3306 | 3342 | |
|
3307 | 3343 | * IPython/ultraTB.py (ColorSchemeTable.set_active_scheme): |
|
3308 | 3344 | modified to allow case-insensitive color scheme changes. |
|
3309 | 3345 | |
|
3310 | 3346 | 2002-02-09 Fernando Perez <fperez@colorado.edu> |
|
3311 | 3347 | |
|
3312 | 3348 | * IPython/genutils.py (native_line_ends): new function to leave |
|
3313 | 3349 | user config files with os-native line-endings. |
|
3314 | 3350 | |
|
3315 | 3351 | * README and manual updates. |
|
3316 | 3352 | |
|
3317 | 3353 | * IPython/genutils.py: fixed unicode bug: use types.StringTypes |
|
3318 | 3354 | instead of StringType to catch Unicode strings. |
|
3319 | 3355 | |
|
3320 | 3356 | * IPython/genutils.py (filefind): fixed bug for paths with |
|
3321 | 3357 | embedded spaces (very common in Windows). |
|
3322 | 3358 | |
|
3323 | 3359 | * IPython/ipmaker.py (make_IPython): added a '.ini' to the rc |
|
3324 | 3360 | files under Windows, so that they get automatically associated |
|
3325 | 3361 | with a text editor. Windows makes it a pain to handle |
|
3326 | 3362 | extension-less files. |
|
3327 | 3363 | |
|
3328 | 3364 | * IPython/iplib.py (InteractiveShell.init_readline): Made the |
|
3329 | 3365 | warning about readline only occur for Posix. In Windows there's no |
|
3330 | 3366 | way to get readline, so why bother with the warning. |
|
3331 | 3367 | |
|
3332 | 3368 | * IPython/Struct.py (Struct.__str__): fixed to use self.__dict__ |
|
3333 | 3369 | for __str__ instead of dir(self), since dir() changed in 2.2. |
|
3334 | 3370 | |
|
3335 | 3371 | * Ported to Windows! Tested on XP, I suspect it should work fine |
|
3336 | 3372 | on NT/2000, but I don't think it will work on 98 et al. That |
|
3337 | 3373 | series of Windows is such a piece of junk anyway that I won't try |
|
3338 | 3374 | porting it there. The XP port was straightforward, showed a few |
|
3339 | 3375 | bugs here and there (fixed all), in particular some string |
|
3340 | 3376 | handling stuff which required considering Unicode strings (which |
|
3341 | 3377 | Windows uses). This is good, but hasn't been too tested :) No |
|
3342 | 3378 | fancy installer yet, I'll put a note in the manual so people at |
|
3343 | 3379 | least make manually a shortcut. |
|
3344 | 3380 | |
|
3345 | 3381 | * IPython/iplib.py (Magic.magic_colors): Unified the color options |
|
3346 | 3382 | into a single one, "colors". This now controls both prompt and |
|
3347 | 3383 | exception color schemes, and can be changed both at startup |
|
3348 | 3384 | (either via command-line switches or via ipythonrc files) and at |
|
3349 | 3385 | runtime, with @colors. |
|
3350 | 3386 | (Magic.magic_run): renamed @prun to @run and removed the old |
|
3351 | 3387 | @run. The two were too similar to warrant keeping both. |
|
3352 | 3388 | |
|
3353 | 3389 | 2002-02-03 Fernando Perez <fperez@colorado.edu> |
|
3354 | 3390 | |
|
3355 | 3391 | * IPython/iplib.py (install_first_time): Added comment on how to |
|
3356 | 3392 | configure the color options for first-time users. Put a <return> |
|
3357 | 3393 | request at the end so that small-terminal users get a chance to |
|
3358 | 3394 | read the startup info. |
|
3359 | 3395 | |
|
3360 | 3396 | 2002-01-23 Fernando Perez <fperez@colorado.edu> |
|
3361 | 3397 | |
|
3362 | 3398 | * IPython/iplib.py (CachedOutput.update): Changed output memory |
|
3363 | 3399 | variable names from _o,_oo,_ooo,_o<n> to simply _,__,___,_<n>. For |
|
3364 | 3400 | input history we still use _i. Did this b/c these variable are |
|
3365 | 3401 | very commonly used in interactive work, so the less we need to |
|
3366 | 3402 | type the better off we are. |
|
3367 | 3403 | (Magic.magic_prun): updated @prun to better handle the namespaces |
|
3368 | 3404 | the file will run in, including a fix for __name__ not being set |
|
3369 | 3405 | before. |
|
3370 | 3406 | |
|
3371 | 3407 | 2002-01-20 Fernando Perez <fperez@colorado.edu> |
|
3372 | 3408 | |
|
3373 | 3409 | * IPython/ultraTB.py (VerboseTB.linereader): Fixed printing of |
|
3374 | 3410 | extra garbage for Python 2.2. Need to look more carefully into |
|
3375 | 3411 | this later. |
|
3376 | 3412 | |
|
3377 | 3413 | 2002-01-19 Fernando Perez <fperez@colorado.edu> |
|
3378 | 3414 | |
|
3379 | 3415 | * IPython/iplib.py (InteractiveShell.showtraceback): fixed to |
|
3380 | 3416 | display SyntaxError exceptions properly formatted when they occur |
|
3381 | 3417 | (they can be triggered by imported code). |
|
3382 | 3418 | |
|
3383 | 3419 | 2002-01-18 Fernando Perez <fperez@colorado.edu> |
|
3384 | 3420 | |
|
3385 | 3421 | * IPython/iplib.py (InteractiveShell.safe_execfile): now |
|
3386 | 3422 | SyntaxError exceptions are reported nicely formatted, instead of |
|
3387 | 3423 | spitting out only offset information as before. |
|
3388 | 3424 | (Magic.magic_prun): Added the @prun function for executing |
|
3389 | 3425 | programs with command line args inside IPython. |
|
3390 | 3426 | |
|
3391 | 3427 | 2002-01-16 Fernando Perez <fperez@colorado.edu> |
|
3392 | 3428 | |
|
3393 | 3429 | * IPython/iplib.py (Magic.magic_hist): Changed @hist and @dhist |
|
3394 | 3430 | to *not* include the last item given in a range. This brings their |
|
3395 | 3431 | behavior in line with Python's slicing: |
|
3396 | 3432 | a[n1:n2] -> a[n1]...a[n2-1] |
|
3397 | 3433 | It may be a bit less convenient, but I prefer to stick to Python's |
|
3398 | 3434 | conventions *everywhere*, so users never have to wonder. |
|
3399 | 3435 | (Magic.magic_macro): Added @macro function to ease the creation of |
|
3400 | 3436 | macros. |
|
3401 | 3437 | |
|
3402 | 3438 | 2002-01-05 Fernando Perez <fperez@colorado.edu> |
|
3403 | 3439 | |
|
3404 | 3440 | * Released 0.2.4. |
|
3405 | 3441 | |
|
3406 | 3442 | * IPython/iplib.py (Magic.magic_pdef): |
|
3407 | 3443 | (InteractiveShell.safe_execfile): report magic lines and error |
|
3408 | 3444 | lines without line numbers so one can easily copy/paste them for |
|
3409 | 3445 | re-execution. |
|
3410 | 3446 | |
|
3411 | 3447 | * Updated manual with recent changes. |
|
3412 | 3448 | |
|
3413 | 3449 | * IPython/iplib.py (Magic.magic_oinfo): added constructor |
|
3414 | 3450 | docstring printing when class? is called. Very handy for knowing |
|
3415 | 3451 | how to create class instances (as long as __init__ is well |
|
3416 | 3452 | documented, of course :) |
|
3417 | 3453 | (Magic.magic_doc): print both class and constructor docstrings. |
|
3418 | 3454 | (Magic.magic_pdef): give constructor info if passed a class and |
|
3419 | 3455 | __call__ info for callable object instances. |
|
3420 | 3456 | |
|
3421 | 3457 | 2002-01-04 Fernando Perez <fperez@colorado.edu> |
|
3422 | 3458 | |
|
3423 | 3459 | * Made deep_reload() off by default. It doesn't always work |
|
3424 | 3460 | exactly as intended, so it's probably safer to have it off. It's |
|
3425 | 3461 | still available as dreload() anyway, so nothing is lost. |
|
3426 | 3462 | |
|
3427 | 3463 | 2002-01-02 Fernando Perez <fperez@colorado.edu> |
|
3428 | 3464 | |
|
3429 | 3465 | * Released 0.2.3 (contacted R.Singh at CU about biopython course, |
|
3430 | 3466 | so I wanted an updated release). |
|
3431 | 3467 | |
|
3432 | 3468 | 2001-12-27 Fernando Perez <fperez@colorado.edu> |
|
3433 | 3469 | |
|
3434 | 3470 | * IPython/iplib.py (InteractiveShell.interact): Added the original |
|
3435 | 3471 | code from 'code.py' for this module in order to change the |
|
3436 | 3472 | handling of a KeyboardInterrupt. This was necessary b/c otherwise |
|
3437 | 3473 | the history cache would break when the user hit Ctrl-C, and |
|
3438 | 3474 | interact() offers no way to add any hooks to it. |
|
3439 | 3475 | |
|
3440 | 3476 | 2001-12-23 Fernando Perez <fperez@colorado.edu> |
|
3441 | 3477 | |
|
3442 | 3478 | * setup.py: added check for 'MANIFEST' before trying to remove |
|
3443 | 3479 | it. Thanks to Sean Reifschneider. |
|
3444 | 3480 | |
|
3445 | 3481 | 2001-12-22 Fernando Perez <fperez@colorado.edu> |
|
3446 | 3482 | |
|
3447 | 3483 | * Released 0.2.2. |
|
3448 | 3484 | |
|
3449 | 3485 | * Finished (reasonably) writing the manual. Later will add the |
|
3450 | 3486 | python-standard navigation stylesheets, but for the time being |
|
3451 | 3487 | it's fairly complete. Distribution will include html and pdf |
|
3452 | 3488 | versions. |
|
3453 | 3489 | |
|
3454 | 3490 | * Bugfix: '.' wasn't being added to sys.path. Thanks to Prabhu |
|
3455 | 3491 | (MayaVi author). |
|
3456 | 3492 | |
|
3457 | 3493 | 2001-12-21 Fernando Perez <fperez@colorado.edu> |
|
3458 | 3494 | |
|
3459 | 3495 | * Released 0.2.1. Barring any nasty bugs, this is it as far as a |
|
3460 | 3496 | good public release, I think (with the manual and the distutils |
|
3461 | 3497 | installer). The manual can use some work, but that can go |
|
3462 | 3498 | slowly. Otherwise I think it's quite nice for end users. Next |
|
3463 | 3499 | summer, rewrite the guts of it... |
|
3464 | 3500 | |
|
3465 | 3501 | * Changed format of ipythonrc files to use whitespace as the |
|
3466 | 3502 | separator instead of an explicit '='. Cleaner. |
|
3467 | 3503 | |
|
3468 | 3504 | 2001-12-20 Fernando Perez <fperez@colorado.edu> |
|
3469 | 3505 | |
|
3470 | 3506 | * Started a manual in LyX. For now it's just a quick merge of the |
|
3471 | 3507 | various internal docstrings and READMEs. Later it may grow into a |
|
3472 | 3508 | nice, full-blown manual. |
|
3473 | 3509 | |
|
3474 | 3510 | * Set up a distutils based installer. Installation should now be |
|
3475 | 3511 | trivially simple for end-users. |
|
3476 | 3512 | |
|
3477 | 3513 | 2001-12-11 Fernando Perez <fperez@colorado.edu> |
|
3478 | 3514 | |
|
3479 | 3515 | * Released 0.2.0. First public release, announced it at |
|
3480 | 3516 | comp.lang.python. From now on, just bugfixes... |
|
3481 | 3517 | |
|
3482 | 3518 | * Went through all the files, set copyright/license notices and |
|
3483 | 3519 | cleaned up things. Ready for release. |
|
3484 | 3520 | |
|
3485 | 3521 | 2001-12-10 Fernando Perez <fperez@colorado.edu> |
|
3486 | 3522 | |
|
3487 | 3523 | * Changed the first-time installer not to use tarfiles. It's more |
|
3488 | 3524 | robust now and less unix-dependent. Also makes it easier for |
|
3489 | 3525 | people to later upgrade versions. |
|
3490 | 3526 | |
|
3491 | 3527 | * Changed @exit to @abort to reflect the fact that it's pretty |
|
3492 | 3528 | brutal (a sys.exit()). The difference between @abort and Ctrl-D |
|
3493 | 3529 | becomes significant only when IPyhton is embedded: in that case, |
|
3494 | 3530 | C-D closes IPython only, but @abort kills the enclosing program |
|
3495 | 3531 | too (unless it had called IPython inside a try catching |
|
3496 | 3532 | SystemExit). |
|
3497 | 3533 | |
|
3498 | 3534 | * Created Shell module which exposes the actuall IPython Shell |
|
3499 | 3535 | classes, currently the normal and the embeddable one. This at |
|
3500 | 3536 | least offers a stable interface we won't need to change when |
|
3501 | 3537 | (later) the internals are rewritten. That rewrite will be confined |
|
3502 | 3538 | to iplib and ipmaker, but the Shell interface should remain as is. |
|
3503 | 3539 | |
|
3504 | 3540 | * Added embed module which offers an embeddable IPShell object, |
|
3505 | 3541 | useful to fire up IPython *inside* a running program. Great for |
|
3506 | 3542 | debugging or dynamical data analysis. |
|
3507 | 3543 | |
|
3508 | 3544 | 2001-12-08 Fernando Perez <fperez@colorado.edu> |
|
3509 | 3545 | |
|
3510 | 3546 | * Fixed small bug preventing seeing info from methods of defined |
|
3511 | 3547 | objects (incorrect namespace in _ofind()). |
|
3512 | 3548 | |
|
3513 | 3549 | * Documentation cleanup. Moved the main usage docstrings to a |
|
3514 | 3550 | separate file, usage.py (cleaner to maintain, and hopefully in the |
|
3515 | 3551 | future some perlpod-like way of producing interactive, man and |
|
3516 | 3552 | html docs out of it will be found). |
|
3517 | 3553 | |
|
3518 | 3554 | * Added @profile to see your profile at any time. |
|
3519 | 3555 | |
|
3520 | 3556 | * Added @p as an alias for 'print'. It's especially convenient if |
|
3521 | 3557 | using automagic ('p x' prints x). |
|
3522 | 3558 | |
|
3523 | 3559 | * Small cleanups and fixes after a pychecker run. |
|
3524 | 3560 | |
|
3525 | 3561 | * Changed the @cd command to handle @cd - and @cd -<n> for |
|
3526 | 3562 | visiting any directory in _dh. |
|
3527 | 3563 | |
|
3528 | 3564 | * Introduced _dh, a history of visited directories. @dhist prints |
|
3529 | 3565 | it out with numbers. |
|
3530 | 3566 | |
|
3531 | 3567 | 2001-12-07 Fernando Perez <fperez@colorado.edu> |
|
3532 | 3568 | |
|
3533 | 3569 | * Released 0.1.22 |
|
3534 | 3570 | |
|
3535 | 3571 | * Made initialization a bit more robust against invalid color |
|
3536 | 3572 | options in user input (exit, not traceback-crash). |
|
3537 | 3573 | |
|
3538 | 3574 | * Changed the bug crash reporter to write the report only in the |
|
3539 | 3575 | user's .ipython directory. That way IPython won't litter people's |
|
3540 | 3576 | hard disks with crash files all over the place. Also print on |
|
3541 | 3577 | screen the necessary mail command. |
|
3542 | 3578 | |
|
3543 | 3579 | * With the new ultraTB, implemented LightBG color scheme for light |
|
3544 | 3580 | background terminals. A lot of people like white backgrounds, so I |
|
3545 | 3581 | guess we should at least give them something readable. |
|
3546 | 3582 | |
|
3547 | 3583 | 2001-12-06 Fernando Perez <fperez@colorado.edu> |
|
3548 | 3584 | |
|
3549 | 3585 | * Modified the structure of ultraTB. Now there's a proper class |
|
3550 | 3586 | for tables of color schemes which allow adding schemes easily and |
|
3551 | 3587 | switching the active scheme without creating a new instance every |
|
3552 | 3588 | time (which was ridiculous). The syntax for creating new schemes |
|
3553 | 3589 | is also cleaner. I think ultraTB is finally done, with a clean |
|
3554 | 3590 | class structure. Names are also much cleaner (now there's proper |
|
3555 | 3591 | color tables, no need for every variable to also have 'color' in |
|
3556 | 3592 | its name). |
|
3557 | 3593 | |
|
3558 | 3594 | * Broke down genutils into separate files. Now genutils only |
|
3559 | 3595 | contains utility functions, and classes have been moved to their |
|
3560 | 3596 | own files (they had enough independent functionality to warrant |
|
3561 | 3597 | it): ConfigLoader, OutputTrap, Struct. |
|
3562 | 3598 | |
|
3563 | 3599 | 2001-12-05 Fernando Perez <fperez@colorado.edu> |
|
3564 | 3600 | |
|
3565 | 3601 | * IPython turns 21! Released version 0.1.21, as a candidate for |
|
3566 | 3602 | public consumption. If all goes well, release in a few days. |
|
3567 | 3603 | |
|
3568 | 3604 | * Fixed path bug (files in Extensions/ directory wouldn't be found |
|
3569 | 3605 | unless IPython/ was explicitly in sys.path). |
|
3570 | 3606 | |
|
3571 | 3607 | * Extended the FlexCompleter class as MagicCompleter to allow |
|
3572 | 3608 | completion of @-starting lines. |
|
3573 | 3609 | |
|
3574 | 3610 | * Created __release__.py file as a central repository for release |
|
3575 | 3611 | info that other files can read from. |
|
3576 | 3612 | |
|
3577 | 3613 | * Fixed small bug in logging: when logging was turned on in |
|
3578 | 3614 | mid-session, old lines with special meanings (!@?) were being |
|
3579 | 3615 | logged without the prepended comment, which is necessary since |
|
3580 | 3616 | they are not truly valid python syntax. This should make session |
|
3581 | 3617 | restores produce less errors. |
|
3582 | 3618 | |
|
3583 | 3619 | * The namespace cleanup forced me to make a FlexCompleter class |
|
3584 | 3620 | which is nothing but a ripoff of rlcompleter, but with selectable |
|
3585 | 3621 | namespace (rlcompleter only works in __main__.__dict__). I'll try |
|
3586 | 3622 | to submit a note to the authors to see if this change can be |
|
3587 | 3623 | incorporated in future rlcompleter releases (Dec.6: done) |
|
3588 | 3624 | |
|
3589 | 3625 | * More fixes to namespace handling. It was a mess! Now all |
|
3590 | 3626 | explicit references to __main__.__dict__ are gone (except when |
|
3591 | 3627 | really needed) and everything is handled through the namespace |
|
3592 | 3628 | dicts in the IPython instance. We seem to be getting somewhere |
|
3593 | 3629 | with this, finally... |
|
3594 | 3630 | |
|
3595 | 3631 | * Small documentation updates. |
|
3596 | 3632 | |
|
3597 | 3633 | * Created the Extensions directory under IPython (with an |
|
3598 | 3634 | __init__.py). Put the PhysicalQ stuff there. This directory should |
|
3599 | 3635 | be used for all special-purpose extensions. |
|
3600 | 3636 | |
|
3601 | 3637 | * File renaming: |
|
3602 | 3638 | ipythonlib --> ipmaker |
|
3603 | 3639 | ipplib --> iplib |
|
3604 | 3640 | This makes a bit more sense in terms of what these files actually do. |
|
3605 | 3641 | |
|
3606 | 3642 | * Moved all the classes and functions in ipythonlib to ipplib, so |
|
3607 | 3643 | now ipythonlib only has make_IPython(). This will ease up its |
|
3608 | 3644 | splitting in smaller functional chunks later. |
|
3609 | 3645 | |
|
3610 | 3646 | * Cleaned up (done, I think) output of @whos. Better column |
|
3611 | 3647 | formatting, and now shows str(var) for as much as it can, which is |
|
3612 | 3648 | typically what one gets with a 'print var'. |
|
3613 | 3649 | |
|
3614 | 3650 | 2001-12-04 Fernando Perez <fperez@colorado.edu> |
|
3615 | 3651 | |
|
3616 | 3652 | * Fixed namespace problems. Now builtin/IPyhton/user names get |
|
3617 | 3653 | properly reported in their namespace. Internal namespace handling |
|
3618 | 3654 | is finally getting decent (not perfect yet, but much better than |
|
3619 | 3655 | the ad-hoc mess we had). |
|
3620 | 3656 | |
|
3621 | 3657 | * Removed -exit option. If people just want to run a python |
|
3622 | 3658 | script, that's what the normal interpreter is for. Less |
|
3623 | 3659 | unnecessary options, less chances for bugs. |
|
3624 | 3660 | |
|
3625 | 3661 | * Added a crash handler which generates a complete post-mortem if |
|
3626 | 3662 | IPython crashes. This will help a lot in tracking bugs down the |
|
3627 | 3663 | road. |
|
3628 | 3664 | |
|
3629 | 3665 | * Fixed nasty bug in auto-evaluation part of prefilter(). Names |
|
3630 | 3666 | which were boud to functions being reassigned would bypass the |
|
3631 | 3667 | logger, breaking the sync of _il with the prompt counter. This |
|
3632 | 3668 | would then crash IPython later when a new line was logged. |
|
3633 | 3669 | |
|
3634 | 3670 | 2001-12-02 Fernando Perez <fperez@colorado.edu> |
|
3635 | 3671 | |
|
3636 | 3672 | * Made IPython a package. This means people don't have to clutter |
|
3637 | 3673 | their sys.path with yet another directory. Changed the INSTALL |
|
3638 | 3674 | file accordingly. |
|
3639 | 3675 | |
|
3640 | 3676 | * Cleaned up the output of @who_ls, @who and @whos. @who_ls now |
|
3641 | 3677 | sorts its output (so @who shows it sorted) and @whos formats the |
|
3642 | 3678 | table according to the width of the first column. Nicer, easier to |
|
3643 | 3679 | read. Todo: write a generic table_format() which takes a list of |
|
3644 | 3680 | lists and prints it nicely formatted, with optional row/column |
|
3645 | 3681 | separators and proper padding and justification. |
|
3646 | 3682 | |
|
3647 | 3683 | * Released 0.1.20 |
|
3648 | 3684 | |
|
3649 | 3685 | * Fixed bug in @log which would reverse the inputcache list (a |
|
3650 | 3686 | copy operation was missing). |
|
3651 | 3687 | |
|
3652 | 3688 | * Code cleanup. @config was changed to use page(). Better, since |
|
3653 | 3689 | its output is always quite long. |
|
3654 | 3690 | |
|
3655 | 3691 | * Itpl is back as a dependency. I was having too many problems |
|
3656 | 3692 | getting the parametric aliases to work reliably, and it's just |
|
3657 | 3693 | easier to code weird string operations with it than playing %()s |
|
3658 | 3694 | games. It's only ~6k, so I don't think it's too big a deal. |
|
3659 | 3695 | |
|
3660 | 3696 | * Found (and fixed) a very nasty bug with history. !lines weren't |
|
3661 | 3697 | getting cached, and the out of sync caches would crash |
|
3662 | 3698 | IPython. Fixed it by reorganizing the prefilter/handlers/logger |
|
3663 | 3699 | division of labor a bit better. Bug fixed, cleaner structure. |
|
3664 | 3700 | |
|
3665 | 3701 | 2001-12-01 Fernando Perez <fperez@colorado.edu> |
|
3666 | 3702 | |
|
3667 | 3703 | * Released 0.1.19 |
|
3668 | 3704 | |
|
3669 | 3705 | * Added option -n to @hist to prevent line number printing. Much |
|
3670 | 3706 | easier to copy/paste code this way. |
|
3671 | 3707 | |
|
3672 | 3708 | * Created global _il to hold the input list. Allows easy |
|
3673 | 3709 | re-execution of blocks of code by slicing it (inspired by Janko's |
|
3674 | 3710 | comment on 'macros'). |
|
3675 | 3711 | |
|
3676 | 3712 | * Small fixes and doc updates. |
|
3677 | 3713 | |
|
3678 | 3714 | * Rewrote @history function (was @h). Renamed it to @hist, @h is |
|
3679 | 3715 | much too fragile with automagic. Handles properly multi-line |
|
3680 | 3716 | statements and takes parameters. |
|
3681 | 3717 | |
|
3682 | 3718 | 2001-11-30 Fernando Perez <fperez@colorado.edu> |
|
3683 | 3719 | |
|
3684 | 3720 | * Version 0.1.18 released. |
|
3685 | 3721 | |
|
3686 | 3722 | * Fixed nasty namespace bug in initial module imports. |
|
3687 | 3723 | |
|
3688 | 3724 | * Added copyright/license notes to all code files (except |
|
3689 | 3725 | DPyGetOpt). For the time being, LGPL. That could change. |
|
3690 | 3726 | |
|
3691 | 3727 | * Rewrote a much nicer README, updated INSTALL, cleaned up |
|
3692 | 3728 | ipythonrc-* samples. |
|
3693 | 3729 | |
|
3694 | 3730 | * Overall code/documentation cleanup. Basically ready for |
|
3695 | 3731 | release. Only remaining thing: licence decision (LGPL?). |
|
3696 | 3732 | |
|
3697 | 3733 | * Converted load_config to a class, ConfigLoader. Now recursion |
|
3698 | 3734 | control is better organized. Doesn't include the same file twice. |
|
3699 | 3735 | |
|
3700 | 3736 | 2001-11-29 Fernando Perez <fperez@colorado.edu> |
|
3701 | 3737 | |
|
3702 | 3738 | * Got input history working. Changed output history variables from |
|
3703 | 3739 | _p to _o so that _i is for input and _o for output. Just cleaner |
|
3704 | 3740 | convention. |
|
3705 | 3741 | |
|
3706 | 3742 | * Implemented parametric aliases. This pretty much allows the |
|
3707 | 3743 | alias system to offer full-blown shell convenience, I think. |
|
3708 | 3744 | |
|
3709 | 3745 | * Version 0.1.17 released, 0.1.18 opened. |
|
3710 | 3746 | |
|
3711 | 3747 | * dot_ipython/ipythonrc (alias): added documentation. |
|
3712 | 3748 | (xcolor): Fixed small bug (xcolors -> xcolor) |
|
3713 | 3749 | |
|
3714 | 3750 | * Changed the alias system. Now alias is a magic command to define |
|
3715 | 3751 | aliases just like the shell. Rationale: the builtin magics should |
|
3716 | 3752 | be there for things deeply connected to IPython's |
|
3717 | 3753 | architecture. And this is a much lighter system for what I think |
|
3718 | 3754 | is the really important feature: allowing users to define quickly |
|
3719 | 3755 | magics that will do shell things for them, so they can customize |
|
3720 | 3756 | IPython easily to match their work habits. If someone is really |
|
3721 | 3757 | desperate to have another name for a builtin alias, they can |
|
3722 | 3758 | always use __IP.magic_newname = __IP.magic_oldname. Hackish but |
|
3723 | 3759 | works. |
|
3724 | 3760 | |
|
3725 | 3761 | 2001-11-28 Fernando Perez <fperez@colorado.edu> |
|
3726 | 3762 | |
|
3727 | 3763 | * Changed @file so that it opens the source file at the proper |
|
3728 | 3764 | line. Since it uses less, if your EDITOR environment is |
|
3729 | 3765 | configured, typing v will immediately open your editor of choice |
|
3730 | 3766 | right at the line where the object is defined. Not as quick as |
|
3731 | 3767 | having a direct @edit command, but for all intents and purposes it |
|
3732 | 3768 | works. And I don't have to worry about writing @edit to deal with |
|
3733 | 3769 | all the editors, less does that. |
|
3734 | 3770 | |
|
3735 | 3771 | * Version 0.1.16 released, 0.1.17 opened. |
|
3736 | 3772 | |
|
3737 | 3773 | * Fixed some nasty bugs in the page/page_dumb combo that could |
|
3738 | 3774 | crash IPython. |
|
3739 | 3775 | |
|
3740 | 3776 | 2001-11-27 Fernando Perez <fperez@colorado.edu> |
|
3741 | 3777 | |
|
3742 | 3778 | * Version 0.1.15 released, 0.1.16 opened. |
|
3743 | 3779 | |
|
3744 | 3780 | * Finally got ? and ?? to work for undefined things: now it's |
|
3745 | 3781 | possible to type {}.get? and get information about the get method |
|
3746 | 3782 | of dicts, or os.path? even if only os is defined (so technically |
|
3747 | 3783 | os.path isn't). Works at any level. For example, after import os, |
|
3748 | 3784 | os?, os.path?, os.path.abspath? all work. This is great, took some |
|
3749 | 3785 | work in _ofind. |
|
3750 | 3786 | |
|
3751 | 3787 | * Fixed more bugs with logging. The sanest way to do it was to add |
|
3752 | 3788 | to @log a 'mode' parameter. Killed two in one shot (this mode |
|
3753 | 3789 | option was a request of Janko's). I think it's finally clean |
|
3754 | 3790 | (famous last words). |
|
3755 | 3791 | |
|
3756 | 3792 | * Added a page_dumb() pager which does a decent job of paging on |
|
3757 | 3793 | screen, if better things (like less) aren't available. One less |
|
3758 | 3794 | unix dependency (someday maybe somebody will port this to |
|
3759 | 3795 | windows). |
|
3760 | 3796 | |
|
3761 | 3797 | * Fixed problem in magic_log: would lock of logging out if log |
|
3762 | 3798 | creation failed (because it would still think it had succeeded). |
|
3763 | 3799 | |
|
3764 | 3800 | * Improved the page() function using curses to auto-detect screen |
|
3765 | 3801 | size. Now it can make a much better decision on whether to print |
|
3766 | 3802 | or page a string. Option screen_length was modified: a value 0 |
|
3767 | 3803 | means auto-detect, and that's the default now. |
|
3768 | 3804 | |
|
3769 | 3805 | * Version 0.1.14 released, 0.1.15 opened. I think this is ready to |
|
3770 | 3806 | go out. I'll test it for a few days, then talk to Janko about |
|
3771 | 3807 | licences and announce it. |
|
3772 | 3808 | |
|
3773 | 3809 | * Fixed the length of the auto-generated ---> prompt which appears |
|
3774 | 3810 | for auto-parens and auto-quotes. Getting this right isn't trivial, |
|
3775 | 3811 | with all the color escapes, different prompt types and optional |
|
3776 | 3812 | separators. But it seems to be working in all the combinations. |
|
3777 | 3813 | |
|
3778 | 3814 | 2001-11-26 Fernando Perez <fperez@colorado.edu> |
|
3779 | 3815 | |
|
3780 | 3816 | * Wrote a regexp filter to get option types from the option names |
|
3781 | 3817 | string. This eliminates the need to manually keep two duplicate |
|
3782 | 3818 | lists. |
|
3783 | 3819 | |
|
3784 | 3820 | * Removed the unneeded check_option_names. Now options are handled |
|
3785 | 3821 | in a much saner manner and it's easy to visually check that things |
|
3786 | 3822 | are ok. |
|
3787 | 3823 | |
|
3788 | 3824 | * Updated version numbers on all files I modified to carry a |
|
3789 | 3825 | notice so Janko and Nathan have clear version markers. |
|
3790 | 3826 | |
|
3791 | 3827 | * Updated docstring for ultraTB with my changes. I should send |
|
3792 | 3828 | this to Nathan. |
|
3793 | 3829 | |
|
3794 | 3830 | * Lots of small fixes. Ran everything through pychecker again. |
|
3795 | 3831 | |
|
3796 | 3832 | * Made loading of deep_reload an cmd line option. If it's not too |
|
3797 | 3833 | kosher, now people can just disable it. With -nodeep_reload it's |
|
3798 | 3834 | still available as dreload(), it just won't overwrite reload(). |
|
3799 | 3835 | |
|
3800 | 3836 | * Moved many options to the no| form (-opt and -noopt |
|
3801 | 3837 | accepted). Cleaner. |
|
3802 | 3838 | |
|
3803 | 3839 | * Changed magic_log so that if called with no parameters, it uses |
|
3804 | 3840 | 'rotate' mode. That way auto-generated logs aren't automatically |
|
3805 | 3841 | over-written. For normal logs, now a backup is made if it exists |
|
3806 | 3842 | (only 1 level of backups). A new 'backup' mode was added to the |
|
3807 | 3843 | Logger class to support this. This was a request by Janko. |
|
3808 | 3844 | |
|
3809 | 3845 | * Added @logoff/@logon to stop/restart an active log. |
|
3810 | 3846 | |
|
3811 | 3847 | * Fixed a lot of bugs in log saving/replay. It was pretty |
|
3812 | 3848 | broken. Now special lines (!@,/) appear properly in the command |
|
3813 | 3849 | history after a log replay. |
|
3814 | 3850 | |
|
3815 | 3851 | * Tried and failed to implement full session saving via pickle. My |
|
3816 | 3852 | idea was to pickle __main__.__dict__, but modules can't be |
|
3817 | 3853 | pickled. This would be a better alternative to replaying logs, but |
|
3818 | 3854 | seems quite tricky to get to work. Changed -session to be called |
|
3819 | 3855 | -logplay, which more accurately reflects what it does. And if we |
|
3820 | 3856 | ever get real session saving working, -session is now available. |
|
3821 | 3857 | |
|
3822 | 3858 | * Implemented color schemes for prompts also. As for tracebacks, |
|
3823 | 3859 | currently only NoColor and Linux are supported. But now the |
|
3824 | 3860 | infrastructure is in place, based on a generic ColorScheme |
|
3825 | 3861 | class. So writing and activating new schemes both for the prompts |
|
3826 | 3862 | and the tracebacks should be straightforward. |
|
3827 | 3863 | |
|
3828 | 3864 | * Version 0.1.13 released, 0.1.14 opened. |
|
3829 | 3865 | |
|
3830 | 3866 | * Changed handling of options for output cache. Now counter is |
|
3831 | 3867 | hardwired starting at 1 and one specifies the maximum number of |
|
3832 | 3868 | entries *in the outcache* (not the max prompt counter). This is |
|
3833 | 3869 | much better, since many statements won't increase the cache |
|
3834 | 3870 | count. It also eliminated some confusing options, now there's only |
|
3835 | 3871 | one: cache_size. |
|
3836 | 3872 | |
|
3837 | 3873 | * Added 'alias' magic function and magic_alias option in the |
|
3838 | 3874 | ipythonrc file. Now the user can easily define whatever names he |
|
3839 | 3875 | wants for the magic functions without having to play weird |
|
3840 | 3876 | namespace games. This gives IPython a real shell-like feel. |
|
3841 | 3877 | |
|
3842 | 3878 | * Fixed doc/?/?? for magics. Now all work, in all forms (explicit |
|
3843 | 3879 | @ or not). |
|
3844 | 3880 | |
|
3845 | 3881 | This was one of the last remaining 'visible' bugs (that I know |
|
3846 | 3882 | of). I think if I can clean up the session loading so it works |
|
3847 | 3883 | 100% I'll release a 0.2.0 version on c.p.l (talk to Janko first |
|
3848 | 3884 | about licensing). |
|
3849 | 3885 | |
|
3850 | 3886 | 2001-11-25 Fernando Perez <fperez@colorado.edu> |
|
3851 | 3887 | |
|
3852 | 3888 | * Rewrote somewhat oinfo (?/??). Nicer, now uses page() and |
|
3853 | 3889 | there's a cleaner distinction between what ? and ?? show. |
|
3854 | 3890 | |
|
3855 | 3891 | * Added screen_length option. Now the user can define his own |
|
3856 | 3892 | screen size for page() operations. |
|
3857 | 3893 | |
|
3858 | 3894 | * Implemented magic shell-like functions with automatic code |
|
3859 | 3895 | generation. Now adding another function is just a matter of adding |
|
3860 | 3896 | an entry to a dict, and the function is dynamically generated at |
|
3861 | 3897 | run-time. Python has some really cool features! |
|
3862 | 3898 | |
|
3863 | 3899 | * Renamed many options to cleanup conventions a little. Now all |
|
3864 | 3900 | are lowercase, and only underscores where needed. Also in the code |
|
3865 | 3901 | option name tables are clearer. |
|
3866 | 3902 | |
|
3867 | 3903 | * Changed prompts a little. Now input is 'In [n]:' instead of |
|
3868 | 3904 | 'In[n]:='. This allows it the numbers to be aligned with the |
|
3869 | 3905 | Out[n] numbers, and removes usage of ':=' which doesn't exist in |
|
3870 | 3906 | Python (it was a Mathematica thing). The '...' continuation prompt |
|
3871 | 3907 | was also changed a little to align better. |
|
3872 | 3908 | |
|
3873 | 3909 | * Fixed bug when flushing output cache. Not all _p<n> variables |
|
3874 | 3910 | exist, so their deletion needs to be wrapped in a try: |
|
3875 | 3911 | |
|
3876 | 3912 | * Figured out how to properly use inspect.formatargspec() (it |
|
3877 | 3913 | requires the args preceded by *). So I removed all the code from |
|
3878 | 3914 | _get_pdef in Magic, which was just replicating that. |
|
3879 | 3915 | |
|
3880 | 3916 | * Added test to prefilter to allow redefining magic function names |
|
3881 | 3917 | as variables. This is ok, since the @ form is always available, |
|
3882 | 3918 | but whe should allow the user to define a variable called 'ls' if |
|
3883 | 3919 | he needs it. |
|
3884 | 3920 | |
|
3885 | 3921 | * Moved the ToDo information from README into a separate ToDo. |
|
3886 | 3922 | |
|
3887 | 3923 | * General code cleanup and small bugfixes. I think it's close to a |
|
3888 | 3924 | state where it can be released, obviously with a big 'beta' |
|
3889 | 3925 | warning on it. |
|
3890 | 3926 | |
|
3891 | 3927 | * Got the magic function split to work. Now all magics are defined |
|
3892 | 3928 | in a separate class. It just organizes things a bit, and now |
|
3893 | 3929 | Xemacs behaves nicer (it was choking on InteractiveShell b/c it |
|
3894 | 3930 | was too long). |
|
3895 | 3931 | |
|
3896 | 3932 | * Changed @clear to @reset to avoid potential confusions with |
|
3897 | 3933 | the shell command clear. Also renamed @cl to @clear, which does |
|
3898 | 3934 | exactly what people expect it to from their shell experience. |
|
3899 | 3935 | |
|
3900 | 3936 | Added a check to the @reset command (since it's so |
|
3901 | 3937 | destructive, it's probably a good idea to ask for confirmation). |
|
3902 | 3938 | But now reset only works for full namespace resetting. Since the |
|
3903 | 3939 | del keyword is already there for deleting a few specific |
|
3904 | 3940 | variables, I don't see the point of having a redundant magic |
|
3905 | 3941 | function for the same task. |
|
3906 | 3942 | |
|
3907 | 3943 | 2001-11-24 Fernando Perez <fperez@colorado.edu> |
|
3908 | 3944 | |
|
3909 | 3945 | * Updated the builtin docs (esp. the ? ones). |
|
3910 | 3946 | |
|
3911 | 3947 | * Ran all the code through pychecker. Not terribly impressed with |
|
3912 | 3948 | it: lots of spurious warnings and didn't really find anything of |
|
3913 | 3949 | substance (just a few modules being imported and not used). |
|
3914 | 3950 | |
|
3915 | 3951 | * Implemented the new ultraTB functionality into IPython. New |
|
3916 | 3952 | option: xcolors. This chooses color scheme. xmode now only selects |
|
3917 | 3953 | between Plain and Verbose. Better orthogonality. |
|
3918 | 3954 | |
|
3919 | 3955 | * Large rewrite of ultraTB. Much cleaner now, with a separation of |
|
3920 | 3956 | mode and color scheme for the exception handlers. Now it's |
|
3921 | 3957 | possible to have the verbose traceback with no coloring. |
|
3922 | 3958 | |
|
3923 | 3959 | 2001-11-23 Fernando Perez <fperez@colorado.edu> |
|
3924 | 3960 | |
|
3925 | 3961 | * Version 0.1.12 released, 0.1.13 opened. |
|
3926 | 3962 | |
|
3927 | 3963 | * Removed option to set auto-quote and auto-paren escapes by |
|
3928 | 3964 | user. The chances of breaking valid syntax are just too high. If |
|
3929 | 3965 | someone *really* wants, they can always dig into the code. |
|
3930 | 3966 | |
|
3931 | 3967 | * Made prompt separators configurable. |
|
3932 | 3968 | |
|
3933 | 3969 | 2001-11-22 Fernando Perez <fperez@colorado.edu> |
|
3934 | 3970 | |
|
3935 | 3971 | * Small bugfixes in many places. |
|
3936 | 3972 | |
|
3937 | 3973 | * Removed the MyCompleter class from ipplib. It seemed redundant |
|
3938 | 3974 | with the C-p,C-n history search functionality. Less code to |
|
3939 | 3975 | maintain. |
|
3940 | 3976 | |
|
3941 | 3977 | * Moved all the original ipython.py code into ipythonlib.py. Right |
|
3942 | 3978 | now it's just one big dump into a function called make_IPython, so |
|
3943 | 3979 | no real modularity has been gained. But at least it makes the |
|
3944 | 3980 | wrapper script tiny, and since ipythonlib is a module, it gets |
|
3945 | 3981 | compiled and startup is much faster. |
|
3946 | 3982 | |
|
3947 | 3983 | This is a reasobably 'deep' change, so we should test it for a |
|
3948 | 3984 | while without messing too much more with the code. |
|
3949 | 3985 | |
|
3950 | 3986 | 2001-11-21 Fernando Perez <fperez@colorado.edu> |
|
3951 | 3987 | |
|
3952 | 3988 | * Version 0.1.11 released, 0.1.12 opened for further work. |
|
3953 | 3989 | |
|
3954 | 3990 | * Removed dependency on Itpl. It was only needed in one place. It |
|
3955 | 3991 | would be nice if this became part of python, though. It makes life |
|
3956 | 3992 | *a lot* easier in some cases. |
|
3957 | 3993 | |
|
3958 | 3994 | * Simplified the prefilter code a bit. Now all handlers are |
|
3959 | 3995 | expected to explicitly return a value (at least a blank string). |
|
3960 | 3996 | |
|
3961 | 3997 | * Heavy edits in ipplib. Removed the help system altogether. Now |
|
3962 | 3998 | obj?/?? is used for inspecting objects, a magic @doc prints |
|
3963 | 3999 | docstrings, and full-blown Python help is accessed via the 'help' |
|
3964 | 4000 | keyword. This cleans up a lot of code (less to maintain) and does |
|
3965 | 4001 | the job. Since 'help' is now a standard Python component, might as |
|
3966 | 4002 | well use it and remove duplicate functionality. |
|
3967 | 4003 | |
|
3968 | 4004 | Also removed the option to use ipplib as a standalone program. By |
|
3969 | 4005 | now it's too dependent on other parts of IPython to function alone. |
|
3970 | 4006 | |
|
3971 | 4007 | * Fixed bug in genutils.pager. It would crash if the pager was |
|
3972 | 4008 | exited immediately after opening (broken pipe). |
|
3973 | 4009 | |
|
3974 | 4010 | * Trimmed down the VerboseTB reporting a little. The header is |
|
3975 | 4011 | much shorter now and the repeated exception arguments at the end |
|
3976 | 4012 | have been removed. For interactive use the old header seemed a bit |
|
3977 | 4013 | excessive. |
|
3978 | 4014 | |
|
3979 | 4015 | * Fixed small bug in output of @whos for variables with multi-word |
|
3980 | 4016 | types (only first word was displayed). |
|
3981 | 4017 | |
|
3982 | 4018 | 2001-11-17 Fernando Perez <fperez@colorado.edu> |
|
3983 | 4019 | |
|
3984 | 4020 | * Version 0.1.10 released, 0.1.11 opened for further work. |
|
3985 | 4021 | |
|
3986 | 4022 | * Modified dirs and friends. dirs now *returns* the stack (not |
|
3987 | 4023 | prints), so one can manipulate it as a variable. Convenient to |
|
3988 | 4024 | travel along many directories. |
|
3989 | 4025 | |
|
3990 | 4026 | * Fixed bug in magic_pdef: would only work with functions with |
|
3991 | 4027 | arguments with default values. |
|
3992 | 4028 | |
|
3993 | 4029 | 2001-11-14 Fernando Perez <fperez@colorado.edu> |
|
3994 | 4030 | |
|
3995 | 4031 | * Added the PhysicsInput stuff to dot_ipython so it ships as an |
|
3996 | 4032 | example with IPython. Various other minor fixes and cleanups. |
|
3997 | 4033 | |
|
3998 | 4034 | * Version 0.1.9 released, 0.1.10 opened for further work. |
|
3999 | 4035 | |
|
4000 | 4036 | * Added sys.path to the list of directories searched in the |
|
4001 | 4037 | execfile= option. It used to be the current directory and the |
|
4002 | 4038 | user's IPYTHONDIR only. |
|
4003 | 4039 | |
|
4004 | 4040 | 2001-11-13 Fernando Perez <fperez@colorado.edu> |
|
4005 | 4041 | |
|
4006 | 4042 | * Reinstated the raw_input/prefilter separation that Janko had |
|
4007 | 4043 | initially. This gives a more convenient setup for extending the |
|
4008 | 4044 | pre-processor from the outside: raw_input always gets a string, |
|
4009 | 4045 | and prefilter has to process it. We can then redefine prefilter |
|
4010 | 4046 | from the outside and implement extensions for special |
|
4011 | 4047 | purposes. |
|
4012 | 4048 | |
|
4013 | 4049 | Today I got one for inputting PhysicalQuantity objects |
|
4014 | 4050 | (from Scientific) without needing any function calls at |
|
4015 | 4051 | all. Extremely convenient, and it's all done as a user-level |
|
4016 | 4052 | extension (no IPython code was touched). Now instead of: |
|
4017 | 4053 | a = PhysicalQuantity(4.2,'m/s**2') |
|
4018 | 4054 | one can simply say |
|
4019 | 4055 | a = 4.2 m/s**2 |
|
4020 | 4056 | or even |
|
4021 | 4057 | a = 4.2 m/s^2 |
|
4022 | 4058 | |
|
4023 | 4059 | I use this, but it's also a proof of concept: IPython really is |
|
4024 | 4060 | fully user-extensible, even at the level of the parsing of the |
|
4025 | 4061 | command line. It's not trivial, but it's perfectly doable. |
|
4026 | 4062 | |
|
4027 | 4063 | * Added 'add_flip' method to inclusion conflict resolver. Fixes |
|
4028 | 4064 | the problem of modules being loaded in the inverse order in which |
|
4029 | 4065 | they were defined in |
|
4030 | 4066 | |
|
4031 | 4067 | * Version 0.1.8 released, 0.1.9 opened for further work. |
|
4032 | 4068 | |
|
4033 | 4069 | * Added magics pdef, source and file. They respectively show the |
|
4034 | 4070 | definition line ('prototype' in C), source code and full python |
|
4035 | 4071 | file for any callable object. The object inspector oinfo uses |
|
4036 | 4072 | these to show the same information. |
|
4037 | 4073 | |
|
4038 | 4074 | * Version 0.1.7 released, 0.1.8 opened for further work. |
|
4039 | 4075 | |
|
4040 | 4076 | * Separated all the magic functions into a class called Magic. The |
|
4041 | 4077 | InteractiveShell class was becoming too big for Xemacs to handle |
|
4042 | 4078 | (de-indenting a line would lock it up for 10 seconds while it |
|
4043 | 4079 | backtracked on the whole class!) |
|
4044 | 4080 | |
|
4045 | 4081 | FIXME: didn't work. It can be done, but right now namespaces are |
|
4046 | 4082 | all messed up. Do it later (reverted it for now, so at least |
|
4047 | 4083 | everything works as before). |
|
4048 | 4084 | |
|
4049 | 4085 | * Got the object introspection system (magic_oinfo) working! I |
|
4050 | 4086 | think this is pretty much ready for release to Janko, so he can |
|
4051 | 4087 | test it for a while and then announce it. Pretty much 100% of what |
|
4052 | 4088 | I wanted for the 'phase 1' release is ready. Happy, tired. |
|
4053 | 4089 | |
|
4054 | 4090 | 2001-11-12 Fernando Perez <fperez@colorado.edu> |
|
4055 | 4091 | |
|
4056 | 4092 | * Version 0.1.6 released, 0.1.7 opened for further work. |
|
4057 | 4093 | |
|
4058 | 4094 | * Fixed bug in printing: it used to test for truth before |
|
4059 | 4095 | printing, so 0 wouldn't print. Now checks for None. |
|
4060 | 4096 | |
|
4061 | 4097 | * Fixed bug where auto-execs increase the prompt counter by 2 (b/c |
|
4062 | 4098 | they have to call len(str(sys.ps1)) ). But the fix is ugly, it |
|
4063 | 4099 | reaches by hand into the outputcache. Think of a better way to do |
|
4064 | 4100 | this later. |
|
4065 | 4101 | |
|
4066 | 4102 | * Various small fixes thanks to Nathan's comments. |
|
4067 | 4103 | |
|
4068 | 4104 | * Changed magic_pprint to magic_Pprint. This way it doesn't |
|
4069 | 4105 | collide with pprint() and the name is consistent with the command |
|
4070 | 4106 | line option. |
|
4071 | 4107 | |
|
4072 | 4108 | * Changed prompt counter behavior to be fully like |
|
4073 | 4109 | Mathematica's. That is, even input that doesn't return a result |
|
4074 | 4110 | raises the prompt counter. The old behavior was kind of confusing |
|
4075 | 4111 | (getting the same prompt number several times if the operation |
|
4076 | 4112 | didn't return a result). |
|
4077 | 4113 | |
|
4078 | 4114 | * Fixed Nathan's last name in a couple of places (Gray, not Graham). |
|
4079 | 4115 | |
|
4080 | 4116 | * Fixed -Classic mode (wasn't working anymore). |
|
4081 | 4117 | |
|
4082 | 4118 | * Added colored prompts using Nathan's new code. Colors are |
|
4083 | 4119 | currently hardwired, they can be user-configurable. For |
|
4084 | 4120 | developers, they can be chosen in file ipythonlib.py, at the |
|
4085 | 4121 | beginning of the CachedOutput class def. |
|
4086 | 4122 | |
|
4087 | 4123 | 2001-11-11 Fernando Perez <fperez@colorado.edu> |
|
4088 | 4124 | |
|
4089 | 4125 | * Version 0.1.5 released, 0.1.6 opened for further work. |
|
4090 | 4126 | |
|
4091 | 4127 | * Changed magic_env to *return* the environment as a dict (not to |
|
4092 | 4128 | print it). This way it prints, but it can also be processed. |
|
4093 | 4129 | |
|
4094 | 4130 | * Added Verbose exception reporting to interactive |
|
4095 | 4131 | exceptions. Very nice, now even 1/0 at the prompt gives a verbose |
|
4096 | 4132 | traceback. Had to make some changes to the ultraTB file. This is |
|
4097 | 4133 | probably the last 'big' thing in my mental todo list. This ties |
|
4098 | 4134 | in with the next entry: |
|
4099 | 4135 | |
|
4100 | 4136 | * Changed -Xi and -Xf to a single -xmode option. Now all the user |
|
4101 | 4137 | has to specify is Plain, Color or Verbose for all exception |
|
4102 | 4138 | handling. |
|
4103 | 4139 | |
|
4104 | 4140 | * Removed ShellServices option. All this can really be done via |
|
4105 | 4141 | the magic system. It's easier to extend, cleaner and has automatic |
|
4106 | 4142 | namespace protection and documentation. |
|
4107 | 4143 | |
|
4108 | 4144 | 2001-11-09 Fernando Perez <fperez@colorado.edu> |
|
4109 | 4145 | |
|
4110 | 4146 | * Fixed bug in output cache flushing (missing parameter to |
|
4111 | 4147 | __init__). Other small bugs fixed (found using pychecker). |
|
4112 | 4148 | |
|
4113 | 4149 | * Version 0.1.4 opened for bugfixing. |
|
4114 | 4150 | |
|
4115 | 4151 | 2001-11-07 Fernando Perez <fperez@colorado.edu> |
|
4116 | 4152 | |
|
4117 | 4153 | * Version 0.1.3 released, mainly because of the raw_input bug. |
|
4118 | 4154 | |
|
4119 | 4155 | * Fixed NASTY bug in raw_input: input line wasn't properly parsed |
|
4120 | 4156 | and when testing for whether things were callable, a call could |
|
4121 | 4157 | actually be made to certain functions. They would get called again |
|
4122 | 4158 | once 'really' executed, with a resulting double call. A disaster |
|
4123 | 4159 | in many cases (list.reverse() would never work!). |
|
4124 | 4160 | |
|
4125 | 4161 | * Removed prefilter() function, moved its code to raw_input (which |
|
4126 | 4162 | after all was just a near-empty caller for prefilter). This saves |
|
4127 | 4163 | a function call on every prompt, and simplifies the class a tiny bit. |
|
4128 | 4164 | |
|
4129 | 4165 | * Fix _ip to __ip name in magic example file. |
|
4130 | 4166 | |
|
4131 | 4167 | * Changed 'tar -x -f' to 'tar xvf' in auto-installer. This should |
|
4132 | 4168 | work with non-gnu versions of tar. |
|
4133 | 4169 | |
|
4134 | 4170 | 2001-11-06 Fernando Perez <fperez@colorado.edu> |
|
4135 | 4171 | |
|
4136 | 4172 | * Version 0.1.2. Just to keep track of the recent changes. |
|
4137 | 4173 | |
|
4138 | 4174 | * Fixed nasty bug in output prompt routine. It used to check 'if |
|
4139 | 4175 | arg != None...'. Problem is, this fails if arg implements a |
|
4140 | 4176 | special comparison (__cmp__) which disallows comparing to |
|
4141 | 4177 | None. Found it when trying to use the PhysicalQuantity module from |
|
4142 | 4178 | ScientificPython. |
|
4143 | 4179 | |
|
4144 | 4180 | 2001-11-05 Fernando Perez <fperez@colorado.edu> |
|
4145 | 4181 | |
|
4146 | 4182 | * Also added dirs. Now the pushd/popd/dirs family functions |
|
4147 | 4183 | basically like the shell, with the added convenience of going home |
|
4148 | 4184 | when called with no args. |
|
4149 | 4185 | |
|
4150 | 4186 | * pushd/popd slightly modified to mimic shell behavior more |
|
4151 | 4187 | closely. |
|
4152 | 4188 | |
|
4153 | 4189 | * Added env,pushd,popd from ShellServices as magic functions. I |
|
4154 | 4190 | think the cleanest will be to port all desired functions from |
|
4155 | 4191 | ShellServices as magics and remove ShellServices altogether. This |
|
4156 | 4192 | will provide a single, clean way of adding functionality |
|
4157 | 4193 | (shell-type or otherwise) to IP. |
|
4158 | 4194 | |
|
4159 | 4195 | 2001-11-04 Fernando Perez <fperez@colorado.edu> |
|
4160 | 4196 | |
|
4161 | 4197 | * Added .ipython/ directory to sys.path. This way users can keep |
|
4162 | 4198 | customizations there and access them via import. |
|
4163 | 4199 | |
|
4164 | 4200 | 2001-11-03 Fernando Perez <fperez@colorado.edu> |
|
4165 | 4201 | |
|
4166 | 4202 | * Opened version 0.1.1 for new changes. |
|
4167 | 4203 | |
|
4168 | 4204 | * Changed version number to 0.1.0: first 'public' release, sent to |
|
4169 | 4205 | Nathan and Janko. |
|
4170 | 4206 | |
|
4171 | 4207 | * Lots of small fixes and tweaks. |
|
4172 | 4208 | |
|
4173 | 4209 | * Minor changes to whos format. Now strings are shown, snipped if |
|
4174 | 4210 | too long. |
|
4175 | 4211 | |
|
4176 | 4212 | * Changed ShellServices to work on __main__ so they show up in @who |
|
4177 | 4213 | |
|
4178 | 4214 | * Help also works with ? at the end of a line: |
|
4179 | 4215 | ?sin and sin? |
|
4180 | 4216 | both produce the same effect. This is nice, as often I use the |
|
4181 | 4217 | tab-complete to find the name of a method, but I used to then have |
|
4182 | 4218 | to go to the beginning of the line to put a ? if I wanted more |
|
4183 | 4219 | info. Now I can just add the ? and hit return. Convenient. |
|
4184 | 4220 | |
|
4185 | 4221 | 2001-11-02 Fernando Perez <fperez@colorado.edu> |
|
4186 | 4222 | |
|
4187 | 4223 | * Python version check (>=2.1) added. |
|
4188 | 4224 | |
|
4189 | 4225 | * Added LazyPython documentation. At this point the docs are quite |
|
4190 | 4226 | a mess. A cleanup is in order. |
|
4191 | 4227 | |
|
4192 | 4228 | * Auto-installer created. For some bizarre reason, the zipfiles |
|
4193 | 4229 | module isn't working on my system. So I made a tar version |
|
4194 | 4230 | (hopefully the command line options in various systems won't kill |
|
4195 | 4231 | me). |
|
4196 | 4232 | |
|
4197 | 4233 | * Fixes to Struct in genutils. Now all dictionary-like methods are |
|
4198 | 4234 | protected (reasonably). |
|
4199 | 4235 | |
|
4200 | 4236 | * Added pager function to genutils and changed ? to print usage |
|
4201 | 4237 | note through it (it was too long). |
|
4202 | 4238 | |
|
4203 | 4239 | * Added the LazyPython functionality. Works great! I changed the |
|
4204 | 4240 | auto-quote escape to ';', it's on home row and next to '. But |
|
4205 | 4241 | both auto-quote and auto-paren (still /) escapes are command-line |
|
4206 | 4242 | parameters. |
|
4207 | 4243 | |
|
4208 | 4244 | |
|
4209 | 4245 | 2001-11-01 Fernando Perez <fperez@colorado.edu> |
|
4210 | 4246 | |
|
4211 | 4247 | * Version changed to 0.0.7. Fairly large change: configuration now |
|
4212 | 4248 | is all stored in a directory, by default .ipython. There, all |
|
4213 | 4249 | config files have normal looking names (not .names) |
|
4214 | 4250 | |
|
4215 | 4251 | * Version 0.0.6 Released first to Lucas and Archie as a test |
|
4216 | 4252 | run. Since it's the first 'semi-public' release, change version to |
|
4217 | 4253 | > 0.0.6 for any changes now. |
|
4218 | 4254 | |
|
4219 | 4255 | * Stuff I had put in the ipplib.py changelog: |
|
4220 | 4256 | |
|
4221 | 4257 | Changes to InteractiveShell: |
|
4222 | 4258 | |
|
4223 | 4259 | - Made the usage message a parameter. |
|
4224 | 4260 | |
|
4225 | 4261 | - Require the name of the shell variable to be given. It's a bit |
|
4226 | 4262 | of a hack, but allows the name 'shell' not to be hardwire in the |
|
4227 | 4263 | magic (@) handler, which is problematic b/c it requires |
|
4228 | 4264 | polluting the global namespace with 'shell'. This in turn is |
|
4229 | 4265 | fragile: if a user redefines a variable called shell, things |
|
4230 | 4266 | break. |
|
4231 | 4267 | |
|
4232 | 4268 | - magic @: all functions available through @ need to be defined |
|
4233 | 4269 | as magic_<name>, even though they can be called simply as |
|
4234 | 4270 | @<name>. This allows the special command @magic to gather |
|
4235 | 4271 | information automatically about all existing magic functions, |
|
4236 | 4272 | even if they are run-time user extensions, by parsing the shell |
|
4237 | 4273 | instance __dict__ looking for special magic_ names. |
|
4238 | 4274 | |
|
4239 | 4275 | - mainloop: added *two* local namespace parameters. This allows |
|
4240 | 4276 | the class to differentiate between parameters which were there |
|
4241 | 4277 | before and after command line initialization was processed. This |
|
4242 | 4278 | way, later @who can show things loaded at startup by the |
|
4243 | 4279 | user. This trick was necessary to make session saving/reloading |
|
4244 | 4280 | really work: ideally after saving/exiting/reloading a session, |
|
4245 | 4281 | *everythin* should look the same, including the output of @who. I |
|
4246 | 4282 | was only able to make this work with this double namespace |
|
4247 | 4283 | trick. |
|
4248 | 4284 | |
|
4249 | 4285 | - added a header to the logfile which allows (almost) full |
|
4250 | 4286 | session restoring. |
|
4251 | 4287 | |
|
4252 | 4288 | - prepend lines beginning with @ or !, with a and log |
|
4253 | 4289 | them. Why? !lines: may be useful to know what you did @lines: |
|
4254 | 4290 | they may affect session state. So when restoring a session, at |
|
4255 | 4291 | least inform the user of their presence. I couldn't quite get |
|
4256 | 4292 | them to properly re-execute, but at least the user is warned. |
|
4257 | 4293 | |
|
4258 | 4294 | * Started ChangeLog. |
General Comments 0
You need to be logged in to leave comments.
Login now