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 9.x 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. 

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

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

38Python 3.5 was supported with IPython 7.0 to 7.9. 

39Python 3.6 was supported with IPython up to 7.16. 

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

41 

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

43 

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

45 

46""" 

47 ) 

48 

49#----------------------------------------------------------------------------- 

50# Setup the top level names 

51#----------------------------------------------------------------------------- 

52 

53from .core.getipython import get_ipython 

54from .core import release 

55from .core.application import Application 

56from .terminal.embed import embed 

57 

58from .core.interactiveshell import InteractiveShell 

59from .utils.sysinfo import sys_info 

60from .utils.frame import extract_module_locals 

61 

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

63 

64# Release data 

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

66__license__ = release.license 

67__version__ = release.version 

68version_info = release.version_info 

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

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

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

72 

73 

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

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

76 

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

78 from the scope of the surrounding function, 

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

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

81 

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

83 to be removed in the future. 

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

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

86 

87 Parameters 

88 ---------- 

89 module : types.ModuleType, optional 

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

91 local_ns : dict, optional 

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

93 **kwargs : various, optional 

94 Further keyword args are relayed to the IPKernelApp constructor, 

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

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

97 on the first embed_kernel call for a given process. 

98 """ 

99 

100 warnings.warn( 

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

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

103 DeprecationWarning, 

104 stacklevel=2, 

105 ) 

106 

107 (caller_module, caller_locals) = extract_module_locals(1) 

108 if module is None: 

109 module = caller_module 

110 if local_ns is None: 

111 local_ns = dict(**caller_locals) 

112 

113 # Only import .zmq when we really need it 

114 from ipykernel.embed import embed_kernel as real_embed_kernel 

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

116 

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

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

119 

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

121 such as a function or method for debugging purposes, 

122 which is often not desirable. 

123 

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

125 including loading startup files, configuration, etc. 

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

127 

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

129 

130 Parameters 

131 ---------- 

132 argv : list or None, optional 

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

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

135 user_ns : dict, optional 

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

137 **kwargs : various, optional 

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

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

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

141 """ 

142 from IPython.terminal.ipapp import launch_new_instance 

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