Cython 3.1.0a1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (301) hide show
  1. Cython/Build/BuildExecutable.py +169 -0
  2. Cython/Build/Cache.py +199 -0
  3. Cython/Build/Cythonize.py +250 -0
  4. Cython/Build/Dependencies.py +1275 -0
  5. Cython/Build/Distutils.py +1 -0
  6. Cython/Build/Inline.py +342 -0
  7. Cython/Build/IpythonMagic.py +560 -0
  8. Cython/Build/Tests/TestCyCache.py +119 -0
  9. Cython/Build/Tests/TestCythonizeArgsParser.py +481 -0
  10. Cython/Build/Tests/TestDependencies.py +133 -0
  11. Cython/Build/Tests/TestInline.py +112 -0
  12. Cython/Build/Tests/TestIpythonMagic.py +287 -0
  13. Cython/Build/Tests/TestRecythonize.py +212 -0
  14. Cython/Build/Tests/TestStripLiterals.py +155 -0
  15. Cython/Build/Tests/__init__.py +1 -0
  16. Cython/Build/__init__.py +8 -0
  17. Cython/CodeWriter.py +811 -0
  18. Cython/Compiler/AnalysedTreeTransforms.py +97 -0
  19. Cython/Compiler/Annotate.py +326 -0
  20. Cython/Compiler/AutoDocTransforms.py +314 -0
  21. Cython/Compiler/Buffer.py +680 -0
  22. Cython/Compiler/Builtin.py +862 -0
  23. Cython/Compiler/CmdLine.py +243 -0
  24. Cython/Compiler/Code.pxd +145 -0
  25. Cython/Compiler/Code.py +3328 -0
  26. Cython/Compiler/CodeGeneration.py +33 -0
  27. Cython/Compiler/CythonScope.py +179 -0
  28. Cython/Compiler/Dataclass.py +868 -0
  29. Cython/Compiler/DebugFlags.py +21 -0
  30. Cython/Compiler/Errors.py +295 -0
  31. Cython/Compiler/ExprNodes.py +15051 -0
  32. Cython/Compiler/FlowControl.pxd +97 -0
  33. Cython/Compiler/FlowControl.py +1438 -0
  34. Cython/Compiler/FusedNode.py +998 -0
  35. Cython/Compiler/Future.py +16 -0
  36. Cython/Compiler/Interpreter.py +57 -0
  37. Cython/Compiler/Lexicon.py +340 -0
  38. Cython/Compiler/LineTable.py +114 -0
  39. Cython/Compiler/Main.py +779 -0
  40. Cython/Compiler/MatchCaseNodes.py +259 -0
  41. Cython/Compiler/MemoryView.py +860 -0
  42. Cython/Compiler/ModuleNode.py +4065 -0
  43. Cython/Compiler/Naming.py +369 -0
  44. Cython/Compiler/Nodes.py +10557 -0
  45. Cython/Compiler/Optimize.py +5269 -0
  46. Cython/Compiler/Options.py +828 -0
  47. Cython/Compiler/ParseTreeTransforms.pxd +78 -0
  48. Cython/Compiler/ParseTreeTransforms.py +4441 -0
  49. Cython/Compiler/Parsing.pxd +9 -0
  50. Cython/Compiler/Parsing.py +4797 -0
  51. Cython/Compiler/Pipeline.py +425 -0
  52. Cython/Compiler/PyrexTypes.py +5572 -0
  53. Cython/Compiler/Pythran.py +223 -0
  54. Cython/Compiler/Scanning.pxd +40 -0
  55. Cython/Compiler/Scanning.py +574 -0
  56. Cython/Compiler/StringEncoding.py +347 -0
  57. Cython/Compiler/Symtab.py +2998 -0
  58. Cython/Compiler/Tests/TestBuffer.py +105 -0
  59. Cython/Compiler/Tests/TestBuiltin.py +72 -0
  60. Cython/Compiler/Tests/TestCmdLine.py +573 -0
  61. Cython/Compiler/Tests/TestCode.py +86 -0
  62. Cython/Compiler/Tests/TestFlowControl.py +65 -0
  63. Cython/Compiler/Tests/TestGrammar.py +202 -0
  64. Cython/Compiler/Tests/TestMemView.py +71 -0
  65. Cython/Compiler/Tests/TestParseTreeTransforms.py +285 -0
  66. Cython/Compiler/Tests/TestScanning.py +134 -0
  67. Cython/Compiler/Tests/TestSignatureMatching.py +73 -0
  68. Cython/Compiler/Tests/TestStringEncoding.py +33 -0
  69. Cython/Compiler/Tests/TestTreeFragment.py +63 -0
  70. Cython/Compiler/Tests/TestTreePath.py +93 -0
  71. Cython/Compiler/Tests/TestTypes.py +75 -0
  72. Cython/Compiler/Tests/TestUtilityLoad.py +112 -0
  73. Cython/Compiler/Tests/TestVisitor.py +61 -0
  74. Cython/Compiler/Tests/Utils.py +36 -0
  75. Cython/Compiler/Tests/__init__.py +1 -0
  76. Cython/Compiler/TreeFragment.py +278 -0
  77. Cython/Compiler/TreePath.py +290 -0
  78. Cython/Compiler/TypeInference.py +584 -0
  79. Cython/Compiler/TypeSlots.py +1181 -0
  80. Cython/Compiler/UFuncs.py +311 -0
  81. Cython/Compiler/UtilNodes.py +387 -0
  82. Cython/Compiler/UtilityCode.py +274 -0
  83. Cython/Compiler/Version.py +8 -0
  84. Cython/Compiler/Visitor.pxd +53 -0
  85. Cython/Compiler/Visitor.py +861 -0
  86. Cython/Compiler/__init__.py +1 -0
  87. Cython/Coverage.py +443 -0
  88. Cython/Debugger/Cygdb.py +179 -0
  89. Cython/Debugger/DebugWriter.py +82 -0
  90. Cython/Debugger/Tests/TestLibCython.py +275 -0
  91. Cython/Debugger/Tests/__init__.py +1 -0
  92. Cython/Debugger/Tests/cfuncs.c +8 -0
  93. Cython/Debugger/Tests/codefile +49 -0
  94. Cython/Debugger/Tests/test_libcython_in_gdb.py +578 -0
  95. Cython/Debugger/Tests/test_libpython_in_gdb.py +90 -0
  96. Cython/Debugger/__init__.py +1 -0
  97. Cython/Debugger/libcython.py +1549 -0
  98. Cython/Debugger/libpython.py +2821 -0
  99. Cython/Debugging.py +20 -0
  100. Cython/Distutils/__init__.py +2 -0
  101. Cython/Distutils/build_ext.py +137 -0
  102. Cython/Distutils/extension.py +96 -0
  103. Cython/Distutils/old_build_ext.py +351 -0
  104. Cython/Includes/cpython/__init__.pxd +173 -0
  105. Cython/Includes/cpython/array.pxd +174 -0
  106. Cython/Includes/cpython/bool.pxd +37 -0
  107. Cython/Includes/cpython/buffer.pxd +112 -0
  108. Cython/Includes/cpython/bytearray.pxd +33 -0
  109. Cython/Includes/cpython/bytes.pxd +200 -0
  110. Cython/Includes/cpython/cellobject.pxd +35 -0
  111. Cython/Includes/cpython/ceval.pxd +8 -0
  112. Cython/Includes/cpython/codecs.pxd +121 -0
  113. Cython/Includes/cpython/complex.pxd +55 -0
  114. Cython/Includes/cpython/contextvars.pxd +141 -0
  115. Cython/Includes/cpython/conversion.pxd +36 -0
  116. Cython/Includes/cpython/datetime.pxd +384 -0
  117. Cython/Includes/cpython/descr.pxd +26 -0
  118. Cython/Includes/cpython/dict.pxd +187 -0
  119. Cython/Includes/cpython/exc.pxd +263 -0
  120. Cython/Includes/cpython/fileobject.pxd +57 -0
  121. Cython/Includes/cpython/float.pxd +47 -0
  122. Cython/Includes/cpython/function.pxd +65 -0
  123. Cython/Includes/cpython/genobject.pxd +25 -0
  124. Cython/Includes/cpython/getargs.pxd +12 -0
  125. Cython/Includes/cpython/instance.pxd +25 -0
  126. Cython/Includes/cpython/iterator.pxd +36 -0
  127. Cython/Includes/cpython/iterobject.pxd +24 -0
  128. Cython/Includes/cpython/list.pxd +92 -0
  129. Cython/Includes/cpython/long.pxd +149 -0
  130. Cython/Includes/cpython/longintrepr.pxd +19 -0
  131. Cython/Includes/cpython/mapping.pxd +63 -0
  132. Cython/Includes/cpython/marshal.pxd +66 -0
  133. Cython/Includes/cpython/mem.pxd +120 -0
  134. Cython/Includes/cpython/memoryview.pxd +50 -0
  135. Cython/Includes/cpython/method.pxd +49 -0
  136. Cython/Includes/cpython/module.pxd +208 -0
  137. Cython/Includes/cpython/number.pxd +258 -0
  138. Cython/Includes/cpython/object.pxd +433 -0
  139. Cython/Includes/cpython/pycapsule.pxd +143 -0
  140. Cython/Includes/cpython/pylifecycle.pxd +68 -0
  141. Cython/Includes/cpython/pyport.pxd +8 -0
  142. Cython/Includes/cpython/pystate.pxd +95 -0
  143. Cython/Includes/cpython/pythread.pxd +53 -0
  144. Cython/Includes/cpython/ref.pxd +67 -0
  145. Cython/Includes/cpython/sequence.pxd +134 -0
  146. Cython/Includes/cpython/set.pxd +119 -0
  147. Cython/Includes/cpython/slice.pxd +70 -0
  148. Cython/Includes/cpython/time.pxd +129 -0
  149. Cython/Includes/cpython/tuple.pxd +72 -0
  150. Cython/Includes/cpython/type.pxd +53 -0
  151. Cython/Includes/cpython/unicode.pxd +639 -0
  152. Cython/Includes/cpython/version.pxd +32 -0
  153. Cython/Includes/cpython/weakref.pxd +42 -0
  154. Cython/Includes/libc/__init__.pxd +1 -0
  155. Cython/Includes/libc/complex.pxd +35 -0
  156. Cython/Includes/libc/errno.pxd +127 -0
  157. Cython/Includes/libc/float.pxd +43 -0
  158. Cython/Includes/libc/limits.pxd +28 -0
  159. Cython/Includes/libc/locale.pxd +46 -0
  160. Cython/Includes/libc/math.pxd +209 -0
  161. Cython/Includes/libc/setjmp.pxd +10 -0
  162. Cython/Includes/libc/signal.pxd +64 -0
  163. Cython/Includes/libc/stddef.pxd +9 -0
  164. Cython/Includes/libc/stdint.pxd +105 -0
  165. Cython/Includes/libc/stdio.pxd +80 -0
  166. Cython/Includes/libc/stdlib.pxd +72 -0
  167. Cython/Includes/libc/string.pxd +50 -0
  168. Cython/Includes/libc/time.pxd +47 -0
  169. Cython/Includes/libcpp/__init__.pxd +4 -0
  170. Cython/Includes/libcpp/algorithm.pxd +320 -0
  171. Cython/Includes/libcpp/any.pxd +16 -0
  172. Cython/Includes/libcpp/atomic.pxd +59 -0
  173. Cython/Includes/libcpp/bit.pxd +29 -0
  174. Cython/Includes/libcpp/cast.pxd +12 -0
  175. Cython/Includes/libcpp/cmath.pxd +518 -0
  176. Cython/Includes/libcpp/complex.pxd +106 -0
  177. Cython/Includes/libcpp/deque.pxd +165 -0
  178. Cython/Includes/libcpp/execution.pxd +15 -0
  179. Cython/Includes/libcpp/forward_list.pxd +63 -0
  180. Cython/Includes/libcpp/functional.pxd +26 -0
  181. Cython/Includes/libcpp/iterator.pxd +34 -0
  182. Cython/Includes/libcpp/limits.pxd +61 -0
  183. Cython/Includes/libcpp/list.pxd +117 -0
  184. Cython/Includes/libcpp/map.pxd +252 -0
  185. Cython/Includes/libcpp/memory.pxd +115 -0
  186. Cython/Includes/libcpp/numbers.pxd +15 -0
  187. Cython/Includes/libcpp/numeric.pxd +131 -0
  188. Cython/Includes/libcpp/optional.pxd +34 -0
  189. Cython/Includes/libcpp/pair.pxd +1 -0
  190. Cython/Includes/libcpp/queue.pxd +25 -0
  191. Cython/Includes/libcpp/random.pxd +166 -0
  192. Cython/Includes/libcpp/set.pxd +228 -0
  193. Cython/Includes/libcpp/stack.pxd +11 -0
  194. Cython/Includes/libcpp/string.pxd +333 -0
  195. Cython/Includes/libcpp/typeindex.pxd +15 -0
  196. Cython/Includes/libcpp/typeinfo.pxd +10 -0
  197. Cython/Includes/libcpp/unordered_map.pxd +193 -0
  198. Cython/Includes/libcpp/unordered_set.pxd +152 -0
  199. Cython/Includes/libcpp/utility.pxd +30 -0
  200. Cython/Includes/libcpp/vector.pxd +167 -0
  201. Cython/Includes/openmp.pxd +50 -0
  202. Cython/Includes/posix/__init__.pxd +1 -0
  203. Cython/Includes/posix/dlfcn.pxd +14 -0
  204. Cython/Includes/posix/fcntl.pxd +86 -0
  205. Cython/Includes/posix/ioctl.pxd +4 -0
  206. Cython/Includes/posix/mman.pxd +101 -0
  207. Cython/Includes/posix/resource.pxd +57 -0
  208. Cython/Includes/posix/select.pxd +21 -0
  209. Cython/Includes/posix/signal.pxd +73 -0
  210. Cython/Includes/posix/stat.pxd +98 -0
  211. Cython/Includes/posix/stdio.pxd +37 -0
  212. Cython/Includes/posix/stdlib.pxd +29 -0
  213. Cython/Includes/posix/strings.pxd +9 -0
  214. Cython/Includes/posix/time.pxd +71 -0
  215. Cython/Includes/posix/types.pxd +30 -0
  216. Cython/Includes/posix/uio.pxd +26 -0
  217. Cython/Includes/posix/unistd.pxd +271 -0
  218. Cython/Includes/posix/wait.pxd +38 -0
  219. Cython/Plex/Actions.pxd +24 -0
  220. Cython/Plex/Actions.py +119 -0
  221. Cython/Plex/DFA.pxd +14 -0
  222. Cython/Plex/DFA.py +164 -0
  223. Cython/Plex/Errors.py +48 -0
  224. Cython/Plex/Lexicons.py +178 -0
  225. Cython/Plex/Machines.pxd +36 -0
  226. Cython/Plex/Machines.py +238 -0
  227. Cython/Plex/Regexps.py +539 -0
  228. Cython/Plex/Scanners.pxd +47 -0
  229. Cython/Plex/Scanners.py +360 -0
  230. Cython/Plex/Transitions.pxd +14 -0
  231. Cython/Plex/Transitions.py +239 -0
  232. Cython/Plex/__init__.py +34 -0
  233. Cython/Runtime/__init__.py +1 -0
  234. Cython/Runtime/refnanny.pyx +261 -0
  235. Cython/Shadow.py +656 -0
  236. Cython/Shadow.pyi +521 -0
  237. Cython/StringIOTree.py +170 -0
  238. Cython/Tempita/__init__.py +4 -0
  239. Cython/Tempita/_looper.py +154 -0
  240. Cython/Tempita/_tempita.py +1091 -0
  241. Cython/TestUtils.py +417 -0
  242. Cython/Tests/TestCodeWriter.py +128 -0
  243. Cython/Tests/TestCythonUtils.py +202 -0
  244. Cython/Tests/TestJediTyper.py +223 -0
  245. Cython/Tests/TestShadow.py +114 -0
  246. Cython/Tests/TestStringIOTree.py +67 -0
  247. Cython/Tests/TestTestUtils.py +90 -0
  248. Cython/Tests/__init__.py +1 -0
  249. Cython/Tests/xmlrunner.py +390 -0
  250. Cython/Utility/AsyncGen.c +1263 -0
  251. Cython/Utility/Buffer.c +875 -0
  252. Cython/Utility/Builtins.c +660 -0
  253. Cython/Utility/CConvert.pyx +134 -0
  254. Cython/Utility/CMath.c +95 -0
  255. Cython/Utility/CommonStructures.c +139 -0
  256. Cython/Utility/Complex.c +378 -0
  257. Cython/Utility/Coroutine.c +2413 -0
  258. Cython/Utility/CpdefEnums.pyx +108 -0
  259. Cython/Utility/CppConvert.pyx +279 -0
  260. Cython/Utility/CppSupport.cpp +133 -0
  261. Cython/Utility/CythonFunction.c +1851 -0
  262. Cython/Utility/Dataclasses.c +185 -0
  263. Cython/Utility/Dataclasses.py +112 -0
  264. Cython/Utility/Embed.c +125 -0
  265. Cython/Utility/Exceptions.c +1017 -0
  266. Cython/Utility/ExtensionTypes.c +797 -0
  267. Cython/Utility/FunctionArguments.c +573 -0
  268. Cython/Utility/ImportExport.c +912 -0
  269. Cython/Utility/MemoryView.pyx +1478 -0
  270. Cython/Utility/MemoryView_C.c +992 -0
  271. Cython/Utility/ModuleSetupCode.c +2501 -0
  272. Cython/Utility/NumpyImportArray.c +46 -0
  273. Cython/Utility/ObjectHandling.c +3054 -0
  274. Cython/Utility/Optimize.c +1533 -0
  275. Cython/Utility/Overflow.c +404 -0
  276. Cython/Utility/Printing.c +86 -0
  277. Cython/Utility/Profile.c +660 -0
  278. Cython/Utility/StringTools.c +1206 -0
  279. Cython/Utility/TestCyUtilityLoader.pyx +8 -0
  280. Cython/Utility/TestCythonScope.pyx +75 -0
  281. Cython/Utility/TestUtilityLoader.c +12 -0
  282. Cython/Utility/TypeConversion.c +1329 -0
  283. Cython/Utility/UFuncs.pyx +50 -0
  284. Cython/Utility/UFuncs_C.c +89 -0
  285. Cython/Utility/__init__.py +28 -0
  286. Cython/Utility/arrayarray.h +143 -0
  287. Cython/Utils.py +687 -0
  288. Cython/__init__.py +10 -0
  289. Cython/__init__.pyi +7 -0
  290. Cython/py.typed +0 -0
  291. Cython-3.1.0a1.dist-info/COPYING.txt +19 -0
  292. Cython-3.1.0a1.dist-info/LICENSE.txt +176 -0
  293. Cython-3.1.0a1.dist-info/METADATA +67 -0
  294. Cython-3.1.0a1.dist-info/RECORD +301 -0
  295. Cython-3.1.0a1.dist-info/WHEEL +5 -0
  296. Cython-3.1.0a1.dist-info/entry_points.txt +4 -0
  297. Cython-3.1.0a1.dist-info/top_level.txt +3 -0
  298. cython.py +29 -0
  299. pyximport/__init__.py +4 -0
  300. pyximport/pyxbuild.py +160 -0
  301. pyximport/pyximport.py +482 -0
@@ -0,0 +1,828 @@
1
+ #
2
+ # Cython - Compilation-wide options and pragma declarations
3
+ #
4
+
5
+
6
+ import os
7
+
8
+ from .. import Utils
9
+
10
+
11
+ class ShouldBeFromDirective:
12
+
13
+ known_directives = []
14
+
15
+ def __init__(self, options_name, directive_name=None, disallow=False):
16
+ self.options_name = options_name
17
+ self.directive_name = directive_name or options_name
18
+ self.disallow = disallow
19
+ self.known_directives.append(self)
20
+
21
+ def __nonzero__(self):
22
+ self._bad_access()
23
+
24
+ def __int__(self):
25
+ self._bad_access()
26
+
27
+ def _bad_access(self):
28
+ raise RuntimeError(repr(self))
29
+
30
+ def __repr__(self):
31
+ return "Illegal access of '%s' from Options module rather than directive '%s'" % (
32
+ self.options_name, self.directive_name)
33
+
34
+
35
+ """
36
+ The members of this module are documented using autodata in
37
+ Cython/docs/src/reference/compilation.rst.
38
+ See https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#directive-autoattribute
39
+ for how autodata works.
40
+ Descriptions of those members should start with a #:
41
+ Donc forget to keep the docs in sync by removing and adding
42
+ the members in both this file and the .rst file.
43
+ """
44
+
45
+ #: Whether or not to include docstring in the Python extension. If False, the binary size
46
+ #: will be smaller, but the ``__doc__`` attribute of any class or function will be an
47
+ #: empty string.
48
+ docstrings = True
49
+
50
+ #: Embed the source code position in the docstrings of functions and classes.
51
+ embed_pos_in_docstring = False
52
+
53
+ # undocumented
54
+ pre_import = None
55
+
56
+ #: Decref global variables in each module on exit for garbage collection.
57
+ #: 0: None, 1+: interned objects, 2+: cdef globals, 3+: types objects
58
+ #: Mostly for reducing noise in Valgrind as it typically executes at process exit
59
+ #: (when all memory will be reclaimed anyways).
60
+ #: Note that directly or indirectly executed cleanup code that makes use of global
61
+ #: variables or types may no longer be safe when enabling the respective level since
62
+ #: there is no guaranteed order in which the (reference counted) objects will
63
+ #: be cleaned up. The order can change due to live references and reference cycles.
64
+ generate_cleanup_code = False
65
+
66
+ #: Should tp_clear() set object fields to None instead of clearing them to NULL?
67
+ clear_to_none = True
68
+
69
+ #: Generate an annotated HTML version of the input source files for debugging and optimisation purposes.
70
+ #: This has the same effect as the ``annotate`` argument in :func:`cythonize`.
71
+ annotate = False
72
+
73
+ # When annotating source files in HTML, include coverage information from
74
+ # this file.
75
+ annotate_coverage_xml = None
76
+
77
+ #: This will abort the compilation on the first error occurred rather than trying
78
+ #: to keep going and printing further error messages.
79
+ fast_fail = False
80
+
81
+ #: Turn all warnings into errors.
82
+ warning_errors = False
83
+
84
+ #: Make unknown names an error. Python raises a NameError when
85
+ #: encountering unknown names at runtime, whereas this option makes
86
+ #: them a compile time error. If you want full Python compatibility,
87
+ #: you should disable this option and also 'cache_builtins'.
88
+ error_on_unknown_names = True
89
+
90
+ #: Make uninitialized local variable reference a compile time error.
91
+ #: Python raises UnboundLocalError at runtime, whereas this option makes
92
+ #: them a compile time error. Note that this option affects only variables
93
+ #: of "python object" type.
94
+ error_on_uninitialized = True
95
+
96
+ #: This will convert statements of the form ``for i in range(...)``
97
+ #: to ``for i from ...`` when ``i`` is a C integer type, and the direction
98
+ #: (i.e. sign of step) can be determined.
99
+ #: WARNING: This may change the semantics if the range causes assignment to
100
+ #: i to overflow. Specifically, if this option is set, an error will be
101
+ #: raised before the loop is entered, whereas without this option the loop
102
+ #: will execute until an overflowing value is encountered.
103
+ convert_range = True
104
+
105
+ #: Perform lookups on builtin names only once, at module initialisation
106
+ #: time. This will prevent the module from getting imported if a
107
+ #: builtin name that it uses cannot be found during initialisation.
108
+ #: Default is True.
109
+ #: Note that some legacy builtins are automatically remapped
110
+ #: from their Python 2 names to their Python 3 names by Cython
111
+ #: when building in Python 3.x,
112
+ #: so that they do not get in the way even if this option is enabled.
113
+ cache_builtins = True
114
+
115
+ #: Generate branch prediction hints to speed up error handling etc.
116
+ gcc_branch_hints = True
117
+
118
+ #: Enable this to allow one to write ``your_module.foo = ...`` to overwrite the
119
+ #: definition if the cpdef function foo, at the cost of an extra dictionary
120
+ #: lookup on every call.
121
+ #: If this is false it generates only the Python wrapper and no override check.
122
+ lookup_module_cpdef = False
123
+
124
+ #: Whether or not to embed the Python interpreter, for use in making a
125
+ #: standalone executable or calling from external libraries.
126
+ #: This will provide a C function which initialises the interpreter and
127
+ #: executes the body of this module.
128
+ #: See `this demo <https://github.com/cython/cython/tree/master/Demos/embed>`_
129
+ #: for a concrete example.
130
+ #: If true, the initialisation function is the C main() function, but
131
+ #: this option can also be set to a non-empty string to provide a function name explicitly.
132
+ #: Default is False.
133
+ embed = None
134
+
135
+ # In previous iterations of Cython, globals() gave the first non-Cython module
136
+ # globals in the call stack. Sage relies on this behavior for variable injection.
137
+ old_style_globals = ShouldBeFromDirective('old_style_globals')
138
+
139
+ #: Allows cimporting from a pyx file without a pxd file.
140
+ cimport_from_pyx = False
141
+
142
+ #: Maximum number of dimensions for buffers -- set lower than number of
143
+ #: dimensions in numpy, as
144
+ #: slices are passed by value and involve a lot of copying.
145
+ buffer_max_dims = 8
146
+
147
+ #: Number of function closure instances to keep in a freelist (0: no freelists)
148
+ closure_freelist_size = 8
149
+
150
+
151
+ def get_directive_defaults():
152
+ # To add an item to this list, all accesses should be changed to use the new
153
+ # directive, and the global option itself should be set to an instance of
154
+ # ShouldBeFromDirective.
155
+ for old_option in ShouldBeFromDirective.known_directives:
156
+ value = globals().get(old_option.options_name)
157
+ assert old_option.directive_name in _directive_defaults
158
+ if not isinstance(value, ShouldBeFromDirective):
159
+ if old_option.disallow:
160
+ raise RuntimeError(
161
+ "Option '%s' must be set from directive '%s'" % (
162
+ old_option.option_name, old_option.directive_name))
163
+ else:
164
+ # Warn?
165
+ _directive_defaults[old_option.directive_name] = value
166
+ return _directive_defaults
167
+
168
+ def copy_inherited_directives(outer_directives, **new_directives):
169
+ # A few directives are not copied downwards and this function removes them.
170
+ # For example, test_assert_path_exists and test_fail_if_path_exists should not be inherited
171
+ # otherwise they can produce very misleading test failures
172
+ new_directives_out = dict(outer_directives)
173
+ for name in ('test_assert_path_exists', 'test_fail_if_path_exists', 'test_assert_c_code_has', 'test_fail_if_c_code_has'):
174
+ new_directives_out.pop(name, None)
175
+ new_directives_out.update(new_directives)
176
+ return new_directives_out
177
+
178
+
179
+ def copy_for_internal(outer_directives):
180
+ # Reset some directives that users should not control for internal code.
181
+ return copy_inherited_directives(
182
+ outer_directives,
183
+ binding=False,
184
+ profile=False,
185
+ linetrace=False,
186
+ )
187
+
188
+
189
+ # Declare compiler directives
190
+ _directive_defaults = {
191
+ 'binding': True, # was False before 3.0
192
+ 'boundscheck' : True,
193
+ 'nonecheck' : False,
194
+ 'initializedcheck' : True,
195
+ 'freethreading_compatible': False,
196
+ 'embedsignature': False,
197
+ 'embedsignature.format': 'c',
198
+ 'auto_cpdef': False,
199
+ 'auto_pickle': None,
200
+ 'cdivision': False, # was True before 0.12
201
+ 'cdivision_warnings': False,
202
+ 'cpow': None, # was True before 3.0
203
+ # None (not set by user) is treated as slightly different from False
204
+ 'c_api_binop_methods': False, # was True before 3.0
205
+ 'overflowcheck': False,
206
+ 'overflowcheck.fold': True,
207
+ 'always_allow_keywords': True,
208
+ 'allow_none_for_extension_args': True,
209
+ 'wraparound' : True,
210
+ 'ccomplex' : False, # use C99/C++ for complex types and arith
211
+ 'callspec' : "",
212
+ 'nogil' : False,
213
+ 'gil' : False,
214
+ 'with_gil' : False,
215
+ 'profile': False,
216
+ 'linetrace': False,
217
+ 'emit_code_comments': True, # copy original source code into C code comments
218
+ 'annotation_typing': True, # read type declarations from Python function annotations
219
+ 'infer_types': None,
220
+ 'infer_types.verbose': False,
221
+ 'autotestdict': True,
222
+ 'autotestdict.cdef': False,
223
+ 'autotestdict.all': False,
224
+ 'language_level': None,
225
+ 'fast_getattr': False, # Undocumented until we come up with a better way to handle this everywhere.
226
+ 'py2_import': False, # For backward compatibility of Cython's source code in Py3 source mode
227
+ 'preliminary_late_includes_cy28': False, # Temporary directive in 0.28, to be removed in a later version (see GH#2079).
228
+ 'iterable_coroutine': False, # Make async coroutines backwards compatible with the old asyncio yield-from syntax.
229
+ 'c_string_type': 'bytes',
230
+ 'c_string_encoding': '',
231
+ 'type_version_tag': True, # enables Py_TPFLAGS_HAVE_VERSION_TAG on extension types
232
+ 'unraisable_tracebacks': True,
233
+ 'old_style_globals': False,
234
+ 'np_pythran': False,
235
+ 'fast_gil': False,
236
+ 'cpp_locals': False, # uses std::optional for C++ locals, so that they work more like Python locals
237
+ 'legacy_implicit_noexcept': False,
238
+
239
+ # set __file__ and/or __path__ to known source/target path at import time (instead of not having them available)
240
+ 'set_initial_path' : None, # SOURCEFILE or "/full/path/to/module"
241
+
242
+ 'warn': None,
243
+ 'warn.undeclared': False,
244
+ 'warn.unreachable': True,
245
+ 'warn.maybe_uninitialized': False,
246
+ 'warn.unused': False,
247
+ 'warn.unused_arg': False,
248
+ 'warn.unused_result': False,
249
+ 'warn.multiple_declarators': True,
250
+ 'warn.deprecated.DEF': False,
251
+ 'warn.deprecated.IF': True,
252
+ 'show_performance_hints': True,
253
+
254
+ # optimizations
255
+ 'optimize.inline_defnode_calls': True,
256
+ 'optimize.unpack_method_calls': True, # increases code size when True
257
+ 'optimize.unpack_method_calls_in_pyinit': False, # uselessly increases code size when True
258
+ 'optimize.use_switch': True,
259
+
260
+ # remove unreachable code
261
+ 'remove_unreachable': True,
262
+
263
+ # control flow debug directives
264
+ 'control_flow.dot_output': "", # Graphviz output filename
265
+ 'control_flow.dot_annotate_defs': False, # Annotate definitions
266
+
267
+ # test support
268
+ 'test_assert_path_exists' : [],
269
+ 'test_fail_if_path_exists' : [],
270
+ 'test_assert_c_code_has' : [],
271
+ 'test_fail_if_c_code_has' : [],
272
+
273
+ # experimental, subject to change
274
+ 'formal_grammar': False,
275
+ }
276
+
277
+ # Extra warning directives
278
+ extra_warnings = {
279
+ 'warn.maybe_uninitialized': True,
280
+ 'warn.unreachable': True,
281
+ 'warn.unused': True,
282
+ }
283
+
284
+ def one_of(*args, map=None):
285
+ def validate(name, value):
286
+ if map is not None:
287
+ value = map.get(value, value)
288
+ if value not in args:
289
+ raise ValueError("%s directive must be one of %s, got '%s'" % (
290
+ name, args, value))
291
+ return value
292
+ return validate
293
+
294
+
295
+ _normalise_common_encoding_name = {
296
+ 'utf8': 'utf8',
297
+ 'utf-8': 'utf8',
298
+ 'default': 'utf8',
299
+ 'ascii': 'ascii',
300
+ 'us-ascii': 'ascii',
301
+ }.get
302
+
303
+
304
+ def normalise_encoding_name(option_name, encoding):
305
+ """
306
+ >>> normalise_encoding_name('c_string_encoding', 'ascii')
307
+ 'ascii'
308
+ >>> normalise_encoding_name('c_string_encoding', 'AsCIi')
309
+ 'ascii'
310
+ >>> normalise_encoding_name('c_string_encoding', 'us-ascii')
311
+ 'ascii'
312
+ >>> normalise_encoding_name('c_string_encoding', 'utF8')
313
+ 'utf8'
314
+ >>> normalise_encoding_name('c_string_encoding', 'utF-8')
315
+ 'utf8'
316
+ >>> normalise_encoding_name('c_string_encoding', 'deFAuLT')
317
+ 'utf8'
318
+ >>> normalise_encoding_name('c_string_encoding', 'default')
319
+ 'utf8'
320
+ >>> normalise_encoding_name('c_string_encoding', 'SeriousLyNoSuch--Encoding')
321
+ 'SeriousLyNoSuch--Encoding'
322
+ """
323
+ if not encoding:
324
+ return ''
325
+ encoding_name = _normalise_common_encoding_name(encoding.lower())
326
+ if encoding_name is not None:
327
+ return encoding_name
328
+
329
+ import codecs
330
+ try:
331
+ decoder = codecs.getdecoder(encoding)
332
+ except LookupError:
333
+ return encoding # may exists at runtime ...
334
+ for name in ('ascii', 'utf8'):
335
+ if codecs.getdecoder(name) == decoder:
336
+ return name
337
+ return encoding
338
+
339
+ # use as a sential value to defer analysis of the arguments
340
+ # instead of analysing them in InterpretCompilerDirectives. The dataclass directives are quite
341
+ # complicated and it's easier to deal with them at the point the dataclass is created
342
+ class DEFER_ANALYSIS_OF_ARGUMENTS:
343
+ pass
344
+ DEFER_ANALYSIS_OF_ARGUMENTS = DEFER_ANALYSIS_OF_ARGUMENTS()
345
+
346
+ # Override types possibilities above, if needed
347
+ directive_types = {
348
+ 'language_level': str, # values can be None/2/3/'3str', where None == 2+warning
349
+ 'auto_pickle': bool,
350
+ 'locals': dict,
351
+ 'final' : bool, # final cdef classes and methods
352
+ 'collection_type': one_of('sequence'),
353
+ 'nogil' : DEFER_ANALYSIS_OF_ARGUMENTS,
354
+ 'gil' : DEFER_ANALYSIS_OF_ARGUMENTS,
355
+ 'with_gil' : None,
356
+ 'internal' : bool, # cdef class visibility in the module dict
357
+ 'infer_types' : bool, # values can be True/None/False
358
+ 'binding' : bool,
359
+ 'cfunc' : None, # decorators do not take directive value
360
+ 'ccall' : None,
361
+ 'ufunc': None,
362
+ 'cpow' : bool,
363
+ 'inline' : None,
364
+ 'staticmethod' : None,
365
+ 'cclass' : None,
366
+ 'no_gc_clear' : bool,
367
+ 'no_gc' : bool,
368
+ 'returns' : type,
369
+ 'exceptval': type, # actually (type, check=True/False), but has its own parser
370
+ 'set_initial_path': str,
371
+ 'freelist': int,
372
+ 'c_string_type': one_of('bytes', 'bytearray', 'str', 'unicode', map={'unicode': 'str'}),
373
+ 'c_string_encoding': normalise_encoding_name,
374
+ 'trashcan': bool,
375
+ 'total_ordering': None,
376
+ 'dataclasses.dataclass': DEFER_ANALYSIS_OF_ARGUMENTS,
377
+ 'dataclasses.field': DEFER_ANALYSIS_OF_ARGUMENTS,
378
+ 'embedsignature.format': one_of('c', 'clinic', 'python'),
379
+ }
380
+
381
+ for key, val in _directive_defaults.items():
382
+ if key not in directive_types:
383
+ directive_types[key] = type(val)
384
+
385
+ directive_scopes = { # defaults to available everywhere
386
+ # 'module', 'function', 'class', 'with statement'
387
+ 'auto_pickle': ('module', 'cclass'),
388
+ 'final' : ('cclass', 'function'),
389
+ 'ccomplex' : ('module',),
390
+ 'collection_type': ('cclass',),
391
+ 'nogil' : ('function', 'with statement'),
392
+ 'gil' : ('with statement'),
393
+ 'with_gil' : ('function',),
394
+ 'inline' : ('function',),
395
+ 'cfunc' : ('function', 'with statement'),
396
+ 'ccall' : ('function', 'with statement'),
397
+ 'returns' : ('function',),
398
+ 'exceptval' : ('function',),
399
+ 'locals' : ('function',),
400
+ 'staticmethod' : ('function',), # FIXME: analysis currently lacks more specific function scope
401
+ 'no_gc_clear' : ('cclass',),
402
+ 'no_gc' : ('cclass',),
403
+ 'internal' : ('cclass',),
404
+ 'cclass' : ('class', 'cclass', 'with statement'),
405
+ 'autotestdict' : ('module',),
406
+ 'autotestdict.all' : ('module',),
407
+ 'autotestdict.cdef' : ('module',),
408
+ 'set_initial_path' : ('module',),
409
+ 'test_assert_path_exists' : ('function', 'class', 'cclass'),
410
+ 'test_fail_if_path_exists' : ('function', 'class', 'cclass'),
411
+ 'test_assert_c_code_has' : ('module',),
412
+ 'test_fail_if_c_code_has' : ('module',),
413
+ 'freelist': ('cclass',),
414
+ 'formal_grammar': ('module',),
415
+ 'emit_code_comments': ('module',),
416
+ # Avoid scope-specific to/from_py_functions for c_string.
417
+ 'c_string_type': ('module',),
418
+ 'c_string_encoding': ('module',),
419
+ 'type_version_tag': ('module', 'cclass'),
420
+ 'language_level': ('module',),
421
+ # globals() could conceivably be controlled at a finer granularity,
422
+ # but that would complicate the implementation
423
+ 'old_style_globals': ('module',),
424
+ 'np_pythran': ('module',),
425
+ 'preliminary_late_includes_cy28': ('module',),
426
+ 'fast_gil': ('module',),
427
+ 'iterable_coroutine': ('module', 'function'),
428
+ 'trashcan' : ('cclass',),
429
+ 'total_ordering': ('class', 'cclass'),
430
+ 'dataclasses.dataclass' : ('class', 'cclass'),
431
+ 'cpp_locals': ('module', 'function', 'cclass'), # I don't think they make sense in a with_statement
432
+ 'ufunc': ('function',),
433
+ 'legacy_implicit_noexcept': ('module', ),
434
+ 'control_flow.dot_output': ('module',),
435
+ 'control_flow.dot_annotate_defs': ('module',),
436
+ 'freethreading_compatible': ('module',)
437
+ }
438
+
439
+
440
+ # A list of directives that (when used as a decorator) are only applied to
441
+ # the object they decorate and not to its children.
442
+ immediate_decorator_directives = {
443
+ 'cfunc', 'ccall', 'cclass', 'dataclasses.dataclass', 'ufunc',
444
+ # function signature directives
445
+ 'inline', 'exceptval', 'returns', 'with_gil', # 'nogil',
446
+ # class directives
447
+ 'freelist', 'no_gc', 'no_gc_clear', 'type_version_tag', 'final',
448
+ 'auto_pickle', 'internal', 'collection_type', 'total_ordering',
449
+ # testing directives
450
+ 'test_fail_if_path_exists', 'test_assert_path_exists',
451
+ }
452
+
453
+
454
+ def parse_directive_value(name, value, relaxed_bool=False):
455
+ """
456
+ Parses value as an option value for the given name and returns
457
+ the interpreted value. None is returned if the option does not exist.
458
+
459
+ >>> print(parse_directive_value('nonexisting', 'asdf asdfd'))
460
+ None
461
+ >>> parse_directive_value('boundscheck', 'True')
462
+ True
463
+ >>> parse_directive_value('boundscheck', 'true')
464
+ Traceback (most recent call last):
465
+ ...
466
+ ValueError: boundscheck directive must be set to True or False, got 'true'
467
+
468
+ >>> parse_directive_value('c_string_encoding', 'us-ascii')
469
+ 'ascii'
470
+ >>> parse_directive_value('c_string_type', 'str')
471
+ 'str'
472
+ >>> parse_directive_value('c_string_type', 'bytes')
473
+ 'bytes'
474
+ >>> parse_directive_value('c_string_type', 'bytearray')
475
+ 'bytearray'
476
+ >>> parse_directive_value('c_string_type', 'unicode')
477
+ 'str'
478
+ >>> parse_directive_value('c_string_type', 'unnicode')
479
+ Traceback (most recent call last):
480
+ ValueError: c_string_type directive must be one of ('bytes', 'bytearray', 'str', 'unicode'), got 'unnicode'
481
+ """
482
+ type = directive_types.get(name)
483
+ if not type:
484
+ return None
485
+ orig_value = value
486
+ if type is bool:
487
+ value = str(value)
488
+ if value == 'True':
489
+ return True
490
+ if value == 'False':
491
+ return False
492
+ if relaxed_bool:
493
+ value = value.lower()
494
+ if value in ("true", "yes"):
495
+ return True
496
+ elif value in ("false", "no"):
497
+ return False
498
+ raise ValueError("%s directive must be set to True or False, got '%s'" % (
499
+ name, orig_value))
500
+ elif type is int:
501
+ try:
502
+ return int(value)
503
+ except ValueError:
504
+ raise ValueError("%s directive must be set to an integer, got '%s'" % (
505
+ name, orig_value))
506
+ elif type is str:
507
+ return str(value)
508
+ elif callable(type):
509
+ return type(name, value)
510
+ else:
511
+ assert False
512
+
513
+
514
+ def parse_directive_list(s, relaxed_bool=False, ignore_unknown=False,
515
+ current_settings=None):
516
+ """
517
+ Parses a comma-separated list of pragma options. Whitespace
518
+ is not considered.
519
+
520
+ >>> parse_directive_list(' ')
521
+ {}
522
+ >>> (parse_directive_list('boundscheck=True') ==
523
+ ... {'boundscheck': True})
524
+ True
525
+ >>> parse_directive_list(' asdf')
526
+ Traceback (most recent call last):
527
+ ...
528
+ ValueError: Expected "=" in option "asdf"
529
+ >>> parse_directive_list('boundscheck=hey')
530
+ Traceback (most recent call last):
531
+ ...
532
+ ValueError: boundscheck directive must be set to True or False, got 'hey'
533
+ >>> parse_directive_list('unknown=True')
534
+ Traceback (most recent call last):
535
+ ...
536
+ ValueError: Unknown option: "unknown"
537
+ >>> warnings = parse_directive_list('warn.all=True')
538
+ >>> len(warnings) > 1
539
+ True
540
+ >>> sum(warnings.values()) == len(warnings) # all true.
541
+ True
542
+ """
543
+ if current_settings is None:
544
+ result = {}
545
+ else:
546
+ result = current_settings
547
+ for item in s.split(','):
548
+ item = item.strip()
549
+ if not item:
550
+ continue
551
+ if '=' not in item:
552
+ raise ValueError('Expected "=" in option "%s"' % item)
553
+ name, value = [s.strip() for s in item.strip().split('=', 1)]
554
+ if name not in _directive_defaults:
555
+ found = False
556
+ if name.endswith('.all'):
557
+ prefix = name[:-3]
558
+ for directive in _directive_defaults:
559
+ if directive.startswith(prefix):
560
+ found = True
561
+ parsed_value = parse_directive_value(directive, value, relaxed_bool=relaxed_bool)
562
+ result[directive] = parsed_value
563
+ if not found and not ignore_unknown:
564
+ raise ValueError('Unknown option: "%s"' % name)
565
+ elif directive_types.get(name) is list:
566
+ if name in result:
567
+ result[name].append(value)
568
+ else:
569
+ result[name] = [value]
570
+ else:
571
+ parsed_value = parse_directive_value(name, value, relaxed_bool=relaxed_bool)
572
+ result[name] = parsed_value
573
+ return result
574
+
575
+
576
+ def parse_variable_value(value):
577
+ """
578
+ Parses value as an option value for the given name and returns
579
+ the interpreted value.
580
+
581
+ >>> parse_variable_value('True')
582
+ True
583
+ >>> parse_variable_value('true')
584
+ 'true'
585
+ >>> parse_variable_value('us-ascii')
586
+ 'us-ascii'
587
+ >>> parse_variable_value('str')
588
+ 'str'
589
+ >>> parse_variable_value('123')
590
+ 123
591
+ >>> parse_variable_value('1.23')
592
+ 1.23
593
+
594
+ """
595
+ if value == "True":
596
+ return True
597
+ elif value == "False":
598
+ return False
599
+ elif value == "None":
600
+ return None
601
+ elif value.isdigit():
602
+ return int(value)
603
+ else:
604
+ try:
605
+ value = float(value)
606
+ except Exception:
607
+ # Not a float
608
+ pass
609
+ return value
610
+
611
+
612
+ def parse_compile_time_env(s, current_settings=None):
613
+ """
614
+ Parses a comma-separated list of pragma options. Whitespace
615
+ is not considered.
616
+
617
+ >>> parse_compile_time_env(' ')
618
+ {}
619
+ >>> (parse_compile_time_env('HAVE_OPENMP=True') ==
620
+ ... {'HAVE_OPENMP': True})
621
+ True
622
+ >>> parse_compile_time_env(' asdf')
623
+ Traceback (most recent call last):
624
+ ...
625
+ ValueError: Expected "=" in option "asdf"
626
+ >>> parse_compile_time_env('NUM_THREADS=4') == {'NUM_THREADS': 4}
627
+ True
628
+ >>> parse_compile_time_env('unknown=anything') == {'unknown': 'anything'}
629
+ True
630
+ """
631
+ if current_settings is None:
632
+ result = {}
633
+ else:
634
+ result = current_settings
635
+ for item in s.split(','):
636
+ item = item.strip()
637
+ if not item:
638
+ continue
639
+ if '=' not in item:
640
+ raise ValueError('Expected "=" in option "%s"' % item)
641
+ name, value = [s.strip() for s in item.split('=', 1)]
642
+ result[name] = parse_variable_value(value)
643
+ return result
644
+
645
+
646
+ # ------------------------------------------------------------------------
647
+ # CompilationOptions are constructed from user input and are the `option`
648
+ # object passed throughout the compilation pipeline.
649
+
650
+ class CompilationOptions:
651
+ r"""
652
+ See default_options at the end of this module for a list of all possible
653
+ options and CmdLine.usage and CmdLine.parse_command_line() for their
654
+ meaning.
655
+ """
656
+ def __init__(self, defaults=None, **kw):
657
+ self.include_path = []
658
+ if defaults:
659
+ if isinstance(defaults, CompilationOptions):
660
+ defaults = defaults.__dict__
661
+ else:
662
+ defaults = default_options
663
+
664
+ options = dict(defaults)
665
+ options.update(kw)
666
+
667
+ # let's assume 'default_options' contains a value for most known compiler options
668
+ # and validate against them
669
+ unknown_options = set(options) - set(default_options)
670
+ # ignore valid options that are not in the defaults
671
+ unknown_options.difference_update(['include_path'])
672
+ if unknown_options:
673
+ message = "got unknown compilation option%s, please remove: %s" % (
674
+ 's' if len(unknown_options) > 1 else '',
675
+ ', '.join(unknown_options))
676
+ raise ValueError(message)
677
+
678
+ directive_defaults = get_directive_defaults()
679
+ directives = dict(options['compiler_directives']) # copy mutable field
680
+ # check for invalid directives
681
+ unknown_directives = set(directives) - set(directive_defaults)
682
+ if unknown_directives:
683
+ message = "got unknown compiler directive%s: %s" % (
684
+ 's' if len(unknown_directives) > 1 else '',
685
+ ', '.join(unknown_directives))
686
+ raise ValueError(message)
687
+ options['compiler_directives'] = directives
688
+ if directives.get('np_pythran', False) and not options['cplus']:
689
+ import warnings
690
+ warnings.warn("C++ mode forced when in Pythran mode!")
691
+ options['cplus'] = True
692
+ if 'language_level' not in kw and directives.get('language_level'):
693
+ options['language_level'] = directives['language_level']
694
+ elif not options.get('language_level'):
695
+ options['language_level'] = directive_defaults.get('language_level')
696
+ if 'formal_grammar' in directives and 'formal_grammar' not in kw:
697
+ options['formal_grammar'] = directives['formal_grammar']
698
+
699
+ self.__dict__.update(options)
700
+
701
+ def configure_language_defaults(self, source_extension):
702
+ if source_extension == 'py':
703
+ if self.compiler_directives.get('binding') is None:
704
+ self.compiler_directives['binding'] = True
705
+
706
+ def get_fingerprint(self):
707
+ r"""
708
+ Return a string that contains all the options that are relevant for cache invalidation.
709
+ """
710
+ # Collect only the data that can affect the generated file(s).
711
+ data = {}
712
+
713
+ for key, value in self.__dict__.items():
714
+ if key in ['show_version', 'errors_to_stderr', 'verbose', 'quiet']:
715
+ # verbosity flags have no influence on the compilation result
716
+ continue
717
+ elif key in ['output_file', 'output_dir']:
718
+ # ignore the exact name of the output file
719
+ continue
720
+ elif key in ['depfile']:
721
+ # external build system dependency tracking file does not influence outputs
722
+ continue
723
+ elif key in ['timestamps']:
724
+ # the cache cares about the content of files, not about the timestamps of sources
725
+ continue
726
+ elif key in ['cache']:
727
+ # hopefully caching has no influence on the compilation result
728
+ continue
729
+ elif key in ['compiler_directives']:
730
+ # directives passed on to the C compiler do not influence the generated C code
731
+ continue
732
+ elif key in ['include_path']:
733
+ # this path changes which headers are tracked as dependencies,
734
+ # it has no influence on the generated C code
735
+ continue
736
+ elif key in ['working_path']:
737
+ # this path changes where modules and pxd files are found;
738
+ # their content is part of the fingerprint anyway, their
739
+ # absolute path does not matter
740
+ continue
741
+ elif key in ['create_extension']:
742
+ # create_extension() has already mangled the options, e.g.,
743
+ # embedded_metadata, when the fingerprint is computed so we
744
+ # ignore it here.
745
+ continue
746
+ elif key in ['build_dir']:
747
+ # the (temporary) directory where we collect dependencies
748
+ # has no influence on the C output
749
+ continue
750
+ elif key in ['use_listing_file', 'generate_pxi', 'annotate', 'annotate_coverage_xml']:
751
+ # all output files are contained in the cache so the types of
752
+ # files generated must be part of the fingerprint
753
+ data[key] = value
754
+ elif key in ['formal_grammar', 'evaluate_tree_assertions']:
755
+ # these bits can change whether compilation to C passes/fails
756
+ data[key] = value
757
+ elif key in ['embedded_metadata', 'emit_linenums',
758
+ 'c_line_in_traceback', 'gdb_debug',
759
+ 'relative_path_in_code_position_comments']:
760
+ # the generated code contains additional bits when these are set
761
+ data[key] = value
762
+ elif key in ['cplus', 'language_level', 'compile_time_env', 'np_pythran']:
763
+ # assorted bits that, e.g., influence the parser
764
+ data[key] = value
765
+ elif key == ['capi_reexport_cincludes']:
766
+ if self.capi_reexport_cincludes:
767
+ # our caching implementation does not yet include fingerprints of all the header files
768
+ raise NotImplementedError('capi_reexport_cincludes is not compatible with Cython caching')
769
+ elif key == ['common_utility_include_dir']:
770
+ if self.common_utility_include_dir:
771
+ raise NotImplementedError('common_utility_include_dir is not compatible with Cython caching yet')
772
+ else:
773
+ # any unexpected option should go into the fingerprint; it's better
774
+ # to recompile than to return incorrect results from the cache.
775
+ data[key] = value
776
+
777
+ def to_fingerprint(item):
778
+ r"""
779
+ Recursively turn item into a string, turning dicts into lists with
780
+ deterministic ordering.
781
+ """
782
+ if isinstance(item, dict):
783
+ item = sorted([(repr(key), to_fingerprint(value)) for key, value in item.items()])
784
+ return repr(item)
785
+
786
+ return to_fingerprint(data)
787
+
788
+
789
+ # ------------------------------------------------------------------------
790
+ #
791
+ # Set the default options depending on the platform
792
+ #
793
+ # ------------------------------------------------------------------------
794
+
795
+ default_options = dict(
796
+ show_version=0,
797
+ use_listing_file=0,
798
+ errors_to_stderr=1,
799
+ cplus=0,
800
+ output_file=None,
801
+ depfile=None,
802
+ annotate=None,
803
+ annotate_coverage_xml=None,
804
+ generate_pxi=0,
805
+ capi_reexport_cincludes=0,
806
+ working_path="",
807
+ timestamps=None,
808
+ verbose=0,
809
+ quiet=0,
810
+ compiler_directives={},
811
+ embedded_metadata={},
812
+ evaluate_tree_assertions=False,
813
+ emit_linenums=False,
814
+ relative_path_in_code_position_comments=True,
815
+ c_line_in_traceback=None,
816
+ language_level=None, # warn but default to 2
817
+ formal_grammar=False,
818
+ gdb_debug=False,
819
+ compile_time_env=None,
820
+ module_name=None,
821
+ common_utility_include_dir=None,
822
+ output_dir=None,
823
+ build_dir=None,
824
+ cache=None,
825
+ create_extension=None,
826
+ np_pythran=False,
827
+ legacy_implicit_noexcept=None,
828
+ )