update jupyter
This commit is contained in:
parent
3fdbbc6a77
commit
c59b01e53c
@ -40,13 +40,45 @@ static int py_putc(int sno, int ch) {
|
|||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
char s[2];
|
unsigned char s[2];
|
||||||
PyObject *err;
|
PyObject *err;
|
||||||
s[0] = ch;
|
s[0] = ch;
|
||||||
s[1] = '\0';
|
s[1] = '\0';
|
||||||
term_t g0 = python_acquire_GIL();
|
term_t g0 = python_acquire_GIL();
|
||||||
PyObject_CallMethodObjArgs(st->u.private_data, PyUnicode_FromString("write"),
|
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);
|
python_release_GIL(g0);
|
||||||
if ((err = PyErr_Occurred())) {
|
if ((err = PyErr_Occurred())) {
|
||||||
PyErr_SetString(
|
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->u.w_irl.ptr = st->u.w_irl.buf = outbuf;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
]\]
|
]\]
|
||||||
st->user_name = TermOutStream;
|
st->user_name = TermOutStream;
|
||||||
} else if (strcmp(name, "sys.stderr") == 0) {
|
} else if (strcmp(name, "sys.stderr") == 0) {
|
||||||
@ -127,38 +157,49 @@ static bool py_close(int sno) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool pygetLine(StreamDesc *rl_iostream, int sno) {
|
static bool pygetLine(StreamDesc *rl_iostream, int sno) {
|
||||||
// term_t ctk = python_acquire_GIL();
|
// term_t ctk = python_acquire_GIL();
|
||||||
const char *myrl_line;
|
const char *myrl_line;
|
||||||
PyObject *user_line;
|
PyObject *user_line, *readl = NULL;
|
||||||
|
PyObject *err;
|
||||||
StreamDesc *s = YAP_GetStreamFromId(sno);
|
StreamDesc *s = YAP_GetStreamFromId(sno);
|
||||||
//term_t tg = python_acquire_GIL();
|
// term_t tg = python_acquire_GIL();
|
||||||
if (!strcmp(RepAtom(s->name)->StrOfAE,"input") ) {
|
PyObject_Print(s->u.private_data,stderr,0);
|
||||||
// note that input may change
|
if (PyFunction_Check( s->u.private_data )) {
|
||||||
PyObject *pystream = PyDict_GetItemString( py_Builtin, "input");
|
readl = s->u.private_data;
|
||||||
if (pystream == NULL) {
|
|
||||||
PyObject *err;
|
|
||||||
if ((err = PyErr_Occurred())) {
|
|
||||||
PyErr_Print();
|
|
||||||
Yap_ThrowError(SYSTEM_ERROR_GET_FAILED, YAP_MkIntTerm(sno), err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
user_line = PyObject_CallFunctionObjArgs(pystream, PyUnicode_FromString("?- ") , NULL);
|
if (!strcmp(RepAtom(s->name)->StrOfAE, "user_input")) {
|
||||||
} else {
|
// note that input may change
|
||||||
PyObject *readl = PyObject_GetAttrString(s->u.private_data, "readline");
|
readl = PythonLookupSpecial("input");
|
||||||
user_line = PyObject_CallFunction(readl, "?- ");
|
|
||||||
}
|
}
|
||||||
|
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);
|
myrl_line = PyUnicode_AsUTF8(user_line);
|
||||||
if (myrl_line == NULL)
|
if (myrl_line == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
PyObject *err;
|
|
||||||
if ((err = PyErr_Occurred())) {
|
if ((err = PyErr_Occurred())) {
|
||||||
|
|
||||||
if (PyErr_GivenExceptionMatches(err, PyExc_EOFError))
|
if (PyErr_GivenExceptionMatches(err, PyExc_EOFError))
|
||||||
return NULL;
|
return NULL;
|
||||||
PyErr_SetString(err, "Error in getLine\n");
|
PyErr_Print();
|
||||||
Yap_ThrowError(SYSTEM_ERROR_GET_FAILED, YAP_MkIntTerm(sno), err);
|
Yap_ThrowError(SYSTEM_ERROR_GET_FAILED, YAP_MkIntTerm(sno), err);
|
||||||
|
|
||||||
}
|
}
|
||||||
rl_iostream->u.irl.ptr = rl_iostream->u.irl.buf = (unsigned char *)myrl_line;
|
rl_iostream->u.irl.ptr = rl_iostream->u.irl.buf = (unsigned char *)myrl_line;
|
||||||
return true;
|
return true;
|
||||||
@ -182,6 +223,29 @@ static int py_getc(int sno) {
|
|||||||
return ch;
|
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
|
@brief Yap_ReadlinePeekChar peeks the next char from the
|
||||||
readline buffer, but does not actually grab it.
|
readline buffer, but does not actually grab it.
|
||||||
@ -253,8 +317,10 @@ bool init_python_vfs(void) {
|
|||||||
pystream.open = py_open;
|
pystream.open = py_open;
|
||||||
pystream.close = py_close;
|
pystream.close = py_close;
|
||||||
pystream.get_char = py_getc;
|
pystream.get_char = py_getc;
|
||||||
|
pystream.get_wchar = py_wgetc;
|
||||||
pystream.peek_char = py_peek;
|
pystream.peek_char = py_peek;
|
||||||
pystream.put_char = py_putc;
|
pystream.put_char = py_putc;
|
||||||
|
pystream.put_wchar = py_wputc;
|
||||||
pystream.flush = py_flush;
|
pystream.flush = py_flush;
|
||||||
pystream.seek = py_seek;
|
pystream.seek = py_seek;
|
||||||
pystream.next = GLOBAL_VFS;
|
pystream.next = GLOBAL_VFS;
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
# encoding: utf-8
|
# 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
|
# Distributed under the terms of the BSD License. The full license is in
|
||||||
# the file COPYING, distributed as part of this software.
|
# the file COPYING, distributed as part of this software.
|
||||||
|
@ -15,7 +15,7 @@ Computational Science, by H. P. Langtangen:
|
|||||||
|
|
||||||
http://folk.uio.no/hpl/scripting
|
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).
|
separate implementation).
|
||||||
|
|
||||||
An example notebook is provided in our documentation illustrating interactive
|
An example notebook is provided in our documentation illustrating interactive
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""Module for interactive demos using yap_ipython.
|
"""Module for interactive demos using yap_ipython.
|
||||||
|
|
||||||
This module implements a few classes for running Python scripts interactively
|
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
|
comments), you can control points where the script stops executing and returns
|
||||||
control to yap_ipython.
|
control to yap_ipython.
|
||||||
|
|
||||||
@ -13,15 +13,15 @@ The classes are (see their docstrings for further details):
|
|||||||
|
|
||||||
- Demo: pure python demos
|
- 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
|
typed interactively (so magics work, as well as any other special syntax you
|
||||||
may have added via input prefilters).
|
may have added via input prefilters).
|
||||||
|
|
||||||
- LineDemo: single-line version of the Demo class. These demos are executed
|
- LineDemo: single-line version of the Demo class. These demos are executed
|
||||||
one line at a time, and require no markup.
|
one line at a time, and require no markup.
|
||||||
|
|
||||||
- IPythonLineDemo: yap_ipython version of the LineDemo class (the demo is
|
- IPythonLineDemo: IPython version of the LineDemo class (the demo is
|
||||||
executed a line at a time, but processed via yap_ipython).
|
executed a line at a time, but processed via IPython).
|
||||||
|
|
||||||
- ClearMixin: mixin to make Demo classes with less visual clutter. It
|
- 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
|
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
|
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
|
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
|
current internal demo namespace, so you can work interactively with the data
|
||||||
accumulated so far.
|
accumulated so far.
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ The supported tags are:
|
|||||||
|
|
||||||
# <demo> stop
|
# <demo> 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.
|
file and returns to the interactive prompt.
|
||||||
|
|
||||||
You can optionally mark the stop tag with extra dashes before and after the
|
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
|
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
|
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
|
%run demo-exercizer.py
|
||||||
|
|
||||||
@ -134,11 +134,11 @@ The following is a very simple example of a valid demo file.
|
|||||||
::
|
::
|
||||||
|
|
||||||
#################### EXAMPLE DEMO <ex_demo.py> ###############################
|
#################### EXAMPLE DEMO <ex_demo.py> ###############################
|
||||||
'''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
|
# 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
|
# optional and used only as a visual aid to clearly separate blocks while
|
||||||
# editing the demo code.
|
# editing the demo code.
|
||||||
@ -188,7 +188,7 @@ import pygments
|
|||||||
from yap_ipython.utils.text import marquee
|
from yap_ipython.utils.text import marquee
|
||||||
from yap_ipython.utils import openpy
|
from yap_ipython.utils import openpy
|
||||||
from yap_ipython.utils import py3compat
|
from yap_ipython.utils import py3compat
|
||||||
__all__ = ['Demo','IPythonDemo','LineDemo','IPythonLineDemo','DemoError']
|
__all__ = ['Demo','yap_ipythonDemo','LineDemo','yap_ipythonLineDemo','DemoError']
|
||||||
|
|
||||||
class DemoError(Exception): pass
|
class DemoError(Exception): pass
|
||||||
|
|
||||||
@ -536,10 +536,10 @@ class Demo(object):
|
|||||||
|
|
||||||
|
|
||||||
class IPythonDemo(Demo):
|
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
|
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.
|
filters which may be in place are applied to the input block.
|
||||||
|
|
||||||
If you have an interactive environment which exposes special input
|
If you have an interactive environment which exposes special input
|
||||||
|
@ -2,13 +2,14 @@
|
|||||||
|
|
||||||
Authors : MinRK, gregcaporaso, dannystaple
|
Authors : MinRK, gregcaporaso, dannystaple
|
||||||
"""
|
"""
|
||||||
|
from html import escape as html_escape
|
||||||
from os.path import exists, isfile, splitext, abspath, join, isdir
|
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',
|
__all__ = ['Audio', 'IFrame', 'YouTubeVideo', 'VimeoVideo', 'ScribdDocument',
|
||||||
'FileLink', 'FileLinks']
|
'FileLink', 'FileLinks', 'Code']
|
||||||
|
|
||||||
|
|
||||||
class Audio(DisplayObject):
|
class Audio(DisplayObject):
|
||||||
@ -197,7 +198,7 @@ class Audio(DisplayObject):
|
|||||||
|
|
||||||
class IFrame(object):
|
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 = """
|
iframe = """
|
||||||
@ -232,7 +233,7 @@ class IFrame(object):
|
|||||||
params=params)
|
params=params)
|
||||||
|
|
||||||
class YouTubeVideo(IFrame):
|
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
|
e.g. to embed the video from https://www.youtube.com/watch?v=foo , you would
|
||||||
do::
|
do::
|
||||||
@ -273,7 +274,7 @@ class YouTubeVideo(IFrame):
|
|||||||
|
|
||||||
class VimeoVideo(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):
|
def __init__(self, id, width=400, height=300, **kwargs):
|
||||||
@ -282,7 +283,7 @@ class VimeoVideo(IFrame):
|
|||||||
|
|
||||||
class ScribdDocument(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 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
|
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)
|
super(ScribdDocument, self).__init__(src, width, height, **kwargs)
|
||||||
|
|
||||||
class FileLink(object):
|
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::
|
you would do::
|
||||||
|
|
||||||
@ -334,15 +335,16 @@ class FileLink(object):
|
|||||||
if isdir(path):
|
if isdir(path):
|
||||||
raise ValueError("Cannot display a directory using FileLink. "
|
raise ValueError("Cannot display a directory using FileLink. "
|
||||||
"Use FileLinks to display '%s'." % path)
|
"Use FileLinks to display '%s'." % path)
|
||||||
self.path = path
|
self.path = fsdecode(path)
|
||||||
self.url_prefix = url_prefix
|
self.url_prefix = url_prefix
|
||||||
self.result_html_prefix = result_html_prefix
|
self.result_html_prefix = result_html_prefix
|
||||||
self.result_html_suffix = result_html_suffix
|
self.result_html_suffix = result_html_suffix
|
||||||
|
|
||||||
def _format_path(self):
|
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,
|
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])
|
self.result_html_suffix])
|
||||||
|
|
||||||
def _repr_html_(self):
|
def _repr_html_(self):
|
||||||
@ -362,9 +364,9 @@ class FileLink(object):
|
|||||||
return abspath(self.path)
|
return abspath(self.path)
|
||||||
|
|
||||||
class FileLinks(FileLink):
|
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::
|
under ``my/data``, you would do::
|
||||||
|
|
||||||
local_files = FileLinks("my/data")
|
local_files = FileLinks("my/data")
|
||||||
@ -424,7 +426,7 @@ class FileLinks(FileLink):
|
|||||||
raise ValueError("Cannot display a file using FileLinks. "
|
raise ValueError("Cannot display a file using FileLinks. "
|
||||||
"Use FileLink to display '%s'." % path)
|
"Use FileLink to display '%s'." % path)
|
||||||
self.included_suffixes = included_suffixes
|
self.included_suffixes = included_suffixes
|
||||||
# remove trailing slashs for more consistent output formatting
|
# remove trailing slashes for more consistent output formatting
|
||||||
path = path.rstrip('/')
|
path = path.rstrip('/')
|
||||||
|
|
||||||
self.path = path
|
self.path = path
|
||||||
@ -555,3 +557,52 @@ class FileLinks(FileLink):
|
|||||||
for dirname, subdirs, fnames in walked_dir:
|
for dirname, subdirs, fnames in walked_dir:
|
||||||
result_lines += self.terminal_display_formatter(dirname, fnames, self.included_suffixes)
|
result_lines += self.terminal_display_formatter(dirname, fnames, self.included_suffixes)
|
||||||
return '\n'.join(result_lines)
|
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 = '<style>{}</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())
|
||||||
|
@ -11,25 +11,25 @@ import shlex
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from yap_ipython import get_ipython
|
from IPython import get_ipython
|
||||||
from yap_ipython.core.error import TryNext
|
from yap_ipython.core.error import TryNext
|
||||||
from yap_ipython.utils import py3compat
|
from yap_ipython.utils import py3compat
|
||||||
|
|
||||||
|
|
||||||
def install_editor(template, wait=False):
|
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
|
This overrides the default editor, which is generally set by your EDITOR
|
||||||
environment variable or is notepad (windows) or vi (linux). By supplying a
|
environment variable or is notepad (windows) or vi (linux). By supplying a
|
||||||
template string `run_template`, you can control how the editor is invoked
|
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
|
Parameters
|
||||||
----------
|
----------
|
||||||
template : basestring
|
template : basestring
|
||||||
run_template acts as a template for how your editor is invoked by
|
run_template acts as a template for how your editor is invoked by
|
||||||
the shell. It should contain '{filename}', which will be replaced on
|
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.
|
(or 0) to invoke the file with.
|
||||||
wait : bool
|
wait : bool
|
||||||
If `wait` is true, wait until the user presses enter before returning,
|
If `wait` is true, wait until the user presses enter before returning,
|
||||||
|
@ -2,26 +2,26 @@
|
|||||||
"""
|
"""
|
||||||
Support for creating GUI apps and starting event loops.
|
Support for creating GUI apps and starting event loops.
|
||||||
|
|
||||||
yap_ipython's GUI integration allows interative plotting and GUI usage in yap_ipython
|
IPython's GUI integration allows interactive plotting and GUI usage in IPython
|
||||||
session. yap_ipython has two different types of GUI integration:
|
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
|
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
|
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
|
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
|
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
|
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.
|
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
|
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
|
calling the function or method of the GUI toolkit that starts the event
|
||||||
loop.
|
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
|
will *always* create an appropriate GUI application object when GUi
|
||||||
integration is enabled.
|
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
|
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
|
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.
|
# Distributed under the terms of the Modified BSD License.
|
||||||
|
|
||||||
from yap_ipython.core.getipython import get_ipython
|
from yap_ipython.core.getipython import get_ipython
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
"""
|
"""
|
||||||
Deprecated since yap_ipython 5.0
|
Deprecated since IPython 5.0
|
||||||
|
|
||||||
Inputhook management for GUI event loop integration.
|
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.
|
# Distributed under the terms of the Modified BSD License.
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -22,7 +22,7 @@ from distutils.version import LooseVersion as V
|
|||||||
from warnings import warn
|
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)
|
DeprecationWarning, stacklevel=2)
|
||||||
|
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
class InputHookManager(object):
|
class InputHookManager(object):
|
||||||
"""DEPRECATED since yap_ipython 5.0
|
"""DEPRECATED since IPython 5.0
|
||||||
|
|
||||||
Manage PyOS_InputHook for different GUI toolkits.
|
Manage PyOS_InputHook for different GUI toolkits.
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ class InputHookManager(object):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
if ctypes is None:
|
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:
|
else:
|
||||||
self.PYFUNC = ctypes.PYFUNCTYPE(ctypes.c_int)
|
self.PYFUNC = ctypes.PYFUNCTYPE(ctypes.c_int)
|
||||||
self.guihooks = {}
|
self.guihooks = {}
|
||||||
@ -130,23 +130,23 @@ class InputHookManager(object):
|
|||||||
self._current_gui = None
|
self._current_gui = None
|
||||||
|
|
||||||
def get_pyos_inputhook(self):
|
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."""
|
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)
|
DeprecationWarning, stacklevel=2)
|
||||||
return ctypes.c_void_p.in_dll(ctypes.pythonapi,"PyOS_InputHook")
|
return ctypes.c_void_p.in_dll(ctypes.pythonapi,"PyOS_InputHook")
|
||||||
|
|
||||||
def get_pyos_inputhook_as_func(self):
|
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."""
|
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)
|
DeprecationWarning, stacklevel=2)
|
||||||
return self.PYFUNC.in_dll(ctypes.pythonapi,"PyOS_InputHook")
|
return self.PYFUNC.in_dll(ctypes.pythonapi,"PyOS_InputHook")
|
||||||
|
|
||||||
def set_inputhook(self, callback):
|
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."""
|
Set PyOS_InputHook to callback and return the previous one."""
|
||||||
# On platforms with 'readline' support, it's all too likely to
|
# On platforms with 'readline' support, it's all too likely to
|
||||||
@ -164,7 +164,7 @@ class InputHookManager(object):
|
|||||||
return original
|
return original
|
||||||
|
|
||||||
def clear_inputhook(self, app=None):
|
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.
|
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
|
This parameter is allowed only so that clear_inputhook() can be
|
||||||
called with a similar interface as all the ``enable_*`` methods. But
|
called with a similar interface as all the ``enable_*`` methods. But
|
||||||
the actual value of the parameter is ignored. This uniform interface
|
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`."""
|
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)
|
DeprecationWarning, stacklevel=2)
|
||||||
pyos_inputhook_ptr = self.get_pyos_inputhook()
|
pyos_inputhook_ptr = self.get_pyos_inputhook()
|
||||||
original = self.get_pyos_inputhook_as_func()
|
original = self.get_pyos_inputhook_as_func()
|
||||||
@ -186,9 +186,9 @@ class InputHookManager(object):
|
|||||||
return original
|
return original
|
||||||
|
|
||||||
def clear_app_refs(self, gui=None):
|
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
|
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
|
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
|
the app for that toolkit. References are not held for gtk or tk
|
||||||
as those toolkits don't have the notion of an app.
|
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)
|
DeprecationWarning, stacklevel=2)
|
||||||
if gui is None:
|
if gui is None:
|
||||||
self.apps = {}
|
self.apps = {}
|
||||||
@ -210,7 +210,7 @@ class InputHookManager(object):
|
|||||||
del self.apps[gui]
|
del self.apps[gui]
|
||||||
|
|
||||||
def register(self, toolkitname, *aliases):
|
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.
|
Register a class to provide the event loop for a given GUI.
|
||||||
|
|
||||||
@ -225,7 +225,7 @@ class InputHookManager(object):
|
|||||||
def enable(self, app=None):
|
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)
|
DeprecationWarning, stacklevel=2)
|
||||||
def decorator(cls):
|
def decorator(cls):
|
||||||
if ctypes is not None:
|
if ctypes is not None:
|
||||||
@ -237,15 +237,15 @@ class InputHookManager(object):
|
|||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
def current_gui(self):
|
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."""
|
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)
|
DeprecationWarning, stacklevel=2)
|
||||||
return self._current_gui
|
return self._current_gui
|
||||||
|
|
||||||
def enable_gui(self, gui=None, app=None):
|
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.
|
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
|
PyOS_InputHook wrapper object or the GUI toolkit app created, if there was
|
||||||
one.
|
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)
|
DeprecationWarning, stacklevel=2)
|
||||||
if gui in (None, GUI_NONE):
|
if gui in (None, GUI_NONE):
|
||||||
return self.disable_gui()
|
return self.disable_gui()
|
||||||
@ -293,14 +293,14 @@ class InputHookManager(object):
|
|||||||
return app
|
return app
|
||||||
|
|
||||||
def disable_gui(self):
|
def disable_gui(self):
|
||||||
"""DEPRECATED since yap_ipython 5.0
|
"""DEPRECATED since IPython 5.0
|
||||||
|
|
||||||
Disable GUI event loop integration.
|
Disable GUI event loop integration.
|
||||||
|
|
||||||
If an application was registered, this sets its ``_in_event_loop``
|
If an application was registered, this sets its ``_in_event_loop``
|
||||||
attribute to False. It then calls :meth:`clear_inputhook`.
|
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)
|
DeprecationWarning, stacklevel=2)
|
||||||
gui = self._current_gui
|
gui = self._current_gui
|
||||||
if gui in self.apps:
|
if gui in self.apps:
|
||||||
@ -308,7 +308,7 @@ class InputHookManager(object):
|
|||||||
return self.clear_inputhook()
|
return self.clear_inputhook()
|
||||||
|
|
||||||
class InputHookBase(object):
|
class InputHookBase(object):
|
||||||
"""DEPRECATED since yap_ipython 5.0
|
"""DEPRECATED since IPython 5.0
|
||||||
|
|
||||||
Base class for input hooks for specific toolkits.
|
Base class for input hooks for specific toolkits.
|
||||||
|
|
||||||
@ -326,17 +326,17 @@ inputhook_manager = InputHookManager()
|
|||||||
|
|
||||||
@inputhook_manager.register('osx')
|
@inputhook_manager.register('osx')
|
||||||
class NullInputHook(InputHookBase):
|
class NullInputHook(InputHookBase):
|
||||||
"""DEPRECATED since yap_ipython 5.0
|
"""DEPRECATED since IPython 5.0
|
||||||
|
|
||||||
A null inputhook that doesn't need to do anything"""
|
A null inputhook that doesn't need to do anything"""
|
||||||
def enable(self, app=None):
|
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)
|
DeprecationWarning, stacklevel=2)
|
||||||
|
|
||||||
@inputhook_manager.register('wx')
|
@inputhook_manager.register('wx')
|
||||||
class WxInputHook(InputHookBase):
|
class WxInputHook(InputHookBase):
|
||||||
def enable(self, app=None):
|
def enable(self, app=None):
|
||||||
"""DEPRECATED since yap_ipython 5.0
|
"""DEPRECATED since IPython 5.0
|
||||||
|
|
||||||
Enable event loop integration with wxPython.
|
Enable event loop integration with wxPython.
|
||||||
|
|
||||||
@ -359,7 +359,7 @@ class WxInputHook(InputHookBase):
|
|||||||
import wx
|
import wx
|
||||||
app = wx.App(redirect=False, clearSigInt=False)
|
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)
|
DeprecationWarning, stacklevel=2)
|
||||||
import wx
|
import wx
|
||||||
|
|
||||||
@ -383,13 +383,13 @@ class WxInputHook(InputHookBase):
|
|||||||
return app
|
return app
|
||||||
|
|
||||||
def disable(self):
|
def disable(self):
|
||||||
"""DEPRECATED since yap_ipython 5.0
|
"""DEPRECATED since IPython 5.0
|
||||||
|
|
||||||
Disable event loop integration with wxPython.
|
Disable event loop integration with wxPython.
|
||||||
|
|
||||||
This restores appnapp on OS X
|
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)
|
DeprecationWarning, stacklevel=2)
|
||||||
if _use_appnope():
|
if _use_appnope():
|
||||||
from appnope import nap
|
from appnope import nap
|
||||||
@ -398,7 +398,7 @@ class WxInputHook(InputHookBase):
|
|||||||
@inputhook_manager.register('qt', 'qt4')
|
@inputhook_manager.register('qt', 'qt4')
|
||||||
class Qt4InputHook(InputHookBase):
|
class Qt4InputHook(InputHookBase):
|
||||||
def enable(self, app=None):
|
def enable(self, app=None):
|
||||||
"""DEPRECATED since yap_ipython 5.0
|
"""DEPRECATED since IPython 5.0
|
||||||
|
|
||||||
Enable event loop integration with PyQt4.
|
Enable event loop integration with PyQt4.
|
||||||
|
|
||||||
@ -421,7 +421,7 @@ class Qt4InputHook(InputHookBase):
|
|||||||
from PyQt4 import QtCore
|
from PyQt4 import QtCore
|
||||||
app = QtGui.QApplication(sys.argv)
|
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)
|
DeprecationWarning, stacklevel=2)
|
||||||
from yap_ipython.lib.inputhookqt4 import create_inputhook_qt4
|
from yap_ipython.lib.inputhookqt4 import create_inputhook_qt4
|
||||||
app, inputhook_qt4 = create_inputhook_qt4(self.manager, app)
|
app, inputhook_qt4 = create_inputhook_qt4(self.manager, app)
|
||||||
@ -433,13 +433,13 @@ class Qt4InputHook(InputHookBase):
|
|||||||
return app
|
return app
|
||||||
|
|
||||||
def disable_qt4(self):
|
def disable_qt4(self):
|
||||||
"""DEPRECATED since yap_ipython 5.0
|
"""DEPRECATED since IPython 5.0
|
||||||
|
|
||||||
Disable event loop integration with PyQt4.
|
Disable event loop integration with PyQt4.
|
||||||
|
|
||||||
This restores appnapp on OS X
|
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)
|
DeprecationWarning, stacklevel=2)
|
||||||
if _use_appnope():
|
if _use_appnope():
|
||||||
from appnope import nap
|
from appnope import nap
|
||||||
@ -449,7 +449,7 @@ class Qt4InputHook(InputHookBase):
|
|||||||
@inputhook_manager.register('qt5')
|
@inputhook_manager.register('qt5')
|
||||||
class Qt5InputHook(Qt4InputHook):
|
class Qt5InputHook(Qt4InputHook):
|
||||||
def enable(self, app=None):
|
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)
|
DeprecationWarning, stacklevel=2)
|
||||||
os.environ['QT_API'] = 'pyqt5'
|
os.environ['QT_API'] = 'pyqt5'
|
||||||
return Qt4InputHook.enable(self, app)
|
return Qt4InputHook.enable(self, app)
|
||||||
@ -458,7 +458,7 @@ class Qt5InputHook(Qt4InputHook):
|
|||||||
@inputhook_manager.register('gtk')
|
@inputhook_manager.register('gtk')
|
||||||
class GtkInputHook(InputHookBase):
|
class GtkInputHook(InputHookBase):
|
||||||
def enable(self, app=None):
|
def enable(self, app=None):
|
||||||
"""DEPRECATED since yap_ipython 5.0
|
"""DEPRECATED since IPython 5.0
|
||||||
|
|
||||||
Enable event loop integration with PyGTK.
|
Enable event loop integration with PyGTK.
|
||||||
|
|
||||||
@ -475,7 +475,7 @@ class GtkInputHook(InputHookBase):
|
|||||||
the PyGTK to integrate with terminal based applications like
|
the PyGTK to integrate with terminal based applications like
|
||||||
yap_ipython.
|
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)
|
DeprecationWarning, stacklevel=2)
|
||||||
import gtk
|
import gtk
|
||||||
try:
|
try:
|
||||||
@ -489,7 +489,7 @@ class GtkInputHook(InputHookBase):
|
|||||||
@inputhook_manager.register('tk')
|
@inputhook_manager.register('tk')
|
||||||
class TkInputHook(InputHookBase):
|
class TkInputHook(InputHookBase):
|
||||||
def enable(self, app=None):
|
def enable(self, app=None):
|
||||||
"""DEPRECATED since yap_ipython 5.0
|
"""DEPRECATED since IPython 5.0
|
||||||
|
|
||||||
Enable event loop integration with Tk.
|
Enable event loop integration with Tk.
|
||||||
|
|
||||||
@ -506,7 +506,7 @@ class TkInputHook(InputHookBase):
|
|||||||
:class:`InputHookManager`, since creating that object automatically
|
:class:`InputHookManager`, since creating that object automatically
|
||||||
sets ``PyOS_InputHook``.
|
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)
|
DeprecationWarning, stacklevel=2)
|
||||||
if app is None:
|
if app is None:
|
||||||
try:
|
try:
|
||||||
@ -522,7 +522,7 @@ class TkInputHook(InputHookBase):
|
|||||||
@inputhook_manager.register('glut')
|
@inputhook_manager.register('glut')
|
||||||
class GlutInputHook(InputHookBase):
|
class GlutInputHook(InputHookBase):
|
||||||
def enable(self, app=None):
|
def enable(self, app=None):
|
||||||
"""DEPRECATED since yap_ipython 5.0
|
"""DEPRECATED since IPython 5.0
|
||||||
|
|
||||||
Enable event loop integration with GLUT.
|
Enable event loop integration with GLUT.
|
||||||
|
|
||||||
@ -547,7 +547,7 @@ class GlutInputHook(InputHookBase):
|
|||||||
The default screen mode is set to:
|
The default screen mode is set to:
|
||||||
glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH
|
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)
|
DeprecationWarning, stacklevel=2)
|
||||||
|
|
||||||
import OpenGL.GLUT as glut
|
import OpenGL.GLUT as glut
|
||||||
@ -576,7 +576,7 @@ class GlutInputHook(InputHookBase):
|
|||||||
|
|
||||||
|
|
||||||
def disable(self):
|
def disable(self):
|
||||||
"""DEPRECATED since yap_ipython 5.0
|
"""DEPRECATED since IPython 5.0
|
||||||
|
|
||||||
Disable event loop integration with glut.
|
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
|
dummy one and set the timer to a dummy timer that will be triggered
|
||||||
very far in the future.
|
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)
|
DeprecationWarning, stacklevel=2)
|
||||||
import OpenGL.GLUT as glut
|
import OpenGL.GLUT as glut
|
||||||
from glut_support import glutMainLoopEvent
|
from glut_support import glutMainLoopEvent
|
||||||
@ -596,7 +596,7 @@ class GlutInputHook(InputHookBase):
|
|||||||
@inputhook_manager.register('pyglet')
|
@inputhook_manager.register('pyglet')
|
||||||
class PygletInputHook(InputHookBase):
|
class PygletInputHook(InputHookBase):
|
||||||
def enable(self, app=None):
|
def enable(self, app=None):
|
||||||
"""DEPRECATED since yap_ipython 5.0
|
"""DEPRECATED since IPython 5.0
|
||||||
|
|
||||||
Enable event loop integration with pyglet.
|
Enable event loop integration with pyglet.
|
||||||
|
|
||||||
@ -614,7 +614,7 @@ class PygletInputHook(InputHookBase):
|
|||||||
yap_ipython.
|
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)
|
DeprecationWarning, stacklevel=2)
|
||||||
from yap_ipython.lib.inputhookpyglet import inputhook_pyglet
|
from yap_ipython.lib.inputhookpyglet import inputhook_pyglet
|
||||||
self.manager.set_inputhook(inputhook_pyglet)
|
self.manager.set_inputhook(inputhook_pyglet)
|
||||||
@ -624,7 +624,7 @@ class PygletInputHook(InputHookBase):
|
|||||||
@inputhook_manager.register('gtk3')
|
@inputhook_manager.register('gtk3')
|
||||||
class Gtk3InputHook(InputHookBase):
|
class Gtk3InputHook(InputHookBase):
|
||||||
def enable(self, app=None):
|
def enable(self, app=None):
|
||||||
"""DEPRECATED since yap_ipython 5.0
|
"""DEPRECATED since IPython 5.0
|
||||||
|
|
||||||
Enable event loop integration with Gtk3 (gir bindings).
|
Enable event loop integration with Gtk3 (gir bindings).
|
||||||
|
|
||||||
@ -641,7 +641,7 @@ class Gtk3InputHook(InputHookBase):
|
|||||||
the Gtk3 to integrate with terminal based applications like
|
the Gtk3 to integrate with terminal based applications like
|
||||||
yap_ipython.
|
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)
|
DeprecationWarning, stacklevel=2)
|
||||||
from yap_ipython.lib.inputhookgtk3 import inputhook_gtk3
|
from yap_ipython.lib.inputhookgtk3 import inputhook_gtk3
|
||||||
self.manager.set_inputhook(inputhook_gtk3)
|
self.manager.set_inputhook(inputhook_gtk3)
|
||||||
@ -658,7 +658,7 @@ guis = inputhook_manager.guihooks
|
|||||||
|
|
||||||
|
|
||||||
def _deprecated_disable():
|
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)
|
DeprecationWarning, stacklevel=2)
|
||||||
inputhook_manager.disable_gui()
|
inputhook_manager.disable_gui()
|
||||||
|
|
||||||
|
@ -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
|
# Distributed under the terms of the BSD License. The full license is in
|
||||||
# the file COPYING, distributed as part of this software.
|
# the file COPYING, distributed as part of this software.
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
|
|
||||||
# GLUT is quite an old library and it is difficult to ensure proper
|
# 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
|
# 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
|
# and never returned (there is not even a function to exit he
|
||||||
# mainloop). Fortunately, there are alternatives such as freeglut
|
# 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
|
# 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
|
# 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
|
# them later without modifying the code. This should probably be made available
|
||||||
# via yap_ipython options system.
|
# via IPython options system.
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
# Imports
|
# Imports
|
||||||
@ -42,12 +42,12 @@ from timeit import default_timer as clock
|
|||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
|
|
||||||
# Frame per second : 60
|
# Frame per second : 60
|
||||||
# Should probably be an yap_ipython option
|
# Should probably be an IPython option
|
||||||
glut_fps = 60
|
glut_fps = 60
|
||||||
|
|
||||||
|
|
||||||
# Display mode : double buffeed + rgba + depth
|
# 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_display_mode = (glut.GLUT_DOUBLE |
|
||||||
glut.GLUT_RGBA |
|
glut.GLUT_RGBA |
|
||||||
glut.GLUT_DEPTH)
|
glut.GLUT_DEPTH)
|
||||||
@ -112,7 +112,7 @@ def glut_close():
|
|||||||
glutMainLoopEvent()
|
glutMainLoopEvent()
|
||||||
|
|
||||||
def glut_int_handler(signum, frame):
|
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)
|
signal.signal(signal.SIGINT, signal.default_int_handler)
|
||||||
print('\nKeyboardInterrupt')
|
print('\nKeyboardInterrupt')
|
||||||
# Need to reprint the prompt at this stage
|
# 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
|
needed, otherwise, CPU usage is at 100%. This sleep time should be tuned
|
||||||
though for best performance.
|
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.
|
# idle and this is running. We trap KeyboardInterrupt and pass.
|
||||||
|
|
||||||
signal.signal(signal.SIGINT, glut_int_handler)
|
signal.signal(signal.SIGINT, glut_int_handler)
|
||||||
|
@ -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
|
# Distributed under the terms of the BSD License. The full license is in
|
||||||
# the file COPYING, distributed as part of this software.
|
# the file COPYING, distributed as part of this software.
|
||||||
|
@ -5,7 +5,7 @@ Enable Gtk3 to be used interacive by yap_ipython.
|
|||||||
Authors: Thomi Richards
|
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.
|
# Distributed under the terms of the Modified BSD License.
|
||||||
#
|
#
|
||||||
|
@ -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
|
# Distributed under the terms of the BSD License. The full license is in
|
||||||
# the file COPYING, distributed as part of this software.
|
# 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
|
needed, otherwise, CPU usage is at 100%. This sleep time should be tuned
|
||||||
though for best performance.
|
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.
|
# idle and this is running. We trap KeyboardInterrupt and pass.
|
||||||
try:
|
try:
|
||||||
t = clock()
|
t = clock()
|
||||||
|
@ -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
|
# Distributed under the terms of the BSD License. The full license is in
|
||||||
# the file COPYING, distributed as part of this software.
|
# the file COPYING, distributed as part of this software.
|
||||||
|
@ -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
|
# Distributed under the terms of the BSD License. The full license is in
|
||||||
# the file COPYING, distributed as part of this software.
|
# 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%.
|
time.sleep is inserted. This is needed, otherwise, CPU usage is at 100%.
|
||||||
This sleep time should be tuned though for best performance.
|
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.
|
# idle and this is running. We trap KeyboardInterrupt and pass.
|
||||||
try:
|
try:
|
||||||
app = wx.GetApp()
|
app = wx.GetApp()
|
||||||
|
@ -4,10 +4,10 @@ Moved to yap_ipython.kernel.connect
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import warnings
|
import warnings
|
||||||
warnings.warn("yap_ipython.lib.kernel moved to yap_ipython.kernel.connect in yap_ipython 1.0,"
|
warnings.warn("yap_ipython.lib.kernel moved to yap_ipython.kernel.connect in IPython 1.0,"
|
||||||
" and will be removed in yap_ipython 6.0.",
|
" and will be removed in IPython 6.0.",
|
||||||
DeprecationWarning
|
DeprecationWarning
|
||||||
)
|
)
|
||||||
|
|
||||||
from yap_kernel.connect import *
|
from ipykernel.connect import *
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""Tools for handling LaTeX."""
|
"""Tools for handling LaTeX."""
|
||||||
|
|
||||||
# Copyright (c) yap_ipython Development Team.
|
# Copyright (c) IPython Development Team.
|
||||||
# Distributed under the terms of the Modified BSD License.
|
# Distributed under the terms of the Modified BSD License.
|
||||||
|
|
||||||
from io import BytesIO, open
|
from io import BytesIO, open
|
||||||
|
@ -1,29 +1,29 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- 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:
|
This includes:
|
||||||
|
|
||||||
IPythonLexer, IPython3Lexer
|
IPythonLexer, IPython3Lexer
|
||||||
Lexers for pure yap_ipython (python + magic/shell commands)
|
Lexers for pure IPython (python + magic/shell commands)
|
||||||
|
|
||||||
IPythonPartialTracebackLexer, IPythonTracebackLexer
|
IPythonPartialTracebackLexer, IPythonTracebackLexer
|
||||||
Supports 2.x and 3.x via keyword `python3`. The partial traceback
|
Supports 2.x and 3.x via keyword `python3`. The partial traceback
|
||||||
lexer reads everything but the Python code appearing in a 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
|
IPythonConsoleLexer
|
||||||
A lexer for yap_ipython console sessions, with support for tracebacks.
|
A lexer for IPython console sessions, with support for tracebacks.
|
||||||
|
|
||||||
IPyLexer
|
IPyLexer
|
||||||
A friendly lexer which examines the first line of text and from it,
|
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
|
This is probably the only lexer that needs to be explicitly added
|
||||||
to Pygments.
|
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.
|
# Distributed under the terms of the Modified BSD License.
|
||||||
#
|
#
|
||||||
@ -34,7 +34,9 @@ This includes:
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
# Third party
|
# 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 (
|
from pygments.lexer import (
|
||||||
Lexer, DelegatingLexer, RegexLexer, do_insertions, bygroups, using,
|
Lexer, DelegatingLexer, RegexLexer, do_insertions, bygroups, using,
|
||||||
)
|
)
|
||||||
@ -51,36 +53,23 @@ __all__ = ['build_ipy_lexer', 'IPython3Lexer', 'IPythonLexer',
|
|||||||
'IPythonPartialTracebackLexer', 'IPythonTracebackLexer',
|
'IPythonPartialTracebackLexer', 'IPythonTracebackLexer',
|
||||||
'IPythonConsoleLexer', 'IPyLexer']
|
'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):
|
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
|
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.)
|
shell commands, etc.)
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
python3 : bool
|
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,
|
# 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:
|
if python3:
|
||||||
PyLexer = Python3Lexer
|
PyLexer = Python3Lexer
|
||||||
name = 'IPython3'
|
name = 'IPython3'
|
||||||
@ -88,9 +77,39 @@ def build_ipy_lexer(python3):
|
|||||||
doc = """IPython3 Lexer"""
|
doc = """IPython3 Lexer"""
|
||||||
else:
|
else:
|
||||||
PyLexer = PythonLexer
|
PyLexer = PythonLexer
|
||||||
name = 'yap_ipython'
|
name = 'IPython'
|
||||||
aliases = ['ipython2', '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 = PyLexer.tokens.copy()
|
||||||
tokens['root'] = ipython_tokens + tokens['root']
|
tokens['root'] = ipython_tokens + tokens['root']
|
||||||
@ -107,12 +126,12 @@ IPythonLexer = build_ipy_lexer(python3=False)
|
|||||||
|
|
||||||
class IPythonPartialTracebackLexer(RegexLexer):
|
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.
|
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 = {
|
tokens = {
|
||||||
'root': [
|
'root': [
|
||||||
@ -156,7 +175,7 @@ class IPythonPartialTracebackLexer(RegexLexer):
|
|||||||
|
|
||||||
class IPythonTracebackLexer(DelegatingLexer):
|
class IPythonTracebackLexer(DelegatingLexer):
|
||||||
"""
|
"""
|
||||||
yap_ipython traceback lexer.
|
IPython traceback lexer.
|
||||||
|
|
||||||
For doctests, the tracebacks can be snipped as much as desired with the
|
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
|
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
|
# The lexer inherits from DelegatingLexer. The "root" lexer is an
|
||||||
# appropriate yap_ipython lexer, which depends on the value of the boolean
|
# appropriate IPython lexer, which depends on the value of the boolean
|
||||||
# `python3`. First, we parse with the partial yap_ipython traceback lexer.
|
# `python3`. First, we parse with the partial IPython traceback lexer.
|
||||||
# Then, any code marked with the "Other" token is delegated to the root
|
# Then, any code marked with the "Other" token is delegated to the root
|
||||||
# lexer.
|
# lexer.
|
||||||
#
|
#
|
||||||
name = 'yap_ipython Traceback'
|
name = 'IPython Traceback'
|
||||||
aliases = ['ipythontb']
|
aliases = ['ipythontb']
|
||||||
|
|
||||||
def __init__(self, **options):
|
def __init__(self, **options):
|
||||||
@ -190,7 +209,7 @@ class IPythonTracebackLexer(DelegatingLexer):
|
|||||||
|
|
||||||
class IPythonConsoleLexer(Lexer):
|
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
|
.. code-block:: rst
|
||||||
|
|
||||||
@ -207,7 +226,7 @@ class IPythonConsoleLexer(Lexer):
|
|||||||
In [4]: 1 / 0
|
In [4]: 1 / 0
|
||||||
|
|
||||||
|
|
||||||
Support is also provided for yap_ipython exceptions:
|
Support is also provided for IPython exceptions:
|
||||||
|
|
||||||
.. code-block:: rst
|
.. code-block:: rst
|
||||||
|
|
||||||
@ -217,18 +236,18 @@ class IPythonConsoleLexer(Lexer):
|
|||||||
|
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
Exception Traceback (most recent call last)
|
Exception Traceback (most recent call last)
|
||||||
<ipython-input-1-fca2ab0ca76b> in <module>()
|
<ipython-input-1-fca2ab0ca76b> in <module>
|
||||||
----> 1 raise Exception
|
----> 1 raise Exception
|
||||||
|
|
||||||
Exception:
|
Exception:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
name = 'yap_ipython console session'
|
name = 'IPython console session'
|
||||||
aliases = ['ipythonconsole']
|
aliases = ['ipythonconsole']
|
||||||
mimetypes = ['text/x-ipython-console']
|
mimetypes = ['text/x-ipython-console']
|
||||||
|
|
||||||
# The regexps used to determine what is input and what is output.
|
# 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 [#]: '
|
# in = 'In [#]: '
|
||||||
# continuation = ' .D.: '
|
# continuation = ' .D.: '
|
||||||
@ -245,7 +264,7 @@ class IPythonConsoleLexer(Lexer):
|
|||||||
ipytb_start = re.compile(r'^(\^C)?(-+\n)|^( File)(.*)(, line )(\d+\n)')
|
ipytb_start = re.compile(r'^(\^C)?(-+\n)|^( File)(.*)(, line )(\d+\n)')
|
||||||
|
|
||||||
def __init__(self, **options):
|
def __init__(self, **options):
|
||||||
"""Initialize the yap_ipython console lexer.
|
"""Initialize the IPython console lexer.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
@ -254,12 +273,12 @@ class IPythonConsoleLexer(Lexer):
|
|||||||
lexer. Otherwise, they are parsed using a Python 2 lexer.
|
lexer. Otherwise, they are parsed using a Python 2 lexer.
|
||||||
in1_regex : RegexObject
|
in1_regex : RegexObject
|
||||||
The compiled regular expression used to detect the start
|
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`,
|
trailing whitespace, do not include it in the regex. If `None`,
|
||||||
then the default input prompt is assumed.
|
then the default input prompt is assumed.
|
||||||
in2_regex : RegexObject
|
in2_regex : RegexObject
|
||||||
The compiled regular expression used to detect the continuation
|
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`,
|
trailing whitespace, do not include it in the regex. If `None`,
|
||||||
then the default input prompt is assumed.
|
then the default input prompt is assumed.
|
||||||
out_regex : RegexObject
|
out_regex : RegexObject
|
||||||
@ -475,11 +494,11 @@ class IPythonConsoleLexer(Lexer):
|
|||||||
|
|
||||||
class IPyLexer(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
|
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
|
"In \[[0-9]+\]:", then the entire text is parsed with an IPython console
|
||||||
lexer. If not, then the entire text is parsed with an yap_ipython lexer.
|
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
|
The goal is to reduce the number of lexers that are registered
|
||||||
with Pygments.
|
with Pygments.
|
||||||
|
@ -77,11 +77,13 @@ Inheritance diagram:
|
|||||||
Portions (c) 2009 by Robert Kern.
|
Portions (c) 2009 by Robert Kern.
|
||||||
:license: BSD License.
|
:license: BSD License.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
import datetime
|
||||||
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import types
|
import types
|
||||||
import re
|
|
||||||
import datetime
|
|
||||||
from collections import deque
|
from collections import deque
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from warnings import warn
|
from warnings import warn
|
||||||
@ -95,6 +97,9 @@ __all__ = ['pretty', 'pprint', 'PrettyPrinter', 'RepresentationPrinter',
|
|||||||
|
|
||||||
|
|
||||||
MAX_SEQ_LENGTH = 1000
|
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(''))
|
_re_pattern_type = type(re.compile(''))
|
||||||
|
|
||||||
def _safe_getattr(obj, attr, default=None):
|
def _safe_getattr(obj, attr, default=None):
|
||||||
@ -112,7 +117,7 @@ def _safe_getattr(obj, attr, default=None):
|
|||||||
class CUnicodeIO(StringIO):
|
class CUnicodeIO(StringIO):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*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."),
|
"Please use io.StringIO instead."),
|
||||||
DeprecationWarning, stacklevel=2)
|
DeprecationWarning, stacklevel=2)
|
||||||
|
|
||||||
@ -392,6 +397,10 @@ class RepresentationPrinter(PrettyPrinter):
|
|||||||
meth = cls._repr_pretty_
|
meth = cls._repr_pretty_
|
||||||
if callable(meth):
|
if callable(meth):
|
||||||
return meth(obj, self, cycle)
|
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)
|
return _default_pprint(obj, self, cycle)
|
||||||
finally:
|
finally:
|
||||||
self.end_group()
|
self.end_group()
|
||||||
@ -537,17 +546,12 @@ def _default_pprint(obj, p, cycle):
|
|||||||
p.end_group(1, '>')
|
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
|
Factory that returns a pprint function useful for sequences. Used by
|
||||||
the default pprint for tuples, dicts, and lists.
|
the default pprint for tuples, dicts, and lists.
|
||||||
"""
|
"""
|
||||||
def inner(obj, p, cycle):
|
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:
|
if cycle:
|
||||||
return p.text(start + '...' + end)
|
return p.text(start + '...' + end)
|
||||||
step = len(start)
|
step = len(start)
|
||||||
@ -564,21 +568,16 @@ def _seq_pprinter_factory(start, end, basetype):
|
|||||||
return inner
|
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.
|
Factory that returns a pprint function useful for sets and frozensets.
|
||||||
"""
|
"""
|
||||||
def inner(obj, p, cycle):
|
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:
|
if cycle:
|
||||||
return p.text(start + '...' + end)
|
return p.text(start + '...' + end)
|
||||||
if len(obj) == 0:
|
if len(obj) == 0:
|
||||||
# Special case.
|
# Special case.
|
||||||
p.text(basetype.__name__ + '()')
|
p.text(type(obj).__name__ + '()')
|
||||||
else:
|
else:
|
||||||
step = len(start)
|
step = len(start)
|
||||||
p.begin_group(step, start)
|
p.begin_group(step, start)
|
||||||
@ -596,24 +595,21 @@ def _set_pprinter_factory(start, end, basetype):
|
|||||||
return inner
|
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
|
Factory that returns a pprint function used by the default pprint of
|
||||||
dicts and dict proxies.
|
dicts and dict proxies.
|
||||||
"""
|
"""
|
||||||
def inner(obj, p, cycle):
|
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:
|
if cycle:
|
||||||
return p.text('{...}')
|
return p.text('{...}')
|
||||||
step = len(start)
|
step = len(start)
|
||||||
p.begin_group(step, start)
|
p.begin_group(step, start)
|
||||||
keys = obj.keys()
|
keys = obj.keys()
|
||||||
# if dict isn't large enough to be truncated, sort keys before displaying
|
# 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)
|
keys = _sorted_for_pprint(keys)
|
||||||
for idx, key in p._enumerate(keys):
|
for idx, key in p._enumerate(keys):
|
||||||
if idx:
|
if idx:
|
||||||
@ -745,24 +741,28 @@ _type_pprinters = {
|
|||||||
int: _repr_pprint,
|
int: _repr_pprint,
|
||||||
float: _repr_pprint,
|
float: _repr_pprint,
|
||||||
str: _repr_pprint,
|
str: _repr_pprint,
|
||||||
tuple: _seq_pprinter_factory('(', ')', tuple),
|
tuple: _seq_pprinter_factory('(', ')'),
|
||||||
list: _seq_pprinter_factory('[', ']', list),
|
list: _seq_pprinter_factory('[', ']'),
|
||||||
dict: _dict_pprinter_factory('{', '}', dict),
|
dict: _dict_pprinter_factory('{', '}'),
|
||||||
|
set: _set_pprinter_factory('{', '}'),
|
||||||
set: _set_pprinter_factory('{', '}', set),
|
frozenset: _set_pprinter_factory('frozenset({', '})'),
|
||||||
frozenset: _set_pprinter_factory('frozenset({', '})', frozenset),
|
|
||||||
super: _super_pprint,
|
super: _super_pprint,
|
||||||
_re_pattern_type: _re_pattern_pprint,
|
_re_pattern_type: _re_pattern_pprint,
|
||||||
type: _type_pprint,
|
type: _type_pprint,
|
||||||
types.FunctionType: _function_pprint,
|
types.FunctionType: _function_pprint,
|
||||||
types.BuiltinFunctionType: _function_pprint,
|
types.BuiltinFunctionType: _function_pprint,
|
||||||
types.MethodType: _repr_pprint,
|
types.MethodType: _repr_pprint,
|
||||||
|
|
||||||
datetime.datetime: _repr_pprint,
|
datetime.datetime: _repr_pprint,
|
||||||
datetime.timedelta: _repr_pprint,
|
datetime.timedelta: _repr_pprint,
|
||||||
_exception_base: _exception_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:
|
try:
|
||||||
# In PyPy, types.DictProxyType is dict, setting the dictproxy printer
|
# In PyPy, types.DictProxyType is dict, setting the dictproxy printer
|
||||||
# using dict.setdefault avoids overwritting the dict printer
|
# using dict.setdefault avoids overwritting the dict printer
|
||||||
@ -774,7 +774,7 @@ except AttributeError: # Python 3
|
|||||||
_type_pprinters[types.MappingProxyType] = \
|
_type_pprinters[types.MappingProxyType] = \
|
||||||
_dict_pprinter_factory('mappingproxy({', '})')
|
_dict_pprinter_factory('mappingproxy({', '})')
|
||||||
_type_pprinters[slice] = _repr_pprint
|
_type_pprinters[slice] = _repr_pprint
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_type_pprinters[long] = _repr_pprint
|
_type_pprinters[long] = _repr_pprint
|
||||||
_type_pprinters[unicode] = _repr_pprint
|
_type_pprinters[unicode] = _repr_pprint
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Password generation for the yap_ipython notebook.
|
Password generation for the IPython notebook.
|
||||||
"""
|
"""
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
# Imports
|
# Imports
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""Tests for pylab tools module.
|
"""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.
|
# Distributed under the terms of the Modified BSD License.
|
||||||
#
|
#
|
||||||
@ -19,7 +19,7 @@ import time
|
|||||||
import nose.tools as nt
|
import nose.tools as nt
|
||||||
|
|
||||||
# Our own imports
|
# Our own imports
|
||||||
from yap_ipython.lib import backgroundjobs as bg
|
from IPython.lib import backgroundjobs as bg
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
# Globals and constants
|
# Globals and constants
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import nose.tools as nt
|
import nose.tools as nt
|
||||||
|
|
||||||
from yap_ipython.core.error import TryNext
|
from IPython.core.error import TryNext
|
||||||
from yap_ipython.lib.clipboard import ClipboardEmpty
|
from IPython.lib.clipboard import ClipboardEmpty
|
||||||
from yap_ipython.testing.decorators import skip_if_no_x11
|
from IPython.testing.decorators import skip_if_no_x11
|
||||||
|
|
||||||
@skip_if_no_x11
|
@skip_if_no_x11
|
||||||
def test_clipboard_get():
|
def test_clipboard_get():
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""Test suite for the deepreload module."""
|
"""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.
|
# Distributed under the terms of the Modified BSD License.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import nose.tools as nt
|
import nose.tools as nt
|
||||||
|
|
||||||
from yap_ipython.utils.syspathcontext import prepended_to_syspath
|
from IPython.utils.syspathcontext import prepended_to_syspath
|
||||||
from yap_ipython.utils.tempdir import TemporaryDirectory
|
from IPython.utils.tempdir import TemporaryDirectory
|
||||||
from yap_ipython.lib.deepreload import reload as dreload
|
from IPython.lib.deepreload import reload as dreload
|
||||||
|
|
||||||
def test_deepreload():
|
def test_deepreload():
|
||||||
"Test that dreload does deep reloads and skips excluded modules."
|
"Test that dreload does deep reloads and skips excluded modules."
|
||||||
|
@ -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.
|
# Distributed under the terms of the Modified BSD License.
|
||||||
#
|
#
|
||||||
@ -14,13 +14,18 @@
|
|||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
from tempfile import NamedTemporaryFile, mkdtemp
|
from tempfile import NamedTemporaryFile, mkdtemp
|
||||||
from os.path import split, join as pjoin, dirname
|
from os.path import split, join as pjoin, dirname
|
||||||
|
import sys
|
||||||
|
try:
|
||||||
|
import pathlib
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
# Third-party imports
|
# Third-party imports
|
||||||
import nose.tools as nt
|
import nose.tools as nt
|
||||||
|
|
||||||
# Our own imports
|
# Our own imports
|
||||||
from yap_ipython.lib import display
|
from IPython.lib import display
|
||||||
from yap_ipython.testing.decorators import skipif_not_numpy
|
from IPython.testing.decorators import skipif_not_numpy
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
# Classes and functions
|
# Classes and functions
|
||||||
@ -33,6 +38,9 @@ from yap_ipython.testing.decorators import skipif_not_numpy
|
|||||||
def test_instantiation_FileLink():
|
def test_instantiation_FileLink():
|
||||||
"""FileLink: Test class can be instantiated"""
|
"""FileLink: Test class can be instantiated"""
|
||||||
fl = display.FileLink('example.txt')
|
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():
|
def test_warning_on_non_existant_path_FileLink():
|
||||||
"""FileLink: Calling _repr_html_ on non-existant files returns a warning
|
"""FileLink: Calling _repr_html_ on non-existant files returns a warning
|
||||||
@ -175,3 +183,7 @@ def test_recursive_FileLinks():
|
|||||||
def test_audio_from_file():
|
def test_audio_from_file():
|
||||||
path = pjoin(dirname(__file__), 'test.wav')
|
path = pjoin(dirname(__file__), 'test.wav')
|
||||||
display.Audio(filename=path)
|
display.Audio(filename=path)
|
||||||
|
|
||||||
|
def test_code_from_file():
|
||||||
|
c = display.Code(filename=__file__)
|
||||||
|
assert c._repr_html_().startswith('<style>')
|
||||||
|
@ -4,8 +4,8 @@ from unittest import mock
|
|||||||
|
|
||||||
import nose.tools as nt
|
import nose.tools as nt
|
||||||
|
|
||||||
from yap_ipython import get_ipython
|
from IPython import get_ipython
|
||||||
from yap_ipython.lib import editorhooks
|
from IPython.lib import editorhooks
|
||||||
|
|
||||||
def test_install_editor():
|
def test_install_editor():
|
||||||
called = []
|
called = []
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
from yap_ipython.testing import decorators as dec
|
from IPython.testing import decorators as dec
|
||||||
|
|
||||||
def test_import_backgroundjobs():
|
def test_import_backgroundjobs():
|
||||||
from yap_ipython.lib import backgroundjobs
|
from IPython.lib import backgroundjobs
|
||||||
|
|
||||||
def test_import_deepreload():
|
def test_import_deepreload():
|
||||||
from yap_ipython.lib import deepreload
|
from IPython.lib import deepreload
|
||||||
|
|
||||||
def test_import_demo():
|
def test_import_demo():
|
||||||
from yap_ipython.lib import demo
|
from IPython.lib import demo
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
"""Tests for yap_ipython.utils.path.py"""
|
"""Tests for IPython.utils.path.py"""
|
||||||
|
|
||||||
# Copyright (c) yap_ipython Development Team.
|
# Copyright (c) IPython Development Team.
|
||||||
# Distributed under the terms of the Modified BSD License.
|
# Distributed under the terms of the Modified BSD License.
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
import nose.tools as nt
|
import nose.tools as nt
|
||||||
|
|
||||||
from yap_ipython.lib import latextools
|
from IPython.lib import latextools
|
||||||
from yap_ipython.testing.decorators import onlyif_cmds_exist, skipif_not_matplotlib
|
from IPython.testing.decorators import onlyif_cmds_exist, skipif_not_matplotlib
|
||||||
from yap_ipython.utils.process import FindCmdError
|
from IPython.utils.process import FindCmdError
|
||||||
|
|
||||||
|
|
||||||
def test_latex_to_png_dvipng_fails_when_no_cmd():
|
def test_latex_to_png_dvipng_fails_when_no_cmd():
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""Test lexers module"""
|
"""Test lexers module"""
|
||||||
|
|
||||||
# Copyright (c) yap_ipython Development Team.
|
# Copyright (c) IPython Development Team.
|
||||||
# Distributed under the terms of the Modified BSD License.
|
# Distributed under the terms of the Modified BSD License.
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
@ -127,3 +127,50 @@ class TestLexers(TestCase):
|
|||||||
(Token.Text, '\n'),
|
(Token.Text, '\n'),
|
||||||
]
|
]
|
||||||
self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))
|
self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))
|
||||||
|
|
||||||
|
fragment = '%%writefile -a foo.py\nif a == b:\n pass'
|
||||||
|
tokens = [
|
||||||
|
(Token.Operator, '%%writefile'),
|
||||||
|
(Token.Text, ' -a foo.py\n'),
|
||||||
|
(Token.Keyword, 'if'),
|
||||||
|
(Token.Text, ' '),
|
||||||
|
(Token.Name, 'a'),
|
||||||
|
(Token.Text, ' '),
|
||||||
|
(Token.Operator, '=='),
|
||||||
|
(Token.Text, ' '),
|
||||||
|
(Token.Name, 'b'),
|
||||||
|
(Token.Punctuation, ':'),
|
||||||
|
(Token.Text, '\n'),
|
||||||
|
(Token.Text, ' '),
|
||||||
|
(Token.Keyword, 'pass'),
|
||||||
|
(Token.Text, '\n'),
|
||||||
|
]
|
||||||
|
self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))
|
||||||
|
|
||||||
|
fragment = '%%timeit\nmath.sin(0)'
|
||||||
|
tokens = [
|
||||||
|
(Token.Operator, '%%timeit\n'),
|
||||||
|
(Token.Name, 'math'),
|
||||||
|
(Token.Operator, '.'),
|
||||||
|
(Token.Name, 'sin'),
|
||||||
|
(Token.Punctuation, '('),
|
||||||
|
(Token.Literal.Number.Integer, '0'),
|
||||||
|
(Token.Punctuation, ')'),
|
||||||
|
(Token.Text, '\n'),
|
||||||
|
]
|
||||||
|
|
||||||
|
fragment = '%%HTML\n<div>foo</div>'
|
||||||
|
tokens = [
|
||||||
|
(Token.Operator, '%%HTML'),
|
||||||
|
(Token.Text, '\n'),
|
||||||
|
(Token.Punctuation, '<'),
|
||||||
|
(Token.Name.Tag, 'div'),
|
||||||
|
(Token.Punctuation, '>'),
|
||||||
|
(Token.Text, 'foo'),
|
||||||
|
(Token.Punctuation, '<'),
|
||||||
|
(Token.Punctuation, '/'),
|
||||||
|
(Token.Name.Tag, 'div'),
|
||||||
|
(Token.Punctuation, '>'),
|
||||||
|
(Token.Text, '\n'),
|
||||||
|
]
|
||||||
|
self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))
|
||||||
|
@ -1,19 +1,20 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
"""Tests for yap_ipython.lib.pretty."""
|
"""Tests for IPython.lib.pretty."""
|
||||||
|
|
||||||
# Copyright (c) yap_ipython Development Team.
|
# Copyright (c) IPython Development Team.
|
||||||
# Distributed under the terms of the Modified BSD License.
|
# Distributed under the terms of the Modified BSD License.
|
||||||
|
|
||||||
|
|
||||||
from collections import Counter, defaultdict, deque, OrderedDict
|
from collections import Counter, defaultdict, deque, OrderedDict
|
||||||
|
import os
|
||||||
import types
|
import types
|
||||||
import string
|
import string
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import nose.tools as nt
|
import nose.tools as nt
|
||||||
|
|
||||||
from yap_ipython.lib import pretty
|
from IPython.lib import pretty
|
||||||
from yap_ipython.testing.decorators import skip_without
|
from IPython.testing.decorators import skip_without
|
||||||
|
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
|
||||||
@ -406,6 +407,15 @@ def test_mappingproxy():
|
|||||||
for obj, expected in cases:
|
for obj, expected in cases:
|
||||||
nt.assert_equal(pretty.pretty(obj), expected)
|
nt.assert_equal(pretty.pretty(obj), expected)
|
||||||
|
|
||||||
|
|
||||||
|
def test_pretty_environ():
|
||||||
|
dict_repr = pretty.pretty(dict(os.environ))
|
||||||
|
# reindent to align with 'environ' prefix
|
||||||
|
dict_indented = dict_repr.replace('\n', '\n' + (' ' * len('environ')))
|
||||||
|
env_repr = pretty.pretty(os.environ)
|
||||||
|
nt.assert_equals(env_repr, 'environ' + dict_indented)
|
||||||
|
|
||||||
|
|
||||||
def test_function_pretty():
|
def test_function_pretty():
|
||||||
"Test pretty print of function"
|
"Test pretty print of function"
|
||||||
# posixpath is a pure python module, its interface is consistent
|
# posixpath is a pure python module, its interface is consistent
|
||||||
@ -420,4 +430,24 @@ def test_function_pretty():
|
|||||||
return "Don't panic"
|
return "Don't panic"
|
||||||
|
|
||||||
nt.assert_in('meaning_of_life(question=None)', pretty.pretty(meaning_of_life))
|
nt.assert_in('meaning_of_life(question=None)', pretty.pretty(meaning_of_life))
|
||||||
|
|
||||||
|
|
||||||
|
class OrderedCounter(Counter, OrderedDict):
|
||||||
|
'Counter that remembers the order elements are first encountered'
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '%s(%r)' % (self.__class__.__name__, OrderedDict(self))
|
||||||
|
|
||||||
|
def __reduce__(self):
|
||||||
|
return self.__class__, (OrderedDict(self),)
|
||||||
|
|
||||||
|
class MySet(set): # Override repr of a basic type
|
||||||
|
def __repr__(self):
|
||||||
|
return 'mine'
|
||||||
|
|
||||||
|
def test_custom_repr():
|
||||||
|
"""A custom repr should override a pretty printer for a parent type"""
|
||||||
|
oc = OrderedCounter("abracadabra")
|
||||||
|
nt.assert_in("OrderedCounter(OrderedDict", pretty.pretty(oc))
|
||||||
|
|
||||||
|
nt.assert_equal(pretty.pretty(MySet()), 'mine')
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
from yap_ipython.lib import passwd
|
from IPython.lib import passwd
|
||||||
from yap_ipython.lib.security import passwd_check, salt_len
|
from IPython.lib.security import passwd_check, salt_len
|
||||||
import nose.tools as nt
|
import nose.tools as nt
|
||||||
|
|
||||||
def test_passwd_structure():
|
def test_passwd_structure():
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
:- module( jupyter,
|
:- module( jupyter,
|
||||||
[jupyter_query/3,
|
[jupyter_query/3,
|
||||||
blank/1,
|
blank/1,
|
||||||
streams/1
|
streams/2
|
||||||
]
|
]
|
||||||
).
|
).
|
||||||
*/
|
*/
|
||||||
@ -91,7 +91,7 @@ blank(Text) :-
|
|||||||
close(user_input),
|
close(user_input),
|
||||||
close(user_output),
|
close(user_output),
|
||||||
close(user_error).
|
close(user_error).
|
||||||
streams(true) :-
|
streams( true) :-
|
||||||
open('/python/input', read, _Input, [alias(user_input),bom(false),script(false)]),
|
open('/python/input', read, _Input, [alias(user_input),bom(false),script(false)]),
|
||||||
open('/python/sys.stdout', append, _Output, [alias(user_output)]),
|
open('/python/sys.stdout', append, _Output, [alias(user_output)]),
|
||||||
open('/python/sys.stderr', append, _Error, [alias(user_error)]).
|
open('/python/sys.stderr', append, _Error, [alias(user_error)]).
|
||||||
|
@ -12,7 +12,7 @@ from traitlets import Instance
|
|||||||
from yap_ipython.core.inputsplitter import *
|
from yap_ipython.core.inputsplitter import *
|
||||||
from yap_ipython.core.inputtransformer import *
|
from yap_ipython.core.inputtransformer import *
|
||||||
from yap_ipython.core.interactiveshell import *
|
from yap_ipython.core.interactiveshell import *
|
||||||
|
from ipython_genutils.py3compat import builtin_mod
|
||||||
from yap_ipython.core import interactiveshell
|
from yap_ipython.core import interactiveshell
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
@ -29,7 +29,7 @@ enter_cell = namedtuple('enter_cell', 'self' )
|
|||||||
exit_cell = namedtuple('exit_cell', 'self' )
|
exit_cell = namedtuple('exit_cell', 'self' )
|
||||||
completions = namedtuple('completions', 'txt self' )
|
completions = namedtuple('completions', 'txt self' )
|
||||||
errors = namedtuple('errors', 'self text' )
|
errors = namedtuple('errors', 'self text' )
|
||||||
streams = namedtuple('streams', ' text' )
|
streams = namedtuple('streams', 'text' )
|
||||||
nostreams = namedtuple('nostreams', ' text' )
|
nostreams = namedtuple('nostreams', ' text' )
|
||||||
|
|
||||||
global engine
|
global engine
|
||||||
@ -727,6 +727,7 @@ class YAPRun:
|
|||||||
self.result.result = False
|
self.result.result = False
|
||||||
has_raised = False
|
has_raised = False
|
||||||
try:
|
try:
|
||||||
|
builtin_mod.input = self.shell.sys_raw_input
|
||||||
self.yapeng.mgoal(streams(True),"user", True)
|
self.yapeng.mgoal(streams(True),"user", True)
|
||||||
if cell.strip('\n \t'):
|
if cell.strip('\n \t'):
|
||||||
#create a Trace object, telling it what to ignore, and whether to
|
#create a Trace object, telling it what to ignore, and whether to
|
||||||
|
@ -166,14 +166,14 @@ class YAPKernel(KernelBase):
|
|||||||
"""
|
"""
|
||||||
self._allow_stdin = allow_stdin
|
self._allow_stdin = allow_stdin
|
||||||
|
|
||||||
if PY3:
|
# if PY3:
|
||||||
self._sys_raw_input = builtin_mod.input
|
# self._sys_raw_input = builtin_mod.input
|
||||||
builtin_mod.input = self.raw_input
|
# builtin_mod.input = self.raw_input
|
||||||
else:
|
# else:
|
||||||
self._sys_raw_input = builtin_mod.raw_input
|
# self._sys_raw_input = builtin_mod.raw_input
|
||||||
self._sys_eval_input = builtin_mod.input
|
# self._sys_eval_input = builtin_mod.input
|
||||||
builtin_mod.raw_input = self.raw_input
|
# builtin_mod.raw_input = self.raw_input
|
||||||
builtin_mod.input = lambda prompt='': eval(self.raw_input(prompt))
|
# builtin_mod.input = lambda prompt='': eval(self.raw_input(prompt))
|
||||||
self._save_getpass = getpass.getpass
|
self._save_getpass = getpass.getpass
|
||||||
getpass.getpass = self.getpass
|
getpass.getpass = self.getpass
|
||||||
|
|
||||||
|
@ -691,7 +691,7 @@ db_files(Fs) :-
|
|||||||
|
|
||||||
'$csult'(Fs, _M) :-
|
'$csult'(Fs, _M) :-
|
||||||
'$skip_list'(_, Fs ,L),
|
'$skip_list'(_, Fs ,L),
|
||||||
L \== [],
|
vz L \== [],
|
||||||
!,
|
!,
|
||||||
user:dot_qualified_goal(Fs).
|
user:dot_qualified_goal(Fs).
|
||||||
'$csult'(Fs, M) :-
|
'$csult'(Fs, M) :-
|
||||||
|
@ -221,7 +221,7 @@ compose_message( loaded(included,AbsFileName,Mod,Time,Space), _Level) --> !,
|
|||||||
[ '~a included in module ~a, ~d msec ~d bytes' -
|
[ '~a included in module ~a, ~d msec ~d bytes' -
|
||||||
[AbsFileName,Mod,Time,Space] ].
|
[AbsFileName,Mod,Time,Space] ].
|
||||||
compose_message( loaded(What,AbsoluteFileName,Mod,Time,Space), _Level) --> !,
|
compose_message( loaded(What,AbsoluteFileName,Mod,Time,Space), _Level) --> !,
|
||||||
[ '~a ~a in module ~a, ~d msec ~g bytes' -
|
[ '~a ~a in module ~a, ~d msec ~d bytes' -
|
||||||
[What, AbsoluteFileName,Mod,Time,Space] ].
|
[What, AbsoluteFileName,Mod,Time,Space] ].
|
||||||
compose_message(signal(SIG,_), _) -->
|
compose_message(signal(SIG,_), _) -->
|
||||||
!,
|
!,
|
||||||
@ -347,8 +347,8 @@ main_error_message(resource_error(Who)) -->
|
|||||||
main_error_message(type_error(Type,Who)) -->
|
main_error_message(type_error(Type,Who)) -->
|
||||||
[ '~*|** ~q should be of type ~a **' - [10,Who,Type]],
|
[ '~*|** ~q should be of type ~a **' - [10,Who,Type]],
|
||||||
[ nl ].
|
[ nl ].
|
||||||
main_error_message(system_error(Who)) -->
|
main_error_message(system_error(Who, In)) -->
|
||||||
[ '~*|** ~q **' - [10,Who]],
|
[ '~*|** ~q ~q **' - [10,Who, In]],
|
||||||
[ nl ].
|
[ nl ].
|
||||||
main_error_message(uninstantiation_error(T)) -->
|
main_error_message(uninstantiation_error(T)) -->
|
||||||
[ '~*|** found ~q, expected unbound variable **' - [10,T], nl ].
|
[ '~*|** found ~q, expected unbound variable **' - [10,T], nl ].
|
||||||
@ -689,11 +689,11 @@ list_of_preds([P|L]) -->
|
|||||||
['~q' - [P]],
|
['~q' - [P]],
|
||||||
list_of_preds(L).
|
list_of_preds(L).
|
||||||
|
|
||||||
syntax_error_term(between(_I,J,_L),S,_LC) -->
|
syntax_error_term(between(_I,J,_L),[S|T],_LC) -->
|
||||||
{string(S)},
|
{string(S)},
|
||||||
!,
|
!,
|
||||||
[ '~s' - [S] ],
|
[ '~s' - [S] ],
|
||||||
[' <<<< at line ~d ' - [J], nl ].
|
[' <<<< at line ~d >>>> ~s' - [J,T], nl ].
|
||||||
syntax_error_term(between(_I,J,_L),LTaL,LC) -->
|
syntax_error_term(between(_I,J,_L),LTaL,LC) -->
|
||||||
syntax_error_tokens(LTaL, J, LC).
|
syntax_error_tokens(LTaL, J, LC).
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user