From c59b01e53c3d7afcfc15745f84a21cf467a52d3a Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Tue, 16 Oct 2018 14:33:16 +0100 Subject: [PATCH] update jupyter --- packages/python/pyio.c | 110 ++++++++++++++---- .../yap_kernel/yap_ipython/lib/__init__.py | 4 +- .../yap_ipython/lib/backgroundjobs.py | 2 +- .../python/yap_kernel/yap_ipython/lib/demo.py | 26 ++--- .../yap_kernel/yap_ipython/lib/display.py | 81 ++++++++++--- .../yap_kernel/yap_ipython/lib/editorhooks.py | 8 +- .../yap_kernel/yap_ipython/lib/guisupport.py | 14 +-- .../yap_kernel/yap_ipython/lib/inputhook.py | 98 ++++++++-------- .../yap_ipython/lib/inputhookglut.py | 14 +-- .../yap_ipython/lib/inputhookgtk.py | 2 +- .../yap_ipython/lib/inputhookgtk3.py | 2 +- .../yap_ipython/lib/inputhookpyglet.py | 4 +- .../yap_ipython/lib/inputhookqt4.py | 2 +- .../yap_kernel/yap_ipython/lib/inputhookwx.py | 4 +- .../yap_kernel/yap_ipython/lib/kernel.py | 6 +- .../yap_kernel/yap_ipython/lib/latextools.py | 2 +- .../yap_kernel/yap_ipython/lib/lexers.py | 107 ++++++++++------- .../yap_kernel/yap_ipython/lib/pretty.py | 62 +++++----- .../yap_kernel/yap_ipython/lib/security.py | 2 +- .../lib/tests/test_backgroundjobs.py | 4 +- .../yap_ipython/lib/tests/test_clipboard.py | 6 +- .../yap_ipython/lib/tests/test_deepreload.py | 8 +- .../yap_ipython/lib/tests/test_display.py | 20 +++- .../yap_ipython/lib/tests/test_editorhooks.py | 4 +- .../yap_ipython/lib/tests/test_imports.py | 8 +- .../yap_ipython/lib/tests/test_latextools.py | 10 +- .../yap_ipython/lib/tests/test_lexers.py | 49 +++++++- .../yap_ipython/lib/tests/test_pretty.py | 40 ++++++- .../yap_ipython/lib/tests/test_security.py | 4 +- .../yap_kernel/yap_ipython/prolog/jupyter.yap | 4 +- .../python/yap_kernel/yap_ipython/yapi.py | 5 +- .../python/yap_kernel/yap_kernel/ipkernel.py | 16 +-- pl/consult.yap | 2 +- pl/messages.yap | 10 +- 34 files changed, 483 insertions(+), 257 deletions(-) diff --git a/packages/python/pyio.c b/packages/python/pyio.c index de0aaa8a7..6647ff6be 100644 --- a/packages/python/pyio.c +++ b/packages/python/pyio.c @@ -40,13 +40,45 @@ static int py_putc(int sno, int ch) { return ch; } #endif - char s[2]; + unsigned char s[2]; PyObject *err; s[0] = ch; s[1] = '\0'; term_t g0 = python_acquire_GIL(); PyObject_CallMethodObjArgs(st->u.private_data, PyUnicode_FromString("write"), - PyUnicode_FromString(s), NULL); + PyUnicode_FromString((char *)s), NULL); + python_release_GIL(g0); + if ((err = PyErr_Occurred())) { + PyErr_SetString( + err, + "Error in put\n"); // %s:%s:%d!\n", __FILE__, __FUNCTION__, __LINE__); + } + return ch; +} + +static int py_wputc(int sno, int ch) { + // PyObject *pyw; // buffer + // int pyw_kind; + // PyObject *pyw_data; + StreamDesc *st = YAP_GetStreamFromId(sno); +#if 0 + if (false && (st->user_name == TermOutStream || st->user_name == TermErrStream)) { + size_t sz = put_utf8(st->u.w_irl.ptr, ch); + if (sz > 0) { + st->u.w_irl.ptr += sz; + if (ch == '\n' || st->u.w_irl.ptr - st->u.w_irl.buf > 256) + {pyflush(st); } + } + return ch; + } +#endif + unsigned char s[8]; + PyObject *err; + size_t n = put_utf8(s, ch); + s[n] = '\0'; + term_t g0 = python_acquire_GIL(); + PyObject_CallMethodObjArgs(st->u.private_data, PyUnicode_FromString("write"), + PyUnicode_FromString((char *)s), NULL); python_release_GIL(g0); if ((err = PyErr_Occurred())) { PyErr_SetString( @@ -84,8 +116,6 @@ static void *py_open(VFS_t *me, const char *name, const char *io_mode, st->u.w_irl.ptr = st->u.w_irl.buf = outbuf; - - ]\] st->user_name = TermOutStream; } else if (strcmp(name, "sys.stderr") == 0) { @@ -127,38 +157,49 @@ static bool py_close(int sno) { return true; } - static bool pygetLine(StreamDesc *rl_iostream, int sno) { // term_t ctk = python_acquire_GIL(); const char *myrl_line; - PyObject *user_line; + PyObject *user_line, *readl = NULL; + PyObject *err; StreamDesc *s = YAP_GetStreamFromId(sno); - //term_t tg = python_acquire_GIL(); - if (!strcmp(RepAtom(s->name)->StrOfAE,"input") ) { - // note that input may change - PyObject *pystream = PyDict_GetItemString( py_Builtin, "input"); - if (pystream == NULL) { - PyObject *err; - if ((err = PyErr_Occurred())) { - PyErr_Print(); - Yap_ThrowError(SYSTEM_ERROR_GET_FAILED, YAP_MkIntTerm(sno), err); - } + // term_t tg = python_acquire_GIL(); + PyObject_Print(s->u.private_data,stderr,0); + if (PyFunction_Check( s->u.private_data )) { + readl = s->u.private_data; } - user_line = PyObject_CallFunctionObjArgs(pystream, PyUnicode_FromString("?- ") , NULL); - } else { - PyObject *readl = PyObject_GetAttrString(s->u.private_data, "readline"); - user_line = PyObject_CallFunction(readl, "?- "); + if (!strcmp(RepAtom(s->name)->StrOfAE, "user_input")) { + // note that input may change + readl = PythonLookupSpecial("input"); } + if (readl == NULL) { + readl = PythonLookup("readline", s->u.private_data); + } + if (readl == NULL) { + readl = PythonLookup("read", s->u.private_data); + } + if (readl == NULL) { + if ((err = PyErr_Occurred())) { + PyErr_Print(); + Yap_ThrowError(SYSTEM_ERROR_GET_FAILED, YAP_MkIntTerm(sno), NULL); + } + } + user_line = PyObject_CallFunctionObjArgs(readl, + NULL); + if ((err = PyErr_Occurred())) { + PyErr_Print(); + Yap_ThrowError(SYSTEM_ERROR_GET_FAILED, YAP_MkIntTerm(sno), err); + } myrl_line = PyUnicode_AsUTF8(user_line); if (myrl_line == NULL) return NULL; - PyObject *err; if ((err = PyErr_Occurred())) { if (PyErr_GivenExceptionMatches(err, PyExc_EOFError)) return NULL; - PyErr_SetString(err, "Error in getLine\n"); + PyErr_Print(); Yap_ThrowError(SYSTEM_ERROR_GET_FAILED, YAP_MkIntTerm(sno), err); + } rl_iostream->u.irl.ptr = rl_iostream->u.irl.buf = (unsigned char *)myrl_line; return true; @@ -182,6 +223,29 @@ static int py_getc(int sno) { return ch; } +static int py_wgetc(int sno) { + StreamDesc *s = YAP_RepStreamFromId(sno); + int ch; + bool fetch = (s->u.irl.ptr == NULL); + + if (fetch) { + if (!pygetLine(s, sno)) { + return EOF; + } + } + if (s->u.irl.ptr == NULL) + return 10; // ???? + const unsigned char *ttyptr = s->u.irl.ptr; + if (*ttyptr == '\0') { + ch = 10; + s->u.irl.ptr = NULL; + } else { + size_t n = get_utf8(ttyptr, strlen((char *)ttyptr), &ch); + s->u.irl.ptr += n; + } + return ch; +} + /** @brief Yap_ReadlinePeekChar peeks the next char from the readline buffer, but does not actually grab it. @@ -253,8 +317,10 @@ bool init_python_vfs(void) { pystream.open = py_open; pystream.close = py_close; pystream.get_char = py_getc; + pystream.get_wchar = py_wgetc; pystream.peek_char = py_peek; pystream.put_char = py_putc; + pystream.put_wchar = py_wputc; pystream.flush = py_flush; pystream.seek = py_seek; pystream.next = GLOBAL_VFS; diff --git a/packages/python/yap_kernel/yap_ipython/lib/__init__.py b/packages/python/yap_kernel/yap_ipython/lib/__init__.py index 70b18c424..fdf65a81f 100644 --- a/packages/python/yap_kernel/yap_ipython/lib/__init__.py +++ b/packages/python/yap_kernel/yap_ipython/lib/__init__.py @@ -1,10 +1,10 @@ # encoding: utf-8 """ -Extra capabilities for yap_ipython +Extra capabilities for IPython """ #----------------------------------------------------------------------------- -# Copyright (C) 2008-2011 The yap_ipython Development Team +# Copyright (C) 2008-2011 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. diff --git a/packages/python/yap_kernel/yap_ipython/lib/backgroundjobs.py b/packages/python/yap_kernel/yap_ipython/lib/backgroundjobs.py index fc02942bd..799d98dfb 100644 --- a/packages/python/yap_kernel/yap_ipython/lib/backgroundjobs.py +++ b/packages/python/yap_kernel/yap_ipython/lib/backgroundjobs.py @@ -15,7 +15,7 @@ Computational Science, by H. P. Langtangen: http://folk.uio.no/hpl/scripting -(although ultimately no code from this text was used, as yap_ipython's system is a +(although ultimately no code from this text was used, as IPython's system is a separate implementation). An example notebook is provided in our documentation illustrating interactive diff --git a/packages/python/yap_kernel/yap_ipython/lib/demo.py b/packages/python/yap_kernel/yap_ipython/lib/demo.py index baaad75fe..0b4147175 100644 --- a/packages/python/yap_kernel/yap_ipython/lib/demo.py +++ b/packages/python/yap_kernel/yap_ipython/lib/demo.py @@ -1,7 +1,7 @@ """Module for interactive demos using yap_ipython. This module implements a few classes for running Python scripts interactively -in yap_ipython for demonstrations. With very simple markup (a few tags in +in IPython for demonstrations. With very simple markup (a few tags in comments), you can control points where the script stops executing and returns control to yap_ipython. @@ -13,15 +13,15 @@ The classes are (see their docstrings for further details): - Demo: pure python demos - - IPythonDemo: demos with input to be processed by yap_ipython as if it had been + - IPythonDemo: demos with input to be processed by IPython as if it had been typed interactively (so magics work, as well as any other special syntax you may have added via input prefilters). - LineDemo: single-line version of the Demo class. These demos are executed one line at a time, and require no markup. - - IPythonLineDemo: yap_ipython version of the LineDemo class (the demo is - executed a line at a time, but processed via yap_ipython). + - IPythonLineDemo: IPython version of the LineDemo class (the demo is + executed a line at a time, but processed via IPython). - ClearMixin: mixin to make Demo classes with less visual clutter. It declares an empty marquee and a pre_cmd that clears the screen before each @@ -58,7 +58,7 @@ Operation The file is run in its own empty namespace (though you can pass it a string of arguments as if in a command line environment, and it will see those as -sys.argv). But at each stop, the global yap_ipython namespace is updated with the +sys.argv). But at each stop, the global IPython namespace is updated with the current internal demo namespace, so you can work interactively with the data accumulated so far. @@ -72,7 +72,7 @@ The supported tags are: # stop - Defines block boundaries, the points where yap_ipython stops execution of the + Defines block boundaries, the points where IPython stops execution of the file and returns to the interactive prompt. You can optionally mark the stop tag with extra dashes before and after the @@ -120,7 +120,7 @@ and back(). It can be reset for a new run via reset() or reloaded from disk Note: To make this simpler to explore, a file called "demo-exercizer.py" has been added to the "docs/examples/core" directory. Just cd to this directory in -an yap_ipython session, and type:: +an IPython session, and type:: %run demo-exercizer.py @@ -134,11 +134,11 @@ The following is a very simple example of a valid demo file. :: #################### EXAMPLE DEMO ############################### - '''A simple interactive demo to illustrate the use of yap_ipython's Demo class.''' + '''A simple interactive demo to illustrate the use of IPython's Demo class.''' - print 'Hello, welcome to an interactive yap_ipython demo.' + print 'Hello, welcome to an interactive IPython demo.' - # The mark below defines a block boundary, which is a point where yap_ipython will + # The mark below defines a block boundary, which is a point where IPython will # stop execution and return to the interactive prompt. The dashes are actually # optional and used only as a visual aid to clearly separate blocks while # editing the demo code. @@ -188,7 +188,7 @@ import pygments from yap_ipython.utils.text import marquee from yap_ipython.utils import openpy from yap_ipython.utils import py3compat -__all__ = ['Demo','IPythonDemo','LineDemo','IPythonLineDemo','DemoError'] +__all__ = ['Demo','yap_ipythonDemo','LineDemo','yap_ipythonLineDemo','DemoError'] class DemoError(Exception): pass @@ -536,10 +536,10 @@ class Demo(object): class IPythonDemo(Demo): - """Class for interactive demos with yap_ipython's input processing applied. + """Class for interactive demos with IPython's input processing applied. This subclasses Demo, but instead of executing each block by the Python - interpreter (via exec), it actually calls yap_ipython on it, so that any input + interpreter (via exec), it actually calls IPython on it, so that any input filters which may be in place are applied to the input block. If you have an interactive environment which exposes special input diff --git a/packages/python/yap_kernel/yap_ipython/lib/display.py b/packages/python/yap_kernel/yap_ipython/lib/display.py index 1f88caa46..dc52a9217 100644 --- a/packages/python/yap_kernel/yap_ipython/lib/display.py +++ b/packages/python/yap_kernel/yap_ipython/lib/display.py @@ -2,13 +2,14 @@ Authors : MinRK, gregcaporaso, dannystaple """ +from html import escape as html_escape from os.path import exists, isfile, splitext, abspath, join, isdir -from os import walk, sep +from os import walk, sep, fsdecode -from yap_ipython.core.display import DisplayObject +from yap_ipython.core.display import DisplayObject, TextDisplayObject __all__ = ['Audio', 'IFrame', 'YouTubeVideo', 'VimeoVideo', 'ScribdDocument', - 'FileLink', 'FileLinks'] + 'FileLink', 'FileLinks', 'Code'] class Audio(DisplayObject): @@ -197,7 +198,7 @@ class Audio(DisplayObject): class IFrame(object): """ - Generic class to embed an iframe in an yap_ipython notebook + Generic class to embed an iframe in an IPython notebook """ iframe = """ @@ -232,7 +233,7 @@ class IFrame(object): params=params) class YouTubeVideo(IFrame): - """Class for embedding a YouTube Video in an yap_ipython session, based on its video id. + """Class for embedding a YouTube Video in an IPython session, based on its video id. e.g. to embed the video from https://www.youtube.com/watch?v=foo , you would do:: @@ -273,7 +274,7 @@ class YouTubeVideo(IFrame): class VimeoVideo(IFrame): """ - Class for embedding a Vimeo video in an yap_ipython session, based on its video id. + Class for embedding a Vimeo video in an IPython session, based on its video id. """ def __init__(self, id, width=400, height=300, **kwargs): @@ -282,7 +283,7 @@ class VimeoVideo(IFrame): class ScribdDocument(IFrame): """ - Class for embedding a Scribd document in an yap_ipython session + Class for embedding a Scribd document in an IPython session Use the start_page params to specify a starting point in the document Use the view_mode params to specify display type one off scroll | slideshow | book @@ -297,9 +298,9 @@ class ScribdDocument(IFrame): super(ScribdDocument, self).__init__(src, width, height, **kwargs) class FileLink(object): - """Class for embedding a local file link in an yap_ipython session, based on path + """Class for embedding a local file link in an IPython session, based on path - e.g. to embed a link that was generated in the yap_ipython notebook as my/data.txt + e.g. to embed a link that was generated in the IPython notebook as my/data.txt you would do:: @@ -334,15 +335,16 @@ class FileLink(object): if isdir(path): raise ValueError("Cannot display a directory using FileLink. " "Use FileLinks to display '%s'." % path) - self.path = path + self.path = fsdecode(path) self.url_prefix = url_prefix self.result_html_prefix = result_html_prefix self.result_html_suffix = result_html_suffix def _format_path(self): - fp = ''.join([self.url_prefix,self.path]) + fp = ''.join([self.url_prefix, html_escape(self.path)]) return ''.join([self.result_html_prefix, - self.html_link_str % (fp, self.path), + self.html_link_str % \ + (fp, html_escape(self.path, quote=False)), self.result_html_suffix]) def _repr_html_(self): @@ -362,9 +364,9 @@ class FileLink(object): return abspath(self.path) class FileLinks(FileLink): - """Class for embedding local file links in an yap_ipython session, based on path + """Class for embedding local file links in an IPython session, based on path - e.g. to embed links to files that were generated in the yap_ipython notebook + e.g. to embed links to files that were generated in the IPython notebook under ``my/data``, you would do:: local_files = FileLinks("my/data") @@ -424,7 +426,7 @@ class FileLinks(FileLink): raise ValueError("Cannot display a file using FileLinks. " "Use FileLink to display '%s'." % path) self.included_suffixes = included_suffixes - # remove trailing slashs for more consistent output formatting + # remove trailing slashes for more consistent output formatting path = path.rstrip('/') self.path = path @@ -555,3 +557,52 @@ class FileLinks(FileLink): for dirname, subdirs, fnames in walked_dir: result_lines += self.terminal_display_formatter(dirname, fnames, self.included_suffixes) return '\n'.join(result_lines) + + +class Code(TextDisplayObject): + """Display syntax-highlighted source code. + + This uses Pygments to highlight the code for HTML and Latex output. + + Parameters + ---------- + data : str + The code as a string + url : str + A URL to fetch the code from + filename : str + A local filename to load the code from + language : str + The short name of a Pygments lexer to use for highlighting. + If not specified, it will guess the lexer based on the filename + or the code. Available lexers: http://pygments.org/docs/lexers/ + """ + def __init__(self, data=None, url=None, filename=None, language=None): + self.language = language + super().__init__(data=data, url=url, filename=filename) + + def _get_lexer(self): + if self.language: + from pygments.lexers import get_lexer_by_name + return get_lexer_by_name(self.language) + elif self.filename: + from pygments.lexers import get_lexer_for_filename + return get_lexer_for_filename(self.filename) + else: + from pygments.lexers import guess_lexer + return guess_lexer(self.data) + + def __repr__(self): + return self.data + + def _repr_html_(self): + from pygments import highlight + from pygments.formatters import HtmlFormatter + fmt = HtmlFormatter() + style = ''.format(fmt.get_style_defs('.output_html')) + return style + highlight(self.data, self._get_lexer(), fmt) + + def _repr_latex_(self): + from pygments import highlight + from pygments.formatters import LatexFormatter + return highlight(self.data, self._get_lexer(), LatexFormatter()) diff --git a/packages/python/yap_kernel/yap_ipython/lib/editorhooks.py b/packages/python/yap_kernel/yap_ipython/lib/editorhooks.py index 4c3fc93db..5d709c23b 100644 --- a/packages/python/yap_kernel/yap_ipython/lib/editorhooks.py +++ b/packages/python/yap_kernel/yap_ipython/lib/editorhooks.py @@ -11,25 +11,25 @@ import shlex import subprocess import sys -from yap_ipython import get_ipython +from IPython import get_ipython from yap_ipython.core.error import TryNext from yap_ipython.utils import py3compat def install_editor(template, wait=False): - """Installs the editor that is called by yap_ipython for the %edit magic. + """Installs the editor that is called by IPython for the %edit magic. This overrides the default editor, which is generally set by your EDITOR environment variable or is notepad (windows) or vi (linux). By supplying a template string `run_template`, you can control how the editor is invoked - by yap_ipython -- (e.g. the format in which it accepts command line options) + by IPython -- (e.g. the format in which it accepts command line options) Parameters ---------- template : basestring run_template acts as a template for how your editor is invoked by the shell. It should contain '{filename}', which will be replaced on - invokation with the file name, and '{line}', $line by line number + invocation with the file name, and '{line}', $line by line number (or 0) to invoke the file with. wait : bool If `wait` is true, wait until the user presses enter before returning, diff --git a/packages/python/yap_kernel/yap_ipython/lib/guisupport.py b/packages/python/yap_kernel/yap_ipython/lib/guisupport.py index 3ecfa69c6..f82fc11a3 100644 --- a/packages/python/yap_kernel/yap_ipython/lib/guisupport.py +++ b/packages/python/yap_kernel/yap_ipython/lib/guisupport.py @@ -2,26 +2,26 @@ """ Support for creating GUI apps and starting event loops. -yap_ipython's GUI integration allows interative plotting and GUI usage in yap_ipython -session. yap_ipython has two different types of GUI integration: +IPython's GUI integration allows interactive plotting and GUI usage in IPython +session. IPython has two different types of GUI integration: -1. The terminal based yap_ipython supports GUI event loops through Python's +1. The terminal based IPython supports GUI event loops through Python's PyOS_InputHook. PyOS_InputHook is a hook that Python calls periodically whenever raw_input is waiting for a user to type code. We implement GUI support in the terminal by setting PyOS_InputHook to a function that iterates the event loop for a short while. It is important to note that in this situation, the real GUI event loop is NOT run in the normal manner, so you can't use the normal means to detect that it is running. -2. In the two process yap_ipython kernel/frontend, the GUI event loop is run in +2. In the two process IPython kernel/frontend, the GUI event loop is run in the kernel. In this case, the event loop is run in the normal manner by calling the function or method of the GUI toolkit that starts the event loop. -In addition to starting the GUI event loops in one of these two ways, yap_ipython +In addition to starting the GUI event loops in one of these two ways, IPython will *always* create an appropriate GUI application object when GUi integration is enabled. -If you want your GUI apps to run in yap_ipython you need to do two things: +If you want your GUI apps to run in IPython you need to do two things: 1. Test to see if there is already an existing main application object. If there is, you should use it. If there is not an existing application object @@ -57,7 +57,7 @@ so you don't have to depend on yap_ipython. """ -# Copyright (c) yap_ipython Development Team. +# Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. from yap_ipython.core.getipython import get_ipython diff --git a/packages/python/yap_kernel/yap_ipython/lib/inputhook.py b/packages/python/yap_kernel/yap_ipython/lib/inputhook.py index fcf54ecb8..b71975535 100644 --- a/packages/python/yap_kernel/yap_ipython/lib/inputhook.py +++ b/packages/python/yap_kernel/yap_ipython/lib/inputhook.py @@ -1,11 +1,11 @@ # coding: utf-8 """ -Deprecated since yap_ipython 5.0 +Deprecated since IPython 5.0 Inputhook management for GUI event loop integration. """ -# Copyright (c) yap_ipython Development Team. +# Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. try: @@ -22,7 +22,7 @@ from distutils.version import LooseVersion as V from warnings import warn -warn("`yap_ipython.lib.inputhook` is deprecated since yap_ipython 5.0 and will be removed in future versions.", +warn("`yap_ipython.lib.inputhook` is deprecated since IPython 5.0 and will be removed in future versions.", DeprecationWarning, stacklevel=2) @@ -105,7 +105,7 @@ else: class InputHookManager(object): - """DEPRECATED since yap_ipython 5.0 + """DEPRECATED since IPython 5.0 Manage PyOS_InputHook for different GUI toolkits. @@ -115,7 +115,7 @@ class InputHookManager(object): def __init__(self): if ctypes is None: - warn("yap_ipython GUI event loop requires ctypes, %gui will not be available") + warn("IPython GUI event loop requires ctypes, %gui will not be available") else: self.PYFUNC = ctypes.PYFUNCTYPE(ctypes.c_int) self.guihooks = {} @@ -130,23 +130,23 @@ class InputHookManager(object): self._current_gui = None def get_pyos_inputhook(self): - """DEPRECATED since yap_ipython 5.0 + """DEPRECATED since IPython 5.0 Return the current PyOS_InputHook as a ctypes.c_void_p.""" - warn("`get_pyos_inputhook` is deprecated since yap_ipython 5.0 and will be removed in future versions.", + warn("`get_pyos_inputhook` is deprecated since IPython 5.0 and will be removed in future versions.", DeprecationWarning, stacklevel=2) return ctypes.c_void_p.in_dll(ctypes.pythonapi,"PyOS_InputHook") def get_pyos_inputhook_as_func(self): - """DEPRECATED since yap_ipython 5.0 + """DEPRECATED since IPython 5.0 Return the current PyOS_InputHook as a ctypes.PYFUNCYPE.""" - warn("`get_pyos_inputhook_as_func` is deprecated since yap_ipython 5.0 and will be removed in future versions.", + warn("`get_pyos_inputhook_as_func` is deprecated since IPython 5.0 and will be removed in future versions.", DeprecationWarning, stacklevel=2) return self.PYFUNC.in_dll(ctypes.pythonapi,"PyOS_InputHook") def set_inputhook(self, callback): - """DEPRECATED since yap_ipython 5.0 + """DEPRECATED since IPython 5.0 Set PyOS_InputHook to callback and return the previous one.""" # On platforms with 'readline' support, it's all too likely to @@ -164,7 +164,7 @@ class InputHookManager(object): return original def clear_inputhook(self, app=None): - """DEPRECATED since yap_ipython 5.0 + """DEPRECATED since IPython 5.0 Set PyOS_InputHook to NULL and return the previous one. @@ -174,9 +174,9 @@ class InputHookManager(object): This parameter is allowed only so that clear_inputhook() can be called with a similar interface as all the ``enable_*`` methods. But the actual value of the parameter is ignored. This uniform interface - makes it easier to have user-level entry points in the main yap_ipython + makes it easier to have user-level entry points in the main IPython app like :meth:`enable_gui`.""" - warn("`clear_inputhook` is deprecated since yap_ipython 5.0 and will be removed in future versions.", + warn("`clear_inputhook` is deprecated since IPython 5.0 and will be removed in future versions.", DeprecationWarning, stacklevel=2) pyos_inputhook_ptr = self.get_pyos_inputhook() original = self.get_pyos_inputhook_as_func() @@ -186,9 +186,9 @@ class InputHookManager(object): return original def clear_app_refs(self, gui=None): - """DEPRECATED since yap_ipython 5.0 + """DEPRECATED since IPython 5.0 - Clear yap_ipython's internal reference to an application instance. + Clear IPython's internal reference to an application instance. Whenever we create an app for a user on qt4 or wx, we hold a reference to the app. This is needed because in some cases bad things @@ -202,7 +202,7 @@ class InputHookManager(object): the app for that toolkit. References are not held for gtk or tk as those toolkits don't have the notion of an app. """ - warn("`clear_app_refs` is deprecated since yap_ipython 5.0 and will be removed in future versions.", + warn("`clear_app_refs` is deprecated since IPython 5.0 and will be removed in future versions.", DeprecationWarning, stacklevel=2) if gui is None: self.apps = {} @@ -210,7 +210,7 @@ class InputHookManager(object): del self.apps[gui] def register(self, toolkitname, *aliases): - """DEPRECATED since yap_ipython 5.0 + """DEPRECATED since IPython 5.0 Register a class to provide the event loop for a given GUI. @@ -225,7 +225,7 @@ class InputHookManager(object): def enable(self, app=None): ... """ - warn("`register` is deprecated since yap_ipython 5.0 and will be removed in future versions.", + warn("`register` is deprecated since IPython 5.0 and will be removed in future versions.", DeprecationWarning, stacklevel=2) def decorator(cls): if ctypes is not None: @@ -237,15 +237,15 @@ class InputHookManager(object): return decorator def current_gui(self): - """DEPRECATED since yap_ipython 5.0 + """DEPRECATED since IPython 5.0 Return a string indicating the currently active GUI or None.""" - warn("`current_gui` is deprecated since yap_ipython 5.0 and will be removed in future versions.", + warn("`current_gui` is deprecated since IPython 5.0 and will be removed in future versions.", DeprecationWarning, stacklevel=2) return self._current_gui def enable_gui(self, gui=None, app=None): - """DEPRECATED since yap_ipython 5.0 + """DEPRECATED since IPython 5.0 Switch amongst GUI input hooks by name. @@ -271,7 +271,7 @@ class InputHookManager(object): PyOS_InputHook wrapper object or the GUI toolkit app created, if there was one. """ - warn("`enable_gui` is deprecated since yap_ipython 5.0 and will be removed in future versions.", + warn("`enable_gui` is deprecated since IPython 5.0 and will be removed in future versions.", DeprecationWarning, stacklevel=2) if gui in (None, GUI_NONE): return self.disable_gui() @@ -293,14 +293,14 @@ class InputHookManager(object): return app def disable_gui(self): - """DEPRECATED since yap_ipython 5.0 + """DEPRECATED since IPython 5.0 Disable GUI event loop integration. If an application was registered, this sets its ``_in_event_loop`` attribute to False. It then calls :meth:`clear_inputhook`. """ - warn("`disable_gui` is deprecated since yap_ipython 5.0 and will be removed in future versions.", + warn("`disable_gui` is deprecated since IPython 5.0 and will be removed in future versions.", DeprecationWarning, stacklevel=2) gui = self._current_gui if gui in self.apps: @@ -308,7 +308,7 @@ class InputHookManager(object): return self.clear_inputhook() class InputHookBase(object): - """DEPRECATED since yap_ipython 5.0 + """DEPRECATED since IPython 5.0 Base class for input hooks for specific toolkits. @@ -326,17 +326,17 @@ inputhook_manager = InputHookManager() @inputhook_manager.register('osx') class NullInputHook(InputHookBase): - """DEPRECATED since yap_ipython 5.0 + """DEPRECATED since IPython 5.0 A null inputhook that doesn't need to do anything""" def enable(self, app=None): - warn("This function is deprecated since yap_ipython 5.0 and will be removed in future versions.", + warn("This function is deprecated since IPython 5.0 and will be removed in future versions.", DeprecationWarning, stacklevel=2) @inputhook_manager.register('wx') class WxInputHook(InputHookBase): def enable(self, app=None): - """DEPRECATED since yap_ipython 5.0 + """DEPRECATED since IPython 5.0 Enable event loop integration with wxPython. @@ -359,7 +359,7 @@ class WxInputHook(InputHookBase): import wx app = wx.App(redirect=False, clearSigInt=False) """ - warn("This function is deprecated since yap_ipython 5.0 and will be removed in future versions.", + warn("This function is deprecated since IPython 5.0 and will be removed in future versions.", DeprecationWarning, stacklevel=2) import wx @@ -383,13 +383,13 @@ class WxInputHook(InputHookBase): return app def disable(self): - """DEPRECATED since yap_ipython 5.0 + """DEPRECATED since IPython 5.0 Disable event loop integration with wxPython. This restores appnapp on OS X """ - warn("This function is deprecated since yap_ipython 5.0 and will be removed in future versions.", + warn("This function is deprecated since IPython 5.0 and will be removed in future versions.", DeprecationWarning, stacklevel=2) if _use_appnope(): from appnope import nap @@ -398,7 +398,7 @@ class WxInputHook(InputHookBase): @inputhook_manager.register('qt', 'qt4') class Qt4InputHook(InputHookBase): def enable(self, app=None): - """DEPRECATED since yap_ipython 5.0 + """DEPRECATED since IPython 5.0 Enable event loop integration with PyQt4. @@ -421,7 +421,7 @@ class Qt4InputHook(InputHookBase): from PyQt4 import QtCore app = QtGui.QApplication(sys.argv) """ - warn("This function is deprecated since yap_ipython 5.0 and will be removed in future versions.", + warn("This function is deprecated since IPython 5.0 and will be removed in future versions.", DeprecationWarning, stacklevel=2) from yap_ipython.lib.inputhookqt4 import create_inputhook_qt4 app, inputhook_qt4 = create_inputhook_qt4(self.manager, app) @@ -433,13 +433,13 @@ class Qt4InputHook(InputHookBase): return app def disable_qt4(self): - """DEPRECATED since yap_ipython 5.0 + """DEPRECATED since IPython 5.0 Disable event loop integration with PyQt4. This restores appnapp on OS X """ - warn("This function is deprecated since yap_ipython 5.0 and will be removed in future versions.", + warn("This function is deprecated since IPython 5.0 and will be removed in future versions.", DeprecationWarning, stacklevel=2) if _use_appnope(): from appnope import nap @@ -449,7 +449,7 @@ class Qt4InputHook(InputHookBase): @inputhook_manager.register('qt5') class Qt5InputHook(Qt4InputHook): def enable(self, app=None): - warn("This function is deprecated since yap_ipython 5.0 and will be removed in future versions.", + warn("This function is deprecated since IPython 5.0 and will be removed in future versions.", DeprecationWarning, stacklevel=2) os.environ['QT_API'] = 'pyqt5' return Qt4InputHook.enable(self, app) @@ -458,7 +458,7 @@ class Qt5InputHook(Qt4InputHook): @inputhook_manager.register('gtk') class GtkInputHook(InputHookBase): def enable(self, app=None): - """DEPRECATED since yap_ipython 5.0 + """DEPRECATED since IPython 5.0 Enable event loop integration with PyGTK. @@ -475,7 +475,7 @@ class GtkInputHook(InputHookBase): the PyGTK to integrate with terminal based applications like yap_ipython. """ - warn("This function is deprecated since yap_ipython 5.0 and will be removed in future versions.", + warn("This function is deprecated since IPython 5.0 and will be removed in future versions.", DeprecationWarning, stacklevel=2) import gtk try: @@ -489,7 +489,7 @@ class GtkInputHook(InputHookBase): @inputhook_manager.register('tk') class TkInputHook(InputHookBase): def enable(self, app=None): - """DEPRECATED since yap_ipython 5.0 + """DEPRECATED since IPython 5.0 Enable event loop integration with Tk. @@ -506,7 +506,7 @@ class TkInputHook(InputHookBase): :class:`InputHookManager`, since creating that object automatically sets ``PyOS_InputHook``. """ - warn("This function is deprecated since yap_ipython 5.0 and will be removed in future versions.", + warn("This function is deprecated since IPython 5.0 and will be removed in future versions.", DeprecationWarning, stacklevel=2) if app is None: try: @@ -522,7 +522,7 @@ class TkInputHook(InputHookBase): @inputhook_manager.register('glut') class GlutInputHook(InputHookBase): def enable(self, app=None): - """DEPRECATED since yap_ipython 5.0 + """DEPRECATED since IPython 5.0 Enable event loop integration with GLUT. @@ -547,7 +547,7 @@ class GlutInputHook(InputHookBase): The default screen mode is set to: glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH """ - warn("This function is deprecated since yap_ipython 5.0 and will be removed in future versions.", + warn("This function is deprecated since IPython 5.0 and will be removed in future versions.", DeprecationWarning, stacklevel=2) import OpenGL.GLUT as glut @@ -576,7 +576,7 @@ class GlutInputHook(InputHookBase): def disable(self): - """DEPRECATED since yap_ipython 5.0 + """DEPRECATED since IPython 5.0 Disable event loop integration with glut. @@ -584,7 +584,7 @@ class GlutInputHook(InputHookBase): dummy one and set the timer to a dummy timer that will be triggered very far in the future. """ - warn("This function is deprecated since yap_ipython 5.0 and will be removed in future versions.", + warn("This function is deprecated since IPython 5.0 and will be removed in future versions.", DeprecationWarning, stacklevel=2) import OpenGL.GLUT as glut from glut_support import glutMainLoopEvent @@ -596,7 +596,7 @@ class GlutInputHook(InputHookBase): @inputhook_manager.register('pyglet') class PygletInputHook(InputHookBase): def enable(self, app=None): - """DEPRECATED since yap_ipython 5.0 + """DEPRECATED since IPython 5.0 Enable event loop integration with pyglet. @@ -614,7 +614,7 @@ class PygletInputHook(InputHookBase): yap_ipython. """ - warn("This function is deprecated since yap_ipython 5.0 and will be removed in future versions.", + warn("This function is deprecated since IPython 5.0 and will be removed in future versions.", DeprecationWarning, stacklevel=2) from yap_ipython.lib.inputhookpyglet import inputhook_pyglet self.manager.set_inputhook(inputhook_pyglet) @@ -624,7 +624,7 @@ class PygletInputHook(InputHookBase): @inputhook_manager.register('gtk3') class Gtk3InputHook(InputHookBase): def enable(self, app=None): - """DEPRECATED since yap_ipython 5.0 + """DEPRECATED since IPython 5.0 Enable event loop integration with Gtk3 (gir bindings). @@ -641,7 +641,7 @@ class Gtk3InputHook(InputHookBase): the Gtk3 to integrate with terminal based applications like yap_ipython. """ - warn("This function is deprecated since yap_ipython 5.0 and will be removed in future versions.", + warn("This function is deprecated since IPython 5.0 and will be removed in future versions.", DeprecationWarning, stacklevel=2) from yap_ipython.lib.inputhookgtk3 import inputhook_gtk3 self.manager.set_inputhook(inputhook_gtk3) @@ -658,7 +658,7 @@ guis = inputhook_manager.guihooks def _deprecated_disable(): - warn("This function is deprecated since yap_ipython 4.0 use disable_gui() instead", + warn("This function is deprecated since IPython 4.0 use disable_gui() instead", DeprecationWarning, stacklevel=2) inputhook_manager.disable_gui() diff --git a/packages/python/yap_kernel/yap_ipython/lib/inputhookglut.py b/packages/python/yap_kernel/yap_ipython/lib/inputhookglut.py index d2ac09ef0..e6f7f1257 100644 --- a/packages/python/yap_kernel/yap_ipython/lib/inputhookglut.py +++ b/packages/python/yap_kernel/yap_ipython/lib/inputhookglut.py @@ -4,14 +4,14 @@ GLUT Inputhook support functions """ #----------------------------------------------------------------------------- -# Copyright (C) 2008-2011 The yap_ipython Development Team +# Copyright (C) 2008-2011 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. #----------------------------------------------------------------------------- # GLUT is quite an old library and it is difficult to ensure proper -# integration within yap_ipython since original GLUT does not allow to handle +# integration within IPython since original GLUT does not allow to handle # events one by one. Instead, it requires for the mainloop to be entered # and never returned (there is not even a function to exit he # mainloop). Fortunately, there are alternatives such as freeglut @@ -24,7 +24,7 @@ GLUT Inputhook support functions # being first created. We choose to make this window invisible. This means that # display mode options are set at this level and user won't be able to change # them later without modifying the code. This should probably be made available -# via yap_ipython options system. +# via IPython options system. #----------------------------------------------------------------------------- # Imports @@ -42,12 +42,12 @@ from timeit import default_timer as clock #----------------------------------------------------------------------------- # Frame per second : 60 -# Should probably be an yap_ipython option +# Should probably be an IPython option glut_fps = 60 # Display mode : double buffeed + rgba + depth -# Should probably be an yap_ipython option +# Should probably be an IPython option glut_display_mode = (glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH) @@ -112,7 +112,7 @@ def glut_close(): glutMainLoopEvent() def glut_int_handler(signum, frame): - # Catch sigint and print the defautl message + # Catch sigint and print the default message signal.signal(signal.SIGINT, signal.default_int_handler) print('\nKeyboardInterrupt') # Need to reprint the prompt at this stage @@ -130,7 +130,7 @@ def inputhook_glut(): needed, otherwise, CPU usage is at 100%. This sleep time should be tuned though for best performance. """ - # We need to protect against a user pressing Control-C when yap_ipython is + # We need to protect against a user pressing Control-C when IPython is # idle and this is running. We trap KeyboardInterrupt and pass. signal.signal(signal.SIGINT, glut_int_handler) diff --git a/packages/python/yap_kernel/yap_ipython/lib/inputhookgtk.py b/packages/python/yap_kernel/yap_ipython/lib/inputhookgtk.py index 68c364a91..2b4b656f9 100644 --- a/packages/python/yap_kernel/yap_ipython/lib/inputhookgtk.py +++ b/packages/python/yap_kernel/yap_ipython/lib/inputhookgtk.py @@ -6,7 +6,7 @@ Authors: Brian Granger """ #----------------------------------------------------------------------------- -# Copyright (C) 2008-2011 The yap_ipython Development Team +# Copyright (C) 2008-2011 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. diff --git a/packages/python/yap_kernel/yap_ipython/lib/inputhookgtk3.py b/packages/python/yap_kernel/yap_ipython/lib/inputhookgtk3.py index 4f740319f..21fcece19 100644 --- a/packages/python/yap_kernel/yap_ipython/lib/inputhookgtk3.py +++ b/packages/python/yap_kernel/yap_ipython/lib/inputhookgtk3.py @@ -5,7 +5,7 @@ Enable Gtk3 to be used interacive by yap_ipython. Authors: Thomi Richards """ #----------------------------------------------------------------------------- -# Copyright (c) 2012, the yap_ipython Development Team. +# Copyright (c) 2012, the IPython Development Team. # # Distributed under the terms of the Modified BSD License. # diff --git a/packages/python/yap_kernel/yap_ipython/lib/inputhookpyglet.py b/packages/python/yap_kernel/yap_ipython/lib/inputhookpyglet.py index 7bd047a9e..b82fcf5ea 100644 --- a/packages/python/yap_kernel/yap_ipython/lib/inputhookpyglet.py +++ b/packages/python/yap_kernel/yap_ipython/lib/inputhookpyglet.py @@ -10,7 +10,7 @@ Authors """ #----------------------------------------------------------------------------- -# Copyright (C) 2008-2011 The yap_ipython Development Team +# Copyright (C) 2008-2011 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. @@ -73,7 +73,7 @@ def inputhook_pyglet(): needed, otherwise, CPU usage is at 100%. This sleep time should be tuned though for best performance. """ - # We need to protect against a user pressing Control-C when yap_ipython is + # We need to protect against a user pressing Control-C when IPython is # idle and this is running. We trap KeyboardInterrupt and pass. try: t = clock() diff --git a/packages/python/yap_kernel/yap_ipython/lib/inputhookqt4.py b/packages/python/yap_kernel/yap_ipython/lib/inputhookqt4.py index ba2febc97..9d4b2a34f 100644 --- a/packages/python/yap_kernel/yap_ipython/lib/inputhookqt4.py +++ b/packages/python/yap_kernel/yap_ipython/lib/inputhookqt4.py @@ -6,7 +6,7 @@ Author: Christian Boos """ #----------------------------------------------------------------------------- -# Copyright (C) 2011 The yap_ipython Development Team +# Copyright (C) 2011 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. diff --git a/packages/python/yap_kernel/yap_ipython/lib/inputhookwx.py b/packages/python/yap_kernel/yap_ipython/lib/inputhookwx.py index c5c7b2b4d..f53d8cfb6 100644 --- a/packages/python/yap_kernel/yap_ipython/lib/inputhookwx.py +++ b/packages/python/yap_kernel/yap_ipython/lib/inputhookwx.py @@ -7,7 +7,7 @@ Authors: Robin Dunn, Brian Granger, Ondrej Certik """ #----------------------------------------------------------------------------- -# Copyright (C) 2008-2011 The yap_ipython Development Team +# Copyright (C) 2008-2011 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. @@ -110,7 +110,7 @@ def inputhook_wx3(): time.sleep is inserted. This is needed, otherwise, CPU usage is at 100%. This sleep time should be tuned though for best performance. """ - # We need to protect against a user pressing Control-C when yap_ipython is + # We need to protect against a user pressing Control-C when IPython is # idle and this is running. We trap KeyboardInterrupt and pass. try: app = wx.GetApp() diff --git a/packages/python/yap_kernel/yap_ipython/lib/kernel.py b/packages/python/yap_kernel/yap_ipython/lib/kernel.py index 50ff88b47..3095aaabf 100644 --- a/packages/python/yap_kernel/yap_ipython/lib/kernel.py +++ b/packages/python/yap_kernel/yap_ipython/lib/kernel.py @@ -4,10 +4,10 @@ Moved to yap_ipython.kernel.connect """ import warnings -warnings.warn("yap_ipython.lib.kernel moved to yap_ipython.kernel.connect in yap_ipython 1.0," - " and will be removed in yap_ipython 6.0.", +warnings.warn("yap_ipython.lib.kernel moved to yap_ipython.kernel.connect in IPython 1.0," + " and will be removed in IPython 6.0.", DeprecationWarning ) -from yap_kernel.connect import * +from ipykernel.connect import * diff --git a/packages/python/yap_kernel/yap_ipython/lib/latextools.py b/packages/python/yap_kernel/yap_ipython/lib/latextools.py index eaf303873..e60f18713 100644 --- a/packages/python/yap_kernel/yap_ipython/lib/latextools.py +++ b/packages/python/yap_kernel/yap_ipython/lib/latextools.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Tools for handling LaTeX.""" -# Copyright (c) yap_ipython Development Team. +# Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. from io import BytesIO, open diff --git a/packages/python/yap_kernel/yap_ipython/lib/lexers.py b/packages/python/yap_kernel/yap_ipython/lib/lexers.py index ec5cc5f29..b8dec7e43 100644 --- a/packages/python/yap_kernel/yap_ipython/lib/lexers.py +++ b/packages/python/yap_kernel/yap_ipython/lib/lexers.py @@ -1,29 +1,29 @@ # -*- coding: utf-8 -*- """ -Defines a variety of Pygments lexers for highlighting yap_ipython code. +Defines a variety of Pygments lexers for highlighting IPython code. This includes: IPythonLexer, IPython3Lexer - Lexers for pure yap_ipython (python + magic/shell commands) + Lexers for pure IPython (python + magic/shell commands) IPythonPartialTracebackLexer, IPythonTracebackLexer Supports 2.x and 3.x via keyword `python3`. The partial traceback lexer reads everything but the Python code appearing in a traceback. - The full lexer combines the partial lexer with an yap_ipython lexer. + The full lexer combines the partial lexer with an IPython lexer. IPythonConsoleLexer - A lexer for yap_ipython console sessions, with support for tracebacks. + A lexer for IPython console sessions, with support for tracebacks. IPyLexer A friendly lexer which examines the first line of text and from it, - decides whether to use an yap_ipython lexer or an yap_ipython console lexer. + decides whether to use an IPython lexer or an IPython console lexer. This is probably the only lexer that needs to be explicitly added to Pygments. """ #----------------------------------------------------------------------------- -# Copyright (c) 2013, the yap_ipython Development Team. +# Copyright (c) 2013, the IPython Development Team. # # Distributed under the terms of the Modified BSD License. # @@ -34,7 +34,9 @@ This includes: import re # Third party -from pygments.lexers import BashLexer, PythonLexer, Python3Lexer +from pygments.lexers import ( + BashLexer, HtmlLexer, JavascriptLexer, RubyLexer, PerlLexer, PythonLexer, + Python3Lexer, TexLexer) from pygments.lexer import ( Lexer, DelegatingLexer, RegexLexer, do_insertions, bygroups, using, ) @@ -51,36 +53,23 @@ __all__ = ['build_ipy_lexer', 'IPython3Lexer', 'IPythonLexer', 'IPythonPartialTracebackLexer', 'IPythonTracebackLexer', 'IPythonConsoleLexer', 'IPyLexer'] -ipython_tokens = [ - (r"(?s)(\s*)(%%)(\w+)(.*)", bygroups(Text, Operator, Keyword, Text)), - (r'(?s)(^\s*)(%%!)([^\n]*\n)(.*)', bygroups(Text, Operator, Text, using(BashLexer))), - (r"(%%?)(\w+)(\?\??)$", bygroups(Operator, Keyword, Operator)), - (r"\b(\?\??)(\s*)$", bygroups(Operator, Text)), - (r'(%)(sx|sc|system)(.*)(\n)', bygroups(Operator, Keyword, - using(BashLexer), Text)), - (r'(%)(\w+)(.*\n)', bygroups(Operator, Keyword, Text)), - (r'^(!!)(.+)(\n)', bygroups(Operator, using(BashLexer), Text)), - (r'(!)(?!=)(.+)(\n)', bygroups(Operator, using(BashLexer), Text)), - (r'^(\s*)(\?\??)(\s*%{0,2}[\w\.\*]*)', bygroups(Text, Operator, Text)), - (r'(\s*%{0,2}[\w\.\*]*)(\?\??)(\s*)$', bygroups(Text, Operator, Text)), -] def build_ipy_lexer(python3): - """Builds yap_ipython lexers depending on the value of `python3`. + """Builds IPython lexers depending on the value of `python3`. The lexer inherits from an appropriate Python lexer and then adds - information about yap_ipython specific keywords (i.e. magic commands, + information about IPython specific keywords (i.e. magic commands, shell commands, etc.) Parameters ---------- python3 : bool - If `True`, then build an yap_ipython lexer from a Python 3 lexer. + If `True`, then build an IPython lexer from a Python 3 lexer. """ - # It would be nice to have a single yap_ipython lexer class which takes + # It would be nice to have a single IPython lexer class which takes # a boolean `python3`. But since there are two Python lexer classes, - # we will also have two yap_ipython lexer classes. + # we will also have two IPython lexer classes. if python3: PyLexer = Python3Lexer name = 'IPython3' @@ -88,9 +77,39 @@ def build_ipy_lexer(python3): doc = """IPython3 Lexer""" else: PyLexer = PythonLexer - name = 'yap_ipython' + name = 'IPython' aliases = ['ipython2', 'ipython'] - doc = """yap_ipython Lexer""" + doc = """IPython Lexer""" + + ipython_tokens = [ + (r'(?s)(\s*)(%%capture)([^\n]*\n)(.*)', bygroups(Text, Operator, Text, using(PyLexer))), + (r'(?s)(\s*)(%%debug)([^\n]*\n)(.*)', bygroups(Text, Operator, Text, using(PyLexer))), + (r'(?is)(\s*)(%%html)([^\n]*\n)(.*)', bygroups(Text, Operator, Text, using(HtmlLexer))), + (r'(?s)(\s*)(%%javascript)([^\n]*\n)(.*)', bygroups(Text, Operator, Text, using(JavascriptLexer))), + (r'(?s)(\s*)(%%js)([^\n]*\n)(.*)', bygroups(Text, Operator, Text, using(JavascriptLexer))), + (r'(?s)(\s*)(%%latex)([^\n]*\n)(.*)', bygroups(Text, Operator, Text, using(TexLexer))), + (r'(?s)(\s*)(%%pypy)([^\n]*\n)(.*)', bygroups(Text, Operator, Text, using(PerlLexer))), + (r'(?s)(\s*)(%%prun)([^\n]*\n)(.*)', bygroups(Text, Operator, Text, using(PyLexer))), + (r'(?s)(\s*)(%%pypy)([^\n]*\n)(.*)', bygroups(Text, Operator, Text, using(PyLexer))), + (r'(?s)(\s*)(%%python)([^\n]*\n)(.*)', bygroups(Text, Operator, Text, using(PyLexer))), + (r'(?s)(\s*)(%%python2)([^\n]*\n)(.*)', bygroups(Text, Operator, Text, using(PythonLexer))), + (r'(?s)(\s*)(%%python3)([^\n]*\n)(.*)', bygroups(Text, Operator, Text, using(Python3Lexer))), + (r'(?s)(\s*)(%%ruby)([^\n]*\n)(.*)', bygroups(Text, Operator, Text, using(RubyLexer))), + (r'(?s)(\s*)(%%time)([^\n]*\n)(.*)', bygroups(Text, Operator, Text, using(PyLexer))), + (r'(?s)(\s*)(%%timeit)([^\n]*\n)(.*)', bygroups(Text, Operator, Text, using(PyLexer))), + (r'(?s)(\s*)(%%writefile)([^\n]*\n)(.*)', bygroups(Text, Operator, Text, using(PyLexer))), + (r"(?s)(\s*)(%%)(\w+)(.*)", bygroups(Text, Operator, Keyword, Text)), + (r'(?s)(^\s*)(%%!)([^\n]*\n)(.*)', bygroups(Text, Operator, Text, using(BashLexer))), + (r"(%%?)(\w+)(\?\??)$", bygroups(Operator, Keyword, Operator)), + (r"\b(\?\??)(\s*)$", bygroups(Operator, Text)), + (r'(%)(sx|sc|system)(.*)(\n)', bygroups(Operator, Keyword, + using(BashLexer), Text)), + (r'(%)(\w+)(.*\n)', bygroups(Operator, Keyword, Text)), + (r'^(!!)(.+)(\n)', bygroups(Operator, using(BashLexer), Text)), + (r'(!)(?!=)(.+)(\n)', bygroups(Operator, using(BashLexer), Text)), + (r'^(\s*)(\?\??)(\s*%{0,2}[\w\.\*]*)', bygroups(Text, Operator, Text)), + (r'(\s*%{0,2}[\w\.\*]*)(\?\??)(\s*)$', bygroups(Text, Operator, Text)), + ] tokens = PyLexer.tokens.copy() tokens['root'] = ipython_tokens + tokens['root'] @@ -107,12 +126,12 @@ IPythonLexer = build_ipy_lexer(python3=False) class IPythonPartialTracebackLexer(RegexLexer): """ - Partial lexer for yap_ipython tracebacks. + Partial lexer for IPython tracebacks. Handles all the non-python output. This works for both Python 2.x and 3.x. """ - name = 'yap_ipython Partial Traceback' + name = 'IPython Partial Traceback' tokens = { 'root': [ @@ -156,7 +175,7 @@ class IPythonPartialTracebackLexer(RegexLexer): class IPythonTracebackLexer(DelegatingLexer): """ - yap_ipython traceback lexer. + IPython traceback lexer. For doctests, the tracebacks can be snipped as much as desired with the exception to the lines that designate a traceback. For non-syntax error @@ -165,12 +184,12 @@ class IPythonTracebackLexer(DelegatingLexer): """ # The lexer inherits from DelegatingLexer. The "root" lexer is an - # appropriate yap_ipython lexer, which depends on the value of the boolean - # `python3`. First, we parse with the partial yap_ipython traceback lexer. + # appropriate IPython lexer, which depends on the value of the boolean + # `python3`. First, we parse with the partial IPython traceback lexer. # Then, any code marked with the "Other" token is delegated to the root # lexer. # - name = 'yap_ipython Traceback' + name = 'IPython Traceback' aliases = ['ipythontb'] def __init__(self, **options): @@ -190,7 +209,7 @@ class IPythonTracebackLexer(DelegatingLexer): class IPythonConsoleLexer(Lexer): """ - An yap_ipython console lexer for yap_ipython code-blocks and doctests, such as: + An IPython console lexer for IPython code-blocks and doctests, such as: .. code-block:: rst @@ -207,7 +226,7 @@ class IPythonConsoleLexer(Lexer): In [4]: 1 / 0 - Support is also provided for yap_ipython exceptions: + Support is also provided for IPython exceptions: .. code-block:: rst @@ -217,18 +236,18 @@ class IPythonConsoleLexer(Lexer): --------------------------------------------------------------------------- Exception Traceback (most recent call last) - in () + in ----> 1 raise Exception Exception: """ - name = 'yap_ipython console session' + name = 'IPython console session' aliases = ['ipythonconsole'] mimetypes = ['text/x-ipython-console'] # The regexps used to determine what is input and what is output. - # The default prompts for yap_ipython are: + # The default prompts for IPython are: # # in = 'In [#]: ' # continuation = ' .D.: ' @@ -245,7 +264,7 @@ class IPythonConsoleLexer(Lexer): ipytb_start = re.compile(r'^(\^C)?(-+\n)|^( File)(.*)(, line )(\d+\n)') def __init__(self, **options): - """Initialize the yap_ipython console lexer. + """Initialize the IPython console lexer. Parameters ---------- @@ -254,12 +273,12 @@ class IPythonConsoleLexer(Lexer): lexer. Otherwise, they are parsed using a Python 2 lexer. in1_regex : RegexObject The compiled regular expression used to detect the start - of inputs. Although the yap_ipython configuration setting may have a + of inputs. Although the IPython configuration setting may have a trailing whitespace, do not include it in the regex. If `None`, then the default input prompt is assumed. in2_regex : RegexObject The compiled regular expression used to detect the continuation - of inputs. Although the yap_ipython configuration setting may have a + of inputs. Although the IPython configuration setting may have a trailing whitespace, do not include it in the regex. If `None`, then the default input prompt is assumed. out_regex : RegexObject @@ -475,11 +494,11 @@ class IPythonConsoleLexer(Lexer): class IPyLexer(Lexer): """ - Primary lexer for all yap_ipython-like code. + Primary lexer for all IPython-like code. This is a simple helper lexer. If the first line of the text begins with - "In \[[0-9]+\]:", then the entire text is parsed with an yap_ipython console - lexer. If not, then the entire text is parsed with an yap_ipython lexer. + "In \[[0-9]+\]:", then the entire text is parsed with an IPython console + lexer. If not, then the entire text is parsed with an IPython lexer. The goal is to reduce the number of lexers that are registered with Pygments. diff --git a/packages/python/yap_kernel/yap_ipython/lib/pretty.py b/packages/python/yap_kernel/yap_ipython/lib/pretty.py index 9c830b947..1c3e0b2b6 100644 --- a/packages/python/yap_kernel/yap_ipython/lib/pretty.py +++ b/packages/python/yap_kernel/yap_ipython/lib/pretty.py @@ -77,11 +77,13 @@ Inheritance diagram: Portions (c) 2009 by Robert Kern. :license: BSD License. """ + from contextlib import contextmanager +import datetime +import os +import re import sys import types -import re -import datetime from collections import deque from io import StringIO from warnings import warn @@ -95,6 +97,9 @@ __all__ = ['pretty', 'pprint', 'PrettyPrinter', 'RepresentationPrinter', MAX_SEQ_LENGTH = 1000 +# The language spec says that dicts preserve order from 3.7, but CPython +# does so from 3.6, so it seems likely that people will expect that. +DICT_IS_ORDERED = sys.version_info >= (3, 6) _re_pattern_type = type(re.compile('')) def _safe_getattr(obj, attr, default=None): @@ -112,7 +117,7 @@ def _safe_getattr(obj, attr, default=None): class CUnicodeIO(StringIO): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - warn(("CUnicodeIO is deprecated since yap_ipython 6.0. " + warn(("CUnicodeIO is deprecated since IPython 6.0. " "Please use io.StringIO instead."), DeprecationWarning, stacklevel=2) @@ -392,6 +397,10 @@ class RepresentationPrinter(PrettyPrinter): meth = cls._repr_pretty_ if callable(meth): return meth(obj, self, cycle) + if cls is not object \ + and callable(cls.__dict__.get('__repr__')): + return _repr_pprint(obj, self, cycle) + return _default_pprint(obj, self, cycle) finally: self.end_group() @@ -537,17 +546,12 @@ def _default_pprint(obj, p, cycle): p.end_group(1, '>') -def _seq_pprinter_factory(start, end, basetype): +def _seq_pprinter_factory(start, end): """ Factory that returns a pprint function useful for sequences. Used by the default pprint for tuples, dicts, and lists. """ def inner(obj, p, cycle): - typ = type(obj) - if basetype is not None and typ is not basetype and typ.__repr__ != basetype.__repr__: - # If the subclass provides its own repr, use it instead. - return p.text(typ.__repr__(obj)) - if cycle: return p.text(start + '...' + end) step = len(start) @@ -564,21 +568,16 @@ def _seq_pprinter_factory(start, end, basetype): return inner -def _set_pprinter_factory(start, end, basetype): +def _set_pprinter_factory(start, end): """ Factory that returns a pprint function useful for sets and frozensets. """ def inner(obj, p, cycle): - typ = type(obj) - if basetype is not None and typ is not basetype and typ.__repr__ != basetype.__repr__: - # If the subclass provides its own repr, use it instead. - return p.text(typ.__repr__(obj)) - if cycle: return p.text(start + '...' + end) if len(obj) == 0: # Special case. - p.text(basetype.__name__ + '()') + p.text(type(obj).__name__ + '()') else: step = len(start) p.begin_group(step, start) @@ -596,24 +595,21 @@ def _set_pprinter_factory(start, end, basetype): return inner -def _dict_pprinter_factory(start, end, basetype=None): +def _dict_pprinter_factory(start, end): """ Factory that returns a pprint function used by the default pprint of dicts and dict proxies. """ def inner(obj, p, cycle): - typ = type(obj) - if basetype is not None and typ is not basetype and typ.__repr__ != basetype.__repr__: - # If the subclass provides its own repr, use it instead. - return p.text(typ.__repr__(obj)) - if cycle: return p.text('{...}') step = len(start) p.begin_group(step, start) keys = obj.keys() # if dict isn't large enough to be truncated, sort keys before displaying - if not (p.max_seq_length and len(obj) >= p.max_seq_length): + # From Python 3.7, dicts preserve order by definition, so we don't sort. + if not DICT_IS_ORDERED \ + and not (p.max_seq_length and len(obj) >= p.max_seq_length): keys = _sorted_for_pprint(keys) for idx, key in p._enumerate(keys): if idx: @@ -745,24 +741,28 @@ _type_pprinters = { int: _repr_pprint, float: _repr_pprint, str: _repr_pprint, - tuple: _seq_pprinter_factory('(', ')', tuple), - list: _seq_pprinter_factory('[', ']', list), - dict: _dict_pprinter_factory('{', '}', dict), - - set: _set_pprinter_factory('{', '}', set), - frozenset: _set_pprinter_factory('frozenset({', '})', frozenset), + tuple: _seq_pprinter_factory('(', ')'), + list: _seq_pprinter_factory('[', ']'), + dict: _dict_pprinter_factory('{', '}'), + set: _set_pprinter_factory('{', '}'), + frozenset: _set_pprinter_factory('frozenset({', '})'), super: _super_pprint, _re_pattern_type: _re_pattern_pprint, type: _type_pprint, types.FunctionType: _function_pprint, types.BuiltinFunctionType: _function_pprint, types.MethodType: _repr_pprint, - datetime.datetime: _repr_pprint, datetime.timedelta: _repr_pprint, _exception_base: _exception_pprint } +# render os.environ like a dict +_env_type = type(os.environ) +# future-proof in case os.environ becomes a plain dict? +if _env_type is not dict: + _type_pprinters[_env_type] = _dict_pprinter_factory('environ{', '}') + try: # In PyPy, types.DictProxyType is dict, setting the dictproxy printer # using dict.setdefault avoids overwritting the dict printer @@ -774,7 +774,7 @@ except AttributeError: # Python 3 _type_pprinters[types.MappingProxyType] = \ _dict_pprinter_factory('mappingproxy({', '})') _type_pprinters[slice] = _repr_pprint - + try: _type_pprinters[long] = _repr_pprint _type_pprinters[unicode] = _repr_pprint diff --git a/packages/python/yap_kernel/yap_ipython/lib/security.py b/packages/python/yap_kernel/yap_ipython/lib/security.py index f726474a7..f6d373325 100644 --- a/packages/python/yap_kernel/yap_ipython/lib/security.py +++ b/packages/python/yap_kernel/yap_ipython/lib/security.py @@ -1,5 +1,5 @@ """ -Password generation for the yap_ipython notebook. +Password generation for the IPython notebook. """ #----------------------------------------------------------------------------- # Imports diff --git a/packages/python/yap_kernel/yap_ipython/lib/tests/test_backgroundjobs.py b/packages/python/yap_kernel/yap_ipython/lib/tests/test_backgroundjobs.py index aa8efd0ed..d7793f505 100644 --- a/packages/python/yap_kernel/yap_ipython/lib/tests/test_backgroundjobs.py +++ b/packages/python/yap_kernel/yap_ipython/lib/tests/test_backgroundjobs.py @@ -1,7 +1,7 @@ """Tests for pylab tools module. """ #----------------------------------------------------------------------------- -# Copyright (c) 2011, the yap_ipython Development Team. +# Copyright (c) 2011, the IPython Development Team. # # Distributed under the terms of the Modified BSD License. # @@ -19,7 +19,7 @@ import time import nose.tools as nt # Our own imports -from yap_ipython.lib import backgroundjobs as bg +from IPython.lib import backgroundjobs as bg #----------------------------------------------------------------------------- # Globals and constants diff --git a/packages/python/yap_kernel/yap_ipython/lib/tests/test_clipboard.py b/packages/python/yap_kernel/yap_ipython/lib/tests/test_clipboard.py index a7f65c3f7..f1050bfb5 100644 --- a/packages/python/yap_kernel/yap_ipython/lib/tests/test_clipboard.py +++ b/packages/python/yap_kernel/yap_ipython/lib/tests/test_clipboard.py @@ -1,8 +1,8 @@ import nose.tools as nt -from yap_ipython.core.error import TryNext -from yap_ipython.lib.clipboard import ClipboardEmpty -from yap_ipython.testing.decorators import skip_if_no_x11 +from IPython.core.error import TryNext +from IPython.lib.clipboard import ClipboardEmpty +from IPython.testing.decorators import skip_if_no_x11 @skip_if_no_x11 def test_clipboard_get(): diff --git a/packages/python/yap_kernel/yap_ipython/lib/tests/test_deepreload.py b/packages/python/yap_kernel/yap_ipython/lib/tests/test_deepreload.py index 2d9e2a945..abc57a38f 100644 --- a/packages/python/yap_kernel/yap_ipython/lib/tests/test_deepreload.py +++ b/packages/python/yap_kernel/yap_ipython/lib/tests/test_deepreload.py @@ -1,16 +1,16 @@ # -*- coding: utf-8 -*- """Test suite for the deepreload module.""" -# Copyright (c) yap_ipython Development Team. +# Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. import os import nose.tools as nt -from yap_ipython.utils.syspathcontext import prepended_to_syspath -from yap_ipython.utils.tempdir import TemporaryDirectory -from yap_ipython.lib.deepreload import reload as dreload +from IPython.utils.syspathcontext import prepended_to_syspath +from IPython.utils.tempdir import TemporaryDirectory +from IPython.lib.deepreload import reload as dreload def test_deepreload(): "Test that dreload does deep reloads and skips excluded modules." diff --git a/packages/python/yap_kernel/yap_ipython/lib/tests/test_display.py b/packages/python/yap_kernel/yap_ipython/lib/tests/test_display.py index c3db84aff..aa0d617ed 100644 --- a/packages/python/yap_kernel/yap_ipython/lib/tests/test_display.py +++ b/packages/python/yap_kernel/yap_ipython/lib/tests/test_display.py @@ -1,8 +1,8 @@ -"""Tests for yap_ipython.lib.display. +"""Tests for IPython.lib.display. """ #----------------------------------------------------------------------------- -# Copyright (c) 2012, the yap_ipython Development Team. +# Copyright (c) 2012, the IPython Development Team. # # Distributed under the terms of the Modified BSD License. # @@ -14,13 +14,18 @@ #----------------------------------------------------------------------------- from tempfile import NamedTemporaryFile, mkdtemp from os.path import split, join as pjoin, dirname +import sys +try: + import pathlib +except ImportError: + pass # Third-party imports import nose.tools as nt # Our own imports -from yap_ipython.lib import display -from yap_ipython.testing.decorators import skipif_not_numpy +from IPython.lib import display +from IPython.testing.decorators import skipif_not_numpy #----------------------------------------------------------------------------- # Classes and functions @@ -33,6 +38,9 @@ from yap_ipython.testing.decorators import skipif_not_numpy def test_instantiation_FileLink(): """FileLink: Test class can be instantiated""" fl = display.FileLink('example.txt') + # TODO: remove if when only Python >= 3.6 is supported + if sys.version_info >= (3, 6): + fl = display.FileLink(pathlib.PurePath('example.txt')) def test_warning_on_non_existant_path_FileLink(): """FileLink: Calling _repr_html_ on non-existant files returns a warning @@ -175,3 +183,7 @@ def test_recursive_FileLinks(): def test_audio_from_file(): path = pjoin(dirname(__file__), 'test.wav') display.Audio(filename=path) + +def test_code_from_file(): + c = display.Code(filename=__file__) + assert c._repr_html_().startswith('