Show More
@@ -1,157 +1,146 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 | import warnings |
|
26 | 26 | |
|
27 | 27 | #----------------------------------------------------------------------------- |
|
28 | 28 | # Setup everything |
|
29 | 29 | #----------------------------------------------------------------------------- |
|
30 | 30 | |
|
31 | 31 | # Don't forget to also update setup.py when this changes! |
|
32 | 32 | v = sys.version_info |
|
33 | 33 | if v[:2] < (2,7) or (v[0] >= 3 and v[:2] < (3,3)): |
|
34 | 34 | raise ImportError('IPython requires Python version 2.7 or 3.3 or above.') |
|
35 | 35 | del v |
|
36 | 36 | |
|
37 | 37 | # Make it easy to import extensions - they are always directly on pythonpath. |
|
38 | 38 | # Therefore, non-IPython modules can be added to extensions directory. |
|
39 | 39 | # This should probably be in ipapp.py. |
|
40 | 40 | sys.path.append(os.path.join(os.path.dirname(__file__), "extensions")) |
|
41 | 41 | |
|
42 | 42 | #----------------------------------------------------------------------------- |
|
43 | 43 | # Setup the top level names |
|
44 | 44 | #----------------------------------------------------------------------------- |
|
45 | 45 | |
|
46 | 46 | from .core.getipython import get_ipython |
|
47 | 47 | from .core import release |
|
48 | 48 | from .core.application import Application |
|
49 | 49 | from .terminal.embed import embed |
|
50 | 50 | |
|
51 | 51 | from .core.interactiveshell import InteractiveShell |
|
52 | 52 | from .testing import test |
|
53 | 53 | from .utils.sysinfo import sys_info |
|
54 | 54 | from .utils.frame import extract_module_locals |
|
55 | 55 | |
|
56 | 56 | # Release data |
|
57 | 57 | __author__ = '%s <%s>' % (release.author, release.author_email) |
|
58 | 58 | __license__ = release.license |
|
59 | 59 | __version__ = release.version |
|
60 | 60 | version_info = release.version_info |
|
61 | 61 | |
|
62 | 62 | def embed_kernel(module=None, local_ns=None, **kwargs): |
|
63 | 63 | """Embed and start an IPython kernel in a given scope. |
|
64 | 64 | |
|
65 | 65 | If you don't want the kernel to initialize the namespace |
|
66 | 66 | from the scope of the surrounding function, |
|
67 | 67 | and/or you want to load full IPython configuration, |
|
68 | 68 | you probably want `IPython.start_kernel()` instead. |
|
69 | 69 | |
|
70 | 70 | Parameters |
|
71 | 71 | ---------- |
|
72 | 72 | module : ModuleType, optional |
|
73 | 73 | The module to load into IPython globals (default: caller) |
|
74 | 74 | local_ns : dict, optional |
|
75 | 75 | The namespace to load into IPython user namespace (default: caller) |
|
76 | 76 | |
|
77 | 77 | kwargs : various, optional |
|
78 | 78 | Further keyword args are relayed to the IPKernelApp constructor, |
|
79 | 79 | allowing configuration of the Kernel. Will only have an effect |
|
80 | 80 | on the first embed_kernel call for a given process. |
|
81 | 81 | """ |
|
82 | 82 | |
|
83 | 83 | (caller_module, caller_locals) = extract_module_locals(1) |
|
84 | 84 | if module is None: |
|
85 | 85 | module = caller_module |
|
86 | 86 | if local_ns is None: |
|
87 | 87 | local_ns = caller_locals |
|
88 | 88 | |
|
89 | 89 | # Only import .zmq when we really need it |
|
90 | 90 | from ipykernel.embed import embed_kernel as real_embed_kernel |
|
91 | 91 | real_embed_kernel(module=module, local_ns=local_ns, **kwargs) |
|
92 | 92 | |
|
93 | 93 | def start_ipython(argv=None, **kwargs): |
|
94 | 94 | """Launch a normal IPython instance (as opposed to embedded) |
|
95 | 95 | |
|
96 | 96 | `IPython.embed()` puts a shell in a particular calling scope, |
|
97 | 97 | such as a function or method for debugging purposes, |
|
98 | 98 | which is often not desirable. |
|
99 | 99 | |
|
100 | 100 | `start_ipython()` does full, regular IPython initialization, |
|
101 | 101 | including loading startup files, configuration, etc. |
|
102 | 102 | much of which is skipped by `embed()`. |
|
103 | 103 | |
|
104 | 104 | This is a public API method, and will survive implementation changes. |
|
105 | 105 | |
|
106 | 106 | Parameters |
|
107 | 107 | ---------- |
|
108 | 108 | |
|
109 | 109 | argv : list or None, optional |
|
110 | 110 | If unspecified or None, IPython will parse command-line options from sys.argv. |
|
111 | 111 | To prevent any command-line parsing, pass an empty list: `argv=[]`. |
|
112 | 112 | user_ns : dict, optional |
|
113 | 113 | specify this dictionary to initialize the IPython user namespace with particular values. |
|
114 | 114 | kwargs : various, optional |
|
115 | 115 | Any other kwargs will be passed to the Application constructor, |
|
116 | 116 | such as `config`. |
|
117 | 117 | """ |
|
118 | 118 | from IPython.terminal.ipapp import launch_new_instance |
|
119 | 119 | return launch_new_instance(argv=argv, **kwargs) |
|
120 | 120 | |
|
121 | 121 | def start_kernel(argv=None, **kwargs): |
|
122 | 122 | """Launch a normal IPython kernel instance (as opposed to embedded) |
|
123 | 123 | |
|
124 | 124 | `IPython.embed_kernel()` puts a shell in a particular calling scope, |
|
125 | 125 | such as a function or method for debugging purposes, |
|
126 | 126 | which is often not desirable. |
|
127 | 127 | |
|
128 | 128 | `start_kernel()` does full, regular IPython initialization, |
|
129 | 129 | including loading startup files, configuration, etc. |
|
130 | 130 | much of which is skipped by `embed()`. |
|
131 | 131 | |
|
132 | 132 | Parameters |
|
133 | 133 | ---------- |
|
134 | 134 | |
|
135 | 135 | argv : list or None, optional |
|
136 | 136 | If unspecified or None, IPython will parse command-line options from sys.argv. |
|
137 | 137 | To prevent any command-line parsing, pass an empty list: `argv=[]`. |
|
138 | 138 | user_ns : dict, optional |
|
139 | 139 | specify this dictionary to initialize the IPython user namespace with particular values. |
|
140 | 140 | kwargs : various, optional |
|
141 | 141 | Any other kwargs will be passed to the Application constructor, |
|
142 | 142 | such as `config`. |
|
143 | 143 | """ |
|
144 | 144 | from IPython.kernel.zmq.kernelapp import launch_new_instance |
|
145 | 145 | return launch_new_instance(argv=argv, **kwargs) |
|
146 | 146 | |
|
147 | # deprecated shim for IPython.Config | |
|
148 | import traitlets.config | |
|
149 | class Config(traitlets.config.Config): | |
|
150 | def __init__(self, *args, **kwargs): | |
|
151 | warnings.warn( | |
|
152 | "IPython.Config is deprecated and will be removed in IPython 5." | |
|
153 | " Use traitlets.config.Config.", | |
|
154 | DeprecationWarning, stacklevel=2, | |
|
155 | ) | |
|
156 | super(Config, self).__init__(*args, **kwargs) | |
|
157 |
General Comments 0
You need to be logged in to leave comments.
Login now