JavaScripthon is a tool that seems to transpile Python3 code into javascript (ES6) code. Github:https://github.com/azazel75/metapensiero.pj
It also supports SourceMap, and it was said that you can debug with Python code as it is, so I thought it would be interesting and tried it, so I wrote a story that I gave up after all. (I really wanted to make an article "I tried it" ...)
The bottom line is, don't do it on Windows? I don't really know because I don't have a Mac.
Reference below http://www.moongift.jp/2016/05/javascripthon-pythonで書いてes6のコードを生成/
pip install javascripthon
So, when I did "Ei", I was able to install dukpy, which depends on it. Without vcvarsall.bat. It seems that it was supposed to include Visual Studio Community 2015. http://thinkami.hatenablog.com/entry/2016/06/06/225903
When I put it in and did it again, it fell off. Without unistd.h. I give up because it can't be installed on Windows with pip install like a unix type.
I decided to clone it from Github and run it directly. Since dukpy seems to be an engine for running js, I thought that it would not be necessary if only transpile was used, so I decided to run it directly.
If you read the code, it's probably necessary, so comment out the import of dukpy in src / metapensiero / pj / api.py
and execute it.
python -m metapensiero.pj source.py
When I said "Ei", it fell. UnicodeDecodeError. This is the cause of the fall.
src/metapensiero/pj/api.py
src_text = open(src_filename).readlines()
I will die from Japanese comments. I will rewrite it once.
src_text = open(src_filename, encoding='utf-8').readlines()
It fell again. This is the next cause.
src/metapensiero/pj/processor/util.py
def parent_of(path):
return '/'.join(path.rstrip('/').split('/')[:-1])
Windows backslash delimiters aren't taken into account. For the time being, I want to run it on Windows, so I will change it to backslash once.
def parent_of(path):
return '\\'.join(path.rstrip('\\').split('\\')[:-1])
python -m metapensiero.pj source.py
Now I have a .js file and a .js.map file. Hooray.
However, it seems that Python that goes a little deeper cannot be transpiled. For example
for i, x in enumerate(list1):
#processing
Or, a loop with two variables seems to be useless and will result in an error.
Let's give up already. Let's buy a Mac first. Let's talk to my wife.
Recommended Posts