##// END OF EJS Templates
adopt traitlets 4.2 API...
Min RK -
Show More
@@ -192,8 +192,8 b' class Alias(object):'
192 192
193 193 class AliasManager(Configurable):
194 194
195 default_aliases = List(default_aliases(), config=True)
196 user_aliases = List(default_value=[], config=True)
195 default_aliases = List(default_aliases()).tag(config=True)
196 user_aliases = List(default_value=[]).tag(config=True)
197 197 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True)
198 198
199 199 def __init__(self, shell=None, **kwargs):
@@ -26,7 +26,10 b' from IPython.core.profiledir import ProfileDir, ProfileDirError'
26 26 from IPython.paths import get_ipython_dir, get_ipython_package_dir
27 27 from IPython.utils.path import ensure_dir_exists
28 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 34 if os.name == 'nt':
32 35 programdata = os.environ.get('PROGRAMDATA', None)
@@ -96,11 +99,13 b' class BaseIPythonApplication(Application):'
96 99 config_file_specified = Set()
97 100
98 101 config_file_name = Unicode()
102 @default('config_file_name')
99 103 def _config_file_name_default(self):
100 104 return self.name.replace('-','_') + u'_config.py'
101 def _config_file_name_changed(self, name, old, new):
102 if new != old:
103 self.config_file_specified.add(new)
105 @observe('config_file_name')
106 def _config_file_name_changed(self, change):
107 if change['new'] != change['old']:
108 self.config_file_specified.add(change['new'])
104 109
105 110 # The directory that contains IPython's builtin profiles.
106 111 builtin_profile_dir = Unicode(
@@ -108,15 +113,19 b' class BaseIPythonApplication(Application):'
108 113 )
109 114
110 115 config_file_paths = List(Unicode())
116 @default('config_file_paths')
111 117 def _config_file_paths_default(self):
112 118 return [py3compat.getcwd()]
113 119
114 extra_config_file = Unicode(config=True,
120 extra_config_file = Unicode(
115 121 help="""Path to an extra config file to load.
116 122
117 123 If specified, load this config file in addition to any other IPython config.
118 """)
119 def _extra_config_file_changed(self, name, old, new):
124 """).tag(config=True)
125 @observe('extra_config_file')
126 def _extra_config_file_changed(self, change):
127 old = change['old']
128 new = change['new']
120 129 try:
121 130 self.config_files.remove(old)
122 131 except ValueError:
@@ -124,30 +133,37 b' class BaseIPythonApplication(Application):'
124 133 self.config_file_specified.add(new)
125 134 self.config_files.append(new)
126 135
127 profile = Unicode(u'default', config=True,
136 profile = Unicode(u'default',
128 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 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 147 help="""
138 148 The name of the IPython directory. This directory is used for logging
139 149 configuration (through profiles), history storage, etc. The default
140 150 is usually $HOME/.ipython. This option can also be specified through
141 151 the environment variable IPYTHONDIR.
142 152 """
143 )
153 ).tag(config=True)
154 @default('ipython_dir')
144 155 def _ipython_dir_default(self):
145 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 162 return d
148 163
149 164 _in_init_profile_dir = False
150 165 profile_dir = Instance(ProfileDir, allow_none=True)
166 @default('profile_dir')
151 167 def _profile_dir_default(self):
152 168 # avoid recursion
153 169 if self._in_init_profile_dir:
@@ -156,26 +172,29 b' class BaseIPythonApplication(Application):'
156 172 self.init_profile_dir()
157 173 return self.profile_dir
158 174
159 overwrite = Bool(False, config=True,
160 help="""Whether to overwrite existing config files when copying""")
161 auto_create = Bool(False, config=True,
162 help="""Whether to create profile dir if it doesn't exist""")
175 overwrite = Bool(False,
176 help="""Whether to overwrite existing config files when copying"""
177 ).tag(config=True)
178 auto_create = Bool(False,
179 help="""Whether to create profile dir if it doesn't exist"""
180 ).tag(config=True)
163 181
164 182 config_files = List(Unicode())
183 @default('config_files')
165 184 def _config_files_default(self):
166 185 return [self.config_file_name]
167 186
168 copy_config_files = Bool(False, config=True,
187 copy_config_files = Bool(False,
169 188 help="""Whether to install the default config files into the profile dir.
170 189 If a new profile is being created, and IPython contains config files for that
171 190 profile, then they will be staged into the new directory. Otherwise,
172 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 195 help="""Create a massive crash report when IPython encounters what may be an
177 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 199 # The class to use as the crash handler.
181 200 crash_handler_class = Type(crashhandler.CrashHandler)
@@ -199,7 +218,6 b' class BaseIPythonApplication(Application):'
199 218
200 219 def initialize_subcommand(self, subc, argv=None):
201 220 if subc in self.deprecated_subcommands:
202 import time
203 221 self.log.warning("Subcommand `ipython {sub}` is deprecated and will be removed "
204 222 "in future versions.".format(sub=subc))
205 223 self.log.warning("You likely want to use `jupyter {sub}` in the "
@@ -226,7 +244,10 b' class BaseIPythonApplication(Application):'
226 244 else:
227 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 251 if old is not Undefined:
231 252 str_old = py3compat.cast_bytes_py2(os.path.abspath(old),
232 253 sys.getfilesystemencoding()
@@ -75,7 +75,7 b' from IPython.utils.decorators import undoc'
75 75 from IPython.utils.dir2 import dir2, get_real_method
76 76 from IPython.utils.process import arg_split
77 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 80 import jedi
81 81 import jedi.api.helpers
@@ -174,7 +174,6 b' def compress_user(path, tilde_expand, tilde_val):'
174 174 return path
175 175
176 176
177
178 177 def completions_sorting_key(word):
179 178 """key for sorting completions
180 179
@@ -273,14 +272,14 b' class CompletionSplitter(object):'
273 272
274 273 class Completer(Configurable):
275 274
276 greedy = CBool(False, config=True,
275 greedy = Bool(False,
277 276 help="""Activate greedy completion
278 277 PENDING DEPRECTION. this is now mostly taken care of with Jedi.
279 278
280 279 This will enable completion on elements of lists, results of function calls, etc.,
281 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 285 def __init__(self, namespace=None, global_namespace=None, **kwargs):
@@ -505,7 +504,7 b' def back_unicode_name_matches(text):'
505 504 try :
506 505 unic = unicodedata.name(char)
507 506 return '\\'+char,['\\'+unic]
508 except KeyError as e:
507 except KeyError:
509 508 pass
510 509 return u'', ()
511 510
@@ -532,7 +531,7 b' def back_latex_name_matches(text):'
532 531 latex = reverse_latex_symbol[char]
533 532 # '\\' replace the \ as well
534 533 return '\\'+char,[latex]
535 except KeyError as e:
534 except KeyError:
536 535 pass
537 536 return u'', ()
538 537
@@ -540,9 +539,10 b' def back_latex_name_matches(text):'
540 539 class IPCompleter(Completer):
541 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 544 """update the splitter and readline delims when greedy is changed"""
545 if new:
545 if change['new']:
546 546 self.splitter.delims = GREEDY_DELIMS
547 547 else:
548 548 self.splitter.delims = DELIMS
@@ -550,14 +550,14 b' class IPCompleter(Completer):'
550 550 if self.readline:
551 551 self.readline.set_completer_delims(self.splitter.delims)
552 552
553 merge_completions = CBool(True, config=True,
553 merge_completions = Bool(True,
554 554 help="""Whether to merge completion results into a single list
555 555
556 556 If False, only the completion results from the first non-empty
557 557 completer will be returned.
558 558 """
559 )
560 omit__names = Enum((0,1,2), default_value=2, config=True,
559 ).tag(config=True)
560 omit__names = Enum((0,1,2), default_value=2,
561 561 help="""Instruct the completer to omit private method names
562 562
563 563 Specifically, when completing on ``object.<tab>``.
@@ -568,8 +568,8 b' class IPCompleter(Completer):'
568 568
569 569 When 0: nothing will be excluded.
570 570 """
571 )
572 limit_to__all__ = CBool(default_value=False, config=True,
571 ).tag(config=True)
572 limit_to__all__ = Bool(False,
573 573 help="""
574 574 DEPRECATED as of version 5.0.
575 575
@@ -580,8 +580,8 b' class IPCompleter(Completer):'
580 580 When True: only those names in obj.__all__ will be included.
581 581
582 582 When False [default]: the __all__ attribute is ignored
583 """
584 )
583 """,
584 ).tag(config=True)
585 585
586 586 def __init__(self, shell=None, namespace=None, global_namespace=None,
587 587 use_readline=True, config=None, **kwargs):
@@ -1101,7 +1101,7 b' class IPCompleter(Completer):'
1101 1101 # allow combining chars
1102 1102 if ('a'+unic).isidentifier():
1103 1103 return '\\'+s,[unic]
1104 except KeyError as e:
1104 except KeyError:
1105 1105 pass
1106 1106 return u'', []
1107 1107
@@ -26,6 +26,7 b' from IPython.lib import pretty'
26 26 from traitlets import (
27 27 Bool, Dict, Integer, Unicode, CUnicode, ObjectName, List,
28 28 ForwardDeclaredInstance,
29 default, observe,
29 30 )
30 31 from IPython.utils.py3compat import (
31 32 with_metaclass, string_types, unicode_type,
@@ -49,29 +50,34 b' class DisplayFormatter(Configurable):'
49 50 else:
50 51 self.active_types = self.format_types
51 52
52 active_types = List(Unicode()).tag(config=True,
53 active_types = List(Unicode(),
53 54 help="""List of currently active mime-types to display.
54 55 You can use this to set a white-list for formats to display.
55 56
56 57 Most users will not need to change this value.
57 """)
58 """).tag(config=True)
59
60 @default('active_types')
58 61 def _active_types_default(self):
59 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 66 for key, formatter in self.formatters.items():
63 if key in new:
67 if key in change['new']:
64 68 formatter.enabled = True
65 69 else:
66 70 formatter.enabled = False
67 71
68 72 ipython_display_formatter = ForwardDeclaredInstance('FormatterABC')
69 def _ipython_display_formatter_default(self):
73 @default('ipython_display_formatter')
74 def _default_formatter(self):
70 75 return IPythonDisplayFormatter(parent=self)
71 76
72 77 # A dict of formatter whose keys are format types (MIME types) and whose
73 78 # values are subclasses of BaseFormatter.
74 79 formatters = Dict()
80 @default('formatters')
75 81 def _formatters_default(self):
76 82 """Activate the default formatters."""
77 83 formatter_classes = [
@@ -570,12 +576,12 b' class PlainTextFormatter(BaseFormatter):'
570 576 # something.
571 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 580 help="""Truncate large collections (lists, dicts, tuples, sets) to this size.
575 581
576 582 Set to 0 to disable truncation.
577 583 """
578 )
584 ).tag(config=True)
579 585
580 586 # Look for a _repr_pretty_ methods to use for pretty printing.
581 587 print_method = ObjectName('_repr_pretty_')
@@ -643,14 +649,17 b' class PlainTextFormatter(BaseFormatter):'
643 649 self.float_format = fmt
644 650
645 651 # Use the default pretty printers from IPython.lib.pretty.
652 @default('singleton_printers')
646 653 def _singleton_printers_default(self):
647 654 return pretty._singleton_pprinters.copy()
648 655
656 @default('type_printers')
649 657 def _type_printers_default(self):
650 658 d = pretty._type_pprinters.copy()
651 659 d[float] = lambda obj,p,cycle: p.text(self.float_format%obj)
652 660 return d
653 661
662 @default('deferred_printers')
654 663 def _deferred_printers_default(self):
655 664 return pretty._deferred_type_pprinters.copy()
656 665
@@ -25,6 +25,7 b' from IPython.utils.path import locate_profile'
25 25 from IPython.utils import py3compat
26 26 from traitlets import (
27 27 Any, Bool, Dict, Instance, Integer, List, Unicode, TraitError,
28 default, observe,
28 29 )
29 30 from warnings import warn
30 31
@@ -148,7 +149,7 b' class HistoryAccessor(HistoryAccessorBase):'
148 149 _corrupt_db_limit = 2
149 150
150 151 # String holding the path to the history file
151 hist_file = Unicode(config=True,
152 hist_file = Unicode(
152 153 help="""Path to file to use for SQLite history database.
153 154
154 155 By default, IPython will put the history database in the IPython
@@ -161,9 +162,9 b' class HistoryAccessor(HistoryAccessorBase):'
161 162
162 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 168 help="""enable the SQLite history
168 169
169 170 set enabled=False to disable the SQLite history,
@@ -171,20 +172,22 b' class HistoryAccessor(HistoryAccessorBase):'
171 172 and no background saving thread. This may be necessary in some
172 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 178 help="""Options for configuring the SQLite connection
178 179
179 180 These options are passed as keyword args to sqlite3.connect
180 181 when establishing database conenctions.
181 182 """
182 )
183 ).tag(config=True)
183 184
184 185 # The SQLite database
185 186 db = Any()
186 def _db_changed(self, name, old, new):
187 @observe('db')
188 def _db_changed(self, change):
187 189 """validate the db, since it can be an Instance of two different types"""
190 new = change['new']
188 191 connection_types = (DummyDB,)
189 192 if sqlite3 is not None:
190 193 connection_types = (DummyDB, sqlite3.Connection)
@@ -479,6 +482,7 b' class HistoryManager(HistoryAccessor):'
479 482 input_hist_raw = List([""])
480 483 # A list of directories visited during session
481 484 dir_hist = List()
485 @default('dir_hist')
482 486 def _dir_hist_default(self):
483 487 try:
484 488 return [py3compat.getcwd()]
@@ -494,13 +498,13 b' class HistoryManager(HistoryAccessor):'
494 498 # The number of the current session in the history database
495 499 session_number = Integer()
496 500
497 db_log_output = Bool(False, config=True,
501 db_log_output = Bool(False,
498 502 help="Should the history database include output? (default: no)"
499 )
500 db_cache_size = Integer(0, config=True,
503 ).tag(config=True)
504 db_cache_size = Integer(0,
501 505 help="Write to database every x commands (higher values save disk access & power).\n"
502 506 "Values of 1 or less effectively disable caching."
503 )
507 ).tag(config=True)
504 508 # The input and output caches
505 509 db_input_cache = List()
506 510 db_output_cache = List()
@@ -49,7 +49,7 b' from IPython.core.error import InputRejected, UsageError'
49 49 from IPython.core.extensions import ExtensionManager
50 50 from IPython.core.formatters import DisplayFormatter
51 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 53 from IPython.core.logger import Logger
54 54 from IPython.core.macro import Macro
55 55 from IPython.core.payload import PayloadManager
@@ -75,8 +75,10 b' from IPython.utils.strdispatch import StrDispatch'
75 75 from IPython.utils.syspathcontext import prepended_to_syspath
76 76 from IPython.utils.text import (format_screen, LSString, SList,
77 77 DollarFormatter)
78 from traitlets import (Integer, Bool, CBool, CaselessStrEnum, Enum,
79 List, Dict, Unicode, Instance, Type)
78 from traitlets import (
79 Integer, Bool, CaselessStrEnum, Enum, List, Dict, Unicode, Instance, Type,
80 observe, default,
81 )
80 82 from warnings import warn
81 83 from logging import error
82 84 import IPython.core.hooks
@@ -114,9 +116,6 b' def no_op(*a, **kw): pass'
114 116
115 117 class SpaceInInput(Exception): pass
116 118
117 @undoc
118 class Bunch: pass
119
120 119
121 120 def get_default_colors():
122 121 if sys.platform=='darwin':
@@ -173,14 +172,14 b' class InteractiveShell(SingletonConfigurable):'
173 172
174 173 _instance = None
175 174
176 ast_transformers = List([], config=True, help=
175 ast_transformers = List([], help=
177 176 """
178 177 A list of ast.NodeTransformer subclass instances, which will be applied
179 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 184 Make IPython automatically call any callable object even if you didn't
186 185 type explicit parentheses. For example, 'str 43' becomes 'str(43)'
@@ -189,28 +188,28 b' class InteractiveShell(SingletonConfigurable):'
189 188 arguments on the line, and '2' for 'full' autocall, where all callable
190 189 objects are automatically called (even if no arguments are present).
191 190 """
192 )
191 ).tag(config=True)
193 192 # TODO: remove all autoindent logic and put into frontends.
194 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 196 Autoindent IPython code entered interactively.
198 197 """
199 )
200 automagic = CBool(True, config=True, help=
198 ).tag(config=True)
199 automagic = Bool(True, help=
201 200 """
202 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 206 help="""The part of the banner to be printed before the profile"""
208 )
209 banner2 = Unicode('', config=True,
207 ).tag(config=True)
208 banner2 = Unicode('',
210 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 214 Set the size of the output cache. The default is 1000, you can
216 215 change it permanently in your config file. Setting it to 0 completely
@@ -219,19 +218,19 b' class InteractiveShell(SingletonConfigurable):'
219 218 issued). This limit is defined because otherwise you'll spend more
220 219 time re-flushing a too small cache than working
221 220 """
222 )
223 color_info = CBool(True, config=True, help=
221 ).tag(config=True)
222 color_info = Bool(True, help=
224 223 """
225 224 Use colors for displaying information about objects. Because this
226 225 information is passed through a pager (like 'less'), and some pagers
227 226 get confused with color codes, this capability can be turned off.
228 227 """
229 )
228 ).tag(config=True)
230 229 colors = CaselessStrEnum(('NoColor','LightBG','Linux'),
231 default_value=get_default_colors(), config=True,
230 default_value=get_default_colors(),
232 231 help="Set the color scheme (NoColor, Linux, or LightBG)."
233 )
234 colors_force = CBool(False, help=
232 ).tag(config=True)
233 colors_force = Bool(False, help=
235 234 """
236 235 Force use of ANSI color codes, regardless of OS and readline
237 236 availability.
@@ -240,8 +239,8 b' class InteractiveShell(SingletonConfigurable):'
240 239 # without readline on Win32. When the ZMQ formatting system is
241 240 # refactored, this should be removed.
242 241 )
243 debug = CBool(False, config=True)
244 deep_reload = CBool(False, config=True, help=
242 debug = Bool(False).tag(config=True)
243 deep_reload = Bool(False, help=
245 244 """
246 245 **Deprecated**
247 246
@@ -255,23 +254,24 b' class InteractiveShell(SingletonConfigurable):'
255 254 deep_reload is off, IPython will use the normal reload(), but
256 255 deep_reload will still be available as dreload().
257 256 """
258 )
259 disable_failing_post_execute = CBool(False, config=True,
257 ).tag(config=True)
258 disable_failing_post_execute = Bool(False,
260 259 help="Don't call post-execute functions that have failed in the past."
261 )
260 ).tag(config=True)
262 261 display_formatter = Instance(DisplayFormatter, allow_none=True)
263 262 displayhook_class = Type(DisplayHook)
264 263 display_pub_class = Type(DisplayPublisher)
265 264 data_pub_class = None
266 265
267 exit_now = CBool(False)
266 exit_now = Bool(False)
268 267 exiter = Instance(ExitAutocall)
268 @default('exiter')
269 269 def _exiter_default(self):
270 270 return ExitAutocall(self)
271 271 # Monotonically increasing execution counter
272 272 execution_count = Integer(1)
273 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 276 # Input splitter, to transform input line by line and detect when a block
277 277 # is ready to be executed.
@@ -283,88 +283,91 b' class InteractiveShell(SingletonConfigurable):'
283 283 input_transformer_manager = Instance('IPython.core.inputsplitter.IPythonInputSplitter',
284 284 (), {'line_input_checker': False})
285 285
286 logstart = CBool(False, config=True, help=
286 logstart = Bool(False, help=
287 287 """
288 288 Start logging to the default log file in overwrite mode.
289 289 Use `logappend` to specify a log file to **append** logs to.
290 290 """
291 )
292 logfile = Unicode('', config=True, help=
291 ).tag(config=True)
292 logfile = Unicode('', help=
293 293 """
294 294 The name of the logfile to use.
295 295 """
296 )
297 logappend = Unicode('', config=True, help=
296 ).tag(config=True)
297 logappend = Unicode('', help=
298 298 """
299 299 Start logging to the given file in append mode.
300 300 Use `logfile` to specify a log file to **overwrite** logs to.
301 301 """
302 )
302 ).tag(config=True)
303 303 object_info_string_level = Enum((0,1,2), default_value=0,
304 config=True)
305 pdb = CBool(False, config=True, help=
304 ).tag(config=True)
305 pdb = Bool(False, help=
306 306 """
307 307 Automatically call the pdb debugger after every exception.
308 308 """
309 )
310 multiline_history = CBool(sys.platform != 'win32', config=True,
309 ).tag(config=True)
310 multiline_history = Bool(sys.platform != 'win32',
311 311 help="Save multi-line entries as one entry in readline history"
312 )
313 display_page = Bool(False, config=True,
312 ).tag(config=True)
313 display_page = Bool(False,
314 314 help="""If True, anything that would be passed to the pager
315 315 will be displayed as regular output instead."""
316 )
316 ).tag(config=True)
317 317
318 318 # deprecated prompt traits:
319 319
320 prompt_in1 = Unicode('In [\\#]: ', config=True,
321 help="Deprecated, will be removed in IPython 5.0, use PromptManager.in_template")
322 prompt_in2 = Unicode(' .\\D.: ', config=True,
323 help="Deprecated, will be removed in IPython 5.0, use PromptManager.in2_template")
324 prompt_out = Unicode('Out[\\#]: ', config=True,
325 help="Deprecated, will be removed in IPython 5.0, use PromptManager.out_template")
326 prompts_pad_left = CBool(True, config=True,
327 help="Deprecated, will be removed in IPython 5.0, use PromptManager.justify")
328
329 def _prompt_trait_changed(self, name, old, new):
320 prompt_in1 = Unicode('In [\\#]: ',
321 help="Deprecated, will be removed in IPython 5.0, use PromptManager.in_template"
322 ).tag(config=True)
323 prompt_in2 = Unicode(' .\\D.: ',
324 help="Deprecated, will be removed in IPython 5.0, use PromptManager.in2_template"
325 ).tag(config=True)
326 prompt_out = Unicode('Out[\\#]: ',
327 help="Deprecated, will be removed in IPython 5.0, use PromptManager.out_template"
328 ).tag(config=True)
329 prompts_pad_left = Bool(True,
330 help="Deprecated, will be removed in IPython 5.0, use PromptManager.justify"
331 ).tag(config=True)
332
333 @observe('prompt_in1', 'prompt_in2', 'prompt_out', 'prompt_pad_left')
334 def _prompt_trait_changed(self, change):
330 335 table = {
331 336 'prompt_in1' : 'in_template',
332 337 'prompt_in2' : 'in2_template',
333 338 'prompt_out' : 'out_template',
334 339 'prompts_pad_left' : 'justify',
335 340 }
341 name = change['name']
336 342 warn("InteractiveShell.{name} is deprecated, use PromptManager.{newname}".format(
337 343 name=name, newname=table[name])
338 344 )
339 345 # protect against weird cases where self.config may not exist:
340 346 if self.config is not None:
341 347 # propagate to corresponding PromptManager trait
342 setattr(self.config.PromptManager, table[name], new)
343
344 _prompt_in1_changed = _prompt_trait_changed
345 _prompt_in2_changed = _prompt_trait_changed
346 _prompt_out_changed = _prompt_trait_changed
347 _prompt_pad_left_changed = _prompt_trait_changed
348 setattr(self.config.PromptManager, table[name], change['new'])
348 349
349 show_rewritten_input = CBool(True, config=True,
350 show_rewritten_input = Bool(True,
350 351 help="Show rewritten input, e.g. for autocall."
351 )
352 ).tag(config=True)
352 353
353 quiet = CBool(False, config=True)
354 quiet = Bool(False).tag(config=True)
354 355
355 history_length = Integer(10000, config=True)
356 history_length = Integer(10000,
357 help='Total length of command history'
358 ).tag(config=True)
356 359
357 history_load_length = Integer(1000, config=True, help=
360 history_load_length = Integer(1000, help=
358 361 """
359 362 The number of saved history entries to be loaded
360 363 into the readline buffer at startup.
361 364 """
362 )
365 ).tag(config=True)
363 366
364 367 # The readline stuff will eventually be moved to the terminal subclass
365 368 # but for now, we can't do that as readline is welded in everywhere.
366 readline_use = CBool(True, config=True)
367 readline_remove_delims = Unicode('-/~', config=True)
369 readline_use = Bool(True).tag(config=True)
370 readline_remove_delims = Unicode('-/~').tag(config=True)
368 371 readline_delims = Unicode() # set by init_readline()
369 372 # don't use \M- bindings by default, because they
370 373 # conflict with 8-bit encodings. See gh-58,gh-88
@@ -381,29 +384,31 b' class InteractiveShell(SingletonConfigurable):'
381 384 '"\e[B": history-search-forward',
382 385 '"\C-k": kill-line',
383 386 '"\C-u": unix-line-discard',
384 ], config=True)
387 ]).tag(config=True)
385 388
386 389 _custom_readline_config = False
387 390
388 def _readline_parse_and_bind_changed(self, name, old, new):
391 @observe('readline_parse_and_bind')
392 def _readline_parse_and_bind_changed(self, change):
389 393 # notice that readline config is customized
390 394 # indicates that it should have higher priority than inputrc
391 395 self._custom_readline_config = True
392 396
393 397 ast_node_interactivity = Enum(['all', 'last', 'last_expr', 'none'],
394 default_value='last_expr', config=True,
398 default_value='last_expr',
395 399 help="""
396 400 'all', 'last', 'last_expr' or 'none', specifying which nodes should be
397 run interactively (displaying output from expressions).""")
401 run interactively (displaying output from expressions)."""
402 ).tag(config=True)
398 403
399 404 # TODO: this part of prompt management should be moved to the frontends.
400 405 # Use custom TraitTypes that convert '0'->'' and '\\n'->'\n'
401 separate_in = SeparateUnicode('\n', config=True)
402 separate_out = SeparateUnicode('', config=True)
403 separate_out2 = SeparateUnicode('', config=True)
404 wildcards_case_sensitive = CBool(True, config=True)
406 separate_in = SeparateUnicode('\n').tag(config=True)
407 separate_out = SeparateUnicode('').tag(config=True)
408 separate_out2 = SeparateUnicode('').tag(config=True)
409 wildcards_case_sensitive = Bool(True).tag(config=True)
405 410 xmode = CaselessStrEnum(('Context','Plain', 'Verbose'),
406 default_value='Context', config=True)
411 default_value='Context').tag(config=True)
407 412
408 413 # Subcomponents of InteractiveShell
409 414 alias_manager = Instance('IPython.core.alias.AliasManager', allow_none=True)
@@ -522,9 +527,9 b' class InteractiveShell(SingletonConfigurable):'
522 527 #-------------------------------------------------------------------------
523 528 # Trait changed handlers
524 529 #-------------------------------------------------------------------------
525
526 def _ipython_dir_changed(self, name, new):
527 ensure_dir_exists(new)
530 @observe('ipython_dir')
531 def _ipython_dir_changed(self, change):
532 ensure_dir_exists(change['new'])
528 533
529 534 def set_autoindent(self,value=None):
530 535 """Set the autoindent flag.
@@ -785,7 +790,7 b' class InteractiveShell(SingletonConfigurable):'
785 790 def show_banner(self, banner=None):
786 791 if banner is None:
787 792 banner = self.banner
788 self.write(banner)
793 sys.stdout.write(banner)
789 794
790 795 #-------------------------------------------------------------------------
791 796 # Things related to hooks
@@ -12,17 +12,12 b' from __future__ import print_function'
12 12 # the file COPYING, distributed as part of this software.
13 13 #-----------------------------------------------------------------------------
14 14
15 #-----------------------------------------------------------------------------
16 # Imports
17 #-----------------------------------------------------------------------------
18 # Stdlib
19 15 import os
20 16 import re
21 17 import sys
22 18 import types
23 19 from getopt import getopt, GetoptError
24 20
25 # Our own
26 21 from traitlets.config.configurable import Configurable
27 22 from IPython.core import oinspect
28 23 from IPython.core.error import UsageError
@@ -32,7 +27,7 b' from IPython.utils.ipstruct import Struct'
32 27 from IPython.utils.process import arg_split
33 28 from IPython.utils.py3compat import string_types, iteritems
34 29 from IPython.utils.text import dedent
35 from traitlets import Bool, Dict, Instance
30 from traitlets import Bool, Dict, Instance, observe
36 31 from logging import error
37 32
38 33 #-----------------------------------------------------------------------------
@@ -303,11 +298,12 b' class MagicsManager(Configurable):'
303 298
304 299 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True)
305 300
306 auto_magic = Bool(True, config=True, help=
307 "Automatically call line magics without requiring explicit % prefix")
308
309 def _auto_magic_changed(self, name, value):
310 self.shell.automagic = value
301 auto_magic = Bool(True, help=
302 "Automatically call line magics without requiring explicit % prefix"
303 ).tag(config=True)
304 @observe('auto_magic')
305 def _auto_magic_changed(self, change):
306 self.shell.automagic = change['new']
311 307
312 308 _auto_status = [
313 309 'Automagic is OFF, % prefix IS needed for line magics.',
@@ -1,18 +1,9 b''
1 1 """Magic functions for running cells in various scripts."""
2 2 from __future__ import print_function
3 #-----------------------------------------------------------------------------
4 # Copyright (c) 2012 The IPython Development Team.
5 #
6 # Distributed under the terms of the Modified BSD License.
7 #
8 # The full license is in the file COPYING.txt, distributed with this software.
9 #-----------------------------------------------------------------------------
10 3
11 #-----------------------------------------------------------------------------
12 # Imports
13 #-----------------------------------------------------------------------------
4 # Copyright (c) IPython Development Team.
5 # Distributed under the terms of the Modified BSD License.
14 6
15 # Stdlib
16 7 import errno
17 8 import os
18 9 import sys
@@ -21,8 +12,6 b' import time'
21 12 from subprocess import Popen, PIPE
22 13 import atexit
23 14
24 # Our own packages
25 from traitlets.config.configurable import Configurable
26 15 from IPython.core import magic_arguments
27 16 from IPython.core.magic import (
28 17 Magics, magics_class, line_magic, cell_magic
@@ -30,7 +19,7 b' from IPython.core.magic import ('
30 19 from IPython.lib.backgroundjobs import BackgroundJobManager
31 20 from IPython.utils import py3compat
32 21 from IPython.utils.process import arg_split
33 from traitlets import List, Dict
22 from traitlets import List, Dict, default
34 23
35 24 #-----------------------------------------------------------------------------
36 25 # Magic implementation classes
@@ -79,7 +68,7 b' class ScriptMagics(Magics):'
79 68 with a program in a subprocess, and registers a few top-level
80 69 magics that call %%script with common interpreters.
81 70 """
82 script_magics = List(config=True,
71 script_magics = List(
83 72 help="""Extra script cell magics to define
84 73
85 74 This generates simple wrappers of `%%script foo` as `%%foo`.
@@ -87,7 +76,8 b' class ScriptMagics(Magics):'
87 76 If you want to add script magics that aren't on your path,
88 77 specify them in script_paths
89 78 """,
90 )
79 ).tag(config=True)
80 @default('script_magics')
91 81 def _script_magics_default(self):
92 82 """default to a common list of programs"""
93 83
@@ -108,13 +98,13 b' class ScriptMagics(Magics):'
108 98
109 99 return defaults
110 100
111 script_paths = Dict(config=True,
101 script_paths = Dict(
112 102 help="""Dict mapping short 'ruby' names to full paths, such as '/opt/secret/bin/ruby'
113 103
114 104 Only necessary for items in script_magics where the default path will not
115 105 find the right interpreter.
116 106 """
117 )
107 ).tag(config=True)
118 108
119 109 def __init__(self, shell=None):
120 110 super(ScriptMagics, self).__init__(shell=shell)
@@ -4,25 +4,10 b' Prefiltering components.'
4 4
5 5 Prefilters transform user input before it is exec'd by Python. These
6 6 transforms are used to implement additional syntax such as !ls and %magic.
7
8 Authors:
9
10 * Brian Granger
11 * Fernando Perez
12 * Dan Milstein
13 * Ville Vainio
14 7 """
15 8
16 #-----------------------------------------------------------------------------
17 # Copyright (C) 2008-2011 The IPython Development Team
18 #
19 # Distributed under the terms of the BSD License. The full license is in
20 # the file COPYING, distributed as part of this software.
21 #-----------------------------------------------------------------------------
22
23 #-----------------------------------------------------------------------------
24 # Imports
25 #-----------------------------------------------------------------------------
9 # Copyright (c) IPython Development Team.
10 # Distributed under the terms of the Modified BSD License.
26 11
27 12 from keyword import iskeyword
28 13 import re
@@ -39,7 +24,7 b' from IPython.core.macro import Macro'
39 24 from IPython.core.splitinput import LineInfo
40 25
41 26 from traitlets import (
42 List, Integer, Unicode, CBool, Bool, Instance, CRegExp
27 List, Integer, Unicode, Bool, Instance, CRegExp
43 28 )
44 29
45 30 #-----------------------------------------------------------------------------
@@ -129,7 +114,7 b' class PrefilterManager(Configurable):'
129 114 or :meth:`sort_transformers` method after changing the priority.
130 115 """
131 116
132 multi_line_specials = CBool(True).tag(config=True)
117 multi_line_specials = Bool(True).tag(config=True)
133 118 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True)
134 119
135 120 def __init__(self, shell=None, **kwargs):
@@ -12,7 +12,7 b' from traitlets.config.configurable import LoggingConfigurable'
12 12 from IPython.paths import get_ipython_package_dir
13 13 from IPython.utils.path import expand_path, ensure_dir_exists
14 14 from IPython.utils import py3compat
15 from traitlets import Unicode, Bool
15 from traitlets import Unicode, Bool, observe
16 16
17 17 #-----------------------------------------------------------------------------
18 18 # Module errors
@@ -47,17 +47,18 b' class ProfileDir(LoggingConfigurable):'
47 47 pid_dir = Unicode(u'')
48 48 static_dir = Unicode(u'')
49 49
50 location = Unicode(u'', config=True,
50 location = Unicode(u'',
51 51 help="""Set the profile location directly. This overrides the logic used by the
52 52 `profile` option.""",
53 )
53 ).tag(config=True)
54 54
55 55 _location_isset = Bool(False) # flag for detecting multiply set location
56
57 def _location_changed(self, name, old, new):
56 @observe('location')
57 def _location_changed(self, change):
58 58 if self._location_isset:
59 59 raise RuntimeError("Cannot set profile location more than once.")
60 60 self._location_isset = True
61 new = change['new']
61 62 ensure_dir_exists(new)
62 63
63 64 # ensure config files exist:
@@ -68,9 +69,6 b' class ProfileDir(LoggingConfigurable):'
68 69 self.static_dir = os.path.join(new, self.static_dir_name)
69 70 self.check_dirs()
70 71
71 def _log_dir_changed(self, name, old, new):
72 self.check_log_dir()
73
74 72 def _mkdir(self, path, mode=None):
75 73 """ensure a directory exists at a given path
76 74
@@ -105,13 +103,12 b' class ProfileDir(LoggingConfigurable):'
105 103
106 104 return True
107 105
108 def check_log_dir(self):
106 @observe('log_dir')
107 def check_log_dir(self, change=None):
109 108 self._mkdir(self.log_dir)
110 109
111 def _startup_dir_changed(self, name, old, new):
112 self.check_startup_dir()
113
114 def check_startup_dir(self):
110 @observe('startup_dir')
111 def check_startup_dir(self, change=None):
115 112 self._mkdir(self.startup_dir)
116 113
117 114 readme = os.path.join(self.startup_dir, 'README')
@@ -123,21 +120,14 b' class ProfileDir(LoggingConfigurable):'
123 120 if os.path.exists(src) and not os.path.exists(readme):
124 121 shutil.copy(src, readme)
125 122
126 def _security_dir_changed(self, name, old, new):
127 self.check_security_dir()
128
129 def check_security_dir(self):
123 @observe('security_dir')
124 def check_security_dir(self, change=None):
130 125 self._mkdir(self.security_dir, 0o40700)
131 126
132 def _pid_dir_changed(self, name, old, new):
133 self.check_pid_dir()
134
135 def check_pid_dir(self):
127 @observe('pid_dir')
128 def check_pid_dir(self, change=None):
136 129 self._mkdir(self.pid_dir, 0o40700)
137 130
138 def _static_dir_changed(self, name, old, new):
139 self.check_startup_dir()
140
141 131 def check_dirs(self):
142 132 self.check_security_dir()
143 133 self.check_log_dir()
@@ -1,24 +1,9 b''
1 1 # -*- coding: utf-8 -*-
2 """Classes for handling input/output prompts.
2 """Classes for handling input/output prompts."""
3 3
4 Authors:
5
6 * Fernando Perez
7 * Brian Granger
8 * Thomas Kluyver
9 """
10
11 #-----------------------------------------------------------------------------
12 # Copyright (C) 2008-2011 The IPython Development Team
13 # Copyright (C) 2001-2007 Fernando Perez <fperez@colorado.edu>
14 #
15 # Distributed under the terms of the BSD License. The full license is in
16 # the file COPYING, distributed as part of this software.
17 #-----------------------------------------------------------------------------
18
19 #-----------------------------------------------------------------------------
20 # Imports
21 #-----------------------------------------------------------------------------
4 # Copyright (c) 2001-2007 Fernando Perez <fperez@colorado.edu>
5 # Copyright (c) IPython Development Team.
6 # Distributed under the terms of the Modified BSD License.
22 7
23 8 import os
24 9 import re
@@ -31,7 +16,7 b' from string import Formatter'
31 16 from traitlets.config.configurable import Configurable
32 17 from IPython.core import release
33 18 from IPython.utils import coloransi, py3compat
34 from traitlets import Unicode, Instance, Dict, Bool, Int, observe
19 from traitlets import Unicode, Instance, Dict, Bool, Int, observe, default
35 20
36 21 from IPython.utils.PyColorize import LightBGColors, LinuxColors, NoColor
37 22
@@ -271,7 +256,6 b' class PromptManager(Configurable):'
271 256 things like the current time in the prompts. Functions are only called
272 257 if they are used in the prompt.
273 258 """)
274 def _lazy_evaluate_fields_default(self): return lazily_evaluate.copy()
275 259
276 260 in_template = Unicode('In [\\#]: ',
277 261 help="Input prompt. '\\#' will be transformed to the prompt number"
@@ -282,6 +266,10 b' class PromptManager(Configurable):'
282 266 help="Output prompt. '\\#' will be transformed to the prompt number"
283 267 ).tag(config=True)
284 268
269 @default('lazy_evaluate_fields')
270 def _lazy_evaluate_fields_default(self):
271 return lazily_evaluate.copy()
272
285 273 justify = Bool(True, help="""
286 274 If True (default), each prompt will be right-aligned with the
287 275 preceding one.
@@ -297,6 +285,7 b' class PromptManager(Configurable):'
297 285
298 286 # The number of characters in each prompt which don't contribute to width
299 287 invisible_chars = Dict()
288 @default('invisible_chars')
300 289 def _invisible_chars_default(self):
301 290 return {'in': 0, 'in2': 0, 'out': 0, 'rewrite':0}
302 291
@@ -313,8 +302,8 b' class PromptManager(Configurable):'
313 302 self.update_prompt('in2', self.in2_template)
314 303 self.update_prompt('out', self.out_template)
315 304 self.update_prompt('rewrite')
316 self.on_trait_change(self._update_prompt_trait, ['in_template',
317 'in2_template', 'out_template'])
305 self.observe(self._update_prompt_trait,
306 names=['in_template', 'in2_template', 'out_template'])
318 307
319 308 def update_prompt(self, name, new_template=None):
320 309 """This is called when a prompt template is updated. It processes
@@ -22,7 +22,7 b' from IPython.utils import py3compat'
22 22 from IPython.utils.contexts import preserve_keys
23 23 from IPython.utils.path import filefind
24 24 from traitlets import (
25 Unicode, Instance, List, Bool, CaselessStrEnum
25 Unicode, Instance, List, Bool, CaselessStrEnum, default, observe,
26 26 )
27 27 from IPython.lib.inputhook import guis
28 28
@@ -135,76 +135,73 b' class InteractiveShellApp(Configurable):'
135 135 - :meth:`init_extensions`
136 136 - :meth:`init_code`
137 137 """
138 extensions = List(Unicode(), config=True,
138 extensions = List(Unicode(),
139 139 help="A list of dotted module names of IPython extensions to load."
140 )
141 extra_extension = Unicode('', config=True,
140 ).tag(config=True)
141 extra_extension = Unicode('',
142 142 help="dotted module name of an IPython extension to load."
143 )
143 ).tag(config=True)
144 144
145 reraise_ipython_extension_failures = Bool(
146 False,
147 config=True,
145 reraise_ipython_extension_failures = Bool(False,
148 146 help="Reraise exceptions encountered loading IPython extensions?",
149 )
147 ).tag(config=True)
150 148
151 149 # Extensions that are always loaded (not configurable)
152 default_extensions = List(Unicode(), [u'storemagic'], config=False)
150 default_extensions = List(Unicode(), [u'storemagic']).tag(config=False)
153 151
154 hide_initial_ns = Bool(True, config=True,
152 hide_initial_ns = Bool(True,
155 153 help="""Should variables loaded at startup (by startup files, exec_lines, etc.)
156 154 be hidden from tools like %who?"""
157 )
155 ).tag(config=True)
158 156
159 exec_files = List(Unicode(), config=True,
157 exec_files = List(Unicode(),
160 158 help="""List of files to run at IPython startup."""
161 )
162 exec_PYTHONSTARTUP = Bool(True, config=True,
159 ).tag(config=True)
160 exec_PYTHONSTARTUP = Bool(True,
163 161 help="""Run the file referenced by the PYTHONSTARTUP environment
164 162 variable at IPython startup."""
165 )
166 file_to_run = Unicode('', config=True,
167 help="""A file to be run""")
163 ).tag(config=True)
164 file_to_run = Unicode('',
165 help="""A file to be run""").tag(config=True)
168 166
169 exec_lines = List(Unicode(), config=True,
167 exec_lines = List(Unicode(),
170 168 help="""lines of code to run at IPython startup."""
171 )
172 code_to_run = Unicode('', config=True,
169 ).tag(config=True)
170 code_to_run = Unicode('',
173 171 help="Execute the given command string."
174 )
175 module_to_run = Unicode('', config=True,
172 ).tag(config=True)
173 module_to_run = Unicode('',
176 174 help="Run the module as a script."
177 )
178 gui = CaselessStrEnum(gui_keys, config=True, allow_none=True,
175 ).tag(config=True)
176 gui = CaselessStrEnum(gui_keys, allow_none=True,
179 177 help="Enable GUI event loop integration with any of {0}.".format(gui_keys)
180 )
178 ).tag(config=True)
181 179 matplotlib = CaselessStrEnum(backend_keys, allow_none=True,
182 config=True,
183 180 help="""Configure matplotlib for interactive use with
184 181 the default matplotlib backend."""
185 )
182 ).tag(config=True)
186 183 pylab = CaselessStrEnum(backend_keys, allow_none=True,
187 config=True,
188 184 help="""Pre-load matplotlib and numpy for interactive use,
189 185 selecting a particular matplotlib backend and loop integration.
190 186 """
191 )
192 pylab_import_all = Bool(True, config=True,
187 ).tag(config=True)
188 pylab_import_all = Bool(True,
193 189 help="""If true, IPython will populate the user namespace with numpy, pylab, etc.
194 190 and an ``import *`` is done from numpy and pylab, when using pylab mode.
195 191
196 192 When False, pylab mode should not import any names into the user namespace.
197 193 """
198 )
194 ).tag(config=True)
199 195 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC',
200 196 allow_none=True)
201 197 # whether interact-loop should start
202 198 interact = Bool(True)
203 199
204 200 user_ns = Instance(dict, args=None, allow_none=True)
205 def _user_ns_changed(self, name, old, new):
201 @observe('user_ns')
202 def _user_ns_changed(self, change):
206 203 if self.shell is not None:
207 self.shell.user_ns = new
204 self.shell.user_ns = change['new']
208 205 self.shell.init_user_ns()
209 206
210 207 def init_path(self):
@@ -10,30 +10,17 b' To automatically restore stored variables at startup, add this to your'
10 10 c.StoreMagics.autorestore = True
11 11 """
12 12 from __future__ import print_function
13 #-----------------------------------------------------------------------------
14 # Copyright (c) 2012, The IPython Development Team.
15 #
16 # Distributed under the terms of the Modified BSD License.
17 #
18 # The full license is in the file COPYING.txt, distributed with this software.
19 #-----------------------------------------------------------------------------
20 13
21 #-----------------------------------------------------------------------------
22 # Imports
23 #-----------------------------------------------------------------------------
14 # Copyright (c) IPython Development Team.
15 # Distributed under the terms of the Modified BSD License.
24 16
25 # Stdlib
26 17 import inspect, os, sys, textwrap
27 18
28 # Our own
29 19 from IPython.core.error import UsageError
30 20 from IPython.core.magic import Magics, magics_class, line_magic
31 21 from traitlets import Bool
32 22 from IPython.utils.py3compat import string_types
33 23
34 #-----------------------------------------------------------------------------
35 # Functions and classes
36 #-----------------------------------------------------------------------------
37 24
38 25 def restore_aliases(ip):
39 26 staliases = ip.db.get('stored_aliases', {})
@@ -74,11 +61,11 b' class StoreMagics(Magics):'
74 61
75 62 Provides the %store magic."""
76 63
77 autorestore = Bool(False, config=True, help=
64 autorestore = Bool(False, help=
78 65 """If True, any %store-d variables will be automatically restored
79 66 when IPython starts.
80 67 """
81 )
68 ).tag(config=True)
82 69
83 70 def __init__(self, shell):
84 71 super(StoreMagics, self).__init__(shell=shell)
@@ -14,6 +14,7 b' from __future__ import print_function'
14 14 import logging
15 15 import os
16 16 import sys
17 import warnings
17 18
18 19 from traitlets.config.loader import Config
19 20 from traitlets.config.application import boolean_flag, catch_config_error, Application
@@ -33,10 +34,9 b' from IPython.core.shellapp import ('
33 34 )
34 35 from IPython.extensions.storemagic import StoreMagics
35 36 from .ptshell import TerminalInteractiveShell
36 from IPython.utils import warn
37 37 from IPython.paths import get_ipython_dir
38 38 from traitlets import (
39 Bool, List, Dict,
39 Bool, List, Dict, default, observe,
40 40 )
41 41
42 42 #-----------------------------------------------------------------------------
@@ -183,6 +183,7 b' class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):'
183 183 flags = Dict(flags)
184 184 aliases = Dict(aliases)
185 185 classes = List()
186 @default('classes')
186 187 def _classes_default(self):
187 188 """This has to be in a method, for TerminalIPythonApp to be available."""
188 189 return [
@@ -241,35 +242,37 b' class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):'
241 242 # *do* autocreate requested profile, but don't create the config file.
242 243 auto_create=Bool(True)
243 244 # configurables
244 quick = Bool(False, config=True,
245 quick = Bool(False,
245 246 help="""Start IPython quickly by skipping the loading of config files."""
246 )
247 def _quick_changed(self, name, old, new):
248 if new:
247 ).tag(config=True)
248 @observe('quick')
249 def _quick_changed(self, change):
250 if change['new']:
249 251 self.load_config_file = lambda *a, **kw: None
250 252
251 display_banner = Bool(True, config=True,
253 display_banner = Bool(True,
252 254 help="Whether to display a banner upon starting IPython."
253 )
255 ).tag(config=True)
254 256
255 257 # if there is code of files to run from the cmd line, don't interact
256 258 # unless the --i flag (App.force_interact) is true.
257 force_interact = Bool(False, config=True,
259 force_interact = Bool(False,
258 260 help="""If a command or file is given via the command-line,
259 261 e.g. 'ipython foo.py', start an interactive shell after executing the
260 262 file or command."""
261 )
262 def _force_interact_changed(self, name, old, new):
263 if new:
263 ).tag(config=True)
264 @observe('force_interact')
265 def _force_interact_changed(self, change):
266 if change['new']:
264 267 self.interact = True
265 268
266 def _file_to_run_changed(self, name, old, new):
269 @observe('file_to_run', 'code_to_run', 'module_to_run')
270 def _file_to_run_changed(self, change):
271 new = change['new']
267 272 if new:
268 273 self.something_to_run = True
269 274 if new and not self.force_interact:
270 275 self.interact = False
271 _code_to_run_changed = _file_to_run_changed
272 _module_to_run_changed = _file_to_run_changed
273 276
274 277 # internal, not-configurable
275 278 something_to_run=Bool(False)
@@ -284,7 +287,7 b' class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):'
284 287 # warn and transform into current syntax
285 288 argv = argv[:] # copy, don't clobber
286 289 idx = argv.index('-pylab')
287 warn.warn("`-pylab` flag has been deprecated.\n"
290 warnings.warn("`-pylab` flag has been deprecated.\n"
288 291 " Use `--matplotlib <backend>` and import pylab manually.")
289 292 argv[idx] = '--pylab'
290 293
@@ -331,7 +334,7 b' class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):'
331 334 def _pylab_changed(self, name, old, new):
332 335 """Replace --pylab='inline' with --pylab='auto'"""
333 336 if new == 'inline':
334 warn.warn("'inline' not available as pylab backend, "
337 warnings.warn("'inline' not available as pylab backend, "
335 338 "using 'auto' instead.")
336 339 self.pylab = 'auto'
337 340
@@ -13,7 +13,7 b' from IPython.core.interactiveshell import InteractiveShell'
13 13 from IPython.utils.py3compat import PY3, cast_unicode_py2, input
14 14 from IPython.utils.terminal import toggle_set_term_title, set_term_title
15 15 from IPython.utils.process import abbrev_cwd
16 from traitlets import Bool, CBool, Unicode, Dict, Integer, observe
16 from traitlets import Bool, Unicode, Dict, Integer, observe
17 17
18 18 from prompt_toolkit.completion import Completer, Completion
19 19 from prompt_toolkit.enums import DEFAULT_BUFFER, SEARCH_BUFFER, EditingMode
@@ -100,15 +100,18 b' class TerminalInteractiveShell(InteractiveShell):'
100 100
101 101 pt_cli = None
102 102
103 autoedit_syntax = CBool(False).tag(config=True,
104 help="auto editing of files with syntax errors.")
103 autoedit_syntax = Bool(False,
104 help="auto editing of files with syntax errors.",
105 ).tag(config=True)
106
105 107
106 confirm_exit = CBool(True).tag(config=True,
108 confirm_exit = Bool(True,
107 109 help="""
108 110 Set to confirm when you try to exit IPython with an EOF (Control-D
109 111 in Unix, Control-Z/Enter in Windows). By typing 'exit' or 'quit',
110 112 you can force a direct exit without any confirmation.""",
111 )
113 ).tag(config=True)
114
112 115 editing_mode = Unicode('emacs',
113 116 help="Shortcut style to use at the prompt. 'vi' or 'emacs'.",
114 117 ).tag(config=True)
@@ -121,7 +124,9 b' class TerminalInteractiveShell(InteractiveShell):'
121 124 help="The name of a Pygments style to use for syntax highlighting: \n %s" % ', '.join(get_all_styles())
122 125 ).tag(config=True)
123 126
124 def _highlighting_style_changed(self, old, new):
127
128 @observe('highlighting_style')
129 def _highlighting_style_changed(self, change):
125 130 self._style = self._make_style_from_name(self.highlighting_style)
126 131
127 132 highlighting_style_overrides = Dict(
@@ -140,11 +145,9 b' class TerminalInteractiveShell(InteractiveShell):'
140 145 help="Display a multi column completion menu.",
141 146 ).tag(config=True)
142 147
143 @observe('term_title')
144 def _term_title_changed(self, change):
145 self.init_term_title()
146 148
147 def init_term_title(self):
149 @observe('term_title')
150 def init_term_title(self, change=None):
148 151 # Enable or disable the terminal title.
149 152 if self.term_title:
150 153 toggle_set_term_title(True)
@@ -22,5 +22,5 b' class Colorable(Configurable):'
22 22 """
23 23 A subclass of configurable for all the classes that have a `default_scheme`
24 24 """
25 default_style=Unicode('lightbg', config=True)
25 default_style=Unicode('lightbg').tag(config=True)
26 26
General Comments 0
You need to be logged in to leave comments. Login now