Show More
@@ -0,0 +1,61 b'' | |||
|
1 | .. _extensions_overview: | |
|
2 | ||
|
3 | ================== | |
|
4 | IPython extensions | |
|
5 | ================== | |
|
6 | ||
|
7 | Configuration files are just the first level of customization that IPython | |
|
8 | supports. The next level is that of extensions. An IPython extension is an | |
|
9 | importable Python module that has a a few special function. By defining these | |
|
10 | functions, users can customize IPython by accessing the actual runtime objects | |
|
11 | of IPython. Here is a sample extension:: | |
|
12 | ||
|
13 | # myextension.py | |
|
14 | ||
|
15 | def load_ipython_extension(ipython): | |
|
16 | # The ``ipython`` argument is the currently active | |
|
17 | # :class:`InteractiveShell` instance that can be used in any way. | |
|
18 | # This allows you do to things like register new magics, plugins or | |
|
19 | # aliases. | |
|
20 | ||
|
21 | def unload_ipython_extension(ipython): | |
|
22 | # If you want your extension to be unloadable, put that logic here. | |
|
23 | ||
|
24 | This :func:`load_ipython_extension` function is called after your extension is | |
|
25 | imported and the currently active :class:`InteractiveShell` instance is passed | |
|
26 | as the only argument. You can do anything you want with IPython at that point. | |
|
27 | ||
|
28 | The :func:`load_ipython_extension` will be called again is you load or reload | |
|
29 | the extension again. It is up to the extension author to add code to manage | |
|
30 | that. | |
|
31 | ||
|
32 | You can put your extension modules anywhere you want, as long as they can be | |
|
33 | imported by Python's standard import mechanism. However, to make it easy to | |
|
34 | write extensions, you can also put your extensions in | |
|
35 | ``os.path.join(self.ipython_dir, 'extensions')``. This directory is added to | |
|
36 | ``sys.path`` automatically. | |
|
37 | ||
|
38 | Using extensions | |
|
39 | ================ | |
|
40 | ||
|
41 | There are two ways you can tell IPython to use your extension: | |
|
42 | ||
|
43 | 1. Listing it in a configuration file. | |
|
44 | 2. Using the ``%load_ext`` magic function. | |
|
45 | ||
|
46 | To load an extension called :file:`myextension.py` add the following logic | |
|
47 | to your configuration file:: | |
|
48 | ||
|
49 | c.Global.extensions = [ | |
|
50 | 'myextension' | |
|
51 | ] | |
|
52 | ||
|
53 | To load that same extension at runtime, use the ``%load_ext`` magic:: | |
|
54 | ||
|
55 | .. sourcecode:: ipython | |
|
56 | ||
|
57 | In [1]: %load_ext myextension | |
|
58 | ||
|
59 | To summarize, in conjunction with configuration files and profiles, IPython | |
|
60 | extensions give you complete and flexible control over your IPython | |
|
61 | setup. |
@@ -0,0 +1,23 b'' | |||
|
1 | .. _plugins_overview: | |
|
2 | ||
|
3 | =============== | |
|
4 | IPython plugins | |
|
5 | =============== | |
|
6 | ||
|
7 | IPython has a plugin mechanism that allows users to create new and custom | |
|
8 | runtime components for IPython. Plugins are different from extensions: | |
|
9 | ||
|
10 | * Extensions are used to load plugins. | |
|
11 | * Extensions are a more advanced configuration system that gives you access | |
|
12 | to the running IPython instance. | |
|
13 | * Plugins add entirely new capabilities to IPython. | |
|
14 | * Plugins are traited and configurable. | |
|
15 | ||
|
16 | At this point, our plugin system is brand new and the documentation is | |
|
17 | minimal. If you are interested in creating a new plugin, see the following | |
|
18 | files: | |
|
19 | ||
|
20 | * :file:`IPython/extensions/parallemagic.py` | |
|
21 | * :file:`IPython/extensions/pretty.` | |
|
22 | ||
|
23 | As well as our documentation on the configuration system and extensions. |
@@ -1,13 +1,15 b'' | |||
|
1 | 1 | .. _config_index: |
|
2 | 2 | |
|
3 | 3 | =============================== |
|
4 | 4 | Configuration and customization |
|
5 | 5 | =============================== |
|
6 | 6 | |
|
7 | 7 | .. toctree:: |
|
8 | 8 | :maxdepth: 2 |
|
9 | 9 | |
|
10 | 10 | overview.txt |
|
11 | extensions.txt | |
|
12 | plugins.txt | |
|
11 | 13 | ipython.txt |
|
12 | 14 | editors.txt |
|
13 | 15 | old.txt |
@@ -1,136 +1,136 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 | 13 | is :file:`ipython_config.py`. By setting the attributes in this file, you |
|
14 | 14 | can configure the application. A sample is provided in |
|
15 | 15 | :mod:`IPython.config.default.ipython_config`. Simply copy this file to your |
|
16 | 16 | IPython directory to start using it. |
|
17 | 17 | |
|
18 | 18 | Most configuration attributes that this file accepts are associated with |
|
19 | 19 | classes that are subclasses of :class:`~IPython.core.component.Component`. |
|
20 | 20 | |
|
21 | 21 | A few configuration attributes are not associated with a particular |
|
22 | 22 | :class:`~IPython.core.component.Component` subclass. These are application |
|
23 | 23 | wide configuration attributes and are stored in the ``Global`` |
|
24 | 24 | sub-configuration section. We begin with a description of these |
|
25 | 25 | attributes. |
|
26 | 26 | |
|
27 | 27 | Global configuration |
|
28 | 28 | ==================== |
|
29 | 29 | |
|
30 | 30 | Assuming that your configuration file has the following at the top:: |
|
31 | 31 | |
|
32 | 32 | c = get_config() |
|
33 | 33 | |
|
34 | 34 | the following attributes can be set in the ``Global`` section. |
|
35 | 35 | |
|
36 | 36 | :attr:`c.Global.display_banner` |
|
37 | 37 | A boolean that determined if the banner is printer when :command:`ipython` |
|
38 | 38 | is started. |
|
39 | 39 | |
|
40 | 40 | :attr:`c.Global.classic` |
|
41 | 41 | A boolean that determines if IPython starts in "classic" mode. In this |
|
42 | 42 | mode, the prompts and everything mimic that of the normal :command:`python` |
|
43 | 43 | shell |
|
44 | 44 | |
|
45 | 45 | :attr:`c.Global.nosep` |
|
46 | 46 | A boolean that determines if there should be no blank lines between |
|
47 | 47 | prompts. |
|
48 | 48 | |
|
49 | 49 | :attr:`c.Global.log_level` |
|
50 | 50 | An integer that sets the detail of the logging level during the startup |
|
51 | 51 | of :command:`ipython`. The default is 30 and the possible values are |
|
52 | 52 | (0, 10, 20, 30, 40, 50). Higher is quieter and lower is more verbose. |
|
53 | 53 | |
|
54 | 54 | :attr:`c.Global.extensions` |
|
55 | 55 | A list of strings, each of which is an importable IPython extension. An |
|
56 | 56 | IPython extension is a regular Python module or package that has a |
|
57 | 57 | :func:`load_ipython_extension(ip)` method. This method gets called when |
|
58 | 58 | the extension is loaded with the currently running |
|
59 | 59 | :class:`~IPython.core.iplib.InteractiveShell` as its only argument. You |
|
60 | 60 | can put your extensions anywhere they can be imported but we add the |
|
61 | 61 | :file:`extensions` subdirectory of the ipython directory to ``sys.path`` |
|
62 | 62 | during extension loading, so you can put them there as well. Extensions |
|
63 | 63 | are not executed in the user's interactive namespace and they must be pure |
|
64 | 64 | Python code. Extensions are the recommended way of customizing |
|
65 | 65 | :command:`ipython`. Extensions can provide an |
|
66 | 66 | :func:`unload_ipython_extension` that will be called when the extension is |
|
67 | 67 | unloaded. |
|
68 | 68 | |
|
69 | 69 | :attr:`c.Global.exec_lines` |
|
70 | 70 | A list of strings, each of which is Python code that is run in the user's |
|
71 | 71 | namespace after IPython start. These lines can contain full IPython syntax |
|
72 | 72 | with magics, etc. |
|
73 | 73 | |
|
74 | 74 | :attr:`c.Global.exec_files` |
|
75 | 75 | A list of strings, each of which is the full pathname of a ``.py`` or |
|
76 | 76 | ``.ipy`` file that will be executed as IPython starts. These files are run |
|
77 | 77 | in IPython in the user's namespace. Files with a ``.py`` extension need to |
|
78 | 78 | be pure Python. Files with a ``.ipy`` extension can have custom IPython |
|
79 | 79 | syntax (magics, etc.). These files need to be in the cwd, the ipythondir |
|
80 | 80 | or be absolute paths. |
|
81 | 81 | |
|
82 | 82 | Classes that can be configured |
|
83 | 83 | ============================== |
|
84 | 84 | |
|
85 | 85 | The following classes can also be configured in the configuration file for |
|
86 | 86 | :command:`ipython`: |
|
87 | 87 | |
|
88 | 88 | * :class:`~IPython.core.iplib.InteractiveShell` |
|
89 | 89 | |
|
90 | 90 | * :class:`~IPython.core.prefilter.PrefilterManager` |
|
91 | 91 | |
|
92 | 92 | * :class:`~IPython.core.alias.AliasManager` |
|
93 | 93 | |
|
94 | 94 | To see which attributes of these classes are configurable, please see the |
|
95 | 95 | source code for these classes, the class docstrings or the sample |
|
96 | 96 | configuration file :mod:`IPython.config.default.ipython_config`. |
|
97 | 97 | |
|
98 | 98 | Example |
|
99 | 99 | ======= |
|
100 | 100 | |
|
101 | 101 | For those who want to get a quick start, here is a sample |
|
102 | 102 | :file:`ipython_config.py` that sets some of the common configuration |
|
103 | 103 | attributes:: |
|
104 | 104 | |
|
105 | 105 | # sample ipython_config.py |
|
106 | 106 | c = get_config() |
|
107 | 107 | |
|
108 | 108 | c.Global.display_banner = True |
|
109 | 109 | c.Global.log_level = 20 |
|
110 | 110 | c.Global.extensions = [ |
|
111 | 111 | 'myextension' |
|
112 | 112 | ] |
|
113 | 113 | c.Global.exec_lines = [ |
|
114 | 114 | 'import numpy', |
|
115 | 115 | 'import scipy' |
|
116 | 116 | ] |
|
117 | 117 | c.Global.exec_files = [ |
|
118 | 118 | 'mycode.py', |
|
119 | 119 | 'fancy.ipy' |
|
120 | 120 | ] |
|
121 | 121 | c.InteractiveShell.autoindent = True |
|
122 | 122 | c.InteractiveShell.colors = 'LightBG' |
|
123 | 123 | c.InteractiveShell.confirm_exit = False |
|
124 | 124 | c.InteractiveShell.deep_reload = True |
|
125 | 125 | c.InteractiveShell.editor = 'nano' |
|
126 | 126 | c.InteractiveShell.prompt_in1 = 'In [\#]: ' |
|
127 | 127 | c.InteractiveShell.prompt_in2 = ' .\D.: ' |
|
128 | 128 | c.InteractiveShell.prompt_out = 'Out[\#]: ' |
|
129 | 129 | c.InteractiveShell.prompts_pad_left = True |
|
130 | 130 | c.InteractiveShell.xmode = 'Context' |
|
131 | 131 | |
|
132 | 132 | c.PrefilterManager.multi_line_specials = True |
|
133 | 133 | |
|
134 | 134 | c.AliasManager.user_aliases = [ |
|
135 | 135 | ('la', 'ls -al') |
|
136 | ] No newline at end of file | |
|
136 | ] |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now