Show More
@@ -101,18 +101,15 class HistoryManager(Configurable): | |||
|
101 | 101 | |
|
102 | 102 | if self.hist_file == u'': |
|
103 | 103 | # No one has set the hist_file, yet. |
|
104 | if shell.profile: | |
|
105 | histfname = 'history-%s' % shell.profile | |
|
106 | else: | |
|
107 | histfname = 'history' | |
|
108 | self.hist_file = os.path.join(shell.ipython_dir, histfname + '.sqlite') | |
|
104 | histfname = 'history' | |
|
105 | self.hist_file = os.path.join(shell.profile_dir.location, histfname + '.sqlite') | |
|
109 | 106 | |
|
110 | 107 | try: |
|
111 | 108 | self.init_db() |
|
112 | 109 | except sqlite3.DatabaseError: |
|
113 | 110 | if os.path.isfile(self.hist_file): |
|
114 | 111 | # Try to move the file out of the way. |
|
115 |
newpath = os.path.join(self.shell. |
|
|
112 | newpath = os.path.join(self.shell.profile_dir.location, "hist-corrupt.sqlite") | |
|
116 | 113 | os.rename(self.hist_file, newpath) |
|
117 | 114 | print("ERROR! History file wasn't a valid SQLite database.", |
|
118 | 115 | "It was moved to %s" % newpath, "and a new file created.") |
@@ -54,6 +54,7 from IPython.core.inputsplitter import IPythonInputSplitter | |||
|
54 | 54 | from IPython.core.logger import Logger |
|
55 | 55 | from IPython.core.macro import Macro |
|
56 | 56 | from IPython.core.magic import Magic |
|
57 | from IPython.core.newapplication import ProfileDir | |
|
57 | 58 | from IPython.core.payload import PayloadManager |
|
58 | 59 | from IPython.core.plugin import PluginManager |
|
59 | 60 | from IPython.core.prefilter import PrefilterManager, ESC_MAGIC |
@@ -238,7 +239,9 class InteractiveShell(SingletonConfigurable, Magic): | |||
|
238 | 239 | """ |
|
239 | 240 | ) |
|
240 | 241 | colors = CaselessStrEnum(('NoColor','LightBG','Linux'), |
|
241 |
default_value=get_default_colors(), config=True |
|
|
242 | default_value=get_default_colors(), config=True, | |
|
243 | help="Set the color scheme (NoColor, Linux, and LightBG)." | |
|
244 | ) | |
|
242 | 245 | debug = CBool(False, config=True) |
|
243 | 246 | deep_reload = CBool(False, config=True, help= |
|
244 | 247 | """ |
@@ -291,7 +294,6 class InteractiveShell(SingletonConfigurable, Magic): | |||
|
291 | 294 | """ |
|
292 | 295 | ) |
|
293 | 296 | |
|
294 | profile = Unicode('', config=True) | |
|
295 | 297 | prompt_in1 = Str('In [\\#]: ', config=True) |
|
296 | 298 | prompt_in2 = Str(' .\\D.: ', config=True) |
|
297 | 299 | prompt_out = Str('Out[\\#]: ', config=True) |
@@ -342,10 +344,18 class InteractiveShell(SingletonConfigurable, Magic): | |||
|
342 | 344 | payload_manager = Instance('IPython.core.payload.PayloadManager') |
|
343 | 345 | history_manager = Instance('IPython.core.history.HistoryManager') |
|
344 | 346 | |
|
347 | profile_dir = Instance('IPython.core.newapplication.ProfileDir') | |
|
348 | @property | |
|
349 | def profile(self): | |
|
350 | if self.profile_dir is not None: | |
|
351 | name = os.path.basename(self.profile_dir.location) | |
|
352 | return name.replace('profile_','') | |
|
353 | ||
|
354 | ||
|
345 | 355 | # Private interface |
|
346 | 356 | _post_execute = Instance(dict) |
|
347 | 357 | |
|
348 | def __init__(self, config=None, ipython_dir=None, | |
|
358 | def __init__(self, config=None, ipython_dir=None, profile_dir=None, | |
|
349 | 359 | user_ns=None, user_global_ns=None, |
|
350 | 360 | custom_exceptions=((), None)): |
|
351 | 361 | |
@@ -355,6 +365,7 class InteractiveShell(SingletonConfigurable, Magic): | |||
|
355 | 365 | |
|
356 | 366 | # These are relatively independent and stateless |
|
357 | 367 | self.init_ipython_dir(ipython_dir) |
|
368 | self.init_profile_dir(profile_dir) | |
|
358 | 369 | self.init_instance_attrs() |
|
359 | 370 | self.init_environment() |
|
360 | 371 | |
@@ -372,7 +383,7 class InteractiveShell(SingletonConfigurable, Magic): | |||
|
372 | 383 | # While we're trying to have each part of the code directly access what |
|
373 | 384 | # it needs without keeping redundant references to objects, we have too |
|
374 | 385 | # much legacy code that expects ip.db to exist. |
|
375 |
self.db = PickleShareDB(os.path.join(self. |
|
|
386 | self.db = PickleShareDB(os.path.join(self.profile_dir.location, 'db')) | |
|
376 | 387 | |
|
377 | 388 | self.init_history() |
|
378 | 389 | self.init_encoding() |
@@ -457,16 +468,16 class InteractiveShell(SingletonConfigurable, Magic): | |||
|
457 | 468 | def init_ipython_dir(self, ipython_dir): |
|
458 | 469 | if ipython_dir is not None: |
|
459 | 470 | self.ipython_dir = ipython_dir |
|
460 | self.config.Global.ipython_dir = self.ipython_dir | |
|
461 | 471 | return |
|
462 | 472 | |
|
463 | if hasattr(self.config.Global, 'ipython_dir'): | |
|
464 | self.ipython_dir = self.config.Global.ipython_dir | |
|
465 | else: | |
|
466 | self.ipython_dir = get_ipython_dir() | |
|
473 | self.ipython_dir = get_ipython_dir() | |
|
467 | 474 | |
|
468 | # All children can just read this | |
|
469 | self.config.Global.ipython_dir = self.ipython_dir | |
|
475 | def init_profile_dir(self, profile_dir): | |
|
476 | if profile_dir is not None: | |
|
477 | self.profile_dir = profile_dir | |
|
478 | return | |
|
479 | self.profile_dir =\ | |
|
480 | ProfileDir.create_profile_dir_by_name(self.ipython_dir, 'default') | |
|
470 | 481 | |
|
471 | 482 | def init_instance_attrs(self): |
|
472 | 483 | self.more = False |
@@ -46,6 +46,7 from IPython.core import debugger, oinspect | |||
|
46 | 46 | from IPython.core.error import TryNext |
|
47 | 47 | from IPython.core.error import UsageError |
|
48 | 48 | from IPython.core.fakemodule import FakeModule |
|
49 | from IPython.core.newapplication import ProfileDir | |
|
49 | 50 | from IPython.core.macro import Macro |
|
50 | 51 | from IPython.core import page |
|
51 | 52 | from IPython.core.prefilter import ESC_MAGIC |
@@ -533,10 +534,7 Currently the magic system has the following functions:\n""" | |||
|
533 | 534 | |
|
534 | 535 | def magic_profile(self, parameter_s=''): |
|
535 | 536 | """Print your currently active IPython profile.""" |
|
536 |
|
|
|
537 | printpl('Current IPython profile: $self.shell.profile.') | |
|
538 | else: | |
|
539 | print 'No profile active.' | |
|
537 | print self.shell.profile | |
|
540 | 538 | |
|
541 | 539 | def magic_pinfo(self, parameter_s='', namespaces=None): |
|
542 | 540 | """Provide detailed information about an object. |
@@ -3373,22 +3371,16 Defaulting color scheme to 'NoColor'""" | |||
|
3373 | 3371 | else: |
|
3374 | 3372 | overwrite = False |
|
3375 | 3373 | from IPython.config import profile |
|
3376 |
profile_dir = os.path. |
|
|
3374 | profile_dir = os.path.dirname(profile.__file__) | |
|
3377 | 3375 | ipython_dir = self.ipython_dir |
|
3378 | files = os.listdir(profile_dir) | |
|
3379 | ||
|
3380 | to_install = [] | |
|
3381 | for f in files: | |
|
3382 | if f.startswith('ipython_config'): | |
|
3383 | src = os.path.join(profile_dir, f) | |
|
3384 | dst = os.path.join(ipython_dir, f) | |
|
3385 | if (not os.path.isfile(dst)) or overwrite: | |
|
3386 | to_install.append((f, src, dst)) | |
|
3387 | if len(to_install)>0: | |
|
3388 | print "Installing profiles to: ", ipython_dir | |
|
3389 | for (f, src, dst) in to_install: | |
|
3390 | shutil.copy(src, dst) | |
|
3391 | print " %s" % f | |
|
3376 | print "Installing profiles to: %s [overwrite=%s]"(ipython_dir,overwrite) | |
|
3377 | for src in os.listdir(profile_dir): | |
|
3378 | if src.startswith('profile_'): | |
|
3379 | name = src.replace('profile_', '') | |
|
3380 | print " %s"%name | |
|
3381 | pd = ProfileDir.create_profile_dir_by_name(ipython_dir, name) | |
|
3382 | pd.copy_config_file('ipython_config.py', path=src, | |
|
3383 | overwrite=overwrite) | |
|
3392 | 3384 | |
|
3393 | 3385 | @skip_doctest |
|
3394 | 3386 | def magic_install_default_config(self, s): |
@@ -3404,15 +3396,9 Defaulting color scheme to 'NoColor'""" | |||
|
3404 | 3396 | overwrite = True |
|
3405 | 3397 | else: |
|
3406 | 3398 | overwrite = False |
|
3407 | from IPython.config import default | |
|
3408 | config_dir = os.path.split(default.__file__)[0] | |
|
3409 | ipython_dir = self.ipython_dir | |
|
3410 | default_config_file_name = 'ipython_config.py' | |
|
3411 | src = os.path.join(config_dir, default_config_file_name) | |
|
3412 | dst = os.path.join(ipython_dir, default_config_file_name) | |
|
3413 | if (not os.path.isfile(dst)) or overwrite: | |
|
3414 | shutil.copy(src, dst) | |
|
3415 | print "Installing default config file: %s" % dst | |
|
3399 | pd = self.shell.profile_dir | |
|
3400 | print "Installing default config file in: %s" % pd.location | |
|
3401 | pd.copy_config_file('ipython_config.py', overwrite=overwrite) | |
|
3416 | 3402 | |
|
3417 | 3403 | # Pylab support: simple wrappers that activate pylab, load gui input |
|
3418 | 3404 | # handling and modify slightly %run |
@@ -58,11 +58,21 raw_input_original = raw_input | |||
|
58 | 58 | |
|
59 | 59 | class TerminalInteractiveShell(InteractiveShell): |
|
60 | 60 | |
|
61 |
autoedit_syntax = CBool(False, config=True |
|
|
61 | autoedit_syntax = CBool(False, config=True, | |
|
62 | help="auto editing of files with syntax errors.") | |
|
62 | 63 | banner = Unicode('') |
|
63 |
banner1 = Unicode(default_banner, config=True |
|
|
64 | banner2 = Unicode('', config=True) | |
|
65 | confirm_exit = CBool(True, config=True) | |
|
64 | banner1 = Unicode(default_banner, config=True, | |
|
65 | help="""The part of the banner to be printed before the profile""" | |
|
66 | ) | |
|
67 | banner2 = Unicode('', config=True, | |
|
68 | help="""The part of the banner to be printed after the profile""" | |
|
69 | ) | |
|
70 | confirm_exit = CBool(True, config=True, | |
|
71 | help=""" | |
|
72 | Set to confirm when you try to exit IPython with an EOF (Control-D | |
|
73 | in Unix, Control-Z/Enter in Windows). By typing 'exit', 'quit' or | |
|
74 | '%%Exit', you can force a direct exit without any confirmation.""", | |
|
75 | ) | |
|
66 | 76 | # This display_banner only controls whether or not self.show_banner() |
|
67 | 77 | # is called when mainloop/interact are called. The default is False |
|
68 | 78 | # because for the terminal based application, the banner behavior |
@@ -71,19 +81,35 class TerminalInteractiveShell(InteractiveShell): | |||
|
71 | 81 | display_banner = CBool(False) # This isn't configurable! |
|
72 | 82 | embedded = CBool(False) |
|
73 | 83 | embedded_active = CBool(False) |
|
74 |
editor = Unicode(get_default_editor(), config=True |
|
|
75 | pager = Unicode('less', config=True) | |
|
76 | ||
|
77 | screen_length = Int(0, config=True) | |
|
78 | term_title = CBool(False, config=True) | |
|
79 | ||
|
80 | def __init__(self, config=None, ipython_dir=None, user_ns=None, | |
|
84 | editor = Unicode(get_default_editor(), config=True, | |
|
85 | help="Set the editor used by IPython (default to $EDITOR/vi/notepad)." | |
|
86 | ) | |
|
87 | pager = Unicode('less', config=True, | |
|
88 | help="The shell program to be used for paging.") | |
|
89 | ||
|
90 | screen_length = Int(0, config=True, | |
|
91 | help= | |
|
92 | """Number of lines of your screen, used to control printing of very | |
|
93 | long strings. Strings longer than this number of lines will be sent | |
|
94 | through a pager instead of directly printed. The default value for | |
|
95 | this is 0, which means IPython will auto-detect your screen size every | |
|
96 | time it needs to print certain potentially long strings (this doesn't | |
|
97 | change the behavior of the 'print' keyword, it's only triggered | |
|
98 | internally). If for some reason this isn't working well (it needs | |
|
99 | curses support), specify it yourself. Otherwise don't change the | |
|
100 | default.""", | |
|
101 | ) | |
|
102 | term_title = CBool(False, config=True, | |
|
103 | help="Enable auto setting the terminal title." | |
|
104 | ) | |
|
105 | ||
|
106 | def __init__(self, config=None, ipython_dir=None, profile_dir=None, user_ns=None, | |
|
81 | 107 | user_global_ns=None, custom_exceptions=((),None), |
|
82 | 108 | usage=None, banner1=None, banner2=None, |
|
83 | 109 | display_banner=None): |
|
84 | 110 | |
|
85 | 111 | super(TerminalInteractiveShell, self).__init__( |
|
86 |
config=config, |
|
|
112 | config=config, profile_dir=profile_dir, user_ns=user_ns, | |
|
87 | 113 | user_global_ns=user_global_ns, custom_exceptions=custom_exceptions |
|
88 | 114 | ) |
|
89 | 115 | # use os.system instead of utils.process.system by default, except on Windows |
This diff has been collapsed as it changes many lines, (768 lines changed) Show them Hide them | |||
@@ -1,7 +1,7 | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | # encoding: utf-8 |
|
3 | 3 | """ |
|
4 | The :class:`~IPython.core.application.Application` object for the command | |
|
4 | The :class:`~IPython.core.newapplication.Application` object for the command | |
|
5 | 5 | line :command:`ipython` program. |
|
6 | 6 | |
|
7 | 7 | Authors |
@@ -9,6 +9,7 Authors | |||
|
9 | 9 | |
|
10 | 10 | * Brian Granger |
|
11 | 11 | * Fernando Perez |
|
12 | * Min Ragan-Kelley | |
|
12 | 13 | """ |
|
13 | 14 | |
|
14 | 15 | #----------------------------------------------------------------------------- |
@@ -28,17 +29,23 import logging | |||
|
28 | 29 | import os |
|
29 | 30 | import sys |
|
30 | 31 | |
|
32 | from IPython.config.loader import ( | |
|
33 | Config, PyFileConfigLoader | |
|
34 | ) | |
|
35 | from IPython.config.application import boolean_flag | |
|
31 | 36 | from IPython.core import release |
|
37 | from IPython.core import usage | |
|
32 | 38 | from IPython.core.crashhandler import CrashHandler |
|
33 | from IPython.core.application import Application, BaseAppConfigLoader | |
|
34 | from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell | |
|
35 | from IPython.config.loader import ( | |
|
36 | Config, | |
|
37 | PyFileConfigLoader | |
|
39 | from IPython.core.formatters import PlainTextFormatter | |
|
40 | from IPython.core.newapplication import ( | |
|
41 | ProfileDir, BaseIPythonApplication, base_flags, base_aliases | |
|
38 | 42 | ) |
|
43 | from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell | |
|
39 | 44 | from IPython.lib import inputhook |
|
40 | 45 | from IPython.utils.path import filefind, get_ipython_dir, check_for_old_config |
|
41 |
from IPython. |
|
|
46 | from IPython.utils.traitlets import ( | |
|
47 | Bool, Unicode, Dict, Instance, List,CaselessStrEnum | |
|
48 | ) | |
|
42 | 49 | |
|
43 | 50 | #----------------------------------------------------------------------------- |
|
44 | 51 | # Globals, utilities and helpers |
@@ -48,275 +55,6 from IPython.core import usage | |||
|
48 | 55 | default_config_file_name = u'ipython_config.py' |
|
49 | 56 | |
|
50 | 57 | |
|
51 | class IPAppConfigLoader(BaseAppConfigLoader): | |
|
52 | ||
|
53 | def _add_arguments(self): | |
|
54 | super(IPAppConfigLoader, self)._add_arguments() | |
|
55 | paa = self.parser.add_argument | |
|
56 | paa('-p', | |
|
57 | '--profile', dest='Global.profile', type=unicode, | |
|
58 | help= | |
|
59 | """The string name of the ipython profile to be used. Assume that your | |
|
60 | config file is ipython_config-<name>.py (looks in current dir first, | |
|
61 | then in IPYTHON_DIR). This is a quick way to keep and load multiple | |
|
62 | config files for different tasks, especially if include your basic one | |
|
63 | in your more specialized ones. You can keep a basic | |
|
64 | IPYTHON_DIR/ipython_config.py file and then have other 'profiles' which | |
|
65 | include this one and load extra things for particular tasks.""", | |
|
66 | metavar='Global.profile') | |
|
67 | paa('--config-file', | |
|
68 | dest='Global.config_file', type=unicode, | |
|
69 | help= | |
|
70 | """Set the config file name to override default. Normally IPython | |
|
71 | loads ipython_config.py (from current directory) or | |
|
72 | IPYTHON_DIR/ipython_config.py. If the loading of your config file | |
|
73 | fails, IPython starts with a bare bones configuration (no modules | |
|
74 | loaded at all).""", | |
|
75 | metavar='Global.config_file') | |
|
76 | paa('--autocall', | |
|
77 | dest='InteractiveShell.autocall', type=int, | |
|
78 | help= | |
|
79 | """Make IPython automatically call any callable object even if you | |
|
80 | didn't type explicit parentheses. For example, 'str 43' becomes | |
|
81 | 'str(43)' automatically. The value can be '0' to disable the feature, | |
|
82 | '1' for 'smart' autocall, where it is not applied if there are no more | |
|
83 | arguments on the line, and '2' for 'full' autocall, where all callable | |
|
84 | objects are automatically called (even if no arguments are present). | |
|
85 | The default is '1'.""", | |
|
86 | metavar='InteractiveShell.autocall') | |
|
87 | paa('--autoindent', | |
|
88 | action='store_true', dest='InteractiveShell.autoindent', | |
|
89 | help='Turn on autoindenting.') | |
|
90 | paa('--no-autoindent', | |
|
91 | action='store_false', dest='InteractiveShell.autoindent', | |
|
92 | help='Turn off autoindenting.') | |
|
93 | paa('--automagic', | |
|
94 | action='store_true', dest='InteractiveShell.automagic', | |
|
95 | help= | |
|
96 | """Turn on the auto calling of magic commands. Type %%magic at the | |
|
97 | IPython prompt for more information.""") | |
|
98 | paa('--no-automagic', | |
|
99 | action='store_false', dest='InteractiveShell.automagic', | |
|
100 | help='Turn off the auto calling of magic commands.') | |
|
101 | paa('--autoedit-syntax', | |
|
102 | action='store_true', dest='TerminalInteractiveShell.autoedit_syntax', | |
|
103 | help='Turn on auto editing of files with syntax errors.') | |
|
104 | paa('--no-autoedit-syntax', | |
|
105 | action='store_false', dest='TerminalInteractiveShell.autoedit_syntax', | |
|
106 | help='Turn off auto editing of files with syntax errors.') | |
|
107 | paa('--banner', | |
|
108 | action='store_true', dest='Global.display_banner', | |
|
109 | help='Display a banner upon starting IPython.') | |
|
110 | paa('--no-banner', | |
|
111 | action='store_false', dest='Global.display_banner', | |
|
112 | help="Don't display a banner upon starting IPython.") | |
|
113 | paa('--cache-size', | |
|
114 | type=int, dest='InteractiveShell.cache_size', | |
|
115 | help= | |
|
116 | """Set the size of the output cache. The default is 1000, you can | |
|
117 | change it permanently in your config file. Setting it to 0 completely | |
|
118 | disables the caching system, and the minimum value accepted is 20 (if | |
|
119 | you provide a value less than 20, it is reset to 0 and a warning is | |
|
120 | issued). This limit is defined because otherwise you'll spend more | |
|
121 | time re-flushing a too small cache than working""", | |
|
122 | metavar='InteractiveShell.cache_size') | |
|
123 | paa('--classic', | |
|
124 | action='store_true', dest='Global.classic', | |
|
125 | help="Gives IPython a similar feel to the classic Python prompt.") | |
|
126 | paa('--colors', | |
|
127 | type=str, dest='InteractiveShell.colors', | |
|
128 | help="Set the color scheme (NoColor, Linux, and LightBG).", | |
|
129 | metavar='InteractiveShell.colors') | |
|
130 | paa('--color-info', | |
|
131 | action='store_true', dest='InteractiveShell.color_info', | |
|
132 | help= | |
|
133 | """IPython can display information about objects via a set of func- | |
|
134 | tions, and optionally can use colors for this, syntax highlighting | |
|
135 | source code and various other elements. However, because this | |
|
136 | information is passed through a pager (like 'less') and many pagers get | |
|
137 | confused with color codes, this option is off by default. You can test | |
|
138 | it and turn it on permanently in your ipython_config.py file if it | |
|
139 | works for you. Test it and turn it on permanently if it works with | |
|
140 | your system. The magic function %%color_info allows you to toggle this | |
|
141 | inter- actively for testing.""") | |
|
142 | paa('--no-color-info', | |
|
143 | action='store_false', dest='InteractiveShell.color_info', | |
|
144 | help="Disable using colors for info related things.") | |
|
145 | paa('--confirm-exit', | |
|
146 | action='store_true', dest='TerminalInteractiveShell.confirm_exit', | |
|
147 | help= | |
|
148 | """Set to confirm when you try to exit IPython with an EOF (Control-D | |
|
149 | in Unix, Control-Z/Enter in Windows). By typing 'exit', 'quit' or | |
|
150 | '%%Exit', you can force a direct exit without any confirmation.""") | |
|
151 | paa('--no-confirm-exit', | |
|
152 | action='store_false', dest='TerminalInteractiveShell.confirm_exit', | |
|
153 | help="Don't prompt the user when exiting.") | |
|
154 | paa('--deep-reload', | |
|
155 | action='store_true', dest='InteractiveShell.deep_reload', | |
|
156 | help= | |
|
157 | """Enable deep (recursive) reloading by default. IPython can use the | |
|
158 | deep_reload module which reloads changes in modules recursively (it | |
|
159 | replaces the reload() function, so you don't need to change anything to | |
|
160 | use it). deep_reload() forces a full reload of modules whose code may | |
|
161 | have changed, which the default reload() function does not. When | |
|
162 | deep_reload is off, IPython will use the normal reload(), but | |
|
163 | deep_reload will still be available as dreload(). This fea- ture is off | |
|
164 | by default [which means that you have both normal reload() and | |
|
165 | dreload()].""") | |
|
166 | paa('--no-deep-reload', | |
|
167 | action='store_false', dest='InteractiveShell.deep_reload', | |
|
168 | help="Disable deep (recursive) reloading by default.") | |
|
169 | paa('--editor', | |
|
170 | type=str, dest='TerminalInteractiveShell.editor', | |
|
171 | help="Set the editor used by IPython (default to $EDITOR/vi/notepad).", | |
|
172 | metavar='TerminalInteractiveShell.editor') | |
|
173 | paa('--log','-l', | |
|
174 | action='store_true', dest='InteractiveShell.logstart', | |
|
175 | help="Start logging to the default log file (./ipython_log.py).") | |
|
176 | paa('--logfile','-lf', | |
|
177 | type=unicode, dest='InteractiveShell.logfile', | |
|
178 | help="Start logging to logfile with this name.", | |
|
179 | metavar='InteractiveShell.logfile') | |
|
180 | paa('--log-append','-la', | |
|
181 | type=unicode, dest='InteractiveShell.logappend', | |
|
182 | help="Start logging to the given file in append mode.", | |
|
183 | metavar='InteractiveShell.logfile') | |
|
184 | paa('--pdb', | |
|
185 | action='store_true', dest='InteractiveShell.pdb', | |
|
186 | help="Enable auto calling the pdb debugger after every exception.") | |
|
187 | paa('--no-pdb', | |
|
188 | action='store_false', dest='InteractiveShell.pdb', | |
|
189 | help="Disable auto calling the pdb debugger after every exception.") | |
|
190 | paa('--pprint', | |
|
191 | action='store_true', dest='PlainTextFormatter.pprint', | |
|
192 | help="Enable auto pretty printing of results.") | |
|
193 | paa('--no-pprint', | |
|
194 | action='store_false', dest='PlainTextFormatter.pprint', | |
|
195 | help="Disable auto auto pretty printing of results.") | |
|
196 | paa('--prompt-in1','-pi1', | |
|
197 | type=str, dest='InteractiveShell.prompt_in1', | |
|
198 | help= | |
|
199 | """Set the main input prompt ('In [\#]: '). Note that if you are using | |
|
200 | numbered prompts, the number is represented with a '\#' in the string. | |
|
201 | Don't forget to quote strings with spaces embedded in them. Most | |
|
202 | bash-like escapes can be used to customize IPython's prompts, as well | |
|
203 | as a few additional ones which are IPython-spe- cific. All valid | |
|
204 | prompt escapes are described in detail in the Customization section of | |
|
205 | the IPython manual.""", | |
|
206 | metavar='InteractiveShell.prompt_in1') | |
|
207 | paa('--prompt-in2','-pi2', | |
|
208 | type=str, dest='InteractiveShell.prompt_in2', | |
|
209 | help= | |
|
210 | """Set the secondary input prompt (' .\D.: '). Similar to the previous | |
|
211 | option, but used for the continuation prompts. The special sequence | |
|
212 | '\D' is similar to '\#', but with all digits replaced by dots (so you | |
|
213 | can have your continuation prompt aligned with your input prompt). | |
|
214 | Default: ' .\D.: ' (note three spaces at the start for alignment with | |
|
215 | 'In [\#]')""", | |
|
216 | metavar='InteractiveShell.prompt_in2') | |
|
217 | paa('--prompt-out','-po', | |
|
218 | type=str, dest='InteractiveShell.prompt_out', | |
|
219 | help="Set the output prompt ('Out[\#]:')", | |
|
220 | metavar='InteractiveShell.prompt_out') | |
|
221 | paa('--quick', | |
|
222 | action='store_true', dest='Global.quick', | |
|
223 | help="Enable quick startup with no config files.") | |
|
224 | paa('--readline', | |
|
225 | action='store_true', dest='InteractiveShell.readline_use', | |
|
226 | help="Enable readline for command line usage.") | |
|
227 | paa('--no-readline', | |
|
228 | action='store_false', dest='InteractiveShell.readline_use', | |
|
229 | help="Disable readline for command line usage.") | |
|
230 | paa('--screen-length','-sl', | |
|
231 | type=int, dest='TerminalInteractiveShell.screen_length', | |
|
232 | help= | |
|
233 | """Number of lines of your screen, used to control printing of very | |
|
234 | long strings. Strings longer than this number of lines will be sent | |
|
235 | through a pager instead of directly printed. The default value for | |
|
236 | this is 0, which means IPython will auto-detect your screen size every | |
|
237 | time it needs to print certain potentially long strings (this doesn't | |
|
238 | change the behavior of the 'print' keyword, it's only triggered | |
|
239 | internally). If for some reason this isn't working well (it needs | |
|
240 | curses support), specify it yourself. Otherwise don't change the | |
|
241 | default.""", | |
|
242 | metavar='TerminalInteractiveShell.screen_length') | |
|
243 | paa('--separate-in','-si', | |
|
244 | type=str, dest='InteractiveShell.separate_in', | |
|
245 | help="Separator before input prompts. Default '\\n'.", | |
|
246 | metavar='InteractiveShell.separate_in') | |
|
247 | paa('--separate-out','-so', | |
|
248 | type=str, dest='InteractiveShell.separate_out', | |
|
249 | help="Separator before output prompts. Default 0 (nothing).", | |
|
250 | metavar='InteractiveShell.separate_out') | |
|
251 | paa('--separate-out2','-so2', | |
|
252 | type=str, dest='InteractiveShell.separate_out2', | |
|
253 | help="Separator after output prompts. Default 0 (nonight).", | |
|
254 | metavar='InteractiveShell.separate_out2') | |
|
255 | paa('--no-sep', | |
|
256 | action='store_true', dest='Global.nosep', | |
|
257 | help="Eliminate all spacing between prompts.") | |
|
258 | paa('--term-title', | |
|
259 | action='store_true', dest='TerminalInteractiveShell.term_title', | |
|
260 | help="Enable auto setting the terminal title.") | |
|
261 | paa('--no-term-title', | |
|
262 | action='store_false', dest='TerminalInteractiveShell.term_title', | |
|
263 | help="Disable auto setting the terminal title.") | |
|
264 | paa('--xmode', | |
|
265 | type=str, dest='InteractiveShell.xmode', | |
|
266 | help= | |
|
267 | """Exception reporting mode ('Plain','Context','Verbose'). Plain: | |
|
268 | similar to python's normal traceback printing. Context: prints 5 lines | |
|
269 | of context source code around each line in the traceback. Verbose: | |
|
270 | similar to Context, but additionally prints the variables currently | |
|
271 | visible where the exception happened (shortening their strings if too | |
|
272 | long). This can potentially be very slow, if you happen to have a huge | |
|
273 | data structure whose string representation is complex to compute. | |
|
274 | Your computer may appear to freeze for a while with cpu usage at 100%%. | |
|
275 | If this occurs, you can cancel the traceback with Ctrl-C (maybe hitting | |
|
276 | it more than once). | |
|
277 | """, | |
|
278 | metavar='InteractiveShell.xmode') | |
|
279 | paa('--ext', | |
|
280 | type=str, dest='Global.extra_extension', | |
|
281 | help="The dotted module name of an IPython extension to load.", | |
|
282 | metavar='Global.extra_extension') | |
|
283 | paa('-c', | |
|
284 | type=str, dest='Global.code_to_run', | |
|
285 | help="Execute the given command string.", | |
|
286 | metavar='Global.code_to_run') | |
|
287 | paa('-i', | |
|
288 | action='store_true', dest='Global.force_interact', | |
|
289 | help= | |
|
290 | "If running code from the command line, become interactive afterwards.") | |
|
291 | ||
|
292 | # Options to start with GUI control enabled from the beginning | |
|
293 | paa('--gui', | |
|
294 | type=str, dest='Global.gui', | |
|
295 | help="Enable GUI event loop integration ('qt', 'wx', 'gtk').", | |
|
296 | metavar='gui-mode') | |
|
297 | paa('--pylab','-pylab', | |
|
298 | type=str, dest='Global.pylab', | |
|
299 | nargs='?', const='auto', metavar='gui-mode', | |
|
300 | help="Pre-load matplotlib and numpy for interactive use. "+ | |
|
301 | "If no value is given, the gui backend is matplotlib's, else use "+ | |
|
302 | "one of: ['tk', 'qt', 'wx', 'gtk', 'osx'].") | |
|
303 | ||
|
304 | # Legacy GUI options. Leave them in for backwards compatibility, but the | |
|
305 | # 'thread' names are really a misnomer now. | |
|
306 | paa('--wthread', '-wthread', | |
|
307 | action='store_true', dest='Global.wthread', | |
|
308 | help= | |
|
309 | """Enable wxPython event loop integration. (DEPRECATED, use --gui wx)""") | |
|
310 | paa('--q4thread', '--qthread', '-q4thread', '-qthread', | |
|
311 | action='store_true', dest='Global.q4thread', | |
|
312 | help= | |
|
313 | """Enable Qt4 event loop integration. Qt3 is no longer supported. | |
|
314 | (DEPRECATED, use --gui qt)""") | |
|
315 | paa('--gthread', '-gthread', | |
|
316 | action='store_true', dest='Global.gthread', | |
|
317 | help= | |
|
318 | """Enable GTK event loop integration. (DEPRECATED, use --gui gtk)""") | |
|
319 | ||
|
320 | 58 | |
|
321 | 59 | #----------------------------------------------------------------------------- |
|
322 | 60 | # Crash handler for this application |
@@ -377,206 +115,337 class IPAppCrashHandler(CrashHandler): | |||
|
377 | 115 | |
|
378 | 116 | return ''.join(report) |
|
379 | 117 | |
|
118 | #----------------------------------------------------------------------------- | |
|
119 | # Aliases and Flags | |
|
120 | #----------------------------------------------------------------------------- | |
|
121 | flags = dict(base_flags) | |
|
122 | flags.update({ | |
|
123 | ||
|
124 | ||
|
125 | }) | |
|
126 | addflag = lambda *args: flags.update(boolean_flag(*args)) | |
|
127 | addflag('autoindent', 'InteractiveShell.autoindent', | |
|
128 | 'Turn on autoindenting.', 'Turn off autoindenting.' | |
|
129 | ) | |
|
130 | addflag('automagic', 'InteractiveShell.automagic', | |
|
131 | """Turn on the auto calling of magic commands. Type %%magic at the | |
|
132 | IPython prompt for more information.""", | |
|
133 | 'Turn off the auto calling of magic commands.' | |
|
134 | ) | |
|
135 | addflag('autoedit-syntax', 'TerminalInteractiveShell.autoedit_syntax', | |
|
136 | 'Turn on auto editing of files with syntax errors.', | |
|
137 | 'Turn off auto editing of files with syntax errors.' | |
|
138 | ) | |
|
139 | addflag('banner', 'IPythonApp.display_banner', | |
|
140 | "Display a banner upon starting IPython.", | |
|
141 | "Don't display a banner upon starting IPython." | |
|
142 | ) | |
|
143 | addflag('pdb', 'InteractiveShell.pdb', | |
|
144 | "Enable auto calling the pdb debugger after every exception.", | |
|
145 | "Disable auto calling the pdb debugger after every exception." | |
|
146 | ) | |
|
147 | addflag('pprint', 'PlainTextFormatter.pprint', | |
|
148 | "Enable auto pretty printing of results.", | |
|
149 | "Disable auto auto pretty printing of results." | |
|
150 | ) | |
|
151 | addflag('color-info', 'InteractiveShell.color_info', | |
|
152 | """IPython can display information about objects via a set of func- | |
|
153 | tions, and optionally can use colors for this, syntax highlighting | |
|
154 | source code and various other elements. However, because this | |
|
155 | information is passed through a pager (like 'less') and many pagers get | |
|
156 | confused with color codes, this option is off by default. You can test | |
|
157 | it and turn it on permanently in your ipython_config.py file if it | |
|
158 | works for you. Test it and turn it on permanently if it works with | |
|
159 | your system. The magic function %%color_info allows you to toggle this | |
|
160 | inter- actively for testing.""", | |
|
161 | "Disable using colors for info related things." | |
|
162 | ) | |
|
163 | addflag('confirm-exit', 'TerminalInteractiveShell.confirm_exit', | |
|
164 | """Set to confirm when you try to exit IPython with an EOF (Control-D | |
|
165 | in Unix, Control-Z/Enter in Windows). By typing 'exit', 'quit' or | |
|
166 | '%%Exit', you can force a direct exit without any confirmation.""", | |
|
167 | "Don't prompt the user when exiting." | |
|
168 | ) | |
|
169 | addflag('deep-reload', 'InteractiveShell.deep_reload', | |
|
170 | """Enable deep (recursive) reloading by default. IPython can use the | |
|
171 | deep_reload module which reloads changes in modules recursively (it | |
|
172 | replaces the reload() function, so you don't need to change anything to | |
|
173 | use it). deep_reload() forces a full reload of modules whose code may | |
|
174 | have changed, which the default reload() function does not. When | |
|
175 | deep_reload is off, IPython will use the normal reload(), but | |
|
176 | deep_reload will still be available as dreload(). This fea- ture is off | |
|
177 | by default [which means that you have both normal reload() and | |
|
178 | dreload()].""", | |
|
179 | "Disable deep (recursive) reloading by default." | |
|
180 | ) | |
|
181 | addflag('readline', 'InteractiveShell.readline_use', | |
|
182 | "Enable readline for command line usage.", | |
|
183 | "Disable readline for command line usage." | |
|
184 | ) | |
|
185 | addflag('term-title', 'TerminalInteractiveShell.term_title', | |
|
186 | "Enable auto setting the terminal title.", | |
|
187 | "Disable auto setting the terminal title." | |
|
188 | ) | |
|
189 | classic_config = Config() | |
|
190 | classic_config.InteractiveShell.cache_size = 0 | |
|
191 | classic_config.PlainTextFormatter.pprint = False | |
|
192 | classic_config.InteractiveShell.prompt_in1 = '>>> ' | |
|
193 | classic_config.InteractiveShell.prompt_in2 = '... ' | |
|
194 | classic_config.InteractiveShell.prompt_out = '' | |
|
195 | classic_config.InteractiveShell.separate_in = '' | |
|
196 | classic_config.InteractiveShell.separate_out = '' | |
|
197 | classic_config.InteractiveShell.separate_out2 = '' | |
|
198 | classic_config.InteractiveShell.colors = 'NoColor' | |
|
199 | classic_config.InteractiveShell.xmode = 'Plain' | |
|
200 | ||
|
201 | flags['classic']=( | |
|
202 | classic_config, | |
|
203 | "Gives IPython a similar feel to the classic Python prompt." | |
|
204 | ) | |
|
205 | # # log doesn't make so much sense this way anymore | |
|
206 | # paa('--log','-l', | |
|
207 | # action='store_true', dest='InteractiveShell.logstart', | |
|
208 | # help="Start logging to the default log file (./ipython_log.py).") | |
|
209 | # | |
|
210 | # # quick is harder to implement | |
|
211 | flags['quick']=( | |
|
212 | {'IPythonApp' : {'quick' : True}}, | |
|
213 | "Enable quick startup with no config files." | |
|
214 | ) | |
|
215 | ||
|
216 | nosep_config = Config() | |
|
217 | nosep_config.InteractiveShell.separate_in = '' | |
|
218 | nosep_config.InteractiveShell.separate_out = '' | |
|
219 | nosep_config.InteractiveShell.separate_out2 = '' | |
|
220 | ||
|
221 | flags['nosep']=(nosep_config, "Eliminate all spacing between prompts.") | |
|
222 | ||
|
223 | flags['i'] = ( | |
|
224 | {'IPythonApp' : {'force_interact' : True}}, | |
|
225 | "If running code from the command line, become interactive afterwards." | |
|
226 | ) | |
|
227 | flags['pylab'] = ( | |
|
228 | {'IPythonApp' : {'pylab' : 'auto'}}, | |
|
229 | """Pre-load matplotlib and numpy for interactive use with | |
|
230 | the default matplotlib backend.""" | |
|
231 | ) | |
|
232 | ||
|
233 | aliases = dict(base_aliases) | |
|
234 | ||
|
235 | # it's possible we don't want short aliases for *all* of these: | |
|
236 | aliases.update(dict( | |
|
237 | autocall='InteractiveShell.autocall', | |
|
238 | cache_size='InteractiveShell.cache_size', | |
|
239 | colors='InteractiveShell.colors', | |
|
240 | editor='TerminalInteractiveShell.editor', | |
|
241 | logfile='InteractiveShell.logfile', | |
|
242 | log_append='InteractiveShell.logappend', | |
|
243 | pi1='InteractiveShell.prompt_in1', | |
|
244 | pi2='InteractiveShell.prompt_in1', | |
|
245 | po='InteractiveShell.prompt_out', | |
|
246 | sl='TerminalInteractiveShell.screen_length', | |
|
247 | si='InteractiveShell.separate_in', | |
|
248 | so='InteractiveShell.separate_out', | |
|
249 | so2='InteractiveShell.separate_out2', | |
|
250 | xmode='InteractiveShell.xmode', | |
|
251 | c='IPythonApp.code_to_run', | |
|
252 | ext='IPythonApp.extra_extension', | |
|
253 | gui='IPythonApp.gui', | |
|
254 | pylab='IPythonApp.pylab', | |
|
255 | )) | |
|
380 | 256 | |
|
381 | 257 | #----------------------------------------------------------------------------- |
|
382 | 258 | # Main classes and functions |
|
383 | 259 | #----------------------------------------------------------------------------- |
|
384 | 260 | |
|
385 | class IPythonApp(Application): | |
|
261 | class IPythonApp(BaseIPythonApplication): | |
|
386 | 262 | name = u'ipython' |
|
387 | #: argparse formats better the 'usage' than the 'description' field | |
|
388 | description = None | |
|
389 | usage = usage.cl_usage | |
|
390 | command_line_loader = IPAppConfigLoader | |
|
263 | description = usage.cl_usage | |
|
264 | # command_line_loader = IPAppConfigLoader | |
|
391 | 265 | default_config_file_name = default_config_file_name |
|
392 | 266 | crash_handler_class = IPAppCrashHandler |
|
393 | ||
|
394 | def create_default_config(self): | |
|
395 | super(IPythonApp, self).create_default_config() | |
|
396 | # Eliminate multiple lookups | |
|
397 | Global = self.default_config.Global | |
|
398 | ||
|
399 | # Set all default values | |
|
400 | Global.display_banner = True | |
|
267 | flags = Dict(flags) | |
|
268 | aliases = Dict(aliases) | |
|
269 | classes = [TerminalInteractiveShell, ProfileDir, PlainTextFormatter] | |
|
270 | # *do* autocreate requested profile | |
|
271 | auto_create=Bool(True) | |
|
272 | copy_config_files=Bool(True) | |
|
273 | # configurables | |
|
274 | ignore_old_config=Bool(False, config=True, | |
|
275 | help="Suppress warning messages about legacy config files" | |
|
276 | ) | |
|
277 | quick = Bool(False, config=True, | |
|
278 | help="""Start IPython quickly by skipping the loading of config files.""" | |
|
279 | ) | |
|
280 | def _quick_changed(self, name, old, new): | |
|
281 | if new: | |
|
282 | self.load_config_file = lambda *a, **kw: None | |
|
283 | self.ignore_old_config=True | |
|
284 | ||
|
285 | gui = CaselessStrEnum(('qt','wx','gtk'), config=True, | |
|
286 | help="Enable GUI event loop integration ('qt', 'wx', 'gtk')." | |
|
287 | ) | |
|
288 | pylab = CaselessStrEnum(['tk', 'qt', 'wx', 'gtk', 'osx', 'auto'], | |
|
289 | config=True, | |
|
290 | help="""Pre-load matplotlib and numpy for interactive use, | |
|
291 | selecting a particular matplotlib backend and loop integration. | |
|
292 | """ | |
|
293 | ) | |
|
294 | display_banner = Bool(True, config=True, | |
|
295 | help="Whether to display a banner upon starting IPython." | |
|
296 | ) | |
|
297 | extensions = List(Unicode, config=True, | |
|
298 | help="A list of dotted module names of IPython extensions to load." | |
|
299 | ) | |
|
300 | extra_extension = Unicode('', config=True, | |
|
301 | help="dotted module name of an IPython extension to load." | |
|
302 | ) | |
|
303 | def _extra_extension_changed(self, name, old, new): | |
|
304 | if new: | |
|
305 | # add to self.extensions | |
|
306 | self.extensions.append(new) | |
|
307 | ||
|
308 | # if there is code of files to run from the cmd line, don't interact | |
|
309 | # unless the --i flag (App.force_interact) is true. | |
|
310 | force_interact = Bool(False, config=True, | |
|
311 | help="""If a command or file is given via the command-line, | |
|
312 | e.g. 'ipython foo.py""" | |
|
313 | ) | |
|
314 | def _force_interact_changed(self, name, old, new): | |
|
315 | if new: | |
|
316 | self.interact = True | |
|
317 | ||
|
318 | exec_files = List(Unicode, config=True, | |
|
319 | help="""List of files to run at IPython startup.""" | |
|
320 | ) | |
|
321 | file_to_run = Unicode('', config=True, | |
|
322 | help="""A file to be run""") | |
|
323 | def _file_to_run_changed(self, name, old, new): | |
|
324 | if new and not self.force_interact: | |
|
325 | self.interact = False | |
|
326 | ||
|
327 | exec_lines = List(Unicode, config=True, | |
|
328 | help="""lines of code to run at IPython startup.""" | |
|
329 | ) | |
|
330 | code_to_run = Unicode('', config=True, | |
|
331 | help="Execute the given command string." | |
|
332 | ) | |
|
333 | _code_to_run_changed = _file_to_run_changed | |
|
334 | ||
|
335 | # internal, not-configurable | |
|
336 | interact=Bool(True) | |
|
337 | ||
|
338 | ||
|
339 | def initialize(self, argv=None): | |
|
340 | """Do actions after construct, but before starting the app.""" | |
|
341 | super(IPythonApp, self).initialize(argv) | |
|
342 | if not self.ignore_old_config: | |
|
343 | check_for_old_config(self.ipython_dir) | |
|
401 | 344 | |
|
402 | # If the -c flag is given or a file is given to run at the cmd line | |
|
403 | # like "ipython foo.py", normally we exit without starting the main | |
|
404 | # loop. The force_interact config variable allows a user to override | |
|
405 | # this and interact. It is also set by the -i cmd line flag, just | |
|
406 | # like Python. | |
|
407 | Global.force_interact = False | |
|
408 | ||
|
409 | # By default always interact by starting the IPython mainloop. | |
|
410 | Global.interact = True | |
|
411 | ||
|
412 | # No GUI integration by default | |
|
413 | Global.gui = False | |
|
414 | # Pylab off by default | |
|
415 | Global.pylab = False | |
|
416 | ||
|
417 | # Deprecated versions of gui support that used threading, we support | |
|
418 | # them just for bacwards compatibility as an alternate spelling for | |
|
419 | # '--gui X' | |
|
420 | Global.qthread = False | |
|
421 | Global.q4thread = False | |
|
422 | Global.wthread = False | |
|
423 | Global.gthread = False | |
|
424 | ||
|
425 | def load_file_config(self): | |
|
426 | if hasattr(self.command_line_config.Global, 'quick'): | |
|
427 | if self.command_line_config.Global.quick: | |
|
428 | self.file_config = Config() | |
|
429 | return | |
|
430 | super(IPythonApp, self).load_file_config() | |
|
431 | ||
|
432 | def post_load_file_config(self): | |
|
433 | if hasattr(self.command_line_config.Global, 'extra_extension'): | |
|
434 | if not hasattr(self.file_config.Global, 'extensions'): | |
|
435 | self.file_config.Global.extensions = [] | |
|
436 | self.file_config.Global.extensions.append( | |
|
437 | self.command_line_config.Global.extra_extension) | |
|
438 | del self.command_line_config.Global.extra_extension | |
|
439 | ||
|
440 | def pre_construct(self): | |
|
441 | config = self.master_config | |
|
442 | ||
|
443 | if hasattr(config.Global, 'classic'): | |
|
444 | if config.Global.classic: | |
|
445 | config.InteractiveShell.cache_size = 0 | |
|
446 | config.PlainTextFormatter.pprint = False | |
|
447 | config.InteractiveShell.prompt_in1 = '>>> ' | |
|
448 | config.InteractiveShell.prompt_in2 = '... ' | |
|
449 | config.InteractiveShell.prompt_out = '' | |
|
450 | config.InteractiveShell.separate_in = \ | |
|
451 | config.InteractiveShell.separate_out = \ | |
|
452 | config.InteractiveShell.separate_out2 = '' | |
|
453 | config.InteractiveShell.colors = 'NoColor' | |
|
454 | config.InteractiveShell.xmode = 'Plain' | |
|
455 | ||
|
456 | if hasattr(config.Global, 'nosep'): | |
|
457 | if config.Global.nosep: | |
|
458 | config.InteractiveShell.separate_in = \ | |
|
459 | config.InteractiveShell.separate_out = \ | |
|
460 | config.InteractiveShell.separate_out2 = '' | |
|
461 | ||
|
462 | # if there is code of files to run from the cmd line, don't interact | |
|
463 | # unless the -i flag (Global.force_interact) is true. | |
|
464 | code_to_run = config.Global.get('code_to_run','') | |
|
465 | file_to_run = False | |
|
466 | if self.extra_args and self.extra_args[0]: | |
|
467 | file_to_run = True | |
|
468 | if file_to_run or code_to_run: | |
|
469 | if not config.Global.force_interact: | |
|
470 | config.Global.interact = False | |
|
471 | ||
|
472 | def construct(self): | |
|
345 | # print self.extra_args | |
|
346 | if self.extra_args: | |
|
347 | self.file_to_run = self.extra_args[0] | |
|
348 | # create the shell | |
|
349 | self.init_shell() | |
|
350 | # and draw the banner | |
|
351 | self.init_banner() | |
|
352 | # Now a variety of things that happen after the banner is printed. | |
|
353 | self.init_gui_pylab() | |
|
354 | self.init_extensions() | |
|
355 | self.init_code() | |
|
356 | ||
|
357 | def init_shell(self): | |
|
358 | """initialize the InteractiveShell instance""" | |
|
473 | 359 | # I am a little hesitant to put these into InteractiveShell itself. |
|
474 | 360 | # But that might be the place for them |
|
475 | 361 | sys.path.insert(0, '') |
|
476 | 362 | |
|
477 | 363 | # Create an InteractiveShell instance. |
|
478 | self.shell = TerminalInteractiveShell.instance(config=self.master_config) | |
|
479 | ||
|
480 | def post_construct(self): | |
|
481 | """Do actions after construct, but before starting the app.""" | |
|
482 | config = self.master_config | |
|
483 | ||
|
484 | 364 | # shell.display_banner should always be False for the terminal |
|
485 | 365 | # based app, because we call shell.show_banner() by hand below |
|
486 | 366 | # so the banner shows *before* all extension loading stuff. |
|
487 | self.shell.display_banner = False | |
|
488 | if config.Global.display_banner and \ | |
|
489 | config.Global.interact: | |
|
490 | self.shell.show_banner() | |
|
367 | self.shell = TerminalInteractiveShell.instance(config=self.config, | |
|
368 | display_banner=False, profile_dir=self.profile_dir, | |
|
369 | ipython_dir=self.ipython_dir) | |
|
491 | 370 | |
|
371 | def init_banner(self): | |
|
372 | """optionally display the banner""" | |
|
373 | if self.display_banner and self.interact: | |
|
374 | self.shell.show_banner() | |
|
492 | 375 | # Make sure there is a space below the banner. |
|
493 | 376 | if self.log_level <= logging.INFO: print |
|
494 | 377 | |
|
495 | # Now a variety of things that happen after the banner is printed. | |
|
496 | self._enable_gui_pylab() | |
|
497 | self._load_extensions() | |
|
498 | self._run_exec_lines() | |
|
499 | self._run_exec_files() | |
|
500 | self._run_cmd_line_code() | |
|
501 | 378 | |
|
502 |
def |
|
|
379 | def init_gui_pylab(self): | |
|
503 | 380 | """Enable GUI event loop integration, taking pylab into account.""" |
|
504 | Global = self.master_config.Global | |
|
505 | ||
|
506 | # Select which gui to use | |
|
507 | if Global.gui: | |
|
508 | gui = Global.gui | |
|
509 | # The following are deprecated, but there's likely to be a lot of use | |
|
510 | # of this form out there, so we might as well support it for now. But | |
|
511 | # the --gui option above takes precedence. | |
|
512 | elif Global.wthread: | |
|
513 | gui = inputhook.GUI_WX | |
|
514 | elif Global.qthread: | |
|
515 | gui = inputhook.GUI_QT | |
|
516 | elif Global.gthread: | |
|
517 | gui = inputhook.GUI_GTK | |
|
518 | else: | |
|
519 | gui = None | |
|
381 | gui = self.gui | |
|
520 | 382 | |
|
521 |
# Using |
|
|
383 | # Using `pylab` will also require gui activation, though which toolkit | |
|
522 | 384 | # to use may be chosen automatically based on mpl configuration. |
|
523 |
if |
|
|
385 | if self.pylab: | |
|
524 | 386 | activate = self.shell.enable_pylab |
|
525 |
if |
|
|
387 | if self.pylab == 'auto': | |
|
526 | 388 | gui = None |
|
527 | 389 | else: |
|
528 |
gui = |
|
|
390 | gui = self.pylab | |
|
529 | 391 | else: |
|
530 | 392 | # Enable only GUI integration, no pylab |
|
531 | 393 | activate = inputhook.enable_gui |
|
532 | 394 | |
|
533 |
if gui or |
|
|
395 | if gui or self.pylab: | |
|
534 | 396 | try: |
|
535 | 397 | self.log.info("Enabling GUI event loop integration, " |
|
536 |
"toolkit=%s, pylab=%s" % (gui, |
|
|
398 | "toolkit=%s, pylab=%s" % (gui, self.pylab) ) | |
|
537 | 399 | activate(gui) |
|
538 | 400 | except: |
|
539 | 401 | self.log.warn("Error in enabling GUI event loop integration:") |
|
540 | 402 | self.shell.showtraceback() |
|
541 | 403 | |
|
542 |
def |
|
|
543 |
"""Load all IPython extensions in |
|
|
404 | def init_extensions(self): | |
|
405 | """Load all IPython extensions in IPythonApp.extensions. | |
|
544 | 406 | |
|
545 | 407 | This uses the :meth:`ExtensionManager.load_extensions` to load all |
|
546 |
the extensions listed in ``self. |
|
|
408 | the extensions listed in ``self.extensions``. | |
|
547 | 409 | """ |
|
410 | if not self.extensions: | |
|
411 | return | |
|
548 | 412 | try: |
|
549 | if hasattr(self.master_config.Global, 'extensions'): | |
|
550 | self.log.debug("Loading IPython extensions...") | |
|
551 | extensions = self.master_config.Global.extensions | |
|
552 |
|
|
|
553 | try: | |
|
554 | self.log.info("Loading IPython extension: %s" % ext) | |
|
555 | self.shell.extension_manager.load_extension(ext) | |
|
556 | except: | |
|
557 | self.log.warn("Error in loading extension: %s" % ext) | |
|
558 | self.shell.showtraceback() | |
|
413 | self.log.debug("Loading IPython extensions...") | |
|
414 | extensions = self.extensions | |
|
415 | for ext in extensions: | |
|
416 | try: | |
|
417 | self.log.info("Loading IPython extension: %s" % ext) | |
|
418 | self.shell.extension_manager.load_extension(ext) | |
|
419 | except: | |
|
420 | self.log.warn("Error in loading extension: %s" % ext) | |
|
421 | self.shell.showtraceback() | |
|
559 | 422 | except: |
|
560 | 423 | self.log.warn("Unknown error in loading extensions:") |
|
561 | 424 | self.shell.showtraceback() |
|
562 | 425 | |
|
426 | def init_code(self): | |
|
427 | """run the pre-flight code, specified via exec_lines""" | |
|
428 | self._run_exec_lines() | |
|
429 | self._run_exec_files() | |
|
430 | self._run_cmd_line_code() | |
|
431 | ||
|
563 | 432 | def _run_exec_lines(self): |
|
564 |
"""Run lines of code in |
|
|
433 | """Run lines of code in IPythonApp.exec_lines in the user's namespace.""" | |
|
434 | if not self.exec_lines: | |
|
435 | return | |
|
565 | 436 | try: |
|
566 | if hasattr(self.master_config.Global, 'exec_lines'): | |
|
567 | self.log.debug("Running code from Global.exec_lines...") | |
|
568 | exec_lines = self.master_config.Global.exec_lines | |
|
569 | for line in exec_lines: | |
|
570 |
|
|
|
571 | self.log.info("Running code in user namespace: %s" % | |
|
572 | line) | |
|
573 | self.shell.run_cell(line, store_history=False) | |
|
574 | except: | |
|
575 | self.log.warn("Error in executing line in user " | |
|
576 | "namespace: %s" % line) | |
|
577 | self.shell.showtraceback() | |
|
437 | self.log.debug("Running code from IPythonApp.exec_lines...") | |
|
438 | for line in self.exec_lines: | |
|
439 | try: | |
|
440 | self.log.info("Running code in user namespace: %s" % | |
|
441 | line) | |
|
442 | self.shell.run_cell(line, store_history=False) | |
|
443 | except: | |
|
444 | self.log.warn("Error in executing line in user " | |
|
445 | "namespace: %s" % line) | |
|
446 | self.shell.showtraceback() | |
|
578 | 447 | except: |
|
579 |
self.log.warn("Unknown error in handling |
|
|
448 | self.log.warn("Unknown error in handling IPythonApp.exec_lines:") | |
|
580 | 449 | self.shell.showtraceback() |
|
581 | 450 | |
|
582 | 451 | def _exec_file(self, fname): |
@@ -598,35 +467,36 class IPythonApp(Application): | |||
|
598 | 467 | else: |
|
599 | 468 | self.log.warn("File does not have a .py or .ipy extension: <%s>" |
|
600 | 469 | % full_filename) |
|
470 | ||
|
601 | 471 | def _run_exec_files(self): |
|
472 | """Run files from IPythonApp.exec_files""" | |
|
473 | if not self.exec_files: | |
|
474 | return | |
|
475 | ||
|
476 | self.log.debug("Running files in IPythonApp.exec_files...") | |
|
602 | 477 | try: |
|
603 | if hasattr(self.master_config.Global, 'exec_files'): | |
|
604 | self.log.debug("Running files in Global.exec_files...") | |
|
605 | exec_files = self.master_config.Global.exec_files | |
|
606 | for fname in exec_files: | |
|
607 | self._exec_file(fname) | |
|
478 | for fname in self.exec_files: | |
|
479 | self._exec_file(fname) | |
|
608 | 480 | except: |
|
609 |
self.log.warn("Unknown error in handling |
|
|
481 | self.log.warn("Unknown error in handling IPythonApp.exec_files:") | |
|
610 | 482 | self.shell.showtraceback() |
|
611 | 483 | |
|
612 | 484 | def _run_cmd_line_code(self): |
|
613 | if hasattr(self.master_config.Global, 'code_to_run'): | |
|
614 |
|
|
|
485 | """Run code or file specified at the command-line""" | |
|
486 | if self.code_to_run: | |
|
487 | line = self.code_to_run | |
|
615 | 488 | try: |
|
616 |
self.log.info("Running code given at command line ( |
|
|
489 | self.log.info("Running code given at command line (c=): %s" % | |
|
617 | 490 | line) |
|
618 | 491 | self.shell.run_cell(line, store_history=False) |
|
619 | 492 | except: |
|
620 | 493 | self.log.warn("Error in executing line in user namespace: %s" % |
|
621 | 494 | line) |
|
622 | 495 | self.shell.showtraceback() |
|
623 | return | |
|
496 | ||
|
624 | 497 | # Like Python itself, ignore the second if the first of these is present |
|
625 | try: | |
|
626 |
fname = self. |
|
|
627 | except: | |
|
628 | pass | |
|
629 | else: | |
|
498 | elif self.file_to_run: | |
|
499 | fname = self.file_to_run | |
|
630 | 500 | try: |
|
631 | 501 | self._exec_file(fname) |
|
632 | 502 | except: |
@@ -634,14 +504,14 class IPythonApp(Application): | |||
|
634 | 504 | fname) |
|
635 | 505 | self.shell.showtraceback() |
|
636 | 506 | |
|
637 | def start_app(self): | |
|
638 | if not getattr(self.master_config.Global, 'ignore_old_config', False): | |
|
639 | check_for_old_config(self.ipython_dir) | |
|
640 |
if self. |
|
|
507 | ||
|
508 | def start(self): | |
|
509 | # perform any prexec steps: | |
|
510 | if self.interact: | |
|
641 | 511 | self.log.debug("Starting IPython's mainloop...") |
|
642 | 512 | self.shell.mainloop() |
|
643 | 513 | else: |
|
644 |
self.log.debug("IPython not interactive |
|
|
514 | self.log.debug("IPython not interactive...") | |
|
645 | 515 | |
|
646 | 516 | |
|
647 | 517 | def load_default_config(ipython_dir=None): |
@@ -651,7 +521,8 def load_default_config(ipython_dir=None): | |||
|
651 | 521 | """ |
|
652 | 522 | if ipython_dir is None: |
|
653 | 523 | ipython_dir = get_ipython_dir() |
|
654 | cl = PyFileConfigLoader(default_config_file_name, ipython_dir) | |
|
524 | profile_dir = os.path.join(ipython_dir, 'profile_default') | |
|
525 | cl = PyFileConfigLoader(default_config_file_name, profile_dir) | |
|
655 | 526 | config = cl.load_config() |
|
656 | 527 | return config |
|
657 | 528 | |
@@ -659,6 +530,9 def load_default_config(ipython_dir=None): | |||
|
659 | 530 | def launch_new_instance(): |
|
660 | 531 | """Create and run a full blown IPython instance""" |
|
661 | 532 | app = IPythonApp() |
|
533 | app.initialize() | |
|
534 | # print app.config | |
|
535 | # print app.profile_dir.location | |
|
662 | 536 | app.start() |
|
663 | 537 | |
|
664 | 538 |
@@ -304,9 +304,7 class IPythonRunner(InteractiveRunner): | |||
|
304 | 304 | def __init__(self,program = 'ipython',args=None,out=sys.stdout,echo=True): |
|
305 | 305 | """New runner, optionally passing the ipython command to use.""" |
|
306 | 306 | |
|
307 |
args0 = [' |
|
|
308 | '-pi1','In [\\#]: ', | |
|
309 | '-pi2',' .\\D.: ', | |
|
307 | args0 = ['colors=NoColor', | |
|
310 | 308 | '--no-term-title', |
|
311 | 309 | '--no-autoindent'] |
|
312 | 310 | if args is None: args = args0 |
@@ -158,8 +158,8 def default_argv(): | |||
|
158 | 158 | |
|
159 | 159 | return ['--quick', # so no config file is loaded |
|
160 | 160 | # Other defaults to minimize side effects on stdout |
|
161 |
' |
|
|
162 |
' |
|
|
161 | 'colors=NoColor', '--no-term-title','--no-banner', | |
|
162 | 'autocall=0'] | |
|
163 | 163 | |
|
164 | 164 | |
|
165 | 165 | def default_config(): |
@@ -197,7 +197,7 def ipexec(fname, options=None): | |||
|
197 | 197 | |
|
198 | 198 | # For these subprocess calls, eliminate all prompt printing so we only see |
|
199 | 199 | # output from script execution |
|
200 |
prompt_opts = [' |
|
|
200 | prompt_opts = ['pi1=""', 'pi2=""', 'po=""'] | |
|
201 | 201 | cmdargs = ' '.join(default_argv() + prompt_opts + options) |
|
202 | 202 | |
|
203 | 203 | _ip = get_ipython() |
General Comments 0
You need to be logged in to leave comments.
Login now