Cython 3.2.0__cp39-abi3-win32.whl

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