2015-12-22 08:54:17 +00:00
|
|
|
#!/usr/bin/env python
|
2021-12-17 21:08:29 +00:00
|
|
|
""" Trivial helper program to byte compile and uncompile the bytecode file.
|
2015-12-22 08:54:17 +00:00
|
|
|
"""
|
|
|
|
import os, sys, py_compile
|
2021-11-23 21:38:30 +00:00
|
|
|
from xdis.version_info import version_tuple_to_str, PYTHON_VERSION_TRIPLE
|
2019-09-23 12:23:31 +00:00
|
|
|
|
2021-11-24 20:12:53 +00:00
|
|
|
if len(sys.argv) < 2:
|
|
|
|
print("Usage: add-test.py [--run] *python-source*... [optimize-level]")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2021-12-17 21:08:29 +00:00
|
|
|
assert 2 <= len(sys.argv) <= 4
|
|
|
|
version = sys.version[0:3]
|
|
|
|
vers = sys.version_info[:2]
|
2019-09-23 12:23:31 +00:00
|
|
|
if sys.argv[1] in ("--run", "-r"):
|
|
|
|
suffix = "_run"
|
2022-04-03 10:41:58 +00:00
|
|
|
assert len(sys.argv) >= 3
|
2019-04-10 11:22:43 +00:00
|
|
|
py_source = sys.argv[2:]
|
2020-07-21 14:31:07 +00:00
|
|
|
i = 2
|
2019-04-10 11:22:43 +00:00
|
|
|
else:
|
2019-09-23 12:23:31 +00:00
|
|
|
suffix = ""
|
2019-04-10 11:22:43 +00:00
|
|
|
py_source = sys.argv[1:]
|
2020-07-21 14:31:07 +00:00
|
|
|
i = 1
|
|
|
|
try:
|
|
|
|
optimize = int(sys.argv[-1])
|
2021-11-24 20:12:53 +00:00
|
|
|
assert sys.argv >= i + 2
|
2020-07-21 14:31:07 +00:00
|
|
|
py_source = sys.argv[i:-1]
|
2021-11-24 20:12:53 +00:00
|
|
|
i = 2
|
|
|
|
|
2020-07-21 14:31:07 +00:00
|
|
|
except:
|
|
|
|
optimize = 2
|
2019-04-10 11:22:43 +00:00
|
|
|
|
|
|
|
for path in py_source:
|
2016-07-08 18:56:57 +00:00
|
|
|
short = os.path.basename(path)
|
2021-12-17 21:08:29 +00:00
|
|
|
if short.endswith(".py"):
|
|
|
|
short = short[: -len(".py")]
|
2019-09-23 12:23:31 +00:00
|
|
|
if hasattr(sys, "pypy_version_info"):
|
2021-11-23 21:38:30 +00:00
|
|
|
version = version_tuple_to_str(end=2, delimiter="")
|
|
|
|
bytecode = "bytecode_pypy%s%s/%spy%s.pyc" % (version, suffix, short, version)
|
2016-07-24 14:32:35 +00:00
|
|
|
else:
|
2021-11-23 21:38:30 +00:00
|
|
|
version = version_tuple_to_str(end=2)
|
|
|
|
bytecode = "bytecode_%s%s/%s.pyc" % (version, suffix, short)
|
|
|
|
|
|
|
|
print("byte-compiling %s to %s" % (path, bytecode))
|
2021-11-24 20:12:53 +00:00
|
|
|
if PYTHON_VERSION_TRIPLE >= (3, 2):
|
2021-11-23 21:38:30 +00:00
|
|
|
py_compile.compile(path, bytecode, optimize=optimize)
|
2020-07-06 22:19:06 +00:00
|
|
|
else:
|
2021-11-23 21:38:30 +00:00
|
|
|
py_compile.compile(path, bytecode)
|
|
|
|
if PYTHON_VERSION_TRIPLE >= (2, 6):
|
|
|
|
os.system("../bin/uncompyle6 -a -t %s" % bytecode)
|