2323import tempfile
2424
2525import pyficache
26-
2726from xdis import IS_PYPY , PYTHON_VERSION_TRIPLE , load_module
2827from xdis .disasm import disassemble_file
2928from xdis .version_info import version_tuple_to_str
29+
3030from trepan .client import run
3131from trepan .clifns import whence_file
3232from trepan .debugger import Trepan
@@ -111,7 +111,9 @@ def main(dbg=None, sys_argv=list(sys.argv)):
111111 if is_pypy != IS_PYPY :
112112 bytecode_pypy = "" if is_pypy else "not "
113113 running_pypy = "" if IS_PYPY else "not "
114- print (f"Bytecode is for Version { version_tuple_to_str (end = 2 )} { bytecode_pypy } running PyPY, but we are { running_pypy } running PyPy." )
114+ print (
115+ f"Bytecode is for Version { version_tuple_to_str (end = 2 )} { bytecode_pypy } running PyPY, but we are { running_pypy } running PyPy."
116+ )
115117 print ("For a cross-version debugger, use trepan-xpy with x-python." )
116118 sys .exit (2 )
117119 if python_version [:2 ] != PYTHON_VERSION_TRIPLE [:2 ]:
@@ -120,7 +122,9 @@ def main(dbg=None, sys_argv=list(sys.argv)):
120122 f"Bytecode is for version { version_tuple_to_str (python_version , end = 2 )} { bytecode_pypy } , but we are "
121123 f"version { version_tuple_to_str (end = 2 )} { bytecode_pypy } ."
122124 )
123- print ("For a cross-version debugger, trepan-xpy with x-python might work." )
125+ print (
126+ "For a cross-version debugger, trepan-xpy with x-python might work."
127+ )
124128 sys .exit (2 )
125129
126130 py_file = co .co_filename
@@ -159,9 +163,10 @@ def main(dbg=None, sys_argv=list(sys.argv)):
159163 except ImportError :
160164 if PYTHON_VERSION_TRIPLE >= (3 , 9 ):
161165 print (
162- "%s: Decompiler not available for %s." % (__title__ , version_tuple_to_str ()),
166+ "%s: Decompiler not available for %s."
167+ % (__title__ , version_tuple_to_str ()),
163168 file = sys .stderr ,
164- )
169+ )
165170 else :
166171 print (
167172 "%s: Compiled python file '%s', but %s not found"
@@ -198,7 +203,12 @@ def write_wrapper(*args, **kwargs):
198203 f"{ __title__ } : error decompiling '{ mainpyfile } '; disassembling instead." ,
199204 file = sys .stderr ,
200205 )
201- info = disassemble_file (mainpyfile , outstream = fd , asm_format = "extended-bytes" , show_source = False )
206+ info = disassemble_file (
207+ mainpyfile ,
208+ outstream = fd ,
209+ asm_format = "extended-bytes" ,
210+ show_source = False ,
211+ )
202212 code_module = info [1 ]
203213 embedded_filename = code_module .co_filename
204214
@@ -217,18 +227,18 @@ def write_wrapper(*args, **kwargs):
217227 else :
218228 print (
219229 "%s: couldn't find Python source '%s' or decompile it, so we disassembled it at '%s'"
220- % (__title__ , embedded_filename , pyasm_name ),
221- file = sys .stderr ,
230+ % (__title__ , embedded_filename , pyasm_name ),
231+ file = sys .stderr ,
222232 )
223233 pyficache .remap_file (pyasm_name , embedded_filename )
224234
225235 else :
236+ decompile_file = fd .name
226237 print (
227238 "%s: couldn't find Python source, so we recreated it at '%s'."
228- % (__title__ , mainpyfile ),
239+ % (__title__ , decompile_file ),
229240 file = sys .stderr ,
230241 )
231- decompile_file = fd .name
232242 fd .close ()
233243 embedded_filename = co .co_filename
234244 pyficache .remap_file (decompile_file , embedded_filename )
0 commit comments