Skip to content

Instantly share code, notes, and snippets.

@doloopwhile
Last active April 11, 2024 00:00
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save doloopwhile/8c6ec7dd4703e8a44e559411cb2ea221 to your computer and use it in GitHub Desktop.
Save doloopwhile/8c6ec7dd4703e8a44e559411cb2ea221 to your computer and use it in GitHub Desktop.
Why I decided to discontinue PyExecJS and Python-CoffeeScript ?

What is PyExecJS and Python-CoffeeScript.

They are Python libraries that I developped on 2011.

  • PyExecJS: Automatically picks the best runtime available to evaluate your JavaScript program.
  • Python-CoffeeScript: A bridge to the JS CoffeeScript compiler.

They are ports of ruby gems with same name (execjs and ruby-coffee-script).

The aim of them were to compile CoffeeScript code on Windows XP. It was difficult and tangled to install Ruby, NodeJS or V8 (at least, I thought so). What I could use were builtin JScript and Python (which is installed with installer).

Current status

EOL. PyExecJS and Python-CoffeeScript are no longer maintananced. Bugs are not be fixed (even if they are trivial or essential).

We suggest to use other library or to make a fork.

Reason of EOL #1: node is available on Windows

Currently, NodeJS works on Windows 10.

  • To execute JavaScript snippet, We can use subprocess.check_output(['node', ...]).
  • To compile CoffeeScript code, we can use build tool such as WebPacker.

So, I think that PyExecJS and Python-CoffeeScript are useless (for my original purpose).

Reason of EOL #2: It seems that PyExecJS is improperly used

It seems for me that PyExecJS is mainly used as a bridge to NodeJS.

However, As a bridge to NodeJS, PyExecJS is badly designed. It is because I designed (cloned) PyExecJS as a adapter to cover-up difference of JS engines (NodeJS, PyV8, JScript, etc..). So, PyExecJS does not support NodeJS specific features (such as to specify NODE_ENV). It is difficult to add features while keeping consistency with original design.

If we want to call NodeJS function from Python, I think we should use raw subprocess.check_output or an single purpose library.

Thanks

Thanks for using PyExecJS and Python-CoffeeScript, for sending merge requests and issues.

@wiwichips
Copy link

Hello @doloopwhile, check out PythonMonkey https://github.com/Distributive-Network/PythonMonkey - a Python library that uses the SpiderMonkey JS engine to execute JavaScript from Python.

Just $ pip install pythonmonkey to get started!

Example #1 (pythonmonkey.eval)

Evaluating JavaScript code in Python.

>>> import pythonmonkey as pm
>>> hello = pm.eval("(func) => { func('Hello World!')}")
>>> hello(print)
Hello World!

Example #2 (pythonmonkey.require)

Loading a JavaScript module from Python and executing it.
main.py:

import pythonmonkey as pm
test = pm.require('./my-javascript-module');
test.sayHello() # this prints hello, world

my-javascript-module.js:

exports.sayHello = () => { console.log('hello, world') };

$ python3 main.py outputs hello, world!

@ryan2625
Copy link

RIP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment