onelinerizer
onelinerizer copied to clipboard
Python3 support
Hi, this repository looks really interesting.
I was wondering would you consider to support python3?
+1
+1
+1
+1
+1
This needs to be a thing.
+1
Would this look like a fork, auto-detecting the Python version, a command line flag, or what? Would be be possible to write this so it's runnable in Python 2 or 3? Also, I noticed that the ContextDecorator class could help with rewriting with statements for Python 3.
Command-line flag, most likely!
Turns out onelinerizing is great for obfuscating autograders to pass out to students for virtual classes. We were using it last year, but this year we are switching all of our assignments to python 3. Because onelinerizing is so convenient, I'm gonna try and see if I can get basic functionality working for python 3.
I've forked the repo here: https://github.com/ehannigan/onelinerizer
For anyone who is interested, I would be very appreciative of help. If we can get it to work in the fork, we can merge it back here as a python3 version. (@csvoss , Is this the right way to make changes? If not, let me know and I will follow whatever development style you want to use for this repo).
Amazing!
Yes, I accept pull requests! I don't have any formal guidelines or anything – happy to give feedback and help iterate on any PRs.
Got the errors down to 32/113 (compared to 113/113 yesterday) by fixing the lowest hanging fruit.
- print statements
- from io import StringIO, ByteIO
- reduce -> functools.reduce (although still running into errors resulting from reduce, so I probably am missing something here)
- visit_Call https://greentreesnakes.readthedocs.io/en/latest/nodes.html?highlight=starargs#Call https://github.com/PyCQA/bandit/commit/1b11246e595675abad1669ce7f64f4a17caf9e8f
- visit_Constant (replaces visit_Num and visit_Str) https://greentreesnakes.readthedocs.io/en/latest/nodes.html#Constant
- visit_arguments (id is now arg) https://greentreesnakes.readthedocs.io/en/latest/nodes.html?highlight=starargs#arg
- removed ast.Exec and ast.Print in onelinerizer.py (line 820) as those don't seem to exist anymore?
I am not 100% sure these fixes have not led to other issues. It works on a very simple chunk of code for my autograder, so it's a good start. I'm slowly beginning to wrap my head around everything. I think the last 32 errors are going to be more difficult.
I'll keep updating on progress
Any movements on this?
I've tried the current state of the fork, it seems to work for the provided examples, but definitely does not like django throwing an ast Error: "Case not cought"
Hey! If any of you are still interested in python3 support, I made my own version of this project called Flatliner with a demo website at https://flatliner.herokuapp.com/.
It's not as full featured as this project though (this project was excellent), I have no support for things like try-except, scope modifiers like global
, nonlocal
, etc, but it can convert a good number of python3 programs. The source code is also available here.