1 from __future__
import with_statement
14 from xml
.etree
import cElementTree
as etree
18 from xml
.etree
import ElementTree
as etree
21 # normal cElementTree install
22 import cElementTree
as etree
25 # normal ElementTree install
26 import elementtree
.ElementTree
as etree
30 from Cython
.Compiler
import Errors
33 class CythonDebugWriter(object):
35 Class to output debugging information for cygdb
37 It writes debug information to cython_debug/cython_debug_info_<modulename>
38 in the build directory.
41 def __init__(self
, output_dir
):
43 raise Errors
.NoElementTreeInstalledException()
45 self
.output_dir
= os
.path
.join(output_dir
, 'cython_debug')
46 self
.tb
= etree
.TreeBuilder()
47 # set by Cython.Compiler.ParseTreeTransforms.DebugTransform
48 self
.module_name
= None
49 self
.start('cython_debug', attrs
=dict(version
='1.0'))
51 def start(self
, name
, attrs
=None):
52 self
.tb
.start(name
, attrs
or {})
59 self
.tb
.end('cython_debug')
60 xml_root_element
= self
.tb
.close()
63 os
.makedirs(self
.output_dir
)
65 if e
.errno
!= errno
.EEXIST
:
68 et
= etree
.ElementTree(xml_root_element
)
71 kw
['pretty_print'] = True
73 fn
= "cython_debug_info_" + self
.module_name
74 et
.write(os
.path
.join(self
.output_dir
, fn
), encoding
="UTF-8", **kw
)
76 interpreter_path
= os
.path
.join(self
.output_dir
, 'interpreter')
77 with
open(interpreter_path
, 'w') as f
:
78 f
.write(sys
.executable
)