koatl-kernel 1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- koatl_kernel-1.0/.gitignore +19 -0
- koatl_kernel-1.0/LICENSE +21 -0
- koatl_kernel-1.0/PKG-INFO +40 -0
- koatl_kernel-1.0/README.rst +1 -0
- koatl_kernel-1.0/hatch_build.py +44 -0
- koatl_kernel-1.0/koatl_kernel/__init__.py +3 -0
- koatl_kernel-1.0/koatl_kernel/__main__.py +4 -0
- koatl_kernel-1.0/koatl_kernel/kernel.py +67 -0
- koatl_kernel-1.0/koatl_kernel/shell.py +62 -0
- koatl_kernel-1.0/pyproject.toml +53 -0
koatl_kernel-1.0/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Kevin Zhang
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,40 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: koatl-kernel
|
3
|
+
Version: 1.0
|
4
|
+
Summary: Koatl kernel for Jupyter
|
5
|
+
Project-URL: Homepage, https://github.com/skkestrel/koatl
|
6
|
+
Author-email: Kevin <skkestrel@gmail.com>
|
7
|
+
License: MIT License
|
8
|
+
|
9
|
+
Copyright (c) 2025 Kevin Zhang
|
10
|
+
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
13
|
+
in the Software without restriction, including without limitation the rights
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
16
|
+
furnished to do so, subject to the following conditions:
|
17
|
+
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
19
|
+
copies or substantial portions of the Software.
|
20
|
+
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
27
|
+
SOFTWARE.
|
28
|
+
License-File: LICENSE
|
29
|
+
Classifier: Intended Audience :: Developers
|
30
|
+
Classifier: License :: OSI Approved :: BSD License
|
31
|
+
Classifier: Programming Language :: Python :: 3
|
32
|
+
Requires-Python: >=3.8
|
33
|
+
Requires-Dist: ipykernel
|
34
|
+
Requires-Dist: jupyter-client
|
35
|
+
Requires-Dist: koatl
|
36
|
+
Provides-Extra: test
|
37
|
+
Requires-Dist: jupyter-kernel-test; extra == 'test'
|
38
|
+
Description-Content-Type: text/x-rst
|
39
|
+
|
40
|
+
This is the jupyter kernel for koatl.
|
@@ -0,0 +1 @@
|
|
1
|
+
This is the jupyter kernel for koatl.
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import os
|
2
|
+
import sys
|
3
|
+
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
4
|
+
|
5
|
+
|
6
|
+
import argparse
|
7
|
+
import json
|
8
|
+
import os
|
9
|
+
import sys
|
10
|
+
import shutil
|
11
|
+
|
12
|
+
from jupyter_client.kernelspec import KernelSpecManager
|
13
|
+
from tempfile import TemporaryDirectory
|
14
|
+
|
15
|
+
kernel_json = {
|
16
|
+
"argv": [sys.executable, "-m", "koatl_kernel", "-f", "{connection_file}"],
|
17
|
+
"display_name": "Koatl",
|
18
|
+
"language": "koatl",
|
19
|
+
}
|
20
|
+
|
21
|
+
|
22
|
+
class CustomHook(BuildHookInterface):
|
23
|
+
def initialize(self, version, build_data):
|
24
|
+
here = os.path.abspath(os.path.dirname(__file__))
|
25
|
+
sys.path.insert(0, here)
|
26
|
+
prefix = os.path.join(here, "data_kernelspec")
|
27
|
+
|
28
|
+
with TemporaryDirectory() as td:
|
29
|
+
os.chmod(td, 0o755) # Starts off as 700, not user readable
|
30
|
+
with open(os.path.join(td, "kernel.json"), "w") as f:
|
31
|
+
json.dump(kernel_json, f, sort_keys=True)
|
32
|
+
print("Installing Jupyter kernel spec")
|
33
|
+
|
34
|
+
# Requires logo files in kernel root directory
|
35
|
+
cur_path = os.path.dirname(os.path.realpath(__file__))
|
36
|
+
for logo in ["logo-32x32.png", "logo-64x64.png"]:
|
37
|
+
try:
|
38
|
+
shutil.copy(os.path.join(cur_path, logo), td)
|
39
|
+
except FileNotFoundError:
|
40
|
+
print("Custom logo files not found. Default logos will be used.")
|
41
|
+
|
42
|
+
KernelSpecManager().install_kernel_spec(
|
43
|
+
td, "koatl", user=False, prefix=prefix
|
44
|
+
)
|
@@ -0,0 +1,67 @@
|
|
1
|
+
from ipykernel.ipkernel import IPythonKernel
|
2
|
+
from IPython.core.inputtransformer2 import find_last_indent
|
3
|
+
from koatl.notebook import source_code_transformer, import_prelude
|
4
|
+
from koatl.notebook.magic import koatl_cell_magic
|
5
|
+
from .shell import KoatlShell
|
6
|
+
|
7
|
+
|
8
|
+
class KoatlKernel(IPythonKernel):
|
9
|
+
implementation = "Koatl"
|
10
|
+
implementation_version = "1.0"
|
11
|
+
language = "koatl"
|
12
|
+
language_version = "0.1"
|
13
|
+
language_info = {
|
14
|
+
"name": "koatl",
|
15
|
+
"mimetype": "text/x-koatl",
|
16
|
+
"file_extension": ".tl",
|
17
|
+
}
|
18
|
+
|
19
|
+
shell_class = KoatlShell
|
20
|
+
|
21
|
+
@property
|
22
|
+
def banner(self):
|
23
|
+
return "Koatl Kernel - Interactive Koatl Environment"
|
24
|
+
|
25
|
+
def __init__(self, **kwargs):
|
26
|
+
super().__init__(**kwargs)
|
27
|
+
|
28
|
+
# TODO: these depend on the python tokenizer which don't work
|
29
|
+
|
30
|
+
# itm.token_transformers.insert(0, KoatlMagicAssign)
|
31
|
+
# itm.token_transformers.insert(1, KoatlEscapedCommand)
|
32
|
+
# itm.token_transformers.insert(2, KoatlSystemAssign)
|
33
|
+
|
34
|
+
itm = self.shell.input_transformer_manager
|
35
|
+
|
36
|
+
itm.do_token_transforms = lambda lines: lines
|
37
|
+
itm.line_transforms.insert(0, koatl_cell_magic)
|
38
|
+
itm.check_complete = self._itm_check_complete
|
39
|
+
|
40
|
+
import_prelude(self.shell.user_ns)
|
41
|
+
|
42
|
+
def _itm_check_complete(self, cell):
|
43
|
+
import re
|
44
|
+
|
45
|
+
lines = cell.splitlines(keepends=True)
|
46
|
+
|
47
|
+
if (
|
48
|
+
lines[-1].endswith(":")
|
49
|
+
or lines[-1].endswith("=>")
|
50
|
+
or lines[-1].endswith("[")
|
51
|
+
or lines[-1].endswith("(")
|
52
|
+
):
|
53
|
+
return "incomplete", find_last_indent(lines) + 2
|
54
|
+
|
55
|
+
if lines[-1].startswith(" "):
|
56
|
+
if (
|
57
|
+
len(lines) > 2
|
58
|
+
and re.match(r"^\s*$", lines[-2])
|
59
|
+
and re.match(r"^\s*$", lines[-1])
|
60
|
+
):
|
61
|
+
return "complete", None
|
62
|
+
return "incomplete", find_last_indent(lines)
|
63
|
+
|
64
|
+
return "complete", None
|
65
|
+
|
66
|
+
async def do_execute(self, code, *args, **kwargs):
|
67
|
+
return await super().do_execute(code, *args, **kwargs)
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import koatl
|
2
|
+
import builtins as builtin_mod
|
3
|
+
import sys
|
4
|
+
import warnings
|
5
|
+
from typing import List as ListType, Dict as DictType, Any as AnyType
|
6
|
+
from typing import Optional, Sequence, Tuple
|
7
|
+
from ipykernel.compiler import XCachingCompiler
|
8
|
+
from ipykernel.zmqshell import ZMQInteractiveShell
|
9
|
+
from IPython.core.error import InputRejected
|
10
|
+
from IPython.core.interactiveshell import *
|
11
|
+
from IPython.core.ultratb import FrameInfo
|
12
|
+
|
13
|
+
_source_map_override = {}
|
14
|
+
_orig_frame_info_init = None
|
15
|
+
|
16
|
+
if _orig_frame_info_init is None:
|
17
|
+
_orig_frame_info_init = FrameInfo.__init__
|
18
|
+
|
19
|
+
def _new_init(self, *args, **kwargs):
|
20
|
+
_orig_frame_info_init(self, *args, **kwargs)
|
21
|
+
|
22
|
+
# only override for ipykernel frames
|
23
|
+
if "ipykernel_" in self.filename:
|
24
|
+
old_lineno = self.lineno
|
25
|
+
self.lineno = _source_map_override.get(old_lineno, 0)
|
26
|
+
self._sd.lineno = _source_map_override.get(old_lineno, 0)
|
27
|
+
|
28
|
+
FrameInfo.__init__ = _new_init
|
29
|
+
|
30
|
+
|
31
|
+
class KoatlXCachingCompiler(XCachingCompiler):
|
32
|
+
def cache(self, transformed_code, number=0, raw_code=None):
|
33
|
+
return super().cache(self.shell._koatl_cell, number, raw_code)
|
34
|
+
|
35
|
+
|
36
|
+
class KoatlShell(ZMQInteractiveShell):
|
37
|
+
def __init__(self, *args, **kwargs):
|
38
|
+
kwargs["compiler_class"] = KoatlXCachingCompiler
|
39
|
+
super().__init__(*args, **kwargs)
|
40
|
+
self.compile.shell = self
|
41
|
+
|
42
|
+
def _get_exc_info(self, exc_tuple=None):
|
43
|
+
ret = super()._get_exc_info(exc_tuple)
|
44
|
+
self._exc_info = ret
|
45
|
+
return ret
|
46
|
+
|
47
|
+
def transform_cell(self, raw_cell):
|
48
|
+
cell = super().transform_cell(raw_cell)
|
49
|
+
|
50
|
+
self._koatl_cell = cell
|
51
|
+
(cell, sourcemap) = koatl.transpile(cell, mode="interactive", sourcemap=True)
|
52
|
+
_source_map_override.clear()
|
53
|
+
|
54
|
+
last_seen_line = 0
|
55
|
+
for i in range(len(cell.splitlines()) + 1):
|
56
|
+
if i in sourcemap:
|
57
|
+
_source_map_override[i] = sourcemap[i]
|
58
|
+
last_seen_line = sourcemap[i]
|
59
|
+
else:
|
60
|
+
_source_map_override[i] = last_seen_line
|
61
|
+
|
62
|
+
return cell
|
@@ -0,0 +1,53 @@
|
|
1
|
+
[build-system]
|
2
|
+
requires = [
|
3
|
+
"hatchling>=1.10.0", "ipykernel"
|
4
|
+
]
|
5
|
+
build-backend = "hatchling.build"
|
6
|
+
|
7
|
+
[project]
|
8
|
+
name = "koatl-kernel"
|
9
|
+
dynamic = [
|
10
|
+
"version",
|
11
|
+
]
|
12
|
+
description = "Koatl kernel for Jupyter"
|
13
|
+
readme = "README.rst"
|
14
|
+
license = { file = "LICENSE" }
|
15
|
+
authors = [
|
16
|
+
{ name = "Kevin", email = "skkestrel@gmail.com" },
|
17
|
+
]
|
18
|
+
classifiers = [
|
19
|
+
"Intended Audience :: Developers",
|
20
|
+
"License :: OSI Approved :: BSD License",
|
21
|
+
"Programming Language :: Python :: 3",
|
22
|
+
]
|
23
|
+
requires-python = ">=3.8"
|
24
|
+
dependencies = [
|
25
|
+
"ipykernel",
|
26
|
+
"jupyter_client",
|
27
|
+
"koatl"
|
28
|
+
]
|
29
|
+
|
30
|
+
[project.optional-dependencies]
|
31
|
+
test = [
|
32
|
+
"jupyter_kernel_test",
|
33
|
+
]
|
34
|
+
|
35
|
+
[project.urls]
|
36
|
+
Homepage = "https://github.com/skkestrel/koatl"
|
37
|
+
|
38
|
+
[tool.hatch.version]
|
39
|
+
path = "koatl_kernel/__init__.py"
|
40
|
+
|
41
|
+
# Used to call hatch_build.py
|
42
|
+
[tool.hatch.build.hooks.custom]
|
43
|
+
|
44
|
+
[tool.hatch.build.targets.wheel]
|
45
|
+
packages = ["/koatl_kernel"]
|
46
|
+
|
47
|
+
[tool.hatch.build.targets.sdist]
|
48
|
+
include = [
|
49
|
+
"/koatl_kernel",
|
50
|
+
]
|
51
|
+
|
52
|
+
[tool.hatch.build.targets.wheel.shared-data]
|
53
|
+
"data_kernelspec/share" = "share"
|