2 # Cython - Compilation-wide options and pragma declarations
5 cache_builtins = 1 # Perform lookups on builtin names only once
7 embed_pos_in_docstring = 0
13 # Decref global variables in this module on exit for garbage collection.
14 # 0: None, 1+: interned objects, 2+: cdef globals, 3+: types objects
15 # Mostly for reducing noise for Valgrind, only executes at process exit
16 # (when all memory will be reclaimed anyways).
17 generate_cleanup_code = 0
21 # This will abort the compilation on the first error occured rather than trying
22 # to keep going and printing further error messages.
25 # This will convert statements of the form "for i in range(...)"
26 # to "for i from ..." when i is a cdef'd integer type, and the direction
27 # (i.e. sign of step) can be determined.
28 # WARNING: This may change the semantics if the range causes assignment to
29 # i to overflow. Specifically, if this option is set, an error will be
30 # raised before the loop is entered, wheras without this option the loop
31 # will execute until an overflowing value is encountered.
34 # Enable this to allow one to write your_module.foo = ... to overwrite the
35 # definition if the cpdef function foo, at the cost of an extra dictionary
36 # lookup on every call.
37 # If this is 0 it simply creates a wrapper.
38 lookup_module_cpdef = 0
40 # This will set local variables to None rather than NULL which may cause
41 # surpress what would be an UnboundLocalError in pure Python but eliminates
42 # checking for NULL on every use, and can decref rather than xdecref at the end.
43 # WARNING: This is a work in progress, may currently segfault.
46 # Append the c file and line number to the traceback for exceptions.
47 c_line_in_traceback = 1
49 # Whether or not to embed the Python interpreter, for use in making a
50 # standalone executable. This will provide a main() method which simply
51 # executes the body of this module.
55 # Declare compiler directives
56 directive_defaults = {
59 'embedsignature' : False,
62 'cdivision': False, # was True before 0.12
63 'cdivision_warnings': False,
64 'always_allow_keywords': False,
65 'allow_none_for_extension_args': True,
67 'ccomplex' : False, # use C99/C++ for complex types and arith
73 'infer_types.verbose': False,
75 'autotestdict.cdef': False,
76 'autotestdict.all': False,
78 'fast_getattr': False, # Undocumented until we come up with a better way to handle this everywhere.
81 'warn.undeclared': False,
84 'test_assert_path_exists' : [],
85 'test_fail_if_path_exists' : [],
87 # experimental, subject to change
91 # Override types possibilities above, if needed
93 'final' : bool, # final cdef classes and methods
94 'internal' : bool, # cdef class visibility in the module dict
95 'infer_types' : bool, # values can be True/None/False
98 for key, val in directive_defaults.items():
99 if key not in directive_types:
100 directive_types[key] = type(val)
102 directive_scopes = { # defaults to available everywhere
103 # 'module', 'function', 'class', 'with statement'
104 'final' : ('cclass',), # add 'method' in the future
105 'internal' : ('cclass',),
106 'autotestdict' : ('module',),
107 'autotestdict.all' : ('module',),
108 'autotestdict.cdef' : ('module',),
109 'test_assert_path_exists' : ('function', 'class', 'cclass'),
110 'test_fail_if_path_exists' : ('function', 'class', 'cclass'),
113 def parse_directive_value(name, value, relaxed_bool=False):
115 Parses value as an option value for the given name and returns
116 the interpreted value. None is returned if the option does not exist.
118 >>> print parse_directive_value('nonexisting', 'asdf asdfd')
120 >>> parse_directive_value('boundscheck', 'True')
122 >>> parse_directive_value('boundscheck', 'true')
123 Traceback (most recent call last):
125 ValueError: boundscheck directive must be set to True or False, got 'true'
128 type = directive_types.get(name)
129 if not type: return None
133 if value == 'True': return True
134 if value == 'False': return False
136 value = value.lower()
137 if value in ("true", "yes"): return True
138 elif value in ("false", "no"): return False
139 raise ValueError("%s directive must be set to True or False, got '%s'" % (
145 raise ValueError("%s directive must be set to an integer, got '%s'" % (
152 def parse_directive_list(s, relaxed_bool=False, ignore_unknown=False,
153 current_settings=None):
155 Parses a comma-separated list of pragma options. Whitespace
158 >>> parse_directive_list(' ')
160 >>> (parse_directive_list('boundscheck=True') ==
161 ... {'boundscheck': True})
163 >>> parse_directive_list(' asdf')
164 Traceback (most recent call last):
166 ValueError: Expected "=" in option "asdf"
167 >>> parse_directive_list('boundscheck=hey')
168 Traceback (most recent call last):
170 ValueError: boundscheck directive must be set to True or False, got 'hey'
171 >>> parse_directive_list('unknown=True')
172 Traceback (most recent call last):
174 ValueError: Unknown option: "unknown"
176 if current_settings is None:
179 result = current_settings
180 for item in s.split(','):
182 if not item: continue
183 if not '=' in item: raise ValueError('Expected "=" in option "%s"' % item)
184 name, value = [ s.strip() for s in item.strip().split('=', 1) ]
185 parsed_value = parse_directive_value(name, value, relaxed_bool=relaxed_bool)
186 if parsed_value is None:
187 if not ignore_unknown:
188 raise ValueError('Unknown option: "%s"' % name)
190 result[name] = parsed_value