Added basic Jupyter Note support
This commit is contained in:
@@ -2,6 +2,7 @@ venv
|
||||
.pytest_cache
|
||||
.idea
|
||||
.vscode
|
||||
.ipynb_checkpoints
|
||||
__pycache__
|
||||
build
|
||||
_build
|
||||
|
||||
@@ -12,6 +12,8 @@ clean:
|
||||
rm -rf docs/source/_build
|
||||
rm -rf prof
|
||||
rm -rf tests/prof
|
||||
rm -rf Untitled*.ipynb
|
||||
find . -name '.pytest_cache' -exec rm -rf {} +
|
||||
find . -name '__pycache__' -exec rm -rf {} +
|
||||
find . -name 'debug.txt' -exec rm -rf {} +
|
||||
find . -name 'debug.txt' -exec rm -rf {} +
|
||||
|
||||
@@ -18,6 +18,7 @@ def main(argv):
|
||||
loggers = set()
|
||||
|
||||
try:
|
||||
print(f"main arguments {argv=}")
|
||||
opts, args = getopt.getopt(argv, "hdl:i", ["help", "debug", "logger=", "interactive"])
|
||||
|
||||
for o, a in opts:
|
||||
|
||||
@@ -18,3 +18,6 @@ pytest-profiling==1.7.0
|
||||
pytz==2019.3
|
||||
six==1.13.0
|
||||
wcwidth==0.1.7
|
||||
|
||||
ipykernel~=5.3.4
|
||||
setuptools~=41.6.0
|
||||
@@ -115,6 +115,7 @@ class Sheerka(Concept):
|
||||
|
||||
self.last_executions = []
|
||||
self.last_return_values = []
|
||||
self.execution_count = 0
|
||||
|
||||
@property
|
||||
def resolved_concepts_by_first_keyword(self):
|
||||
@@ -436,6 +437,7 @@ class Sheerka(Concept):
|
||||
# with open(CONCEPTS_FILE, "a") as f:
|
||||
# f.write(text + "\n")
|
||||
|
||||
self.execution_count += 1
|
||||
self._last_execution = execution_context
|
||||
if len(self.last_executions) == self.MAX_EXECUTION_HISTORY:
|
||||
del self.last_executions[0]
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
from core.sheerka.Sheerka import Sheerka
|
||||
from ipykernel.ipkernel import IPythonKernel
|
||||
from ipykernel.kernelapp import IPKernelApp
|
||||
from sheerkapickle import encode
|
||||
|
||||
|
||||
class SheerkaKernel(IPythonKernel):
|
||||
implementation = 'Sheerka'
|
||||
implementation_version = '0.1'
|
||||
language = 'sheerka'
|
||||
language_version = '0.1'
|
||||
language_info = {
|
||||
'name': 'Any text',
|
||||
'mimetype': 'text/plain',
|
||||
'file_extension': '.txt',
|
||||
}
|
||||
banner = "Sheerka kernel"
|
||||
|
||||
sheerka = Sheerka()
|
||||
sheerka.initialize()
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
print(f"SheerkaKernel args: {kwargs}")
|
||||
super().__init__(**kwargs)
|
||||
|
||||
def do_execute(self, code, silent, store_history=True, user_expressions=None, allow_stdin=False):
|
||||
result = self.sheerka.evaluate_user_input(code)
|
||||
|
||||
if not silent:
|
||||
display_data_content = {
|
||||
'data': {
|
||||
'text/plain': str(result),
|
||||
'application/json': encode(self.sheerka, result)
|
||||
},
|
||||
'metadata': {
|
||||
'application/json': {'expanded': True}
|
||||
},
|
||||
'execution_count': self.sheerka.execution_count,
|
||||
|
||||
}
|
||||
stream_content = {'name': 'stdout', 'text': display_data_content}
|
||||
# self.send_response(self.iopub_socket, "stream", stream_content)
|
||||
self.send_response(self.iopub_socket, "execute_result", display_data_content)
|
||||
|
||||
return {'status': 'ok',
|
||||
# The base class increments the execution count
|
||||
'execution_count': self.sheerka.execution_count,
|
||||
'payload': [],
|
||||
'user_expressions': {}}
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
IPKernelApp.launch_instance(kernel_class=SheerkaKernel)
|
||||
@@ -0,0 +1,18 @@
|
||||
To make Jupyter notebook recognize Sheerka,
|
||||
the file kernel.json must be copied where the kernels are declared
|
||||
|
||||
* First, open the kernel.json file and make sure that the path to SheerkaKernel is correct.
|
||||
* The copy it to the correct location
|
||||
* You can use the command 'jupyter kernelspec install </path/to/kernel>'
|
||||
* or simply copy it using cp ;-)
|
||||
|
||||
Valid locations for kernel.json are
|
||||
|
||||
| | Unix | Windows |
|
||||
|----|------| ---------------|
|
||||
|System | /usr/share/jupyter/kernels<br> /usr/local/share/jupyter/kernels | %PROGRAMDATA%\jupyter\kernels |
|
||||
|Env |{sys.prefix}/share/jupyter/kernels | |
|
||||
| User | ~/.local/share/jupyter/kernels (Linux)<br> ~/Library/Jupyter/kernels (Mac) | %APPDATA%\jupyter\kernels |
|
||||
|
||||
|
||||
from https://jupyter-client.readthedocs.io/en/latest/kernels.html#kernel-specs
|
||||
@@ -0,0 +1,3 @@
|
||||
{"argv":["python", "/home/kodjo/Dev/Sheerka/src/jupyter/SheerkaKernel.py", "-f", "{connection_file}"],
|
||||
"display_name":"Sheerka"
|
||||
}
|
||||
@@ -16,7 +16,7 @@ class UnexpectedEndOfFileError(ErrorNode):
|
||||
|
||||
class BnfParser(BaseParser):
|
||||
"""
|
||||
Parser used to transform litteral into ParsingExpression
|
||||
Parser used to transform literal into ParsingExpression
|
||||
example :
|
||||
a | b, c -> Sequence(OrderedChoice(a, b) ,c)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user