dflook / python-minifier

Transform Python source code into its most compact representation
MIT License
583 stars 43 forks source link

python version compatibilty #31

Open indexofrefraction opened 3 years ago

indexofrefraction commented 3 years ago

hi, i tried this to minify code that needs to run on python 2.7 and python 3.7 sadly print() gets translated to print if minifying is run on 2.7 which breaks compatibilty exec(...) gets minified to: exec ... also triggering errors on 3.x

it would be nice if there was a compatibilty mode not downgrading all code to 2.x standard best, index

dflook commented 3 years ago

If you run python-minifier using python 3.7, the output will be compatible with 3.7 Do you have any problems running the 3.7 minified code on 2.7?

indexofrefraction commented 3 years ago

i'd have to test if 3.7 minified code works on 2.7, that would be a workaround. but for me ideally minification would work from both python versions with results working on both versions, too. hence the idea of a compat mode without syntax changes. (the code itself works on both versions)

dflook commented 3 years ago

Python-minifier relies on the running interpreter for parsing, so it won't have greater compat than python itself. If there is any code that works on a lower version than it's being minified with but breaks after being minified, that might be worth a compatability mode.

On that note, did you from __future__ import print_function in the code where print() is transformed to print? That would be a bug

rochacbruno commented 3 years ago

Is 3.10 support on the roadmap?

dflook commented 3 years ago

@rochacbruno Yes. It's been implemented, but must be validated against the release version. If all goes well it will be released today 🤞.

rochacbruno commented 3 years ago

thanks @dflook I am bumping https://GitHub.com/rochacbruno/dynaconf to run CI on 3.10 and looks like the missing package is minify, we use it for our vendoring script.

Thanks

dflook commented 3 years ago

@rochacbruno python-minifier 2.5.0 is now available on PyPI with Python3.10 support

rochacbruno commented 3 years ago

Thanks @dflook now dynaconf install test on 3.10 is passing :)

https://github.com/rochacbruno/dynaconf/runs/3816321083?check_suite_focus=true

WebReflection commented 2 months ago

is there any reason for that <3.12 as Python version requirement? I am on Python 3.12.4 which is latest stable and it'd be unfortunate to need to downgrade latest stable for this lovely module, thanks.


edit never mind, I've seen this only now https://github.com/dflook/python-minifier/pull/94