# Cython - Command Line Parsing
#
+import os
import sys
import Options
Level indicates aggressiveness, default 0 releases nothing.
-w, --working <directory> Sets the working directory for Cython (the directory modules
are searched from)
+ --debug Output debug information for cygdb
-D, --no-docstrings Remove docstrings.
-a, --annotate Produce a colorized HTML version of the source.
options.emit_linenums = True
elif option == "--debug":
options.debug = True
+ options.output_dir = os.curdir
elif option == '-2':
options.language_level = 2
elif option == '-3':
test_support.append(TreeAssertVisitor())
if options.debug:
- import ParseTreeTransforms
- debug_transform = [ParseTreeTransforms.DebuggerTransform(self)]
+ from ParseTreeTransforms import DebuggerTransform
+ debug_transform = [DebuggerTransform(self, options.output_dir)]
else:
debug_transform = []
enable debugging
"""
- def __init__(self, context):
+ def __init__(self, context, output_dir):
super(DebuggerTransform, self).__init__(context)
+ self.output_dir = os.path.join(output_dir, 'cython_debug')
+
if etree is None:
raise Errors.NoElementTreeInstalledException()
- else:
- self.tb = etree.TreeBuilder()
+
+ self.tb = etree.TreeBuilder()
self.visited = set()
def visit_ModuleNode(self, node):
xml_root_element = self.tb.close()
try:
- os.mkdir('cython_debug')
+ os.makedirs(self.output_dir)
except OSError, e:
if e.errno != errno.EEXIST:
raise
kw = {}
if have_lxml:
kw['pretty_print'] = True
- et.write("cython_debug/cython_debug_info_" + self.module_name,
- encoding="UTF-8",
- **kw)
+
+ fn = "cython_debug_info_" + self.module_name
+ et.write(os.path.join(self.output_dir, fn), encoding="UTF-8", **kw)
return root
\ No newline at end of file
The current directory should contain a directory named 'cython_debug', or a
path to the cython project directory should be given (the parent directory of
cython_debug).
+
+Additional gdb args can be provided only if a path to the project directory is
+given.
"""
import os
import tempfile
import subprocess
-def main(import_libpython=False, path_to_debug_info=os.curdir):
+def usage():
+ print("Usage: cygdb [PATH GDB_ARGUMENTS]")
+
+def main(gdb_argv=[], import_libpython=False, path_to_debug_info=os.curdir):
"""
Start the Cython debugger. This tells gdb to import the Cython and Python
extensions (libpython.py and libcython.py) and it enables gdb's pending
os.path.join(path_to_debug_info, 'cython_debug/cython_debug_info_*'))
if not debug_files:
+ usage()
sys.exit('No debug files were found in %s. Aborting.' % (
os.path.abspath(path_to_debug_info)))
f.write('python from Cython.Debugger import libpython\n')
f.write('\n'.join('cy import %s\n' % fn for fn in debug_files))
f.close()
-
- p = subprocess.Popen(['gdb', '-command', tempfilename])
+
+ p = subprocess.Popen(['gdb', '-command', tempfilename] + gdb_argv)
while True:
try:
p.wait()
if rebuild:
log.info("cythoning %s to %s", source, target)
self.mkpath(os.path.dirname(target))
+ if self.inplace:
+ output_dir = os.curdir
+ else:
+ output_dir = self.build_lib
options = CompilationOptions(pyrex_default_options,
use_listing_file = create_listing,
include_path = includes,
cplus = cplus,
emit_linenums = line_directives,
generate_pxi = pyrex_gen_pxi,
+ output_dir = output_dir,
debug = pyrex_debug)
result = cython_compile(source, options=options,
full_module_name=module_name)
if __name__ == '__main__':
if len(sys.argv) > 1:
- cygdb.main(path_to_debug_info=sys.argv[1])
+ cygdb.main(path_to_debug_info=sys.argv[1],
+ gdb_argv=sys.argv[2:])
else:
cygdb.main()
if __name__ == '__main__':
if len(sys.argv) > 1:
- cygdb.main(path_to_debug_info=sys.argv[1])
+ cygdb.main(path_to_debug_info=sys.argv[1],
+ gdb_argv=sys.argv[2:])
else:
cygdb.main()