Show More
@@ -379,6 +379,7 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||||
379 | # This is where traits with a config_key argument are updated |
|
379 | # This is where traits with a config_key argument are updated | |
380 | # from the values on config. |
|
380 | # from the values on config. | |
381 | super(InteractiveShell, self).__init__(config=config) |
|
381 | super(InteractiveShell, self).__init__(config=config) | |
|
382 | self.configurables = [self] | |||
382 |
|
383 | |||
383 | # These are relatively independent and stateless |
|
384 | # These are relatively independent and stateless | |
384 | self.init_ipython_dir(ipython_dir) |
|
385 | self.init_ipython_dir(ipython_dir) | |
@@ -602,9 +603,11 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||||
602 |
|
603 | |||
603 | def init_display_formatter(self): |
|
604 | def init_display_formatter(self): | |
604 | self.display_formatter = DisplayFormatter(config=self.config) |
|
605 | self.display_formatter = DisplayFormatter(config=self.config) | |
|
606 | self.configurables.append(self.display_formatter) | |||
605 |
|
607 | |||
606 | def init_display_pub(self): |
|
608 | def init_display_pub(self): | |
607 | self.display_pub = self.display_pub_class(config=self.config) |
|
609 | self.display_pub = self.display_pub_class(config=self.config) | |
|
610 | self.configurables.append(self.display_pub) | |||
608 |
|
611 | |||
609 | def init_displayhook(self): |
|
612 | def init_displayhook(self): | |
610 | # Initialize displayhook, set in/out prompts and printing system |
|
613 | # Initialize displayhook, set in/out prompts and printing system | |
@@ -620,6 +623,7 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||||
620 | ps_out = self.prompt_out, |
|
623 | ps_out = self.prompt_out, | |
621 | pad_left = self.prompts_pad_left |
|
624 | pad_left = self.prompts_pad_left | |
622 | ) |
|
625 | ) | |
|
626 | self.configurables.append(self.displayhook) | |||
623 | # This is a context manager that installs/revmoes the displayhook at |
|
627 | # This is a context manager that installs/revmoes the displayhook at | |
624 | # the appropriate time. |
|
628 | # the appropriate time. | |
625 | self.display_trap = DisplayTrap(hook=self.displayhook) |
|
629 | self.display_trap = DisplayTrap(hook=self.displayhook) | |
@@ -1435,6 +1439,7 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||||
1435 | def init_history(self): |
|
1439 | def init_history(self): | |
1436 | """Sets up the command history, and starts regular autosaves.""" |
|
1440 | """Sets up the command history, and starts regular autosaves.""" | |
1437 | self.history_manager = HistoryManager(shell=self, config=self.config) |
|
1441 | self.history_manager = HistoryManager(shell=self, config=self.config) | |
|
1442 | self.configurables.append(self.history_manager) | |||
1438 |
|
1443 | |||
1439 | #------------------------------------------------------------------------- |
|
1444 | #------------------------------------------------------------------------- | |
1440 | # Things related to exception handling and tracebacks (not debugging) |
|
1445 | # Things related to exception handling and tracebacks (not debugging) | |
@@ -1856,6 +1861,7 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||||
1856 | use_readline=self.has_readline, |
|
1861 | use_readline=self.has_readline, | |
1857 | config=self.config, |
|
1862 | config=self.config, | |
1858 | ) |
|
1863 | ) | |
|
1864 | self.configurables.append(self.Completer) | |||
1859 |
|
1865 | |||
1860 | # Add custom completers to the basic ones built into IPCompleter |
|
1866 | # Add custom completers to the basic ones built into IPCompleter | |
1861 | sdisp = self.strdispatchers.get('complete_command', StrDispatch()) |
|
1867 | sdisp = self.strdispatchers.get('complete_command', StrDispatch()) | |
@@ -2112,6 +2118,7 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||||
2112 |
|
2118 | |||
2113 | def init_alias(self): |
|
2119 | def init_alias(self): | |
2114 | self.alias_manager = AliasManager(shell=self, config=self.config) |
|
2120 | self.alias_manager = AliasManager(shell=self, config=self.config) | |
|
2121 | self.configurables.append(self.alias_manager) | |||
2115 | self.ns_table['alias'] = self.alias_manager.alias_table, |
|
2122 | self.ns_table['alias'] = self.alias_manager.alias_table, | |
2116 |
|
2123 | |||
2117 | #------------------------------------------------------------------------- |
|
2124 | #------------------------------------------------------------------------- | |
@@ -2120,9 +2127,12 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||||
2120 |
|
2127 | |||
2121 | def init_extension_manager(self): |
|
2128 | def init_extension_manager(self): | |
2122 | self.extension_manager = ExtensionManager(shell=self, config=self.config) |
|
2129 | self.extension_manager = ExtensionManager(shell=self, config=self.config) | |
|
2130 | self.configurables.append(self.extension_manager) | |||
2123 |
|
2131 | |||
2124 | def init_plugin_manager(self): |
|
2132 | def init_plugin_manager(self): | |
2125 | self.plugin_manager = PluginManager(config=self.config) |
|
2133 | self.plugin_manager = PluginManager(config=self.config) | |
|
2134 | self.configurables.append(self.plugin_manager) | |||
|
2135 | ||||
2126 |
|
2136 | |||
2127 | #------------------------------------------------------------------------- |
|
2137 | #------------------------------------------------------------------------- | |
2128 | # Things related to payloads |
|
2138 | # Things related to payloads | |
@@ -2130,6 +2140,7 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||||
2130 |
|
2140 | |||
2131 | def init_payload(self): |
|
2141 | def init_payload(self): | |
2132 | self.payload_manager = PayloadManager(config=self.config) |
|
2142 | self.payload_manager = PayloadManager(config=self.config) | |
|
2143 | self.configurables.append(self.payload_manager) | |||
2133 |
|
2144 | |||
2134 | #------------------------------------------------------------------------- |
|
2145 | #------------------------------------------------------------------------- | |
2135 | # Things related to the prefilter |
|
2146 | # Things related to the prefilter | |
@@ -2137,6 +2148,7 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||||
2137 |
|
2148 | |||
2138 | def init_prefilter(self): |
|
2149 | def init_prefilter(self): | |
2139 | self.prefilter_manager = PrefilterManager(shell=self, config=self.config) |
|
2150 | self.prefilter_manager = PrefilterManager(shell=self, config=self.config) | |
|
2151 | self.configurables.append(self.prefilter_manager) | |||
2140 | # Ultimately this will be refactored in the new interpreter code, but |
|
2152 | # Ultimately this will be refactored in the new interpreter code, but | |
2141 | # for now, we should expose the main prefilter method (there's legacy |
|
2153 | # for now, we should expose the main prefilter method (there's legacy | |
2142 | # code out there that may rely on this). |
|
2154 | # code out there that may rely on this). |
@@ -123,6 +123,8 b' class Magic:' | |||||
123 | auto_status = ['Automagic is OFF, % prefix IS needed for magic functions.', |
|
123 | auto_status = ['Automagic is OFF, % prefix IS needed for magic functions.', | |
124 | 'Automagic is ON, % prefix NOT needed for magic functions.'] |
|
124 | 'Automagic is ON, % prefix NOT needed for magic functions.'] | |
125 |
|
125 | |||
|
126 | ||||
|
127 | configurables = None | |||
126 | #...................................................................... |
|
128 | #...................................................................... | |
127 | # some utility functions |
|
129 | # some utility functions | |
128 |
|
130 | |||
@@ -132,6 +134,8 b' class Magic:' | |||||
132 | if profile is None: |
|
134 | if profile is None: | |
133 | self.magic_prun = self.profile_missing_notice |
|
135 | self.magic_prun = self.profile_missing_notice | |
134 | self.shell = shell |
|
136 | self.shell = shell | |
|
137 | if self.configurables is None: | |||
|
138 | self.configurables = [] | |||
135 |
|
139 | |||
136 | # namespace for holding state we may need |
|
140 | # namespace for holding state we may need | |
137 | self._magic_state = Bunch() |
|
141 | self._magic_state = Bunch() | |
@@ -3607,4 +3611,92 b' Defaulting color scheme to \'NoColor\'"""' | |||||
3607 | with open(new_fname, 'w') as f: |
|
3611 | with open(new_fname, 'w') as f: | |
3608 | current.write(nb, f, new_format) |
|
3612 | current.write(nb, f, new_format) | |
3609 |
|
3613 | |||
|
3614 | def magic_config(self, s): | |||
|
3615 | """configure IPython | |||
|
3616 | ||||
|
3617 | %config Class.trait=value | |||
|
3618 | or | |||
|
3619 | %config Class | |||
|
3620 | ||||
|
3621 | This magic exposes most of the IPython config system. Any | |||
|
3622 | Configurable class should be able to be configured with the simple | |||
|
3623 | line: | |||
|
3624 | ||||
|
3625 | %config Class.trait=value | |||
|
3626 | ||||
|
3627 | Where `value` will be resolved in the user's namespace, if it is an | |||
|
3628 | expression or variable name. | |||
|
3629 | ||||
|
3630 | Examples | |||
|
3631 | -------- | |||
|
3632 | ||||
|
3633 | To see what classes are availabe for config, pass no arguments: | |||
|
3634 | In [1]: %config | |||
|
3635 | Available objects for config: | |||
|
3636 | TerminalInteractiveShell | |||
|
3637 | HistoryManager | |||
|
3638 | PrefilterManager | |||
|
3639 | AliasManager | |||
|
3640 | IPCompleter | |||
|
3641 | DisplayFormatter | |||
|
3642 | DisplayPublisher | |||
|
3643 | DisplayHook | |||
|
3644 | ExtensionManager | |||
|
3645 | PluginManager | |||
|
3646 | PayloadManager | |||
|
3647 | ||||
|
3648 | # To view what is configurable on a given class, just pass the class name | |||
|
3649 | In [2]: %config IPCompleter | |||
|
3650 | IPCompleter options | |||
|
3651 | ----------------- | |||
|
3652 | IPCompleter.greedy=<CBool> | |||
|
3653 | Current: False | |||
|
3654 | Activate greedy completion | |||
|
3655 | This will enable completion on elements of lists, results of function calls, | |||
|
3656 | etc., but can be unsafe because the code is actually evaluated on TAB. | |||
|
3657 | ||||
|
3658 | # but the real use is in setting values: | |||
|
3659 | In [3]: %config IPCompleter.greedy = True | |||
|
3660 | ||||
|
3661 | # and these values are read from the user_ns if they are variables: | |||
|
3662 | In [4]: feeling_greedy=False | |||
|
3663 | ||||
|
3664 | In [5]: %config IPCompleter.greedy = feeling_greedy | |||
|
3665 | ||||
|
3666 | """ | |||
|
3667 | from IPython.config.loader import Config | |||
|
3668 | classnames = [ c.__class__.__name__ for c in self.configurables ] | |||
|
3669 | line = s.strip() | |||
|
3670 | if not line: | |||
|
3671 | # print available configurable names | |||
|
3672 | print "Available objects for config:" | |||
|
3673 | for name in classnames: | |||
|
3674 | print " ", name | |||
|
3675 | return | |||
|
3676 | elif line in classnames: | |||
|
3677 | # `%config TerminalInteractiveShell` will print trait info for | |||
|
3678 | # TerminalInteractiveShell | |||
|
3679 | c = self.configurables[classnames.index(line)] | |||
|
3680 | cls = c.__class__ | |||
|
3681 | help = cls.class_get_help(c) | |||
|
3682 | # strip leading '--' from cl-args: | |||
|
3683 | help = re.sub(r'^\-\-', '', help, flags=re.MULTILINE) | |||
|
3684 | print help | |||
|
3685 | return | |||
|
3686 | elif '=' not in line: | |||
|
3687 | raise UsageError("Invalid config statement: %r, should be Class.trait = value" % line) | |||
|
3688 | ||||
|
3689 | ||||
|
3690 | # otherwise, assume we are setting configurables. | |||
|
3691 | # leave quotes on args when splitting, because we want | |||
|
3692 | # unquoted args to eval in user_ns | |||
|
3693 | cfg = Config() | |||
|
3694 | exec "cfg."+line in locals(), self.user_ns | |||
|
3695 | ||||
|
3696 | for configurable in self.configurables: | |||
|
3697 | try: | |||
|
3698 | configurable.update_config(cfg) | |||
|
3699 | except Exception as e: | |||
|
3700 | error(e) | |||
|
3701 | ||||
3610 | # end Magic |
|
3702 | # end Magic |
@@ -257,6 +257,8 b' def import_pylab(user_ns, backend, import_all=True, shell=None):' | |||||
257 |
|
257 | |||
258 | cfg = InlineBackendConfig.instance(config=shell.config) |
|
258 | cfg = InlineBackendConfig.instance(config=shell.config) | |
259 | cfg.shell = shell |
|
259 | cfg.shell = shell | |
|
260 | if cfg not in shell.configurables: | |||
|
261 | shell.configurables.append(cfg) | |||
260 |
|
262 | |||
261 | if backend == backends['inline']: |
|
263 | if backend == backends['inline']: | |
262 | from IPython.zmq.pylab.backend_inline import flush_figures |
|
264 | from IPython.zmq.pylab.backend_inline import flush_figures |
General Comments 0
You need to be logged in to leave comments.
Login now