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