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

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

31 statements  

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 

23import warnings 

24 

25#----------------------------------------------------------------------------- 

26# Setup everything 

27#----------------------------------------------------------------------------- 

28 

29# Don't forget to also update setup.py when this changes! 

30if sys.version_info < (3, 11): 

31 raise ImportError( 

32 """ 

33IPython 8.31+ supports Python 3.11 and above, following SPEC0 

34IPython 8.19+ supports Python 3.10 and above, following SPEC0. 

35IPython 8.13+ supports Python 3.9 and above, following NEP 29. 

36IPython 8.0-8.12 supports Python 3.8 and above, following NEP 29. 

37When using Python 2.7, please install IPython 5.x LTS Long Term Support version. 

38Python 3.3 and 3.4 were supported up to IPython 6.x. 

39Python 3.5 was supported with IPython 7.0 to 7.9. 

40Python 3.6 was supported with IPython up to 7.16. 

41Python 3.7 was still supported with the 7.x branch. 

42 

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

44 

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

46 

47""" 

48 ) 

49 

50#----------------------------------------------------------------------------- 

51# Setup the top level names 

52#----------------------------------------------------------------------------- 

53 

54from .core.getipython import get_ipython 

55from .core import release 

56from .core.application import Application 

57from .terminal.embed import embed 

58 

59from .core.interactiveshell import InteractiveShell 

60from .utils.sysinfo import sys_info 

61from .utils.frame import extract_module_locals 

62 

63__all__ = ["start_ipython", "embed", "embed_kernel"] 

64 

65# Release data 

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

67__license__ = release.license 

68__version__ = release.version 

69version_info = release.version_info 

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

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

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

73 

74 

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

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

77 

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

79 from the scope of the surrounding function, 

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

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

82 

83 This is a deprecated alias for `ipykernel.embed.embed_kernel()`, 

84 to be removed in the future. 

85 You should import directly from `ipykernel.embed`; this wrapper 

86 fails anyway if you don't have `ipykernel` package installed. 

87 

88 Parameters 

89 ---------- 

90 module : types.ModuleType, optional 

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

92 local_ns : dict, optional 

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

94 **kwargs : various, optional 

95 Further keyword args are relayed to the IPKernelApp constructor, 

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

97 allowing configuration of the kernel. Will only have an effect 

98 on the first embed_kernel call for a given process. 

99 """ 

100 

101 warnings.warn( 

102 "import embed_kernel from ipykernel.embed directly (since 2013)." 

103 " Importing from IPython will be removed in the future", 

104 DeprecationWarning, 

105 stacklevel=2, 

106 ) 

107 

108 (caller_module, caller_locals) = extract_module_locals(1) 

109 if module is None: 

110 module = caller_module 

111 if local_ns is None: 

112 local_ns = dict(**caller_locals) 

113 

114 # Only import .zmq when we really need it 

115 from ipykernel.embed import embed_kernel as real_embed_kernel 

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

117 

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

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

120 

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

122 such as a function or method for debugging purposes, 

123 which is often not desirable. 

124 

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

126 including loading startup files, configuration, etc. 

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

128 

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

130 

131 Parameters 

132 ---------- 

133 argv : list or None, optional 

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

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

136 user_ns : dict, optional 

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

138 **kwargs : various, optional 

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

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

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

142 """ 

143 from IPython.terminal.ipapp import launch_new_instance 

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