Show More
@@ -1,114 +1,147 b'' | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | """ |
|
3 | 3 | IPython: tools for interactive and parallel computing in Python. |
|
4 | 4 | |
|
5 | 5 | http://ipython.org |
|
6 | 6 | """ |
|
7 | 7 | #----------------------------------------------------------------------------- |
|
8 | 8 | # Copyright (c) 2008-2011, IPython Development Team. |
|
9 | 9 | # Copyright (c) 2001-2007, Fernando Perez <fernando.perez@colorado.edu> |
|
10 | 10 | # Copyright (c) 2001, Janko Hauser <jhauser@zscout.de> |
|
11 | 11 | # Copyright (c) 2001, Nathaniel Gray <n8gray@caltech.edu> |
|
12 | 12 | # |
|
13 | 13 | # Distributed under the terms of the Modified BSD License. |
|
14 | 14 | # |
|
15 | 15 | # The full license is in the file COPYING.txt, distributed with this software. |
|
16 | 16 | #----------------------------------------------------------------------------- |
|
17 | 17 | |
|
18 | 18 | #----------------------------------------------------------------------------- |
|
19 | 19 | # Imports |
|
20 | 20 | #----------------------------------------------------------------------------- |
|
21 | 21 | from __future__ import absolute_import |
|
22 | 22 | |
|
23 | 23 | import os |
|
24 | 24 | import sys |
|
25 | 25 | |
|
26 | 26 | #----------------------------------------------------------------------------- |
|
27 | 27 | # Setup everything |
|
28 | 28 | #----------------------------------------------------------------------------- |
|
29 | 29 | |
|
30 | 30 | # Don't forget to also update setup.py when this changes! |
|
31 | 31 | if sys.version[0:3] < '2.6': |
|
32 | 32 | raise ImportError('Python Version 2.6 or above is required for IPython.') |
|
33 | 33 | |
|
34 | 34 | # Make it easy to import extensions - they are always directly on pythonpath. |
|
35 | 35 | # Therefore, non-IPython modules can be added to extensions directory. |
|
36 | 36 | # This should probably be in ipapp.py. |
|
37 | 37 | sys.path.append(os.path.join(os.path.dirname(__file__), "extensions")) |
|
38 | 38 | |
|
39 | 39 | #----------------------------------------------------------------------------- |
|
40 | 40 | # Setup the top level names |
|
41 | 41 | #----------------------------------------------------------------------------- |
|
42 | 42 | |
|
43 | 43 | from .config.loader import Config |
|
44 | 44 | from .core.getipython import get_ipython |
|
45 | 45 | from .core import release |
|
46 | 46 | from .core.application import Application |
|
47 | 47 | from .terminal.embed import embed |
|
48 | 48 | |
|
49 | 49 | from .core.error import TryNext |
|
50 | 50 | from .core.interactiveshell import InteractiveShell |
|
51 | 51 | from .testing import test |
|
52 | 52 | from .utils.sysinfo import sys_info |
|
53 | 53 | from .utils.frame import extract_module_locals |
|
54 | 54 | |
|
55 | 55 | # Release data |
|
56 | 56 | __author__ = '%s <%s>' % (release.author, release.author_email) |
|
57 | 57 | __license__ = release.license |
|
58 | 58 | __version__ = release.version |
|
59 | 59 | version_info = release.version_info |
|
60 | 60 | |
|
61 | 61 | def embed_kernel(module=None, local_ns=None, **kwargs): |
|
62 | 62 | """Embed and start an IPython kernel in a given scope. |
|
63 | 63 | |
|
64 | If you don't want the kernel to initialize the namespace | |
|
65 | from the scope of the surrounding function, | |
|
66 | and/or you want to load full IPython configuration, | |
|
67 | you probably want `IPython.start_kernel()` instead. | |
|
68 | ||
|
69 | ||
|
64 | 70 | Parameters |
|
65 | 71 | ---------- |
|
66 | 72 | module : ModuleType, optional |
|
67 | 73 | The module to load into IPython globals (default: caller) |
|
68 | 74 | local_ns : dict, optional |
|
69 | 75 | The namespace to load into IPython user namespace (default: caller) |
|
70 | 76 | |
|
71 | 77 | kwargs : various, optional |
|
72 | 78 | Further keyword args are relayed to the IPKernelApp constructor, |
|
73 | 79 | allowing configuration of the Kernel. Will only have an effect |
|
74 | 80 | on the first embed_kernel call for a given process. |
|
75 | 81 | |
|
76 | 82 | """ |
|
77 | 83 | |
|
78 | 84 | (caller_module, caller_locals) = extract_module_locals(1) |
|
79 | 85 | if module is None: |
|
80 | 86 | module = caller_module |
|
81 | 87 | if local_ns is None: |
|
82 | 88 | local_ns = caller_locals |
|
83 | 89 | |
|
84 | 90 | # Only import .zmq when we really need it |
|
85 | 91 | from IPython.kernel.zmq.embed import embed_kernel as real_embed_kernel |
|
86 | 92 | real_embed_kernel(module=module, local_ns=local_ns, **kwargs) |
|
87 | 93 | |
|
88 | 94 | def start_ipython(argv=None, **kwargs): |
|
89 | 95 | """Launch a normal IPython instance (as opposed to embedded) |
|
90 | 96 | |
|
91 | 97 | `IPython.embed()` puts a shell in a particular calling scope, |
|
92 | 98 | such as a function or method for debugging purposes, |
|
93 | 99 | which is often not desirable. |
|
94 | 100 | |
|
95 | 101 | `start_ipython()` does full, regular IPython initialization, |
|
96 | 102 | including loading startup files, configuration, etc. |
|
97 | 103 | much of which is skipped by `embed()`. |
|
98 | 104 | |
|
99 | 105 | This is a public API method, and will survive implementation changes. |
|
100 | 106 | |
|
101 | 107 | Parameters |
|
102 | 108 | ---------- |
|
103 | 109 | |
|
104 | 110 | argv : list or None, optional |
|
105 | 111 | If unspecified or None, IPython will parse command-line options from sys.argv. |
|
106 | 112 | To prevent any command-line parsing, pass an empty list: `argv=[]`. |
|
107 | 113 | user_ns : dict, optional |
|
108 | 114 | specify this dictionary to initialize the IPython user namespace with particular values. |
|
109 | 115 | kwargs : various, optional |
|
110 | 116 | Any other kwargs will be passed to the Application constructor, |
|
111 | 117 | such as `config`. |
|
112 | 118 | """ |
|
113 | 119 | from IPython.terminal.ipapp import launch_new_instance |
|
114 | 120 | return launch_new_instance(argv=argv, **kwargs) |
|
121 | ||
|
122 | def start_kernel(argv=None, **kwargs): | |
|
123 | """Launch a normal IPython kernel instance (as opposed to embedded) | |
|
124 | ||
|
125 | `IPython.embed_kernel()` puts a shell in a particular calling scope, | |
|
126 | such as a function or method for debugging purposes, | |
|
127 | which is often not desirable. | |
|
128 | ||
|
129 | `start_kernel()` does full, regular IPython initialization, | |
|
130 | including loading startup files, configuration, etc. | |
|
131 | much of which is skipped by `embed()`. | |
|
132 | ||
|
133 | Parameters | |
|
134 | ---------- | |
|
135 | ||
|
136 | argv : list or None, optional | |
|
137 | If unspecified or None, IPython will parse command-line options from sys.argv. | |
|
138 | To prevent any command-line parsing, pass an empty list: `argv=[]`. | |
|
139 | user_ns : dict, optional | |
|
140 | specify this dictionary to initialize the IPython user namespace with particular values. | |
|
141 | kwargs : various, optional | |
|
142 | Any other kwargs will be passed to the Application constructor, | |
|
143 | such as `config`. | |
|
144 | """ | |
|
145 | from IPython.kernel.zmq.kernelapp import launch_new_instance | |
|
146 | return launch_new_instance(argv=argv, **kwargs) | |
|
147 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now