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