More version tuple conversions

This commit is contained in:
rocky
2021-10-23 15:54:14 -04:00
parent 1bcd21a6f4
commit 7387e5094b
2 changed files with 11 additions and 10 deletions

View File

@@ -1,4 +1,4 @@
# Copyright (C) 2018, 2020 Rocky Bernstein <rocky@gnu.org> # Copyright (C) 2018, 2020-2021 Rocky Bernstein <rocky@gnu.org>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by

View File

@@ -1,4 +1,4 @@
# Copyright (C) 2018-2020 Rocky Bernstein <rocky@gnu.org> # Copyright (C) 2018-2021 Rocky Bernstein <rocky@gnu.org>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -15,8 +15,9 @@
from __future__ import print_function from __future__ import print_function
import datetime, py_compile, os, subprocess, sys, tempfile import datetime, py_compile, os, subprocess, sys, tempfile
from uncompyle6 import verify, IS_PYPY, PYTHON_VERSION from uncompyle6 import verify
from xdis import iscode, sysinfo2float from xdis import iscode
from xdis.version_info import IS_PYPY, PYTHON_VERSION_TRIPLE, version_tuple_to_str
from uncompyle6.disas import check_object_path from uncompyle6.disas import check_object_path
from uncompyle6.semantics import pysource from uncompyle6.semantics import pysource
from uncompyle6.parser import ParserError from uncompyle6.parser import ParserError
@@ -40,7 +41,7 @@ def _get_outstream(outfile):
os.makedirs(dir) os.makedirs(dir)
except OSError: except OSError:
pass pass
if PYTHON_VERSION < 3.0: if PYTHON_VERSION_TRIPLE < (3, 0):
return open(outfile, mode="wb") return open(outfile, mode="wb")
else: else:
return open(outfile, mode="w", encoding="utf-8") return open(outfile, mode="w", encoding="utf-8")
@@ -71,7 +72,7 @@ def decompile(
Caller is responsible for closing `out` and `mapstream` Caller is responsible for closing `out` and `mapstream`
""" """
if bytecode_version is None: if bytecode_version is None:
bytecode_version = sysinfo2float() bytecode_version = PYTHON_VERSION_TRIPLE
# store final output stream for case of error # store final output stream for case of error
real_out = out or sys.stdout real_out = out or sys.stdout
@@ -93,13 +94,13 @@ def decompile(
% ( % (
__version__, __version__,
co_pypy_str, co_pypy_str,
bytecode_version, version_tuple_to_str(bytecode_version),
" (%s)" % str(magic_int) if magic_int else "", " (%s)" % str(magic_int) if magic_int else "",
run_pypy_str, run_pypy_str,
"\n# ".join(sys_version_lines), "\n# ".join(sys_version_lines),
) )
) )
if PYTHON_VERSION < 3.0 and bytecode_version >= 3.0: if PYTHON_VERSION_TRIPLE < (3, 0) and bytecode_version >= (3, 0):
write( write(
'# Warning: this version of Python has problems handling the Python 3 "byte" type in constants properly.\n' '# Warning: this version of Python has problems handling the Python 3 "byte" type in constants properly.\n'
) )
@@ -154,9 +155,9 @@ def compile_file(source_path):
basename = source_path basename = source_path
if hasattr(sys, "pypy_version_info"): if hasattr(sys, "pypy_version_info"):
bytecode_path = "%s-pypy%s.pyc" % (basename, PYTHON_VERSION) bytecode_path = "%s-pypy%s.pyc" % (basename, version_tuple_to_str())
else: else:
bytecode_path = "%s-%s.pyc" % (basename, PYTHON_VERSION) bytecode_path = "%s-%s.pyc" % (basename, version_tuple_to_str())
print("compiling %s to %s" % (source_path, bytecode_path)) print("compiling %s to %s" % (source_path, bytecode_path))
py_compile.compile(source_path, bytecode_path, "exec") py_compile.compile(source_path, bytecode_path, "exec")