Skip to content

Commit

Permalink
Remove some mention of IPython 0.10 and ipython_genutils
Browse files Browse the repository at this point in the history
Those shuould both be 7+ years old and deprecatedt
  • Loading branch information
Carreau committed Dec 4, 2024
1 parent 2219183 commit 16dbef6
Showing 1 changed file with 1 addition and 111 deletions.
112 changes: 1 addition & 111 deletions lib/python/pyflyby/_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ def _get_or_create_ipython_terminal_app():
else:
return TerminalIPythonApp.instance()
# The following has been tested on IPython 0.10.
if hasattr(IPython, "ipapi"):
return _IPython010TerminalApplication.instance()
raise RuntimeError(
"Couldn't get TerminalIPythonApp class. "
"Is your IPython version too old (or too new)? "
Expand Down Expand Up @@ -121,53 +119,6 @@ def _app_is_initialized(app):
return False



class _IPython010TerminalApplication(object):
"""
Shim class that mimics IPython 0.11+ application classes, for use in
IPython 0.10.
"""

# IPython.ipapi.launch_instance() => IPython.Shell.start() creates an
# instance of "IPShell". IPShell has an attribute named "IP" which is an
# "InteractiveShell".

_instance = None

@classmethod
def instance(cls):
if cls._instance is not None:
self = cls._instance
self.init_shell()
return self
import IPython
if not hasattr(IPython, "ipapi"):
raise RuntimeError("Inappropriate version of IPython %r"
% (IPython.__version__,))
self = cls._instance = cls()
self.init_shell()
return self

def init_shell(self):
import IPython
ipapi = IPython.ipapi.get() # IPApi instance
if ipapi is not None:
self.shell = ipapi.IP # InteractiveShell instance
else:
self.shell = None

def initialize(self, argv=None):
import IPython
logger.debug("Creating IPython 0.10 session")
self._session = IPython.ipapi.make_session() # IPShell instance
self.init_shell()
assert self._session is not None

def start(self):
self._session.mainloop()



class _DummyIPythonEmbeddedApp(object):
"""
Small wrapper around an `InteractiveShellEmbed`.
Expand Down Expand Up @@ -429,13 +380,6 @@ def install_in_ipython_config_file():
else:
_install_in_ipython_config_file_011()
return
try:
IPython.genutils.get_ipython_dir
except AttributeError:
pass
else:
_install_in_ipython_config_file_010()
return
raise RuntimeError(
"Couldn't install pyflyby autoimporter in IPython. "
"Is your IPython version too old (or too new)? "
Expand Down Expand Up @@ -620,33 +564,6 @@ def _install_in_ipython_config_file_011():
atomic_write_file(fn, contents)


def _install_in_ipython_config_file_010():
"""
Implementation of `install_in_ipython_config_file` for IPython 0.10.
"""
import IPython
ipython_dir = Filename(IPython.genutils.get_ipython_dir())
fn = ipython_dir / "ipy_user_conf.py"
if not fn.exists:
raise RuntimeError(
"Couldn't find IPython config file. Tried %s" % (fn,))
old_contents = read_file(fn).joined
if re.search(r"^ *(pyflyby[.])?enable_auto_importer[(][)]", old_contents, re.M):
logger.info("Doing nothing, because already installed in %s", fn)
return
header = (
"\n"
"\n"
"#\n"
"# Enable the Pyflyby Auto Importer.\n"
)
new_contents = header + _generate_enabler_code()
contents = old_contents.rstrip() + new_contents
logger.info("Installing pyflyby auto importer in your IPython startup")
logger.info("Appending to %s:\n%s", fn, new_contents)
atomic_write_file(fn, contents)


def _ipython_in_multiline(ip):
"""
Return ``False`` if the user has entered only one line of input so far,
Expand Down Expand Up @@ -734,25 +651,6 @@ def get_prompt_ipython_012():
else:
return ip.separate_in + prompt_manager.render("in")
get_prompt = get_prompt_ipython_012
elif hasattr(ip.hooks, "generate_prompt"):
# IPython 0.10, 0.11
generate_prompt = ip.hooks.generate_prompt
def get_prompt_ipython_010():
pdb_instance = _get_pdb_if_is_in_pdb()
if pdb_instance is not None:
return pdb_instance.prompt
elif _ipython_in_multiline(ip):
return generate_prompt(True)
else:
if hasattr(ip, "outputcache"):
# IPython 0.10 (but not 0.11+):
# Decrement the prompt_count since it otherwise
# auto-increments. (It's hard to avoid the
# auto-increment as it happens as a side effect of
# __str__!)
ip.outputcache.prompt_count -= 1
return generate_prompt(False)
get_prompt = get_prompt_ipython_010
else:
# Too old or too new IPython version?
return NullCtx()
Expand Down Expand Up @@ -817,9 +715,6 @@ def _get_ipython_app():
return _DummyIPythonEmbeddedApp(shell)
# No active IPython app/shell.
raise NoActiveIPythonAppError("No active IPython application")
# The following has been tested on IPython 0.10.
if hasattr(IPython, "ipapi"):
return _IPython010TerminalApplication.instance()
raise NoActiveIPythonAppError(
"Could not figure out how to get active IPython application for IPython version %s"
% (IPython.__version__,))
Expand Down Expand Up @@ -1346,11 +1241,6 @@ def UpdateIPythonStdioCtx():
module = sys.modules["IPython.utils.io"]
container = module
IOStream = module.IOStream
elif "IPython.genutils" in sys.modules:
# Tested with IPython 0.10.
module = sys.modules["IPython.genutils"]
container = module.Term
IOStream = module.IOStream
else:
# IPython version too old or too new?
# For now just silently do nothing.
Expand Down Expand Up @@ -1420,7 +1310,7 @@ def __new__(cls, arg=Ellipsis):
if hasattr(arg, 'parent') and getattr(arg.parent, 'shell', None) is arg:
app = arg.parent
return cls._from_app(app)
# Tested with IPython 0.10, 0.11, 0.12, 0.13.
# Tested with IPython 0.11, 0.12, 0.13.
app = _get_ipython_app()
if app.shell is arg:
return cls._from_app(app)
Expand Down

0 comments on commit 16dbef6

Please sign in to comment.