Cython 3.0.11__cp313-cp313-win32.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (318) hide show
  1. Cython/Build/BuildExecutable.py +170 -0
  2. Cython/Build/Cythonize.py +255 -0
  3. Cython/Build/Dependencies.py +1380 -0
  4. Cython/Build/Distutils.py +1 -0
  5. Cython/Build/Inline.py +372 -0
  6. Cython/Build/IpythonMagic.py +572 -0
  7. Cython/Build/Tests/TestCyCache.py +119 -0
  8. Cython/Build/Tests/TestCythonizeArgsParser.py +482 -0
  9. Cython/Build/Tests/TestDependencies.py +142 -0
  10. Cython/Build/Tests/TestInline.py +112 -0
  11. Cython/Build/Tests/TestIpythonMagic.py +295 -0
  12. Cython/Build/Tests/TestRecythonize.py +212 -0
  13. Cython/Build/Tests/TestStripLiterals.py +56 -0
  14. Cython/Build/Tests/__init__.py +1 -0
  15. Cython/Build/__init__.py +14 -0
  16. Cython/CodeWriter.py +820 -0
  17. Cython/Compiler/AnalysedTreeTransforms.py +99 -0
  18. Cython/Compiler/Annotate.py +341 -0
  19. Cython/Compiler/AutoDocTransforms.py +318 -0
  20. Cython/Compiler/Buffer.py +749 -0
  21. Cython/Compiler/Builtin.py +644 -0
  22. Cython/Compiler/CmdLine.py +251 -0
  23. Cython/Compiler/Code.cp313-win32.pyd +0 -0
  24. Cython/Compiler/Code.pxd +131 -0
  25. Cython/Compiler/Code.py +2745 -0
  26. Cython/Compiler/CodeGeneration.py +35 -0
  27. Cython/Compiler/CythonScope.py +181 -0
  28. Cython/Compiler/Dataclass.py +839 -0
  29. Cython/Compiler/DebugFlags.py +21 -0
  30. Cython/Compiler/Errors.py +300 -0
  31. Cython/Compiler/ExprNodes.py +14758 -0
  32. Cython/Compiler/FlowControl.cp313-win32.pyd +0 -0
  33. Cython/Compiler/FlowControl.pxd +111 -0
  34. Cython/Compiler/FlowControl.py +1383 -0
  35. Cython/Compiler/FusedNode.cp313-win32.pyd +0 -0
  36. Cython/Compiler/FusedNode.py +1015 -0
  37. Cython/Compiler/Future.py +16 -0
  38. Cython/Compiler/Interpreter.py +64 -0
  39. Cython/Compiler/Lexicon.py +342 -0
  40. Cython/Compiler/Main.py +789 -0
  41. Cython/Compiler/MemoryView.py +863 -0
  42. Cython/Compiler/ModuleNode.py +4029 -0
  43. Cython/Compiler/Naming.py +198 -0
  44. Cython/Compiler/Nodes.py +10420 -0
  45. Cython/Compiler/Optimize.py +5213 -0
  46. Cython/Compiler/Options.py +799 -0
  47. Cython/Compiler/ParseTreeTransforms.pxd +84 -0
  48. Cython/Compiler/ParseTreeTransforms.py +4234 -0
  49. Cython/Compiler/Parsing.cp313-win32.pyd +0 -0
  50. Cython/Compiler/Parsing.pxd +205 -0
  51. Cython/Compiler/Parsing.py +4080 -0
  52. Cython/Compiler/Pipeline.py +419 -0
  53. Cython/Compiler/PyrexTypes.py +5535 -0
  54. Cython/Compiler/Pythran.py +227 -0
  55. Cython/Compiler/Scanning.cp313-win32.pyd +0 -0
  56. Cython/Compiler/Scanning.pxd +63 -0
  57. Cython/Compiler/Scanning.py +582 -0
  58. Cython/Compiler/StringEncoding.py +392 -0
  59. Cython/Compiler/Symtab.py +2916 -0
  60. Cython/Compiler/Tests/TestBuffer.py +105 -0
  61. Cython/Compiler/Tests/TestCmdLine.py +579 -0
  62. Cython/Compiler/Tests/TestFlowControl.py +68 -0
  63. Cython/Compiler/Tests/TestGrammar.py +203 -0
  64. Cython/Compiler/Tests/TestMemView.py +71 -0
  65. Cython/Compiler/Tests/TestParseTreeTransforms.py +289 -0
  66. Cython/Compiler/Tests/TestScanning.py +136 -0
  67. Cython/Compiler/Tests/TestSignatureMatching.py +73 -0
  68. Cython/Compiler/Tests/TestStringEncoding.py +44 -0
  69. Cython/Compiler/Tests/TestTreeFragment.py +63 -0
  70. Cython/Compiler/Tests/TestTreePath.py +93 -0
  71. Cython/Compiler/Tests/TestTypes.py +77 -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 +280 -0
  77. Cython/Compiler/TreePath.py +296 -0
  78. Cython/Compiler/TypeInference.py +596 -0
  79. Cython/Compiler/TypeSlots.py +1180 -0
  80. Cython/Compiler/UFuncs.py +286 -0
  81. Cython/Compiler/UtilNodes.py +388 -0
  82. Cython/Compiler/UtilityCode.py +266 -0
  83. Cython/Compiler/Version.py +9 -0
  84. Cython/Compiler/Visitor.cp313-win32.pyd +0 -0
  85. Cython/Compiler/Visitor.pxd +55 -0
  86. Cython/Compiler/Visitor.py +871 -0
  87. Cython/Compiler/__init__.py +1 -0
  88. Cython/Coverage.py +439 -0
  89. Cython/Debugger/Cygdb.py +180 -0
  90. Cython/Debugger/DebugWriter.py +90 -0
  91. Cython/Debugger/Tests/TestLibCython.py +276 -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 +553 -0
  96. Cython/Debugger/Tests/test_libpython_in_gdb.py +112 -0
  97. Cython/Debugger/__init__.py +1 -0
  98. Cython/Debugger/libcython.py +1461 -0
  99. Cython/Debugger/libpython.py +2851 -0
  100. Cython/Debugging.py +20 -0
  101. Cython/Distutils/__init__.py +2 -0
  102. Cython/Distutils/build_ext.py +138 -0
  103. Cython/Distutils/extension.py +123 -0
  104. Cython/Distutils/old_build_ext.py +357 -0
  105. Cython/Includes/cpython/__init__.pxd +187 -0
  106. Cython/Includes/cpython/array.pxd +174 -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/cobject.pxd +36 -0
  114. Cython/Includes/cpython/codecs.pxd +121 -0
  115. Cython/Includes/cpython/complex.pxd +55 -0
  116. Cython/Includes/cpython/contextvars.pxd +140 -0
  117. Cython/Includes/cpython/conversion.pxd +36 -0
  118. Cython/Includes/cpython/datetime.pxd +426 -0
  119. Cython/Includes/cpython/descr.pxd +26 -0
  120. Cython/Includes/cpython/dict.pxd +186 -0
  121. Cython/Includes/cpython/exc.pxd +263 -0
  122. Cython/Includes/cpython/fileobject.pxd +57 -0
  123. Cython/Includes/cpython/float.pxd +46 -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/int.pxd +89 -0
  129. Cython/Includes/cpython/iterator.pxd +36 -0
  130. Cython/Includes/cpython/iterobject.pxd +24 -0
  131. Cython/Includes/cpython/list.pxd +92 -0
  132. Cython/Includes/cpython/long.pxd +149 -0
  133. Cython/Includes/cpython/longintrepr.pxd +19 -0
  134. Cython/Includes/cpython/mapping.pxd +63 -0
  135. Cython/Includes/cpython/marshal.pxd +66 -0
  136. Cython/Includes/cpython/mem.pxd +120 -0
  137. Cython/Includes/cpython/memoryview.pxd +50 -0
  138. Cython/Includes/cpython/method.pxd +49 -0
  139. Cython/Includes/cpython/module.pxd +208 -0
  140. Cython/Includes/cpython/number.pxd +265 -0
  141. Cython/Includes/cpython/object.pxd +440 -0
  142. Cython/Includes/cpython/oldbuffer.pxd +63 -0
  143. Cython/Includes/cpython/pycapsule.pxd +143 -0
  144. Cython/Includes/cpython/pylifecycle.pxd +68 -0
  145. Cython/Includes/cpython/pyport.pxd +8 -0
  146. Cython/Includes/cpython/pystate.pxd +95 -0
  147. Cython/Includes/cpython/pythread.pxd +53 -0
  148. Cython/Includes/cpython/ref.pxd +50 -0
  149. Cython/Includes/cpython/sequence.pxd +134 -0
  150. Cython/Includes/cpython/set.pxd +119 -0
  151. Cython/Includes/cpython/slice.pxd +70 -0
  152. Cython/Includes/cpython/string.pxd +196 -0
  153. Cython/Includes/cpython/time.pxd +79 -0
  154. Cython/Includes/cpython/tuple.pxd +72 -0
  155. Cython/Includes/cpython/type.pxd +53 -0
  156. Cython/Includes/cpython/unicode.pxd +639 -0
  157. Cython/Includes/cpython/version.pxd +32 -0
  158. Cython/Includes/cpython/weakref.pxd +42 -0
  159. Cython/Includes/libc/__init__.pxd +1 -0
  160. Cython/Includes/libc/complex.pxd +35 -0
  161. Cython/Includes/libc/errno.pxd +127 -0
  162. Cython/Includes/libc/float.pxd +43 -0
  163. Cython/Includes/libc/limits.pxd +28 -0
  164. Cython/Includes/libc/locale.pxd +46 -0
  165. Cython/Includes/libc/math.pxd +209 -0
  166. Cython/Includes/libc/setjmp.pxd +10 -0
  167. Cython/Includes/libc/signal.pxd +64 -0
  168. Cython/Includes/libc/stddef.pxd +9 -0
  169. Cython/Includes/libc/stdint.pxd +105 -0
  170. Cython/Includes/libc/stdio.pxd +80 -0
  171. Cython/Includes/libc/stdlib.pxd +72 -0
  172. Cython/Includes/libc/string.pxd +50 -0
  173. Cython/Includes/libc/time.pxd +47 -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/bit.pxd +29 -0
  179. Cython/Includes/libcpp/cast.pxd +12 -0
  180. Cython/Includes/libcpp/cmath.pxd +518 -0
  181. Cython/Includes/libcpp/complex.pxd +106 -0
  182. Cython/Includes/libcpp/deque.pxd +165 -0
  183. Cython/Includes/libcpp/execution.pxd +15 -0
  184. Cython/Includes/libcpp/forward_list.pxd +63 -0
  185. Cython/Includes/libcpp/functional.pxd +26 -0
  186. Cython/Includes/libcpp/iterator.pxd +34 -0
  187. Cython/Includes/libcpp/limits.pxd +61 -0
  188. Cython/Includes/libcpp/list.pxd +117 -0
  189. Cython/Includes/libcpp/map.pxd +252 -0
  190. Cython/Includes/libcpp/memory.pxd +115 -0
  191. Cython/Includes/libcpp/numbers.pxd +15 -0
  192. Cython/Includes/libcpp/numeric.pxd +131 -0
  193. Cython/Includes/libcpp/optional.pxd +34 -0
  194. Cython/Includes/libcpp/pair.pxd +1 -0
  195. Cython/Includes/libcpp/queue.pxd +25 -0
  196. Cython/Includes/libcpp/random.pxd +166 -0
  197. Cython/Includes/libcpp/set.pxd +228 -0
  198. Cython/Includes/libcpp/stack.pxd +11 -0
  199. Cython/Includes/libcpp/string.pxd +333 -0
  200. Cython/Includes/libcpp/typeindex.pxd +15 -0
  201. Cython/Includes/libcpp/typeinfo.pxd +10 -0
  202. Cython/Includes/libcpp/unordered_map.pxd +193 -0
  203. Cython/Includes/libcpp/unordered_set.pxd +152 -0
  204. Cython/Includes/libcpp/utility.pxd +30 -0
  205. Cython/Includes/libcpp/vector.pxd +167 -0
  206. Cython/Includes/numpy/__init__.pxd +1057 -0
  207. Cython/Includes/numpy/math.pxd +133 -0
  208. Cython/Includes/openmp.pxd +50 -0
  209. Cython/Includes/posix/__init__.pxd +1 -0
  210. Cython/Includes/posix/dlfcn.pxd +14 -0
  211. Cython/Includes/posix/fcntl.pxd +86 -0
  212. Cython/Includes/posix/ioctl.pxd +4 -0
  213. Cython/Includes/posix/mman.pxd +101 -0
  214. Cython/Includes/posix/resource.pxd +57 -0
  215. Cython/Includes/posix/select.pxd +21 -0
  216. Cython/Includes/posix/signal.pxd +73 -0
  217. Cython/Includes/posix/stat.pxd +98 -0
  218. Cython/Includes/posix/stdio.pxd +37 -0
  219. Cython/Includes/posix/stdlib.pxd +29 -0
  220. Cython/Includes/posix/strings.pxd +9 -0
  221. Cython/Includes/posix/time.pxd +71 -0
  222. Cython/Includes/posix/types.pxd +30 -0
  223. Cython/Includes/posix/uio.pxd +26 -0
  224. Cython/Includes/posix/unistd.pxd +271 -0
  225. Cython/Includes/posix/wait.pxd +38 -0
  226. Cython/Plex/Actions.cp313-win32.pyd +0 -0
  227. Cython/Plex/Actions.pxd +26 -0
  228. Cython/Plex/Actions.py +121 -0
  229. Cython/Plex/DFA.cp313-win32.pyd +0 -0
  230. Cython/Plex/DFA.pxd +30 -0
  231. Cython/Plex/DFA.py +149 -0
  232. Cython/Plex/Errors.py +48 -0
  233. Cython/Plex/Lexicons.py +179 -0
  234. Cython/Plex/Machines.cp313-win32.pyd +0 -0
  235. Cython/Plex/Machines.pxd +33 -0
  236. Cython/Plex/Machines.py +242 -0
  237. Cython/Plex/Regexps.py +540 -0
  238. Cython/Plex/Scanners.cp313-win32.pyd +0 -0
  239. Cython/Plex/Scanners.pxd +48 -0
  240. Cython/Plex/Scanners.py +359 -0
  241. Cython/Plex/Transitions.cp313-win32.pyd +0 -0
  242. Cython/Plex/Transitions.pxd +22 -0
  243. Cython/Plex/Transitions.py +234 -0
  244. Cython/Plex/__init__.py +35 -0
  245. Cython/Runtime/__init__.py +1 -0
  246. Cython/Runtime/refnanny.cp313-win32.pyd +0 -0
  247. Cython/Runtime/refnanny.pyx +192 -0
  248. Cython/Shadow.py +609 -0
  249. Cython/Shadow.pyi +102 -0
  250. Cython/StringIOTree.cp313-win32.pyd +0 -0
  251. Cython/StringIOTree.py +174 -0
  252. Cython/Tempita/__init__.py +4 -0
  253. Cython/Tempita/_looper.py +163 -0
  254. Cython/Tempita/_tempita.cp313-win32.pyd +0 -0
  255. Cython/Tempita/_tempita.py +1091 -0
  256. Cython/Tempita/compat3.py +47 -0
  257. Cython/TestUtils.py +398 -0
  258. Cython/Tests/TestCodeWriter.py +128 -0
  259. Cython/Tests/TestCythonUtils.py +205 -0
  260. Cython/Tests/TestJediTyper.py +225 -0
  261. Cython/Tests/TestShadow.py +79 -0
  262. Cython/Tests/TestStringIOTree.py +67 -0
  263. Cython/Tests/TestTestUtils.py +92 -0
  264. Cython/Tests/__init__.py +1 -0
  265. Cython/Tests/xmlrunner.py +395 -0
  266. Cython/Utility/AsyncGen.c +1317 -0
  267. Cython/Utility/Buffer.c +933 -0
  268. Cython/Utility/Builtins.c +609 -0
  269. Cython/Utility/CConvert.pyx +134 -0
  270. Cython/Utility/CMath.c +95 -0
  271. Cython/Utility/CommonStructures.c +139 -0
  272. Cython/Utility/Complex.c +366 -0
  273. Cython/Utility/Coroutine.c +2635 -0
  274. Cython/Utility/CpdefEnums.pyx +175 -0
  275. Cython/Utility/CppConvert.pyx +273 -0
  276. Cython/Utility/CppSupport.cpp +133 -0
  277. Cython/Utility/CythonFunction.c +1810 -0
  278. Cython/Utility/Dataclasses.c +188 -0
  279. Cython/Utility/Dataclasses.py +112 -0
  280. Cython/Utility/Embed.c +255 -0
  281. Cython/Utility/Exceptions.c +1137 -0
  282. Cython/Utility/ExtensionTypes.c +660 -0
  283. Cython/Utility/FunctionArguments.c +587 -0
  284. Cython/Utility/ImportExport.c +939 -0
  285. Cython/Utility/MemoryView.pyx +1481 -0
  286. Cython/Utility/MemoryView_C.c +987 -0
  287. Cython/Utility/ModuleSetupCode.c +2366 -0
  288. Cython/Utility/NumpyImportArray.c +46 -0
  289. Cython/Utility/ObjectHandling.c +3266 -0
  290. Cython/Utility/Optimize.c +1616 -0
  291. Cython/Utility/Overflow.c +404 -0
  292. Cython/Utility/Printing.c +176 -0
  293. Cython/Utility/Profile.c +383 -0
  294. Cython/Utility/StringTools.c +1294 -0
  295. Cython/Utility/TestCyUtilityLoader.pyx +8 -0
  296. Cython/Utility/TestCythonScope.pyx +70 -0
  297. Cython/Utility/TestUtilityLoader.c +12 -0
  298. Cython/Utility/TypeConversion.c +1310 -0
  299. Cython/Utility/UFuncs.pyx +51 -0
  300. Cython/Utility/UFuncs_C.c +42 -0
  301. Cython/Utility/__init__.py +29 -0
  302. Cython/Utility/arrayarray.h +149 -0
  303. Cython/Utils.cp313-win32.pyd +0 -0
  304. Cython/Utils.py +721 -0
  305. Cython/__init__.py +12 -0
  306. Cython-3.0.11.dist-info/COPYING.txt +19 -0
  307. Cython-3.0.11.dist-info/LICENSE.txt +176 -0
  308. Cython-3.0.11.dist-info/METADATA +63 -0
  309. Cython-3.0.11.dist-info/RECORD +318 -0
  310. Cython-3.0.11.dist-info/WHEEL +5 -0
  311. Cython-3.0.11.dist-info/entry_points.txt +4 -0
  312. Cython-3.0.11.dist-info/top_level.txt +3 -0
  313. cython.py +24 -0
  314. pyximport/__init__.py +4 -0
  315. pyximport/_pyximport2.py +620 -0
  316. pyximport/_pyximport3.py +478 -0
  317. pyximport/pyxbuild.py +160 -0
  318. pyximport/pyximport.py +11 -0
@@ -0,0 +1,170 @@
1
+ """
2
+ Compile a Python script into an executable that embeds CPython.
3
+ Requires CPython to be built as a shared library ('libpythonX.Y').
4
+
5
+ Basic usage:
6
+
7
+ python -m Cython.Build.BuildExecutable [ARGS] somefile.py
8
+ """
9
+
10
+ from __future__ import absolute_import
11
+
12
+ DEBUG = True
13
+
14
+ import sys
15
+ import os
16
+ if sys.version_info < (3, 9):
17
+ from distutils import sysconfig as _sysconfig
18
+
19
+ class sysconfig(object):
20
+
21
+ @staticmethod
22
+ def get_path(name):
23
+ assert name == 'include'
24
+ return _sysconfig.get_python_inc()
25
+
26
+ get_config_var = staticmethod(_sysconfig.get_config_var)
27
+ else:
28
+ # sysconfig can be trusted from cpython >= 3.8.7
29
+ import sysconfig
30
+
31
+
32
+ def get_config_var(name, default=''):
33
+ return sysconfig.get_config_var(name) or default
34
+
35
+ INCDIR = sysconfig.get_path('include')
36
+ LIBDIR1 = get_config_var('LIBDIR')
37
+ LIBDIR2 = get_config_var('LIBPL')
38
+ PYLIB = get_config_var('LIBRARY')
39
+ PYLIB_DYN = get_config_var('LDLIBRARY')
40
+ if PYLIB_DYN == PYLIB:
41
+ # no shared library
42
+ PYLIB_DYN = ''
43
+ else:
44
+ PYLIB_DYN = os.path.splitext(PYLIB_DYN[3:])[0] # 'lib(XYZ).so' -> XYZ
45
+
46
+ CC = get_config_var('CC', os.environ.get('CC', ''))
47
+ CFLAGS = get_config_var('CFLAGS') + ' ' + os.environ.get('CFLAGS', '')
48
+ LINKCC = get_config_var('LINKCC', os.environ.get('LINKCC', CC))
49
+ LINKFORSHARED = get_config_var('LINKFORSHARED')
50
+ LIBS = get_config_var('LIBS')
51
+ SYSLIBS = get_config_var('SYSLIBS')
52
+ EXE_EXT = sysconfig.get_config_var('EXE')
53
+
54
+
55
+ def _debug(msg, *args):
56
+ if DEBUG:
57
+ if args:
58
+ msg = msg % args
59
+ sys.stderr.write(msg + '\n')
60
+
61
+
62
+ def dump_config():
63
+ _debug('INCDIR: %s', INCDIR)
64
+ _debug('LIBDIR1: %s', LIBDIR1)
65
+ _debug('LIBDIR2: %s', LIBDIR2)
66
+ _debug('PYLIB: %s', PYLIB)
67
+ _debug('PYLIB_DYN: %s', PYLIB_DYN)
68
+ _debug('CC: %s', CC)
69
+ _debug('CFLAGS: %s', CFLAGS)
70
+ _debug('LINKCC: %s', LINKCC)
71
+ _debug('LINKFORSHARED: %s', LINKFORSHARED)
72
+ _debug('LIBS: %s', LIBS)
73
+ _debug('SYSLIBS: %s', SYSLIBS)
74
+ _debug('EXE_EXT: %s', EXE_EXT)
75
+
76
+
77
+ def _parse_args(args):
78
+ cy_args = []
79
+ last_arg = None
80
+ for i, arg in enumerate(args):
81
+ if arg.startswith('-'):
82
+ cy_args.append(arg)
83
+ elif last_arg in ('-X', '--directive'):
84
+ cy_args.append(arg)
85
+ else:
86
+ input_file = arg
87
+ args = args[i+1:]
88
+ break
89
+ last_arg = arg
90
+ else:
91
+ raise ValueError('no input file provided')
92
+
93
+ return input_file, cy_args, args
94
+
95
+
96
+ def runcmd(cmd, shell=True):
97
+ if shell:
98
+ cmd = ' '.join(cmd)
99
+ _debug(cmd)
100
+ else:
101
+ _debug(' '.join(cmd))
102
+
103
+ import subprocess
104
+ returncode = subprocess.call(cmd, shell=shell)
105
+
106
+ if returncode:
107
+ sys.exit(returncode)
108
+
109
+
110
+ def clink(basename):
111
+ runcmd([LINKCC, '-o', basename + EXE_EXT, basename+'.o', '-L'+LIBDIR1, '-L'+LIBDIR2]
112
+ + [PYLIB_DYN and ('-l'+PYLIB_DYN) or os.path.join(LIBDIR1, PYLIB)]
113
+ + LIBS.split() + SYSLIBS.split() + LINKFORSHARED.split())
114
+
115
+
116
+ def ccompile(basename):
117
+ runcmd([CC, '-c', '-o', basename+'.o', basename+'.c', '-I' + INCDIR] + CFLAGS.split())
118
+
119
+
120
+ def cycompile(input_file, options=()):
121
+ from ..Compiler import Version, CmdLine, Main
122
+ options, sources = CmdLine.parse_command_line(list(options or ()) + ['--embed', input_file])
123
+ _debug('Using Cython %s to compile %s', Version.version, input_file)
124
+ result = Main.compile(sources, options)
125
+ if result.num_errors > 0:
126
+ sys.exit(1)
127
+
128
+
129
+ def exec_file(program_name, args=()):
130
+ runcmd([os.path.abspath(program_name)] + list(args), shell=False)
131
+
132
+
133
+ def build(input_file, compiler_args=(), force=False):
134
+ """
135
+ Build an executable program from a Cython module.
136
+
137
+ Returns the name of the executable file.
138
+ """
139
+ basename = os.path.splitext(input_file)[0]
140
+ exe_file = basename + EXE_EXT
141
+ if not force and os.path.abspath(exe_file) == os.path.abspath(input_file):
142
+ raise ValueError("Input and output file names are the same, refusing to overwrite")
143
+ if (not force and os.path.exists(exe_file) and os.path.exists(input_file)
144
+ and os.path.getmtime(input_file) <= os.path.getmtime(exe_file)):
145
+ _debug("File is up to date, not regenerating %s", exe_file)
146
+ return exe_file
147
+ cycompile(input_file, compiler_args)
148
+ ccompile(basename)
149
+ clink(basename)
150
+ return exe_file
151
+
152
+
153
+ def build_and_run(args):
154
+ """
155
+ Build an executable program from a Cython module and run it.
156
+
157
+ Arguments after the module name will be passed verbatimly to the program.
158
+ """
159
+ program_name, args = _build(args)
160
+ exec_file(program_name, args)
161
+
162
+
163
+ def _build(args):
164
+ input_file, cy_args, args = _parse_args(args)
165
+ program_name = build(input_file, cy_args)
166
+ return program_name, args
167
+
168
+
169
+ if __name__ == '__main__':
170
+ _build(sys.argv[1:])
@@ -0,0 +1,255 @@
1
+ from __future__ import absolute_import, print_function
2
+
3
+ import os
4
+ import shutil
5
+ import tempfile
6
+
7
+ from .Dependencies import cythonize, extended_iglob
8
+ from ..Utils import is_package_dir
9
+ from ..Compiler import Options
10
+
11
+ try:
12
+ import multiprocessing
13
+ parallel_compiles = int(multiprocessing.cpu_count() * 1.5)
14
+ except ImportError:
15
+ multiprocessing = None
16
+ parallel_compiles = 0
17
+
18
+
19
+ class _FakePool(object):
20
+ def map_async(self, func, args):
21
+ try:
22
+ from itertools import imap
23
+ except ImportError:
24
+ imap=map
25
+ for _ in imap(func, args):
26
+ pass
27
+
28
+ def close(self):
29
+ pass
30
+
31
+ def terminate(self):
32
+ pass
33
+
34
+ def join(self):
35
+ pass
36
+
37
+
38
+ def find_package_base(path):
39
+ base_dir, package_path = os.path.split(path)
40
+ while is_package_dir(base_dir):
41
+ base_dir, parent = os.path.split(base_dir)
42
+ package_path = '%s/%s' % (parent, package_path)
43
+ return base_dir, package_path
44
+
45
+ def cython_compile(path_pattern, options):
46
+ all_paths = map(os.path.abspath, extended_iglob(path_pattern))
47
+ _cython_compile_files(all_paths, options)
48
+
49
+ def _cython_compile_files(all_paths, options):
50
+ pool = None
51
+ try:
52
+ for path in all_paths:
53
+ if options.build_inplace:
54
+ base_dir = path
55
+ while not os.path.isdir(base_dir) or is_package_dir(base_dir):
56
+ base_dir = os.path.dirname(base_dir)
57
+ else:
58
+ base_dir = None
59
+
60
+ if os.path.isdir(path):
61
+ # recursively compiling a package
62
+ paths = [os.path.join(path, '**', '*.{py,pyx}')]
63
+ else:
64
+ # assume it's a file(-like thing)
65
+ paths = [path]
66
+
67
+ ext_modules = cythonize(
68
+ paths,
69
+ nthreads=options.parallel,
70
+ exclude_failures=options.keep_going,
71
+ exclude=options.excludes,
72
+ compiler_directives=options.directives,
73
+ compile_time_env=options.compile_time_env,
74
+ force=options.force,
75
+ quiet=options.quiet,
76
+ depfile=options.depfile,
77
+ language=options.language,
78
+ **options.options)
79
+
80
+ if ext_modules and options.build:
81
+ if len(ext_modules) > 1 and options.parallel > 1:
82
+ if pool is None:
83
+ try:
84
+ pool = multiprocessing.Pool(options.parallel)
85
+ except OSError:
86
+ pool = _FakePool()
87
+ pool.map_async(run_distutils, [
88
+ (base_dir, [ext]) for ext in ext_modules])
89
+ else:
90
+ run_distutils((base_dir, ext_modules))
91
+ except:
92
+ if pool is not None:
93
+ pool.terminate()
94
+ raise
95
+ else:
96
+ if pool is not None:
97
+ pool.close()
98
+ pool.join()
99
+
100
+
101
+ def run_distutils(args):
102
+ try:
103
+ from distutils.core import setup
104
+ except ImportError:
105
+ try:
106
+ from setuptools import setup
107
+ except ImportError:
108
+ raise ImportError("'distutils' is not available. Please install 'setuptools' for binary builds.")
109
+
110
+ base_dir, ext_modules = args
111
+ script_args = ['build_ext', '-i']
112
+ cwd = os.getcwd()
113
+ temp_dir = None
114
+ try:
115
+ if base_dir:
116
+ os.chdir(base_dir)
117
+ temp_dir = tempfile.mkdtemp(dir=base_dir)
118
+ script_args.extend(['--build-temp', temp_dir])
119
+ setup(
120
+ script_name='setup.py',
121
+ script_args=script_args,
122
+ ext_modules=ext_modules,
123
+ )
124
+ finally:
125
+ if base_dir:
126
+ os.chdir(cwd)
127
+ if temp_dir and os.path.isdir(temp_dir):
128
+ shutil.rmtree(temp_dir)
129
+
130
+
131
+ def create_args_parser():
132
+ from argparse import ArgumentParser, RawDescriptionHelpFormatter
133
+ from ..Compiler.CmdLine import ParseDirectivesAction, ParseOptionsAction, ParseCompileTimeEnvAction
134
+
135
+ parser = ArgumentParser(
136
+ formatter_class=RawDescriptionHelpFormatter,
137
+ epilog="""\
138
+ Environment variables:
139
+ CYTHON_FORCE_REGEN: if set to 1, forces cythonize to regenerate the output files regardless
140
+ of modification times and changes.
141
+ Environment variables accepted by setuptools are supported to configure the C compiler and build:
142
+ https://setuptools.pypa.io/en/latest/userguide/ext_modules.html#compiler-and-linker-options"""
143
+ )
144
+
145
+ parser.add_argument('-X', '--directive', metavar='NAME=VALUE,...',
146
+ dest='directives', default={}, type=str,
147
+ action=ParseDirectivesAction,
148
+ help='set a compiler directive')
149
+ parser.add_argument('-E', '--compile-time-env', metavar='NAME=VALUE,...',
150
+ dest='compile_time_env', default={}, type=str,
151
+ action=ParseCompileTimeEnvAction,
152
+ help='set a compile time environment variable')
153
+ parser.add_argument('-s', '--option', metavar='NAME=VALUE',
154
+ dest='options', default={}, type=str,
155
+ action=ParseOptionsAction,
156
+ help='set a cythonize option')
157
+ parser.add_argument('-2', dest='language_level', action='store_const', const=2, default=None,
158
+ help='use Python 2 syntax mode by default')
159
+ parser.add_argument('-3', dest='language_level', action='store_const', const=3,
160
+ help='use Python 3 syntax mode by default')
161
+ parser.add_argument('--3str', dest='language_level', action='store_const', const='3str',
162
+ help='use Python 3 syntax mode by default')
163
+ parser.add_argument('-+', '--cplus', dest='language', action='store_const', const='c++', default=None,
164
+ help='Compile as C++ rather than C')
165
+ parser.add_argument('-a', '--annotate', action='store_const', const='default', dest='annotate',
166
+ help='Produce a colorized HTML version of the source.')
167
+ parser.add_argument('--annotate-fullc', action='store_const', const='fullc', dest='annotate',
168
+ help='Produce a colorized HTML version of the source '
169
+ 'which includes entire generated C/C++-code.')
170
+ parser.add_argument('-x', '--exclude', metavar='PATTERN', dest='excludes',
171
+ action='append', default=[],
172
+ help='exclude certain file patterns from the compilation')
173
+
174
+ parser.add_argument('-b', '--build', dest='build', action='store_true', default=None,
175
+ help='build extension modules using distutils/setuptools')
176
+ parser.add_argument('-i', '--inplace', dest='build_inplace', action='store_true', default=None,
177
+ help='build extension modules in place using distutils/setuptools (implies -b)')
178
+ parser.add_argument('-j', '--parallel', dest='parallel', metavar='N',
179
+ type=int, default=parallel_compiles,
180
+ help=('run builds in N parallel jobs (default: %d)' %
181
+ parallel_compiles or 1))
182
+ parser.add_argument('-f', '--force', dest='force', action='store_true', default=None,
183
+ help='force recompilation')
184
+ parser.add_argument('-q', '--quiet', dest='quiet', action='store_true', default=None,
185
+ help='be less verbose during compilation')
186
+
187
+ parser.add_argument('--lenient', dest='lenient', action='store_true', default=None,
188
+ help='increase Python compatibility by ignoring some compile time errors')
189
+ parser.add_argument('-k', '--keep-going', dest='keep_going', action='store_true', default=None,
190
+ help='compile as much as possible, ignore compilation failures')
191
+ parser.add_argument('--no-docstrings', dest='no_docstrings', action='store_true', default=None,
192
+ help='strip docstrings')
193
+ parser.add_argument('-M', '--depfile', action='store_true', help='produce depfiles for the sources')
194
+ parser.add_argument('sources', nargs='*')
195
+ return parser
196
+
197
+
198
+ def parse_args_raw(parser, args):
199
+ options, unknown = parser.parse_known_args(args)
200
+ sources = options.sources
201
+ # if positional arguments were interspersed
202
+ # some of them are in unknown
203
+ for option in unknown:
204
+ if option.startswith('-'):
205
+ parser.error("unknown option "+option)
206
+ else:
207
+ sources.append(option)
208
+ del options.sources
209
+ return (options, sources)
210
+
211
+
212
+ def parse_args(args):
213
+ parser = create_args_parser()
214
+ options, args = parse_args_raw(parser, args)
215
+
216
+ if not args:
217
+ parser.error("no source files provided")
218
+ if options.build_inplace:
219
+ options.build = True
220
+ if multiprocessing is None:
221
+ options.parallel = 0
222
+ if options.language_level:
223
+ assert options.language_level in (2, 3, '3str')
224
+ options.options['language_level'] = options.language_level
225
+
226
+ if options.lenient:
227
+ # increase Python compatibility by ignoring compile time errors
228
+ Options.error_on_unknown_names = False
229
+ Options.error_on_uninitialized = False
230
+
231
+ if options.annotate:
232
+ Options.annotate = options.annotate
233
+
234
+ if options.no_docstrings:
235
+ Options.docstrings = False
236
+
237
+ return options, args
238
+
239
+
240
+ def main(args=None):
241
+ options, paths = parse_args(args)
242
+
243
+ all_paths = []
244
+ for path in paths:
245
+ expanded_path = [os.path.abspath(p) for p in extended_iglob(path)]
246
+ if not expanded_path:
247
+ import sys
248
+ print("{}: No such file or directory: '{}'".format(sys.argv[0], path), file=sys.stderr)
249
+ sys.exit(1)
250
+ all_paths.extend(expanded_path)
251
+ _cython_compile_files(all_paths, options)
252
+
253
+
254
+ if __name__ == '__main__':
255
+ main()