onelinerizer icon indicating copy to clipboard operation
onelinerizer copied to clipboard

Python3 support

Open gloomy-ghost opened this issue 8 years ago • 15 comments

Hi, this repository looks really interesting.

I was wondering would you consider to support python3?

gloomy-ghost avatar Nov 02 '16 06:11 gloomy-ghost

+1

hanbinpro avatar Aug 13 '17 14:08 hanbinpro

+1

THMonster avatar Nov 12 '17 10:11 THMonster

+1

argolo avatar May 28 '18 03:05 argolo

+1

XCanG avatar Jun 17 '18 21:06 XCanG

+1

dsolmann avatar Sep 30 '18 16:09 dsolmann

This needs to be a thing.

fionafibration avatar Oct 18 '18 20:10 fionafibration

+1

stevenjoezhang avatar Mar 14 '19 03:03 stevenjoezhang

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.

cplir-c avatar Jul 19 '19 21:07 cplir-c

Command-line flag, most likely!

csvoss avatar Jun 06 '20 04:06 csvoss

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).

ehannigan avatar Sep 14 '20 18:09 ehannigan

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.

csvoss avatar Sep 14 '20 22:09 csvoss

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

ehannigan avatar Sep 18 '20 02:09 ehannigan

Any movements on this?

Hendiadyoin1 avatar Nov 25 '20 16:11 Hendiadyoin1

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"

Hendiadyoin1 avatar Nov 25 '20 16:11 Hendiadyoin1

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.

hhc97 avatar Feb 11 '23 04:02 hhc97