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