a-shell icon indicating copy to clipboard operation
a-shell copied to clipboard

execjs._exceptions.RuntimeUnavailableError: Could not find an available JavaScript runtime.

Open Emasoft opened this issue 1 year ago • 3 comments

I have some issue with the PyExecJS library.

[~/Documents]$ python
Python 3.11.0 (heads/3.11-dirty:2af28c9018, Apr 23 2023, 19:57:14) [Clang 14.0.3 (clang-1403.0.22.14.
1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import execjs
>>> execjs.eval("'red yellow blue'.split(' ')")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/var/mobile/Containers/Data/Application/24D7FAD5-9E04-4D2D-8741-A69E0854A4A8/Library/lib/pyth
on3.11/site-packages/execjs/__init__.py", line 51, in eval
    return get().eval(source, cwd)
           ^^^^^
  File "/var/mobile/Containers/Data/Application/24D7FAD5-9E04-4D2D-8741-A69E0854A4A8/Library/lib/pyth
on3.11/site-packages/execjs/_runtimes.py", line 21, in get
    return get_from_environment() or _find_available_runtime()
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/mobile/Containers/Data/Application/24D7FAD5-9E04-4D2D-8741-A69E0854A4A8/Library/lib/pyth
on3.11/site-packages/execjs/_runtimes.py", line 49, in _find_available_runtime
    raise exceptions.RuntimeUnavailableError("Could not find an available JavaScript runtime.")
execjs._exceptions.RuntimeUnavailableError: Could not find an available JavaScript runtime.
>>> 

Emasoft avatar Jun 07 '23 18:06 Emasoft

From the error, it looks like PyExecJS is looking for an executable to run JavaScript files. I certainly has some options, which it tried in _find_available_runtime(), but unfortunately these options do not include the a-Shell command (jsc). The other function on the same line (get_from_environment()) is probably our solution. It seems that you can tell PyExecJS what the JavaScript Runtime is called using environment variables. I'm going to have a look at their documentation.

holzschu avatar Jun 07 '23 18:06 holzschu

It's not going to be that easy: PyExecJS has a list of existing runtimes that it supports, indexed by names. Probably the closest is Apple JavaScriptCore, so you will need:

setenv EXECJS_RUNTIME JavaScriptCore

to tell it to use this runtime. But you will also need to edit PyExecJS/execjs/_external_runtime.py, because it contains the location of the command, hardcoded as /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc, which doesn't exist on iOS. Replacing that string by jsc should work.

holzschu avatar Jun 07 '23 18:06 holzschu

It seems tricky. Can you include a modified custom version of PyExecJS in the next version of a-Shell?

Emasoft avatar Jun 07 '23 18:06 Emasoft