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