From d0ca7b0363eb49c9383c3f815961b36ea1862f3c Mon Sep 17 00:00:00 2001 From: rocky Date: Tue, 26 Oct 2021 06:08:17 -0400 Subject: [PATCH 1/5] Loosen check to allow running from 2.4-3.10 We still only can *decompile* 2.4-3.8 --- uncompyle6/bin/uncompile.py | 4 ++-- uncompyle6/parser.py | 4 +--- uncompyle6/scanner.py | 19 ++++++++++++++++--- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/uncompyle6/bin/uncompile.py b/uncompyle6/bin/uncompile.py index 6266ecd9..2c21a011 100755 --- a/uncompyle6/bin/uncompile.py +++ b/uncompyle6/bin/uncompile.py @@ -74,9 +74,9 @@ def main_bin(): if not (sys.version_info[0:2] in ((2, 6), (2, 7), (3, 0), (3, 1), (3, 2), (3, 3), (3, 4), (3, 5), (3, 6), - (3, 7), (3, 8) + (3, 7), (3, 8), (3, 9), (3, 10) )): - print('Error: %s requires Python 2.6-3.8' % program, + print('Error: %s requires Python 2.4-3.10' % program, file=sys.stderr) sys.exit(-1) diff --git a/uncompyle6/parser.py b/uncompyle6/parser.py index c35febad..198364d6 100644 --- a/uncompyle6/parser.py +++ b/uncompyle6/parser.py @@ -19,13 +19,11 @@ Common uncompyle6 parser routines. """ -from __future__ import print_function - import sys -from xdis import iscode, py_str2float from spark_parser import GenericASTBuilder, DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG from uncompyle6.show import maybe_show_asm +from xdis import iscode class ParserError(Exception): diff --git a/uncompyle6/scanner.py b/uncompyle6/scanner.py index d11adbfa..ba9374a6 100755 --- a/uncompyle6/scanner.py +++ b/uncompyle6/scanner.py @@ -28,7 +28,14 @@ import sys from uncompyle6.scanners.tok import Token from xdis.version_info import IS_PYPY, PYTHON3, version_tuple_to_str import xdis -from xdis import Bytecode, canonic_python_version, code2num, instruction_size, extended_arg_val, next_offset +from xdis import ( + Bytecode, + canonic_python_version, + code2num, + instruction_size, + extended_arg_val, + next_offset, +) # The byte code versions we support. # Note: these all have to be tuples of 2 ints @@ -111,7 +118,10 @@ class Scanner(object): exec("from xdis.opcodes import %s" % v_str) exec("self.opc = %s" % v_str) else: - raise TypeError("%s is not a Python version I know about" % version_tuple_to_str(version)) + raise TypeError( + "%s is not a Python version I know about" + % version_tuple_to_str(version) + ) self.opname = self.opc.opname @@ -566,7 +576,10 @@ def get_scanner(version, is_pypy=False, show_asm=None): "scan.Scanner%s(show_asm=show_asm)" % v_str, locals(), globals() ) else: - raise RuntimeError("Unsupported Python version %s" % version) + raise RuntimeError( + "Unsupported Python version, %s, for decompilation" + % version_tuple_to_str(version) + ) return scanner From 3ad63071ac1b24698aa5698198f51f010b445c9b Mon Sep 17 00:00:00 2001 From: rocky Date: Tue, 26 Oct 2021 18:25:30 -0400 Subject: [PATCH 2/5] Admnistrivia: package info --- __pkginfo__.py | 5 +++++ admin-tools/make-dist-older.sh | 10 +++++++--- setup.py | 9 +++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/__pkginfo__.py b/__pkginfo__.py index fc4acc03..47719c01 100644 --- a/__pkginfo__.py +++ b/__pkginfo__.py @@ -43,10 +43,12 @@ classifiers = [ "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Operating System :: OS Independent", "Programming Language :: Python", + "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.4", "Programming Language :: Python :: 2.5", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.0", "Programming Language :: Python :: 3.1", "Programming Language :: Python :: 3.2", @@ -56,6 +58,9 @@ classifiers = [ "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Software Development :: Debuggers", "Topic :: Software Development :: Libraries :: Python Modules", ] diff --git a/admin-tools/make-dist-older.sh b/admin-tools/make-dist-older.sh index aee0ce92..0e418959 100755 --- a/admin-tools/make-dist-older.sh +++ b/admin-tools/make-dist-older.sh @@ -18,7 +18,7 @@ fi cd .. source $PACKAGE/version.py -echo $VERSION +echo $__version__ for pyversion in $PYVERSIONS; do if ! pyenv local $pyversion ; then @@ -29,11 +29,15 @@ for pyversion in $PYVERSIONS; do python setup.py bdist_egg done +pyenv local 2.7.18 +python setup.py bdist_wheel +mv -v dist/${PACKAGE}-$__version__-py2{.py3,}-none-any.whl + # Pypi can only have one source tarball. # Tarballs can get created from the above setup, so make sure to remove them since we want # the tarball from master. -tarball=dist/${PACKAGE}-$VERSION-tar.gz +tarball=dist/${PACKAGE}-${__version_}_-tar.gz if [[ -f $tarball ]]; then - rm -v dist/${PACKAGE}-$VERSION-tar.gz + rm -v dist/${PACKAGE}-${__version__}-tar.gz fi diff --git a/setup.py b/setup.py index 1d1da4af..c88e7362 100755 --- a/setup.py +++ b/setup.py @@ -4,13 +4,18 @@ import sys """Setup script for the 'uncompyle6' distribution.""" SYS_VERSION = sys.version_info[0:2] -if not ((2, 6) <= SYS_VERSION <= (3, 9)): - mess = "Python Release 2.6 .. 3.9 are supported in this code branch." +if not ((2, 4) <= SYS_VERSION < (3, 11)): + mess = "Python Release 2.6 .. 3.10 are supported in this code branch." if (2, 4) <= SYS_VERSION <= (2, 7): mess += ( "\nFor your Python, version %s, use the python-2.4 code/branch." % sys.version[0:3] ) + if (3, 3) <= SYS_VERSION < (3, 6): + mess += ( + "\nFor your Python, version %s, use the python-3.3-to-3.5 code/branch." + % sys.version[0:3] + ) elif SYS_VERSION < (2, 4): mess += ( "\nThis package is not supported for Python version %s." % sys.version[0:3] From c164df279558d33b4b475d7208a5cd4a281ec535 Mon Sep 17 00:00:00 2001 From: rocky Date: Tue, 26 Oct 2021 18:52:17 -0400 Subject: [PATCH 3/5] Redo packaging. --- ...ake-dist-older.sh => make-dist-2.4-2.7.sh} | 0 admin-tools/make-dist-3.3-3.5.sh | 38 +++++++++++++++++++ ...make-dist-newer.sh => make-dist-newest.sh} | 6 +-- admin-tools/pyenv-2.1-2.3-versions | 9 +++++ admin-tools/pyenv-2.4-2.7-versions | 9 +++++ admin-tools/pyenv-3.1-3.2-versions | 9 +++++ admin-tools/pyenv-3.3-3.5-versions | 8 ++++ admin-tools/pyenv-newest-versions | 2 +- admin-tools/pyenv-versions | 8 ++++ 9 files changed, 85 insertions(+), 4 deletions(-) rename admin-tools/{make-dist-older.sh => make-dist-2.4-2.7.sh} (100%) create mode 100755 admin-tools/make-dist-3.3-3.5.sh rename admin-tools/{make-dist-newer.sh => make-dist-newest.sh} (83%) create mode 100644 admin-tools/pyenv-2.1-2.3-versions create mode 100644 admin-tools/pyenv-2.4-2.7-versions create mode 100644 admin-tools/pyenv-3.1-3.2-versions create mode 100644 admin-tools/pyenv-3.3-3.5-versions create mode 100644 admin-tools/pyenv-versions diff --git a/admin-tools/make-dist-older.sh b/admin-tools/make-dist-2.4-2.7.sh similarity index 100% rename from admin-tools/make-dist-older.sh rename to admin-tools/make-dist-2.4-2.7.sh diff --git a/admin-tools/make-dist-3.3-3.5.sh b/admin-tools/make-dist-3.3-3.5.sh new file mode 100755 index 00000000..95426ffb --- /dev/null +++ b/admin-tools/make-dist-3.3-3.5.sh @@ -0,0 +1,38 @@ +#!/bin/bash +PACKAGE=uncompyle6 + +# FIXME put some of the below in a common routine +function finish { + cd $owd +} + +cd $(dirname ${BASH_SOURCE[0]}) +owd=$(pwd) +trap finish EXIT + +if ! source ./pyenv-3.3-3.5-versions ; then + exit $? +fi +if ! source ./setup-python-3.3.sh ; then + exit $? +fi + +cd .. +source $PACKAGE/version.py +echo $__version__ + +for pyversion in $PYVERSIONS; do + if ! pyenv local $pyversion ; then + exit $? + fi + # pip bdist_egg create too-general wheels. So + # we narrow that by moving the generated wheel. + + # Pick out first two number of version, e.g. 3.5.1 -> 35 + first_two=$(echo $pyversion | cut -d'.' -f 1-2 | sed -e 's/\.//') + rm -fr build + python setup.py bdist_egg bdist_wheel + mv -v dist/${PACKAGE}-$__version__-{py2.py3,py$first_two}-none-any.whl +done + +python ./setup.py sdist diff --git a/admin-tools/make-dist-newer.sh b/admin-tools/make-dist-newest.sh similarity index 83% rename from admin-tools/make-dist-newer.sh rename to admin-tools/make-dist-newest.sh index ca403b88..af04b060 100755 --- a/admin-tools/make-dist-newer.sh +++ b/admin-tools/make-dist-newest.sh @@ -10,7 +10,7 @@ cd $(dirname ${BASH_SOURCE[0]}) owd=$(pwd) trap finish EXIT -if ! source ./pyenv-newer-versions ; then +if ! source ./pyenv-newest-versions ; then exit $? fi if ! source ./setup-master.sh ; then @@ -19,7 +19,7 @@ fi cd .. source $PACKAGE/version.py -echo $VERSION +echo $__version__ for pyversion in $PYVERSIONS; do if ! pyenv local $pyversion ; then @@ -32,7 +32,7 @@ for pyversion in $PYVERSIONS; do first_two=$(echo $pyversion | cut -d'.' -f 1-2 | sed -e 's/\.//') rm -fr build python setup.py bdist_egg bdist_wheel - mv -v dist/${PACKAGE}-$VERSION-{py2.py3,py$first_two}-none-any.whl + mv -v dist/${PACKAGE}-$__version__-{py2.py3,py$first_two}-none-any.whl done python ./setup.py sdist diff --git a/admin-tools/pyenv-2.1-2.3-versions b/admin-tools/pyenv-2.1-2.3-versions new file mode 100644 index 00000000..254fcf85 --- /dev/null +++ b/admin-tools/pyenv-2.1-2.3-versions @@ -0,0 +1,9 @@ +# -*- shell-script -*- +# Sets PYVERSIONS to be all pyenv the oldest versions we have. +# These are not covered (yet) by uncompyle6, although +# some programs do work here. +if [[ $0 == ${BASH_SOURCE[0]} ]] ; then + echo "This script should be *sourced* rather than run directly through bash" + exit 1 +fi +export PYVERSIONS='2.1.3 2.2.3 2.3.7' diff --git a/admin-tools/pyenv-2.4-2.7-versions b/admin-tools/pyenv-2.4-2.7-versions new file mode 100644 index 00000000..6dd7e38c --- /dev/null +++ b/admin-tools/pyenv-2.4-2.7-versions @@ -0,0 +1,9 @@ +# -*- shell-script -*- +# Sets PYVERSIONS to be pyenv versions that +# we can use in the python-2.4-to-2.7 branch. + +if [[ $0 == ${BASH_SOURCE[0]} ]] ; then + echo "This script should be *sourced* rather than run directly through bash" + exit 1 +fi +export PYVERSIONS='2.4.6 2.5.6 2.6.9 2.7.18' diff --git a/admin-tools/pyenv-3.1-3.2-versions b/admin-tools/pyenv-3.1-3.2-versions new file mode 100644 index 00000000..334a2631 --- /dev/null +++ b/admin-tools/pyenv-3.1-3.2-versions @@ -0,0 +1,9 @@ +# -*- shell-script -*- +# Sets PYVERSIONS to be pyenv versions that +# we can use in the python-2.4 branch. + +if [[ $0 == ${BASH_SOURCE[0]} ]] ; then + echo "This script should be *sourced* rather than run directly through bash" + exit 1 +fi +export PYVERSIONS='3.1.5 3.2.6' diff --git a/admin-tools/pyenv-3.3-3.5-versions b/admin-tools/pyenv-3.3-3.5-versions new file mode 100644 index 00000000..5df1ca2a --- /dev/null +++ b/admin-tools/pyenv-3.3-3.5-versions @@ -0,0 +1,8 @@ +# -*- shell-script -*- +# Sets PYVERSIONS to be pyenv versions that +# we can use in the python-3.3-to-3.5 branch. +if [[ $0 == ${BASH_SOURCE[0]} ]] ; then + echo "This script should be *sourced* rather than run directly through bash" + exit 1 +fi +export PYVERSIONS='3.5.10 3.3.7 3.4.10' diff --git a/admin-tools/pyenv-newest-versions b/admin-tools/pyenv-newest-versions index 8e2b4e5d..48ec5e37 100644 --- a/admin-tools/pyenv-newest-versions +++ b/admin-tools/pyenv-newest-versions @@ -5,4 +5,4 @@ if [[ $0 == ${BASH_SOURCE[0]} ]] ; then echo "This script should be *sourced* rather than run directly through bash" exit 1 fi -export PYVERSIONS='3.6.15 3.7.12 pyston-2.3 3.8.11' +export PYVERSIONS='3.6.15 3.7.12 pyston-2.3 3.8.11 3.9.7 3.10.0' diff --git a/admin-tools/pyenv-versions b/admin-tools/pyenv-versions new file mode 100644 index 00000000..dc376826 --- /dev/null +++ b/admin-tools/pyenv-versions @@ -0,0 +1,8 @@ +# -*- shell-script -*- +# Sets PYVERSIONS to be pyenv versions that +# we can use in the master branch. +if [[ $0 == ${BASH_SOURCE[0]} ]] ; then + echo "This script should be *sourced* rather than run directly through bash" + exit 1 +fi +export PYVERSIONS='3.7.10 3.8.10' From 9cf345d446045447e1cc74e0aa89a72044850a1f Mon Sep 17 00:00:00 2001 From: rocky Date: Tue, 26 Oct 2021 19:05:32 -0400 Subject: [PATCH 4/5] Allow running test from 3.9 and 3.10 this does not mean we decompile either of those bytecode though. --- test/Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/Makefile b/test/Makefile index 279f67fb..50af03a7 100644 --- a/test/Makefile +++ b/test/Makefile @@ -77,6 +77,12 @@ check-3.8: check-bytecode $(PYTHON) test_pythonlib.py --bytecode-3.8-run --verify-run $(PYTHON) test_pythonlib.py --bytecode-3.8 --syntax-verify $(COMPILE) +check-3.9: check-bytecode + @echo "Note that we do not support decompiling Python 3.9 bytecode - no 3.9 tests run" + +check-3.10: check-bytecode + @echo "Note that we do not support decompiling Python 3.10 bytecode - no 3.10 tests run" + # FIXME #: this is called when running under pypy3.5-5.8.0, pypy2-5.6.0, or pypy3.6-7.3.0 5.8 5.6: From 32c4b844583719fc71f08cc4b2bd55953696257d Mon Sep 17 00:00:00 2001 From: rocky Date: Thu, 28 Oct 2021 18:37:54 -0400 Subject: [PATCH 5/5] Better handling of bytecode errors --- uncompyle6/bin/uncompile.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/uncompyle6/bin/uncompile.py b/uncompyle6/bin/uncompile.py index 2c21a011..395c5f4e 100755 --- a/uncompyle6/bin/uncompile.py +++ b/uncompyle6/bin/uncompile.py @@ -6,6 +6,7 @@ # from __future__ import print_function import sys, os, getopt, time +from xdis.version_info import version_tuple_to_str program = 'uncompyle6' @@ -76,8 +77,10 @@ def main_bin(): (3, 4), (3, 5), (3, 6), (3, 7), (3, 8), (3, 9), (3, 10) )): - print('Error: %s requires Python 2.4-3.10' % program, - file=sys.stderr) + print( + f"Error: {program} can decompile only bytecode from Python 3.7" + f""" to 3.8.\n\tYou have version: {version_tuple_to_str()}.""" + ) sys.exit(-1) do_verify = recurse_dirs = False @@ -197,6 +200,9 @@ def main_bin(): mess = status_msg(do_verify, *result) print('# ' + mess) pass + except ImportError as e: + print(str(e)) + sys.exit(2) except (KeyboardInterrupt): pass except verify.VerifyCmpError: