Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/IPython/__init__.py: 56%
32 statements
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 06:07 +0000
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 06:07 +0000
1# PYTHON_ARGCOMPLETE_OK
2"""
3IPython: tools for interactive and parallel computing in Python.
5https://ipython.org
6"""
7#-----------------------------------------------------------------------------
8# Copyright (c) 2008-2011, IPython Development Team.
9# Copyright (c) 2001-2007, Fernando Perez <fernando.perez@colorado.edu>
10# Copyright (c) 2001, Janko Hauser <jhauser@zscout.de>
11# Copyright (c) 2001, Nathaniel Gray <n8gray@caltech.edu>
12#
13# Distributed under the terms of the Modified BSD License.
14#
15# The full license is in the file COPYING.txt, distributed with this software.
16#-----------------------------------------------------------------------------
18#-----------------------------------------------------------------------------
19# Imports
20#-----------------------------------------------------------------------------
22import sys
24#-----------------------------------------------------------------------------
25# Setup everything
26#-----------------------------------------------------------------------------
28# Don't forget to also update setup.py when this changes!
29if sys.version_info < (3, 8):
30 raise ImportError(
31 """
32IPython 8+ supports Python 3.8 and above, following NEP 29.
33When using Python 2.7, please install IPython 5.x LTS Long Term Support version.
34Python 3.3 and 3.4 were supported up to IPython 6.x.
35Python 3.5 was supported with IPython 7.0 to 7.9.
36Python 3.6 was supported with IPython up to 7.16.
37Python 3.7 was still supported with the 7.x branch.
39See IPython `README.rst` file for more information:
41 https://github.com/ipython/ipython/blob/main/README.rst
43"""
44 )
46#-----------------------------------------------------------------------------
47# Setup the top level names
48#-----------------------------------------------------------------------------
50from .core.getipython import get_ipython
51from .core import release
52from .core.application import Application
53from .terminal.embed import embed
55from .core.interactiveshell import InteractiveShell
56from .utils.sysinfo import sys_info
57from .utils.frame import extract_module_locals
59# Release data
60__author__ = '%s <%s>' % (release.author, release.author_email)
61__license__ = release.license
62__version__ = release.version
63version_info = release.version_info
64# list of CVEs that should have been patched in this release.
65# this is informational and should not be relied upon.
66__patched_cves__ = {"CVE-2022-21699", "CVE-2023-24816"}
69def embed_kernel(module=None, local_ns=None, **kwargs):
70 """Embed and start an IPython kernel in a given scope.
72 If you don't want the kernel to initialize the namespace
73 from the scope of the surrounding function,
74 and/or you want to load full IPython configuration,
75 you probably want `IPython.start_kernel()` instead.
77 Parameters
78 ----------
79 module : types.ModuleType, optional
80 The module to load into IPython globals (default: caller)
81 local_ns : dict, optional
82 The namespace to load into IPython user namespace (default: caller)
83 **kwargs : various, optional
84 Further keyword args are relayed to the IPKernelApp constructor,
85 allowing configuration of the Kernel. Will only have an effect
86 on the first embed_kernel call for a given process.
87 """
89 (caller_module, caller_locals) = extract_module_locals(1)
90 if module is None:
91 module = caller_module
92 if local_ns is None:
93 local_ns = caller_locals
95 # Only import .zmq when we really need it
96 from ipykernel.embed import embed_kernel as real_embed_kernel
97 real_embed_kernel(module=module, local_ns=local_ns, **kwargs)
99def start_ipython(argv=None, **kwargs):
100 """Launch a normal IPython instance (as opposed to embedded)
102 `IPython.embed()` puts a shell in a particular calling scope,
103 such as a function or method for debugging purposes,
104 which is often not desirable.
106 `start_ipython()` does full, regular IPython initialization,
107 including loading startup files, configuration, etc.
108 much of which is skipped by `embed()`.
110 This is a public API method, and will survive implementation changes.
112 Parameters
113 ----------
114 argv : list or None, optional
115 If unspecified or None, IPython will parse command-line options from sys.argv.
116 To prevent any command-line parsing, pass an empty list: `argv=[]`.
117 user_ns : dict, optional
118 specify this dictionary to initialize the IPython user namespace with particular values.
119 **kwargs : various, optional
120 Any other kwargs will be passed to the Application constructor,
121 such as `config`.
122 """
123 from IPython.terminal.ipapp import launch_new_instance
124 return launch_new_instance(argv=argv, **kwargs)
126def start_kernel(argv=None, **kwargs):
127 """Launch a normal IPython kernel instance (as opposed to embedded)
129 `IPython.embed_kernel()` puts a shell in a particular calling scope,
130 such as a function or method for debugging purposes,
131 which is often not desirable.
133 `start_kernel()` does full, regular IPython initialization,
134 including loading startup files, configuration, etc.
135 much of which is skipped by `embed()`.
137 Parameters
138 ----------
139 argv : list or None, optional
140 If unspecified or None, IPython will parse command-line options from sys.argv.
141 To prevent any command-line parsing, pass an empty list: `argv=[]`.
142 user_ns : dict, optional
143 specify this dictionary to initialize the IPython user namespace with particular values.
144 **kwargs : various, optional
145 Any other kwargs will be passed to the Application constructor,
146 such as `config`.
147 """
148 import warnings
150 warnings.warn(
151 "start_kernel is deprecated since IPython 8.0, use from `ipykernel.kernelapp.launch_new_instance`",
152 DeprecationWarning,
153 stacklevel=2,
154 )
155 from ipykernel.kernelapp import launch_new_instance
156 return launch_new_instance(argv=argv, **kwargs)