Cython has moved to github.
cython-devel
view Cython/Compiler/Options.py @ 1157:075511424c24
Automatic embedding of signatures in docstring (#2)
| author | LisandroDalcin |
|---|---|
| date | Fri Sep 19 16:28:36 2008 +0200 (3 years ago) |
| parents | ac3b586e83ee |
| children | 947f6697b088 |
line source
1 #
2 # Cython - Compilation-wide options and pragma declarations
3 #
5 cache_builtins = 1 # Perform lookups on builtin names only once
7 embed_pos_in_docstring = 0
8 gcc_branch_hints = 1
10 pre_import = None
11 docstrings = True
13 # This is a SAGE-specific option that will
14 # cause Cython to incref local variables before
15 # performing a binary operation on them, for
16 # safe detection of inplace operators.
17 incref_local_binop = 0
19 # Decref global variables in this module on exit for garbage collection.
20 # 0: None, 1+: interned objects, 2+: cdef globals, 3+: types objects
21 # Mostly for reducing noise for Valgrind, only executes at process exit
22 # (when all memory will be reclaimed anyways).
23 generate_cleanup_code = 0
25 annotate = 0
27 # This will convert statements of the form "for i in range(...)"
28 # to "for i from ..." when i is a cdef'd integer type, and the direction
29 # (i.e. sign of step) can be determined.
30 # WARNING: This may change the symantics if the range causes assignment to
31 # i to overflow. Specifically, if this option is set, an error will be
32 # raised before the loop is entered, wheras without this option the loop
33 # will execute util a overflowing value is encountered.
34 convert_range = 1
36 # Enable this to allow one to write your_module.foo = ... to overwrite the
37 # definition if the cpdef function foo, at the cost of an extra dictionary
38 # lookup on every call.
39 # If this is 0 it simply creates a wrapper.
40 lookup_module_cpdef = 0
42 # This will set local variables to None rather than NULL which may cause
43 # surpress what would be an UnboundLocalError in pure Python but eliminates
44 # checking for NULL on every use, and can decref rather than xdecref at the end.
45 # WARNING: This is a work in progress, may currently segfault.
46 init_local_none = 1
48 # Optimize no argument and one argument methods by using the METH_O and METH_NOARGS
49 # calling conventions. These are faster calling conventions, but disallow the use of
50 # keywords (which, admittedly, are of little use in these cases).
51 optimize_simple_methods = 1
53 # Append the c file and line number to the traceback for exceptions.
54 c_line_in_traceback = 1
57 # Declare pragmas
58 option_types = {
59 'boundscheck' : bool,
60 'embedsignature' : bool,
61 }
63 option_defaults = {
64 'boundscheck' : True,
65 'embedsignature' : False,
66 }
68 def parse_option_value(name, value):
69 """
70 Parses value as an option value for the given name and returns
71 the interpreted value. None is returned if the option does not exist.
73 >>> print parse_option_value('nonexisting', 'asdf asdfd')
74 None
75 >>> parse_option_value('boundscheck', 'True')
76 True
77 >>> parse_option_value('boundscheck', 'true')
78 Traceback (most recent call last):
79 ...
80 ValueError: boundscheck directive must be set to True or False
82 """
83 type = option_types.get(name)
84 if not type: return None
85 if type is bool:
86 if value == "True": return True
87 elif value == "False": return False
88 else: raise ValueError("%s directive must be set to True or False" % name)
89 else:
90 assert False
92 def parse_option_list(s):
93 """
94 Parses a comma-seperated list of pragma options. Whitespace
95 is not considered.
97 >>> parse_option_list(' ')
98 {}
99 >>> (parse_option_list('boundscheck=True') ==
100 ... {'boundscheck': True})
101 True
102 >>> parse_option_list(' asdf')
103 Traceback (most recent call last):
104 ...
105 ValueError: Expected "=" in option "asdf"
106 >>> parse_option_list('boundscheck=hey')
107 Traceback (most recent call last):
108 ...
109 ValueError: Must pass a boolean value for option "boundscheck"
110 >>> parse_option_list('unknown=True')
111 Traceback (most recent call last):
112 ...
113 ValueError: Unknown option: "unknown"
114 """
115 result = {}
116 for item in s.split(','):
117 item = item.strip()
118 if not item: continue
119 if not '=' in item: raise ValueError('Expected "=" in option "%s"' % item)
120 name, value = item.strip().split('=')
121 try:
122 type = option_types[name]
123 except KeyError:
124 raise ValueError('Unknown option: "%s"' % name)
125 if type is bool:
126 value = value.lower()
127 if value in ('true', 'yes'):
128 value = True
129 elif value in ('false', 'no'):
130 value = False
131 else: raise ValueError('Must pass a boolean value for option "%s"' % name)
132 result[name] = value
133 else:
134 assert False
135 return result
