Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b82bef4

Browse files
committed
Merge pull request #3286 from minrk/get_ipython
don't use `get_ipython` from builtins in library code mainly adds IPython.get_ipython() as a library-level handle that does the same thing.
2 parents 70362b8 + 1df365a commit b82bef4

11 files changed

Lines changed: 32 additions & 27 deletions

File tree

IPython/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#-----------------------------------------------------------------------------
4242

4343
from .config.loader import Config
44+
from .core.getipython import get_ipython
4445
from .core import release
4546
from .core.application import Application
4647
from .frontend.terminal.embed import embed

IPython/core/completerlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from IPython.utils._process_common import arg_split
3434

3535
# FIXME: this should be pulled in with the right call via the component system
36-
from IPython.core.ipapi import get as get_ipython
36+
from IPython import get_ipython
3737

3838
#-----------------------------------------------------------------------------
3939
# Globals and constants

IPython/core/debugger.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
import linecache
3232
import sys
3333

34+
from IPython import get_ipython
3435
from IPython.utils import PyColorize, ulinecache
35-
from IPython.core import ipapi
3636
from IPython.utils import coloransi, io, py3compat
3737
from IPython.core.excolors import exception_colors
3838

@@ -113,9 +113,8 @@ def __init__(self,colors=None):
113113
from the Python standard library for usage details.
114114
"""
115115

116-
try:
117-
ip = get_ipython()
118-
except NameError:
116+
ip = get_ipython()
117+
if ip is None:
119118
# Outside of ipython, we set our own exception hook manually
120119
sys.excepthook = functools.partial(BdbQuit_excepthook,
121120
excepthook=sys.excepthook)
@@ -205,7 +204,7 @@ def __init__(self,color_scheme='NoColor',completekey=None,
205204
# IPython changes...
206205
self.is_pydb = has_pydb
207206

208-
self.shell = ipapi.get()
207+
self.shell = get_ipython()
209208

210209
if self.is_pydb:
211210

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
# encoding: utf-8
2-
"""
3-
This module is *completely* deprecated and should no longer be used for
4-
any purpose. Currently, we have a few parts of the core that have
5-
not been componentized and thus, still rely on this module. When everything
6-
has been made into a component, this module will be sent to deathrow.
2+
"""Simple function to call to get the current InteractiveShell instance
73
"""
84

95
#-----------------------------------------------------------------------------
10-
# Copyright (C) 2008-2011 The IPython Development Team
6+
# Copyright (C) 2013 The IPython Development Team
117
#
128
# Distributed under the terms of the BSD License. The full license is in
139
# the file COPYING, distributed as part of this software.
@@ -17,13 +13,18 @@
1713
# Imports
1814
#-----------------------------------------------------------------------------
1915

16+
import warnings
17+
2018
#-----------------------------------------------------------------------------
2119
# Classes and functions
2220
#-----------------------------------------------------------------------------
2321

2422

25-
def get():
26-
"""Get the global InteractiveShell instance."""
23+
def get_ipython():
24+
"""Get the global InteractiveShell instance.
25+
26+
Returns None if no InteractiveShell instance is registered.
27+
"""
2728
from IPython.core.interactiveshell import InteractiveShell
28-
return InteractiveShell.instance()
29-
29+
if InteractiveShell.initialized():
30+
return InteractiveShell.instance()

IPython/core/page.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
from io import UnsupportedOperation
3636

37-
from IPython.core import ipapi
37+
from IPython import get_ipython
3838
from IPython.core.error import TryNext
3939
from IPython.utils.data import chop
4040
from IPython.utils import io
@@ -158,7 +158,7 @@ def page(strng, start=0, screen_lines=0, pager_cmd=None):
158158
start = max(0, start)
159159

160160
# first, try the hook
161-
ip = ipapi.get()
161+
ip = get_ipython()
162162
if ip:
163163
try:
164164
ip.hooks.show_in_pager(strng)

IPython/core/tests/refbug.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#-----------------------------------------------------------------------------
1919
import sys
2020

21-
from IPython.core import ipapi
21+
from IPython import get_ipython
2222

2323
#-----------------------------------------------------------------------------
2424
# Globals
@@ -29,7 +29,7 @@
2929
# want to prevent.
3030
if __name__ == '__main__':
3131

32-
ip = ipapi.get()
32+
ip = get_ipython()
3333

3434
if not '_refbug_cache' in ip.user_ns:
3535
ip.user_ns['_refbug_cache'] = []

IPython/core/tests/test_imports.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def test_import_history():
2121
def test_import_hooks():
2222
from IPython.core import hooks
2323

24-
def test_import_ipapi():
25-
from IPython.core import ipapi
24+
def test_import_getipython():
25+
from IPython.core import getipython
2626

2727
def test_import_interactiveshell():
2828
from IPython.core import interactiveshell

IPython/core/ultratb.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@
9999

100100
# IPython's own modules
101101
# Modified pdb which doesn't damage IPython's readline handling
102-
from IPython.core import debugger, ipapi
102+
from IPython import get_ipython
103+
from IPython.core import debugger
103104
from IPython.core.display_trap import DisplayTrap
104105
from IPython.core.excolors import exception_colors
105106
from IPython.utils import PyColorize
@@ -279,7 +280,7 @@ def _format_traceback_lines(lnum, index, lines, Colors, lvals=None,scheme=None):
279280

280281
# This lets us get fully syntax-highlighted tracebacks.
281282
if scheme is None:
282-
ipinst = ipapi.get()
283+
ipinst = get_ipython()
283284
if ipinst is not None:
284285
scheme = ipinst.colors
285286
else:
@@ -602,7 +603,7 @@ def _format_exception_only(self, etype, value):
602603

603604
# sync with user hooks
604605
if have_filedata:
605-
ipinst = ipapi.get()
606+
ipinst = get_ipython()
606607
if ipinst is not None:
607608
ipinst.hooks.synchronize_with_editor(value.filename, value.lineno, 0)
608609

@@ -957,7 +958,7 @@ def linereader(file=file, lnum=[lnum], getline=ulinecache.getline):
957958
filepath, lnum = records[-1][1:3]
958959
#print "file:", str(file), "linenb", str(lnum) # dbg
959960
filepath = os.path.abspath(filepath)
960-
ipinst = ipapi.get()
961+
ipinst = get_ipython()
961962
if ipinst is not None:
962963
ipinst.hooks.synchronize_with_editor(filepath, lnum, 0)
963964
# vds: <<

IPython/lib/backgroundjobs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import sys
3434
import threading
3535

36+
from IPython import get_ipython
3637
from IPython.core.ultratb import AutoFormattedTB
3738
from IPython.utils.warn import error
3839

IPython/lib/editorhooks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import os
99
import pipes
1010
import subprocess
11+
12+
from IPython import get_ipython
1113
from IPython.core.error import TryNext
1214

1315

0 commit comments

Comments
 (0)