Show More
@@ -1,147 +1,137 b'' | |||
|
1 | 1 | .. _configuring_ipython: |
|
2 | 2 | |
|
3 | 3 | =========================================================== |
|
4 | 4 | Configuring the :command:`ipython` command line application |
|
5 | 5 | =========================================================== |
|
6 | 6 | |
|
7 | 7 | This section contains information about how to configure the |
|
8 | 8 | :command:`ipython` command line application. See the :ref:`configuration |
|
9 | 9 | overview <config_overview>` for a more general description of the |
|
10 | 10 | configuration system and configuration file format. |
|
11 | 11 | |
|
12 | 12 | The default configuration file for the :command:`ipython` command line application |
|
13 | is :file:`ipython_config.py`. By setting the attributes in this file, you | |
|
14 | can configure the application. A sample is provided in | |
|
15 | :mod:`IPython.config.default.ipython_config`. Simply copy this file to your | |
|
16 | :ref:`IPython directory <ipython_dir>` to start using it. | |
|
13 | is :file:`profile_default/ipython_config.py` in your :ref:`IPython directory | |
|
14 | <ipython_dir>`. By setting the attributes in this file, you can configure the | |
|
15 | application. To create the default config file, run this command:: | |
|
16 | ||
|
17 | $ ipython profile create | |
|
17 | 18 | |
|
18 | 19 | Most configuration attributes that this file accepts are associated with classes |
|
19 | 20 | that are subclasses of :class:`~IPython.config.configurable.Configurable`. |
|
20 | 21 | |
|
21 | 22 | Applications themselves are Configurable as well, so we will start with some |
|
22 | 23 | application-level config. |
|
23 | 24 | |
|
24 | 25 | Application-level configuration |
|
25 | 26 | =============================== |
|
26 | 27 | |
|
27 | 28 | Assuming that your configuration file has the following at the top:: |
|
28 | 29 | |
|
29 | 30 | c = get_config() |
|
30 | 31 | |
|
31 | 32 | the following attributes are set application-wide: |
|
32 | 33 | |
|
33 | 34 | terminal IPython-only flags: |
|
34 | 35 | |
|
35 | 36 | :attr:`c.TerminalIPythonApp.display_banner` |
|
36 | 37 | A boolean that determined if the banner is printer when :command:`ipython` |
|
37 | 38 | is started. |
|
38 | 39 | |
|
39 | 40 | :attr:`c.TerminalIPythonApp.classic` |
|
40 | 41 | A boolean that determines if IPython starts in "classic" mode. In this |
|
41 | 42 | mode, the prompts and everything mimic that of the normal :command:`python` |
|
42 | 43 | shell |
|
43 | 44 | |
|
44 | 45 | :attr:`c.TerminalIPythonApp.nosep` |
|
45 | 46 | A boolean that determines if there should be no blank lines between |
|
46 | 47 | prompts. |
|
47 | 48 | |
|
48 | 49 | :attr:`c.Application.log_level` |
|
49 | 50 | An integer that sets the detail of the logging level during the startup |
|
50 | 51 | of :command:`ipython`. The default is 30 and the possible values are |
|
51 | 52 | (0, 10, 20, 30, 40, 50). Higher is quieter and lower is more verbose. |
|
52 | 53 | This can also be set by the name of the logging level, e.g. INFO=20, |
|
53 | 54 | WARN=30. |
|
54 | 55 | |
|
55 | 56 | Some options, such as extensions and startup code, can be set for any |
|
56 | 57 | application that starts an |
|
57 | 58 | :class:`~IPython.core.interactiveshell.InteractiveShell`. These apps are |
|
58 | 59 | subclasses of :class:`~IPython.core.shellapp.InteractiveShellApp`. Since |
|
59 | 60 | subclasses inherit configuration, setting a trait of |
|
60 | 61 | :attr:`c.InteractiveShellApp` will affect all IPython applications, but if you |
|
61 | 62 | want terminal IPython and the QtConsole to have different values, you can set |
|
62 | 63 | them via :attr:`c.TerminalIPythonApp` and :attr:`c.IPKernelApp` respectively. |
|
63 | 64 | |
|
64 | 65 | |
|
65 | 66 | :attr:`c.InteractiveShellApp.extensions` |
|
66 |
A list of strings, each of which is an importable IPython extension. |
|
|
67 | IPython extension is a regular Python module or package that has a | |
|
68 | :func:`load_ipython_extension(ip)` method. This method gets called when | |
|
69 | the extension is loaded with the currently running | |
|
70 | :class:`~IPython.core.interactiveshell.InteractiveShell` as its only | |
|
71 | argument. You can put your extensions anywhere they can be imported but we | |
|
72 | add the :file:`extensions` subdirectory of the ipython directory to | |
|
73 | ``sys.path`` during extension loading, so you can put them there as well. | |
|
74 | Extensions are not executed in the user's interactive namespace and they | |
|
75 | must be pure Python code. Extensions are the recommended way of customizing | |
|
76 | :command:`ipython`. Extensions can provide an | |
|
77 | :func:`unload_ipython_extension` that will be called when the extension is | |
|
78 | unloaded. | |
|
67 | A list of strings, each of which is an importable IPython extension. See | |
|
68 | :ref:`extensions_overview` for more details about extensions. | |
|
79 | 69 | |
|
80 | 70 | :attr:`c.InteractiveShellApp.exec_lines` |
|
81 | 71 | A list of strings, each of which is Python code that is run in the user's |
|
82 | 72 | namespace after IPython start. These lines can contain full IPython syntax |
|
83 | 73 | with magics, etc. |
|
84 | 74 | |
|
85 | 75 | :attr:`c.InteractiveShellApp.exec_files` |
|
86 | 76 | A list of strings, each of which is the full pathname of a ``.py`` or |
|
87 | 77 | ``.ipy`` file that will be executed as IPython starts. These files are run |
|
88 | 78 | in IPython in the user's namespace. Files with a ``.py`` extension need to |
|
89 | 79 | be pure Python. Files with a ``.ipy`` extension can have custom IPython |
|
90 | 80 | syntax (magics, etc.). These files need to be in the cwd, the ipythondir |
|
91 | 81 | or be absolute paths. |
|
92 | 82 | |
|
93 | 83 | Classes that can be configured |
|
94 | 84 | ============================== |
|
95 | 85 | |
|
96 | 86 | The following classes can also be configured in the configuration file for |
|
97 | 87 | :command:`ipython`: |
|
98 | 88 | |
|
99 | 89 | * :class:`~IPython.core.interactiveshell.InteractiveShell` |
|
100 | 90 | |
|
101 | 91 | * :class:`~IPython.core.prefilter.PrefilterManager` |
|
102 | 92 | |
|
103 | 93 | * :class:`~IPython.core.alias.AliasManager` |
|
104 | 94 | |
|
105 | 95 | To see which attributes of these classes are configurable, please see the |
|
106 | 96 | source code for these classes, the class docstrings or the sample |
|
107 | 97 | configuration file :mod:`IPython.config.default.ipython_config`. |
|
108 | 98 | |
|
109 | 99 | Example |
|
110 | 100 | ======= |
|
111 | 101 | |
|
112 | 102 | For those who want to get a quick start, here is a sample |
|
113 | 103 | :file:`ipython_config.py` that sets some of the common configuration |
|
114 | 104 | attributes:: |
|
115 | 105 | |
|
116 | 106 | # sample ipython_config.py |
|
117 | 107 | c = get_config() |
|
118 | 108 | |
|
119 |
c. |
|
|
109 | c.TerminalIPythonApp.display_banner = True | |
|
120 | 110 | c.InteractiveShellApp.log_level = 20 |
|
121 | 111 | c.InteractiveShellApp.extensions = [ |
|
122 | 112 | 'myextension' |
|
123 | 113 | ] |
|
124 | 114 | c.InteractiveShellApp.exec_lines = [ |
|
125 | 115 | 'import numpy', |
|
126 | 116 | 'import scipy' |
|
127 | 117 | ] |
|
128 | 118 | c.InteractiveShellApp.exec_files = [ |
|
129 | 119 | 'mycode.py', |
|
130 | 120 | 'fancy.ipy' |
|
131 | 121 | ] |
|
132 | 122 | c.InteractiveShell.autoindent = True |
|
133 | 123 | c.InteractiveShell.colors = 'LightBG' |
|
134 | 124 | c.InteractiveShell.confirm_exit = False |
|
135 | 125 | c.InteractiveShell.deep_reload = True |
|
136 | 126 | c.InteractiveShell.editor = 'nano' |
|
137 | 127 | c.InteractiveShell.prompt_in1 = 'In [\#]: ' |
|
138 | 128 | c.InteractiveShell.prompt_in2 = ' .\D.: ' |
|
139 | 129 | c.InteractiveShell.prompt_out = 'Out[\#]: ' |
|
140 | 130 | c.InteractiveShell.prompts_pad_left = True |
|
141 | 131 | c.InteractiveShell.xmode = 'Context' |
|
142 | 132 | |
|
143 | 133 | c.PrefilterManager.multi_line_specials = True |
|
144 | 134 | |
|
145 | 135 | c.AliasManager.user_aliases = [ |
|
146 | 136 | ('la', 'ls -al') |
|
147 | 137 | ] |
@@ -1,528 +1,531 b'' | |||
|
1 | 1 | .. _config_overview: |
|
2 | 2 | |
|
3 | 3 | ============================================ |
|
4 | 4 | Overview of the IPython configuration system |
|
5 | 5 | ============================================ |
|
6 | 6 | |
|
7 | 7 | This section describes the IPython configuration system. Starting with version |
|
8 | 8 | 0.11, IPython has a completely new configuration system that is quite |
|
9 | 9 | different from the older :file:`ipythonrc` or :file:`ipy_user_conf.py` |
|
10 | 10 | approaches. The new configuration system was designed from scratch to address |
|
11 | 11 | the particular configuration needs of IPython. While there are many |
|
12 | 12 | other excellent configuration systems out there, we found that none of them |
|
13 | 13 | met our requirements. |
|
14 | 14 | |
|
15 | 15 | .. warning:: |
|
16 | 16 | |
|
17 | 17 | If you are upgrading to version 0.11 of IPython, you will need to migrate |
|
18 | 18 | your old :file:`ipythonrc` or :file:`ipy_user_conf.py` configuration files |
|
19 | to the new system. Read on for information on how to do this. | |
|
19 | to the new system. You may want to read the section on | |
|
20 | :ref:`configuring IPython <configuring_ipython>`. There are also some ideas | |
|
21 | `on the IPython wiki <http://wiki.ipython.org/Cookbook/Moving_config_to_IPython_0.11>`_ | |
|
22 | about this. | |
|
20 | 23 | |
|
21 | 24 | The discussion that follows is focused on teaching users how to configure |
|
22 | 25 | IPython to their liking. Developers who want to know more about how they |
|
23 | 26 | can enable their objects to take advantage of the configuration system |
|
24 | 27 | should consult our :ref:`developer guide <developer_guide>` |
|
25 | 28 | |
|
26 | 29 | The main concepts |
|
27 | 30 | ================= |
|
28 | 31 | |
|
29 | 32 | There are a number of abstractions that the IPython configuration system uses. |
|
30 | 33 | Each of these abstractions is represented by a Python class. |
|
31 | 34 | |
|
32 | 35 | Configuration object: :class:`~IPython.config.loader.Config` |
|
33 | 36 | A configuration object is a simple dictionary-like class that holds |
|
34 | 37 | configuration attributes and sub-configuration objects. These classes |
|
35 | 38 | support dotted attribute style access (``Foo.bar``) in addition to the |
|
36 | 39 | regular dictionary style access (``Foo['bar']``). Configuration objects |
|
37 | 40 | are smart. They know how to merge themselves with other configuration |
|
38 | 41 | objects and they automatically create sub-configuration objects. |
|
39 | 42 | |
|
40 | 43 | Application: :class:`~IPython.config.application.Application` |
|
41 | 44 | An application is a process that does a specific job. The most obvious |
|
42 | 45 | application is the :command:`ipython` command line program. Each |
|
43 | 46 | application reads *one or more* configuration files and a single set of |
|
44 | 47 | command line options |
|
45 | 48 | and then produces a master configuration object for the application. This |
|
46 | 49 | configuration object is then passed to the configurable objects that the |
|
47 | 50 | application creates. These configurable objects implement the actual logic |
|
48 | 51 | of the application and know how to configure themselves given the |
|
49 | 52 | configuration object. |
|
50 | 53 | |
|
51 | 54 | Applications always have a `log` attribute that is a configured Logger. |
|
52 | 55 | This allows centralized logging configuration per-application. |
|
53 | 56 | |
|
54 | 57 | Configurable: :class:`~IPython.config.configurable.Configurable` |
|
55 | 58 | A configurable is a regular Python class that serves as a base class for |
|
56 | 59 | all main classes in an application. The |
|
57 | 60 | :class:`~IPython.config.configurable.Configurable` base class is |
|
58 | 61 | lightweight and only does one things. |
|
59 | 62 | |
|
60 | 63 | This :class:`~IPython.config.configurable.Configurable` is a subclass |
|
61 | 64 | of :class:`~IPython.utils.traitlets.HasTraits` that knows how to configure |
|
62 | 65 | itself. Class level traits with the metadata ``config=True`` become |
|
63 | 66 | values that can be configured from the command line and configuration |
|
64 | 67 | files. |
|
65 | 68 | |
|
66 | 69 | Developers create :class:`~IPython.config.configurable.Configurable` |
|
67 | 70 | subclasses that implement all of the logic in the application. Each of |
|
68 | 71 | these subclasses has its own configuration information that controls how |
|
69 | 72 | instances are created. |
|
70 | 73 | |
|
71 | 74 | Singletons: :class:`~IPython.config.configurable.SingletonConfigurable` |
|
72 | 75 | Any object for which there is a single canonical instance. These are |
|
73 | 76 | just like Configurables, except they have a class method |
|
74 | 77 | :meth:`~IPython.config.configurable.SingletonConfigurable.instance`, |
|
75 | 78 | that returns the current active instance (or creates one if it |
|
76 | 79 | does not exist). Examples of singletons include |
|
77 | 80 | :class:`~IPython.config.application.Application`s and |
|
78 | 81 | :class:`~IPython.core.interactiveshell.InteractiveShell`. This lets |
|
79 | 82 | objects easily connect to the current running Application without passing |
|
80 | 83 | objects around everywhere. For instance, to get the current running |
|
81 | 84 | Application instance, simply do: ``app = Application.instance()``. |
|
82 | 85 | |
|
83 | 86 | |
|
84 | 87 | .. note:: |
|
85 | 88 | |
|
86 | 89 | Singletons are not strictly enforced - you can have many instances |
|
87 | 90 | of a given singleton class, but the :meth:`instance` method will always |
|
88 | 91 | return the same one. |
|
89 | 92 | |
|
90 | 93 | Having described these main concepts, we can now state the main idea in our |
|
91 | 94 | configuration system: *"configuration" allows the default values of class |
|
92 | 95 | attributes to be controlled on a class by class basis*. Thus all instances of |
|
93 | 96 | a given class are configured in the same way. Furthermore, if two instances |
|
94 | 97 | need to be configured differently, they need to be instances of two different |
|
95 | 98 | classes. While this model may seem a bit restrictive, we have found that it |
|
96 | 99 | expresses most things that need to be configured extremely well. However, it |
|
97 | 100 | is possible to create two instances of the same class that have different |
|
98 | 101 | trait values. This is done by overriding the configuration. |
|
99 | 102 | |
|
100 | 103 | Now, we show what our configuration objects and files look like. |
|
101 | 104 | |
|
102 | 105 | Configuration objects and files |
|
103 | 106 | =============================== |
|
104 | 107 | |
|
105 | 108 | A configuration file is simply a pure Python file that sets the attributes |
|
106 | 109 | of a global, pre-created configuration object. This configuration object is a |
|
107 | 110 | :class:`~IPython.config.loader.Config` instance. While in a configuration |
|
108 | 111 | file, to get a reference to this object, simply call the :func:`get_config` |
|
109 | 112 | function. We inject this function into the global namespace that the |
|
110 | 113 | configuration file is executed in. |
|
111 | 114 | |
|
112 | 115 | Here is an example of a super simple configuration file that does nothing:: |
|
113 | 116 | |
|
114 | 117 | c = get_config() |
|
115 | 118 | |
|
116 | 119 | Once you get a reference to the configuration object, you simply set |
|
117 | 120 | attributes on it. All you have to know is: |
|
118 | 121 | |
|
119 | 122 | * The name of each attribute. |
|
120 | 123 | * The type of each attribute. |
|
121 | 124 | |
|
122 | 125 | The answers to these two questions are provided by the various |
|
123 | 126 | :class:`~IPython.config.configurable.Configurable` subclasses that an |
|
124 | 127 | application uses. Let's look at how this would work for a simple configurable |
|
125 | 128 | subclass:: |
|
126 | 129 | |
|
127 | 130 | # Sample configurable: |
|
128 | 131 | from IPython.config.configurable import Configurable |
|
129 | 132 | from IPython.utils.traitlets import Int, Float, Unicode, Bool |
|
130 | 133 | |
|
131 | 134 | class MyClass(Configurable): |
|
132 | 135 | name = Unicode(u'defaultname', config=True) |
|
133 | 136 | ranking = Int(0, config=True) |
|
134 | 137 | value = Float(99.0) |
|
135 | 138 | # The rest of the class implementation would go here.. |
|
136 | 139 | |
|
137 | 140 | In this example, we see that :class:`MyClass` has three attributes, two |
|
138 | 141 | of whom (``name``, ``ranking``) can be configured. All of the attributes |
|
139 | 142 | are given types and default values. If a :class:`MyClass` is instantiated, |
|
140 | 143 | but not configured, these default values will be used. But let's see how |
|
141 | 144 | to configure this class in a configuration file:: |
|
142 | 145 | |
|
143 | 146 | # Sample config file |
|
144 | 147 | c = get_config() |
|
145 | 148 | |
|
146 | 149 | c.MyClass.name = 'coolname' |
|
147 | 150 | c.MyClass.ranking = 10 |
|
148 | 151 | |
|
149 | 152 | After this configuration file is loaded, the values set in it will override |
|
150 | 153 | the class defaults anytime a :class:`MyClass` is created. Furthermore, |
|
151 | 154 | these attributes will be type checked and validated anytime they are set. |
|
152 | 155 | This type checking is handled by the :mod:`IPython.utils.traitlets` module, |
|
153 | 156 | which provides the :class:`Unicode`, :class:`Int` and :class:`Float` types. |
|
154 | 157 | In addition to these traitlets, the :mod:`IPython.utils.traitlets` provides |
|
155 | 158 | traitlets for a number of other types. |
|
156 | 159 | |
|
157 | 160 | .. note:: |
|
158 | 161 | |
|
159 | 162 | Underneath the hood, the :class:`Configurable` base class is a subclass of |
|
160 | 163 | :class:`IPython.utils.traitlets.HasTraits`. The |
|
161 | 164 | :mod:`IPython.utils.traitlets` module is a lightweight version of |
|
162 | 165 | :mod:`enthought.traits`. Our implementation is a pure Python subset |
|
163 | 166 | (mostly API compatible) of :mod:`enthought.traits` that does not have any |
|
164 | 167 | of the automatic GUI generation capabilities. Our plan is to achieve 100% |
|
165 | 168 | API compatibility to enable the actual :mod:`enthought.traits` to |
|
166 | 169 | eventually be used instead. Currently, we cannot use |
|
167 | 170 | :mod:`enthought.traits` as we are committed to the core of IPython being |
|
168 | 171 | pure Python. |
|
169 | 172 | |
|
170 | 173 | It should be very clear at this point what the naming convention is for |
|
171 | 174 | configuration attributes:: |
|
172 | 175 | |
|
173 | 176 | c.ClassName.attribute_name = attribute_value |
|
174 | 177 | |
|
175 | 178 | Here, ``ClassName`` is the name of the class whose configuration attribute you |
|
176 | 179 | want to set, ``attribute_name`` is the name of the attribute you want to set |
|
177 | 180 | and ``attribute_value`` the the value you want it to have. The ``ClassName`` |
|
178 | 181 | attribute of ``c`` is not the actual class, but instead is another |
|
179 | 182 | :class:`~IPython.config.loader.Config` instance. |
|
180 | 183 | |
|
181 | 184 | .. note:: |
|
182 | 185 | |
|
183 | 186 | The careful reader may wonder how the ``ClassName`` (``MyClass`` in |
|
184 | 187 | the above example) attribute of the configuration object ``c`` gets |
|
185 | 188 | created. These attributes are created on the fly by the |
|
186 | 189 | :class:`~IPython.config.loader.Config` instance, using a simple naming |
|
187 | 190 | convention. Any attribute of a :class:`~IPython.config.loader.Config` |
|
188 | 191 | instance whose name begins with an uppercase character is assumed to be a |
|
189 | 192 | sub-configuration and a new empty :class:`~IPython.config.loader.Config` |
|
190 | 193 | instance is dynamically created for that attribute. This allows deeply |
|
191 | 194 | hierarchical information created easily (``c.Foo.Bar.value``) on the fly. |
|
192 | 195 | |
|
193 | 196 | Configuration files inheritance |
|
194 | 197 | =============================== |
|
195 | 198 | |
|
196 | 199 | Let's say you want to have different configuration files for various purposes. |
|
197 | 200 | Our configuration system makes it easy for one configuration file to inherit |
|
198 | 201 | the information in another configuration file. The :func:`load_subconfig` |
|
199 | 202 | command can be used in a configuration file for this purpose. Here is a simple |
|
200 | 203 | example that loads all of the values from the file :file:`base_config.py`:: |
|
201 | 204 | |
|
202 | 205 | # base_config.py |
|
203 | 206 | c = get_config() |
|
204 | 207 | c.MyClass.name = 'coolname' |
|
205 | 208 | c.MyClass.ranking = 100 |
|
206 | 209 | |
|
207 | 210 | into the configuration file :file:`main_config.py`:: |
|
208 | 211 | |
|
209 | 212 | # main_config.py |
|
210 | 213 | c = get_config() |
|
211 | 214 | |
|
212 | 215 | # Load everything from base_config.py |
|
213 | 216 | load_subconfig('base_config.py') |
|
214 | 217 | |
|
215 | 218 | # Now override one of the values |
|
216 | 219 | c.MyClass.name = 'bettername' |
|
217 | 220 | |
|
218 | 221 | In a situation like this the :func:`load_subconfig` makes sure that the |
|
219 | 222 | search path for sub-configuration files is inherited from that of the parent. |
|
220 | 223 | Thus, you can typically put the two in the same directory and everything will |
|
221 | 224 | just work. |
|
222 | 225 | |
|
223 | 226 | You can also load configuration files by profile, for instance: |
|
224 | 227 | |
|
225 | 228 | .. sourcecode:: python |
|
226 | 229 | |
|
227 | 230 | load_subconfig('ipython_config.py', profile='default') |
|
228 | 231 | |
|
229 | 232 | to inherit your default configuration as a starting point. |
|
230 | 233 | |
|
231 | 234 | |
|
232 | 235 | Class based configuration inheritance |
|
233 | 236 | ===================================== |
|
234 | 237 | |
|
235 | 238 | There is another aspect of configuration where inheritance comes into play. |
|
236 | 239 | Sometimes, your classes will have an inheritance hierarchy that you want |
|
237 | 240 | to be reflected in the configuration system. Here is a simple example:: |
|
238 | 241 | |
|
239 | 242 | from IPython.config.configurable import Configurable |
|
240 | 243 | from IPython.utils.traitlets import Int, Float, Unicode, Bool |
|
241 | 244 | |
|
242 | 245 | class Foo(Configurable): |
|
243 | 246 | name = Unicode(u'fooname', config=True) |
|
244 | 247 | value = Float(100.0, config=True) |
|
245 | 248 | |
|
246 | 249 | class Bar(Foo): |
|
247 | 250 | name = Unicode(u'barname', config=True) |
|
248 | 251 | othervalue = Int(0, config=True) |
|
249 | 252 | |
|
250 | 253 | Now, we can create a configuration file to configure instances of :class:`Foo` |
|
251 | 254 | and :class:`Bar`:: |
|
252 | 255 | |
|
253 | 256 | # config file |
|
254 | 257 | c = get_config() |
|
255 | 258 | |
|
256 | 259 | c.Foo.name = u'bestname' |
|
257 | 260 | c.Bar.othervalue = 10 |
|
258 | 261 | |
|
259 | 262 | This class hierarchy and configuration file accomplishes the following: |
|
260 | 263 | |
|
261 | 264 | * The default value for :attr:`Foo.name` and :attr:`Bar.name` will be |
|
262 | 265 | 'bestname'. Because :class:`Bar` is a :class:`Foo` subclass it also |
|
263 | 266 | picks up the configuration information for :class:`Foo`. |
|
264 | 267 | * The default value for :attr:`Foo.value` and :attr:`Bar.value` will be |
|
265 | 268 | ``100.0``, which is the value specified as the class default. |
|
266 | 269 | * The default value for :attr:`Bar.othervalue` will be 10 as set in the |
|
267 | 270 | configuration file. Because :class:`Foo` is the parent of :class:`Bar` |
|
268 | 271 | it doesn't know anything about the :attr:`othervalue` attribute. |
|
269 | 272 | |
|
270 | 273 | |
|
271 | 274 | .. _ipython_dir: |
|
272 | 275 | |
|
273 | 276 | Configuration file location |
|
274 | 277 | =========================== |
|
275 | 278 | |
|
276 | 279 | So where should you put your configuration files? IPython uses "profiles" for |
|
277 | 280 | configuration, and by default, all profiles will be stored in the so called |
|
278 | 281 | "IPython directory". The location of this directory is determined by the |
|
279 | 282 | following algorithm: |
|
280 | 283 | |
|
281 | 284 | * If the ``ipython_dir`` command line flag is given, its value is used. |
|
282 | 285 | |
|
283 | 286 | * If not, the value returned by :func:`IPython.utils.path.get_ipython_dir` |
|
284 | 287 | is used. This function will first look at the :envvar:`IPYTHON_DIR` |
|
285 | 288 | environment variable and then default to a platform-specific default. |
|
286 | 289 | |
|
287 | 290 | On posix systems (Linux, Unix, etc.), IPython respects the ``$XDG_CONFIG_HOME`` |
|
288 | 291 | part of the `XDG Base Directory`_ specification. If ``$XDG_CONFIG_HOME`` is |
|
289 | 292 | defined and exists ( ``XDG_CONFIG_HOME`` has a default interpretation of |
|
290 | 293 | :file:`$HOME/.config`), then IPython's config directory will be located in |
|
291 | 294 | :file:`$XDG_CONFIG_HOME/ipython`. If users still have an IPython directory |
|
292 | 295 | in :file:`$HOME/.ipython`, then that will be used. in preference to the |
|
293 | 296 | system default. |
|
294 | 297 | |
|
295 | 298 | For most users, the default value will simply be something like |
|
296 | 299 | :file:`$HOME/.config/ipython` on Linux, or :file:`$HOME/.ipython` |
|
297 | 300 | elsewhere. |
|
298 | 301 | |
|
299 | 302 | Once the location of the IPython directory has been determined, you need to know |
|
300 | 303 | which profile you are using. For users with a single configuration, this will |
|
301 | 304 | simply be 'default', and will be located in |
|
302 | 305 | :file:`<IPYTHON_DIR>/profile_default`. |
|
303 | 306 | |
|
304 | 307 | The next thing you need to know is what to call your configuration file. The |
|
305 | 308 | basic idea is that each application has its own default configuration filename. |
|
306 | 309 | The default named used by the :command:`ipython` command line program is |
|
307 | 310 | :file:`ipython_config.py`, and *all* IPython applications will use this file. |
|
308 | 311 | Other applications, such as the parallel :command:`ipcluster` scripts or the |
|
309 | 312 | QtConsole will load their own config files *after* :file:`ipython_config.py`. To |
|
310 | 313 | load a particular configuration file instead of the default, the name can be |
|
311 | 314 | overridden by the ``config_file`` command line flag. |
|
312 | 315 | |
|
313 | 316 | To generate the default configuration files, do:: |
|
314 | 317 | |
|
315 | 318 | $> ipython profile create |
|
316 | 319 | |
|
317 | 320 | and you will have a default :file:`ipython_config.py` in your IPython directory |
|
318 | 321 | under :file:`profile_default`. If you want the default config files for the |
|
319 | 322 | :mod:`IPython.parallel` applications, add ``--parallel`` to the end of the |
|
320 | 323 | command-line args. |
|
321 | 324 | |
|
322 | 325 | .. _Profiles: |
|
323 | 326 | |
|
324 | 327 | Profiles |
|
325 | 328 | ======== |
|
326 | 329 | |
|
327 | 330 | A profile is a directory containing configuration and runtime files, such as |
|
328 | 331 | logs, connection info for the parallel apps, and your IPython command history. |
|
329 | 332 | |
|
330 | 333 | The idea is that users often want to maintain a set of configuration files for |
|
331 | 334 | different purposes: one for doing numerical computing with NumPy and SciPy and |
|
332 | 335 | another for doing symbolic computing with SymPy. Profiles make it easy to keep a |
|
333 | 336 | separate configuration files, logs, and histories for each of these purposes. |
|
334 | 337 | |
|
335 | 338 | Let's start by showing how a profile is used: |
|
336 | 339 | |
|
337 | 340 | .. code-block:: bash |
|
338 | 341 | |
|
339 | 342 | $ ipython --profile=sympy |
|
340 | 343 | |
|
341 | 344 | This tells the :command:`ipython` command line program to get its configuration |
|
342 | 345 | from the "sympy" profile. The file names for various profiles do not change. The |
|
343 | 346 | only difference is that profiles are named in a special way. In the case above, |
|
344 | 347 | the "sympy" profile means looking for :file:`ipython_config.py` in :file:`<IPYTHON_DIR>/profile_sympy`. |
|
345 | 348 | |
|
346 | 349 | The general pattern is this: simply create a new profile with: |
|
347 | 350 | |
|
348 | 351 | .. code-block:: bash |
|
349 | 352 | |
|
350 | 353 | ipython profile create <name> |
|
351 | 354 | |
|
352 | 355 | which adds a directory called ``profile_<name>`` to your IPython directory. Then |
|
353 | 356 | you can load this profile by adding ``--profile=<name>`` to your command line |
|
354 | 357 | options. Profiles are supported by all IPython applications. |
|
355 | 358 | |
|
356 | 359 | IPython ships with some sample profiles in :file:`IPython/config/profile`. If |
|
357 | 360 | you create profiles with the name of one of our shipped profiles, these config |
|
358 | 361 | files will be copied over instead of starting with the automatically generated |
|
359 | 362 | config files. |
|
360 | 363 | |
|
361 | 364 | Security Files |
|
362 | 365 | -------------- |
|
363 | 366 | |
|
364 | 367 | If you are using the notebook, qtconsole, or parallel code, IPython stores |
|
365 | 368 | connection information in small JSON files in the active profile's security |
|
366 | 369 | directory. This directory is made private, so only you can see the files inside. If |
|
367 | 370 | you need to move connection files around to other computers, this is where they will |
|
368 | 371 | be. If you want your code to be able to open security files by name, we have a |
|
369 | 372 | convenience function :func:`IPython.utils.path.get_security_file`, which will return |
|
370 | 373 | the absolute path to a security file from its filename and [optionally] profile |
|
371 | 374 | name. |
|
372 | 375 | |
|
373 | 376 | Startup Files |
|
374 | 377 | ------------- |
|
375 | 378 | |
|
376 | 379 | If you want some code to be run at the beginning of every IPython session with a |
|
377 | 380 | particular profile, the easiest way is to add Python (.py) or IPython (.ipy) scripts |
|
378 | 381 | to your :file:`<profile>/startup` directory. Files in this directory will always be |
|
379 | 382 | executed as soon as the IPython shell is constructed, and before any other code or |
|
380 | 383 | scripts you have specified. If you have multiple files in the startup directory, |
|
381 | 384 | they will be run in lexicographical order, so you can control the ordering by adding |
|
382 | 385 | a '00-' prefix. |
|
383 | 386 | |
|
384 | 387 | .. note:: |
|
385 | 388 | |
|
386 | 389 | Automatic startup files are new in IPython 0.12. Use the |
|
387 | 390 | InteractiveShellApp.exec_files configurable for similar behavior in 0.11. |
|
388 | 391 | |
|
389 | 392 | |
|
390 | 393 | .. _commandline: |
|
391 | 394 | |
|
392 | 395 | Command-line arguments |
|
393 | 396 | ====================== |
|
394 | 397 | |
|
395 | 398 | IPython exposes *all* configurable options on the command-line. The command-line |
|
396 | 399 | arguments are generated from the Configurable traits of the classes associated |
|
397 | 400 | with a given Application. Configuring IPython from the command-line may look |
|
398 | 401 | very similar to an IPython config file |
|
399 | 402 | |
|
400 | 403 | IPython applications use a parser called |
|
401 | 404 | :class:`~IPython.config.loader.KeyValueLoader` to load values into a Config |
|
402 | 405 | object. Values are assigned in much the same way as in a config file: |
|
403 | 406 | |
|
404 | 407 | .. code-block:: bash |
|
405 | 408 | |
|
406 | 409 | $> ipython --InteractiveShell.use_readline=False --BaseIPythonApplication.profile='myprofile' |
|
407 | 410 | |
|
408 | 411 | Is the same as adding: |
|
409 | 412 | |
|
410 | 413 | .. sourcecode:: python |
|
411 | 414 | |
|
412 | 415 | c.InteractiveShell.use_readline=False |
|
413 | 416 | c.BaseIPythonApplication.profile='myprofile' |
|
414 | 417 | |
|
415 | 418 | to your config file. Key/Value arguments *always* take a value, separated by '=' |
|
416 | 419 | and no spaces. |
|
417 | 420 | |
|
418 | 421 | Common Arguments |
|
419 | 422 | **************** |
|
420 | 423 | |
|
421 | 424 | Since the strictness and verbosity of the KVLoader above are not ideal for everyday |
|
422 | 425 | use, common arguments can be specified as flags_ or aliases_. |
|
423 | 426 | |
|
424 | 427 | Flags and Aliases are handled by :mod:`argparse` instead, allowing for more flexible |
|
425 | 428 | parsing. In general, flags and aliases are prefixed by ``--``, except for those |
|
426 | 429 | that are single characters, in which case they can be specified with a single ``-``, e.g.: |
|
427 | 430 | |
|
428 | 431 | .. code-block:: bash |
|
429 | 432 | |
|
430 | 433 | $> ipython -i -c "import numpy; x=numpy.linspace(0,1)" --profile testing --colors=lightbg |
|
431 | 434 | |
|
432 | 435 | Aliases |
|
433 | 436 | ------- |
|
434 | 437 | |
|
435 | 438 | For convenience, applications have a mapping of commonly used traits, so you don't have |
|
436 | 439 | to specify the whole class name: |
|
437 | 440 | |
|
438 | 441 | .. code-block:: bash |
|
439 | 442 | |
|
440 | 443 | $> ipython --profile myprofile |
|
441 | 444 | # and |
|
442 | 445 | $> ipython --profile='myprofile' |
|
443 | 446 | # are equivalent to |
|
444 | 447 | $> ipython --BaseIPythonApplication.profile='myprofile' |
|
445 | 448 | |
|
446 | 449 | Flags |
|
447 | 450 | ----- |
|
448 | 451 | |
|
449 | 452 | Applications can also be passed **flags**. Flags are options that take no |
|
450 | 453 | arguments. They are simply wrappers for |
|
451 | 454 | setting one or more configurables with predefined values, often True/False. |
|
452 | 455 | |
|
453 | 456 | For instance: |
|
454 | 457 | |
|
455 | 458 | .. code-block:: bash |
|
456 | 459 | |
|
457 | 460 | $> ipcontroller --debug |
|
458 | 461 | # is equivalent to |
|
459 | 462 | $> ipcontroller --Application.log_level=DEBUG |
|
460 | 463 | # and |
|
461 | 464 | $> ipython --pylab |
|
462 | 465 | # is equivalent to |
|
463 | 466 | $> ipython --pylab=auto |
|
464 | 467 | # or |
|
465 | 468 | $> ipython --no-banner |
|
466 | 469 | # is equivalent to |
|
467 | 470 | $> ipython --TerminalIPythonApp.display_banner=False |
|
468 | 471 | |
|
469 | 472 | Subcommands |
|
470 | 473 | *********** |
|
471 | 474 | |
|
472 | 475 | |
|
473 | 476 | Some IPython applications have **subcommands**. Subcommands are modeled after |
|
474 | 477 | :command:`git`, and are called with the form :command:`command subcommand |
|
475 | 478 | [...args]`. Currently, the QtConsole is a subcommand of terminal IPython: |
|
476 | 479 | |
|
477 | 480 | .. code-block:: bash |
|
478 | 481 | |
|
479 | 482 | $> ipython qtconsole --profile=myprofile |
|
480 | 483 | |
|
481 | 484 | and :command:`ipcluster` is simply a wrapper for its various subcommands (start, |
|
482 | 485 | stop, engines). |
|
483 | 486 | |
|
484 | 487 | .. code-block:: bash |
|
485 | 488 | |
|
486 | 489 | $> ipcluster start --profile=myprofile --n=4 |
|
487 | 490 | |
|
488 | 491 | |
|
489 | 492 | To see a list of the available aliases, flags, and subcommands for an IPython application, simply pass ``-h`` or ``--help``. And to see the full list of configurable options (*very* long), pass ``--help-all``. |
|
490 | 493 | |
|
491 | 494 | |
|
492 | 495 | Design requirements |
|
493 | 496 | =================== |
|
494 | 497 | |
|
495 | 498 | Here are the main requirements we wanted our configuration system to have: |
|
496 | 499 | |
|
497 | 500 | * Support for hierarchical configuration information. |
|
498 | 501 | |
|
499 | 502 | * Full integration with command line option parsers. Often, you want to read |
|
500 | 503 | a configuration file, but then override some of the values with command line |
|
501 | 504 | options. Our configuration system automates this process and allows each |
|
502 | 505 | command line option to be linked to a particular attribute in the |
|
503 | 506 | configuration hierarchy that it will override. |
|
504 | 507 | |
|
505 | 508 | * Configuration files that are themselves valid Python code. This accomplishes |
|
506 | 509 | many things. First, it becomes possible to put logic in your configuration |
|
507 | 510 | files that sets attributes based on your operating system, network setup, |
|
508 | 511 | Python version, etc. Second, Python has a super simple syntax for accessing |
|
509 | 512 | hierarchical data structures, namely regular attribute access |
|
510 | 513 | (``Foo.Bar.Bam.name``). Third, using Python makes it easy for users to |
|
511 | 514 | import configuration attributes from one configuration file to another. |
|
512 | 515 | Fourth, even though Python is dynamically typed, it does have types that can |
|
513 | 516 | be checked at runtime. Thus, a ``1`` in a config file is the integer '1', |
|
514 | 517 | while a ``'1'`` is a string. |
|
515 | 518 | |
|
516 | 519 | * A fully automated method for getting the configuration information to the |
|
517 | 520 | classes that need it at runtime. Writing code that walks a configuration |
|
518 | 521 | hierarchy to extract a particular attribute is painful. When you have |
|
519 | 522 | complex configuration information with hundreds of attributes, this makes |
|
520 | 523 | you want to cry. |
|
521 | 524 | |
|
522 | 525 | * Type checking and validation that doesn't require the entire configuration |
|
523 | 526 | hierarchy to be specified statically before runtime. Python is a very |
|
524 | 527 | dynamic language and you don't always know everything that needs to be |
|
525 | 528 | configured when a program starts. |
|
526 | 529 | |
|
527 | 530 | |
|
528 | 531 | .. _`XDG Base Directory`: http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html |
@@ -1,24 +1,22 b'' | |||
|
1 | 1 | .. _plugins_overview: |
|
2 | 2 | |
|
3 | 3 | =============== |
|
4 | 4 | IPython plugins |
|
5 | 5 | =============== |
|
6 | 6 | |
|
7 | 7 | IPython has a plugin mechanism that allows users to create new and custom |
|
8 | 8 | runtime components for IPython. Plugins are different from extensions: |
|
9 | 9 | |
|
10 | 10 | * Extensions are used to load plugins. |
|
11 |
* |
|
|
11 | * Plugins are a more advanced configuration system that gives you access | |
|
12 | 12 | to the running IPython instance. |
|
13 | * Plugins add entirely new capabilities to IPython. | |
|
14 | 13 | * Plugins are traited and configurable. |
|
15 | 14 | |
|
16 | At this point, our plugin system is brand new and the documentation is | |
|
17 |
|
|
|
18 | files: | |
|
15 | At this point, the documentation of our plugin system is minimal. If you are | |
|
16 | interested in creating a new plugin, see the following files: | |
|
19 | 17 | |
|
20 | 18 | * :file:`IPython/extensions/parallelmagic.py` |
|
21 | 19 | * :file:`IPython/extensions/autoreload.py` |
|
22 | * :file:`IPython/extensions/sympyprinting.py` | |
|
23 | 20 | |
|
24 |
As well as our documentation on the configuration system |
|
|
21 | As well as our documentation on the :ref:`configuration system <config_overview>` | |
|
22 | and :ref:`extensions <extensions_overview>`. |
General Comments 0
You need to be logged in to leave comments.
Login now