Giter Club home page Giter Club logo

ilua's Introduction

ILua

ILua is a feature-packed, portable console and Jupyter kernel for the Lua language.

Features

  • Lua-implementation agnostic
  • Code completions
  • Code inspection
    • Retrieve function documentation
    • Can even retrieve the function source if available (invoked with ??)
  • Pretty-printed results
  • Access last result with _
  • Cross-session execution history
  • Works on Linux and Windows
  • No native dependencies for Lua
  • Python's pip based installation

Installation

pip install ilua

# From source
git clone https://github.com/guysv/ilua.git --recurse-submodules
cd ilua
pip install -e . --user
python setup.py install_data -d ~/.local # pip install -e . forgets data_files...

A Bit on ILua's Architecture

As opposed to existing Lua Jupyter kernels which implement the Jupyter protocol in Lua (and depend on lzmq which is a native module), ILua implements the communication with Jupyter in Python, which in turn talks with Lua via named-pipe IPC. This frees ILua from being bounded to a single Lua implementation ABI. The Lua interpreter only needs to respect the $LUA_PATH environment variable and execute a file given as the first argument.

ilua's People

Contributors

dennis-barrett avatar guysv avatar hroncok avatar kolanich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ilua's Issues

Docstring crashing shell

When an illegal character is present in a function's docstring (e.g string.find()) the shell crashes altogether:

In [3]: string.find?
Signature: string.find(s, pattern [, init [, plain]])
Documentation:Traceback (most recent call last):
  File "c:\python27\lib\runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "c:\python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Python27\Scripts\ilua.exe\__main__.py", line 9, in <module>
  File "c:\python27\lib\site-packages\ilua\consoleapp.py", line 37, in main
    ILuaConsoleApp().run()
  File "c:\python27\lib\site-packages\ilua\consoleapp.py", line 34, in run
    ZMQTerminalIPythonApp.launch_instance(argv=['--kernel', 'lua'])
  File "C:\Users\Yoav\AppData\Roaming\Python\Python27\site-packages\jupyter_core\application.py", line 266, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "c:\python27\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance
    app.start()
  File "C:\Users\Yoav\AppData\Roaming\Python\Python27\site-packages\jupyter_console\app.py", line 155, in start
    self.shell.mainloop()
  File "C:\Users\Yoav\AppData\Roaming\Python\Python27\site-packages\jupyter_console\ptshell.py", line 508, in mainloop
    self.interact()
  File "C:\Users\Yoav\AppData\Roaming\Python\Python27\site-packages\jupyter_console\ptshell.py", line 500, in interact
    self.run_cell(code, store_history=True)
  File "C:\Users\Yoav\AppData\Roaming\Python\Python27\site-packages\jupyter_console\ptshell.py", line 564, in run_cell
    self.handle_execute_reply(msg_id, timeout=0.05)
  File "C:\Users\Yoav\AppData\Roaming\Python\Python27\site-packages\jupyter_console\ptshell.py", line 592, in handle_execute_reply
    page.page(item['data']['text/plain'])
  File "c:\python27\lib\site-packages\IPython\core\page.py", line 274, in page
    return pager_page(data, start, screen_lines, pager_cmd)
  File "c:\python27\lib\site-packages\IPython\core\page.py", line 201, in pager_page
    print(str_toprint)
  File "c:\python27\lib\site-packages\colorama\ansitowin32.py", line 40, in write
    self.__convertor.write(text)
  File "c:\python27\lib\site-packages\colorama\ansitowin32.py", line 141, in write
    self.write_and_convert(text)
  File "c:\python27\lib\site-packages\colorama\ansitowin32.py", line 166, in write_and_convert
    self.write_plain_text(text, cursor, start)
  File "c:\python27\lib\site-packages\colorama\ansitowin32.py", line 174, in write_plain_text
    self.wrapped.write(text[start:end])
  File "c:\python27\lib\encodings\cp437.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\xa7' in position 46: character maps to <undefined>

printing

Can I print html or md code (i.e. something like display() or HTML() of iPython) ? I cannot find any hint from the source code. Likewise, is it possible to print html5 charts (e.g. C3.js) or use jQuery ?

Thank you in advance.

builtins.AttributeError: 'ILuaKernel' object has no attribute 'proto'

`In [1]: print'sasd'
2023-12-11T16:11:05+0800 [ilua.kernel.ILuaKernel#critical] Uncought exception in message handler
Traceback (most recent call last):
File "/home/husheng/local/lib/python3.11/site-packages/twisted/internet/defer.py", line 2000, in _inlineCallbacks
result = context.run(gen.send, result)
File "/home/husheng/local/lib/python3.11/site-packages/ilua/kernelbase.py", line 193, in handle_message
content = yield self.do_execute(**msg['content'])
File "/home/husheng/local/lib/python3.11/site-packages/twisted/internet/defer.py", line 2256, in unwindGenerator
return _cancellableInlineCallbacks(gen)
File "/home/husheng/local/lib/python3.11/site-packages/twisted/internet/defer.py", line 2168, in _cancellableInlineCallbacks
_inlineCallbacks(None, gen, status, _copy_context())
--- ---
File "/home/husheng/local/lib/python3.11/site-packages/ilua/kernelbase.py", line 193, in handle_message
content = yield self.do_execute(**msg['content'])
File "/home/husheng/local/lib/python3.11/site-packages/twisted/internet/defer.py", line 2000, in _inlineCallbacks
result = context.run(gen.send, result)
File "/home/husheng/local/lib/python3.11/site-packages/ilua/kernel.py", line 126, in do_execute
result = yield self.proto.sendRequest({"type": "execute",
builtins.AttributeError: 'ILuaKernel' object has no attribute 'proto'

^Z
[4]+ 已停止 ilua`

`(base) [husheng@node26 convert]$ pip show ilua

Name: ilua
Version: 0.2.1
Summary: Portable Lua kernel for Jupyter
Home-page: https://github.com/guysv/ilua
Author: Guy Sviry
Author-email: [email protected]
License: GPLv2
Location: /home/husheng/local/lib/python3.11/site-packages
Requires: jupyter-console, jupyter-core, pygments, termcolor, twisted, txzmq
Required-by: `
I use Python 3.11.6 in a linux platform, This error will show up no matter what command I type.

Operation not permitted when piping in stdin

I wanted to write a simple smoke test, but this is where I ended up:

$ ilua << EOF
print"test"
EOF
Warning: Input is not to a terminal (fd=0).
Jupyter console 6.1.0

ILua 0.2.1
Traceback (most recent call last):
  File "/usr/bin/ilua", line 8, in <module>
    sys.exit(main())
  File "/usr/lib/python3.8/site-packages/ilua/consoleapp.py", line 37, in main
    ILuaConsoleApp().run()
  File "/usr/lib/python3.8/site-packages/ilua/consoleapp.py", line 34, in run
    ZMQTerminalIPythonApp.launch_instance(argv=['--kernel', 'lua'])
  File "/usr/lib/python3.8/site-packages/jupyter_core/application.py", line 268, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/usr/lib/python3.8/site-packages/traitlets/config/application.py", line 664, in launch_instance
    app.start()
  File "/usr/lib/python3.8/site-packages/jupyter_console/app.py", line 156, in start
    self.shell.mainloop()
  File "/usr/lib/python3.8/site-packages/jupyter_console/ptshell.py", line 547, in mainloop
    self.interact()
  File "/usr/lib/python3.8/site-packages/jupyter_console/ptshell.py", line 531, in interact
    code = self.prompt_for_code()
  File "/usr/lib/python3.8/site-packages/jupyter_console/ptshell.py", line 474, in prompt_for_code
    text = self.pt_cli.prompt(
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/shortcuts/prompt.py", line 797, in prompt
    return run_sync()
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/shortcuts/prompt.py", line 786, in run_sync
    return self.app.run(inputhook=self.inputhook, pre_run=pre_run2)
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 736, in run
    return run()
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 710, in run
    return f.result()
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/eventloop/future.py", line 151, in result
    raise self._exception
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/eventloop/coroutine.py", line 92, in step_next
    new_f = coroutine.throw(exc)
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 685, in _run_async2
    result = yield f
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/eventloop/coroutine.py", line 88, in step_next
    new_f = coroutine.send(None)
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 625, in _run_async
    with self.input.attach(read_from_input):
  File "/usr/lib64/python3.8/contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/input/vt100.py", line 150, in _attached_input
    loop.add_reader(fd, callback)
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/eventloop/posix.py", line 273, in add_reader
    self.selector.register(fd)
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/eventloop/select.py", line 78, in register
    sel.register(fd)
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/eventloop/select.py", line 133, in register
    self._sel.register(fd, selectors.EVENT_READ, None)
  File "/usr/lib64/python3.8/selectors.py", line 359, in register
    self._selector.register(key.fd, poller_events)
PermissionError: [Errno 1] Operation not permitted

What exactly is required from the custom lua interpreter?

Hey. I try to use ilua with a custom lua interpreted (used in RPM).

It seems the interpreter doesn't support being called with a file name as an argument. Before I approach RPM to request the functions ilua needs, I'd like to know the set of requirements. I figured it's easier to ask than to reverse engineer it.

So far I think it is:

  • accept filename as a command line argument
  • respect the LUA_PATH environment variable

Is there anythign else? Howe can I see what's happening to debug this?

RFE: A way to pass additional help_links from kernel.json

I'd like to create a kernel.json for RPM Lua. So far so good:

{
	"argv":
	[
		"python",
		"-m",
		"ilua.app",
		"-c",
		"{connection_file}",
		"-i",
		"rpmlua"
	],
	"display_name": "RPM Lua",
	"language": "lua",
	"interrupt_mode": "message",
}

Next, I wanted to include a link to https://rpm.org/user_doc/lua.html in help_links. However, AFAIK this is not possible from the json kernel configuration.

I've seen:

ilua/ilua/kernel.py

Lines 55 to 58 in 9f621dc

help_links = [
{"text": "Lua Reference",
"url": "https://www.lua.org/manual/5.3/"}
]

I wonder whether it would make sense to extend the list based on environment variables? E.g. I'd do something like this:

{
    ...
    "env": {
        "ILUA_HELP_LINKS": "Lua in RPM: https://rpm.org/user_doc/lua.html"
    }
}

And the code would add the links to the list. The devil is in the details, such as defining correct separators etc. However, before I do a Pull Request, would something like this be accepted?

Installing to Jupyter's kernelspec?

Hi! Apologies in advance if this is a terrible question — I'm a little unsure how to install ILua to Jupyter such that it's listed when you run jupyter kernelspec list. IRuby, for example, has a command iruby register that you run to install the kernel to ~/Library/Jupyter/kernels/* (I'm on a Mac). IJavascript has ijsregister. Is there a similar sort of thing for ILua, or any way to accomplish the same?

I tried running jupyter kernelspec install ~/.local/pipx/venvs/ilua/share/jupyter/kernels/lua --user (I installed ILua with pipx, which is why the path is like that), but it failed and said there was 'no module ilua' or something along those lines.

I'm just curious because I use Hydrogen for Atom, which ties into jupyter notebook.

No worries at all if this isn't supported/can't be fixed/etc, just thought I'd ask — and many thanks for making this in the first place :)

Edit — I accidentally hit 'submit new issue' while I was in the middle of writing it; sorry about that!

No such kernel named lua

I'm hoping someone can help me with this. Installed using pip3 install ilua successfully. Lua 5.2.4 has also been installed, following https://www.lua.org/download.html
When running ilua from the console, I get the error message "No such kernel named lua"

I've exhaustively searched google for a resolution, without success.
I'd be very appreciative of any assistance on this Issue.
Please let me know if there is any additional information I can provide (and how to aquire it) to help better diagnose the problem.

~ % ilua
Traceback (most recent call last):
  File "/Users/zccafa3/Library/Python/3.7/bin/ilua", line 8, in <module>
    sys.exit(main())
  File "/Users/zccafa3/Library/Python/3.7/lib/python/site-packages/ilua/consoleapp.py", line 37, in main
    ILuaConsoleApp().run()
  File "/Users/zccafa3/Library/Python/3.7/lib/python/site-packages/ilua/consoleapp.py", line 34, in run
    ZMQTerminalIPythonApp.launch_instance(argv=['--kernel', 'lua'])
  File "/Users/zccafa3/Library/Python/3.7/lib/python/site-packages/jupyter_core/application.py", line 270, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/Users/zccafa3/Library/Python/3.7/lib/python/site-packages/traitlets/config/application.py", line 663, in launch_instance
    app.initialize(argv)
  File "<decorator-gen-117>", line 2, in initialize
  File "/Users/zccafa3/Library/Python/3.7/lib/python/site-packages/traitlets/config/application.py", line 87, in catch_config_error
    return method(app, *args, **kwargs)
  File "/Users/zccafa3/Library/Python/3.7/lib/python/site-packages/jupyter_console/app.py", line 142, in initialize
    self.init_shell()
  File "/Users/zccafa3/Library/Python/3.7/lib/python/site-packages/jupyter_console/app.py", line 109, in init_shell
    JupyterConsoleApp.initialize(self)
  File "/Users/zccafa3/Library/Python/3.7/lib/python/site-packages/jupyter_client/consoleapp.py", line 341, in initialize
    self.init_kernel_manager()
  File "/Users/zccafa3/Library/Python/3.7/lib/python/site-packages/jupyter_client/consoleapp.py", line 293, in init_kernel_manager
    self.kernel_manager.start_kernel(**kwargs)
  File "/Users/zccafa3/Library/Python/3.7/lib/python/site-packages/jupyter_client/manager.py", line 304, in start_kernel
    kernel_cmd, kw = self.pre_start_kernel(**kw)
  File "/Users/zccafa3/Library/Python/3.7/lib/python/site-packages/jupyter_client/manager.py", line 257, in pre_start_kernel
    kernel_cmd = self.format_kernel_cmd(extra_arguments=extra_arguments)
  File "/Users/zccafa3/Library/Python/3.7/lib/python/site-packages/jupyter_client/manager.py", line 181, in format_kernel_cmd
    cmd = self.kernel_spec.argv + extra_arguments
  File "/Users/zccafa3/Library/Python/3.7/lib/python/site-packages/jupyter_client/manager.py", line 87, in kernel_spec
    self._kernel_spec = self.kernel_spec_manager.get_kernel_spec(self.kernel_name)
  File "/Users/zccafa3/Library/Python/3.7/lib/python/site-packages/jupyter_client/kernelspec.py", line 235, in get_kernel_spec
    raise NoSuchKernel(kernel_name)
jupyter_client.kernelspec.NoSuchKernel: No such kernel named lua

ilua in fedora 34 no docstrings, only ?

running
python3-jupyter-console-6.4.0-1.fc34.noarch
lua-5.4.3-1.fc34.x86_64
ilua-0.2.1-6.fc34.noarch

there are no docstrings with either ilua in jupyter-{console,qtconcole}, all I see is a question mark

ipython gives docstrings.

Most of the demo traces I see here are on Windows, do I need some depends from luarocks?

shout out to Churchyard for pointing me to ilua, it has opened new doors for me, docstrings or not.

how to quit/close/exit ilua?

I've looked for docs but can't find any mention of how to exit ilua and return to my shell...

❯ ilua
Jupyter console 6.4.3

ILua 0.2.1
In [1]: v = 2

In [2]: c = 5

In [3]: print(v + c)
7

In [4]: -- ok, it works after fixing https://github.com/guysv/ilua/issues/20

In [5]: exit
Out[5]: nil

In [6]: quit
Out[6]: nil

In [7]: close
Out[7]: nil

In [8]: exit()
(ilua):1: attempt to call global 'exit' (a nil value)
stack traceback:
        (ilua):1: in main chunk
        [C]: in function 'xpcall'
        ...c/.local/lib/python3.8/site-packages/ilua/interp.lua:65: in function 'handle_execute'
        ...c/.local/lib/python3.8/site-packages/ilua/interp.lua:162: in main chunk
        [C]: ?

In [9]: quit()
(ilua):1: attempt to call global 'quit' (a nil value)
stack traceback:
        (ilua):1: in main chunk
        [C]: in function 'xpcall'
        ...c/.local/lib/python3.8/site-packages/ilua/interp.lua:65: in function 'handle_execute'
        ...c/.local/lib/python3.8/site-packages/ilua/interp.lua:162: in main chunk
        [C]: ?

In [10]: close()
(ilua):1: attempt to call global 'close' (a nil value)
stack traceback:
        (ilua):1: in main chunk
        [C]: in function 'xpcall'
        ...c/.local/lib/python3.8/site-packages/ilua/interp.lua:65: in function 'handle_execute'
        ...c/.local/lib/python3.8/site-packages/ilua/interp.lua:162: in main chunk
        [C]: ?

In [11]: -- but how do I quit? Am I in Vim?

In [12]: :q
(ilua):1: unexpected symbol near ':'

In [13]: :q!
(ilua):1: unexpected symbol near ':'

The included "inspect" module poorly respects __tostring metamethods

When "inspecting" a table with a __tostring metamethod, e.g. by evaluating a Jupyter cell, I would expect it to "respect" the representation established by the meta method. What it does instead is mixing the tostring-value with a dump of the entire table. This can look very ugly especially for large objects. Just to clarify using the Lua 5.2 interpreter:

$ lua5.2
Lua 5.2.4  Copyright (C) 1994-2015 Lua.org, PUC-Rio
> inspect = require "ext.inspect"
> t = setmetatable({1, 2, 3}, {__tostring = function(t) return "FOO" end})
> = inspect.inspect(t)
{ -- FOO
   1, 2, 3,
  <metatable> = {
    __tostring = <function 1>
  }
}

The output is the same in ILua. Using the latest version of inspect.lua v3.1.3 is even worse since it entirely omits the tostring-representation after --. Also since they use Teal in recent versions, it might even be tricky to bundle a readable preprocessed version of inspect.lua v3.1.3 with ILua.

For the time being, I have patched my inspect.lua. Perhaps we should always check whether the inspected value contains a __tostring metamethod and only if not pass it to the inspect-library at all. But @guysv might have differing strong opinions about that.

I could prepare a merge request.

Install error on macOS

I know macOS is not officially supported but I tried and this error was a bit confusing for me

❯ pip install ilua                   
Collecting ilua
  Downloading ilua-0.2.1-py2.py3-none-any.whl (70 kB)
     |████████████████████████████████| 70 kB 3.7 MB/s 
Collecting jupyter-core
  Downloading jupyter_core-4.7.1-py3-none-any.whl (82 kB)
     |████████████████████████████████| 82 kB 3.1 MB/s 
Collecting txzmq
  Downloading txZMQ-0.8.2.tar.gz (19 kB)
Collecting jupyter-console
  Downloading jupyter_console-6.2.0-py3-none-any.whl (22 kB)
Requirement already satisfied: pygments in ./.pyenv/versions/3.8.5/lib/python3.8/site-packages (from ilua) (2.7.1)
Collecting ilua
  Downloading ilua-0.2.0-py2.py3-none-any.whl (70 kB)
     |████████████████████████████████| 70 kB 5.2 MB/s 
  Downloading ilua-0.1.0-py2.py3-none-any.whl (48 kB)
     |████████████████████████████████| 48 kB 7.1 MB/s 
ERROR: Cannot install ilua==0.1.0, ilua==0.2.0 and ilua==0.2.1 because these package versions have conflicting dependencies.

The conflict is caused by:
    ilua 0.2.1 depends on twisted
    ilua 0.2.0 depends on twisted
    ilua 0.1.0 depends on twisted

To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict

ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/user_guide/#fixing-conflicting-dependencies

Any ideas what could cause this?

Tab-completion crashes

Tab-completions crash ILua on Ubuntu 20.04. It makes no difference whether I install it via Pip or from sources. To minimize possible interactions with installed Pip-packages (or even apt-installed packages), I tried to install ILua into its own virtual environment.

rhaberkorn@thinkpad-x270:~/working-copies/ilua$ python3 -m venv env
rhaberkorn@thinkpad-x270:~/working-copies/ilua$ . env/bin/activate
(env) rhaberkorn@thinkpad-x270:~/working-copies/ilua$ python3 -m pip install -e . 
Obtaining file:///home/rhaberkorn/working-copies/ilua
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Collecting twisted
  Using cached twisted-23.8.0-py3-none-any.whl (3.1 MB)
Collecting pygments
  Using cached Pygments-2.16.1-py3-none-any.whl (1.2 MB)
Collecting termcolor
  Using cached termcolor-2.3.0-py3-none-any.whl (6.9 kB)
Collecting txzmq
  Using cached txZMQ-1.0.0-py3-none-any.whl (24 kB)
Collecting jupyter-console
  Using cached jupyter_console-6.6.3-py3-none-any.whl (24 kB)
Collecting jupyter-core
  Using cached jupyter_core-5.4.0-py3-none-any.whl (28 kB)
Collecting attrs>=21.3.0
  Using cached attrs-23.1.0-py3-none-any.whl (61 kB)
Collecting automat>=0.8.0
  Using cached Automat-22.10.0-py2.py3-none-any.whl (26 kB)
Collecting typing-extensions>=3.10.0
  Using cached typing_extensions-4.8.0-py3-none-any.whl (31 kB)
Collecting zope-interface>=5
  Using cached zope.interface-6.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (249 kB)
Collecting incremental>=22.10.0
  Using cached incremental-22.10.0-py2.py3-none-any.whl (16 kB)
Collecting constantly>=15.1
  Using cached constantly-15.1.0-py2.py3-none-any.whl (7.9 kB)
Collecting hyperlink>=17.1.1
  Using cached hyperlink-21.0.0-py2.py3-none-any.whl (74 kB)
Collecting pyzmq>=13
  Using cached pyzmq-25.1.1-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.1 MB)
Collecting prompt-toolkit>=3.0.30
  Using cached prompt_toolkit-3.0.39-py3-none-any.whl (385 kB)
Collecting jupyter-client>=7.0.0
  Using cached jupyter_client-8.4.0-py3-none-any.whl (103 kB)
Collecting traitlets>=5.4
  Using cached traitlets-5.11.2-py3-none-any.whl (83 kB)
Collecting ipykernel>=6.14
  Using cached ipykernel-6.25.2-py3-none-any.whl (154 kB)
Collecting ipython
  Using cached ipython-8.12.3-py3-none-any.whl (798 kB)
Collecting platformdirs>=2.5
  Using cached platformdirs-3.11.0-py3-none-any.whl (17 kB)
Collecting six
  Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Requirement already satisfied: setuptools in ./env/lib/python3.8/site-packages (from zope-interface>=5->twisted->ilua==0.2.2.dev18+g05eb181) (44.0.0)
Collecting idna>=2.5
  Using cached idna-3.4-py3-none-any.whl (61 kB)
Collecting wcwidth
  Using cached wcwidth-0.2.8-py2.py3-none-any.whl (31 kB)
Collecting python-dateutil>=2.8.2
  Using cached python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
Collecting tornado>=6.2
  Using cached tornado-6.3.3-cp38-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (427 kB)
Collecting importlib-metadata>=4.8.3; python_version < "3.10"
  Using cached importlib_metadata-6.8.0-py3-none-any.whl (22 kB)
Collecting debugpy>=1.6.5
  Using cached debugpy-1.8.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.5 MB)
Collecting nest-asyncio
  Using cached nest_asyncio-1.5.8-py3-none-any.whl (5.3 kB)
Collecting matplotlib-inline>=0.1
  Using cached matplotlib_inline-0.1.6-py3-none-any.whl (9.4 kB)
Collecting psutil
  Using cached psutil-5.9.6-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (283 kB)
Collecting comm>=0.1.1
  Using cached comm-0.1.4-py3-none-any.whl (6.6 kB)
Collecting packaging
  Using cached packaging-23.2-py3-none-any.whl (53 kB)
Collecting pexpect>4.3; sys_platform != "win32"
  Using cached pexpect-4.8.0-py2.py3-none-any.whl (59 kB)
Collecting stack-data
  Using cached stack_data-0.6.3-py3-none-any.whl (24 kB)
Collecting jedi>=0.16
  Using cached jedi-0.19.1-py2.py3-none-any.whl (1.6 MB)
Collecting pickleshare
  Using cached pickleshare-0.7.5-py2.py3-none-any.whl (6.9 kB)
Collecting decorator
  Using cached decorator-5.1.1-py3-none-any.whl (9.1 kB)
Collecting backcall
  Using cached backcall-0.2.0-py2.py3-none-any.whl (11 kB)
Collecting zipp>=0.5
  Using cached zipp-3.17.0-py3-none-any.whl (7.4 kB)
Collecting ptyprocess>=0.5
  Using cached ptyprocess-0.7.0-py2.py3-none-any.whl (13 kB)
Collecting asttokens>=2.1.0
  Using cached asttokens-2.4.0-py2.py3-none-any.whl (27 kB)
Collecting pure-eval
  Using cached pure_eval-0.2.2-py3-none-any.whl (11 kB)
Collecting executing>=1.2.0
  Using cached executing-2.0.0-py2.py3-none-any.whl (24 kB)
Collecting parso<0.9.0,>=0.8.3
  Using cached parso-0.8.3-py2.py3-none-any.whl (100 kB)
Installing collected packages: attrs, six, automat, typing-extensions, zope-interface, incremental, constantly, idna, hyperlink, twisted, pygments, termcolor, pyzmq, txzmq, wcwidth, prompt-toolkit, python-dateutil, traitlets, tornado, platformdirs, jupyter-core, zipp, importlib-metadata, jupyter-client, debugpy, nest-asyncio, matplotlib-inline, ptyprocess, pexpect, asttokens, pure-eval, executing, stack-data, parso, jedi, pickleshare, decorator, backcall, ipython, psutil, comm, packaging, ipykernel, jupyter-console, ilua
  Running setup.py develop for ilua
Successfully installed asttokens-2.4.0 attrs-23.1.0 automat-22.10.0 backcall-0.2.0 comm-0.1.4 constantly-15.1.0 debugpy-1.8.0 decorator-5.1.1 executing-2.0.0 hyperlink-21.0.0 idna-3.4 ilua importlib-metadata-6.8.0 incremental-22.10.0 ipykernel-6.25.2 ipython-8.12.3 jedi-0.19.1 jupyter-client-8.4.0 jupyter-console-6.6.3 jupyter-core-5.4.0 matplotlib-inline-0.1.6 nest-asyncio-1.5.8 packaging-23.2 parso-0.8.3 pexpect-4.8.0 pickleshare-0.7.5 platformdirs-3.11.0 prompt-toolkit-3.0.39 psutil-5.9.6 ptyprocess-0.7.0 pure-eval-0.2.2 pygments-2.16.1 python-dateutil-2.8.2 pyzmq-25.1.1 six-1.16.0 stack-data-0.6.3 termcolor-2.3.0 tornado-6.3.3 traitlets-5.11.2 twisted-23.8.0 txzmq-1.0.0 typing-extensions-4.8.0 wcwidth-0.2.8 zipp-3.17.0 zope-interface
(env) rhaberkorn@thinkpad-x270:~/working-copies/ilua$ python3 setup.py install_data
WARNING: The wheel package is not available.
WARNING: The wheel package is not available.
WARNING: The wheel package is not available.
/home/rhaberkorn/working-copies/ilua/.eggs/setuptools_scm-8.0.4-py3.8.egg/setuptools_scm/_integration/setuptools.py:30: RuntimeWarning: 
ERROR: setuptools==44.0.0 is used in combination with setuptools_scm>=8.x

Your build configuration is incomplete and previously worked by accident!
setuptools_scm requires setuptools>=61

Suggested workaround if applicable:
 - migrating from the deprecated setup_requires mechanism to pep517/518
   and using a pyproject.toml to declare build dependencies
   which are reliably pre-installed before running the build tools

  warnings.warn(
running install_data
creating /home/rhaberkorn/working-copies/ilua/env/share/jupyter/kernels/lua
copying defaultspec/logo-64x64.png -> /home/rhaberkorn/working-copies/ilua/env/share/jupyter/kernels/lua
copying defaultspec/logo-license.txt -> /home/rhaberkorn/working-copies/ilua/env/share/jupyter/kernels/lua
copying defaultspec/logo-32x32.png -> /home/rhaberkorn/working-copies/ilua/env/share/jupyter/kernels/lua
copying defaultspec/kernel.json -> /home/rhaberkorn/working-copies/ilua/env/share/jupyter/kernels/lua
(env) rhaberkorn@thinkpad-x270:~/working-copies/ilua$ ilua
Jupyter console 6.6.3

ILua 0.2.2.dev18+g05eb181
In [1]: print2023-10-22T01:27:26+0300 [ilua.kernel.ILuaKernel#critical] Uncought exception in message handler
	Traceback (most recent call last):
	  File "/home/rhaberkorn/working-copies/ilua/env/lib/python3.8/site-packages/twisted/internet/defer.py", line 1997, in _inlineCallbacks
	    result = context.run(gen.send, result)
	  File "/home/rhaberkorn/working-copies/ilua/ilua/kernelbase.py", line 199, in handle_message
	    content = yield self.do_complete(**msg['content'])
	  File "/home/rhaberkorn/working-copies/ilua/env/lib/python3.8/site-packages/twisted/internet/defer.py", line 2245, in unwindGenerator
	    return _cancellableInlineCallbacks(gen)
	  File "/home/rhaberkorn/working-copies/ilua/env/lib/python3.8/site-packages/twisted/internet/defer.py", line 2157, in _cancellableInlineCallbacks
	    _inlineCallbacks(None, gen, status, _copy_context())
	--- <exception caught here> ---
	  File "/home/rhaberkorn/working-copies/ilua/ilua/kernelbase.py", line 199, in handle_message
	    content = yield self.do_complete(**msg['content'])
	  File "/home/rhaberkorn/working-copies/ilua/env/lib/python3.8/site-packages/twisted/internet/defer.py", line 1997, in _inlineCallbacks
	    result = context.run(gen.send, result)
	  File "/home/rhaberkorn/working-copies/ilua/ilua/kernel.py", line 197, in do_complete
	    result = yield self.proto.sendRequest({
	builtins.AttributeError: 'ILuaKernel' object has no attribute 'proto'
	

Unhandled exception in event loop:
  File "/home/rhaberkorn/working-copies/ilua/env/lib/python3.8/site-packages/prompt_toolkit/buffer.py", line 1919, in new_coroutine
    await coroutine(*a, **kw)
  File "/home/rhaberkorn/working-copies/ilua/env/lib/python3.8/site-packages/prompt_toolkit/buffer.py", line 1743, in async_completer
    async for completion in async_generator:
  File "/home/rhaberkorn/working-copies/ilua/env/lib/python3.8/site-packages/prompt_toolkit/completion/base.py", line 323, in get_completions_async
    async for completion in completer.get_completions_async(
  File "/home/rhaberkorn/working-copies/ilua/env/lib/python3.8/site-packages/prompt_toolkit/completion/base.py", line 199, in get_completions_async
    for item in self.get_completions(document, complete_event):
  File "/home/rhaberkorn/working-copies/ilua/env/lib/python3.8/site-packages/jupyter_console/ptshell.py", line 150, in get_completions
    content = self.jup_completer.complete_request(
  File "/home/rhaberkorn/working-copies/ilua/env/lib/python3.8/site-packages/jupyter_console/completer.py", line 37, in complete_request
    msg = run_sync(self.client.shell_channel.get_msg)(timeout=self.timeout)
  File "/home/rhaberkorn/working-copies/ilua/env/lib/python3.8/site-packages/jupyter_client/channels.py", line 233, in get_msg
    raise Empty

Exception 
Press ENTER to continue...
In [1]:                                                                                                                                                                                       
Do you really want to exit ([y]/n)? y
Shutting down kernel
(env) rhaberkorn@thinkpad-x270:~/working-copies/ilua$ python3 --version
Python 3.8.10

The Python is quite old as you see, but Ubuntu 20.04 is still LTS. It also makes no difference which Lua interpreter I specify via -i.

Ctrl-C Interrupt Support

This is a tricky feature to implement because of the fact that the popular lua consoles (lua 5.3-5.1 & luajit) implement SIGINTs poorly

For example, lets take the reference implementation lua 5.3.
here is the SIGINT handler:

static void laction (int i) {
  signal(i, SIG_DFL); /* if another SIGINT happens, terminate process */
  lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
}

The handler sets the default handler (which crashes) upon activation.
Because we run in script mode (to execute ilua's interp.lua) that handler is only installed once. Because of that, If the same session will handle two SIGINTs, it will crash.

A secondary problem is that there are many lua consoles who are not even handling SIGINTs, and crash upon the signal.

There are couple of solutions I could think of:

  1. Run in console mode

Pipe the interp.script into the host lua stdin in interactive mode (after getting rid of the prompts)
e.g.

lua -i -e "_PROMPT='' _PROMPT2=''" < interp.lua

This way the lua-error-throwing SIGINT handler is installed after every evaluation, and multiple signals could be caught

The down side is that we should not allow the user to read from stdin (io.input:read) because that will mess things up.

  1. Serialize the session

We could track every evaluation request, serialize a state in the python kernel, and on SIGINT kill the lua host, launch a new one and dump the state back. Not sure this is possible though.

  1. Proxy lua host's signal()

If we could replace signal() with a function that NO-OPs on SIG_DFL, we could use the lua-error-throwing handler multiple times
i.e. Inject the lua host some library like this

void *__real_signal(int sig, void *func);

void *__wrap_signal(int sig, void *func)
{
	void *old_handler = __real_signal(sig, SIG_DFL);
	__real_signal(sig, old_handler);
	if (SIGINT == sig && SIG_DFL == func)
	{
		return old_handler;
	}
	else
	{
		return __real_signal(sig, func);
	}
}

The down-side of course is that implementing DLL injection for every platform (Windows especially) is hell.

  1. Not implementing Ctrl-C at all

We could call this a known issue, and stop bothering about it.
If we were to offer a solution anyway, we could distribute a patched lua.c (that won't reinstall default interrupt upon signal)

Got error in jupyter lab

Got error in jupyter lab. The console works well.
To my surprise, it would run well at first time, but then it always reports the following error.

My system is macOS10

lua: ...b/python3.6/site-packages/ilua/lualibs/json.lua/json.lua:389: expected argument of type string, got nil
stack traceback:
	[C]: in function 'error'
	...b/python3.6/site-packages/ilua/lualibs/json.lua/json.lua:389: in field 'decode'
	...Versions/3.6/lib/python3.6/site-packages/ilua/interp.lua:156: in main chunk
	[C]: in ?

Exception 'coroutine' object is not subscriptable on typing anything

I tried installing with pip into a clean virtual environment did the following:

$ ilua -i lua5.2
Jupyter console 6.4.0

ILua 0.2.1
In [1]: print'hi'

But I got a pretty long traceback:

jupyter_console/ptshell.py:852: RuntimeWarning: coroutine 'ZMQSocketChannel.msg_ready' was never awaited
  while self.client.iopub_channel.msg_ready():
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

Unhandled exception in event loop:
  File "/usr/lib/python3.9/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/aman/.local/python_venv/_ilua/lib/python3.9/site-packages/prompt_toolkit/input/vt100.py", line 168, in callback_wrapper
    callback()
  File "/home/aman/.local/python_venv/_ilua/lib/python3.9/site-packages/prompt_toolkit/application/application.py", line 691, in read_from_input
    self.key_processor.process_keys()
  File "/home/aman/.local/python_venv/_ilua/lib/python3.9/site-packages/prompt_toolkit/key_binding/key_processor.py", line 274, in process_keys
    self._process_coroutine.send(key_press)
  File "/home/aman/.local/python_venv/_ilua/lib/python3.9/site-packages/prompt_toolkit/key_binding/key_processor.py", line 186, in _process
    self._call_handler(matches[-1], key_sequence=buffer[:])
  File "/home/aman/.local/python_venv/_ilua/lib/python3.9/site-packages/prompt_toolkit/key_binding/key_processor.py", line 329, in _call_handler
    handler.call(event)
  File "/home/aman/.local/python_venv/_ilua/lib/python3.9/site-packages/prompt_toolkit/key_binding/key_bindings.py", line 102, in call
    result = self.handler(event)
  File "/home/aman/.local/python_venv/_ilua/lib/python3.9/site-packages/jupyter_console/ptshell.py", line 475, in _
    self.handle_iopub()
  File "/home/aman/.local/python_venv/_ilua/lib/python3.9/site-packages/jupyter_console/ptshell.py", line 854, in handle_iopub
    msg_type = sub_msg['header']['msg_type']

Exception 'coroutine' object is not subscriptable

This seems to happen no matter what I type into the console.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.