diff --git a/test/add-test.py b/test/add-test.py index 71b9c710..af7a4822 100755 --- a/test/add-test.py +++ b/test/add-test.py @@ -1,14 +1,16 @@ #!/usr/bin/env python -""" Trivial helper program to bytecompile and run an uncompile +""" Trivial helper program to byte compile and run an uncompyle6 on the bytecode file. """ import os, sys, py_compile from xdis.version_info import version_tuple_to_str, PYTHON_VERSION_TRIPLE -assert (2 <= len(sys.argv) <= 4) -version = sys.version[0:3] -vers = sys.version_info[:2] +if len(sys.argv) < 2: + print("Usage: add-test.py [--run] *python-source*... [optimize-level]") + sys.exit(1) + if sys.argv[1] in ("--run", "-r"): suffix = "_run" + assert sys.argv >= 3 py_source = sys.argv[2:] i = 2 else: @@ -17,7 +19,10 @@ else: i = 1 try: optimize = int(sys.argv[-1]) + assert sys.argv >= i + 2 py_source = sys.argv[i:-1] + i = 2 + except: optimize = 2 @@ -31,8 +36,7 @@ for path in py_source: bytecode = "bytecode_%s%s/%s.pyc" % (version, suffix, short) print("byte-compiling %s to %s" % (path, bytecode)) - py_compile.compile(path, bytecode, optimize=optimize) - if vers > (3, 1): + if PYTHON_VERSION_TRIPLE >= (3, 2): py_compile.compile(path, bytecode, optimize=optimize) else: py_compile.compile(path, bytecode)