This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
/
kernel.py
165 lines (140 loc) · 5 KB
/
kernel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
"""
The Sage ZMQ Kernel
Version of the IPython kernel when running Sage inside the IPython
notebook or remote IPython sessions.
"""
#*****************************************************************************
# Copyright (C) 2015 Volker Braun <vbraun.name@gmail.com>
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
import sys
from ipykernel.ipkernel import IPythonKernel
from ipykernel.zmqshell import ZMQInteractiveShell
from traitlets import Type
from sage.env import SAGE_VERSION, SAGE_EXTCODE, SAGE_DOC
from sage.repl.interpreter import SageNotebookInteractiveShell
from sage.repl.ipython_extension import SageCustomizations
class SageZMQInteractiveShell(SageNotebookInteractiveShell, ZMQInteractiveShell):
pass
class SageKernel(IPythonKernel):
implementation = 'sage'
implementation_version = SAGE_VERSION
shell_class = Type(SageZMQInteractiveShell)
def __init__(self, **kwds):
"""
The Sage IPython Kernel
INPUT:
See the IPython documentation
EXAMPLES::
sage: from sage.repl.ipython_kernel.kernel import SageKernel
sage: SageKernel.__new__(SageKernel)
<sage.repl.ipython_kernel.kernel.SageKernel object at 0x...>
"""
super(SageKernel, self).__init__(**kwds)
SageCustomizations(self.shell)
@property
def banner(self):
r"""
The Sage Banner
The value of this property is displayed in the IPython
notebook.
OUTPUT:
String.
EXAMPLES::
sage: from sage.repl.ipython_kernel.kernel import SageKernel
sage: sk = SageKernel.__new__(SageKernel)
sage: sk.banner
'\xe2\x94\x8c\xe2...SageMath Version...'
"""
from sage.misc.banner import banner_text
return banner_text()
@property
def help_links(self):
r"""
Help in the IPython Notebook
OUTPUT:
See the IPython documentation.
EXAMPLES::
sage: from sage.repl.ipython_kernel.kernel import SageKernel
sage: sk = SageKernel.__new__(SageKernel)
sage: sk.help_links
[{'text': 'Sage Documentation',
'url': '../kernelspecs/sage_.../doc/index.html'},
...]
"""
from sage.repl.ipython_kernel.install import SageKernelSpec
identifier = SageKernelSpec.identifier()
kernel_url = lambda x: '../kernelspecs/{0}/{1}'.format(identifier, x)
return [
{
'text': 'Sage Documentation',
'url': kernel_url('doc/index.html')
},
{
'text': 'Sage Tutorial',
'url': kernel_url('doc/tutorial/index.html'),
},
{
'text': 'Thematic Tutorials',
'url': kernel_url('doc/thematic_tutorials/index.html'),
},
{
'text': 'FAQs',
'url': kernel_url('doc/faq/index.html'),
},
{
'text': 'PREP Tutorials',
'url': kernel_url('doc/prep/index.html'),
},
{
'text': 'Sage Reference',
'url': kernel_url('doc/reference/index.html'),
},
{
'text': "Developer's Guide",
'url': kernel_url('doc/developer/index.html'),
},
{
'text': "Python",
'url': "http://docs.python.org/%i.%i" % sys.version_info[:2],
},
{
'text': "IPython",
'url': "http://ipython.org/documentation.html",
},
{
'text': 'Singular',
'url': 'http://www.singular.uni-kl.de/Manual/latest/index.htm',
},
{
'text': 'GAP',
'url': 'http://gap-system.org/Manuals/doc/ref/chap0.html',
},
{
'text': "NumPy",
'url': "http://docs.scipy.org/doc/numpy/reference/",
},
{
'text': "SciPy",
'url': "http://docs.scipy.org/doc/scipy/reference/",
},
{
'text': "SymPy",
'url': 'http://docs.sympy.org/latest/index.html',
},
{
'text': "Matplotlib",
'url': "http://matplotlib.org/contents.html",
},
{
'text': "Markdown",
'url': "http://help.github.com/articles/github-flavored-markdown",
},
]
def pre_handler_hook(self):
from sage.ext.interrupt.interrupt import init_interrupts
self.saved_sigint_handler = init_interrupts()