ipapi.py
61 lines
| 1.8 KiB
| text/x-python
|
PythonLexer
Brian Granger
|
r2205 | #!/usr/bin/env python | ||
# encoding: utf-8 | ||||
""" | ||||
Oh my @#*%, where did ipapi go? | ||||
ville
|
r988 | |||
Brian Granger
|
r2205 | Originally, this module was designed to be a public api for IPython. It is | ||
now deprecated and replaced by :class:`IPython.core.Interactive` shell. | ||||
Almost all of the methods that were here are now there, but possibly renamed. | ||||
ville
|
r988 | |||
Brian Granger
|
r2205 | During our transition, we will keep this simple module with its :func:`get` | ||
function. It too will eventually go away when the new component querying | ||||
interface is fully used. | ||||
ville
|
r988 | |||
Brian Granger
|
r2205 | Authors: | ||
ville
|
r988 | |||
Brian Granger
|
r2205 | * Brian Granger | ||
Fernando Perez
|
r1414 | """ | ||
#----------------------------------------------------------------------------- | ||||
Brian Granger
|
r2205 | # Copyright (C) 2008-2009 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. | ||||
Fernando Perez
|
r1414 | #----------------------------------------------------------------------------- | ||
ville
|
r988 | |||
Brian Granger
|
r2205 | #----------------------------------------------------------------------------- | ||
# Imports | ||||
#----------------------------------------------------------------------------- | ||||
Robert Kern
|
r1419 | |||
Brian Granger
|
r2205 | from IPython.core.error import TryNext, UsageError | ||
from IPython.core.component import Component | ||||
from warnings import warn | ||||
Robert Kern
|
r1419 | |||
Brian Granger
|
r2205 | #----------------------------------------------------------------------------- | ||
# Classes and functions | ||||
#----------------------------------------------------------------------------- | ||||
Robert Kern
|
r1419 | |||
Brian Granger
|
r2205 | msg = """ | ||
This module (IPython.core.ipapi) is being deprecated. For now, all we | ||||
offer here is the ``get`` function for getting the most recently created | ||||
InteractiveShell instance.""" | ||||
Robert Kern
|
r1419 | |||
Brian Granger
|
r2205 | warn(msg, category=DeprecationWarning, stacklevel=1) | ||
Robert Kern
|
r1494 | |||
Brian Granger
|
r2205 | def get(): | ||
"""Get the most recently created InteractiveShell instance.""" | ||||
insts = Component.get_instances(name='__IP') | ||||
most_recent = insts[0] | ||||
for inst in insts[1:]: | ||||
if inst.created > most_recent.created: | ||||
most_recent = inst | ||||
return most_recent.getapi() | ||||
Robert Kern
|
r1419 | |||
ville
|
r988 | |||