oxython 0.1.0__py3-none-any.whl

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