|
@@
-1,144
+1,151
b''
|
|
1
|
1
|
"""
|
|
2
|
2
|
IPython: tools for interactive and parallel computing in Python.
|
|
3
|
3
|
|
|
4
|
4
|
https://ipython.org
|
|
5
|
5
|
"""
|
|
6
|
6
|
#-----------------------------------------------------------------------------
|
|
7
|
7
|
# Copyright (c) 2008-2011, IPython Development Team.
|
|
8
|
8
|
# Copyright (c) 2001-2007, Fernando Perez <fernando.perez@colorado.edu>
|
|
9
|
9
|
# Copyright (c) 2001, Janko Hauser <jhauser@zscout.de>
|
|
10
|
10
|
# Copyright (c) 2001, Nathaniel Gray <n8gray@caltech.edu>
|
|
11
|
11
|
#
|
|
12
|
12
|
# Distributed under the terms of the Modified BSD License.
|
|
13
|
13
|
#
|
|
14
|
14
|
# The full license is in the file COPYING.txt, distributed with this software.
|
|
15
|
15
|
#-----------------------------------------------------------------------------
|
|
16
|
16
|
|
|
17
|
17
|
#-----------------------------------------------------------------------------
|
|
18
|
18
|
# Imports
|
|
19
|
19
|
#-----------------------------------------------------------------------------
|
|
20
|
20
|
|
|
21
|
21
|
import os
|
|
22
|
22
|
import sys
|
|
23
|
23
|
|
|
24
|
24
|
#-----------------------------------------------------------------------------
|
|
25
|
25
|
# Setup everything
|
|
26
|
26
|
#-----------------------------------------------------------------------------
|
|
27
|
27
|
|
|
28
|
28
|
# Don't forget to also update setup.py when this changes!
|
|
29
|
29
|
if sys.version_info < (3, 8):
|
|
30
|
30
|
raise ImportError(
|
|
31
|
31
|
"""
|
|
32
|
32
|
IPython 8+ supports Python 3.8 and above, following NEP 29.
|
|
33
|
33
|
When using Python 2.7, please install IPython 5.x LTS Long Term Support version.
|
|
34
|
34
|
Python 3.3 and 3.4 were supported up to IPython 6.x.
|
|
35
|
35
|
Python 3.5 was supported with IPython 7.0 to 7.9.
|
|
36
|
36
|
Python 3.6 was supported with IPython up to 7.16.
|
|
37
|
37
|
Python 3.7 was still supported with the 7.x branch.
|
|
38
|
38
|
|
|
39
|
39
|
See IPython `README.rst` file for more information:
|
|
40
|
40
|
|
|
41
|
41
|
https://github.com/ipython/ipython/blob/master/README.rst
|
|
42
|
42
|
|
|
43
|
43
|
""")
|
|
44
|
44
|
|
|
45
|
45
|
#-----------------------------------------------------------------------------
|
|
46
|
46
|
# Setup the top level names
|
|
47
|
47
|
#-----------------------------------------------------------------------------
|
|
48
|
48
|
|
|
49
|
49
|
from .core.getipython import get_ipython
|
|
50
|
50
|
from .core import release
|
|
51
|
51
|
from .core.application import Application
|
|
52
|
52
|
from .terminal.embed import embed
|
|
53
|
53
|
|
|
54
|
54
|
from .core.interactiveshell import InteractiveShell
|
|
55
|
55
|
from .utils.sysinfo import sys_info
|
|
56
|
56
|
from .utils.frame import extract_module_locals
|
|
57
|
57
|
|
|
58
|
58
|
# Release data
|
|
59
|
59
|
__author__ = '%s <%s>' % (release.author, release.author_email)
|
|
60
|
60
|
__license__ = release.license
|
|
61
|
61
|
__version__ = release.version
|
|
62
|
62
|
version_info = release.version_info
|
|
63
|
63
|
|
|
64
|
64
|
def embed_kernel(module=None, local_ns=None, **kwargs):
|
|
65
|
65
|
"""Embed and start an IPython kernel in a given scope.
|
|
66
|
66
|
|
|
67
|
67
|
If you don't want the kernel to initialize the namespace
|
|
68
|
68
|
from the scope of the surrounding function,
|
|
69
|
69
|
and/or you want to load full IPython configuration,
|
|
70
|
70
|
you probably want `IPython.start_kernel()` instead.
|
|
71
|
71
|
|
|
72
|
72
|
Parameters
|
|
73
|
73
|
----------
|
|
74
|
74
|
module : types.ModuleType, optional
|
|
75
|
75
|
The module to load into IPython globals (default: caller)
|
|
76
|
76
|
local_ns : dict, optional
|
|
77
|
77
|
The namespace to load into IPython user namespace (default: caller)
|
|
78
|
78
|
**kwargs : various, optional
|
|
79
|
79
|
Further keyword args are relayed to the IPKernelApp constructor,
|
|
80
|
80
|
allowing configuration of the Kernel. Will only have an effect
|
|
81
|
81
|
on the first embed_kernel call for a given process.
|
|
82
|
82
|
"""
|
|
83
|
83
|
|
|
84
|
84
|
(caller_module, caller_locals) = extract_module_locals(1)
|
|
85
|
85
|
if module is None:
|
|
86
|
86
|
module = caller_module
|
|
87
|
87
|
if local_ns is None:
|
|
88
|
88
|
local_ns = caller_locals
|
|
89
|
89
|
|
|
90
|
90
|
# Only import .zmq when we really need it
|
|
91
|
91
|
from ipykernel.embed import embed_kernel as real_embed_kernel
|
|
92
|
92
|
real_embed_kernel(module=module, local_ns=local_ns, **kwargs)
|
|
93
|
93
|
|
|
94
|
94
|
def start_ipython(argv=None, **kwargs):
|
|
95
|
95
|
"""Launch a normal IPython instance (as opposed to embedded)
|
|
96
|
96
|
|
|
97
|
97
|
`IPython.embed()` puts a shell in a particular calling scope,
|
|
98
|
98
|
such as a function or method for debugging purposes,
|
|
99
|
99
|
which is often not desirable.
|
|
100
|
100
|
|
|
101
|
101
|
`start_ipython()` does full, regular IPython initialization,
|
|
102
|
102
|
including loading startup files, configuration, etc.
|
|
103
|
103
|
much of which is skipped by `embed()`.
|
|
104
|
104
|
|
|
105
|
105
|
This is a public API method, and will survive implementation changes.
|
|
106
|
106
|
|
|
107
|
107
|
Parameters
|
|
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
|
argv : list or None, optional
|
|
135
|
135
|
If unspecified or None, IPython will parse command-line options from sys.argv.
|
|
136
|
136
|
To prevent any command-line parsing, pass an empty list: `argv=[]`.
|
|
137
|
137
|
user_ns : dict, optional
|
|
138
|
138
|
specify this dictionary to initialize the IPython user namespace with particular values.
|
|
139
|
139
|
**kwargs : various, optional
|
|
140
|
140
|
Any other kwargs will be passed to the Application constructor,
|
|
141
|
141
|
such as `config`.
|
|
142
|
142
|
"""
|
|
143
|
|
from IPython.kernel.zmq.kernelapp import launch_new_instance
|
|
|
143
|
import warnings
|
|
|
144
|
|
|
|
145
|
warnings.warn(
|
|
|
146
|
"start_kernel is deprecated since IPython 8.0, use from `ipykernel.kernelapp.launch_new_instance`",
|
|
|
147
|
DeprecationWarning,
|
|
|
148
|
stacklevel=2,
|
|
|
149
|
)
|
|
|
150
|
from ipykernel.kernelapp import launch_new_instance
|
|
144
|
151
|
return launch_new_instance(argv=argv, **kwargs)
|