Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / third_party / cython / src / Cython / Debugger / DebugWriter.py
blob7242a582ed6e3add6be064b0c11d416fe0553b22
1 from __future__ import with_statement
3 import os
4 import sys
5 import errno
7 try:
8 from lxml import etree
9 have_lxml = True
10 except ImportError:
11 have_lxml = False
12 try:
13 # Python 2.5
14 from xml.etree import cElementTree as etree
15 except ImportError:
16 try:
17 # Python 2.5
18 from xml.etree import ElementTree as etree
19 except ImportError:
20 try:
21 # normal cElementTree install
22 import cElementTree as etree
23 except ImportError:
24 try:
25 # normal ElementTree install
26 import elementtree.ElementTree as etree
27 except ImportError:
28 etree = None
30 from Cython.Compiler import Errors
33 class CythonDebugWriter(object):
34 """
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.
39 """
41 def __init__(self, output_dir):
42 if etree is None:
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 {})
54 def end(self, name):
55 self.tb.end(name)
57 def serialize(self):
58 self.tb.end('Module')
59 self.tb.end('cython_debug')
60 xml_root_element = self.tb.close()
62 try:
63 os.makedirs(self.output_dir)
64 except OSError, e:
65 if e.errno != errno.EEXIST:
66 raise
68 et = etree.ElementTree(xml_root_element)
69 kw = {}
70 if have_lxml:
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)