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