Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 362 lines (319 sloc) 12.826 kB
54ab11e @williamstein Official Pyrex version 0.9.4.1
williamstein authored
1 #
2191ad0 @dagss Added global compilation option/pragma support to parser and command …
dagss authored
2 # Cython - Compilation-wide options and pragma declarations
54ab11e @williamstein Official Pyrex version 0.9.4.1
williamstein authored
3 #
4
a96882e @scoder use explicit relative imports everywhere and enable absolute imports …
scoder authored
5 from __future__ import absolute_import
6
c13aff5 clean up special casing of non-portable builtin types, add option for…
Stefan Behnel authored
7 # Perform lookups on builtin names only once, at module initialisation
8 # time. This will prevent the module from getting imported if a
9 # builtin name that it uses cannot be found during initialisation.
10 cache_builtins = True
5a4ef8d @williamstein Add a new option "-e" or "--embed-positions" to Pyrex.
williamstein authored
11
d190479 @robertwb CLeanup Options.py
robertwb authored
12 embed_pos_in_docstring = False
13 gcc_branch_hints = True
76750ff @robertwb Added pre-import option, which assumes all undeclared names come from…
robertwb authored
14
15 pre_import = None
bbda6f5 @barbieri Re: Disabling docstrings in generated .so?
barbieri authored
16 docstrings = True
c160900 @robertwb incref_local_binop option for SAGE
robertwb authored
17
f6762fa @robertwb Remove trailing whitespace.
robertwb authored
18 # Decref global variables in this module on exit for garbage collection.
fce655c @robertwb Generate module cleanup code
robertwb authored
19 # 0: None, 1+: interned objects, 2+: cdef globals, 3+: types objects
ca96f2e @robertwb Due to occasional issues with cleanup on exit, cleanup now disabled b…
robertwb authored
20 # Mostly for reducing noise for Valgrind, only executes at process exit
f6762fa @robertwb Remove trailing whitespace.
robertwb authored
21 # (when all memory will be reclaimed anyways).
d190479 @robertwb CLeanup Options.py
robertwb authored
22 generate_cleanup_code = False
3d32b84 @robertwb HTML source annotation module
robertwb authored
23
384cc66 @scoder integrate coverage report into annotated HTML source page
scoder authored
24 # Generate an annotated HTML version of the input source files.
d190479 @robertwb CLeanup Options.py
robertwb authored
25 annotate = False
77d9b2e @robertwb (Optionally) mutate range into for..from loops.
robertwb authored
26
384cc66 @scoder integrate coverage report into annotated HTML source page
scoder authored
27 # When annotating source files in HTML, include coverage information from
28 # this file.
29 annotate_coverage_xml = None
30
03397f1 @certik Implement the --fatal-errors command line option
certik authored
31 # This will abort the compilation on the first error occured rather than trying
32 # to keep going and printing further error messages.
4b20838 @robertwb fatal_errors -> fast_fail
robertwb authored
33 fast_fail = False
03397f1 @certik Implement the --fatal-errors command line option
certik authored
34
63abcdc @vitek Add command line flag --warning-errors and gcc compat alias -Werror
vitek authored
35 # Make all warnings into errors.
36 warning_errors = False
37
c13aff5 clean up special casing of non-portable builtin types, add option for…
Stefan Behnel authored
38 # Make unknown names an error. Python raises a NameError when
39 # encountering unknown names at runtime, whereas this option makes
40 # them a compile time error. If you want full Python compatibility,
41 # you should disable this option and also 'cache_builtins'.
42 error_on_unknown_names = True
43
d0627fc @vitek Add error_on_uninitialized option and disable it for pyregr testsuite
vitek authored
44 # Make uninitialized local variable reference a compile time error.
45 # Python raises UnboundLocalError at runtime, whereas this option makes
46 # them a compile time error. Note that this option affects only variables
47 # of "python object" type.
48 error_on_uninitialized = True
49
f6762fa @robertwb Remove trailing whitespace.
robertwb authored
50 # This will convert statements of the form "for i in range(...)"
77d9b2e @robertwb (Optionally) mutate range into for..from loops.
robertwb authored
51 # to "for i from ..." when i is a cdef'd integer type, and the direction
f6762fa @robertwb Remove trailing whitespace.
robertwb authored
52 # (i.e. sign of step) can be determined.
53 # WARNING: This may change the semantics if the range causes assignment to
77d9b2e @robertwb (Optionally) mutate range into for..from loops.
robertwb authored
54 # i to overflow. Specifically, if this option is set, an error will be
55 # raised before the loop is entered, wheras without this option the loop
f6762fa @robertwb Remove trailing whitespace.
robertwb authored
56 # will execute until an overflowing value is encountered.
d190479 @robertwb CLeanup Options.py
robertwb authored
57 convert_range = True
ad4b206 @robertwb Module-level cpdef functions
robertwb authored
58
f6762fa @robertwb Remove trailing whitespace.
robertwb authored
59 # Enable this to allow one to write your_module.foo = ... to overwrite the
60 # definition if the cpdef function foo, at the cost of an extra dictionary
61 # lookup on every call.
62 # If this is 0 it simply creates a wrapper.
d190479 @robertwb CLeanup Options.py
robertwb authored
63 lookup_module_cpdef = False
6a8e079 @robertwb More control flow work
robertwb authored
64
f6762fa @robertwb Remove trailing whitespace.
robertwb authored
65 # Whether or not to embed the Python interpreter, for use in making a
4350d7f @robertwb Allow embed option to take function name.
robertwb authored
66 # standalone executable or calling from external libraries.
4fc682a @robertwb Complile/runtime version mismatch warning.
robertwb authored
67 # This will provide a method which initalizes the interpreter and
68 # executes the body of this module.
4350d7f @robertwb Allow embed option to take function name.
robertwb authored
69 embed = None
0bf694a @robertwb Embed flag for Cython modules
robertwb authored
70
ba0b915 @robertwb Add flag for archaic behavior of globals().
robertwb authored
71 # In previous iterations of Cython, globals() gave the first non-Cython module
72 # globals in the call stack. Sage relies on this behavior for variable injection.
73 old_style_globals = False
74
c7476b5 @robertwb Initial cimport-from-pyx push.
robertwb authored
75 # Allows cimporting from a pyx file without a pxd file.
f42559d @robertwb Comments, test.
robertwb authored
76 cimport_from_pyx = False
c7476b5 @robertwb Initial cimport-from-pyx push.
robertwb authored
77
0e57982 @markflorisson Lower buffer_max_dims to 8
markflorisson authored
78 # max # of dims for buffers -- set lower than number of dimensions in numpy, as
79 # slices are passed by value and involve a lot of copying
80 buffer_max_dims = 8
2191ad0 @dagss Added global compilation option/pragma support to parser and command …
dagss authored
81
9d2837a @scoder use freelists for closure classes
scoder authored
82 # Number of function closure instances to keep in a freelist (0: no freelists)
83 closure_freelist_size = 8
84
b274ea0 @scoder make the NULL-instead-of-None change in tp_clear() optional and off b…
scoder authored
85 # Should tp_clear() set object fields to None instead of clearing them to NULL?
86 clear_to_none = True
87
88
65364b1 @dagss wraparound directive implemented
dagss authored
89 # Declare compiler directives
422a77f naming references changed from 'option' to 'directive'
Peter Alexander authored
90 directive_defaults = {
d2f4df7 @dagss Initial implementation of nonecheck directive; some directive design …
dagss authored
91 'boundscheck' : True,
a223652 @dagss Merge (++, see details)
dagss authored
92 'nonecheck' : False,
efc2e33 @markflorisson initializedcheck directive + uninitialized memslice checking + memory…
markflorisson authored
93 'initializedcheck' : True,
e04c414 Automatic embedding of signatures in docstring (#2)
LisandroDalcin authored
94 'embedsignature' : False,
8f8ef4e @robertwb Compile Cython.Compiler.Parsing.py, auto_cpdef, fix bugs in AlignFunc…
robertwb authored
95 'locals' : {},
96 'auto_cpdef': False,
5cada6c enable cdivision switch for 0.12
Stefan Behnel authored
97 'cdivision': False, # was True before 0.12
43ba295 @robertwb CDP 516 warnings
robertwb authored
98 'cdivision_warnings': False,
4d77dd8 @robertwb control overflow with a directive
robertwb authored
99 'overflowcheck': False,
3ee23f4 @robertwb Directive for overflow folding.
robertwb authored
100 'overflowcheck.fold': True,
a837633 @dalcinl compiler directive to control METH_O and METH_NOARGS flags (ticket #295)
dalcinl authored
101 'always_allow_keywords': False,
7c016d5 implement 'allow_none_for_extension_args' directive for 'not None' an…
Stefan Behnel authored
102 'allow_none_for_extension_args': True,
e8e3a36 @robertwb Compiler directive fixes, add c99 complex directive
robertwb authored
103 'wraparound' : True,
dd37f81 @dalcinl Seamless C99/C++ complex numbers support (ticket #398)
dalcinl authored
104 'ccomplex' : False, # use C99/C++ for complex types and arith
57f327c @dalcinl add compiler directive for user-defined function calling conventions
dalcinl authored
105 'callspec' : "",
55ae33d support 'internal' cdef classes that do not show up in the module dict
Stefan Behnel authored
106 'final' : False,
107 'internal' : False,
a6e074f @robertwb Turn of profiling by default, rename macro.
robertwb authored
108 'profile': False,
73ba98c @Bluehorn Add decorator @gc_no_clear to disable tp_clear slot.
Bluehorn authored
109 'no_gc_clear': False,
e2a07e8 @scoder implement experimental support for line tracing
scoder authored
110 'linetrace': False,
c036607 @scoder implement support for extracting type declarations from signature ann…
scoder authored
111 'annotation_typing': False, # read type declarations from Python function annotations
c585280 @robertwb Enable safe type inferance by default.
robertwb authored
112 'infer_types': None,
75ab0c6 @robertwb Verbose type inference directive.
robertwb authored
113 'infer_types.verbose': False,
74006e3 @dagss merge
dagss authored
114 'autotestdict': True,
ee3e8d2 new autotestdict.{cdef,all} directives that put cdef and non-doctest …
Stefan Behnel authored
115 'autotestdict.cdef': False,
116 'autotestdict.all': False,
1153237 support setting language level (2 or 3) for source code - currently c…
Stefan Behnel authored
117 'language_level': 2,
383b928 @robertwb Create directive for fast __getattr__.
robertwb authored
118 'fast_getattr': False, # Undocumented until we come up with a better way to handle this everywhere.
2111318 @scoder minor cleanup: py2_import option is only useful in Py3 source mode
scoder authored
119 'py2_import': False, # For backward compatibility of Cython's source code in Py3 source mode
1e81abf @robertwb Allow setting a default encoding to ease str/unicode <-> c string con…
robertwb authored
120 'c_string_type': 'bytes',
121 'c_string_encoding': '',
b1f10fa @scoder enable Py_TPFLAGS_HAVE_VERSION_TAG on extension types by default (als…
scoder authored
122 'type_version_tag': True, # enables Py_TPFLAGS_HAVE_VERSION_TAG on extension types
25b65f7 @robertwb Traceback on unraisable exceptions.
robertwb authored
123 'unraisable_tracebacks': False,
f6762fa @robertwb Remove trailing whitespace.
robertwb authored
124
68b2bc0 @scoder fix name setup for package __init__ modules, make sure package is reg…
scoder authored
125 # set __file__ and/or __path__ to known source/target path at import time (instead of not having them available)
126 'set_initial_path' : None, # SOURCEFILE or "/full/path/to/module"
8852368 @scoder provide compiler directive to set __file__ and __path__ from the sour…
scoder authored
127
143113f @robertwb #479, sub-directives via keywords
robertwb authored
128 'warn': None,
129 'warn.undeclared': False,
3f6f0a2 @vitek Add warn.unreachable and remove_unreachable directive
vitek authored
130 'warn.unreachable': True,
4dbd1e0 @vitek Add control flow directives
vitek authored
131 'warn.maybe_uninitialized': False,
132 'warn.unused': False,
133 'warn.unused_arg': False,
134 'warn.unused_result': False,
9e3a2d7 @robertwb Warn for non-trivial type declarators in shared declarations.
robertwb authored
135 'warn.multiple_declarators': True,
3f6f0a2 @vitek Add warn.unreachable and remove_unreachable directive
vitek authored
136
1e94a83 @vitek Simple closure defnode call inlining
vitek authored
137 # optimizations
d70444b @scoder enable compile time DefNode call resolution for nested functions
scoder authored
138 'optimize.inline_defnode_calls': True,
b543eab @scoder allow disabling method call optimisation with a directive
scoder authored
139 'optimize.unpack_method_calls': True, # increases code size when True
d9b3c47 rename "switchcase_transform" to "use_switch"
Alok Singhal authored
140 'optimize.use_switch': True,
1e94a83 @vitek Simple closure defnode call inlining
vitek authored
141
3f6f0a2 @vitek Add warn.unreachable and remove_unreachable directive
vitek authored
142 # remove unreachable code
143 'remove_unreachable': True,
4dd72eb test support for parse tree path assertions
Stefan Behnel authored
144
4dbd1e0 @vitek Add control flow directives
vitek authored
145 # control flow debug directives
146 'control_flow.dot_output': "", # Graphviz output filename
147 'control_flow.dot_annotate_defs': False, # Annotate definitions
148
4dd72eb test support for parse tree path assertions
Stefan Behnel authored
149 # test support
ee0f980 PEP-8-ified the decorator names for parse tree assertions, added a te…
Stefan Behnel authored
150 'test_assert_path_exists' : [],
151 'test_fail_if_path_exists' : [],
7e498e6 @robertwb Work towards #494, binding directive.
robertwb authored
152
153 # experimental, subject to change
621dbe6 @scoder enable 'binding' directive by default when compiling .py files
scoder authored
154 'binding': None,
232d3ca @scoder implement freelist support for extension types with a @cython.freelis…
scoder authored
155 'freelist': 0,
b7c6236 @robertwb Parse files with standard Python grammar.
robertwb authored
156
157 'formal_grammar': False,
2191ad0 @dagss Added global compilation option/pragma support to parser and command …
dagss authored
158 }
159
4dbd1e0 @vitek Add control flow directives
vitek authored
160 # Extra warning directives
161 extra_warnings = {
162 'warn.maybe_uninitialized': True,
163 'warn.unreachable': True,
164 'warn.unused': True,
165 }
166
65ea99f @robertwb multiple-choice directive type
robertwb authored
167 def one_of(*args):
168 def validate(name, value):
169 if value not in args:
170 raise ValueError("%s directive must be one of %s, got '%s'" % (
171 name, args, value))
172 else:
173 return value
174 return validate
175
e6b4ffb @scoder allow alternative spellings for encoding names in c_string_encoding d…
scoder authored
176
177 def normalise_encoding_name(option_name, encoding):
178 """
179 >>> normalise_encoding_name('c_string_encoding', 'ascii')
180 'ascii'
181 >>> normalise_encoding_name('c_string_encoding', 'AsCIi')
182 'ascii'
183 >>> normalise_encoding_name('c_string_encoding', 'us-ascii')
184 'ascii'
185 >>> normalise_encoding_name('c_string_encoding', 'utF8')
186 'utf8'
187 >>> normalise_encoding_name('c_string_encoding', 'utF-8')
188 'utf8'
189 >>> normalise_encoding_name('c_string_encoding', 'deFAuLT')
190 'default'
191 >>> normalise_encoding_name('c_string_encoding', 'default')
192 'default'
193 >>> normalise_encoding_name('c_string_encoding', 'SeriousLyNoSuch--Encoding')
194 'SeriousLyNoSuch--Encoding'
195 """
196 if not encoding:
197 return ''
198 if encoding.lower() in ('default', 'ascii', 'utf8'):
199 return encoding.lower()
200 import codecs
201 try:
202 decoder = codecs.getdecoder(encoding)
203 except LookupError:
204 return encoding # may exists at runtime ...
205 for name in ('ascii', 'utf8'):
206 if codecs.getdecoder(name) == decoder:
207 return name
208 return encoding
209
210
a60c780 @robertwb cdivision pragma as specified for CEP 516
robertwb authored
211 # Override types possibilities above, if needed
9614a25 use True/None/False as infer_types() option values, make 'bint' type …
Stefan Behnel authored
212 directive_types = {
9b57b1c support for 'final' cdef types using a directive decorator
Stefan Behnel authored
213 'final' : bool, # final cdef classes and methods
55ae33d support 'internal' cdef classes that do not show up in the module dict
Stefan Behnel authored
214 'internal' : bool, # cdef class visibility in the module dict
9614a25 use True/None/False as infer_types() option values, make 'bint' type …
Stefan Behnel authored
215 'infer_types' : bool, # values can be True/None/False
621dbe6 @scoder enable 'binding' directive by default when compiling .py files
scoder authored
216 'binding' : bool,
4b61e74 @bhy @cython.cfunc decorator
bhy authored
217 'cfunc' : None, # decorators do not take directive value
c326b2d @bhy @cython.ccall decorator
bhy authored
218 'ccall' : None,
fea7ad6 @scoder implement "@cython.inline" decorator for functions
scoder authored
219 'inline' : None,
ee80d4b @robertwb Static cdef methods.
robertwb authored
220 'staticmethod' : None,
7f563ed @bhy @cython.cclass decorator for class
bhy authored
221 'cclass' : None,
19cdcd6 @robertwb Add @cython.returns(type) decorator.
robertwb authored
222 'returns' : type,
68b2bc0 @scoder fix name setup for package __init__ modules, make sure package is reg…
scoder authored
223 'set_initial_path': str,
232d3ca @scoder implement freelist support for extension types with a @cython.freelis…
scoder authored
224 'freelist': int,
8524b21 @scoder support bytearray as auto encoding string type
scoder authored
225 'c_string_type': one_of('bytes', 'bytearray', 'str', 'unicode'),
e6b4ffb @scoder allow alternative spellings for encoding names in c_string_encoding d…
scoder authored
226 'c_string_encoding': normalise_encoding_name,
227 }
a60c780 @robertwb cdivision pragma as specified for CEP 516
robertwb authored
228
422a77f naming references changed from 'option' to 'directive'
Peter Alexander authored
229 for key, val in directive_defaults.items():
230 if key not in directive_types:
231 directive_types[key] = type(val)
a60c780 @robertwb cdivision pragma as specified for CEP 516
robertwb authored
232
422a77f naming references changed from 'option' to 'directive'
Peter Alexander authored
233 directive_scopes = { # defaults to available everywhere
d12a822 @dagss Functionality for only allowing directives in certain areas
dagss authored
234 # 'module', 'function', 'class', 'with statement'
1c187e8 @vitek Final method support, see ticket #586
vitek authored
235 'final' : ('cclass', 'function'),
fea7ad6 @scoder implement "@cython.inline" decorator for functions
scoder authored
236 'inline' : ('function',),
ee80d4b @robertwb Static cdef methods.
robertwb authored
237 'staticmethod' : ('function',), # FIXME: analysis currently lacks more specific function scope
73ba98c @Bluehorn Add decorator @gc_no_clear to disable tp_clear slot.
Bluehorn authored
238 'no_gc_clear' : ('cclass',),
55ae33d support 'internal' cdef classes that do not show up in the module dict
Stefan Behnel authored
239 'internal' : ('cclass',),
74006e3 @dagss merge
dagss authored
240 'autotestdict' : ('module',),
ee3e8d2 new autotestdict.{cdef,all} directives that put cdef and non-doctest …
Stefan Behnel authored
241 'autotestdict.all' : ('module',),
242 'autotestdict.cdef' : ('module',),
68b2bc0 @scoder fix name setup for package __init__ modules, make sure package is reg…
scoder authored
243 'set_initial_path' : ('module',),
b363f41 optimisation: do not build and test metaclass kwargs if we know the m…
Stefan Behnel authored
244 'test_assert_path_exists' : ('function', 'class', 'cclass'),
245 'test_fail_if_path_exists' : ('function', 'class', 'cclass'),
232d3ca @scoder implement freelist support for extension types with a @cython.freelis…
scoder authored
246 'freelist': ('cclass',),
c036607 @scoder implement support for extracting type declarations from signature ann…
scoder authored
247 'annotation_typing': ('module',), # FIXME: analysis currently lacks more specific function scope
c73a9b2 @robertwb Merge remote-tracking branch 'main/master'
robertwb authored
248 # Avoid scope-specific to/from_py_functions for c_string.
1e81abf @robertwb Allow setting a default encoding to ease str/unicode <-> c string con…
robertwb authored
249 'c_string_type': ('module',),
250 'c_string_encoding': ('module',),
b1f10fa @scoder enable Py_TPFLAGS_HAVE_VERSION_TAG on extension types by default (als…
scoder authored
251 'type_version_tag': ('module', 'cclass'),
fd2c05e @scoder show an error when "language_level" directive is used anywhere below …
scoder authored
252 'language_level': ('module',),
d12a822 @dagss Functionality for only allowing directives in certain areas
dagss authored
253 }
254
2db8ba0 support non-bool options and multiple options as compiler comment dir…
Stefan Behnel authored
255 def parse_directive_value(name, value, relaxed_bool=False):
2f02248 @dagss Changed compiler directive comment format
dagss authored
256 """
257 Parses value as an option value for the given name and returns
ab433f3 'safe' mode for type inference: only infer types that are very unlike…
Stefan Behnel authored
258 the interpreted value. None is returned if the option does not exist.
2f02248 @dagss Changed compiler directive comment format
dagss authored
259
a6b73f6 @scoder enable doctests in Py3 and fix them
scoder authored
260 >>> print(parse_directive_value('nonexisting', 'asdf asdfd'))
2f02248 @dagss Changed compiler directive comment format
dagss authored
261 None
422a77f naming references changed from 'option' to 'directive'
Peter Alexander authored
262 >>> parse_directive_value('boundscheck', 'True')
2f02248 @dagss Changed compiler directive comment format
dagss authored
263 True
422a77f naming references changed from 'option' to 'directive'
Peter Alexander authored
264 >>> parse_directive_value('boundscheck', 'true')
2f02248 @dagss Changed compiler directive comment format
dagss authored
265 Traceback (most recent call last):
266 ...
31fac6c better error output
Stefan Behnel authored
267 ValueError: boundscheck directive must be set to True or False, got 'true'
f6762fa @robertwb Remove trailing whitespace.
robertwb authored
268
e6b4ffb @scoder allow alternative spellings for encoding names in c_string_encoding d…
scoder authored
269 >>> parse_directive_value('c_string_encoding', 'us-ascii')
270 'ascii'
271 >>> parse_directive_value('c_string_type', 'str')
272 'str'
273 >>> parse_directive_value('c_string_type', 'bytes')
274 'bytes'
8524b21 @scoder support bytearray as auto encoding string type
scoder authored
275 >>> parse_directive_value('c_string_type', 'bytearray')
276 'bytearray'
e6b4ffb @scoder allow alternative spellings for encoding names in c_string_encoding d…
scoder authored
277 >>> parse_directive_value('c_string_type', 'unicode')
278 'unicode'
279 >>> parse_directive_value('c_string_type', 'unnicode')
280 Traceback (most recent call last):
8524b21 @scoder support bytearray as auto encoding string type
scoder authored
281 ValueError: c_string_type directive must be one of ('bytes', 'bytearray', 'str', 'unicode'), got 'unnicode'
2f02248 @dagss Changed compiler directive comment format
dagss authored
282 """
422a77f naming references changed from 'option' to 'directive'
Peter Alexander authored
283 type = directive_types.get(name)
2f02248 @dagss Changed compiler directive comment format
dagss authored
284 if not type: return None
31fac6c better error output
Stefan Behnel authored
285 orig_value = value
2f02248 @dagss Changed compiler directive comment format
dagss authored
286 if type is bool:
2db8ba0 support non-bool options and multiple options as compiler comment dir…
Stefan Behnel authored
287 value = str(value)
288 if value == 'True': return True
289 if value == 'False': return False
290 if relaxed_bool:
291 value = value.lower()
292 if value in ("true", "yes"): return True
293 elif value in ("false", "no"): return False
2743fb0 fix tests after changing error output
Stefan Behnel authored
294 raise ValueError("%s directive must be set to True or False, got '%s'" % (
31fac6c better error output
Stefan Behnel authored
295 name, orig_value))
e8e3a36 @robertwb Compiler directive fixes, add c99 complex directive
robertwb authored
296 elif type is int:
297 try:
298 return int(value)
299 except ValueError:
2743fb0 fix tests after changing error output
Stefan Behnel authored
300 raise ValueError("%s directive must be set to an integer, got '%s'" % (
31fac6c better error output
Stefan Behnel authored
301 name, orig_value))
ab433f3 'safe' mode for type inference: only infer types that are very unlike…
Stefan Behnel authored
302 elif type is str:
303 return str(value)
65ea99f @robertwb multiple-choice directive type
robertwb authored
304 elif callable(type):
305 return type(name, value)
2f02248 @dagss Changed compiler directive comment format
dagss authored
306 else:
307 assert False
308
a80790d @craigcitro Make multiple '--directive's on command line cumulative
craigcitro authored
309 def parse_directive_list(s, relaxed_bool=False, ignore_unknown=False,
310 current_settings=None):
2191ad0 @dagss Added global compilation option/pragma support to parser and command …
dagss authored
311 """
bb076b0 @craigcitro seperated -> separated
craigcitro authored
312 Parses a comma-separated list of pragma options. Whitespace
2191ad0 @dagss Added global compilation option/pragma support to parser and command …
dagss authored
313 is not considered.
314
422a77f naming references changed from 'option' to 'directive'
Peter Alexander authored
315 >>> parse_directive_list(' ')
2191ad0 @dagss Added global compilation option/pragma support to parser and command …
dagss authored
316 {}
422a77f naming references changed from 'option' to 'directive'
Peter Alexander authored
317 >>> (parse_directive_list('boundscheck=True') ==
2191ad0 @dagss Added global compilation option/pragma support to parser and command …
dagss authored
318 ... {'boundscheck': True})
319 True
422a77f naming references changed from 'option' to 'directive'
Peter Alexander authored
320 >>> parse_directive_list(' asdf')
2191ad0 @dagss Added global compilation option/pragma support to parser and command …
dagss authored
321 Traceback (most recent call last):
322 ...
323 ValueError: Expected "=" in option "asdf"
422a77f naming references changed from 'option' to 'directive'
Peter Alexander authored
324 >>> parse_directive_list('boundscheck=hey')
2191ad0 @dagss Added global compilation option/pragma support to parser and command …
dagss authored
325 Traceback (most recent call last):
326 ...
31fac6c better error output
Stefan Behnel authored
327 ValueError: boundscheck directive must be set to True or False, got 'hey'
422a77f naming references changed from 'option' to 'directive'
Peter Alexander authored
328 >>> parse_directive_list('unknown=True')
2191ad0 @dagss Added global compilation option/pragma support to parser and command …
dagss authored
329 Traceback (most recent call last):
330 ...
331 ValueError: Unknown option: "unknown"
ce36ba4 @robertwb Implement warn.all (or any_directive.all).
robertwb authored
332 >>> warnings = parse_directive_list('warn.all=True')
333 >>> len(warnings) > 1
334 True
335 >>> sum(warnings.values()) == len(warnings) # all true.
336 True
2191ad0 @dagss Added global compilation option/pragma support to parser and command …
dagss authored
337 """
a80790d @craigcitro Make multiple '--directive's on command line cumulative
craigcitro authored
338 if current_settings is None:
339 result = {}
340 else:
341 result = current_settings
2191ad0 @dagss Added global compilation option/pragma support to parser and command …
dagss authored
342 for item in s.split(','):
343 item = item.strip()
344 if not item: continue
345 if not '=' in item: raise ValueError('Expected "=" in option "%s"' % item)
2db8ba0 support non-bool options and multiple options as compiler comment dir…
Stefan Behnel authored
346 name, value = [ s.strip() for s in item.strip().split('=', 1) ]
ce36ba4 @robertwb Implement warn.all (or any_directive.all).
robertwb authored
347 if name not in directive_defaults:
348 found = False
349 if name.endswith('.all'):
350 prefix = name[:-3]
351 for directive in directive_defaults:
352 if directive.startswith(prefix):
353 found = True
354 parsed_value = parse_directive_value(directive, value, relaxed_bool=relaxed_bool)
355 result[directive] = parsed_value
356 if not found and not ignore_unknown:
6f95dba keep ignoring unknown directives in directive comments
Stefan Behnel authored
357 raise ValueError('Unknown option: "%s"' % name)
358 else:
ce36ba4 @robertwb Implement warn.all (or any_directive.all).
robertwb authored
359 parsed_value = parse_directive_value(name, value, relaxed_bool=relaxed_bool)
6f95dba keep ignoring unknown directives in directive comments
Stefan Behnel authored
360 result[name] = parsed_value
2191ad0 @dagss Added global compilation option/pragma support to parser and command …
dagss authored
361 return result
Something went wrong with that request. Please try again.