Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/IPython/__init__.py: 58%

33 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-20 06:09 +0000

1# PYTHON_ARGCOMPLETE_OK 

2""" 

3IPython: tools for interactive and parallel computing in Python. 

4 

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#----------------------------------------------------------------------------- 

17 

18#----------------------------------------------------------------------------- 

19# Imports 

20#----------------------------------------------------------------------------- 

21 

22import sys 

23 

24#----------------------------------------------------------------------------- 

25# Setup everything 

26#----------------------------------------------------------------------------- 

27 

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. 

38 

39See IPython `README.rst` file for more information: 

40 

41 https://github.com/ipython/ipython/blob/main/README.rst 

42 

43""" 

44 ) 

45 

46#----------------------------------------------------------------------------- 

47# Setup the top level names 

48#----------------------------------------------------------------------------- 

49 

50from .core.getipython import get_ipython 

51from .core import release 

52from .core.application import Application 

53from .terminal.embed import embed 

54 

55from .core.interactiveshell import InteractiveShell 

56from .utils.sysinfo import sys_info 

57from .utils.frame import extract_module_locals 

58 

59__all__ = ["start_ipython", "embed", "start_kernel", "embed_kernel"] 

60 

61# Release data 

62__author__ = '%s <%s>' % (release.author, release.author_email) 

63__license__ = release.license 

64__version__ = release.version 

65version_info = release.version_info 

66# list of CVEs that should have been patched in this release. 

67# this is informational and should not be relied upon. 

68__patched_cves__ = {"CVE-2022-21699", "CVE-2023-24816"} 

69 

70 

71def embed_kernel(module=None, local_ns=None, **kwargs): 

72 """Embed and start an IPython kernel in a given scope. 

73 

74 If you don't want the kernel to initialize the namespace 

75 from the scope of the surrounding function, 

76 and/or you want to load full IPython configuration, 

77 you probably want `IPython.start_kernel()` instead. 

78 

79 Parameters 

80 ---------- 

81 module : types.ModuleType, optional 

82 The module to load into IPython globals (default: caller) 

83 local_ns : dict, optional 

84 The namespace to load into IPython user namespace (default: caller) 

85 **kwargs : various, optional 

86 Further keyword args are relayed to the IPKernelApp constructor, 

87 such as `config`, a traitlets :class:`Config` object (see :ref:`configure_start_ipython`), 

88 allowing configuration of the kernel (see :ref:`kernel_options`). Will only have an effect 

89 on the first embed_kernel call for a given process. 

90 """ 

91 

92 (caller_module, caller_locals) = extract_module_locals(1) 

93 if module is None: 

94 module = caller_module 

95 if local_ns is None: 

96 local_ns = caller_locals 

97 

98 # Only import .zmq when we really need it 

99 from ipykernel.embed import embed_kernel as real_embed_kernel 

100 real_embed_kernel(module=module, local_ns=local_ns, **kwargs) 

101 

102def start_ipython(argv=None, **kwargs): 

103 """Launch a normal IPython instance (as opposed to embedded) 

104 

105 `IPython.embed()` puts a shell in a particular calling scope, 

106 such as a function or method for debugging purposes, 

107 which is often not desirable. 

108 

109 `start_ipython()` does full, regular IPython initialization, 

110 including loading startup files, configuration, etc. 

111 much of which is skipped by `embed()`. 

112 

113 This is a public API method, and will survive implementation changes. 

114 

115 Parameters 

116 ---------- 

117 argv : list or None, optional 

118 If unspecified or None, IPython will parse command-line options from sys.argv. 

119 To prevent any command-line parsing, pass an empty list: `argv=[]`. 

120 user_ns : dict, optional 

121 specify this dictionary to initialize the IPython user namespace with particular values. 

122 **kwargs : various, optional 

123 Any other kwargs will be passed to the Application constructor, 

124 such as `config`, a traitlets :class:`Config` object (see :ref:`configure_start_ipython`), 

125 allowing configuration of the instance (see :ref:`terminal_options`). 

126 """ 

127 from IPython.terminal.ipapp import launch_new_instance 

128 return launch_new_instance(argv=argv, **kwargs) 

129 

130def start_kernel(argv=None, **kwargs): 

131 """Launch a normal IPython kernel instance (as opposed to embedded) 

132 

133 `IPython.embed_kernel()` puts a shell in a particular calling scope, 

134 such as a function or method for debugging purposes, 

135 which is often not desirable. 

136 

137 `start_kernel()` does full, regular IPython initialization, 

138 including loading startup files, configuration, etc. 

139 much of which is skipped by `embed_kernel()`. 

140 

141 Parameters 

142 ---------- 

143 argv : list or None, optional 

144 If unspecified or None, IPython will parse command-line options from sys.argv. 

145 To prevent any command-line parsing, pass an empty list: `argv=[]`. 

146 user_ns : dict, optional 

147 specify this dictionary to initialize the IPython user namespace with particular values. 

148 **kwargs : various, optional 

149 Any other kwargs will be passed to the Application constructor, 

150 such as `config`, a traitlets :class:`Config` object (see :ref:`configure_start_ipython`), 

151 allowing configuration of the kernel (see :ref:`kernel_options`). 

152 """ 

153 import warnings 

154 

155 warnings.warn( 

156 "start_kernel is deprecated since IPython 8.0, use from `ipykernel.kernelapp.launch_new_instance`", 

157 DeprecationWarning, 

158 stacklevel=2, 

159 ) 

160 from ipykernel.kernelapp import launch_new_instance 

161 return launch_new_instance(argv=argv, **kwargs)