-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transpile boolean.py into javascript - Python3-only #72
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Add these as extra dependencies into setup.py - transcrypt (transpiling) - pyaml (to read .yml config files) In development this will install them for you: pip install -e . In production you need to specify your intention: pip install boolean.py[transpile] Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Ok, Now need to interface into transcrypt to make the transpillation call. |
Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
* Allow to pass any argument to transcrypt with '--': transpile -- --license transpile -- --help * If you specify transcrypt arguments manually, specify them all: (this means you need to specify what to transpile) transpile -- --esv 6 /path/to/file.py * To suppress logging from 'transpile': transpile --quiet -- --esv 6 /path/to/file.py * 'transpile' without arguments will try to transpile boolean.py Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
And now |
I am not sure this would need to be part of the main setup code. Especially since your code uses pathlib which is Python 3. I would be more comfy to have a separate scripts under some |
To use it, do the following: pip install -r etc/requirements.txt ./etc/transpile.py You may need a development version of transcrypt: pip install -r etc/requirements.txt pip install -e your/local/transcrypt ./etc/transpile.py Transcrypt cannot handle targets that are "above" it in the directory structure, so the following will not work: cd ./etc ./transpile.py Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Finally moved
Update: will quickly address the unit tests and then finally move on to hacking |
This is attempt 2 at parsing AST: with hand-written functions that iterate over the ast tree and represent state. `ast.NodeTransformer` does not work because it can only visit single nodes and does not know when it *leaves* nodes. Alternative is `astor` Signed-off-by: Aleksandr Lisinaoi <all3fox@gmail.com>
Signed-off-by: Aleksandr Lisinaoi <all3fox@gmail.com>
Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Signed-off-by: Aleksandr Lisinaoi <all3fox@gmail.com>
Tests are broken because of the |
This should be later removed from history. Checking boolean.js helps others avoid the hassle of running a dev version of transcrypt over a dev version of boolean.py to take a look at transpilation results. Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Ok, I've checked in
Current problem:
That throws the following: Several hours of crawling with debugger over This is my best guess right now and I am still looking at it :( |
Finally! |
That function uses type built-in to register a new type. Transcrypt does not support that and, to be honest, I do not see the need for registering a new type. Removing _wrap_type makes no unit test fail. Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Transcrypt does not "alias" basestring as string Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
The first switch forces a transpilation from scratch The second switch forces EcmaScript 6, which allows to have generators Refs: TranscryptOrg/Transcrypt#358 Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
This file is generated by transcrypt and is included temporarily to allow others to just load it and see what works and what does not. Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Ok, the generators work with
|
Ok,
However, some comparison starts to work if you use dunder methods in
|
Use something else.... chain is just a short hand for consuming nested loops.
Use a plain set instead. Alternatively implementing an immutable set is quick enough.
What does JS do here for comparisons? is the
OK, so there is some validation code that is not handled at all then? The parse does not work?
is the symbol
This is not a big problem. Doing this kinda of comparison is not super important I think, is it?
ok. so still some stuff not right in the guts of parsing then?
Hum, this likely means that dunder methods may not be used at all by Transcrypt? |
@@ -1,4 +1,5 @@ | |||
*.pyc | |||
__javascript__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, you both ignored this and committed code that is in the dir.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I did that on purpose: currently, having __javascript__/boolean.js
let's you avoid the hassle of getting a vendored version of Transcrypt and making it work. Later I will remove __javascript__/boolean.js
and the .gitignore
will stay.
boolean/boolean.py
Outdated
yield TOKENS[tok.lower()], tok, position | ||
except KeyError: | ||
value = TOKENS.get(tok.lower()) | ||
if value is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can write: if value:
instead? is there cases where we we get an empty token otherwise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix
etc/transpile.yml
Outdated
@@ -0,0 +1,15 @@ | |||
logging: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to tell Transcrypt to use two or four spaces rather than tabs in the generated JS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know, no.
Javascript objects don't throw an error if you access non-existent keys. Transcrypt can imitate Python dictionaries but it does not always work. Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
…ctionary Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
The '.toString' makes these objects "easier to compare" in js runtime. Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Transcrypt does not support issubclass Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Also, drop preprocess.py, there is no preprocessing of the code. Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Also add extended truth-value testing flag and a --browser flag Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
Signed-off-by: Aleksandr Lisianoi <all3fox@gmail.com>
I just rebased your branch and pushed this as |
When merged we will need to start having a Python2-only maintenance branch as this branch will only support Python3 |
Hi, I was kinda bored and created a (partial) port of this library for javascript. You can check it out here: https://github.com/bigbug/boolean |
This will be a long-running PR where you can monitor progress of actual transpilation.
This will be used to identify actual "blockers" (like missing modules, unsupported features) and these "blockers" will be dealt with in separate PR's and then this PR will be rebased accordingly. Or even in this PR if the "blocker" is super small.
So far I've set up an
entry_point
which in theory should allow the following approach:During development that looks like:
In its simplest form this would generate a
__javascript__
directory directly inside the package. However, there will be anArgumentParser
to deal with a) passing transcrypt related args further to transcrypt and b) configuring some other parameters for transpilation.Current blocker: need to figure out a way to install
transcrypt
andpyaml
as non-necessary dependencies. Probably somehow withextras_require
insetup.py