##// END OF EJS Templates
adopt traitlets 4.2 API...
Min RK -
r22340:04d48146
parent child
Show More
Add another comment
@@ -192,8 +192,8 class Alias(object):
192
192
193 class AliasManager(Configurable):
193 class AliasManager(Configurable):
194
194
195 default_aliases = List(default_aliases(), config=True)
195 default_aliases = List(default_aliases()).tag(config=True)
196 user_aliases = List(default_value=[], config=True)
196 user_aliases = List(default_value=[]).tag(config=True)
197 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True)
197 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True)
198
198
199 def __init__(self, shell=None, **kwargs):
199 def __init__(self, shell=None, **kwargs):
@@ -26,7 +26,10 from IPython.core.profiledir import ProfileDir, ProfileDirError
26 from IPython.paths import get_ipython_dir, get_ipython_package_dir
26 from IPython.paths import get_ipython_dir, get_ipython_package_dir
27 from IPython.utils.path import ensure_dir_exists
27 from IPython.utils.path import ensure_dir_exists
28 from IPython.utils import py3compat
28 from IPython.utils import py3compat
29 from traitlets import List, Unicode, Type, Bool, Dict, Set, Instance, Undefined
29 from traitlets import (
30 List, Unicode, Type, Bool, Dict, Set, Instance, Undefined,
31 default, observe,
32 )
30
33
31 if os.name == 'nt':
34 if os.name == 'nt':
32 programdata = os.environ.get('PROGRAMDATA', None)
35 programdata = os.environ.get('PROGRAMDATA', None)
@@ -96,11 +99,13 class BaseIPythonApplication(Application):
96 config_file_specified = Set()
99 config_file_specified = Set()
97
100
98 config_file_name = Unicode()
101 config_file_name = Unicode()
102 @default('config_file_name')
99 def _config_file_name_default(self):
103 def _config_file_name_default(self):
100 return self.name.replace('-','_') + u'_config.py'
104 return self.name.replace('-','_') + u'_config.py'
101 def _config_file_name_changed(self, name, old, new):
105 @observe('config_file_name')
102 if new != old:
106 def _config_file_name_changed(self, change):
103 self.config_file_specified.add(new)
107 if change['new'] != change['old']:
108 self.config_file_specified.add(change['new'])
104
109
105 # The directory that contains IPython's builtin profiles.
110 # The directory that contains IPython's builtin profiles.
106 builtin_profile_dir = Unicode(
111 builtin_profile_dir = Unicode(
@@ -108,15 +113,19 class BaseIPythonApplication(Application):
108 )
113 )
109
114
110 config_file_paths = List(Unicode())
115 config_file_paths = List(Unicode())
116 @default('config_file_paths')
111 def _config_file_paths_default(self):
117 def _config_file_paths_default(self):
112 return [py3compat.getcwd()]
118 return [py3compat.getcwd()]
113
119
114 extra_config_file = Unicode(config=True,
120 extra_config_file = Unicode(
115 help="""Path to an extra config file to load.
121 help="""Path to an extra config file to load.
116
122
117 If specified, load this config file in addition to any other IPython config.
123 If specified, load this config file in addition to any other IPython config.
118 """)
124 """).tag(config=True)
119 def _extra_config_file_changed(self, name, old, new):
125 @observe('extra_config_file')
126 def _extra_config_file_changed(self, change):
127 old = change['old']
128 new = change['new']
120 try:
129 try:
121 self.config_files.remove(old)
130 self.config_files.remove(old)
122 except ValueError:
131 except ValueError:
@@ -124,30 +133,37 class BaseIPythonApplication(Application):
124 self.config_file_specified.add(new)
133 self.config_file_specified.add(new)
125 self.config_files.append(new)
134 self.config_files.append(new)
126
135
127 profile = Unicode(u'default', config=True,
136 profile = Unicode(u'default',
128 help="""The IPython profile to use."""
137 help="""The IPython profile to use."""
129 )
138 ).tag(config=True)
130
139
131 def _profile_changed(self, name, old, new):
140 @observe('profile')
141 def _profile_changed(self, change):
132 self.builtin_profile_dir = os.path.join(
142 self.builtin_profile_dir = os.path.join(
133 get_ipython_package_dir(), u'config', u'profile', new
143 get_ipython_package_dir(), u'config', u'profile', change['new']
134 )
144 )
135
145
136 ipython_dir = Unicode(config=True,
146 ipython_dir = Unicode(
137 help="""
147 help="""
138 The name of the IPython directory. This directory is used for logging
148 The name of the IPython directory. This directory is used for logging
139 configuration (through profiles), history storage, etc. The default
149 configuration (through profiles), history storage, etc. The default
140 is usually $HOME/.ipython. This option can also be specified through
150 is usually $HOME/.ipython. This option can also be specified through
141 the environment variable IPYTHONDIR.
151 the environment variable IPYTHONDIR.
142 """
152 """
143 )
153 ).tag(config=True)
154 @default('ipython_dir')
144 def _ipython_dir_default(self):
155 def _ipython_dir_default(self):
145 d = get_ipython_dir()
156 d = get_ipython_dir()
146 self._ipython_dir_changed('ipython_dir', d, d)
157 self._ipython_dir_changed({
158 'name': 'ipython_dir',
159 'old': d,
160 'new': d,
161 })
147 return d
162 return d
148
163
149 _in_init_profile_dir = False
164 _in_init_profile_dir = False
150 profile_dir = Instance(ProfileDir, allow_none=True)
165 profile_dir = Instance(ProfileDir, allow_none=True)
166 @default('profile_dir')
151 def _profile_dir_default(self):
167 def _profile_dir_default(self):
152 # avoid recursion
168 # avoid recursion
153 if self._in_init_profile_dir:
169 if self._in_init_profile_dir:
@@ -156,26 +172,29 class BaseIPythonApplication(Application):
156 self.init_profile_dir()
172 self.init_profile_dir()
157 return self.profile_dir
173 return self.profile_dir
158
174
159 overwrite = Bool(False, config=True,
175 overwrite = Bool(False,
160 help="""Whether to overwrite existing config files when copying""")
176 help="""Whether to overwrite existing config files when copying"""
161 auto_create = Bool(False, config=True,
177 ).tag(config=True)
162 help="""Whether to create profile dir if it doesn't exist""")
178 auto_create = Bool(False,
179 help="""Whether to create profile dir if it doesn't exist"""
180 ).tag(config=True)
163
181
164 config_files = List(Unicode())
182 config_files = List(Unicode())
183 @default('config_files')
165 def _config_files_default(self):
184 def _config_files_default(self):
166 return [self.config_file_name]
185 return [self.config_file_name]
167
186
168 copy_config_files = Bool(False, config=True,
187 copy_config_files = Bool(False,
169 help="""Whether to install the default config files into the profile dir.
188 help="""Whether to install the default config files into the profile dir.
170 If a new profile is being created, and IPython contains config files for that
189 If a new profile is being created, and IPython contains config files for that
171 profile, then they will be staged into the new directory. Otherwise,
190 profile, then they will be staged into the new directory. Otherwise,
172 default config files will be automatically generated.
191 default config files will be automatically generated.
173 """)
192 """).tag(config=True)
174
193
175 verbose_crash = Bool(False, config=True,
194 verbose_crash = Bool(False,
176 help="""Create a massive crash report when IPython encounters what may be an
195 help="""Create a massive crash report when IPython encounters what may be an
177 internal error. The default is to append a short message to the
196 internal error. The default is to append a short message to the
178 usual traceback""")
197 usual traceback""").tag(config=True)
179
198
180 # The class to use as the crash handler.
199 # The class to use as the crash handler.
181 crash_handler_class = Type(crashhandler.CrashHandler)
200 crash_handler_class = Type(crashhandler.CrashHandler)
@@ -199,7 +218,6 class BaseIPythonApplication(Application):
199
218
200 def initialize_subcommand(self, subc, argv=None):
219 def initialize_subcommand(self, subc, argv=None):
201 if subc in self.deprecated_subcommands:
220 if subc in self.deprecated_subcommands:
202 import time
203 self.log.warning("Subcommand `ipython {sub}` is deprecated and will be removed "
221 self.log.warning("Subcommand `ipython {sub}` is deprecated and will be removed "
204 "in future versions.".format(sub=subc))
222 "in future versions.".format(sub=subc))
205 self.log.warning("You likely want to use `jupyter {sub}` in the "
223 self.log.warning("You likely want to use `jupyter {sub}` in the "
@@ -225,8 +243,11 class BaseIPythonApplication(Application):
225 return self.crash_handler(etype, evalue, tb)
243 return self.crash_handler(etype, evalue, tb)
226 else:
244 else:
227 return crashhandler.crash_handler_lite(etype, evalue, tb)
245 return crashhandler.crash_handler_lite(etype, evalue, tb)
228
246
229 def _ipython_dir_changed(self, name, old, new):
247 @observe('ipython_dir')
248 def _ipython_dir_changed(self, change):
249 old = change['old']
250 new = change['new']
230 if old is not Undefined:
251 if old is not Undefined:
231 str_old = py3compat.cast_bytes_py2(os.path.abspath(old),
252 str_old = py3compat.cast_bytes_py2(os.path.abspath(old),
232 sys.getfilesystemencoding()
253 sys.getfilesystemencoding()
@@ -66,7 +66,7 import sys
66 import unicodedata
66 import unicodedata
67 import string
67 import string
68
68
69 from traitlets.config.configurable import Configurable
69 from traitlets.config.configurable import Configurable
70 from IPython.core.error import TryNext
70 from IPython.core.error import TryNext
71 from IPython.core.inputsplitter import ESC_MAGIC
71 from IPython.core.inputsplitter import ESC_MAGIC
72 from IPython.core.latex_symbols import latex_symbols, reverse_latex_symbol
72 from IPython.core.latex_symbols import latex_symbols, reverse_latex_symbol
@@ -75,7 +75,7 from IPython.utils.decorators import undoc
75 from IPython.utils.dir2 import dir2, get_real_method
75 from IPython.utils.dir2 import dir2, get_real_method
76 from IPython.utils.process import arg_split
76 from IPython.utils.process import arg_split
77 from IPython.utils.py3compat import builtin_mod, string_types, PY3, cast_unicode_py2
77 from IPython.utils.py3compat import builtin_mod, string_types, PY3, cast_unicode_py2
78 from traitlets import CBool, Enum
78 from traitlets import Bool, Enum, observe
79
79
80 import jedi
80 import jedi
81 import jedi.api.helpers
81 import jedi.api.helpers
@@ -174,7 +174,6 def compress_user(path, tilde_expand, tilde_val):
174 return path
174 return path
175
175
176
176
177
178 def completions_sorting_key(word):
177 def completions_sorting_key(word):
179 """key for sorting completions
178 """key for sorting completions
180
179
@@ -273,14 +272,14 class CompletionSplitter(object):
273
272
274 class Completer(Configurable):
273 class Completer(Configurable):
275
274
276 greedy = CBool(False, config=True,
275 greedy = Bool(False,
277 help="""Activate greedy completion
276 help="""Activate greedy completion
278 PENDING DEPRECTION. this is now mostly taken care of with Jedi.
277 PENDING DEPRECTION. this is now mostly taken care of with Jedi.
279
278
280 This will enable completion on elements of lists, results of function calls, etc.,
279 This will enable completion on elements of lists, results of function calls, etc.,
281 but can be unsafe because the code is actually evaluated on TAB.
280 but can be unsafe because the code is actually evaluated on TAB.
282 """
281 """
283 )
282 ).tag(config=True)
284
283
285
284
286 def __init__(self, namespace=None, global_namespace=None, **kwargs):
285 def __init__(self, namespace=None, global_namespace=None, **kwargs):
@@ -505,7 +504,7 def back_unicode_name_matches(text):
505 try :
504 try :
506 unic = unicodedata.name(char)
505 unic = unicodedata.name(char)
507 return '\\'+char,['\\'+unic]
506 return '\\'+char,['\\'+unic]
508 except KeyError as e:
507 except KeyError:
509 pass
508 pass
510 return u'', ()
509 return u'', ()
511
510
@@ -532,17 +531,18 def back_latex_name_matches(text):
532 latex = reverse_latex_symbol[char]
531 latex = reverse_latex_symbol[char]
533 # '\\' replace the \ as well
532 # '\\' replace the \ as well
534 return '\\'+char,[latex]
533 return '\\'+char,[latex]
535 except KeyError as e:
534 except KeyError:
536 pass
535 pass
537 return u'', ()
536 return u'', ()
538
537
539
538
540 class IPCompleter(Completer):
539 class IPCompleter(Completer):
541 """Extension of the completer class with IPython-specific features"""
540 """Extension of the completer class with IPython-specific features"""
542
541
543 def _greedy_changed(self, name, old, new):
542 @observe('greedy')
543 def _greedy_changed(self, change):
544 """update the splitter and readline delims when greedy is changed"""
544 """update the splitter and readline delims when greedy is changed"""
545 if new:
545 if change['new']:
546 self.splitter.delims = GREEDY_DELIMS
546 self.splitter.delims = GREEDY_DELIMS
547 else:
547 else:
548 self.splitter.delims = DELIMS
548 self.splitter.delims = DELIMS
@@ -550,14 +550,14 class IPCompleter(Completer):
550 if self.readline:
550 if self.readline:
551 self.readline.set_completer_delims(self.splitter.delims)
551 self.readline.set_completer_delims(self.splitter.delims)
552
552
553 merge_completions = CBool(True, config=True,
553 merge_completions = Bool(True,
554 help="""Whether to merge completion results into a single list
554 help="""Whether to merge completion results into a single list
555
555
556 If False, only the completion results from the first non-empty
556 If False, only the completion results from the first non-empty
557 completer will be returned.
557 completer will be returned.
558 """
558 """
559 )
559 ).tag(config=True)
560 omit__names = Enum((0,1,2), default_value=2, config=True,
560 omit__names = Enum((0,1,2), default_value=2,
561 help="""Instruct the completer to omit private method names
561 help="""Instruct the completer to omit private method names
562
562
563 Specifically, when completing on ``object.<tab>``.
563 Specifically, when completing on ``object.<tab>``.
@@ -568,8 +568,8 class IPCompleter(Completer):
568
568
569 When 0: nothing will be excluded.
569 When 0: nothing will be excluded.
570 """
570 """
571 )
571 ).tag(config=True)
572 limit_to__all__ = CBool(default_value=False, config=True,
572 limit_to__all__ = Bool(False,
573 help="""
573 help="""
574 DEPRECATED as of version 5.0.
574 DEPRECATED as of version 5.0.
575
575
@@ -580,8 +580,8 class IPCompleter(Completer):
580 When True: only those names in obj.__all__ will be included.
580 When True: only those names in obj.__all__ will be included.
581
581
582 When False [default]: the __all__ attribute is ignored
582 When False [default]: the __all__ attribute is ignored
583 """
583 """,
584 )
584 ).tag(config=True)
585
585
586 def __init__(self, shell=None, namespace=None, global_namespace=None,
586 def __init__(self, shell=None, namespace=None, global_namespace=None,
587 use_readline=True, config=None, **kwargs):
587 use_readline=True, config=None, **kwargs):
@@ -1101,7 +1101,7 class IPCompleter(Completer):
1101 # allow combining chars
1101 # allow combining chars
1102 if ('a'+unic).isidentifier():
1102 if ('a'+unic).isidentifier():
1103 return '\\'+s,[unic]
1103 return '\\'+s,[unic]
1104 except KeyError as e:
1104 except KeyError:
1105 pass
1105 pass
1106 return u'', []
1106 return u'', []
1107
1107
@@ -26,6 +26,7 from IPython.lib import pretty
26 from traitlets import (
26 from traitlets import (
27 Bool, Dict, Integer, Unicode, CUnicode, ObjectName, List,
27 Bool, Dict, Integer, Unicode, CUnicode, ObjectName, List,
28 ForwardDeclaredInstance,
28 ForwardDeclaredInstance,
29 default, observe,
29 )
30 )
30 from IPython.utils.py3compat import (
31 from IPython.utils.py3compat import (
31 with_metaclass, string_types, unicode_type,
32 with_metaclass, string_types, unicode_type,
@@ -49,29 +50,34 class DisplayFormatter(Configurable):
49 else:
50 else:
50 self.active_types = self.format_types
51 self.active_types = self.format_types
51
52
52 active_types = List(Unicode()).tag(config=True,
53 active_types = List(Unicode(),
53 help="""List of currently active mime-types to display.
54 help="""List of currently active mime-types to display.
54 You can use this to set a white-list for formats to display.
55 You can use this to set a white-list for formats to display.
55
56
56 Most users will not need to change this value.
57 Most users will not need to change this value.
57 """)
58 """).tag(config=True)
59
60 @default('active_types')
58 def _active_types_default(self):
61 def _active_types_default(self):
59 return self.format_types
62 return self.format_types
60
63
61 def _active_types_changed(self, name, old, new):
64 @observe('active_types')
65 def _active_types_changed(self, change):
62 for key, formatter in self.formatters.items():
66 for key, formatter in self.formatters.items():
63 if key in new:
67 if key in change['new']:
64 formatter.enabled = True
68 formatter.enabled = True
65 else:
69 else:
66 formatter.enabled = False
70 formatter.enabled = False
67
71
68 ipython_display_formatter = ForwardDeclaredInstance('FormatterABC')
72 ipython_display_formatter = ForwardDeclaredInstance('FormatterABC')
69 def _ipython_display_formatter_default(self):
73 @default('ipython_display_formatter')
74 def _default_formatter(self):
70 return IPythonDisplayFormatter(parent=self)
75 return IPythonDisplayFormatter(parent=self)
71
76
72 # A dict of formatter whose keys are format types (MIME types) and whose
77 # A dict of formatter whose keys are format types (MIME types) and whose
73 # values are subclasses of BaseFormatter.
78 # values are subclasses of BaseFormatter.
74 formatters = Dict()
79 formatters = Dict()
80 @default('formatters')
75 def _formatters_default(self):
81 def _formatters_default(self):
76 """Activate the default formatters."""
82 """Activate the default formatters."""
77 formatter_classes = [
83 formatter_classes = [
@@ -570,12 +576,12 class PlainTextFormatter(BaseFormatter):
570 # something.
576 # something.
571 enabled = Bool(True).tag(config=False)
577 enabled = Bool(True).tag(config=False)
572
578
573 max_seq_length = Integer(pretty.MAX_SEQ_LENGTH).tag(config=True,
579 max_seq_length = Integer(pretty.MAX_SEQ_LENGTH,
574 help="""Truncate large collections (lists, dicts, tuples, sets) to this size.
580 help="""Truncate large collections (lists, dicts, tuples, sets) to this size.
575
581
576 Set to 0 to disable truncation.
582 Set to 0 to disable truncation.
577 """
583 """
578 )
584 ).tag(config=True)
579
585
580 # Look for a _repr_pretty_ methods to use for pretty printing.
586 # Look for a _repr_pretty_ methods to use for pretty printing.
581 print_method = ObjectName('_repr_pretty_')
587 print_method = ObjectName('_repr_pretty_')
@@ -643,14 +649,17 class PlainTextFormatter(BaseFormatter):
643 self.float_format = fmt
649 self.float_format = fmt
644
650
645 # Use the default pretty printers from IPython.lib.pretty.
651 # Use the default pretty printers from IPython.lib.pretty.
652 @default('singleton_printers')
646 def _singleton_printers_default(self):
653 def _singleton_printers_default(self):
647 return pretty._singleton_pprinters.copy()
654 return pretty._singleton_pprinters.copy()
648
655
656 @default('type_printers')
649 def _type_printers_default(self):
657 def _type_printers_default(self):
650 d = pretty._type_pprinters.copy()
658 d = pretty._type_pprinters.copy()
651 d[float] = lambda obj,p,cycle: p.text(self.float_format%obj)
659 d[float] = lambda obj,p,cycle: p.text(self.float_format%obj)
652 return d
660 return d
653
661
662 @default('deferred_printers')
654 def _deferred_printers_default(self):
663 def _deferred_printers_default(self):
655 return pretty._deferred_type_pprinters.copy()
664 return pretty._deferred_type_pprinters.copy()
656
665
@@ -25,6 +25,7 from IPython.utils.path import locate_profile
25 from IPython.utils import py3compat
25 from IPython.utils import py3compat
26 from traitlets import (
26 from traitlets import (
27 Any, Bool, Dict, Instance, Integer, List, Unicode, TraitError,
27 Any, Bool, Dict, Instance, Integer, List, Unicode, TraitError,
28 default, observe,
28 )
29 )
29 from warnings import warn
30 from warnings import warn
30
31
@@ -148,7 +149,7 class HistoryAccessor(HistoryAccessorBase):
148 _corrupt_db_limit = 2
149 _corrupt_db_limit = 2
149
150
150 # String holding the path to the history file
151 # String holding the path to the history file
151 hist_file = Unicode(config=True,
152 hist_file = Unicode(
152 help="""Path to file to use for SQLite history database.
153 help="""Path to file to use for SQLite history database.
153
154
154 By default, IPython will put the history database in the IPython
155 By default, IPython will put the history database in the IPython
@@ -161,9 +162,9 class HistoryAccessor(HistoryAccessorBase):
161
162
162 ipython --HistoryManager.hist_file=/tmp/ipython_hist.sqlite
163 ipython --HistoryManager.hist_file=/tmp/ipython_hist.sqlite
163
164
164 """)
165 """).tag(config=True)
165
166
166 enabled = Bool(True, config=True,
167 enabled = Bool(True,
167 help="""enable the SQLite history
168 help="""enable the SQLite history
168
169
169 set enabled=False to disable the SQLite history,
170 set enabled=False to disable the SQLite history,
@@ -171,20 +172,22 class HistoryAccessor(HistoryAccessorBase):
171 and no background saving thread. This may be necessary in some
172 and no background saving thread. This may be necessary in some
172 threaded environments where IPython is embedded.
173 threaded environments where IPython is embedded.
173 """
174 """
174 )
175 ).tag(config=True)
175
176
176 connection_options = Dict(config=True,
177 connection_options = Dict(
177 help="""Options for configuring the SQLite connection
178 help="""Options for configuring the SQLite connection
178
179
179 These options are passed as keyword args to sqlite3.connect
180 These options are passed as keyword args to sqlite3.connect
180 when establishing database conenctions.
181 when establishing database conenctions.
181 """
182 """
182 )
183 ).tag(config=True)
183
184
184 # The SQLite database
185 # The SQLite database
185 db = Any()
186 db = Any()
186 def _db_changed(self, name, old, new):
187 @observe('db')
188 def _db_changed(self, change):
187 """validate the db, since it can be an Instance of two different types"""
189 """validate the db, since it can be an Instance of two different types"""
190 new = change['new']
188 connection_types = (DummyDB,)
191 connection_types = (DummyDB,)
189 if sqlite3 is not None:
192 if sqlite3 is not None:
190 connection_types = (DummyDB, sqlite3.Connection)
193 connection_types = (DummyDB, sqlite3.Connection)
@@ -479,6 +482,7 class HistoryManager(HistoryAccessor):
479 input_hist_raw = List([""])
482 input_hist_raw = List([""])
480 # A list of directories visited during session
483 # A list of directories visited during session
481 dir_hist = List()
484 dir_hist = List()
485 @default('dir_hist')
482 def _dir_hist_default(self):
486 def _dir_hist_default(self):
483 try:
487 try:
484 return [py3compat.getcwd()]
488 return [py3compat.getcwd()]
@@ -494,13 +498,13 class HistoryManager(HistoryAccessor):
494 # The number of the current session in the history database
498 # The number of the current session in the history database
495 session_number = Integer()
499 session_number = Integer()
496
500
497 db_log_output = Bool(False, config=True,
501 db_log_output = Bool(False,
498 help="Should the history database include output? (default: no)"
502 help="Should the history database include output? (default: no)"
499 )
503 ).tag(config=True)
500 db_cache_size = Integer(0, config=True,
504 db_cache_size = Integer(0,
501 help="Write to database every x commands (higher values save disk access & power).\n"
505 help="Write to database every x commands (higher values save disk access & power).\n"
502 "Values of 1 or less effectively disable caching."
506 "Values of 1 or less effectively disable caching."
503 )
507 ).tag(config=True)
504 # The input and output caches
508 # The input and output caches
505 db_input_cache = List()
509 db_input_cache = List()
506 db_output_cache = List()
510 db_output_cache = List()
@@ -49,7 +49,7 from IPython.core.error import InputRejected, UsageError
49 from IPython.core.extensions import ExtensionManager
49 from IPython.core.extensions import ExtensionManager
50 from IPython.core.formatters import DisplayFormatter
50 from IPython.core.formatters import DisplayFormatter
51 from IPython.core.history import HistoryManager
51 from IPython.core.history import HistoryManager
52 from IPython.core.inputsplitter import IPythonInputSplitter, ESC_MAGIC, ESC_MAGIC2
52 from IPython.core.inputsplitter import ESC_MAGIC, ESC_MAGIC2
53 from IPython.core.logger import Logger
53 from IPython.core.logger import Logger
54 from IPython.core.macro import Macro
54 from IPython.core.macro import Macro
55 from IPython.core.payload import PayloadManager
55 from IPython.core.payload import PayloadManager
@@ -75,8 +75,10 from IPython.utils.strdispatch import StrDispatch
75 from IPython.utils.syspathcontext import prepended_to_syspath
75 from IPython.utils.syspathcontext import prepended_to_syspath
76 from IPython.utils.text import (format_screen, LSString, SList,
76 from IPython.utils.text import (format_screen, LSString, SList,
77 DollarFormatter)
77 DollarFormatter)
78 from traitlets import (Integer, Bool, CBool, CaselessStrEnum, Enum,
78 from traitlets import (
79 List, Dict, Unicode, Instance, Type)
79 Integer, Bool, CaselessStrEnum, Enum, List, Dict, Unicode, Instance, Type,
80 observe, default,
81 )
80 from warnings import warn
82 from warnings import warn
81 from logging import error
83 from logging import error
82 import IPython.core.hooks
84 import IPython.core.hooks
@@ -114,9 +116,6 def no_op(*a, **kw): pass
114
116
115 class SpaceInInput(Exception): pass
117 class SpaceInInput(Exception): pass
116
118
117 @undoc
118 class Bunch: pass
119
120
119
121 def get_default_colors():
120 def get_default_colors():
122 if sys.platform=='darwin':
121 if sys.platform=='darwin':
@@ -173,14 +172,14 class InteractiveShell(SingletonConfigurable):
173
172
174 _instance = None
173 _instance = None
175
174
176 ast_transformers = List([], config=True, help=
175 ast_transformers = List([], help=
177 """
176 """
178 A list of ast.NodeTransformer subclass instances, which will be applied
177 A list of ast.NodeTransformer subclass instances, which will be applied
179 to user input before code is run.
178 to user input before code is run.
180 """
179 """
181 )
180 ).tag(config=True)
182
181
183 autocall = Enum((0,1,2), default_value=0, config=True, help=
182 autocall = Enum((0,1,2), default_value=0, help=
184 """
183 """
185 Make IPython automatically call any callable object even if you didn't
184 Make IPython automatically call any callable object even if you didn't
186 type explicit parentheses. For example, 'str 43' becomes 'str(43)'
185 type explicit parentheses. For example, 'str 43' becomes 'str(43)'
@@ -189,28 +188,28 class InteractiveShell(SingletonConfigurable):
189 arguments on the line, and '2' for 'full' autocall, where all callable
188 arguments on the line, and '2' for 'full' autocall, where all callable
190 objects are automatically called (even if no arguments are present).
189 objects are automatically called (even if no arguments are present).
191 """
190 """
192 )
191 ).tag(config=True)
193 # TODO: remove all autoindent logic and put into frontends.
192 # TODO: remove all autoindent logic and put into frontends.
194 # We can't do this yet because even runlines uses the autoindent.
193 # We can't do this yet because even runlines uses the autoindent.
195 autoindent = CBool(True, config=True, help=
194 autoindent = Bool(True, help=
196 """
195 """
197 Autoindent IPython code entered interactively.
196 Autoindent IPython code entered interactively.
198 """
197 """
199 )
198 ).tag(config=True)
200 automagic = CBool(True, config=True, help=
199 automagic = Bool(True, help=
201 """
200 """
202 Enable magic commands to be called without the leading %.
201 Enable magic commands to be called without the leading %.
203 """
202 """
204 )
203 ).tag(config=True)
205
204
206 banner1 = Unicode(default_banner, config=True,
205 banner1 = Unicode(default_banner,
207 help="""The part of the banner to be printed before the profile"""
206 help="""The part of the banner to be printed before the profile"""
208 )
207 ).tag(config=True)
209 banner2 = Unicode('', config=True,
208 banner2 = Unicode('',
210 help="""The part of the banner to be printed after the profile"""
209 help="""The part of the banner to be printed after the profile"""
211 )
210 ).tag(config=True)
212
211
213 cache_size = Integer(1000, config=True, help=
212 cache_size = Integer(1000, help=
214 """
213 """
215 Set the size of the output cache. The default is 1000, you can
214 Set the size of the output cache. The default is 1000, you can
216 change it permanently in your config file. Setting it to 0 completely
215 change it permanently in your config file. Setting it to 0 completely
@@ -219,19 +218,19 class InteractiveShell(SingletonConfigurable):
219 issued). This limit is defined because otherwise you'll spend more
218 issued). This limit is defined because otherwise you'll spend more
220 time re-flushing a too small cache than working
219 time re-flushing a too small cache than working
221 """
220 """
222 )
221 ).tag(config=True)
223 color_info = CBool(True, config=True, help=
222 color_info = Bool(True, help=
224 """
223 """
225 Use colors for displaying information about objects. Because this
224 Use colors for displaying information about objects. Because this
226 information is passed through a pager (like 'less'), and some pagers
225 information is passed through a pager (like 'less'), and some pagers
227 get confused with color codes, this capability can be turned off.
226 get confused with color codes, this capability can be turned off.
228 """
227 """
229 )
228 ).tag(config=True)
230 colors = CaselessStrEnum(('NoColor','LightBG','Linux'),
229 colors = CaselessStrEnum(('NoColor','LightBG','Linux'),
231 default_value=get_default_colors(), config=True,
230 default_value=get_default_colors(),
232 help="Set the color scheme (NoColor, Linux, or LightBG)."
231 help="Set the color scheme (NoColor, Linux, or LightBG)."
233 )
232 ).tag(config=True)
234 colors_force = CBool(False, help=
233 colors_force = Bool(False, help=
235 """
234 """
236 Force use of ANSI color codes, regardless of OS and readline
235 Force use of ANSI color codes, regardless of OS and readline
237 availability.
236 availability.
@@ -240,8 +239,8 class InteractiveShell(SingletonConfigurable):
240 # without readline on Win32. When the ZMQ formatting system is
239 # without readline on Win32. When the ZMQ formatting system is
241 # refactored, this should be removed.
240 # refactored, this should be removed.
242 )
241 )
243 debug = CBool(False, config=True)
242 debug = Bool(False).tag(config=True)
244 deep_reload = CBool(False, config=True, help=
243 deep_reload = Bool(False, help=
245 """
244 """
246 **Deprecated**
245 **Deprecated**
247
246
@@ -255,23 +254,24 class InteractiveShell(SingletonConfigurable):
255 deep_reload is off, IPython will use the normal reload(), but
254 deep_reload is off, IPython will use the normal reload(), but
256 deep_reload will still be available as dreload().
255 deep_reload will still be available as dreload().
257 """
256 """
258 )
257 ).tag(config=True)
259 disable_failing_post_execute = CBool(False, config=True,
258 disable_failing_post_execute = Bool(False,
260 help="Don't call post-execute functions that have failed in the past."
259 help="Don't call post-execute functions that have failed in the past."
261 )
260 ).tag(config=True)
262 display_formatter = Instance(DisplayFormatter, allow_none=True)
261 display_formatter = Instance(DisplayFormatter, allow_none=True)
263 displayhook_class = Type(DisplayHook)
262 displayhook_class = Type(DisplayHook)
264 display_pub_class = Type(DisplayPublisher)
263 display_pub_class = Type(DisplayPublisher)
265 data_pub_class = None
264 data_pub_class = None
266
265
267 exit_now = CBool(False)
266 exit_now = Bool(False)
268 exiter = Instance(ExitAutocall)
267 exiter = Instance(ExitAutocall)
268 @default('exiter')
269 def _exiter_default(self):
269 def _exiter_default(self):
270 return ExitAutocall(self)
270 return ExitAutocall(self)
271 # Monotonically increasing execution counter
271 # Monotonically increasing execution counter
272 execution_count = Integer(1)
272 execution_count = Integer(1)
273 filename = Unicode("<ipython console>")
273 filename = Unicode("<ipython console>")
274 ipython_dir= Unicode('', config=True) # Set to get_ipython_dir() in __init__
274 ipython_dir= Unicode('').tag(config=True) # Set to get_ipython_dir() in __init__
275
275
276 # Input splitter, to transform input line by line and detect when a block
276 # Input splitter, to transform input line by line and detect when a block
277 # is ready to be executed.
277 # is ready to be executed.
@@ -283,88 +283,91 class InteractiveShell(SingletonConfigurable):
283 input_transformer_manager = Instance('IPython.core.inputsplitter.IPythonInputSplitter',
283 input_transformer_manager = Instance('IPython.core.inputsplitter.IPythonInputSplitter',
284 (), {'line_input_checker': False})
284 (), {'line_input_checker': False})
285
285
286 logstart = CBool(False, config=True, help=
286 logstart = Bool(False, help=
287 """
287 """
288 Start logging to the default log file in overwrite mode.
288 Start logging to the default log file in overwrite mode.
289 Use `logappend` to specify a log file to **append** logs to.
289 Use `logappend` to specify a log file to **append** logs to.
290 """
290 """
291