You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Use black to reformat some files
This commit is contained in:
@@ -28,64 +28,77 @@ from fnmatch import fnmatch
|
|||||||
from uncompyle6 import main, PYTHON3
|
from uncompyle6 import main, PYTHON3
|
||||||
import xdis.magics as magics
|
import xdis.magics as magics
|
||||||
|
|
||||||
#----- configure this for your needs
|
# ----- configure this for your needs
|
||||||
|
|
||||||
python_versions = [v for v in magics.python_versions if
|
python_versions = [v for v in magics.python_versions if re.match("^[0-9.]+$", v)]
|
||||||
re.match('^[0-9.]+$', v)]
|
|
||||||
|
|
||||||
# FIXME: we should remove Python versions that we don't support.
|
# FIXME: we should remove Python versions that we don't support.
|
||||||
# These include Jython, and Python bytecode changes pre release.
|
# These include Jython, and Python bytecode changes pre release.
|
||||||
|
|
||||||
TEST_VERSIONS = (
|
TEST_VERSIONS = (
|
||||||
'pypy3-2.4.0', 'pypy-2.6.1',
|
"pypy3-2.4.0",
|
||||||
'pypy-5.0.1', 'pypy-5.3.1', 'pypy3.5-5.7.1-beta',
|
"pypy-2.6.1",
|
||||||
'pypy3.5-5.9.0', 'pypy3.5-6.0.0',
|
"pypy-5.0.1",
|
||||||
'native') + tuple(python_versions)
|
"pypy-5.3.1",
|
||||||
|
"pypy3.5-5.7.1-beta",
|
||||||
|
"pypy3.5-5.9.0",
|
||||||
|
"pypy3.5-6.0.0",
|
||||||
|
"native",
|
||||||
|
) + tuple(python_versions)
|
||||||
|
|
||||||
|
|
||||||
target_base = '/tmp/py-dis/'
|
target_base = "/tmp/py-dis/"
|
||||||
lib_prefix = os.path.join(os.environ['HOME'], '.pyenv/versions')
|
lib_prefix = os.path.join(os.environ["HOME"], ".pyenv/versions")
|
||||||
|
|
||||||
PYC = ('*.pyc', )
|
PYC = ("*.pyc",)
|
||||||
PYO = ('*.pyo', )
|
PYO = ("*.pyo",)
|
||||||
PYOC = ('*.pyc', '*.pyo')
|
PYOC = ("*.pyc", "*.pyo")
|
||||||
|
|
||||||
#-----
|
# -----
|
||||||
|
|
||||||
test_options = {
|
test_options = {
|
||||||
# name: (src_basedir, pattern, output_base_suffix)
|
# name: (src_basedir, pattern, output_base_suffix)
|
||||||
'test': ('./test', PYOC, 'test'),
|
"test": ("./test", PYOC, "test"),
|
||||||
'max=': 200,
|
"max=": 200,
|
||||||
}
|
}
|
||||||
|
|
||||||
for vers in TEST_VERSIONS:
|
for vers in TEST_VERSIONS:
|
||||||
if vers.startswith('pypy'):
|
if vers.startswith("pypy"):
|
||||||
if vers.startswith('pypy3.'):
|
if vers.startswith("pypy3."):
|
||||||
short_vers = vers[4:6]
|
short_vers = vers[4:6]
|
||||||
else:
|
else:
|
||||||
short_vers = vers[0:-2]
|
short_vers = vers[0:-2]
|
||||||
|
|
||||||
test_options[vers] = (os.path.join(lib_prefix, vers, 'lib_pypy'),
|
test_options[vers] = (
|
||||||
PYC, 'python-lib'+short_vers)
|
os.path.join(lib_prefix, vers, "lib_pypy"),
|
||||||
|
PYC,
|
||||||
|
"python-lib" + short_vers,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
if vers == 'native':
|
if vers == "native":
|
||||||
short_vers = os.path.basename(sys.path[-1])
|
short_vers = os.path.basename(sys.path[-1])
|
||||||
test_options[vers] = (sys.path[-1],
|
test_options[vers] = (sys.path[-1], PYC, short_vers)
|
||||||
PYC, short_vers)
|
|
||||||
else:
|
else:
|
||||||
short_vers = vers[:3]
|
short_vers = vers[:3]
|
||||||
test_options[vers] = (os.path.join(lib_prefix, vers, 'lib', 'python'+short_vers),
|
test_options[vers] = (
|
||||||
PYC, 'python-lib'+short_vers)
|
os.path.join(lib_prefix, vers, "lib", "python" + short_vers),
|
||||||
|
PYC,
|
||||||
|
"python-lib" + short_vers,
|
||||||
|
)
|
||||||
|
|
||||||
def do_tests(src_dir, patterns, target_dir, start_with=None,
|
|
||||||
do_verify=False, max_files=200):
|
|
||||||
|
|
||||||
|
def do_tests(
|
||||||
|
src_dir, patterns, target_dir, start_with=None, do_verify=False, max_files=200
|
||||||
|
):
|
||||||
def visitor(files, dirname, names):
|
def visitor(files, dirname, names):
|
||||||
files.extend(
|
files.extend(
|
||||||
[os.path.normpath(os.path.join(dirname, n))
|
[
|
||||||
for n in names
|
os.path.normpath(os.path.join(dirname, n))
|
||||||
for pat in patterns
|
for n in names
|
||||||
if fnmatch(n, pat)])
|
for pat in patterns
|
||||||
|
if fnmatch(n, pat)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
files = []
|
files = []
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
@@ -93,10 +106,13 @@ def do_tests(src_dir, patterns, target_dir, start_with=None,
|
|||||||
if PYTHON3:
|
if PYTHON3:
|
||||||
for root, dirname, names in os.walk(os.curdir):
|
for root, dirname, names in os.walk(os.curdir):
|
||||||
files.extend(
|
files.extend(
|
||||||
[os.path.normpath(os.path.join(root, n))
|
[
|
||||||
for n in names
|
os.path.normpath(os.path.join(root, n))
|
||||||
for pat in patterns
|
for n in names
|
||||||
if fnmatch(n, pat)])
|
for pat in patterns
|
||||||
|
if fnmatch(n, pat)
|
||||||
|
]
|
||||||
|
)
|
||||||
pass
|
pass
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
@@ -108,26 +124,29 @@ def do_tests(src_dir, patterns, target_dir, start_with=None,
|
|||||||
try:
|
try:
|
||||||
start_with = files.index(start_with)
|
start_with = files.index(start_with)
|
||||||
files = files[start_with:]
|
files = files[start_with:]
|
||||||
print('>>> starting with file', files[0])
|
print(">>> starting with file", files[0])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if len(files) > max_files:
|
if len(files) > max_files:
|
||||||
files = [file for file in files if not 'site-packages' in file]
|
files = [file for file in files if not "site-packages" in file]
|
||||||
files = [file for file in files if not 'test' in file]
|
files = [file for file in files if not "test" in file]
|
||||||
if len(files) > max_files:
|
if len(files) > max_files:
|
||||||
# print("Number of files %d - truncating to last 200" % len(files))
|
# print("Number of files %d - truncating to last 200" % len(files))
|
||||||
print("Number of files %d - truncating to first %s" %
|
print(
|
||||||
(len(files), max_files))
|
"Number of files %d - truncating to first %s" % (len(files), max_files)
|
||||||
|
)
|
||||||
files = files[:max_files]
|
files = files[:max_files]
|
||||||
|
|
||||||
print(time.ctime())
|
print(time.ctime())
|
||||||
(tot_files, okay_files, failed_files,
|
(tot_files, okay_files, failed_files, verify_failed_files) = main.main(
|
||||||
verify_failed_files) = main.main(src_dir, target_dir, files, [], do_verify=do_verify)
|
src_dir, target_dir, files, [], do_verify=do_verify
|
||||||
|
)
|
||||||
print(time.ctime())
|
print(time.ctime())
|
||||||
return verify_failed_files + failed_files
|
return verify_failed_files + failed_files
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
if __name__ == "__main__":
|
||||||
import getopt, sys
|
import getopt, sys
|
||||||
|
|
||||||
do_coverage = do_verify = False
|
do_coverage = do_verify = False
|
||||||
@@ -136,38 +155,46 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
test_options_keys = list(test_options.keys())
|
test_options_keys = list(test_options.keys())
|
||||||
test_options_keys.sort()
|
test_options_keys.sort()
|
||||||
opts, args = getopt.getopt(sys.argv[1:], '',
|
opts, args = getopt.getopt(
|
||||||
['start-with=', 'verify', 'verify-run', 'syntax-verify',
|
sys.argv[1:],
|
||||||
'max=', 'coverage', 'all', ] \
|
"",
|
||||||
+ test_options_keys )
|
[
|
||||||
vers = ''
|
"start-with=",
|
||||||
|
"verify",
|
||||||
|
"verify-run",
|
||||||
|
"syntax-verify",
|
||||||
|
"max=",
|
||||||
|
"coverage",
|
||||||
|
"all",
|
||||||
|
]
|
||||||
|
+ test_options_keys,
|
||||||
|
)
|
||||||
|
vers = ""
|
||||||
|
|
||||||
for opt, val in opts:
|
for opt, val in opts:
|
||||||
if opt == '--verify':
|
if opt == "--verify":
|
||||||
do_verify = 'strong'
|
do_verify = "strong"
|
||||||
elif opt == '--syntax-verify':
|
elif opt == "--syntax-verify":
|
||||||
do_verify = 'weak'
|
do_verify = "weak"
|
||||||
elif opt == '--verify-run':
|
elif opt == "--verify-run":
|
||||||
do_verify = 'verify-run'
|
do_verify = "verify-run"
|
||||||
elif opt == '--coverage':
|
elif opt == "--coverage":
|
||||||
do_coverage = True
|
do_coverage = True
|
||||||
elif opt == '--start-with':
|
elif opt == "--start-with":
|
||||||
start_with = val
|
start_with = val
|
||||||
elif opt[2:] in test_options_keys:
|
elif opt[2:] in test_options_keys:
|
||||||
triple = test_options[opt[2:]]
|
triple = test_options[opt[2:]]
|
||||||
vers = triple[-1]
|
vers = triple[-1]
|
||||||
test_dirs.append(triple)
|
test_dirs.append(triple)
|
||||||
elif opt == '--max':
|
elif opt == "--max":
|
||||||
test_options['max='] = int(val)
|
test_options["max="] = int(val)
|
||||||
elif opt == '--all':
|
elif opt == "--all":
|
||||||
vers = 'all'
|
vers = "all"
|
||||||
for val in test_options_keys:
|
for val in test_options_keys:
|
||||||
test_dirs.append(test_options[val])
|
test_dirs.append(test_options[val])
|
||||||
|
|
||||||
if do_coverage:
|
if do_coverage:
|
||||||
os.environ['SPARK_PARSER_COVERAGE'] = (
|
os.environ["SPARK_PARSER_COVERAGE"] = "/tmp/spark-grammar-%s.cover" % vers
|
||||||
'/tmp/spark-grammar-%s.cover' % vers
|
|
||||||
)
|
|
||||||
|
|
||||||
failed = 0
|
failed = 0
|
||||||
for src_dir, pattern, target_dir in test_dirs:
|
for src_dir, pattern, target_dir in test_dirs:
|
||||||
@@ -175,8 +202,14 @@ if __name__ == '__main__':
|
|||||||
target_dir = os.path.join(target_base, target_dir)
|
target_dir = os.path.join(target_base, target_dir)
|
||||||
if os.path.exists(target_dir):
|
if os.path.exists(target_dir):
|
||||||
shutil.rmtree(target_dir, ignore_errors=1)
|
shutil.rmtree(target_dir, ignore_errors=1)
|
||||||
failed += do_tests(src_dir, pattern, target_dir, start_with,
|
failed += do_tests(
|
||||||
do_verify, test_options['max='])
|
src_dir,
|
||||||
|
pattern,
|
||||||
|
target_dir,
|
||||||
|
start_with,
|
||||||
|
do_verify,
|
||||||
|
test_options["max="],
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
print("### Path %s doesn't exist; skipping" % src_dir)
|
print("### Path %s doesn't exist; skipping" % src_dir)
|
||||||
pass
|
pass
|
||||||
|
@@ -35,69 +35,89 @@ from uncompyle6 import PYTHON_VERSION
|
|||||||
from uncompyle6.main import main
|
from uncompyle6.main import main
|
||||||
from fnmatch import fnmatch
|
from fnmatch import fnmatch
|
||||||
|
|
||||||
|
|
||||||
def get_srcdir():
|
def get_srcdir():
|
||||||
filename = os.path.normcase(os.path.dirname(__file__))
|
filename = os.path.normcase(os.path.dirname(__file__))
|
||||||
return os.path.realpath(filename)
|
return os.path.realpath(filename)
|
||||||
|
|
||||||
|
|
||||||
src_dir = get_srcdir()
|
src_dir = get_srcdir()
|
||||||
|
|
||||||
|
|
||||||
#----- configure this for your needs
|
# ----- configure this for your needs
|
||||||
|
|
||||||
lib_prefix = '/usr/lib'
|
lib_prefix = "/usr/lib"
|
||||||
#lib_prefix = [src_dir, '/usr/lib/', '/usr/local/lib/']
|
# lib_prefix = [src_dir, '/usr/lib/', '/usr/local/lib/']
|
||||||
|
|
||||||
target_base = tempfile.mkdtemp(prefix='py-dis-')
|
target_base = tempfile.mkdtemp(prefix="py-dis-")
|
||||||
|
|
||||||
PY = ('*.py', )
|
PY = ("*.py",)
|
||||||
PYC = ('*.pyc', )
|
PYC = ("*.pyc",)
|
||||||
PYO = ('*.pyo', )
|
PYO = ("*.pyo",)
|
||||||
PYOC = ('*.pyc', '*.pyo')
|
PYOC = ("*.pyc", "*.pyo")
|
||||||
|
|
||||||
test_options = {
|
test_options = {
|
||||||
# name: (src_basedir, pattern, output_base_suffix, python_version)
|
# name: (src_basedir, pattern, output_base_suffix, python_version)
|
||||||
'test':
|
"test": ("test", PYC, "test"),
|
||||||
('test', PYC, 'test'),
|
"ok-2.6": (os.path.join(src_dir, "ok_lib2.6"), PYOC, "ok-2.6", 2.6),
|
||||||
|
"ok-2.7": (os.path.join(src_dir, "ok_lib2.7"), PYOC, "ok-2.7", 2.7),
|
||||||
'ok-2.6': (os.path.join(src_dir, 'ok_lib2.6'),
|
"ok-3.2": (os.path.join(src_dir, "ok_lib3.2"), PYOC, "ok-3.2", 3.2),
|
||||||
PYOC, 'ok-2.6', 2.6),
|
"base-2.7": (
|
||||||
|
os.path.join(src_dir, "base_tests", "python2.7"),
|
||||||
'ok-2.7': (os.path.join(src_dir, 'ok_lib2.7'),
|
PYOC,
|
||||||
PYOC, 'ok-2.7', 2.7),
|
"base_2.7",
|
||||||
|
2.7,
|
||||||
'ok-3.2': (os.path.join(src_dir, 'ok_lib3.2'),
|
),
|
||||||
PYOC, 'ok-3.2', 3.2),
|
|
||||||
|
|
||||||
'base-2.7': (os.path.join(src_dir, 'base_tests', 'python2.7'),
|
|
||||||
PYOC, 'base_2.7', 2.7),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for vers in (2.7, 3.4, 3.5, 3.6):
|
for vers in (2.7, 3.4, 3.5, 3.6):
|
||||||
pythonlib = "ok_lib%s" % vers
|
pythonlib = "ok_lib%s" % vers
|
||||||
key = "ok-%s" % vers
|
key = "ok-%s" % vers
|
||||||
test_options[key] = (os.path.join(src_dir, pythonlib), PYOC, key, vers)
|
test_options[key] = (os.path.join(src_dir, pythonlib), PYOC, key, vers)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
for vers in (1.3, 1.4, 1.5,
|
for vers in (
|
||||||
2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7,
|
1.3,
|
||||||
3.0, 3.1, 3.2, 3.3,
|
1.4,
|
||||||
3.4, 3.5, 3.6, 3.7, 3.8, 'pypy3.2', 'pypy2.7', 'pypy3.6'):
|
1.5,
|
||||||
|
2.1,
|
||||||
|
2.2,
|
||||||
|
2.3,
|
||||||
|
2.4,
|
||||||
|
2.5,
|
||||||
|
2.6,
|
||||||
|
2.7,
|
||||||
|
3.0,
|
||||||
|
3.1,
|
||||||
|
3.2,
|
||||||
|
3.3,
|
||||||
|
3.4,
|
||||||
|
3.5,
|
||||||
|
3.6,
|
||||||
|
3.7,
|
||||||
|
3.8,
|
||||||
|
"pypy3.2",
|
||||||
|
"pypy2.7",
|
||||||
|
"pypy3.6",
|
||||||
|
):
|
||||||
bytecode = "bytecode_%s" % vers
|
bytecode = "bytecode_%s" % vers
|
||||||
key = "bytecode-%s" % vers
|
key = "bytecode-%s" % vers
|
||||||
test_options[key] = (bytecode, PYC, bytecode, vers)
|
test_options[key] = (bytecode, PYC, bytecode, vers)
|
||||||
bytecode = "bytecode_%s_run" % vers
|
bytecode = "bytecode_%s_run" % vers
|
||||||
key = "bytecode-%s-run" % vers
|
key = "bytecode-%s-run" % vers
|
||||||
test_options[key] = (bytecode, PYC, bytecode, vers)
|
test_options[key] = (bytecode, PYC, bytecode, vers)
|
||||||
key = "%s" % vers
|
key = "%s" % vers
|
||||||
pythonlib = "python%s" % vers
|
pythonlib = "python%s" % vers
|
||||||
if isinstance(vers, float) and vers >= 3.0:
|
if isinstance(vers, float) and vers >= 3.0:
|
||||||
pythonlib = os.path.join(pythonlib, '__pycache__')
|
pythonlib = os.path.join(pythonlib, "__pycache__")
|
||||||
test_options[key] = (os.path.join(lib_prefix, pythonlib), PYOC, pythonlib, vers)
|
test_options[key] = (os.path.join(lib_prefix, pythonlib), PYOC, pythonlib, vers)
|
||||||
|
|
||||||
|
# -----
|
||||||
|
|
||||||
#-----
|
|
||||||
|
|
||||||
def help():
|
def help():
|
||||||
print("""Usage-Examples:
|
print(
|
||||||
|
"""Usage-Examples:
|
||||||
|
|
||||||
# compile, decompyle and verify short tests for Python 2.7:
|
# compile, decompyle and verify short tests for Python 2.7:
|
||||||
test_pythonlib.py --bytecode-2.7 --verify --compile
|
test_pythonlib.py --bytecode-2.7 --verify --compile
|
||||||
@@ -107,18 +127,21 @@ def help():
|
|||||||
|
|
||||||
# decompile and verify known good python 2.7
|
# decompile and verify known good python 2.7
|
||||||
test_pythonlib.py --ok-2.7 --verify
|
test_pythonlib.py --ok-2.7 --verify
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def do_tests(src_dir, obj_patterns, target_dir, opts):
|
def do_tests(src_dir, obj_patterns, target_dir, opts):
|
||||||
|
|
||||||
def file_matches(files, root, basenames, patterns):
|
def file_matches(files, root, basenames, patterns):
|
||||||
files.extend(
|
files.extend(
|
||||||
[os.path.normpath(os.path.join(root, n))
|
[
|
||||||
for n in basenames
|
os.path.normpath(os.path.join(root, n))
|
||||||
for pat in patterns
|
for n in basenames
|
||||||
if fnmatch(n, pat)])
|
for pat in patterns
|
||||||
|
if fnmatch(n, pat)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
files = []
|
files = []
|
||||||
# Change directories so use relative rather than
|
# Change directories so use relative rather than
|
||||||
@@ -127,11 +150,14 @@ def do_tests(src_dir, obj_patterns, target_dir, opts):
|
|||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
os.chdir(src_dir)
|
os.chdir(src_dir)
|
||||||
|
|
||||||
if opts['do_compile']:
|
if opts["do_compile"]:
|
||||||
compiled_version = opts['compiled_version']
|
compiled_version = opts["compiled_version"]
|
||||||
if compiled_version and PYTHON_VERSION != compiled_version:
|
if compiled_version and PYTHON_VERSION != compiled_version:
|
||||||
print("Not compiling: desired Python version is %s but we are running %s" %
|
print(
|
||||||
(compiled_version, PYTHON_VERSION), file=sys.stderr)
|
"Not compiling: desired Python version is %s but we are running %s"
|
||||||
|
% (compiled_version, PYTHON_VERSION),
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
for root, dirs, basenames in os.walk(src_dir):
|
for root, dirs, basenames in os.walk(src_dir):
|
||||||
file_matches(files, root, basenames, PY)
|
file_matches(files, root, basenames, PY)
|
||||||
@@ -143,34 +169,36 @@ def do_tests(src_dir, obj_patterns, target_dir, opts):
|
|||||||
pass
|
pass
|
||||||
pass
|
pass
|
||||||
|
|
||||||
for root, dirs, basenames in os.walk('.'):
|
for root, dirs, basenames in os.walk("."):
|
||||||
# Turn root into a relative path
|
# Turn root into a relative path
|
||||||
dirname = root[2:] # 2 = len('.') + 1
|
dirname = root[2:] # 2 = len('.') + 1
|
||||||
file_matches(files, dirname, basenames, obj_patterns)
|
file_matches(files, dirname, basenames, obj_patterns)
|
||||||
|
|
||||||
if not files:
|
if not files:
|
||||||
print("Didn't come up with any files to test! Try with --compile?",
|
print(
|
||||||
file=sys.stderr)
|
"Didn't come up with any files to test! Try with --compile?",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
os.chdir(cwd)
|
os.chdir(cwd)
|
||||||
files.sort()
|
files.sort()
|
||||||
|
|
||||||
if opts['start_with']:
|
if opts["start_with"]:
|
||||||
try:
|
try:
|
||||||
start_with = files.index(opts['start_with'])
|
start_with = files.index(opts["start_with"])
|
||||||
files = files[start_with:]
|
files = files[start_with:]
|
||||||
print('>>> starting with file', files[0])
|
print(">>> starting with file", files[0])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
print(time.ctime())
|
print(time.ctime())
|
||||||
print('Source directory: ', src_dir)
|
print("Source directory: ", src_dir)
|
||||||
print('Output directory: ', target_dir)
|
print("Output directory: ", target_dir)
|
||||||
try:
|
try:
|
||||||
_, _, failed_files, failed_verify = \
|
_, _, failed_files, failed_verify = main(
|
||||||
main(src_dir, target_dir, files, [],
|
src_dir, target_dir, files, [], do_verify=opts["do_verify"]
|
||||||
do_verify=opts['do_verify'])
|
)
|
||||||
if failed_files != 0:
|
if failed_files != 0:
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
elif failed_verify != 0:
|
elif failed_verify != 0:
|
||||||
@@ -179,71 +207,81 @@ def do_tests(src_dir, obj_patterns, target_dir, opts):
|
|||||||
except (KeyboardInterrupt, OSError):
|
except (KeyboardInterrupt, OSError):
|
||||||
print()
|
print()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if test_opts['rmtree']:
|
if test_opts["rmtree"]:
|
||||||
parent_dir = os.path.dirname(target_dir)
|
parent_dir = os.path.dirname(target_dir)
|
||||||
print("Everything good, removing %s" % parent_dir)
|
print("Everything good, removing %s" % parent_dir)
|
||||||
shutil.rmtree(parent_dir)
|
shutil.rmtree(parent_dir)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
if __name__ == "__main__":
|
||||||
test_dirs = []
|
test_dirs = []
|
||||||
checked_dirs = []
|
checked_dirs = []
|
||||||
start_with = None
|
start_with = None
|
||||||
|
|
||||||
test_options_keys = list(test_options.keys())
|
test_options_keys = list(test_options.keys())
|
||||||
test_options_keys.sort()
|
test_options_keys.sort()
|
||||||
opts, args = getopt.getopt(sys.argv[1:], '',
|
opts, args = getopt.getopt(
|
||||||
['start-with=', 'verify', 'verify-run',
|
sys.argv[1:],
|
||||||
'syntax-verify', 'all',
|
"",
|
||||||
'compile', 'coverage',
|
[
|
||||||
'no-rm'] \
|
"start-with=",
|
||||||
+ test_options_keys )
|
"verify",
|
||||||
if not opts: help()
|
"verify-run",
|
||||||
|
"syntax-verify",
|
||||||
|
"all",
|
||||||
|
"compile",
|
||||||
|
"coverage",
|
||||||
|
"no-rm",
|
||||||
|
]
|
||||||
|
+ test_options_keys,
|
||||||
|
)
|
||||||
|
if not opts:
|
||||||
|
help()
|
||||||
|
|
||||||
test_opts = {
|
test_opts = {
|
||||||
'do_compile': False,
|
"do_compile": False,
|
||||||
'do_verify': False,
|
"do_verify": False,
|
||||||
'start_with': None,
|
"start_with": None,
|
||||||
'rmtree' : True,
|
"rmtree": True,
|
||||||
'coverage' : False
|
"coverage": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
for opt, val in opts:
|
for opt, val in opts:
|
||||||
if opt == '--verify':
|
if opt == "--verify":
|
||||||
test_opts['do_verify'] = 'strong'
|
test_opts["do_verify"] = "strong"
|
||||||
elif opt == '--syntax-verify':
|
elif opt == "--syntax-verify":
|
||||||
test_opts['do_verify'] = 'weak'
|
test_opts["do_verify"] = "weak"
|
||||||
elif opt == '--verify-run':
|
elif opt == "--verify-run":
|
||||||
test_opts['do_verify'] = 'verify-run'
|
test_opts["do_verify"] = "verify-run"
|
||||||
elif opt == '--compile':
|
elif opt == "--compile":
|
||||||
test_opts['do_compile'] = True
|
test_opts["do_compile"] = True
|
||||||
elif opt == '--start-with':
|
elif opt == "--start-with":
|
||||||
test_opts['start_with'] = val
|
test_opts["start_with"] = val
|
||||||
elif opt == '--no-rm':
|
elif opt == "--no-rm":
|
||||||
test_opts['rmtree'] = False
|
test_opts["rmtree"] = False
|
||||||
elif opt[2:] in test_options_keys:
|
elif opt[2:] in test_options_keys:
|
||||||
test_dirs.append(test_options[opt[2:]])
|
test_dirs.append(test_options[opt[2:]])
|
||||||
elif opt == '--all':
|
elif opt == "--all":
|
||||||
for val in test_options_keys:
|
for val in test_options_keys:
|
||||||
test_dirs.append(test_options[val])
|
test_dirs.append(test_options[val])
|
||||||
elif opt == '--coverage':
|
elif opt == "--coverage":
|
||||||
test_opts['coverage'] = True
|
test_opts["coverage"] = True
|
||||||
else:
|
else:
|
||||||
help()
|
help()
|
||||||
pass
|
pass
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if test_opts['coverage']:
|
if test_opts["coverage"]:
|
||||||
os.environ['SPARK_PARSER_COVERAGE'] = (
|
os.environ["SPARK_PARSER_COVERAGE"] = (
|
||||||
'/tmp/spark-grammar-python-lib%s.cover' % test_dirs[0][-1]
|
"/tmp/spark-grammar-python-lib%s.cover" % test_dirs[0][-1]
|
||||||
)
|
)
|
||||||
|
|
||||||
last_compile_version = None
|
last_compile_version = None
|
||||||
for src_dir, pattern, target_dir, compiled_version in test_dirs:
|
for src_dir, pattern, target_dir, compiled_version in test_dirs:
|
||||||
if os.path.isdir(src_dir):
|
if os.path.isdir(src_dir):
|
||||||
checked_dirs.append([src_dir, pattern, target_dir])
|
checked_dirs.append([src_dir, pattern, target_dir])
|
||||||
else:
|
else:
|
||||||
print("Can't find directory %s. Skipping" % src_dir,
|
print("Can't find directory %s. Skipping" % src_dir, file=sys.stderr)
|
||||||
file=sys.stderr)
|
|
||||||
continue
|
continue
|
||||||
last_compile_version = compiled_version
|
last_compile_version = compiled_version
|
||||||
pass
|
pass
|
||||||
@@ -252,7 +290,7 @@ if __name__ == '__main__':
|
|||||||
print("No directories found to check", file=sys.stderr)
|
print("No directories found to check", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
test_opts['compiled_version'] = last_compile_version
|
test_opts["compiled_version"] = last_compile_version
|
||||||
|
|
||||||
for src_dir, pattern, target_dir in checked_dirs:
|
for src_dir, pattern, target_dir in checked_dirs:
|
||||||
target_dir = os.path.join(target_base, target_dir)
|
target_dir = os.path.join(target_base, target_dir)
|
||||||
|
@@ -16,122 +16,152 @@
|
|||||||
"""Isolate Python version-specific semantic actions here.
|
"""Isolate Python version-specific semantic actions here.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from uncompyle6.semantics.consts import (
|
from uncompyle6.semantics.consts import TABLE_R, TABLE_DIRECT
|
||||||
TABLE_R, TABLE_DIRECT)
|
|
||||||
|
|
||||||
from uncompyle6.parsers.treenode import SyntaxTree
|
from uncompyle6.parsers.treenode import SyntaxTree
|
||||||
from uncompyle6.scanners.tok import Token
|
from uncompyle6.scanners.tok import Token
|
||||||
|
|
||||||
|
|
||||||
def customize_for_version(self, is_pypy, version):
|
def customize_for_version(self, is_pypy, version):
|
||||||
if is_pypy:
|
if is_pypy:
|
||||||
########################
|
########################
|
||||||
# PyPy changes
|
# PyPy changes
|
||||||
#######################
|
#######################
|
||||||
TABLE_DIRECT.update({
|
TABLE_DIRECT.update(
|
||||||
'assert_pypy': ( '%|assert %c\n' , 1 ),
|
{
|
||||||
'assert2_pypy': ( '%|assert %c, %c\n' , 1, 4 ),
|
"assert2_pypy": ("%|assert %c, %c\n", (1, "assert_expr"), 4),
|
||||||
'try_except_pypy': ( '%|try:\n%+%c%-%c\n\n', 1, 2 ),
|
"assert_pypy": ("%|assert %c\n", (1, "assert_expr")),
|
||||||
'tryfinallystmt_pypy': ( '%|try:\n%+%c%-%|finally:\n%+%c%-\n\n', 1, 3 ),
|
"assign2_pypy": ("%|%c, %c = %c, %c\n", 3, 2, 0, 1),
|
||||||
'assign3_pypy': ( '%|%c, %c, %c = %c, %c, %c\n', 5, 4, 3, 0, 1, 2 ),
|
"assign3_pypy": ("%|%c, %c, %c = %c, %c, %c\n", 5, 4, 3, 0, 1, 2),
|
||||||
'assign2_pypy': ( '%|%c, %c = %c, %c\n', 3, 2, 0, 1),
|
"try_except_pypy": ("%|try:\n%+%c%-%c\n\n", 1, 2),
|
||||||
})
|
"tryfinallystmt_pypy": ("%|try:\n%+%c%-%|finally:\n%+%c%-\n\n", 1, 3),
|
||||||
|
}
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
########################
|
########################
|
||||||
# Without PyPy
|
# Without PyPy
|
||||||
#######################
|
#######################
|
||||||
TABLE_DIRECT.update({
|
TABLE_DIRECT.update(
|
||||||
'assert': ( '%|assert %c\n' , 0 ),
|
{
|
||||||
'assert2': ( '%|assert %c, %c\n' , 0, 3 ),
|
"assert": ("%|assert %c\n", (0, "assert_expr")),
|
||||||
'try_except': ( '%|try:\n%+%c%-%c\n\n', 1, 3 ),
|
"assert2": ("%|assert %c, %c\n", (0, "assert_expr"), 3),
|
||||||
'assign2': ( '%|%c, %c = %c, %c\n',
|
"assign2": ("%|%c, %c = %c, %c\n", 3, 4, 0, 1),
|
||||||
3, 4, 0, 1 ),
|
"assign3": ("%|%c, %c, %c = %c, %c, %c\n", 5, 6, 7, 0, 1, 2),
|
||||||
'assign3': ( '%|%c, %c, %c = %c, %c, %c\n',
|
"try_except": ("%|try:\n%+%c%-%c\n\n", 1, 3),
|
||||||
5, 6, 7, 0, 1, 2 ),
|
}
|
||||||
})
|
)
|
||||||
if version >= 3.0:
|
if version >= 3.0:
|
||||||
if version >= 3.2:
|
if version >= 3.2:
|
||||||
TABLE_DIRECT.update({
|
TABLE_DIRECT.update(
|
||||||
'del_deref_stmt': ( '%|del %c\n', 0),
|
{"del_deref_stmt": ("%|del %c\n", 0), "DELETE_DEREF": ("%{pattr}", 0)}
|
||||||
'DELETE_DEREF': ( '%{pattr}', 0 ),
|
)
|
||||||
})
|
|
||||||
from uncompyle6.semantics.customize3 import customize_for_version3
|
from uncompyle6.semantics.customize3 import customize_for_version3
|
||||||
|
|
||||||
customize_for_version3(self, version)
|
customize_for_version3(self, version)
|
||||||
else: # < 3.0
|
else: # < 3.0
|
||||||
TABLE_DIRECT.update({
|
TABLE_DIRECT.update(
|
||||||
'except_cond3' : ( '%|except %c, %c:\n',
|
{"except_cond3": ("%|except %c, %c:\n", (1, "expr"), (-2, "store"))}
|
||||||
(1, 'expr'), (-2, 'store') )
|
)
|
||||||
})
|
|
||||||
if 2.4 <= version <= 2.6:
|
if 2.4 <= version <= 2.6:
|
||||||
TABLE_DIRECT.update({
|
TABLE_DIRECT.update({"comp_for": (" for %c in %c", 3, 1)})
|
||||||
'comp_for': ( ' for %c in %c', 3, 1 ),
|
|
||||||
})
|
|
||||||
else:
|
else:
|
||||||
TABLE_DIRECT.update({
|
TABLE_DIRECT.update({"comp_for": (" for %c in %c%c", 2, 0, 3)})
|
||||||
'comp_for': ( ' for %c in %c%c', 2, 0, 3 ),
|
|
||||||
})
|
|
||||||
|
|
||||||
if version >= 2.5:
|
if version >= 2.5:
|
||||||
from uncompyle6.semantics.customize25 import customize_for_version25
|
from uncompyle6.semantics.customize25 import customize_for_version25
|
||||||
|
|
||||||
customize_for_version25(self, version)
|
customize_for_version25(self, version)
|
||||||
|
|
||||||
if version >= 2.6:
|
if version >= 2.6:
|
||||||
from uncompyle6.semantics.customize26_27 import customize_for_version26_27
|
from uncompyle6.semantics.customize26_27 import (
|
||||||
|
customize_for_version26_27,
|
||||||
|
)
|
||||||
|
|
||||||
customize_for_version26_27(self, version)
|
customize_for_version26_27(self, version)
|
||||||
pass
|
pass
|
||||||
else: # < 2.5
|
else: # < 2.5
|
||||||
global NAME_MODULE
|
global NAME_MODULE
|
||||||
NAME_MODULE = SyntaxTree('stmt',
|
NAME_MODULE = SyntaxTree(
|
||||||
[ SyntaxTree('assign',
|
"stmt",
|
||||||
[ SyntaxTree('expr',
|
[
|
||||||
[Token('LOAD_GLOBAL', pattr='__name__',
|
SyntaxTree(
|
||||||
offset=0, has_arg=True)]),
|
"assign",
|
||||||
SyntaxTree('store',
|
[
|
||||||
[ Token('STORE_NAME', pattr='__module__',
|
SyntaxTree(
|
||||||
offset=3, has_arg=True)])
|
"expr",
|
||||||
])])
|
[
|
||||||
TABLE_DIRECT.update({
|
Token(
|
||||||
'importmultiple': ( '%|import %c%c\n', 2, 3),
|
"LOAD_GLOBAL",
|
||||||
'import_cont' : ( ', %c', 2),
|
pattr="__name__",
|
||||||
'tryfinallystmt': ( '%|try:\n%+%c%-%|finally:\n%+%c%-',
|
offset=0,
|
||||||
(1, 'suite_stmts_opt') ,
|
has_arg=True,
|
||||||
(5, 'suite_stmts_opt') )
|
)
|
||||||
})
|
],
|
||||||
|
),
|
||||||
|
SyntaxTree(
|
||||||
|
"store",
|
||||||
|
[
|
||||||
|
Token(
|
||||||
|
"STORE_NAME",
|
||||||
|
pattr="__module__",
|
||||||
|
offset=3,
|
||||||
|
has_arg=True,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
TABLE_DIRECT.update(
|
||||||
|
{
|
||||||
|
"importmultiple": ("%|import %c%c\n", 2, 3),
|
||||||
|
"import_cont": (", %c", 2),
|
||||||
|
"tryfinallystmt": (
|
||||||
|
"%|try:\n%+%c%-%|finally:\n%+%c%-",
|
||||||
|
(1, "suite_stmts_opt"),
|
||||||
|
(5, "suite_stmts_opt"),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
)
|
||||||
if version == 2.4:
|
if version == 2.4:
|
||||||
|
|
||||||
def n_iftrue_stmt24(node):
|
def n_iftrue_stmt24(node):
|
||||||
self.template_engine(('%c', 0), node)
|
self.template_engine(("%c", 0), node)
|
||||||
self.default(node)
|
self.default(node)
|
||||||
self.prune()
|
self.prune()
|
||||||
|
|
||||||
self.n_iftrue_stmt24 = n_iftrue_stmt24
|
self.n_iftrue_stmt24 = n_iftrue_stmt24
|
||||||
else: # version <= 2.3:
|
else: # version <= 2.3:
|
||||||
TABLE_DIRECT.update({
|
TABLE_DIRECT.update({"if1_stmt": ("%|if 1\n%+%c%-", 5)})
|
||||||
'if1_stmt': ( '%|if 1\n%+%c%-', 5 )
|
|
||||||
})
|
|
||||||
if version <= 2.1:
|
if version <= 2.1:
|
||||||
TABLE_DIRECT.update({
|
TABLE_DIRECT.update(
|
||||||
'importmultiple': ( '%c', 2 ),
|
{
|
||||||
# FIXME: not quite right. We have indiividual imports
|
"importmultiple": ("%c", 2),
|
||||||
# when there is in fact one: "import a, b, ..."
|
# FIXME: not quite right. We have indiividual imports
|
||||||
'imports_cont': ( '%C%,', (1, 100, '\n') ),
|
# when there is in fact one: "import a, b, ..."
|
||||||
})
|
"imports_cont": ("%C%,", (1, 100, "\n")),
|
||||||
|
}
|
||||||
|
)
|
||||||
pass
|
pass
|
||||||
pass
|
pass
|
||||||
pass # < 2.5
|
pass # < 2.5
|
||||||
|
|
||||||
# < 3.0 continues
|
# < 3.0 continues
|
||||||
|
|
||||||
TABLE_R.update({
|
TABLE_R.update(
|
||||||
'STORE_SLICE+0': ( '%c[:]', 0 ),
|
{
|
||||||
'STORE_SLICE+1': ( '%c[%p:]', 0, (1, -1) ),
|
"STORE_SLICE+0": ("%c[:]", 0),
|
||||||
'STORE_SLICE+2': ( '%c[:%p]', 0, (1, -1) ),
|
"STORE_SLICE+1": ("%c[%p:]", 0, (1, -1)),
|
||||||
'STORE_SLICE+3': ( '%c[%p:%p]', 0, (1, -1), (2, -1) ),
|
"STORE_SLICE+2": ("%c[:%p]", 0, (1, -1)),
|
||||||
'DELETE_SLICE+0': ( '%|del %c[:]\n', 0 ),
|
"STORE_SLICE+3": ("%c[%p:%p]", 0, (1, -1), (2, -1)),
|
||||||
'DELETE_SLICE+1': ( '%|del %c[%c:]\n', 0, 1 ),
|
"DELETE_SLICE+0": ("%|del %c[:]\n", 0),
|
||||||
'DELETE_SLICE+2': ( '%|del %c[:%c]\n', 0, 1 ),
|
"DELETE_SLICE+1": ("%|del %c[%c:]\n", 0, 1),
|
||||||
'DELETE_SLICE+3': ( '%|del %c[%c:%c]\n', 0, 1, 2 ),
|
"DELETE_SLICE+2": ("%|del %c[:%c]\n", 0, 1),
|
||||||
})
|
"DELETE_SLICE+3": ("%|del %c[%c:%c]\n", 0, 1, 2),
|
||||||
TABLE_DIRECT.update({
|
}
|
||||||
'raise_stmt2': ( '%|raise %c, %c\n', 0, 1),
|
)
|
||||||
})
|
TABLE_DIRECT.update({"raise_stmt2": ("%|raise %c, %c\n", 0, 1)})
|
||||||
|
|
||||||
# exec as a built-in statement is only in Python 2.x
|
# exec as a built-in statement is only in Python 2.x
|
||||||
def n_exec_stmt(node):
|
def n_exec_stmt(node):
|
||||||
@@ -139,17 +169,19 @@ def customize_for_version(self, is_pypy, version):
|
|||||||
exec_stmt ::= expr exprlist DUP_TOP EXEC_STMT
|
exec_stmt ::= expr exprlist DUP_TOP EXEC_STMT
|
||||||
exec_stmt ::= expr exprlist EXEC_STMT
|
exec_stmt ::= expr exprlist EXEC_STMT
|
||||||
"""
|
"""
|
||||||
self.write(self.indent, 'exec ')
|
self.write(self.indent, "exec ")
|
||||||
self.preorder(node[0])
|
self.preorder(node[0])
|
||||||
if not node[1][0].isNone():
|
if not node[1][0].isNone():
|
||||||
sep = ' in '
|
sep = " in "
|
||||||
for subnode in node[1]:
|
for subnode in node[1]:
|
||||||
self.write(sep); sep = ", "
|
self.write(sep)
|
||||||
|
sep = ", "
|
||||||
self.preorder(subnode)
|
self.preorder(subnode)
|
||||||
self.println()
|
self.println()
|
||||||
self.prune() # stop recursing
|
self.prune() # stop recursing
|
||||||
|
|
||||||
self.n_exec_smt = n_exec_stmt
|
self.n_exec_smt = n_exec_stmt
|
||||||
|
|
||||||
pass # < 3.0
|
pass # < 3.0
|
||||||
|
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user