From 790f7312fb7f317b5f2afcbf7abb41dfa59c3610 2013-05-07 00:41:55 From: MinRK Date: 2013-05-07 00:41:55 Subject: [PATCH] add IPython.get_ipython library entry point for get_ipython does not rely on injection into globals --- diff --git a/IPython/__init__.py b/IPython/__init__.py index 8273205..74e70ae 100644 --- a/IPython/__init__.py +++ b/IPython/__init__.py @@ -41,6 +41,7 @@ sys.path.append(os.path.join(os.path.dirname(__file__), "extensions")) #----------------------------------------------------------------------------- from .config.loader import Config +from .core.ipapi import get_ipython from .core import release from .core.application import Application from .frontend.terminal.embed import embed diff --git a/IPython/core/ipapi.py b/IPython/core/ipapi.py index f107121..2c28c92 100644 --- a/IPython/core/ipapi.py +++ b/IPython/core/ipapi.py @@ -1,13 +1,9 @@ # encoding: utf-8 -""" -This module is *completely* deprecated and should no longer be used for -any purpose. Currently, we have a few parts of the core that have -not been componentized and thus, still rely on this module. When everything -has been made into a component, this module will be sent to deathrow. +"""Simple function to call to get the current InteractiveShell instance """ #----------------------------------------------------------------------------- -# Copyright (C) 2008-2011 The IPython Development Team +# Copyright (C) 2013 The IPython Development Team # # Distributed under the terms of the BSD License. The full license is in # the file COPYING, distributed as part of this software. @@ -17,13 +13,25 @@ has been made into a component, this module will be sent to deathrow. # Imports #----------------------------------------------------------------------------- +import warnings + #----------------------------------------------------------------------------- # Classes and functions #----------------------------------------------------------------------------- -def get(): - """Get the global InteractiveShell instance.""" +def get_ipython(): + """Get the global InteractiveShell instance. + + Returns None if no InteractiveShell instance is registered. + """ from IPython.core.interactiveshell import InteractiveShell - return InteractiveShell.instance() + if InteractiveShell.initialized(): + return InteractiveShell.instance() + +def get(): + warnings.warn("ipapi.get has been deprecated since IPython 0.11", + DeprecationWarning + ) + return get_ipython()