Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.9/dist-packages/IPython/__init__.py: 58%
33 statements
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-25 06:05 +0000
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-25 06:05 +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, 9):
30 raise ImportError(
31 """
32IPython 8.13+ supports Python 3.9 and above, following NEP 29.
33IPython 8.0-8.12 supports Python 3.8 and above, following NEP 29.
34When using Python 2.7, please install IPython 5.x LTS Long Term Support version.
35Python 3.3 and 3.4 were supported up to IPython 6.x.
36Python 3.5 was supported with IPython 7.0 to 7.9.
37Python 3.6 was supported with IPython up to 7.16.
38Python 3.7 was still supported with the 7.x branch.
40See IPython `README.rst` file for more information:
42 https://github.com/ipython/ipython/blob/main/README.rst
44"""
45 )
47#-----------------------------------------------------------------------------
48# Setup the top level names
49#-----------------------------------------------------------------------------
51from .core.getipython import get_ipython
52from .core import release
53from .core.application import Application
54from .terminal.embed import embed
56from .core.interactiveshell import InteractiveShell
57from .utils.sysinfo import sys_info
58from .utils.frame import extract_module_locals
60__all__ = ["start_ipython", "embed", "start_kernel", "embed_kernel"]
62# Release data
63__author__ = '%s <%s>' % (release.author, release.author_email)
64__license__ = release.license
65__version__ = release.version
66version_info = release.version_info
67# list of CVEs that should have been patched in this release.
68# this is informational and should not be relied upon.
69__patched_cves__ = {"CVE-2022-21699", "CVE-2023-24816"}
72def embed_kernel(module=None, local_ns=None, **kwargs):
73 """Embed and start an IPython kernel in a given scope.
75 If you don't want the kernel to initialize the namespace
76 from the scope of the surrounding function,
77 and/or you want to load full IPython configuration,
78 you probably want `IPython.start_kernel()` instead.
80 Parameters
81 ----------
82 module : types.ModuleType, optional
83 The module to load into IPython globals (default: caller)
84 local_ns : dict, optional
85 The namespace to load into IPython user namespace (default: caller)
86 **kwargs : various, optional
87 Further keyword args are relayed to the IPKernelApp constructor,
88 such as `config`, a traitlets :class:`Config` object (see :ref:`configure_start_ipython`),
89 allowing configuration of the kernel (see :ref:`kernel_options`). Will only have an effect
90 on the first embed_kernel call for a given process.
91 """
93 (caller_module, caller_locals) = extract_module_locals(1)
94 if module is None:
95 module = caller_module
96 if local_ns is None:
97 local_ns = caller_locals
99 # Only import .zmq when we really need it
100 from ipykernel.embed import embed_kernel as real_embed_kernel
101 real_embed_kernel(module=module, local_ns=local_ns, **kwargs)
103def start_ipython(argv=None, **kwargs):
104 """Launch a normal IPython instance (as opposed to embedded)
106 `IPython.embed()` puts a shell in a particular calling scope,
107 such as a function or method for debugging purposes,
108 which is often not desirable.
110 `start_ipython()` does full, regular IPython initialization,
111 including loading startup files, configuration, etc.
112 much of which is skipped by `embed()`.
114 This is a public API method, and will survive implementation changes.
116 Parameters
117 ----------
118 argv : list or None, optional
119 If unspecified or None, IPython will parse command-line options from sys.argv.
120 To prevent any command-line parsing, pass an empty list: `argv=[]`.
121 user_ns : dict, optional
122 specify this dictionary to initialize the IPython user namespace with particular values.
123 **kwargs : various, optional
124 Any other kwargs will be passed to the Application constructor,
125 such as `config`, a traitlets :class:`Config` object (see :ref:`configure_start_ipython`),
126 allowing configuration of the instance (see :ref:`terminal_options`).
127 """
128 from IPython.terminal.ipapp import launch_new_instance
129 return launch_new_instance(argv=argv, **kwargs)
131def start_kernel(argv=None, **kwargs):
132 """Launch a normal IPython kernel instance (as opposed to embedded)
134 `IPython.embed_kernel()` puts a shell in a particular calling scope,
135 such as a function or method for debugging purposes,
136 which is often not desirable.
138 `start_kernel()` does full, regular IPython initialization,
139 including loading startup files, configuration, etc.
140 much of which is skipped by `embed_kernel()`.
142 Parameters
143 ----------
144 argv : list or None, optional
145 If unspecified or None, IPython will parse command-line options from sys.argv.
146 To prevent any command-line parsing, pass an empty list: `argv=[]`.
147 user_ns : dict, optional
148 specify this dictionary to initialize the IPython user namespace with particular values.
149 **kwargs : various, optional
150 Any other kwargs will be passed to the Application constructor,
151 such as `config`, a traitlets :class:`Config` object (see :ref:`configure_start_ipython`),
152 allowing configuration of the kernel (see :ref:`kernel_options`).
153 """
154 import warnings
156 warnings.warn(
157 "start_kernel is deprecated since IPython 8.0, use from `ipykernel.kernelapp.launch_new_instance`",
158 DeprecationWarning,
159 stacklevel=2,
160 )
161 from ipykernel.kernelapp import launch_new_instance
162 return launch_new_instance(argv=argv, **kwargs)