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,856 @@
1
+ #
2
+ # Cython Top Level
3
+ #
4
+
5
+
6
+ import os
7
+ import re
8
+ import sys
9
+
10
+ if sys.version_info[:2] < (3, 9):
11
+ sys.stderr.write("Sorry, Cython requires Python 3.9+, found %d.%d\n" % tuple(sys.version_info[:2]))
12
+ sys.exit(1)
13
+
14
+ # Do not import Parsing here, import it when needed, because Parsing imports
15
+ # Nodes, which globally needs debug command line options initialized to set a
16
+ # conditional metaclass. These options are processed by CmdLine called from
17
+ # main() in this file.
18
+ # import Parsing
19
+ from . import Errors
20
+ from .StringEncoding import EncodedString
21
+ from .Scanning import PyrexScanner, FileSourceDescriptor
22
+ from .Errors import PyrexError, CompileError, error, warning
23
+ from .Symtab import ModuleScope
24
+ from .. import Utils
25
+ from . import Options
26
+ from .Options import CompilationOptions, default_options
27
+ from .CmdLine import parse_command_line
28
+ from .Lexicon import (unicode_start_ch_any, unicode_continuation_ch_any,
29
+ unicode_start_ch_range, unicode_continuation_ch_range)
30
+
31
+
32
+ def _make_range_re(chrs):
33
+ out = []
34
+ for i in range(0, len(chrs), 2):
35
+ out.append("{}-{}".format(chrs[i], chrs[i+1]))
36
+ return "".join(out)
37
+
38
+ # py2 version looked like r"[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*$"
39
+ module_name_pattern = "[{0}{1}][{0}{2}{1}{3}]*".format(
40
+ unicode_start_ch_any, _make_range_re(unicode_start_ch_range),
41
+ unicode_continuation_ch_any,
42
+ _make_range_re(unicode_continuation_ch_range))
43
+ module_name_pattern = re.compile("{0}(\\.{0})*$".format(module_name_pattern))
44
+
45
+
46
+ standard_include_path = os.path.abspath(
47
+ os.path.join(os.path.dirname(os.path.dirname(__file__)), 'Includes'))
48
+
49
+
50
+ class Context:
51
+ # This class encapsulates the context needed for compiling
52
+ # one or more Cython implementation files along with their
53
+ # associated and imported declaration files. It includes
54
+ # the root of the module import namespace and the list
55
+ # of directories to search for include files.
56
+ #
57
+ # modules {string : ModuleScope}
58
+ # include_directories [string]
59
+ # future_directives [object]
60
+ # language_level int currently 2 or 3 for Python 2/3
61
+
62
+ cython_scope = None
63
+ language_level = None # warn when not set but default to Py2
64
+
65
+ def __init__(self, include_directories, compiler_directives, cpp=False,
66
+ language_level=None, options=None):
67
+ # cython_scope is a hack, set to False by subclasses, in order to break
68
+ # an infinite loop.
69
+ # Better code organization would fix it.
70
+
71
+ from . import Builtin, CythonScope
72
+ self.modules = {"__builtin__" : Builtin.builtin_scope}
73
+ self.cython_scope = CythonScope.create_cython_scope(self)
74
+ self.modules["cython"] = self.cython_scope
75
+ self.include_directories = include_directories
76
+ self.future_directives = set()
77
+ self.compiler_directives = compiler_directives
78
+ self.cpp = cpp
79
+ self.options = options
80
+
81
+ self.pxds = {} # full name -> node tree
82
+ self.utility_pxds = {} # pxd name -> node tree
83
+ self._interned = {} # (type(value), value, *key_args) -> interned_value
84
+
85
+ if language_level is not None:
86
+ self.set_language_level(language_level)
87
+
88
+ self.legacy_implicit_noexcept = self.compiler_directives.get('legacy_implicit_noexcept', False)
89
+
90
+ self.gdb_debug_outputwriter = None
91
+
92
+ @classmethod
93
+ def from_options(cls, options):
94
+ return cls(options.include_path, options.compiler_directives,
95
+ options.cplus, options.language_level, options=options)
96
+
97
+ @property
98
+ def shared_c_file_path(self):
99
+ return self.options.shared_c_file_path if self.options else None
100
+
101
+ @property
102
+ def shared_utility_qualified_name(self):
103
+ return self.options.shared_utility_qualified_name if self.options else None
104
+
105
+ def set_language_level(self, level):
106
+ from .Future import print_function, unicode_literals, absolute_import, division, generator_stop
107
+ future_directives = set()
108
+ if level == '3str':
109
+ level = 3
110
+ else:
111
+ level = int(level)
112
+ if level >= 3:
113
+ future_directives.update([unicode_literals, print_function, absolute_import, division, generator_stop])
114
+ self.language_level = level
115
+ self.future_directives = future_directives
116
+ if level >= 3:
117
+ self.modules['builtins'] = self.modules['__builtin__']
118
+
119
+ def intern_ustring(self, value, encoding=None):
120
+ key = (EncodedString, value, encoding)
121
+ try:
122
+ return self._interned[key]
123
+ except KeyError:
124
+ pass
125
+ value = EncodedString(value)
126
+ if encoding:
127
+ value.encoding = encoding
128
+ self._interned[key] = value
129
+ return value
130
+
131
+ # pipeline creation functions can now be found in Pipeline.py
132
+
133
+ def process_pxd(self, source_desc, scope, module_name):
134
+ from . import Pipeline
135
+ if isinstance(source_desc, FileSourceDescriptor) and source_desc._file_type == 'pyx':
136
+ source = CompilationSource(source_desc, module_name, os.getcwd())
137
+ result_sink = create_default_resultobj(source, self.options)
138
+ pipeline = Pipeline.create_pyx_as_pxd_pipeline(self, result_sink)
139
+ result = Pipeline.run_pipeline(pipeline, source)
140
+ elif source_desc.in_utility_code:
141
+ from . import ParseTreeTransforms
142
+ transform = ParseTreeTransforms.CnameDirectivesTransform(self)
143
+ pipeline = Pipeline.create_pxd_pipeline(self, scope, module_name)
144
+ pipeline = Pipeline.insert_into_pipeline(
145
+ pipeline, transform,
146
+ before=ParseTreeTransforms.InterpretCompilerDirectives)
147
+ result = Pipeline.run_pipeline(pipeline, source_desc)
148
+ else:
149
+ pipeline = Pipeline.create_pxd_pipeline(self, scope, module_name)
150
+ result = Pipeline.run_pipeline(pipeline, source_desc)
151
+ return result
152
+
153
+ def nonfatal_error(self, exc):
154
+ return Errors.report_error(exc)
155
+
156
+ def _split_qualified_name(self, qualified_name, relative_import=False):
157
+ # Splits qualified_name into parts in form of 2-tuples: (PART_NAME, IS_PACKAGE).
158
+ qualified_name_parts = qualified_name.split('.')
159
+ last_part = qualified_name_parts.pop()
160
+ qualified_name_parts = [(p, True) for p in qualified_name_parts]
161
+ if last_part != '__init__':
162
+ # If Last part is __init__, then it is omitted. Otherwise, we need to check whether we can find
163
+ # __init__.pyx/__init__.py file to determine if last part is package or not.
164
+ is_package = False
165
+ for suffix in ('.py', '.pyx'):
166
+ path = self.search_include_directories(
167
+ qualified_name, suffix=suffix, source_pos=None, source_file_path=None, sys_path=not relative_import)
168
+ if path:
169
+ is_package = self._is_init_file(path)
170
+ break
171
+
172
+ qualified_name_parts.append((last_part, is_package))
173
+ return qualified_name_parts
174
+
175
+ @staticmethod
176
+ def _is_init_file(path):
177
+ return os.path.basename(path) in ('__init__.pyx', '__init__.py', '__init__.pxd') if path else False
178
+
179
+ @staticmethod
180
+ def _check_pxd_filename(pos, pxd_pathname, qualified_name):
181
+ if not pxd_pathname:
182
+ return
183
+ pxd_filename = os.path.basename(pxd_pathname)
184
+ if '.' in qualified_name and qualified_name == os.path.splitext(pxd_filename)[0]:
185
+ warning(pos, "Dotted filenames ('%s') are deprecated."
186
+ " Please use the normal Python package directory layout." % pxd_filename, level=1)
187
+
188
+ def find_module(self, module_name, from_module=None, pos=None, need_pxd=1,
189
+ absolute_fallback=True, relative_import=False):
190
+ # Finds and returns the module scope corresponding to
191
+ # the given relative or absolute module name. If this
192
+ # is the first time the module has been requested, finds
193
+ # the corresponding .pxd file and process it.
194
+ # If from_module is not None, it must be a module scope,
195
+ # and the module will first be searched for relative to
196
+ # that module, provided its name is not a dotted name.
197
+ debug_find_module = 0
198
+ if debug_find_module:
199
+ print("Context.find_module: module_name = %s, from_module = %s, pos = %s, need_pxd = %s" % (
200
+ module_name, from_module, pos, need_pxd))
201
+
202
+ scope = None
203
+ pxd_pathname = None
204
+ if from_module:
205
+ if module_name:
206
+ # from .module import ...
207
+ qualified_name = from_module.qualify_name(module_name)
208
+ else:
209
+ # from . import ...
210
+ qualified_name = from_module.qualified_name
211
+ scope = from_module
212
+ from_module = None
213
+ else:
214
+ qualified_name = module_name
215
+
216
+ if not module_name_pattern.match(qualified_name):
217
+ raise CompileError(pos or (module_name, 0, 0),
218
+ "'%s' is not a valid module name" % module_name)
219
+
220
+ if from_module:
221
+ if debug_find_module:
222
+ print("...trying relative import")
223
+ scope = from_module.lookup_submodule(module_name)
224
+ if not scope:
225
+ pxd_pathname = self.find_pxd_file(qualified_name, pos, sys_path=not relative_import)
226
+ self._check_pxd_filename(pos, pxd_pathname, qualified_name)
227
+ if pxd_pathname:
228
+ is_package = self._is_init_file(pxd_pathname)
229
+ scope = from_module.find_submodule(module_name, as_package=is_package)
230
+ if not scope:
231
+ if debug_find_module:
232
+ print("...trying absolute import")
233
+ if absolute_fallback:
234
+ qualified_name = module_name
235
+ scope = self
236
+ for name, is_package in self._split_qualified_name(qualified_name, relative_import=relative_import):
237
+ scope = scope.find_submodule(name, as_package=is_package)
238
+ if debug_find_module:
239
+ print("...scope = %s" % scope)
240
+ if not scope.pxd_file_loaded:
241
+ if debug_find_module:
242
+ print("...pxd not loaded")
243
+ if not pxd_pathname:
244
+ if debug_find_module:
245
+ print("...looking for pxd file")
246
+ # Only look in sys.path if we are explicitly looking
247
+ # for a .pxd file.
248
+ pxd_pathname = self.find_pxd_file(qualified_name, pos, sys_path=need_pxd and not relative_import)
249
+ self._check_pxd_filename(pos, pxd_pathname, qualified_name)
250
+ if debug_find_module:
251
+ print("......found %s" % pxd_pathname)
252
+ if not pxd_pathname and need_pxd:
253
+ # Set pxd_file_loaded such that we don't need to
254
+ # look for the non-existing pxd file next time.
255
+ scope.pxd_file_loaded = True
256
+ package_pathname = self.search_include_directories(
257
+ qualified_name, suffix=".py", source_pos=pos, sys_path=not relative_import)
258
+ if package_pathname and package_pathname.endswith(Utils.PACKAGE_FILES):
259
+ pass
260
+ else:
261
+ error(pos, "'%s.pxd' not found" % qualified_name.replace('.', os.sep))
262
+ if pxd_pathname:
263
+ scope.pxd_file_loaded = True
264
+ try:
265
+ if debug_find_module:
266
+ print("Context.find_module: Parsing %s" % pxd_pathname)
267
+ rel_path = module_name.replace('.', os.sep) + os.path.splitext(pxd_pathname)[1]
268
+ if not pxd_pathname.endswith(rel_path):
269
+ rel_path = pxd_pathname # safety measure to prevent printing incorrect paths
270
+ source_desc = FileSourceDescriptor(pxd_pathname, rel_path)
271
+ err, result = self.process_pxd(source_desc, scope, qualified_name)
272
+ if err:
273
+ raise err
274
+ (pxd_codenodes, pxd_scope) = result
275
+ self.pxds[module_name] = (pxd_codenodes, pxd_scope)
276
+ except CompileError:
277
+ pass
278
+ return scope
279
+
280
+ def find_pxd_file(self, qualified_name, pos=None, sys_path=True, source_file_path=None):
281
+ # Search include path (and sys.path if sys_path is True) for
282
+ # the .pxd file corresponding to the given fully-qualified
283
+ # module name.
284
+ # Will find either a dotted filename or a file in a
285
+ # package directory. If a source file position is given,
286
+ # the directory containing the source file is searched first
287
+ # for a dotted filename, and its containing package root
288
+ # directory is searched first for a non-dotted filename.
289
+ pxd = self.search_include_directories(
290
+ qualified_name, suffix=".pxd", source_pos=pos, sys_path=sys_path, source_file_path=source_file_path)
291
+ if pxd is None and Options.cimport_from_pyx:
292
+ return self.find_pyx_file(qualified_name, pos, sys_path=sys_path)
293
+ return pxd
294
+
295
+ def find_pyx_file(self, qualified_name, pos=None, sys_path=True, source_file_path=None):
296
+ # Search include path for the .pyx file corresponding to the
297
+ # given fully-qualified module name, as for find_pxd_file().
298
+ return self.search_include_directories(
299
+ qualified_name, suffix=".pyx", source_pos=pos, sys_path=sys_path, source_file_path=source_file_path)
300
+
301
+ def find_include_file(self, filename, pos=None, source_file_path=None):
302
+ # Search list of include directories for filename.
303
+ # Reports an error and returns None if not found.
304
+ path = self.search_include_directories(
305
+ filename, source_pos=pos, include=True, source_file_path=source_file_path)
306
+ if not path:
307
+ error(pos, "'%s' not found" % filename)
308
+ return path
309
+
310
+ def search_include_directories(self, qualified_name,
311
+ suffix=None, source_pos=None, include=False, sys_path=False, source_file_path=None):
312
+ include_dirs = self.include_directories
313
+ if sys_path:
314
+ include_dirs = include_dirs + sys.path
315
+ # include_dirs must be hashable for caching in @cached_function
316
+ include_dirs = tuple(include_dirs + [standard_include_path])
317
+ return search_include_directories(
318
+ include_dirs, qualified_name, suffix or "", source_pos, include, source_file_path)
319
+
320
+ def find_root_package_dir(self, file_path):
321
+ return Utils.find_root_package_dir(file_path)
322
+
323
+ def check_package_dir(self, dir, package_names):
324
+ return Utils.check_package_dir(dir, tuple(package_names))
325
+
326
+ def c_file_out_of_date(self, source_path, output_path):
327
+ if not os.path.exists(output_path):
328
+ return 1
329
+ c_time = Utils.modification_time(output_path)
330
+ if Utils.file_newer_than(source_path, c_time):
331
+ return 1
332
+ pxd_path = Utils.replace_suffix(source_path, ".pxd")
333
+ if os.path.exists(pxd_path) and Utils.file_newer_than(pxd_path, c_time):
334
+ return 1
335
+ for kind, name in self.read_dependency_file(source_path):
336
+ if kind == "cimport":
337
+ dep_path = self.find_pxd_file(name, source_file_path=source_path)
338
+ elif kind == "include":
339
+ dep_path = self.search_include_directories(name, source_file_path=source_path)
340
+ else:
341
+ continue
342
+ if dep_path and Utils.file_newer_than(dep_path, c_time):
343
+ return 1
344
+ return 0
345
+
346
+ def find_cimported_module_names(self, source_path):
347
+ return [ name for kind, name in self.read_dependency_file(source_path)
348
+ if kind == "cimport" ]
349
+
350
+ def is_package_dir(self, dir_path):
351
+ return Utils.is_package_dir(dir_path)
352
+
353
+ def read_dependency_file(self, source_path):
354
+ dep_path = Utils.replace_suffix(source_path, ".dep")
355
+ if os.path.exists(dep_path):
356
+ with open(dep_path) as f:
357
+ chunks = [ line.split(" ", 1)
358
+ for line in (l.strip() for l in f)
359
+ if " " in line ]
360
+ return chunks
361
+ else:
362
+ return ()
363
+
364
+ def lookup_submodule(self, name):
365
+ # Look up a top-level module. Returns None if not found.
366
+ return self.modules.get(name, None)
367
+
368
+ def find_submodule(self, name, as_package=False):
369
+ # Find a top-level module, creating a new one if needed.
370
+ scope = self.lookup_submodule(name)
371
+ if not scope:
372
+ scope = ModuleScope(name,
373
+ parent_module = None, context = self, is_package=as_package)
374
+ self.modules[name] = scope
375
+ return scope
376
+
377
+ def parse(self, source_desc, scope, pxd, full_module_name):
378
+ if not isinstance(source_desc, FileSourceDescriptor):
379
+ raise RuntimeError("Only file sources for code supported")
380
+ scope.cpp = self.cpp
381
+ # Parse the given source file and return a parse tree.
382
+ num_errors = Errors.get_errors_count()
383
+ try:
384
+ with source_desc.get_file_object() as f:
385
+ from . import Parsing
386
+ s = PyrexScanner(f, source_desc, source_encoding = f.encoding,
387
+ scope = scope, context = self)
388
+ tree = Parsing.p_module(s, pxd, full_module_name)
389
+ if self.options.formal_grammar:
390
+ try:
391
+ from ..Parser import ConcreteSyntaxTree
392
+ except ImportError:
393
+ raise RuntimeError(
394
+ "Formal grammar can only be used with compiled Cython with an available pgen.")
395
+ ConcreteSyntaxTree.p_module(source_desc.filename)
396
+ except UnicodeDecodeError as e:
397
+ #import traceback
398
+ #traceback.print_exc()
399
+ raise self._report_decode_error(source_desc, e)
400
+
401
+ if Errors.get_errors_count() > num_errors:
402
+ raise CompileError()
403
+ return tree
404
+
405
+ def _report_decode_error(self, source_desc, exc):
406
+ msg = exc.args[-1]
407
+ position = exc.args[2]
408
+ encoding = exc.args[0]
409
+
410
+ line = 1
411
+ column = idx = 0
412
+ with open(source_desc.filename, encoding='iso8859-1', newline='') as f:
413
+ for line, data in enumerate(f, 1):
414
+ idx += len(data)
415
+ if idx >= position:
416
+ column = position - (idx - len(data)) + 1
417
+ break
418
+
419
+ return error((source_desc, line, column),
420
+ "Decoding error, missing or incorrect coding=<encoding-name> "
421
+ "at top of source (cannot decode with encoding %r: %s)" % (encoding, msg))
422
+
423
+ def extract_module_name(self, path, options):
424
+ # Find fully_qualified module name from the full pathname
425
+ # of a source file.
426
+ dir, filename = os.path.split(path)
427
+ module_name, _ = os.path.splitext(filename)
428
+ if "." in module_name:
429
+ return module_name
430
+ names = [module_name]
431
+ while self.is_package_dir(dir):
432
+ parent, package_name = os.path.split(dir)
433
+ if parent == dir:
434
+ break
435
+ names.append(package_name)
436
+ dir = parent
437
+ names.reverse()
438
+ return ".".join(names)
439
+
440
+ def setup_errors(self, options, result):
441
+ Errors.reset()
442
+ if options.use_listing_file:
443
+ path = result.listing_file = Utils.replace_suffix(result.main_source_file, ".lis")
444
+ else:
445
+ path = None
446
+ Errors.open_listing_file(path=path, echo_to_stderr=options.errors_to_stderr)
447
+
448
+ def teardown_errors(self, err, options, result):
449
+ source_desc = result.compilation_source.source_desc
450
+ if not isinstance(source_desc, FileSourceDescriptor):
451
+ raise RuntimeError("Only file sources for code supported")
452
+ Errors.close_listing_file()
453
+ result.num_errors = Errors.get_errors_count()
454
+ if result.num_errors > 0:
455
+ err = True
456
+ if err and result.c_file:
457
+ try:
458
+ Utils.castrate_file(result.c_file, os.stat(source_desc.filename))
459
+ except OSError:
460
+ pass
461
+ result.c_file = None
462
+
463
+
464
+ def get_output_filename(source_filename, cwd, options):
465
+ if options.cplus:
466
+ c_suffix = ".cpp"
467
+ else:
468
+ c_suffix = ".c"
469
+ suggested_file_name = Utils.replace_suffix(source_filename, c_suffix)
470
+ if options.output_file:
471
+ out_path = os.path.join(cwd, options.output_file)
472
+ if os.path.isdir(out_path):
473
+ return os.path.join(out_path, os.path.basename(suggested_file_name))
474
+ else:
475
+ return out_path
476
+ else:
477
+ return suggested_file_name
478
+
479
+
480
+ def create_default_resultobj(compilation_source, options):
481
+ result = CompilationResult()
482
+ result.main_source_file = compilation_source.source_desc.filename
483
+ result.compilation_source = compilation_source
484
+ source_desc = compilation_source.source_desc
485
+ result.c_file = get_output_filename(source_desc.filename,
486
+ compilation_source.cwd, options)
487
+ result.embedded_metadata = options.embedded_metadata
488
+ return result
489
+
490
+
491
+ def setup_source_object(source, source_ext, full_module_name, options, context):
492
+ cwd = os.getcwd()
493
+ abs_path = os.path.abspath(source)
494
+
495
+ full_module_name = full_module_name or context.extract_module_name(source, options)
496
+ full_module_name = EncodedString(full_module_name)
497
+
498
+ Utils.raise_error_if_module_name_forbidden(full_module_name)
499
+ if options.relative_path_in_code_position_comments:
500
+ rel_path = full_module_name.replace('.', os.sep) + source_ext
501
+ if not abs_path.endswith(rel_path):
502
+ rel_path = source # safety measure to prevent printing incorrect paths
503
+ else:
504
+ rel_path = abs_path
505
+ source_desc = FileSourceDescriptor(abs_path, rel_path)
506
+ return CompilationSource(source_desc, full_module_name, cwd)
507
+
508
+
509
+ def run_cached_pipeline(source, options, full_module_name, context, cache, fingerprint):
510
+ cwd = os.getcwd()
511
+ output_filename = get_output_filename(source, cwd, options)
512
+ cached = cache.lookup_cache(output_filename, fingerprint)
513
+ if cached:
514
+ cache.load_from_cache(output_filename, cached)
515
+
516
+ source_ext = os.path.splitext(source)[1]
517
+ options.configure_language_defaults(source_ext[1:]) # py/pyx
518
+
519
+ source = setup_source_object(source, source_ext, full_module_name, options, context)
520
+ # Set up result object
521
+ return create_default_resultobj(source, options)
522
+
523
+ result = run_pipeline(source, options, full_module_name, context)
524
+ if fingerprint:
525
+ cache.store_to_cache(output_filename, fingerprint, result)
526
+ return result
527
+
528
+
529
+ def run_pipeline(source, options, full_module_name, context):
530
+ from . import Pipeline
531
+ if options.verbose:
532
+ sys.stderr.write("Compiling %s\n" % source)
533
+ source_ext = os.path.splitext(source)[1]
534
+ abs_path = os.path.abspath(source)
535
+ options.configure_language_defaults(source_ext[1:]) # py/pyx
536
+
537
+ source = setup_source_object(source, source_ext, full_module_name, options, context)
538
+ # Set up result object
539
+ result = create_default_resultobj(source, options)
540
+
541
+ if options.annotate is None:
542
+ # By default, decide based on whether an html file already exists.
543
+ html_filename = os.path.splitext(result.c_file)[0] + ".html"
544
+ if os.path.exists(html_filename):
545
+ with open(html_filename, encoding="UTF-8") as html_file:
546
+ if '<!-- Generated by Cython' in html_file.read(100):
547
+ options.annotate = True
548
+
549
+ # Get pipeline
550
+ if source_ext.lower() == '.py' or not source_ext:
551
+ pipeline = Pipeline.create_py_pipeline(context, options, result)
552
+ else:
553
+ pipeline = Pipeline.create_pyx_pipeline(context, options, result)
554
+
555
+ context.setup_errors(options, result)
556
+
557
+ if '.' in source.full_module_name and '.' in os.path.splitext(os.path.basename(abs_path))[0]:
558
+ warning((source.source_desc, 1, 0),
559
+ "Dotted filenames ('%s') are deprecated."
560
+ " Please use the normal Python package directory layout." % os.path.basename(abs_path), level=1)
561
+ if re.search("[.]c(pp|[+][+]|xx)$", result.c_file, re.RegexFlag.IGNORECASE) and not context.cpp:
562
+ warning((source.source_desc, 1, 0),
563
+ "Filename implies a c++ file but Cython is not in c++ mode.",
564
+ level=1)
565
+
566
+ err, enddata = Pipeline.run_pipeline(pipeline, source)
567
+ context.teardown_errors(err, options, result)
568
+ if err is None and options.depfile:
569
+ from ..Build.Dependencies import create_dependency_tree
570
+ dependencies = create_dependency_tree(context).all_dependencies(result.main_source_file)
571
+ Utils.write_depfile(result.c_file, result.main_source_file, dependencies)
572
+ return result
573
+
574
+
575
+ # ------------------------------------------------------------------------
576
+ #
577
+ # Main Python entry points
578
+ #
579
+ # ------------------------------------------------------------------------
580
+
581
+ class CompilationSource:
582
+ """
583
+ Contains the data necessary to start up a compilation pipeline for
584
+ a single compilation unit.
585
+ """
586
+ def __init__(self, source_desc, full_module_name, cwd):
587
+ self.source_desc = source_desc
588
+ self.full_module_name = full_module_name
589
+ self.cwd = cwd
590
+
591
+
592
+ class CompilationResult:
593
+ """
594
+ Results from the Cython compiler:
595
+
596
+ c_file string or None The generated C source file
597
+ h_file string or None The generated C header file
598
+ i_file string or None The generated .pxi file
599
+ api_file string or None The generated C API .h file
600
+ listing_file string or None File of error messages
601
+ object_file string or None Result of compiling the C file
602
+ extension_file string or None Result of linking the object file
603
+ num_errors integer Number of compilation errors
604
+ compilation_source CompilationSource
605
+ """
606
+
607
+ c_file = None
608
+ h_file = None
609
+ i_file = None
610
+ api_file = None
611
+ listing_file = None
612
+ object_file = None
613
+ extension_file = None
614
+ main_source_file = None
615
+ num_errors = 0
616
+
617
+ def get_generated_source_files(self):
618
+ return [
619
+ source_file for source_file in [self.c_file, self.h_file, self.i_file, self.api_file]
620
+ if source_file
621
+ ]
622
+
623
+
624
+ class CompilationResultSet(dict):
625
+ """
626
+ Results from compiling multiple Pyrex source files. A mapping
627
+ from source file paths to CompilationResult instances. Also
628
+ has the following attributes:
629
+
630
+ num_errors integer Total number of compilation errors
631
+ """
632
+
633
+ num_errors = 0
634
+
635
+ def add(self, source, result):
636
+ self[source] = result
637
+ self.num_errors += result.num_errors
638
+
639
+
640
+ def get_fingerprint(cache, source, options):
641
+ from ..Build.Dependencies import create_dependency_tree
642
+ from ..Build.Cache import FingerprintFlags
643
+ context = Context.from_options(options)
644
+ dependencies = create_dependency_tree(context)
645
+ return cache.transitive_fingerprint(
646
+ source, dependencies.all_dependencies(source), options,
647
+ FingerprintFlags(
648
+ 'c++' if options.cplus else 'c',
649
+ np_pythran=options.np_pythran
650
+ )
651
+ )
652
+
653
+
654
+ def compile_single(source, options, full_module_name, cache=None, context=None, fingerprint=None):
655
+ """
656
+ compile_single(source, options, full_module_name, cache, context, fingerprint)
657
+
658
+ Compile the given Pyrex implementation file and return a CompilationResult.
659
+ Always compiles a single file; does not perform timestamp checking or
660
+ recursion.
661
+ """
662
+
663
+ if context is None:
664
+ context = Context.from_options(options)
665
+
666
+ if cache:
667
+ fingerprint = fingerprint or get_fingerprint(cache, source, options)
668
+ return run_cached_pipeline(source, options, full_module_name, context, cache, fingerprint)
669
+ else:
670
+ return run_pipeline(source, options, full_module_name, context)
671
+
672
+
673
+ def compile_multiple(sources, options, cache=None):
674
+ """
675
+ compile_multiple(sources, options, cache)
676
+
677
+ Compiles the given sequence of Pyrex implementation files and returns
678
+ a CompilationResultSet. Performs timestamp checking, caching and/or recursion
679
+ if these are specified in the options.
680
+ """
681
+ if len(sources) > 1 and options.module_name:
682
+ raise RuntimeError('Full module name can only be set '
683
+ 'for single source compilation')
684
+ # run_pipeline creates the context
685
+ # context = Context.from_options(options)
686
+ sources = [os.path.abspath(source) for source in sources]
687
+ processed = set()
688
+ results = CompilationResultSet()
689
+ timestamps = options.timestamps
690
+ context = None
691
+ cwd = os.getcwd()
692
+ for source in sources:
693
+ if source not in processed:
694
+ output_filename = get_output_filename(source, cwd, options)
695
+ if context is None:
696
+ context = Context.from_options(options)
697
+ out_of_date = context.c_file_out_of_date(source, output_filename)
698
+ if (not timestamps) or out_of_date:
699
+ result = compile_single(source, options, full_module_name=options.module_name, cache=cache, context=context)
700
+ results.add(source, result)
701
+ # Compiling multiple sources in one context doesn't quite
702
+ # work properly yet.
703
+ context = None
704
+ processed.add(source)
705
+ if cache:
706
+ cache.cleanup_cache()
707
+ return results
708
+
709
+
710
+ def compile(source, options = None, full_module_name = None, **kwds):
711
+ """
712
+ compile(source [, options], [, <option> = <value>]...)
713
+
714
+ Compile one or more Pyrex implementation files, with optional timestamp
715
+ checking and recursing on dependencies. The source argument may be a string
716
+ or a sequence of strings. If it is a string and no recursion or timestamp
717
+ checking is requested, a CompilationResult is returned, otherwise a
718
+ CompilationResultSet is returned.
719
+ """
720
+ options = CompilationOptions(defaults = options, **kwds)
721
+
722
+ # cache is enabled when:
723
+ # * options.cache is True (the default path to the cache base dir is used)
724
+ # * options.cache is the explicit path to the cache base dir
725
+ # unless annotations are generated
726
+ cache = None
727
+ if options.cache:
728
+ if options.annotate or Options.annotate:
729
+ if options.verbose:
730
+ sys.stderr.write('Cache is ignored when annotations are enabled.\n')
731
+ else:
732
+ from ..Build.Cache import Cache
733
+ cache_path = None if options.cache is True else options.cache
734
+ cache = Cache(cache_path)
735
+
736
+ if isinstance(source, str):
737
+ if not options.timestamps:
738
+ return compile_single(source, options, full_module_name, cache)
739
+ source = [source]
740
+ return compile_multiple(source, options, cache)
741
+
742
+
743
+ @Utils.cached_function
744
+ def search_include_directories(dirs, qualified_name, suffix="", pos=None, include=False, source_file_path=None):
745
+ """
746
+ Search the list of include directories for the given file name.
747
+
748
+ If a source file path or position is given, first searches the directory
749
+ containing that file. Returns None if not found, but does not report an error.
750
+
751
+ The 'include' option will disable package dereferencing.
752
+ """
753
+ if pos and not source_file_path:
754
+ file_desc = pos[0]
755
+ if not isinstance(file_desc, FileSourceDescriptor):
756
+ raise RuntimeError("Only file sources for code supported")
757
+ source_file_path = file_desc.filename
758
+ if source_file_path:
759
+ if include:
760
+ dirs = (os.path.dirname(source_file_path),) + dirs
761
+ else:
762
+ dirs = (Utils.find_root_package_dir(source_file_path),) + dirs
763
+
764
+ # search for dotted filename e.g. <dir>/foo.bar.pxd
765
+ dotted_filename = qualified_name
766
+ if suffix:
767
+ dotted_filename += suffix
768
+
769
+ for dirname in dirs:
770
+ path = os.path.join(dirname, dotted_filename)
771
+ if os.path.exists(path):
772
+ return path
773
+
774
+ # search for filename in package structure e.g. <dir>/foo/bar.pxd or <dir>/foo/bar/__init__.pxd
775
+ if not include:
776
+
777
+ names = qualified_name.split('.')
778
+ package_names = tuple(names[:-1])
779
+ module_name = names[-1]
780
+
781
+ # search for standard packages first - PEP420
782
+ namespace_dirs = []
783
+ for dirname in dirs:
784
+ package_dir, is_namespace = Utils.check_package_dir(dirname, package_names)
785
+ if package_dir is not None:
786
+ if is_namespace:
787
+ namespace_dirs.append(package_dir)
788
+ continue
789
+ path = search_module_in_dir(package_dir, module_name, suffix)
790
+ if path:
791
+ return path
792
+
793
+ # search for namespaces second - PEP420
794
+ for package_dir in namespace_dirs:
795
+ path = search_module_in_dir(package_dir, module_name, suffix)
796
+ if path:
797
+ return path
798
+
799
+ return None
800
+
801
+
802
+ @Utils.cached_function
803
+ def search_module_in_dir(package_dir, module_name, suffix):
804
+ # matches modules of the form: <dir>/foo/bar.pxd
805
+ path = Utils.find_versioned_file(package_dir, module_name, suffix)
806
+
807
+ # matches modules of the form: <dir>/foo/bar/__init__.pxd
808
+ if not path and suffix:
809
+ path = Utils.find_versioned_file(os.path.join(package_dir, module_name), "__init__", suffix)
810
+
811
+ return path
812
+
813
+
814
+ # ------------------------------------------------------------------------
815
+ #
816
+ # Main command-line entry point
817
+ #
818
+ # ------------------------------------------------------------------------
819
+
820
+ def setuptools_main():
821
+ return main(command_line = 1)
822
+
823
+
824
+ def main(command_line = 0):
825
+ args = sys.argv[1:]
826
+ any_failures = 0
827
+ if command_line:
828
+ try:
829
+ options, sources = parse_command_line(args)
830
+ except FileNotFoundError as e:
831
+ print("{}: No such file or directory: '{}'".format(sys.argv[0], e.filename), file=sys.stderr)
832
+ sys.exit(1)
833
+ else:
834
+ options = CompilationOptions(default_options)
835
+ sources = args
836
+
837
+ if options.show_version:
838
+ Utils.print_version()
839
+
840
+ if options.working_path!="":
841
+ os.chdir(options.working_path)
842
+
843
+ try:
844
+ if options.shared_c_file_path:
845
+ from ..Build.SharedModule import generate_shared_module
846
+ generate_shared_module(options)
847
+ return
848
+
849
+ result = compile(sources, options)
850
+ if result.num_errors > 0:
851
+ any_failures = 1
852
+ except (OSError, PyrexError) as e:
853
+ sys.stderr.write(str(e) + '\n')
854
+ any_failures = 1
855
+ if any_failures:
856
+ sys.exit(1)