Skip to content
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 license-expression into javascript - Python3-only #19

Closed
wants to merge 77 commits into from
Closed

Transpile license-expression into javascript - Python3-only #19

wants to merge 77 commits into from

Conversation

alisianoi
Copy link
Collaborator

@alisianoi alisianoi commented Jul 13, 2017

This is a long running PR that will capture progress on transpiling license-expression into javascript with Transcrypt. The very first problem was to bundle a vendored version of Transcrypt as a development dependency: a) Transcrypt does not build wheels by default and b) not all changes that are required have been accepted (and they are not instantly accepted, it takes a while).

So, I am bundling a custom wheel with the changes that I need with the first commit. Next order of business: where to put the transpilation script (boolean.py currently has etc/transpile.py as the script that powers transpilation).

Update: relevant license-expression issue about online tool: #18

@pombredanne
Copy link
Member

@all3fox could it therefore make sense to move or fork your transcrypt fork with patches as an org-level repo too?

@alisianoi
Copy link
Collaborator Author

Yes, maybe it is worth to just move my all3fox/Transcrypt to nexB/Transcrypt and give me some modification rights?

@pombredanne
Copy link
Member

@all3fox sure, let's do this tomorrow

@pombredanne
Copy link
Member

This get transcrypt instead directly from a wheel path.... but this also requires mypy? now by default configure work on Python 2.... I am not sure I tested this on Python 3?

@alisianoi
Copy link
Collaborator Author

Thanks for help, I've added PyYAML and transpile.py. Now, when I do:

./configure etc/conf/dev/transpile
./bin/activate
./bin/python ./transpile/transpile.py

Transcrypt works but for some reason does not pick up src/license_expression/__init__.py and instead picks up nothing and generates an "empty" __init__.js in:

lib/python3.6/site-packages/transcrypt/modules/__javascript__/__init__.js (it contains just boilerplate for Transcrypt base modules but nothing from license-expression). I am investigating what's going on.

@pombredanne
Copy link
Member

if it helps temporarily to rename __init__.py to license_expression to go over that hump, do it! remember let's not get mundane stuff go in your way...

@alisianoi
Copy link
Collaborator Author

Ok, at this point ./bin/python transpile/transpile.py chokes because it needs a transcrypt-friendly version of boolean.py. For some reason, creating a wheel out of the transpile branch of boolean.py, copying it over to license-expression/thirdparty/prod and reassembling the virtual environment with:

deactivate
./configure clean
./configure clean etc/conf/dev/transpile
./configure
./configure etc/conf/dev/transpile
./bin/activate
./bin/python transpile/tranpile.py

does not do the trick. That's weird but a more reliable workaround is to manually install required branch of boolean.py after the ./configure etc/conf/dev/transpile step: ./bin/pip install -e ../boolean.py

@pombredanne
Copy link
Member

That's weird but a more reliable workaround is to manually install required branch of boolean.py after the ./configure etc/conf/dev/transpile step: ./bin/pip install -e ../boolean.py

that works too.

@alisianoi
Copy link
Collaborator Author

As I've mentioned on gitter, the Internal Error: too much recursion was caused by a chain of exceptions that got triggered because an if statement branched into the wrong branch. Turns out that I missed a transpilation switch/pragma mechanism pointed out to me here. I will be taking a look at it tomorrow and potentially using it instead of transcrypt_true hack-y function.

Right now I am facing an ReferenceError: py_TypeError is not defined when I try these commands:

let song = __init__.Licensing()
let expr = song.parse("MIT or GPL")

I've seen this error at this exact step before in boolean.py: that was caused by poor iteration over the loop and was fixed by using the -e 6 switch. This time, however, the reason is different and I have not figured it out yet. My best guess: between the Licensing.parse() call and the BooleanAlgebra.parse() call the string "MIT or GPL" magically turns into an empty array (and then BooleanAlgebra.parse() freaks out because it wants a string). However, I've not yet figured out why.

While I was figuring out the cause for a py_TypeError is not defined, I tried to hot-patch Transcrypt to contain that particular type of error: https://github.com/all3fox/Transcrypt/tree/type-error For some reason it did not work. Anyway, when I figure out the problem from the previous paragraph, having a TypeError would not be top priority.

Alexander Lisianoi and others added 20 commits August 15, 2017 15:23
Signed-off-by: Aleksandr Lisianoi <[email protected]>
Transcrypt does not make wheels by default and does not instantly
accept all the changes, so instead of just building a wheel from
qquick/Transcrypt master, this wheel comes from all3fox/Transcrypt
vendored branch.

Refs: https://github.com/all3fox/Transcrypt/tree/vendored
Signed-off-by: Aleksandr Lisianoi <[email protected]>
Signed-off-by: Philippe Ombredanne <[email protected]>
 * also make a specifc transpile config to use with Python 3 only
 * to configure make sure you default python is 3.6 (for instance with
   pyenv local 3.6.1) and then run: ./configure etc/conf/dev/transpile
   to select the extra config for transpile. This will not run by
   default and will not run on Python2

Signed-off-by: Philippe Ombredanne <[email protected]>
It is an adapted version of a similar script from boolean.py

Signed-off-by: Aleksandr Lisianoi <[email protected]>
Transcrypt used to *sometimes* rely on os.getcwd() to get path to the
project. That does not always work and it is better to use
utils.commandArgs.source all the time.

Signed-off-by: Aleksandr Lisianoi <[email protected]>
Note: copy.copy and copy.deepcopy are good candidates to be
implemented in Transcrypt because they could just delegate the work to
.__copy__() and .__deepcopy__() methods on the target objects
respectively.

Signed-off-by: Aleksandr Lisianoi <[email protected]>
1. Transcrypt does not support functools
2. @total_ordering is not really necessary for LicenseSymbols and others

Signed-off-by: Aleksandr Lisianoi <[email protected]>
1. Transcrypt does not support it
2. license_expression does not use it

Signed-off-by: Aleksandr Lisianoi <[email protected]>
Some classes in _pyahocorasick relied on OrderedDict for as_dict which
used an OrderedDict purely for the __repr__, so make them use just
dict. Python 3.6 even has an implementation detail that the built-in
dict behaves like an OrderedDict, so all tests pass there.

Alternative is to bring OrderedDict from collections.py and
_collections_abc.py which still would not transpile with Transcrypt
because it uses decorators heavily.

Signed-off-by: Aleksandr Lisianoi <[email protected]>
In both single and multiple inheritance cases just drop the
arguments. Let's see if Transcrypt will cope with multiple
inheritance.

Signed-off-by: Aleksandr Lisianoi <[email protected]>
Signed-off-by: Aleksandr Lisianoi <[email protected]>
Error was "nil = object(): object is not a function"

Signed-off-by: Aleksandr Lisianoi <[email protected]>
Alexander Lisianoi added 24 commits August 15, 2017 15:58
Transcrypt needs a class instance to be able to call a class method

Signed-off-by: Aleksandr Lisianoi <[email protected]>
When transpiled to javascript, deleting elements from a list does not
change the length of the list there. This leads to eventual "index out
of range" behavior. So, avoid the del keyword altogether.

Signed-off-by: Aleksandr Lisianoi <[email protected]>
Without this calling ./bin/py.test for some reason starts looking for
yaml, which is not installed, and then fails.

Signed-off-by: Aleksandr Lisianoi <[email protected]>
Signed-off-by: Aleksandr Lisianoi <[email protected]>
In Python before 3.6 this conversion does not take place automatically

Signed-off-by: Aleksandr Lisianoi <[email protected]>
The licenses are predefined and not, and are both an alias and not.

Signed-off-by: Aleksandr Lisianoi <[email protected]>
If your key function returns a "complicated" object (an array, etc.)
then you should be prepared that Javascript will use vanilla
comparison operators on that object. Since more often than not objects
in Javascript are compared as Unicode code points, you should really
know what you are doing.

On the other hand, numbers will be compared as numbers.

Signed-off-by: Aleksandr Lisianoi <[email protected]>
Also, throw in some parenthesis

Signed-off-by: Aleksandr Lisianoi <[email protected]>
Since 'or' is also a logical operator, it is important that
LicenseSymbol's supersede it and treat as part of a symbol

Signed-off-by: Aleksandr Lisianoi <[email protected]>
This tells Transcrypt to define __init__ function (named after the
main entry point of license_expression) on the window object. Without
this flag Transcrypt will defined __init__ function on the
module.exports object, which works for node.

Signed-off-by: Aleksandr Lisianoi <[email protected]>
Transcrypt chokes if you use named arguments and decide to skip a
couple in between. Example: if the function has three arguments and
you just use the first and the third (even if named), Transcrypt will
incorrectly assign your third (named) argument into the second in
javascript.

Note: Transcrypt has a `-k` switch that enables extended keyword
argument support. However, this switch does not play nicely with the
`-e 6` switch (EcmaScrypt 6 support) and the problem is unclear: it
may be Transcrypt's fault or not. Fact: AND_class.__bool__ instanceof
Function is true but calling AND_class.__bool__() throws an excpetion.

Refs: https://stackoverflow.com/questions/42064466/instanceof-using-es6-class-inheritance-chain-doesnt-work

Instead, just avoid skipping keyword arguments.

Signed-off-by: Aleksandr Lisianoi <[email protected]>
Transcrypt will transpile your classmethod only if an instance of a
class is explicitly created to call that classmethod. It does not
support calling classmethod on a class itself.

Signed-off-by: Aleksandr Lisianoi <[email protected]>
Transcrypt will transpile your classmethod only if an instance of a
class is explicitly created to call that classmethod. It does not
support calling classmethod on a class itself.

Signed-off-by: Aleksandr Lisianoi <[email protected]>
@pombredanne
Copy link
Member

I just rebased your branch and pushed this as alisianoi-transpile here. I could have but did not dare force push to your repo after the rebase! I might merge this rebased branch instead

@pombredanne pombredanne changed the title [WIP] Transpile license-expression into javascript Transpile license-expression into javascript - Python3-only Apr 5, 2018
@pombredanne
Copy link
Member

For reference, this depends on bastikr/boolean.py#72
And when merged we will need to start having a Python2-only maintenance branch as this branch will only support Python3

pombredanne pushed a commit that referenced this pull request Apr 16, 2021
@pombredanne pombredanne deleted the branch aboutcode-org:master May 10, 2022 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants