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