You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
need disas.py for cross version Python compiling
fixup MANIFEST.in pythonlib.py: store expected python version and don't compile if it mismatches. Work files now go in temp directory. Start masrhal load in Python for Python3.
This commit is contained in:
@@ -4,14 +4,21 @@
|
||||
from __future__ import print_function
|
||||
|
||||
'''
|
||||
test_pythonlib.py -- uncompyle and verify Python libraries
|
||||
test_pythonlib.py -- compile, uncompyle, and verify Python libraries
|
||||
|
||||
Usage-Examples:
|
||||
|
||||
test_pythonlib.py --all # decompile all tests (suite + libs)
|
||||
test_pythonlib.py --all --verify # decomyile all tests and verify results
|
||||
test_pythonlib.py --test # decompile only the testsuite
|
||||
test_pythonlib.py --2.2 --verify # decompile and verify python lib 2.2
|
||||
# decompile, and verify base set of python 2.7 byte-compiled files
|
||||
test_pythonlib.py --base-2.7 --verify
|
||||
|
||||
# Same as above but compile the base set first
|
||||
test_pythonlib.py --base-2.7 --verify --compile
|
||||
|
||||
# Same as above but use a longer set from the python 2.7 library
|
||||
test_pythonlib.py --ok-2.7 --verify --compile
|
||||
|
||||
# Just deompile the longer set of files
|
||||
test_pythonlib.py --ok-2.7
|
||||
|
||||
Adding own test-trees:
|
||||
|
||||
@@ -24,7 +31,7 @@ Step 2: Run the test:
|
||||
|
||||
import getopt, os, py_compile, sys, shutil, tempfile, time
|
||||
|
||||
from uncompyle6 import main, verify
|
||||
from uncompyle6 import main, verify, PYTHON_VERSION
|
||||
from fnmatch import fnmatch
|
||||
|
||||
def get_srcdir():
|
||||
@@ -33,6 +40,7 @@ def get_srcdir():
|
||||
|
||||
src_dir = get_srcdir()
|
||||
|
||||
|
||||
#----- configure this for your needs
|
||||
|
||||
lib_prefix = [src_dir, '/usr/lib/', '/usr/local/lib/']
|
||||
@@ -45,15 +53,15 @@ PYO = ('*.pyo', )
|
||||
PYOC = ('*.pyc', '*.pyo')
|
||||
|
||||
test_options = {
|
||||
# name: (src_basedir, pattern, output_base_suffix)
|
||||
# name: (src_basedir, pattern, output_base_suffix, pythoin_version)
|
||||
'test': ['test', PYC, 'test'],
|
||||
'2.7': ['python2.7', PYC, 'python2.7'],
|
||||
'2.7': ['python2.7', PYC, 'python2.7', '2.7'],
|
||||
'ok-2.6': [os.path.join(src_dir, 'ok_2.6'),
|
||||
PYC, 'ok-2.6'],
|
||||
PYC, 'ok-2.6', '2.6'],
|
||||
'ok-2.7': [os.path.join(src_dir, 'ok_2.7'),
|
||||
PYC, 'ok-2.7'],
|
||||
PYC, 'ok-2.7', '2.7'],
|
||||
'base-2.7': [os.path.join(src_dir, 'base-tests', 'python2.7'),
|
||||
PYC, 'base_2.7'],
|
||||
PYC, 'base_2.7', '2.7'],
|
||||
}
|
||||
|
||||
#-----
|
||||
@@ -83,23 +91,39 @@ def do_tests(src_dir, obj_patterns, target_dir, opts):
|
||||
if fnmatch(n, pat)])
|
||||
|
||||
files = []
|
||||
# Change directories so use relative rather than
|
||||
# absolute paths. This speeds up things, and allows
|
||||
# main() to write to a relative-path destination.
|
||||
cwd = os.getcwd()
|
||||
os.chdir(src_dir)
|
||||
|
||||
if opts['do_compile']:
|
||||
for root, dirs, basenames in os.walk(src_dir):
|
||||
file_matches(files, root, basenames, PY)
|
||||
for sfile in files:
|
||||
py_compile.compile(sfile)
|
||||
compiled_version = opts['compiled_version']
|
||||
if compiled_version and PYTHON_VERSION != compiled_version:
|
||||
print("Not compiling: desired Python version is %s but we are running %s" %
|
||||
(compiled_version, PYTHON_VERSION), file=sys.stderr)
|
||||
else:
|
||||
for root, dirs, basenames in os.walk(src_dir):
|
||||
file_matches(files, root, basenames, PY)
|
||||
for sfile in files:
|
||||
py_compile.compile(sfile)
|
||||
pass
|
||||
pass
|
||||
files = []
|
||||
pass
|
||||
files = []
|
||||
pass
|
||||
|
||||
for root, dirs, basenames in os.walk(src_dir):
|
||||
file_matches(files, root, basenames, obj_patterns)
|
||||
# Turn root into a relative path
|
||||
dirname = root[len(src_dir)+1:]
|
||||
file_matches(files, dirname, basenames, obj_patterns)
|
||||
|
||||
if not files:
|
||||
print("Didn't come up with any files to test! Try with --compile?",
|
||||
file=sys.stderr)
|
||||
exit(1)
|
||||
|
||||
os.chdir(cwd)
|
||||
files.sort()
|
||||
|
||||
if opts['start_with']:
|
||||
@@ -154,19 +178,26 @@ if __name__ == '__main__':
|
||||
pass
|
||||
pass
|
||||
|
||||
for src_dir, pattern, target_dir in test_dirs:
|
||||
last_compile_version = None
|
||||
for src_dir, pattern, target_dir, compiled_version in test_dirs:
|
||||
if os.path.isdir(src_dir):
|
||||
checked_dirs.append([src_dir, pattern, target_dir])
|
||||
else:
|
||||
print("Can't find directory %s. Skipping" % src_dir,
|
||||
file=sys.stderr)
|
||||
pass
|
||||
continue
|
||||
if last_compile_version and last_compile_version != compile_version:
|
||||
print("Warning: mixed python version decompylation")
|
||||
else:
|
||||
last_compile_version = compiled_version
|
||||
pass
|
||||
|
||||
if not checked_dirs:
|
||||
print("No directories found to check", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
test_opts['compiled_version'] = last_compile_version
|
||||
|
||||
for src_dir, pattern, target_dir in checked_dirs:
|
||||
target_dir = os.path.join(target_base, target_dir)
|
||||
if os.path.exists(target_dir):
|
||||
|
Reference in New Issue
Block a user