Show More
@@ -1,58 +1,35 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | # encoding: utf-8 |
|
3 | 3 | """ |
|
4 | Oh my @#*%, where did ipapi go? | |
|
5 | ||
|
6 | Originally, this module was designed to be a public api for IPython. It is | |
|
7 | now deprecated and replaced by :class:`IPython.core.Interactive` shell. | |
|
8 | Almost all of the methods that were here are now there, but possibly renamed. | |
|
9 | ||
|
10 | During our transition, we will keep this simple module with its :func:`get` | |
|
11 | function. It too will eventually go away when the new component querying | |
|
12 | interface is fully used. | |
|
13 | ||
|
14 | Authors: | |
|
15 | ||
|
16 | * Brian Granger | |
|
4 | This module is *completely* deprecated and should no longer be used for | |
|
5 | any purpose. Currently, we have a few parts of the core that have | |
|
6 | not been componentized and thus, still rely on this module. When everything | |
|
7 | has been made into a component, this module will be sent to deathrow. | |
|
17 | 8 | """ |
|
18 | 9 | |
|
19 | 10 | #----------------------------------------------------------------------------- |
|
20 | 11 | # Copyright (C) 2008-2009 The IPython Development Team |
|
21 | 12 | # |
|
22 | 13 | # Distributed under the terms of the BSD License. The full license is in |
|
23 | 14 | # the file COPYING, distributed as part of this software. |
|
24 | 15 | #----------------------------------------------------------------------------- |
|
25 | 16 | |
|
26 | 17 | #----------------------------------------------------------------------------- |
|
27 | 18 | # Imports |
|
28 | 19 | #----------------------------------------------------------------------------- |
|
29 | 20 | |
|
30 | 21 | from IPython.core.error import TryNext, UsageError |
|
31 | 22 | |
|
32 | 23 | #----------------------------------------------------------------------------- |
|
33 | 24 | # Classes and functions |
|
34 | 25 | #----------------------------------------------------------------------------- |
|
35 | 26 | |
|
36 | 27 | def get(): |
|
37 | 28 | """Get the most recently created InteractiveShell instance.""" |
|
38 | 29 | from IPython.core.iplib import InteractiveShell |
|
39 | 30 | insts = InteractiveShell.get_instances() |
|
40 | 31 | most_recent = insts[0] |
|
41 | 32 | for inst in insts[1:]: |
|
42 | 33 | if inst.created > most_recent.created: |
|
43 | 34 | most_recent = inst |
|
44 | 35 | return most_recent |
|
45 | ||
|
46 | def launch_new_instance(): | |
|
47 | """Create a run a full blown IPython instance""" | |
|
48 | from IPython.core.ipapp import IPythonApp | |
|
49 | app = IPythonApp() | |
|
50 | app.start() | |
|
51 | ||
|
52 | ||
|
53 | ||
|
54 | ||
|
55 | ||
|
56 | ||
|
57 | ||
|
58 |
@@ -1,543 +1,545 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | # encoding: utf-8 |
|
3 | 3 | """ |
|
4 | 4 | The main IPython application object |
|
5 | 5 | |
|
6 | 6 | Authors: |
|
7 | 7 | |
|
8 | 8 | * Brian Granger |
|
9 | 9 | * Fernando Perez |
|
10 | 10 | |
|
11 | 11 | Notes |
|
12 | 12 | ----- |
|
13 | 13 | """ |
|
14 | 14 | |
|
15 | 15 | #----------------------------------------------------------------------------- |
|
16 | 16 | # Copyright (C) 2008-2009 The IPython Development Team |
|
17 | 17 | # |
|
18 | 18 | # Distributed under the terms of the BSD License. The full license is in |
|
19 | 19 | # the file COPYING, distributed as part of this software. |
|
20 | 20 | #----------------------------------------------------------------------------- |
|
21 | 21 | |
|
22 | 22 | #----------------------------------------------------------------------------- |
|
23 | 23 | # Imports |
|
24 | 24 | #----------------------------------------------------------------------------- |
|
25 | 25 | |
|
26 | 26 | import logging |
|
27 | 27 | import os |
|
28 | 28 | import sys |
|
29 | 29 | import warnings |
|
30 | 30 | |
|
31 | 31 | from IPython.core.application import Application, IPythonArgParseConfigLoader |
|
32 | 32 | from IPython.core import release |
|
33 | 33 | from IPython.core.iplib import InteractiveShell |
|
34 | 34 | from IPython.config.loader import ( |
|
35 | 35 | NoConfigDefault, |
|
36 | 36 | Config, |
|
37 | 37 | ConfigError, |
|
38 | 38 | PyFileConfigLoader |
|
39 | 39 | ) |
|
40 | 40 | |
|
41 | 41 | from IPython.lib import inputhook |
|
42 | 42 | |
|
43 | 43 | from IPython.utils.ipstruct import Struct |
|
44 | 44 | from IPython.utils.genutils import filefind, get_ipython_dir |
|
45 | 45 | |
|
46 | 46 | #----------------------------------------------------------------------------- |
|
47 | 47 | # Utilities and helpers |
|
48 | 48 | #----------------------------------------------------------------------------- |
|
49 | 49 | |
|
50 | 50 | |
|
51 | 51 | ipython_desc = """ |
|
52 | 52 | A Python shell with automatic history (input and output), dynamic object |
|
53 | 53 | introspection, easier configuration, command completion, access to the system |
|
54 | 54 | shell and more. |
|
55 | 55 | """ |
|
56 | 56 | |
|
57 | 57 | def pylab_warning(): |
|
58 | 58 | msg = """ |
|
59 | 59 | |
|
60 | 60 | IPython's -pylab mode has been disabled until matplotlib supports this version |
|
61 | 61 | of IPython. This version of IPython has greatly improved GUI integration that |
|
62 | 62 | matplotlib will soon be able to take advantage of. This will eventually |
|
63 | 63 | result in greater stability and a richer API for matplotlib under IPython. |
|
64 | 64 | However during this transition, you will either need to use an older version |
|
65 | 65 | of IPython, or do the following to use matplotlib interactively:: |
|
66 | 66 | |
|
67 | 67 | import matplotlib |
|
68 | 68 | matplotlib.interactive(True) |
|
69 | 69 | matplotlib.use('wxagg') # adjust for your backend |
|
70 | 70 | %gui -a wx # adjust for your GUI |
|
71 | 71 | from matplotlib import pyplot as plt |
|
72 | 72 | |
|
73 | 73 | See the %gui magic for information on the new interface. |
|
74 | 74 | """ |
|
75 | 75 | warnings.warn(msg, category=DeprecationWarning, stacklevel=1) |
|
76 | 76 | |
|
77 | 77 | |
|
78 | 78 | #----------------------------------------------------------------------------- |
|
79 | 79 | # Main classes and functions |
|
80 | 80 | #----------------------------------------------------------------------------- |
|
81 | 81 | |
|
82 | 82 | cl_args = ( |
|
83 | 83 | (('-autocall',), dict( |
|
84 | 84 | type=int, dest='InteractiveShell.autocall', default=NoConfigDefault, |
|
85 | 85 | help='Set the autocall value (0,1,2).', |
|
86 | 86 | metavar='InteractiveShell.autocall') |
|
87 | 87 | ), |
|
88 | 88 | (('-autoindent',), dict( |
|
89 | 89 | action='store_true', dest='InteractiveShell.autoindent', default=NoConfigDefault, |
|
90 | 90 | help='Turn on autoindenting.') |
|
91 | 91 | ), |
|
92 | 92 | (('-noautoindent',), dict( |
|
93 | 93 | action='store_false', dest='InteractiveShell.autoindent', default=NoConfigDefault, |
|
94 | 94 | help='Turn off autoindenting.') |
|
95 | 95 | ), |
|
96 | 96 | (('-automagic',), dict( |
|
97 | 97 | action='store_true', dest='InteractiveShell.automagic', default=NoConfigDefault, |
|
98 | 98 | help='Turn on the auto calling of magic commands.') |
|
99 | 99 | ), |
|
100 | 100 | (('-noautomagic',), dict( |
|
101 | 101 | action='store_false', dest='InteractiveShell.automagic', default=NoConfigDefault, |
|
102 | 102 | help='Turn off the auto calling of magic commands.') |
|
103 | 103 | ), |
|
104 | 104 | (('-autoedit_syntax',), dict( |
|
105 | 105 | action='store_true', dest='InteractiveShell.autoedit_syntax', default=NoConfigDefault, |
|
106 | 106 | help='Turn on auto editing of files with syntax errors.') |
|
107 | 107 | ), |
|
108 | 108 | (('-noautoedit_syntax',), dict( |
|
109 | 109 | action='store_false', dest='InteractiveShell.autoedit_syntax', default=NoConfigDefault, |
|
110 | 110 | help='Turn off auto editing of files with syntax errors.') |
|
111 | 111 | ), |
|
112 | 112 | (('-banner',), dict( |
|
113 | 113 | action='store_true', dest='Global.display_banner', default=NoConfigDefault, |
|
114 | 114 | help='Display a banner upon starting IPython.') |
|
115 | 115 | ), |
|
116 | 116 | (('-nobanner',), dict( |
|
117 | 117 | action='store_false', dest='Global.display_banner', default=NoConfigDefault, |
|
118 | 118 | help="Don't display a banner upon starting IPython.") |
|
119 | 119 | ), |
|
120 | 120 | (('-cache_size',), dict( |
|
121 | 121 | type=int, dest='InteractiveShell.cache_size', default=NoConfigDefault, |
|
122 | 122 | help="Set the size of the output cache.", |
|
123 | 123 | metavar='InteractiveShell.cache_size') |
|
124 | 124 | ), |
|
125 | 125 | (('-classic',), dict( |
|
126 | 126 | action='store_true', dest='Global.classic', default=NoConfigDefault, |
|
127 | 127 | help="Gives IPython a similar feel to the classic Python prompt.") |
|
128 | 128 | ), |
|
129 | 129 | (('-colors',), dict( |
|
130 | 130 | type=str, dest='InteractiveShell.colors', default=NoConfigDefault, |
|
131 | 131 | help="Set the color scheme (NoColor, Linux, and LightBG).", |
|
132 | 132 | metavar='InteractiveShell.colors') |
|
133 | 133 | ), |
|
134 | 134 | (('-color_info',), dict( |
|
135 | 135 | action='store_true', dest='InteractiveShell.color_info', default=NoConfigDefault, |
|
136 | 136 | help="Enable using colors for info related things.") |
|
137 | 137 | ), |
|
138 | 138 | (('-nocolor_info',), dict( |
|
139 | 139 | action='store_false', dest='InteractiveShell.color_info', default=NoConfigDefault, |
|
140 | 140 | help="Disable using colors for info related things.") |
|
141 | 141 | ), |
|
142 | 142 | (('-confirm_exit',), dict( |
|
143 | 143 | action='store_true', dest='InteractiveShell.confirm_exit', default=NoConfigDefault, |
|
144 | 144 | help="Prompt the user when existing.") |
|
145 | 145 | ), |
|
146 | 146 | (('-noconfirm_exit',), dict( |
|
147 | 147 | action='store_false', dest='InteractiveShell.confirm_exit', default=NoConfigDefault, |
|
148 | 148 | help="Don't prompt the user when existing.") |
|
149 | 149 | ), |
|
150 | 150 | (('-deep_reload',), dict( |
|
151 | 151 | action='store_true', dest='InteractiveShell.deep_reload', default=NoConfigDefault, |
|
152 | 152 | help="Enable deep (recursive) reloading by default.") |
|
153 | 153 | ), |
|
154 | 154 | (('-nodeep_reload',), dict( |
|
155 | 155 | action='store_false', dest='InteractiveShell.deep_reload', default=NoConfigDefault, |
|
156 | 156 | help="Disable deep (recursive) reloading by default.") |
|
157 | 157 | ), |
|
158 | 158 | (('-editor',), dict( |
|
159 | 159 | type=str, dest='InteractiveShell.editor', default=NoConfigDefault, |
|
160 | 160 | help="Set the editor used by IPython (default to $EDITOR/vi/notepad).", |
|
161 | 161 | metavar='InteractiveShell.editor') |
|
162 | 162 | ), |
|
163 | 163 | (('-log','-l'), dict( |
|
164 | 164 | action='store_true', dest='InteractiveShell.logstart', default=NoConfigDefault, |
|
165 | 165 | help="Start logging to the default file (./ipython_log.py).") |
|
166 | 166 | ), |
|
167 | 167 | (('-logfile','-lf'), dict( |
|
168 | 168 | type=str, dest='InteractiveShell.logfile', default=NoConfigDefault, |
|
169 | 169 | help="Start logging to logfile.", |
|
170 | 170 | metavar='InteractiveShell.logfile') |
|
171 | 171 | ), |
|
172 | 172 | (('-logappend','-la'), dict( |
|
173 | 173 | type=str, dest='InteractiveShell.logappend', default=NoConfigDefault, |
|
174 | 174 | help="Start logging to logappend in append mode.", |
|
175 | 175 | metavar='InteractiveShell.logfile') |
|
176 | 176 | ), |
|
177 | 177 | (('-pdb',), dict( |
|
178 | 178 | action='store_true', dest='InteractiveShell.pdb', default=NoConfigDefault, |
|
179 | 179 | help="Enable auto calling the pdb debugger after every exception.") |
|
180 | 180 | ), |
|
181 | 181 | (('-nopdb',), dict( |
|
182 | 182 | action='store_false', dest='InteractiveShell.pdb', default=NoConfigDefault, |
|
183 | 183 | help="Disable auto calling the pdb debugger after every exception.") |
|
184 | 184 | ), |
|
185 | 185 | (('-pprint',), dict( |
|
186 | 186 | action='store_true', dest='InteractiveShell.pprint', default=NoConfigDefault, |
|
187 | 187 | help="Enable auto pretty printing of results.") |
|
188 | 188 | ), |
|
189 | 189 | (('-nopprint',), dict( |
|
190 | 190 | action='store_false', dest='InteractiveShell.pprint', default=NoConfigDefault, |
|
191 | 191 | help="Disable auto auto pretty printing of results.") |
|
192 | 192 | ), |
|
193 | 193 | (('-prompt_in1','-pi1'), dict( |
|
194 | 194 | type=str, dest='InteractiveShell.prompt_in1', default=NoConfigDefault, |
|
195 | 195 | help="Set the main input prompt ('In [\#]: ')", |
|
196 | 196 | metavar='InteractiveShell.prompt_in1') |
|
197 | 197 | ), |
|
198 | 198 | (('-prompt_in2','-pi2'), dict( |
|
199 | 199 | type=str, dest='InteractiveShell.prompt_in2', default=NoConfigDefault, |
|
200 | 200 | help="Set the secondary input prompt (' .\D.: ')", |
|
201 | 201 | metavar='InteractiveShell.prompt_in2') |
|
202 | 202 | ), |
|
203 | 203 | (('-prompt_out','-po'), dict( |
|
204 | 204 | type=str, dest='InteractiveShell.prompt_out', default=NoConfigDefault, |
|
205 | 205 | help="Set the output prompt ('Out[\#]:')", |
|
206 | 206 | metavar='InteractiveShell.prompt_out') |
|
207 | 207 | ), |
|
208 | 208 | (('-quick',), dict( |
|
209 | 209 | action='store_true', dest='Global.quick', default=NoConfigDefault, |
|
210 | 210 | help="Enable quick startup with no config files.") |
|
211 | 211 | ), |
|
212 | 212 | (('-readline',), dict( |
|
213 | 213 | action='store_true', dest='InteractiveShell.readline_use', default=NoConfigDefault, |
|
214 | 214 | help="Enable readline for command line usage.") |
|
215 | 215 | ), |
|
216 | 216 | (('-noreadline',), dict( |
|
217 | 217 | action='store_false', dest='InteractiveShell.readline_use', default=NoConfigDefault, |
|
218 | 218 | help="Disable readline for command line usage.") |
|
219 | 219 | ), |
|
220 | 220 | (('-screen_length','-sl'), dict( |
|
221 | 221 | type=int, dest='InteractiveShell.screen_length', default=NoConfigDefault, |
|
222 | 222 | help='Number of lines on screen, used to control printing of long strings.', |
|
223 | 223 | metavar='InteractiveShell.screen_length') |
|
224 | 224 | ), |
|
225 | 225 | (('-separate_in','-si'), dict( |
|
226 | 226 | type=str, dest='InteractiveShell.separate_in', default=NoConfigDefault, |
|
227 | 227 | help="Separator before input prompts. Default '\n'.", |
|
228 | 228 | metavar='InteractiveShell.separate_in') |
|
229 | 229 | ), |
|
230 | 230 | (('-separate_out','-so'), dict( |
|
231 | 231 | type=str, dest='InteractiveShell.separate_out', default=NoConfigDefault, |
|
232 | 232 | help="Separator before output prompts. Default 0 (nothing).", |
|
233 | 233 | metavar='InteractiveShell.separate_out') |
|
234 | 234 | ), |
|
235 | 235 | (('-separate_out2','-so2'), dict( |
|
236 | 236 | type=str, dest='InteractiveShell.separate_out2', default=NoConfigDefault, |
|
237 | 237 | help="Separator after output prompts. Default 0 (nonight).", |
|
238 | 238 | metavar='InteractiveShell.separate_out2') |
|
239 | 239 | ), |
|
240 | 240 | (('-nosep',), dict( |
|
241 | 241 | action='store_true', dest='Global.nosep', default=NoConfigDefault, |
|
242 | 242 | help="Eliminate all spacing between prompts.") |
|
243 | 243 | ), |
|
244 | 244 | (('-term_title',), dict( |
|
245 | 245 | action='store_true', dest='InteractiveShell.term_title', default=NoConfigDefault, |
|
246 | 246 | help="Enable auto setting the terminal title.") |
|
247 | 247 | ), |
|
248 | 248 | (('-noterm_title',), dict( |
|
249 | 249 | action='store_false', dest='InteractiveShell.term_title', default=NoConfigDefault, |
|
250 | 250 | help="Disable auto setting the terminal title.") |
|
251 | 251 | ), |
|
252 | 252 | (('-xmode',), dict( |
|
253 | 253 | type=str, dest='InteractiveShell.xmode', default=NoConfigDefault, |
|
254 | 254 | help="Exception mode ('Plain','Context','Verbose')", |
|
255 | 255 | metavar='InteractiveShell.xmode') |
|
256 | 256 | ), |
|
257 | 257 | (('-ext',), dict( |
|
258 | 258 | type=str, dest='Global.extra_extension', default=NoConfigDefault, |
|
259 | 259 | help="The dotted module name of an IPython extension to load.", |
|
260 | 260 | metavar='Global.extra_extension') |
|
261 | 261 | ), |
|
262 | 262 | (('-c',), dict( |
|
263 | 263 | type=str, dest='Global.code_to_run', default=NoConfigDefault, |
|
264 | 264 | help="Execute the given command string.", |
|
265 | 265 | metavar='Global.code_to_run') |
|
266 | 266 | ), |
|
267 | 267 | (('-i',), dict( |
|
268 | 268 | action='store_true', dest='Global.force_interact', default=NoConfigDefault, |
|
269 | 269 | help="If running code from the command line, become interactive afterwards.") |
|
270 | 270 | ), |
|
271 | 271 | (('-wthread',), dict( |
|
272 | 272 | action='store_true', dest='Global.wthread', default=NoConfigDefault, |
|
273 | 273 | help="Enable wxPython event loop integration.") |
|
274 | 274 | ), |
|
275 | 275 | (('-q4thread','-qthread'), dict( |
|
276 | 276 | action='store_true', dest='Global.q4thread', default=NoConfigDefault, |
|
277 | 277 | help="Enable Qt4 event loop integration. Qt3 is no longer supported.") |
|
278 | 278 | ), |
|
279 | 279 | (('-gthread',), dict( |
|
280 | 280 | action='store_true', dest='Global.gthread', default=NoConfigDefault, |
|
281 | 281 | help="Enable GTK event loop integration.") |
|
282 | 282 | ), |
|
283 | 283 | # # These are only here to get the proper deprecation warnings |
|
284 | 284 | (('-pylab',), dict( |
|
285 | 285 | action='store_true', dest='Global.pylab', default=NoConfigDefault, |
|
286 | 286 | help="Disabled. Pylab has been disabled until matplotlib supports this version of IPython.") |
|
287 | 287 | ) |
|
288 | 288 | ) |
|
289 | 289 | |
|
290 | 290 | |
|
291 | 291 | class IPythonAppCLConfigLoader(IPythonArgParseConfigLoader): |
|
292 | 292 | |
|
293 | 293 | arguments = cl_args |
|
294 | 294 | |
|
295 | 295 | |
|
296 | 296 | _default_config_file_name = 'ipython_config.py' |
|
297 | 297 | |
|
298 | 298 | class IPythonApp(Application): |
|
299 | 299 | name = 'ipython' |
|
300 | 300 | config_file_name = _default_config_file_name |
|
301 | 301 | |
|
302 | 302 | def create_default_config(self): |
|
303 | 303 | super(IPythonApp, self).create_default_config() |
|
304 | 304 | self.default_config.Global.display_banner = True |
|
305 | 305 | |
|
306 | 306 | # If the -c flag is given or a file is given to run at the cmd line |
|
307 | 307 | # like "ipython foo.py", normally we exit without starting the main |
|
308 | 308 | # loop. The force_interact config variable allows a user to override |
|
309 | 309 | # this and interact. It is also set by the -i cmd line flag, just |
|
310 | 310 | # like Python. |
|
311 | 311 | self.default_config.Global.force_interact = False |
|
312 | 312 | |
|
313 | 313 | # By default always interact by starting the IPython mainloop. |
|
314 | 314 | self.default_config.Global.interact = True |
|
315 | 315 | |
|
316 | 316 | # Let the parent class set the default, but each time log_level |
|
317 | 317 | # changes from config, we need to update self.log_level as that is |
|
318 | 318 | # what updates the actual log level in self.log. |
|
319 | 319 | self.default_config.Global.log_level = self.log_level |
|
320 | 320 | |
|
321 | 321 | # No GUI integration by default |
|
322 | 322 | self.default_config.Global.wthread = False |
|
323 | 323 | self.default_config.Global.q4thread = False |
|
324 | 324 | self.default_config.Global.gthread = False |
|
325 | 325 | |
|
326 | 326 | def create_command_line_config(self): |
|
327 | 327 | """Create and return a command line config loader.""" |
|
328 | 328 | return IPythonAppCLConfigLoader( |
|
329 | 329 | description=ipython_desc, |
|
330 | 330 | version=release.version) |
|
331 | 331 | |
|
332 | 332 | def post_load_command_line_config(self): |
|
333 | 333 | """Do actions after loading cl config.""" |
|
334 | 334 | clc = self.command_line_config |
|
335 | 335 | |
|
336 | 336 | # Display the deprecation warnings about threaded shells |
|
337 | 337 | if hasattr(clc.Global, 'pylab'): |
|
338 | 338 | pylab_warning() |
|
339 | 339 | del clc.Global['pylab'] |
|
340 | 340 | |
|
341 | 341 | def load_file_config(self): |
|
342 | 342 | if hasattr(self.command_line_config.Global, 'quick'): |
|
343 | 343 | if self.command_line_config.Global.quick: |
|
344 | 344 | self.file_config = Config() |
|
345 | 345 | return |
|
346 | 346 | super(IPythonApp, self).load_file_config() |
|
347 | 347 | |
|
348 | 348 | def post_load_file_config(self): |
|
349 | 349 | if hasattr(self.command_line_config.Global, 'extra_extension'): |
|
350 | 350 | if not hasattr(self.file_config.Global, 'extensions'): |
|
351 | 351 | self.file_config.Global.extensions = [] |
|
352 | 352 | self.file_config.Global.extensions.append( |
|
353 | 353 | self.command_line_config.Global.extra_extension) |
|
354 | 354 | del self.command_line_config.Global.extra_extension |
|
355 | 355 | |
|
356 | 356 | def pre_construct(self): |
|
357 | 357 | config = self.master_config |
|
358 | 358 | |
|
359 | 359 | if hasattr(config.Global, 'classic'): |
|
360 | 360 | if config.Global.classic: |
|
361 | 361 | config.InteractiveShell.cache_size = 0 |
|
362 | 362 | config.InteractiveShell.pprint = 0 |
|
363 | 363 | config.InteractiveShell.prompt_in1 = '>>> ' |
|
364 | 364 | config.InteractiveShell.prompt_in2 = '... ' |
|
365 | 365 | config.InteractiveShell.prompt_out = '' |
|
366 | 366 | config.InteractiveShell.separate_in = \ |
|
367 | 367 | config.InteractiveShell.separate_out = \ |
|
368 | 368 | config.InteractiveShell.separate_out2 = '' |
|
369 | 369 | config.InteractiveShell.colors = 'NoColor' |
|
370 | 370 | config.InteractiveShell.xmode = 'Plain' |
|
371 | 371 | |
|
372 | 372 | if hasattr(config.Global, 'nosep'): |
|
373 | 373 | if config.Global.nosep: |
|
374 | 374 | config.InteractiveShell.separate_in = \ |
|
375 | 375 | config.InteractiveShell.separate_out = \ |
|
376 | 376 | config.InteractiveShell.separate_out2 = '' |
|
377 | 377 | |
|
378 | 378 | # if there is code of files to run from the cmd line, don't interact |
|
379 | 379 | # unless the -i flag (Global.force_interact) is true. |
|
380 | 380 | code_to_run = config.Global.get('code_to_run','') |
|
381 | 381 | file_to_run = False |
|
382 | 382 | if len(self.extra_args)>=1: |
|
383 | 383 | if self.extra_args[0]: |
|
384 | 384 | file_to_run = True |
|
385 | 385 | if file_to_run or code_to_run: |
|
386 | 386 | if not config.Global.force_interact: |
|
387 | 387 | config.Global.interact = False |
|
388 | 388 | |
|
389 | 389 | def construct(self): |
|
390 | 390 | # I am a little hesitant to put these into InteractiveShell itself. |
|
391 | 391 | # But that might be the place for them |
|
392 | 392 | sys.path.insert(0, '') |
|
393 | 393 | |
|
394 | 394 | # Create an InteractiveShell instance |
|
395 | 395 | self.shell = InteractiveShell( |
|
396 | 396 | parent=None, |
|
397 | 397 | config=self.master_config |
|
398 | 398 | ) |
|
399 | 399 | |
|
400 | 400 | def post_construct(self): |
|
401 | 401 | """Do actions after construct, but before starting the app.""" |
|
402 | 402 | config = self.master_config |
|
403 | 403 | |
|
404 | 404 | # shell.display_banner should always be False for the terminal |
|
405 | 405 | # based app, because we call shell.show_banner() by hand below |
|
406 | 406 | # so the banner shows *before* all extension loading stuff. |
|
407 | 407 | self.shell.display_banner = False |
|
408 | 408 | |
|
409 | 409 | if config.Global.display_banner and \ |
|
410 | 410 | config.Global.interact: |
|
411 | 411 | self.shell.show_banner() |
|
412 | 412 | |
|
413 | 413 | # Make sure there is a space below the banner. |
|
414 | 414 | if self.log_level <= logging.INFO: print |
|
415 | 415 | |
|
416 | 416 | self._enable_gui() |
|
417 | 417 | self._load_extensions() |
|
418 | 418 | self._run_exec_lines() |
|
419 | 419 | self._run_exec_files() |
|
420 | 420 | self._run_cmd_line_code() |
|
421 | 421 | |
|
422 | 422 | def _enable_gui(self): |
|
423 | 423 | """Enable GUI event loop integration.""" |
|
424 | 424 | config = self.master_config |
|
425 | 425 | try: |
|
426 | 426 | # Enable GUI integration |
|
427 | 427 | if config.Global.wthread: |
|
428 | 428 | self.log.info("Enabling wx GUI event loop integration") |
|
429 | 429 | inputhook.enable_wx(app=True) |
|
430 | 430 | elif config.Global.q4thread: |
|
431 | 431 | self.log.info("Enabling Qt4 GUI event loop integration") |
|
432 | 432 | inputhook.enable_qt4(app=True) |
|
433 | 433 | elif config.Global.gthread: |
|
434 | 434 | self.log.info("Enabling GTK GUI event loop integration") |
|
435 | 435 | inputhook.enable_gtk(app=True) |
|
436 | 436 | except: |
|
437 | 437 | self.log.warn("Error in enabling GUI event loop integration:") |
|
438 | 438 | self.shell.showtraceback() |
|
439 | 439 | |
|
440 | 440 | def _load_extensions(self): |
|
441 | 441 | """Load all IPython extensions in Global.extensions. |
|
442 | 442 | |
|
443 | 443 | This uses the :meth:`InteractiveShell.load_extensions` to load all |
|
444 | 444 | the extensions listed in ``self.master_config.Global.extensions``. |
|
445 | 445 | """ |
|
446 | 446 | try: |
|
447 | 447 | if hasattr(self.master_config.Global, 'extensions'): |
|
448 | 448 | self.log.debug("Loading IPython extensions...") |
|
449 | 449 | extensions = self.master_config.Global.extensions |
|
450 | 450 | for ext in extensions: |
|
451 | 451 | try: |
|
452 | 452 | self.log.info("Loading IPython extension: %s" % ext) |
|
453 | 453 | self.shell.load_extension(ext) |
|
454 | 454 | except: |
|
455 | 455 | self.log.warn("Error in loading extension: %s" % ext) |
|
456 | 456 | self.shell.showtraceback() |
|
457 | 457 | except: |
|
458 | 458 | self.log.warn("Unknown error in loading extensions:") |
|
459 | 459 | self.shell.showtraceback() |
|
460 | 460 | |
|
461 | 461 | def _run_exec_lines(self): |
|
462 | 462 | """Run lines of code in Global.exec_lines in the user's namespace.""" |
|
463 | 463 | try: |
|
464 | 464 | if hasattr(self.master_config.Global, 'exec_lines'): |
|
465 | 465 | self.log.debug("Running code from Global.exec_lines...") |
|
466 | 466 | exec_lines = self.master_config.Global.exec_lines |
|
467 | 467 | for line in exec_lines: |
|
468 | 468 | try: |
|
469 | 469 | self.log.info("Running code in user namespace: %s" % line) |
|
470 | 470 | self.shell.runlines(line) |
|
471 | 471 | except: |
|
472 | 472 | self.log.warn("Error in executing line in user namespace: %s" % line) |
|
473 | 473 | self.shell.showtraceback() |
|
474 | 474 | except: |
|
475 | 475 | self.log.warn("Unknown error in handling Global.exec_lines:") |
|
476 | 476 | self.shell.showtraceback() |
|
477 | 477 | |
|
478 | 478 | def _exec_file(self, fname): |
|
479 | 479 | full_filename = filefind(fname, ['.', self.ipythondir]) |
|
480 | 480 | if os.path.isfile(full_filename): |
|
481 | 481 | if full_filename.endswith('.py'): |
|
482 | 482 | self.log.info("Running file in user namespace: %s" % full_filename) |
|
483 | 483 | self.shell.safe_execfile(full_filename, self.shell.user_ns) |
|
484 | 484 | elif full_filename.endswith('.ipy'): |
|
485 | 485 | self.log.info("Running file in user namespace: %s" % full_filename) |
|
486 | 486 | self.shell.safe_execfile_ipy(full_filename) |
|
487 | 487 | else: |
|
488 | 488 | self.log.warn("File does not have a .py or .ipy extension: <%s>" % full_filename) |
|
489 | 489 | |
|
490 | 490 | def _run_exec_files(self): |
|
491 | 491 | try: |
|
492 | 492 | if hasattr(self.master_config.Global, 'exec_files'): |
|
493 | 493 | self.log.debug("Running files in Global.exec_files...") |
|
494 | 494 | exec_files = self.master_config.Global.exec_files |
|
495 | 495 | for fname in exec_files: |
|
496 | 496 | self._exec_file(fname) |
|
497 | 497 | except: |
|
498 | 498 | self.log.warn("Unknown error in handling Global.exec_files:") |
|
499 | 499 | self.shell.showtraceback() |
|
500 | 500 | |
|
501 | 501 | def _run_cmd_line_code(self): |
|
502 | 502 | if hasattr(self.master_config.Global, 'code_to_run'): |
|
503 | 503 | line = self.master_config.Global.code_to_run |
|
504 | 504 | try: |
|
505 | 505 | self.log.info("Running code given at command line (-c): %s" % line) |
|
506 | 506 | self.shell.runlines(line) |
|
507 | 507 | except: |
|
508 | 508 | self.log.warn("Error in executing line in user namespace: %s" % line) |
|
509 | 509 | self.shell.showtraceback() |
|
510 | 510 | return |
|
511 | 511 | # Like Python itself, ignore the second if the first of these is present |
|
512 | 512 | try: |
|
513 | 513 | fname = self.extra_args[0] |
|
514 | 514 | except: |
|
515 | 515 | pass |
|
516 | 516 | else: |
|
517 | 517 | try: |
|
518 | 518 | self._exec_file(fname) |
|
519 | 519 | except: |
|
520 | 520 | self.log.warn("Error in executing file in user namespace: %s" % fname) |
|
521 | 521 | self.shell.showtraceback() |
|
522 | 522 | |
|
523 | 523 | def start_app(self): |
|
524 | 524 | if self.master_config.Global.interact: |
|
525 | 525 | self.log.debug("Starting IPython's mainloop...") |
|
526 | 526 | self.shell.mainloop() |
|
527 | 527 | |
|
528 | 528 | |
|
529 | 529 | def load_default_config(ipythondir=None): |
|
530 | 530 | """Load the default config file from the default ipythondir. |
|
531 | 531 | |
|
532 | 532 | This is useful for embedded shells. |
|
533 | 533 | """ |
|
534 | 534 | if ipythondir is None: |
|
535 | 535 | ipythondir = get_ipython_dir() |
|
536 | 536 | cl = PyFileConfigLoader(_default_config_file_name, ipythondir) |
|
537 | 537 | config = cl.load_config() |
|
538 | 538 | return config |
|
539 | 539 | |
|
540 | 540 | |
|
541 | if __name__ == '__main__': | |
|
541 | def launch_new_instance(): | |
|
542 | """Create a run a full blown IPython instance""" | |
|
542 | 543 | app = IPythonApp() |
|
543 | app.start() No newline at end of file | |
|
544 | app.start() | |
|
545 |
@@ -1,28 +1,6 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | # -*- coding: utf-8 -*- |
|
3 | """IPython -- An enhanced Interactive Python | |
|
4 | 3 | |
|
5 | This is just the startup wrapper script, kept deliberately to a minimum. | |
|
6 | ||
|
7 | The shell's mainloop() takes an optional argument, sys_exit (default=0). If | |
|
8 | set to 1, it calls sys.exit() at exit time. You can use the following code in | |
|
9 | your PYTHONSTARTUP file: | |
|
10 | ||
|
11 | import IPython | |
|
12 | IPython.Shell.IPShell().mainloop(sys_exit=1) | |
|
13 | ||
|
14 | [or simply IPython.Shell.IPShell().mainloop(1) ] | |
|
15 | ||
|
16 | and IPython will be your working environment when you start python. The final | |
|
17 | sys.exit() call will make python exit transparently when IPython finishes, so | |
|
18 | you don't have an extra prompt to get out of. | |
|
19 | ||
|
20 | This is probably useful to developers who manage multiple Python versions and | |
|
21 | don't want to have correspondingly multiple IPython versions. Note that in | |
|
22 | this mode, there is no way to pass IPython any command-line options, as those | |
|
23 | are trapped first by Python itself. | |
|
24 | """ | |
|
25 | ||
|
26 | from IPython.core.ipapi import launch_new_instance | |
|
4 | from IPython.core.ipapp import launch_new_instance | |
|
27 | 5 | |
|
28 | 6 | launch_new_instance() |
@@ -1,37 +1,36 b'' | |||
|
1 | 1 | include ipython.py |
|
2 | 2 | include setupbase.py |
|
3 | 3 | include setupegg.py |
|
4 | 4 | |
|
5 | 5 | graft setupext |
|
6 | 6 | |
|
7 | 7 | graft scripts |
|
8 | 8 | graft IPython/kernel |
|
9 | 9 | graft IPython/config |
|
10 | 10 | graft IPython/core |
|
11 | 11 | graft IPython/deathrow |
|
12 | 12 | graft IPython/external |
|
13 | 13 | graft IPython/frontend |
|
14 | 14 | graft IPython/gui |
|
15 | 15 | graft IPython/lib |
|
16 | 16 | graft IPython/quarantine |
|
17 | 17 | graft IPython/scripts |
|
18 | 18 | graft IPython/testing |
|
19 | 19 | graft IPython/utils |
|
20 | 20 | |
|
21 | recursive-include IPython/extensions igrid_help* | |
|
22 | 21 | |
|
23 | 22 | graft docs |
|
24 | 23 | exclude docs/\#* |
|
25 | 24 | exclude docs/man/*.1 |
|
26 | 25 | |
|
27 | 26 | # docs subdirs we want to skip |
|
28 | 27 | prune docs/attic |
|
29 | 28 | prune docs/build |
|
30 | 29 | |
|
31 | 30 | global-exclude *~ |
|
32 | 31 | global-exclude *.flc |
|
33 | 32 | global-exclude *.pyc |
|
34 | 33 | global-exclude .dircopy.log |
|
35 | 34 | global-exclude .svn |
|
36 | 35 | global-exclude .bzr |
|
37 | 36 | global-exclude .hgignore |
@@ -1,214 +1,210 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | # -*- coding: utf-8 -*- |
|
3 | 3 | """Setup script for IPython. |
|
4 | 4 | |
|
5 | 5 | Under Posix environments it works like a typical setup.py script. |
|
6 | 6 | Under Windows, the command sdist is not supported, since IPython |
|
7 | 7 | requires utilities which are not available under Windows.""" |
|
8 | 8 | |
|
9 | 9 | #------------------------------------------------------------------------------- |
|
10 | 10 | # Copyright (C) 2008 The IPython Development Team |
|
11 | 11 | # |
|
12 | 12 | # Distributed under the terms of the BSD License. The full license is in |
|
13 | 13 | # the file COPYING, distributed as part of this software. |
|
14 | 14 | #------------------------------------------------------------------------------- |
|
15 | 15 | |
|
16 | 16 | #------------------------------------------------------------------------------- |
|
17 | 17 | # Imports |
|
18 | 18 | #------------------------------------------------------------------------------- |
|
19 | 19 | |
|
20 | 20 | # Stdlib imports |
|
21 | 21 | import os |
|
22 | 22 | import sys |
|
23 | 23 | |
|
24 | 24 | from glob import glob |
|
25 | 25 | |
|
26 | 26 | # BEFORE importing distutils, remove MANIFEST. distutils doesn't properly |
|
27 | 27 | # update it when the contents of directories change. |
|
28 | 28 | if os.path.exists('MANIFEST'): os.remove('MANIFEST') |
|
29 | 29 | |
|
30 | 30 | from distutils.core import setup |
|
31 | 31 | |
|
32 | 32 | from IPython.utils.genutils import target_update |
|
33 | 33 | |
|
34 | 34 | from setupbase import ( |
|
35 | 35 | setup_args, |
|
36 | 36 | find_packages, |
|
37 | 37 | find_package_data, |
|
38 | 38 | find_scripts, |
|
39 | 39 | find_data_files, |
|
40 | 40 | check_for_dependencies |
|
41 | 41 | ) |
|
42 | 42 | |
|
43 | 43 | isfile = os.path.isfile |
|
44 | 44 | pjoin = os.path.join |
|
45 | 45 | |
|
46 | 46 | #------------------------------------------------------------------------------- |
|
47 | 47 | # Handle OS specific things |
|
48 | 48 | #------------------------------------------------------------------------------- |
|
49 | 49 | |
|
50 | 50 | if os.name == 'posix': |
|
51 | 51 | os_name = 'posix' |
|
52 | 52 | elif os.name in ['nt','dos']: |
|
53 | 53 | os_name = 'windows' |
|
54 | 54 | else: |
|
55 | 55 | print 'Unsupported operating system:',os.name |
|
56 | 56 | sys.exit(1) |
|
57 | 57 | |
|
58 | 58 | # Under Windows, 'sdist' has not been supported. Now that the docs build with |
|
59 | 59 | # Sphinx it might work, but let's not turn it on until someone confirms that it |
|
60 | 60 | # actually works. |
|
61 | 61 | if os_name == 'windows' and 'sdist' in sys.argv: |
|
62 | 62 | print 'The sdist command is not available under Windows. Exiting.' |
|
63 | 63 | sys.exit(1) |
|
64 | 64 | |
|
65 | 65 | #------------------------------------------------------------------------------- |
|
66 | 66 | # Things related to the IPython documentation |
|
67 | 67 | #------------------------------------------------------------------------------- |
|
68 | 68 | |
|
69 | 69 | # update the manuals when building a source dist |
|
70 | 70 | if len(sys.argv) >= 2 and sys.argv[1] in ('sdist','bdist_rpm'): |
|
71 | 71 | import textwrap |
|
72 | 72 | |
|
73 | 73 | # List of things to be updated. Each entry is a triplet of args for |
|
74 | 74 | # target_update() |
|
75 | 75 | to_update = [ |
|
76 | 76 | # FIXME - Disabled for now: we need to redo an automatic way |
|
77 | 77 | # of generating the magic info inside the rst. |
|
78 | 78 | #('docs/magic.tex', |
|
79 | 79 | #['IPython/Magic.py'], |
|
80 | 80 | #"cd doc && ./update_magic.sh" ), |
|
81 | 81 | |
|
82 | 82 | ('docs/man/ipcluster.1.gz', |
|
83 | 83 | ['docs/man/ipcluster.1'], |
|
84 | 84 | 'cd docs/man && gzip -9c ipcluster.1 > ipcluster.1.gz'), |
|
85 | 85 | |
|
86 | 86 | ('docs/man/ipcontroller.1.gz', |
|
87 | 87 | ['docs/man/ipcontroller.1'], |
|
88 | 88 | 'cd docs/man && gzip -9c ipcontroller.1 > ipcontroller.1.gz'), |
|
89 | 89 | |
|
90 | 90 | ('docs/man/ipengine.1.gz', |
|
91 | 91 | ['docs/man/ipengine.1'], |
|
92 | 92 | 'cd docs/man && gzip -9c ipengine.1 > ipengine.1.gz'), |
|
93 | 93 | |
|
94 | 94 | ('docs/man/ipython.1.gz', |
|
95 | 95 | ['docs/man/ipython.1'], |
|
96 | 96 | 'cd docs/man && gzip -9c ipython.1 > ipython.1.gz'), |
|
97 | 97 | |
|
98 | 98 | ('docs/man/ipython-wx.1.gz', |
|
99 | 99 | ['docs/man/ipython-wx.1'], |
|
100 | 100 | 'cd docs/man && gzip -9c ipython-wx.1 > ipython-wx.1.gz'), |
|
101 | 101 | |
|
102 | 102 | ('docs/man/ipythonx.1.gz', |
|
103 | 103 | ['docs/man/ipythonx.1'], |
|
104 | 104 | 'cd docs/man && gzip -9c ipythonx.1 > ipythonx.1.gz'), |
|
105 | 105 | |
|
106 | 106 | ('docs/man/irunner.1.gz', |
|
107 | 107 | ['docs/man/irunner.1'], |
|
108 | 108 | 'cd docs/man && gzip -9c irunner.1 > irunner.1.gz'), |
|
109 | 109 | |
|
110 | 110 | ('docs/man/pycolor.1.gz', |
|
111 | 111 | ['docs/man/pycolor.1'], |
|
112 | 112 | 'cd docs/man && gzip -9c pycolor.1 > pycolor.1.gz'), |
|
113 | 113 | ] |
|
114 | 114 | |
|
115 | 115 | # Only build the docs if sphinx is present |
|
116 | 116 | try: |
|
117 | 117 | import sphinx |
|
118 | 118 | except ImportError: |
|
119 | 119 | pass |
|
120 | 120 | else: |
|
121 | 121 | # The Makefile calls the do_sphinx scripts to build html and pdf, so |
|
122 | 122 | # just one target is enough to cover all manual generation |
|
123 | 123 | |
|
124 | 124 | # First, compute all the dependencies that can force us to rebuild the |
|
125 | 125 | # docs. Start with the main release file that contains metadata |
|
126 | 126 | docdeps = ['IPython/core/release.py'] |
|
127 | 127 | # Inculde all the reST sources |
|
128 | 128 | pjoin = os.path.join |
|
129 | 129 | for dirpath,dirnames,filenames in os.walk('docs/source'): |
|
130 | 130 | if dirpath in ['_static','_templates']: |
|
131 | 131 | continue |
|
132 | 132 | docdeps += [ pjoin(dirpath,f) for f in filenames |
|
133 | 133 | if f.endswith('.txt') ] |
|
134 | 134 | # and the examples |
|
135 | 135 | for dirpath,dirnames,filenames in os.walk('docs/example'): |
|
136 | 136 | docdeps += [ pjoin(dirpath,f) for f in filenames |
|
137 | 137 | if not f.endswith('~') ] |
|
138 | 138 | # then, make them all dependencies for the main PDF (the html will get |
|
139 | 139 | # auto-generated as well). |
|
140 | 140 | to_update.append( |
|
141 | 141 | ('docs/dist/ipython.pdf', |
|
142 | 142 | docdeps, |
|
143 | 143 | "cd docs && make dist") |
|
144 | 144 | ) |
|
145 | 145 | |
|
146 | 146 | [ target_update(*t) for t in to_update ] |
|
147 | 147 | |
|
148 | 148 | |
|
149 | 149 | #--------------------------------------------------------------------------- |
|
150 | 150 | # Find all the packages, package data, scripts and data_files |
|
151 | 151 | #--------------------------------------------------------------------------- |
|
152 | 152 | |
|
153 | 153 | packages = find_packages() |
|
154 | 154 | package_data = find_package_data() |
|
155 | 155 | scripts = find_scripts() |
|
156 | 156 | data_files = find_data_files() |
|
157 | 157 | |
|
158 | 158 | #--------------------------------------------------------------------------- |
|
159 | 159 | # Handle dependencies and setuptools specific things |
|
160 | 160 | #--------------------------------------------------------------------------- |
|
161 | 161 | |
|
162 | 162 | # This dict is used for passing extra arguments that are setuptools |
|
163 | 163 | # specific to setup |
|
164 | 164 | setuptools_extra_args = {} |
|
165 | 165 | |
|
166 | 166 | if 'setuptools' in sys.modules: |
|
167 | 167 | setuptools_extra_args['zip_safe'] = False |
|
168 | 168 | setuptools_extra_args['entry_points'] = { |
|
169 | 169 | 'console_scripts': [ |
|
170 |
'ipython = IPython.core.ipap |
|
|
170 | 'ipython = IPython.core.ipapp:launch_new_instance', | |
|
171 | 171 | 'pycolor = IPython.utils.PyColorize:main', |
|
172 | 172 | 'ipcontroller = IPython.kernel.scripts.ipcontroller:main', |
|
173 | 173 | 'ipengine = IPython.kernel.scripts.ipengine:main', |
|
174 | 174 | 'ipcluster = IPython.kernel.scripts.ipcluster:main', |
|
175 | 175 | 'ipythonx = IPython.frontend.wx.ipythonx:main', |
|
176 | 176 | 'iptest = IPython.testing.iptest:main', |
|
177 | 177 | 'irunner = IPython.lib.irunner:main' |
|
178 | 178 | ] |
|
179 | 179 | } |
|
180 | 180 | setup_args['extras_require'] = dict( |
|
181 | 181 | kernel = [ |
|
182 | 182 | 'zope.interface>=3.4.1', |
|
183 | 183 | 'Twisted>=8.0.1', |
|
184 | 184 | 'foolscap>=0.2.6' |
|
185 | 185 | ], |
|
186 | 186 | doc='Sphinx>=0.3', |
|
187 | 187 | test='nose>=0.10.1', |
|
188 | 188 | security='pyOpenSSL>=0.6' |
|
189 | 189 | ) |
|
190 | 190 | # Allow setuptools to handle the scripts |
|
191 | 191 | scripts = [] |
|
192 | 192 | else: |
|
193 | # package_data of setuptools was introduced to distutils in 2.4 | |
|
194 | cfgfiles = filter(isfile, glob(pjoin('IPython','config','userconfig'))) | |
|
195 | if sys.version_info < (2,4): | |
|
196 | data_files.append(('lib', pjoin('IPython','config','userconfig'), cfgfiles)) | |
|
197 | 193 | # If we are running without setuptools, call this function which will |
|
198 | 194 | # check for dependencies an inform the user what is needed. This is |
|
199 | 195 | # just to make life easy for users. |
|
200 | 196 | check_for_dependencies() |
|
201 | 197 | |
|
202 | 198 | |
|
203 | 199 | #--------------------------------------------------------------------------- |
|
204 | 200 | # Do the actual setup now |
|
205 | 201 | #--------------------------------------------------------------------------- |
|
206 | 202 | |
|
207 | 203 | setup_args['packages'] = packages |
|
208 | 204 | setup_args['package_data'] = package_data |
|
209 | 205 | setup_args['scripts'] = scripts |
|
210 | 206 | setup_args['data_files'] = data_files |
|
211 | 207 | setup_args.update(setuptools_extra_args) |
|
212 | 208 | |
|
213 | 209 | if __name__ == '__main__': |
|
214 | 210 | setup(**setup_args) |
@@ -1,320 +1,320 b'' | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | |
|
3 | 3 | """ |
|
4 | 4 | This module defines the things that are used in setup.py for building IPython |
|
5 | 5 | |
|
6 | 6 | This includes: |
|
7 | 7 | |
|
8 | 8 | * The basic arguments to setup |
|
9 | 9 | * Functions for finding things like packages, package data, etc. |
|
10 | 10 | * A function for checking dependencies. |
|
11 | 11 | """ |
|
12 | 12 | |
|
13 | 13 | __docformat__ = "restructuredtext en" |
|
14 | 14 | |
|
15 | 15 | #------------------------------------------------------------------------------- |
|
16 | 16 | # Copyright (C) 2008 The IPython Development Team |
|
17 | 17 | # |
|
18 | 18 | # Distributed under the terms of the BSD License. The full license is in |
|
19 | 19 | # the file COPYING, distributed as part of this software. |
|
20 | 20 | #------------------------------------------------------------------------------- |
|
21 | 21 | |
|
22 | 22 | #------------------------------------------------------------------------------- |
|
23 | 23 | # Imports |
|
24 | 24 | #------------------------------------------------------------------------------- |
|
25 | 25 | |
|
26 | 26 | import os, sys |
|
27 | 27 | |
|
28 | 28 | from glob import glob |
|
29 | 29 | |
|
30 | 30 | from setupext import install_data_ext |
|
31 | 31 | |
|
32 | 32 | #------------------------------------------------------------------------------- |
|
33 | 33 | # Useful globals and utility functions |
|
34 | 34 | #------------------------------------------------------------------------------- |
|
35 | 35 | |
|
36 | 36 | # A few handy globals |
|
37 | 37 | isfile = os.path.isfile |
|
38 | 38 | pjoin = os.path.join |
|
39 | 39 | |
|
40 | 40 | def oscmd(s): |
|
41 | 41 | print ">", s |
|
42 | 42 | os.system(s) |
|
43 | 43 | |
|
44 | 44 | # A little utility we'll need below, since glob() does NOT allow you to do |
|
45 | 45 | # exclusion on multiple endings! |
|
46 | 46 | def file_doesnt_endwith(test,endings): |
|
47 | 47 | """Return true if test is a file and its name does NOT end with any |
|
48 | 48 | of the strings listed in endings.""" |
|
49 | 49 | if not isfile(test): |
|
50 | 50 | return False |
|
51 | 51 | for e in endings: |
|
52 | 52 | if test.endswith(e): |
|
53 | 53 | return False |
|
54 | 54 | return True |
|
55 | 55 | |
|
56 | 56 | #--------------------------------------------------------------------------- |
|
57 | 57 | # Basic project information |
|
58 | 58 | #--------------------------------------------------------------------------- |
|
59 | 59 | |
|
60 | 60 | # release.py contains version, authors, license, url, keywords, etc. |
|
61 | 61 | execfile(pjoin('IPython','core','release.py')) |
|
62 | 62 | |
|
63 | 63 | # Create a dict with the basic information |
|
64 | 64 | # This dict is eventually passed to setup after additional keys are added. |
|
65 | 65 | setup_args = dict( |
|
66 | 66 | name = name, |
|
67 | 67 | version = version, |
|
68 | 68 | description = description, |
|
69 | 69 | long_description = long_description, |
|
70 | 70 | author = author, |
|
71 | 71 | author_email = author_email, |
|
72 | 72 | url = url, |
|
73 | 73 | download_url = download_url, |
|
74 | 74 | license = license, |
|
75 | 75 | platforms = platforms, |
|
76 | 76 | keywords = keywords, |
|
77 | 77 | cmdclass = {'install_data': install_data_ext}, |
|
78 | 78 | ) |
|
79 | 79 | |
|
80 | 80 | |
|
81 | 81 | #--------------------------------------------------------------------------- |
|
82 | 82 | # Find packages |
|
83 | 83 | #--------------------------------------------------------------------------- |
|
84 | 84 | |
|
85 | 85 | def add_package(packages,pname,config=False,tests=False,scripts=False, |
|
86 | 86 | others=None): |
|
87 | 87 | """ |
|
88 | 88 | Add a package to the list of packages, including certain subpackages. |
|
89 | 89 | """ |
|
90 | 90 | packages.append('.'.join(['IPython',pname])) |
|
91 | 91 | if config: |
|
92 | 92 | packages.append('.'.join(['IPython',pname,'config'])) |
|
93 | 93 | if tests: |
|
94 | 94 | packages.append('.'.join(['IPython',pname,'tests'])) |
|
95 | 95 | if scripts: |
|
96 | 96 | packages.append('.'.join(['IPython',pname,'scripts'])) |
|
97 | 97 | if others is not None: |
|
98 | 98 | for o in others: |
|
99 | 99 | packages.append('.'.join(['IPython',pname,o])) |
|
100 | 100 | |
|
101 | 101 | def find_packages(): |
|
102 | 102 | """ |
|
103 | 103 | Find all of IPython's packages. |
|
104 | 104 | """ |
|
105 | 105 | packages = ['IPython'] |
|
106 | add_package(packages, 'config', tests=True) | |
|
106 | add_package(packages, 'config', tests=True, others=['default','profile']) | |
|
107 | 107 | add_package(packages, 'core', tests=True) |
|
108 | 108 | add_package(packages, 'deathrow', tests=True) |
|
109 | 109 | add_package(packages , 'extensions') |
|
110 | 110 | add_package(packages, 'external') |
|
111 | 111 | add_package(packages, 'frontend', tests=True) |
|
112 | 112 | # Don't include the cocoa frontend for now as it is not stable |
|
113 | 113 | if sys.platform == 'darwin' and False: |
|
114 | 114 | add_package(packages, 'frontend.cocoa', tests=True, others=['plugin']) |
|
115 | 115 | add_package(packages, 'frontend.cocoa.examples') |
|
116 | 116 | add_package(packages, 'frontend.cocoa.examples.IPython1Sandbox') |
|
117 | 117 | add_package(packages, 'frontend.cocoa.examples.IPython1Sandbox.English.lproj') |
|
118 | 118 | add_package(packages, 'frontend.process') |
|
119 | 119 | add_package(packages, 'frontend.wx') |
|
120 | 120 | add_package(packages, 'gui') |
|
121 | 121 | add_package(packages, 'gui.wx') |
|
122 | 122 | add_package(packages, 'kernel', config=True, tests=True, scripts=True) |
|
123 | 123 | add_package(packages, 'kernel.core', config=True, tests=True) |
|
124 | 124 | add_package(packages, 'lib', tests=True) |
|
125 | 125 | add_package(packages, 'quarantine', tests=True) |
|
126 | 126 | add_package(packages, 'scripts') |
|
127 | 127 | add_package(packages, 'testing', tests=True) |
|
128 | 128 | add_package(packages, 'testing.plugin', tests=False) |
|
129 | 129 | add_package(packages, 'utils', tests=True) |
|
130 | 130 | return packages |
|
131 | 131 | |
|
132 | 132 | #--------------------------------------------------------------------------- |
|
133 | 133 | # Find package data |
|
134 | 134 | #--------------------------------------------------------------------------- |
|
135 | 135 | |
|
136 | 136 | def find_package_data(): |
|
137 | 137 | """ |
|
138 | 138 | Find IPython's package_data. |
|
139 | 139 | """ |
|
140 | 140 | # This is not enough for these things to appear in an sdist. |
|
141 | 141 | # We need to muck with the MANIFEST to get this to work |
|
142 | 142 | package_data = { |
|
143 | 143 | 'IPython.config.userconfig' : ['*'], |
|
144 | 144 | 'IPython.testing' : ['*.txt'] |
|
145 | 145 | } |
|
146 | 146 | return package_data |
|
147 | 147 | |
|
148 | 148 | |
|
149 | 149 | #--------------------------------------------------------------------------- |
|
150 | 150 | # Find data files |
|
151 | 151 | #--------------------------------------------------------------------------- |
|
152 | 152 | |
|
153 | 153 | def make_dir_struct(tag,base,out_base): |
|
154 | 154 | """Make the directory structure of all files below a starting dir. |
|
155 | 155 | |
|
156 | 156 | This is just a convenience routine to help build a nested directory |
|
157 | 157 | hierarchy because distutils is too stupid to do this by itself. |
|
158 | 158 | |
|
159 | 159 | XXX - this needs a proper docstring! |
|
160 | 160 | """ |
|
161 | 161 | |
|
162 | 162 | # we'll use these a lot below |
|
163 | 163 | lbase = len(base) |
|
164 | 164 | pathsep = os.path.sep |
|
165 | 165 | lpathsep = len(pathsep) |
|
166 | 166 | |
|
167 | 167 | out = [] |
|
168 | 168 | for (dirpath,dirnames,filenames) in os.walk(base): |
|
169 | 169 | # we need to strip out the dirpath from the base to map it to the |
|
170 | 170 | # output (installation) path. This requires possibly stripping the |
|
171 | 171 | # path separator, because otherwise pjoin will not work correctly |
|
172 | 172 | # (pjoin('foo/','/bar') returns '/bar'). |
|
173 | 173 | |
|
174 | 174 | dp_eff = dirpath[lbase:] |
|
175 | 175 | if dp_eff.startswith(pathsep): |
|
176 | 176 | dp_eff = dp_eff[lpathsep:] |
|
177 | 177 | # The output path must be anchored at the out_base marker |
|
178 | 178 | out_path = pjoin(out_base,dp_eff) |
|
179 | 179 | # Now we can generate the final filenames. Since os.walk only produces |
|
180 | 180 | # filenames, we must join back with the dirpath to get full valid file |
|
181 | 181 | # paths: |
|
182 | 182 | pfiles = [pjoin(dirpath,f) for f in filenames] |
|
183 | 183 | # Finally, generate the entry we need, which is a triple of (tag,output |
|
184 | 184 | # path, files) for use as a data_files parameter in install_data. |
|
185 | 185 | out.append((tag,out_path,pfiles)) |
|
186 | 186 | |
|
187 | 187 | return out |
|
188 | 188 | |
|
189 | 189 | |
|
190 | 190 | def find_data_files(): |
|
191 | 191 | """ |
|
192 | 192 | Find IPython's data_files. |
|
193 | 193 | |
|
194 | 194 | Most of these are docs. |
|
195 | 195 | """ |
|
196 | 196 | |
|
197 | 197 | docdirbase = pjoin('share', 'doc', 'ipython') |
|
198 | 198 | manpagebase = pjoin('share', 'man', 'man1') |
|
199 | 199 | |
|
200 | 200 | # Simple file lists can be made by hand |
|
201 | 201 | manpages = filter(isfile, glob(pjoin('docs','man','*.1.gz'))) |
|
202 | 202 | igridhelpfiles = filter(isfile, glob(pjoin('IPython','extensions','igrid_help.*'))) |
|
203 | 203 | |
|
204 | 204 | # For nested structures, use the utility above |
|
205 | 205 | example_files = make_dir_struct( |
|
206 | 206 | 'data', |
|
207 | 207 | pjoin('docs','examples'), |
|
208 | 208 | pjoin(docdirbase,'examples') |
|
209 | 209 | ) |
|
210 | 210 | manual_files = make_dir_struct( |
|
211 | 211 | 'data', |
|
212 | 212 | pjoin('docs','dist'), |
|
213 | 213 | pjoin(docdirbase,'manual') |
|
214 | 214 | ) |
|
215 | 215 | |
|
216 | 216 | # And assemble the entire output list |
|
217 | 217 | data_files = [ ('data',manpagebase, manpages), |
|
218 | 218 | ('data',pjoin(docdirbase,'extensions'),igridhelpfiles), |
|
219 | 219 | ] + manual_files + example_files |
|
220 | 220 | |
|
221 | 221 | ## import pprint # dbg |
|
222 | 222 | ## print '*'*80 |
|
223 | 223 | ## print 'data files' |
|
224 | 224 | ## pprint.pprint(data_files) |
|
225 | 225 | ## print '*'*80 |
|
226 | 226 | |
|
227 | 227 | return data_files |
|
228 | 228 | |
|
229 | 229 | |
|
230 | 230 | def make_man_update_target(manpage): |
|
231 | 231 | """Return a target_update-compliant tuple for the given manpage. |
|
232 | 232 | |
|
233 | 233 | Parameters |
|
234 | 234 | ---------- |
|
235 | 235 | manpage : string |
|
236 | 236 | Name of the manpage, must include the section number (trailing number). |
|
237 | 237 | |
|
238 | 238 | Example |
|
239 | 239 | ------- |
|
240 | 240 | |
|
241 | 241 | >>> make_man_update_target('ipython.1') #doctest: +NORMALIZE_WHITESPACE |
|
242 | 242 | ('docs/man/ipython.1.gz', |
|
243 | 243 | ['docs/man/ipython.1'], |
|
244 | 244 | 'cd docs/man && gzip -9c ipython.1 > ipython.1.gz') |
|
245 | 245 | """ |
|
246 | 246 | man_dir = pjoin('docs', 'man') |
|
247 | 247 | manpage_gz = manpage + '.gz' |
|
248 | 248 | manpath = pjoin(man_dir, manpage) |
|
249 | 249 | manpath_gz = pjoin(man_dir, manpage_gz) |
|
250 | 250 | gz_cmd = ( "cd %(man_dir)s && gzip -9c %(manpage)s > %(manpage_gz)s" % |
|
251 | 251 | locals() ) |
|
252 | 252 | return (manpath_gz, [manpath], gz_cmd) |
|
253 | 253 | |
|
254 | 254 | #--------------------------------------------------------------------------- |
|
255 | 255 | # Find scripts |
|
256 | 256 | #--------------------------------------------------------------------------- |
|
257 | 257 | |
|
258 | 258 | def find_scripts(): |
|
259 | 259 | """ |
|
260 | 260 | Find IPython's scripts. |
|
261 | 261 | """ |
|
262 | 262 | kernel_scripts = pjoin('IPython','kernel','scripts') |
|
263 | 263 | main_scripts = pjoin('IPython','scripts') |
|
264 | 264 | scripts = [pjoin(kernel_scripts, 'ipengine'), |
|
265 | 265 | pjoin(kernel_scripts, 'ipcontroller'), |
|
266 | 266 | pjoin(kernel_scripts, 'ipcluster'), |
|
267 | 267 | pjoin(main_scripts, 'ipython'), |
|
268 | 268 | pjoin(main_scripts, 'ipythonx'), |
|
269 | 269 | pjoin(main_scripts, 'ipython-wx'), |
|
270 | 270 | pjoin(main_scripts, 'pycolor'), |
|
271 | 271 | pjoin(main_scripts, 'irunner'), |
|
272 | 272 | pjoin(main_scripts, 'iptest') |
|
273 | 273 | ] |
|
274 | 274 | |
|
275 | 275 | # Script to be run by the windows binary installer after the default setup |
|
276 | 276 | # routine, to add shortcuts and similar windows-only things. Windows |
|
277 | 277 | # post-install scripts MUST reside in the scripts/ dir, otherwise distutils |
|
278 | 278 | # doesn't find them. |
|
279 | 279 | if 'bdist_wininst' in sys.argv: |
|
280 | 280 | if len(sys.argv) > 2 and ('sdist' in sys.argv or 'bdist_rpm' in sys.argv): |
|
281 | 281 | print >> sys.stderr,"ERROR: bdist_wininst must be run alone. Exiting." |
|
282 | 282 | sys.exit(1) |
|
283 | 283 | scripts.append(pjoin('scripts','ipython_win_post_install.py')) |
|
284 | 284 | |
|
285 | 285 | return scripts |
|
286 | 286 | |
|
287 | 287 | #--------------------------------------------------------------------------- |
|
288 | 288 | # Verify all dependencies |
|
289 | 289 | #--------------------------------------------------------------------------- |
|
290 | 290 | |
|
291 | 291 | def check_for_dependencies(): |
|
292 | 292 | """Check for IPython's dependencies. |
|
293 | 293 | |
|
294 | 294 | This function should NOT be called if running under setuptools! |
|
295 | 295 | """ |
|
296 | 296 | from setupext.setupext import ( |
|
297 | 297 | print_line, print_raw, print_status, print_message, |
|
298 | 298 | check_for_zopeinterface, check_for_twisted, |
|
299 | 299 | check_for_foolscap, check_for_pyopenssl, |
|
300 | 300 | check_for_sphinx, check_for_pygments, |
|
301 | 301 | check_for_nose, check_for_pexpect |
|
302 | 302 | ) |
|
303 | 303 | print_line() |
|
304 | 304 | print_raw("BUILDING IPYTHON") |
|
305 | 305 | print_status('python', sys.version) |
|
306 | 306 | print_status('platform', sys.platform) |
|
307 | 307 | if sys.platform == 'win32': |
|
308 | 308 | print_status('Windows version', sys.getwindowsversion()) |
|
309 | 309 | |
|
310 | 310 | print_raw("") |
|
311 | 311 | print_raw("OPTIONAL DEPENDENCIES") |
|
312 | 312 | |
|
313 | 313 | check_for_zopeinterface() |
|
314 | 314 | check_for_twisted() |
|
315 | 315 | check_for_foolscap() |
|
316 | 316 | check_for_pyopenssl() |
|
317 | 317 | check_for_sphinx() |
|
318 | 318 | check_for_pygments() |
|
319 | 319 | check_for_nose() |
|
320 | 320 | check_for_pexpect() |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now