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
+ --gdb Output debug information for cygdb
-D, --no-docstrings Remove docstrings.
-a, --annotate Produce a colorized HTML version of the source.
Options.convert_range = True
elif option == "--line-directives":
options.emit_linenums = True
- elif option == "--debug":
- options.debug = True
+ elif option == "--gdb":
+ options.gdb_debug = True
options.output_dir = os.curdir
elif option == '-2':
options.language_level = 2
CompileError.__init__(self, pos, message)
class NoElementTreeInstalledException(PyrexError):
- """raised when the user enabled options.debug but no ElementTree
+ """raised when the user enabled options.gdb_debug but no ElementTree
implementation was found
"""
self.set_language_level(language_level)
- self.debug_outputwriter = None
+ self.gdb_debug_outputwriter = None
def set_language_level(self, level):
self.language_level = level
from Cython.TestUtils import TreeAssertVisitor
test_support.append(TreeAssertVisitor())
- if options.debug:
+ if options.gdb_debug:
from Cython.Debugger import DebugWriter
from ParseTreeTransforms import DebugTransform
- self.debug_outputwriter = DebugWriter.CythonDebugWriter(
+ self.gdb_debug_outputwriter = DebugWriter.CythonDebugWriter(
options.output_dir)
debug_transform = [DebugTransform(self, options, result)]
else:
evaluate_tree_assertions = False,
emit_linenums = False,
language_level = 2,
- debug = False,
+ gdb_debug = False,
)
f = open_new_file(result.c_file)
rootwriter.copyto(f)
- if options.debug:
+ if options.gdb_debug:
self._serialize_lineno_map(env, rootwriter)
f.close()
result.c_file_generated = 1
rootwriter.save_annotation(result.main_source_file, result.c_file)
def _serialize_lineno_map(self, env, ccodewriter):
- tb = env.context.debug_outputwriter
+ tb = env.context.gdb_debug_outputwriter
markers = ccodewriter.buffer.allmarkers()
d = {}
self.visited = set()
# our treebuilder and debug output writer
# (see Cython.Debugger.debug_output.CythonDebugWriter)
- self.tb = self.context.debug_outputwriter
+ self.tb = self.context.gdb_debug_outputwriter
#self.c_output_file = options.output_file
self.c_output_file = result.c_file
def visit_FuncDefNode(self, node):
self.visited.add(node.local_scope.qualified_name)
- node.entry.visibility = 'extern'
+ # node.entry.visibility = 'extern'
if node.py_func is None:
pf_cname = ''
else:
import os
from Cython.Debugger import DebugWriter
-from Cython.Compiler import Main
from Cython.Compiler import CmdLine
from Cython.TestUtils import TransformTest
from Cython.Compiler.ParseTreeTransforms import *
class TestDebugTransform(TestLibCython.DebuggerTestCase):
def elem_hasattrs(self, elem, attrs):
- return all(attr in elem.attrib for attr in attrs)
+ # we shall supporteth python 2.3 !
+ return all([attr in elem.attrib for attr in attrs])
def test_debug_info(self):
try:
L = list(t.find('/Module/Globals'))
# assertTrue is retarded, use the normal assert statement
assert L
- xml_globals = dict((e.attrib['name'], e.attrib['type']) for e in L)
+ xml_globals = dict(
+ [(e.attrib['name'], e.attrib['type']) for e in L])
self.assertEqual(len(L), len(xml_globals))
L = list(t.find('/Module/Functions'))
assert L
- xml_funcs = dict((e.attrib['qualified_name'], e) for e in L)
+ xml_funcs = dict([(e.attrib['qualified_name'], e) for e in L])
self.assertEqual(len(L), len(xml_funcs))
# test globals
# test functions
funcnames = 'codefile.spam', 'codefile.ham', 'codefile.eggs'
required_xml_attrs = 'name', 'cname', 'qualified_name'
- assert all(f in xml_funcs for f in funcnames)
- spam, ham, eggs = (xml_funcs[funcname] for funcname in funcnames)
+ assert all([f in xml_funcs for f in funcnames])
+ spam, ham, eggs = [xml_funcs[funcname] for funcname in funcnames]
self.assertEqual(spam.attrib['name'], 'spam')
self.assertNotEqual('spam', spam.attrib['cname'])
import tempfile
import subprocess
-def usage():
- print("Usage: cygdb [PATH GDB_ARGUMENTS]")
+usage = "Usage: cygdb [PATH [GDB_ARGUMENTS]]"
def make_command_file(path_to_debug_info, prefix_code='', no_import=False):
if not no_import:
debug_files = glob.glob(pattern)
if not debug_files:
- usage()
- sys.exit('No debug files were found in %s. Aborting.' % (
- os.path.abspath(path_to_debug_info)))
-
-
+ sys.exit('%s.\nNo debug files were found in %s. Aborting.' % (
+ usage, os.path.abspath(path_to_debug_info)))
fd, tempfilename = tempfile.mkstemp()
f = os.fdopen(fd, 'w')
return tempfilename
-def main(path_to_debug_info=os.curdir, gdb_argv=[], no_import=False):
+def main(path_to_debug_info=None, gdb_argv=None, no_import=False):
"""
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
- breakpoints
+ extensions (libcython.py and libpython.py) and it enables gdb's pending
+ breakpoints.
- path_to_debug_info is the path to the cython_debug directory
+ path_to_debug_info is the path to the Cython build directory
+ gdb_argv is the list of options to gdb
+ no_import tells cygdb whether it should import debug information
"""
+ if path_to_debug_info is None:
+ if len(sys.argv) > 1:
+ path_to_debug_info = sys.argv[1]
+ else:
+ path_to_debug_info = os.curdir
+
+ if gdb_argv is None:
+ gdb_argv = sys.argv[2:]
+
+ if path_to_debug_info == '--':
+ no_import = True
+
tempfilename = make_command_file(path_to_debug_info, no_import=no_import)
p = subprocess.Popen(['gdb', '-command', tempfilename] + gdb_argv)
while True:
pass
else:
break
- os.remove(tempfilename)
\ No newline at end of file
+ os.remove(tempfilename)
+from __future__ import with_statement
+
import os
import sys
import errno
ext = Cython.Distutils.extension.Extension(
'codefile',
['codefile.pyx'],
- pyrex_debug=True,
+ pyrex_gdb=True,
extra_objects=['cfuncs.o'])
distutils.core.setup(
command_class = gdb.COMMAND_NONE
completer_class = gdb.COMPLETE_COMMAND
- def __init__(self, *args):
- super(CythonCommand, self).__init__(*args, prefix=True)
+ def __init__(self, name, command_class, completer_class):
+ # keep the signature 2.5 compatible (i.e. do not use f(*a, k=v)
+ super(CythonCommand, self).__init__(name, command_class,
+ completer_class, prefix=True)
commands = dict(
import_ = CyImport.register(),
class CyExec(CythonCommand, libpython.PyExec):
+ """
+ Execute Python code in the nearest Python or Cython frame.
+ """
+
name = '-cy-exec'
command_class = gdb.COMMAND_STACK
completer_class = gdb.COMPLETE_NONE
self._fill_locals_dict(executor, libpython.pointervalue(local_dict))
executor.evalcode(expr, input_type, global_dict, local_dict)
finally:
-
- # try:
- # tp, val, tb = sys.exc_info()
- # sys.exc_clear()
- #
- # try:
- # long(gdb.parse_and_eval("(void *) 0")) == 0
- # except RuntimeError:
- # # At this point gdb is broken, just exit this shite, it
- # # ain't getting better.
- #
-# # /home/mark/source/code/cython/Cython/Debugger/libcython.py:1206:
-# # RuntimeWarning: tp_compare didn't return -1 or -2 for exception
-# # long(gdb.parse_and_eval("(void *) 0")) == 0
-# # Traceback (most recent call last):
-# # File "/home/mark/source/code/cython/Cython/Debugger/libcython.py", line 1206,
-# # in invoke
-# # long(gdb.parse_and_eval("(void *) 0")) == 0
-# # RuntimeError: Cannot convert value to int.
-# # Error occurred in Python command: Cannot convert value to int.
- # if sys.exc_info()[0] is None and val is not None:
- # raise val, tb
- #
- # for name, value in libpython.PyDictObjectPtr(local_dict).iteritems():
- # name = name.proxyval(set())
- # cyvar = cython_function.locals.get(name)
- # if cyvar is not None and cyvar.type == PythonObject:
- # gdb.parse_and_eval('set %s = (PyObject *) %d' % (cyvar.cname,
- # pointervalue(value._gdbval)))
- # finally:
executor.decref(libpython.pointervalue(local_dict))
-
- # if sys.exc_info()[0] is None and val is not None:
- # raise val, tb
-
# Functions
#!/usr/bin/python
# NOTE: this file is taken from the Python source distribution
-# It can be found under Tools/gdb/libpython.py
+# It can be found under Tools/gdb/libpython.py. It is shipped with Cython
+# because it's not installed as a python module, and because changes are only
+# merged into new python versions (v3.2+).
'''
From gdb 7 onwards, gdb's build can be configured --with-python, allowing gdb
for flag, option in zip(self.flags, self.state):
if option is not None:
- g = (opt for opt in option.split() if opt not in badoptions)
- self.config_vars[flag] = ' '.join(g)
+ L = [opt for opt in option.split() if opt not in badoptions]
+ self.config_vars[flag] = ' '.join(L)
def restore_state(self):
"restore the original state"
optimization = Optimization()
+try:
+ any
+except NameError:
+ def any(it):
+ for x in it:
+ if x:
+ return True
+
+ return False
+
class build_ext(_build_ext.build_ext):
"generate .pxi file for public declarations"),
('pyrex-directives=', None,
"compiler directive overrides"),
- ('pyrex-debug', None,
+ ('pyrex-gdb', None,
"generate debug information for cygdb"),
])
boolean_options.extend([
'pyrex-cplus', 'pyrex-create-listing', 'pyrex-line-directives',
- 'pyrex-c-in-temp', 'pyrex-debug',
+ 'pyrex-c-in-temp', 'pyrex-gdb',
])
def initialize_options(self):
self.pyrex_directives = None
self.pyrex_c_in_temp = 0
self.pyrex_gen_pxi = 0
- self.pyrex_debug = False
+ self.pyrex_gdb = False
def finalize_options (self):
_build_ext.build_ext.finalize_options(self)
def run(self):
# We have one shot at this before build_ext initializes the compiler.
- # If --pyrex-debug is in effect as a command line option or as option
+ # If --pyrex-gdb is in effect as a command line option or as option
# of any Extension module, disable optimization for the C or C++
# compiler.
- if (self.pyrex_debug or any(getattr(ext, 'pyrex_debug', False)
- for ext in self.extensions)):
+ if (self.pyrex_gdb or any([getattr(ext, 'pyrex_gdb', False)
+ for ext in self.extensions])):
optimization.disable_optimization()
_build_ext.build_ext.run(self)
cplus = self.pyrex_cplus or getattr(extension, 'pyrex_cplus', 0) or \
(extension.language and extension.language.lower() == 'c++')
pyrex_gen_pxi = self.pyrex_gen_pxi or getattr(extension, 'pyrex_gen_pxi', 0)
- pyrex_debug = self.pyrex_debug or getattr(extension, 'pyrex_debug', False)
+ pyrex_gdb = self.pyrex_gdb or getattr(extension, 'pyrex_gdb', False)
# Set up the include_path for the Cython compiler:
# 1. Start with the command line option.
# 2. Add in any (unique) paths from the extension
emit_linenums = line_directives,
generate_pxi = pyrex_gen_pxi,
output_dir = output_dir,
- debug = pyrex_debug)
+ gdb_debug = pyrex_gdb)
result = cython_compile(source, options=options,
full_module_name=module_name)
else:
put generated C files in temp directory.
pyrex_gen_pxi : boolean
generate .pxi file for public declarations
- pyrex_debug : boolean
+ pyrex_gdb : boolean
generate Cython debug information for this extension for cygdb
"""
pyrex_cplus = 0,
pyrex_c_in_temp = 0,
pyrex_gen_pxi = 0,
- pyrex_debug = False,
+ pyrex_gdb = False,
**kw):
_Extension.Extension.__init__(self, name, sources,
self.pyrex_cplus = pyrex_cplus
self.pyrex_c_in_temp = pyrex_c_in_temp
self.pyrex_gen_pxi = pyrex_gen_pxi
- self.pyrex_debug = pyrex_debug
+ self.pyrex_gdb = pyrex_gdb
# class Extension
from Cython.Debugger import Cygdb as cygdb
if __name__ == '__main__':
- if len(sys.argv) > 1:
- path_to_debug_info = sys.argv[1]
-
- no_import = False
- if path_to_debug_info == '--':
- no_import = True
-
- cygdb.main(path_to_debug_info,
- gdb_argv=sys.argv[2:],
- no_import=no_import)
- else:
cygdb.main()
from Cython.Debugger import Cygdb as cygdb
if __name__ == '__main__':
- if len(sys.argv) > 1:
- path_to_debug_info = sys.argv[1]
-
- no_import = False
- if path_to_debug_info == '--':
- no_import = True
-
- cygdb.main(path_to_debug_info,
- gdb_argv=sys.argv[2:],
- no_import=no_import)
- else:
cygdb.main()
# specific to setup
setuptools_extra_args = {}
+# tells whether to include cygdb (the script and the Cython.Debugger package
+include_debugger = sys.version_info[:2] > (2, 4)
+
if 'setuptools' in sys.modules:
setuptools_extra_args['zip_safe'] = False
setuptools_extra_args['entry_points'] = {
scripts = []
else:
if os.name == "posix":
- scripts = ["bin/cython", "bin/cygdb"]
+ scripts = ["bin/cython"]
+ if include_debugger:
+ scripts.append('bin/cygdb')
else:
- scripts = ["cython.py", "cygdb.py"]
+ scripts = ["cython.py"]
+ if include_debugger:
+ scripts.append('cygdb.py')
def compile_cython_modules(profile=False, compile_more=False, cython_with_refnanny=False):
source_root = os.path.abspath(os.path.dirname(__file__))
from Cython import __version__ as version
+packages = [
+ 'Cython',
+ 'Cython.Build',
+ 'Cython.Compiler',
+ 'Cython.Runtime',
+ 'Cython.Distutils',
+ 'Cython.Plex',
+ 'Cython.Tests',
+ 'Cython.Compiler.Tests',
+]
+
+if include_debugger:
+ packages.append('Cython.Debugger')
+
setup(
name = 'Cython',
version = version,
],
scripts = scripts,
- packages=[
- 'Cython',
- 'Cython.Build',
- 'Cython.Compiler',
- 'Cython.Runtime',
- 'Cython.Distutils',
- 'Cython.Plex',
- 'Cython.Debugger',
- 'Cython.Tests',
- 'Cython.Compiler.Tests',
- ],
+ packages=packages,
# pyximport
py_modules = ["pyximport/__init__",