pytron-kit 0.3.12__py3-none-macosx_11_0_universal2.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 (419) hide show
  1. pytron/__init__.py +112 -0
  2. pytron/application.py +562 -0
  3. pytron/apputils/__init__.py +0 -0
  4. pytron/apputils/chrome_ipc.py +203 -0
  5. pytron/apputils/codegen.py +261 -0
  6. pytron/apputils/config.py +303 -0
  7. pytron/apputils/deadmansswitch.py +47 -0
  8. pytron/apputils/extras.py +76 -0
  9. pytron/apputils/native.py +148 -0
  10. pytron/apputils/shell.py +73 -0
  11. pytron/apputils/windows.py +286 -0
  12. pytron/cli.py +384 -0
  13. pytron/commands/__init__.py +0 -0
  14. pytron/commands/android.py +28 -0
  15. pytron/commands/build.py +26 -0
  16. pytron/commands/doctor.py +221 -0
  17. pytron/commands/engine.py +23 -0
  18. pytron/commands/frontend.py +60 -0
  19. pytron/commands/harvest.py +112 -0
  20. pytron/commands/helpers.py +239 -0
  21. pytron/commands/info.py +50 -0
  22. pytron/commands/init.py +521 -0
  23. pytron/commands/install.py +294 -0
  24. pytron/commands/login.py +130 -0
  25. pytron/commands/package.py +228 -0
  26. pytron/commands/plugin.py +442 -0
  27. pytron/commands/run.py +312 -0
  28. pytron/commands/scan.py +210 -0
  29. pytron/commands/show.py +23 -0
  30. pytron/commands/uninstall.py +150 -0
  31. pytron/commands/utils.py +42 -0
  32. pytron/commands/workflow.py +95 -0
  33. pytron/console.py +133 -0
  34. pytron/core.py +18 -0
  35. pytron/dependencies/WebView2Loader.dll +0 -0
  36. pytron/dependencies/__init__.py +1 -0
  37. pytron/dependencies/pytron_native.so +0 -0
  38. pytron/engines/chrome/adapter.py +445 -0
  39. pytron/engines/chrome/engine.py +576 -0
  40. pytron/engines/chrome/forge.py +147 -0
  41. pytron/engines/chrome/shell/package.json +8 -0
  42. pytron/engines/chrome/shell/preload.js +12 -0
  43. pytron/engines/chrome/shell/shell.js +534 -0
  44. pytron/exceptions.py +36 -0
  45. pytron/inspector.py +201 -0
  46. pytron/inspector_ui.py +512 -0
  47. pytron/installer/Installation.nsi +236 -0
  48. pytron/installer/header.bmp +0 -0
  49. pytron/installer/pytron.ico +0 -0
  50. pytron/installer/sidebar.bmp +0 -0
  51. pytron/llms.md +98 -0
  52. pytron/manifests/README.md +29 -0
  53. pytron/manifests/windows-utf8.manifest +44 -0
  54. pytron/menu.py +128 -0
  55. pytron/nsis-setup.exe +0 -0
  56. pytron/pack/__init__.py +0 -0
  57. pytron/pack/assets.py +131 -0
  58. pytron/pack/compilers.py +289 -0
  59. pytron/pack/crystal.py +297 -0
  60. pytron/pack/graph.py +377 -0
  61. pytron/pack/inference.py +157 -0
  62. pytron/pack/installers.py +402 -0
  63. pytron/pack/introspect.py +357 -0
  64. pytron/pack/metadata.py +213 -0
  65. pytron/pack/modules.py +618 -0
  66. pytron/pack/nuitka.py +108 -0
  67. pytron/pack/pipeline.py +107 -0
  68. pytron/pack/pyinstaller.py +176 -0
  69. pytron/pack/rust_engine.py +273 -0
  70. pytron/pack/secure.py +309 -0
  71. pytron/pack/secure_loader/bin/pytron_rust_bootloader +0 -0
  72. pytron/pack/secure_loader/icon.ico +0 -0
  73. pytron/pack/utils.py +110 -0
  74. pytron/pack/virtual_root.py +124 -0
  75. pytron/platforms/__init__.py +0 -0
  76. pytron/platforms/android/__init__.py +3 -0
  77. pytron/platforms/android/android.py +103 -0
  78. pytron/platforms/android/builder.py +736 -0
  79. pytron/platforms/android/ops/build.py +79 -0
  80. pytron/platforms/android/ops/init.py +63 -0
  81. pytron/platforms/android/ops/run.py +79 -0
  82. pytron/platforms/android/ops/sync.py +770 -0
  83. pytron/platforms/android/ops/utils.py +8 -0
  84. pytron/platforms/android/shell/README.md +30 -0
  85. pytron/platforms/android/shell/app/build.gradle +64 -0
  86. pytron/platforms/android/shell/app/src/main/AndroidManifest.xml +29 -0
  87. pytron/platforms/android/shell/app/src/main/assets/python/main.py +86 -0
  88. pytron/platforms/android/shell/app/src/main/assets/python/python314.zip +0 -0
  89. pytron/platforms/android/shell/app/src/main/cpp/CMakeLists.txt +25 -0
  90. pytron/platforms/android/shell/app/src/main/cpp/include/Python.h +155 -0
  91. pytron/platforms/android/shell/app/src/main/cpp/include/abstract.h +915 -0
  92. pytron/platforms/android/shell/app/src/main/cpp/include/audit.h +30 -0
  93. pytron/platforms/android/shell/app/src/main/cpp/include/bltinmodule.h +14 -0
  94. pytron/platforms/android/shell/app/src/main/cpp/include/boolobject.h +54 -0
  95. pytron/platforms/android/shell/app/src/main/cpp/include/bytearrayobject.h +44 -0
  96. pytron/platforms/android/shell/app/src/main/cpp/include/bytesobject.h +66 -0
  97. pytron/platforms/android/shell/app/src/main/cpp/include/ceval.h +145 -0
  98. pytron/platforms/android/shell/app/src/main/cpp/include/codecs.h +176 -0
  99. pytron/platforms/android/shell/app/src/main/cpp/include/compile.h +22 -0
  100. pytron/platforms/android/shell/app/src/main/cpp/include/complexobject.h +30 -0
  101. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/abstract.h +104 -0
  102. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/audit.h +8 -0
  103. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/bytearrayobject.h +38 -0
  104. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/bytesobject.h +42 -0
  105. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/cellobject.h +50 -0
  106. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/ceval.h +43 -0
  107. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/classobject.h +71 -0
  108. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/code.h +340 -0
  109. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/compile.h +50 -0
  110. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/complexobject.h +33 -0
  111. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/context.h +107 -0
  112. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/critical_section.h +154 -0
  113. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/descrobject.h +62 -0
  114. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/dictobject.h +105 -0
  115. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/fileobject.h +16 -0
  116. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/fileutils.h +16 -0
  117. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/floatobject.h +27 -0
  118. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/frameobject.h +35 -0
  119. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/funcobject.h +185 -0
  120. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/genobject.h +56 -0
  121. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/import.h +30 -0
  122. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/initconfig.h +334 -0
  123. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/listobject.h +53 -0
  124. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/lock.h +74 -0
  125. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/longintrepr.h +184 -0
  126. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/longobject.h +89 -0
  127. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/memoryobject.h +50 -0
  128. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/methodobject.h +66 -0
  129. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/modsupport.h +26 -0
  130. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/monitoring.h +269 -0
  131. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/object.h +493 -0
  132. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/objimpl.h +104 -0
  133. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/odictobject.h +43 -0
  134. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/picklebufobject.h +31 -0
  135. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pthread_stubs.h +105 -0
  136. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyatomic.h +614 -0
  137. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyatomic_gcc.h +615 -0
  138. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyatomic_msc.h +1197 -0
  139. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyatomic_std.h +1112 -0
  140. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyctype.h +39 -0
  141. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pydebug.h +38 -0
  142. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyerrors.h +132 -0
  143. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyfpe.h +15 -0
  144. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyframe.h +45 -0
  145. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyhash.h +54 -0
  146. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pylifecycle.h +89 -0
  147. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pymem.h +84 -0
  148. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pystate.h +275 -0
  149. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pystats.h +194 -0
  150. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pythonrun.h +96 -0
  151. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pythread.h +43 -0
  152. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pytime.h +27 -0
  153. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/setobject.h +71 -0
  154. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/traceback.h +13 -0
  155. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/tracemalloc.h +32 -0
  156. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/tupleobject.h +40 -0
  157. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/unicodeobject.h +773 -0
  158. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/warnings.h +20 -0
  159. pytron/platforms/android/shell/app/src/main/cpp/include/cpython/weakrefobject.h +66 -0
  160. pytron/platforms/android/shell/app/src/main/cpp/include/critical_section.h +16 -0
  161. pytron/platforms/android/shell/app/src/main/cpp/include/datetime.h +267 -0
  162. pytron/platforms/android/shell/app/src/main/cpp/include/descrobject.h +100 -0
  163. pytron/platforms/android/shell/app/src/main/cpp/include/dictobject.h +108 -0
  164. pytron/platforms/android/shell/app/src/main/cpp/include/dynamic_annotations.h +499 -0
  165. pytron/platforms/android/shell/app/src/main/cpp/include/enumobject.h +17 -0
  166. pytron/platforms/android/shell/app/src/main/cpp/include/errcode.h +45 -0
  167. pytron/platforms/android/shell/app/src/main/cpp/include/exports.h +105 -0
  168. pytron/platforms/android/shell/app/src/main/cpp/include/fileobject.h +41 -0
  169. pytron/platforms/android/shell/app/src/main/cpp/include/fileutils.h +62 -0
  170. pytron/platforms/android/shell/app/src/main/cpp/include/floatobject.h +54 -0
  171. pytron/platforms/android/shell/app/src/main/cpp/include/frameobject.h +20 -0
  172. pytron/platforms/android/shell/app/src/main/cpp/include/genericaliasobject.h +14 -0
  173. pytron/platforms/android/shell/app/src/main/cpp/include/import.h +103 -0
  174. pytron/platforms/android/shell/app/src/main/cpp/include/internal/mimalloc/mimalloc/atomic.h +392 -0
  175. pytron/platforms/android/shell/app/src/main/cpp/include/internal/mimalloc/mimalloc/internal.h +969 -0
  176. pytron/platforms/android/shell/app/src/main/cpp/include/internal/mimalloc/mimalloc/prim.h +329 -0
  177. pytron/platforms/android/shell/app/src/main/cpp/include/internal/mimalloc/mimalloc/track.h +147 -0
  178. pytron/platforms/android/shell/app/src/main/cpp/include/internal/mimalloc/mimalloc/types.h +721 -0
  179. pytron/platforms/android/shell/app/src/main/cpp/include/internal/mimalloc/mimalloc.h +565 -0
  180. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_abstract.h +61 -0
  181. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_asdl.h +112 -0
  182. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_ast.h +945 -0
  183. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_ast_state.h +271 -0
  184. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_atexit.h +31 -0
  185. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_audit.h +35 -0
  186. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_backoff.h +133 -0
  187. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_bitutils.h +186 -0
  188. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_blocks_output_buffer.h +321 -0
  189. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_brc.h +73 -0
  190. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_bytes_methods.h +82 -0
  191. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_bytesobject.h +149 -0
  192. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_c_array.h +39 -0
  193. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_call.h +206 -0
  194. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_capsule.h +17 -0
  195. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_cell.h +75 -0
  196. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_ceval.h +390 -0
  197. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_ceval_state.h +48 -0
  198. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_code.h +671 -0
  199. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_codecs.h +76 -0
  200. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_compile.h +230 -0
  201. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_complexobject.h +34 -0
  202. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_condvar.h +93 -0
  203. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_context.h +59 -0
  204. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_critical_section.h +237 -0
  205. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_crossinterp.h +406 -0
  206. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_crossinterp_data_registry.h +41 -0
  207. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_debug_offsets.h +379 -0
  208. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_descrobject.h +28 -0
  209. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_dict.h +410 -0
  210. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_dict_state.h +28 -0
  211. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_dtoa.h +40 -0
  212. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_emscripten_signal.h +30 -0
  213. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_emscripten_trampoline.h +70 -0
  214. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_exceptions.h +40 -0
  215. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_faulthandler.h +100 -0
  216. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_fileutils.h +320 -0
  217. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_fileutils_windows.h +98 -0
  218. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_floatobject.h +49 -0
  219. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_flowgraph.h +47 -0
  220. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_format.h +27 -0
  221. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_frame.h +61 -0
  222. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_freelist.h +111 -0
  223. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_freelist_state.h +70 -0
  224. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_function.h +53 -0
  225. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_gc.h +378 -0
  226. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_genobject.h +43 -0
  227. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_getopt.h +22 -0
  228. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_gil.h +66 -0
  229. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_global_objects.h +34 -0
  230. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_global_objects_fini_generated.h +1592 -0
  231. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_global_strings.h +854 -0
  232. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_hamt.h +113 -0
  233. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_hashtable.h +150 -0
  234. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_import.h +141 -0
  235. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_importdl.h +139 -0
  236. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_index_pool.h +36 -0
  237. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_initconfig.h +197 -0
  238. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_instruction_sequence.h +83 -0
  239. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_instruments.h +127 -0
  240. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_interp.h +109 -0
  241. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_interp_structs.h +977 -0
  242. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_interpframe.h +401 -0
  243. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_interpframe_structs.h +95 -0
  244. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_interpolation.h +26 -0
  245. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_intrinsics.h +51 -0
  246. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_jit.h +29 -0
  247. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_list.h +81 -0
  248. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_llist.h +106 -0
  249. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_lock.h +236 -0
  250. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_long.h +319 -0
  251. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_magic_number.h +305 -0
  252. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_memoryobject.h +20 -0
  253. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_mimalloc.h +69 -0
  254. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_modsupport.h +99 -0
  255. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_moduleobject.h +62 -0
  256. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_namespace.h +21 -0
  257. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_object.h +1029 -0
  258. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_object_alloc.h +71 -0
  259. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_object_deferred.h +32 -0
  260. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_object_stack.h +95 -0
  261. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_object_state.h +49 -0
  262. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_obmalloc.h +702 -0
  263. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_obmalloc_init.h +66 -0
  264. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_opcode_metadata.h +2117 -0
  265. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_opcode_utils.h +90 -0
  266. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_optimizer.h +318 -0
  267. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_parking_lot.h +97 -0
  268. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_parser.h +78 -0
  269. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pathconfig.h +26 -0
  270. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pyarena.h +68 -0
  271. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pyatomic_ft_wrappers.h +174 -0
  272. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pybuffer.h +21 -0
  273. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pyerrors.h +213 -0
  274. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pyhash.h +91 -0
  275. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pylifecycle.h +136 -0
  276. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pymath.h +205 -0
  277. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pymem.h +145 -0
  278. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pymem_init.h +103 -0
  279. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pystate.h +339 -0
  280. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pystats.h +21 -0
  281. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pythonrun.h +68 -0
  282. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pythread.h +172 -0
  283. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_qsbr.h +172 -0
  284. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_range.h +21 -0
  285. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_runtime.h +63 -0
  286. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_runtime_init.h +239 -0
  287. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_runtime_init_generated.h +1589 -0
  288. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_runtime_structs.h +310 -0
  289. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_semaphore.h +67 -0
  290. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_setobject.h +41 -0
  291. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_signal.h +108 -0
  292. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_sliceobject.h +20 -0
  293. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_stackref.h +791 -0
  294. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_stats.h +97 -0
  295. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_strhex.h +39 -0
  296. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_structs.h +88 -0
  297. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_structseq.h +40 -0
  298. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_symtable.h +201 -0
  299. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_sysmodule.h +32 -0
  300. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_template.h +26 -0
  301. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_time.h +334 -0
  302. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_token.h +110 -0
  303. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_traceback.h +111 -0
  304. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_tracemalloc.h +164 -0
  305. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_tstate.h +88 -0
  306. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_tuple.h +75 -0
  307. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_typedefs.h +18 -0
  308. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_typeobject.h +155 -0
  309. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_typevarobject.h +28 -0
  310. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_ucnhash.h +36 -0
  311. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_unicodeobject.h +308 -0
  312. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_unicodeobject_generated.h +3132 -0
  313. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_unionobject.h +26 -0
  314. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_uniqueid.h +57 -0
  315. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_uop_ids.h +335 -0
  316. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_uop_metadata.h +1204 -0
  317. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_warnings.h +21 -0
  318. pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_weakref.h +133 -0
  319. pytron/platforms/android/shell/app/src/main/cpp/include/intrcheck.h +23 -0
  320. pytron/platforms/android/shell/app/src/main/cpp/include/iterobject.h +24 -0
  321. pytron/platforms/android/shell/app/src/main/cpp/include/listobject.h +55 -0
  322. pytron/platforms/android/shell/app/src/main/cpp/include/lock.h +16 -0
  323. pytron/platforms/android/shell/app/src/main/cpp/include/longobject.h +178 -0
  324. pytron/platforms/android/shell/app/src/main/cpp/include/marshal.h +31 -0
  325. pytron/platforms/android/shell/app/src/main/cpp/include/memoryobject.h +34 -0
  326. pytron/platforms/android/shell/app/src/main/cpp/include/methodobject.h +146 -0
  327. pytron/platforms/android/shell/app/src/main/cpp/include/modsupport.h +146 -0
  328. pytron/platforms/android/shell/app/src/main/cpp/include/moduleobject.h +122 -0
  329. pytron/platforms/android/shell/app/src/main/cpp/include/monitoring.h +18 -0
  330. pytron/platforms/android/shell/app/src/main/cpp/include/object.h +828 -0
  331. pytron/platforms/android/shell/app/src/main/cpp/include/objimpl.h +211 -0
  332. pytron/platforms/android/shell/app/src/main/cpp/include/opcode.h +43 -0
  333. pytron/platforms/android/shell/app/src/main/cpp/include/opcode_ids.h +259 -0
  334. pytron/platforms/android/shell/app/src/main/cpp/include/osdefs.h +57 -0
  335. pytron/platforms/android/shell/app/src/main/cpp/include/osmodule.h +17 -0
  336. pytron/platforms/android/shell/app/src/main/cpp/include/patchlevel.h +49 -0
  337. pytron/platforms/android/shell/app/src/main/cpp/include/py_curses.h +117 -0
  338. pytron/platforms/android/shell/app/src/main/cpp/include/pyatomic.h +16 -0
  339. pytron/platforms/android/shell/app/src/main/cpp/include/pybuffer.h +145 -0
  340. pytron/platforms/android/shell/app/src/main/cpp/include/pycapsule.h +58 -0
  341. pytron/platforms/android/shell/app/src/main/cpp/include/pyconfig.h +2088 -0
  342. pytron/platforms/android/shell/app/src/main/cpp/include/pydtrace.h +59 -0
  343. pytron/platforms/android/shell/app/src/main/cpp/include/pyerrors.h +335 -0
  344. pytron/platforms/android/shell/app/src/main/cpp/include/pyexpat.h +62 -0
  345. pytron/platforms/android/shell/app/src/main/cpp/include/pyframe.h +26 -0
  346. pytron/platforms/android/shell/app/src/main/cpp/include/pyhash.h +59 -0
  347. pytron/platforms/android/shell/app/src/main/cpp/include/pylifecycle.h +80 -0
  348. pytron/platforms/android/shell/app/src/main/cpp/include/pymacconfig.h +91 -0
  349. pytron/platforms/android/shell/app/src/main/cpp/include/pymacro.h +243 -0
  350. pytron/platforms/android/shell/app/src/main/cpp/include/pymath.h +65 -0
  351. pytron/platforms/android/shell/app/src/main/cpp/include/pymem.h +110 -0
  352. pytron/platforms/android/shell/app/src/main/cpp/include/pyport.h +710 -0
  353. pytron/platforms/android/shell/app/src/main/cpp/include/pystate.h +132 -0
  354. pytron/platforms/android/shell/app/src/main/cpp/include/pystats.h +28 -0
  355. pytron/platforms/android/shell/app/src/main/cpp/include/pystrcmp.h +23 -0
  356. pytron/platforms/android/shell/app/src/main/cpp/include/pystrtod.h +37 -0
  357. pytron/platforms/android/shell/app/src/main/cpp/include/pythonrun.h +42 -0
  358. pytron/platforms/android/shell/app/src/main/cpp/include/pythread.h +131 -0
  359. pytron/platforms/android/shell/app/src/main/cpp/include/pytypedefs.h +30 -0
  360. pytron/platforms/android/shell/app/src/main/cpp/include/rangeobject.h +27 -0
  361. pytron/platforms/android/shell/app/src/main/cpp/include/refcount.h +555 -0
  362. pytron/platforms/android/shell/app/src/main/cpp/include/setobject.h +49 -0
  363. pytron/platforms/android/shell/app/src/main/cpp/include/sliceobject.h +69 -0
  364. pytron/platforms/android/shell/app/src/main/cpp/include/structmember.h +56 -0
  365. pytron/platforms/android/shell/app/src/main/cpp/include/structseq.h +46 -0
  366. pytron/platforms/android/shell/app/src/main/cpp/include/sysmodule.h +27 -0
  367. pytron/platforms/android/shell/app/src/main/cpp/include/traceback.h +26 -0
  368. pytron/platforms/android/shell/app/src/main/cpp/include/tupleobject.h +46 -0
  369. pytron/platforms/android/shell/app/src/main/cpp/include/typeslots.h +96 -0
  370. pytron/platforms/android/shell/app/src/main/cpp/include/unicodeobject.h +1029 -0
  371. pytron/platforms/android/shell/app/src/main/cpp/include/warnings.h +45 -0
  372. pytron/platforms/android/shell/app/src/main/cpp/include/weakrefobject.h +46 -0
  373. pytron/platforms/android/shell/app/src/main/cpp/pytron_bridge.cpp +224 -0
  374. pytron/platforms/android/shell/app/src/main/java/com/pytron/shell/MainActivity.kt +208 -0
  375. pytron/platforms/android/shell/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  376. pytron/platforms/android/shell/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  377. pytron/platforms/android/shell/build.gradle +11 -0
  378. pytron/platforms/android/shell/gradle/wrapper/gradle-wrapper.jar +0 -0
  379. pytron/platforms/android/shell/gradle/wrapper/gradle-wrapper.properties +5 -0
  380. pytron/platforms/android/shell/gradle.properties +2 -0
  381. pytron/platforms/android/shell/gradlew.bat +85 -0
  382. pytron/platforms/android/shell/settings.gradle +16 -0
  383. pytron/platforms/darwin.py +82 -0
  384. pytron/platforms/darwin_ops/libs.py +31 -0
  385. pytron/platforms/darwin_ops/system.py +182 -0
  386. pytron/platforms/darwin_ops/utils.py +85 -0
  387. pytron/platforms/darwin_ops/webview.py +5 -0
  388. pytron/platforms/darwin_ops/window.py +102 -0
  389. pytron/platforms/interface.py +152 -0
  390. pytron/platforms/linux.py +82 -0
  391. pytron/platforms/linux_ops/libs.py +49 -0
  392. pytron/platforms/linux_ops/system.py +316 -0
  393. pytron/platforms/linux_ops/utils.py +19 -0
  394. pytron/platforms/linux_ops/webview.py +5 -0
  395. pytron/platforms/linux_ops/window.py +115 -0
  396. pytron/platforms/windows.py +136 -0
  397. pytron/platforms/windows_ops/__init__.py +0 -0
  398. pytron/platforms/windows_ops/constants.py +126 -0
  399. pytron/platforms/windows_ops/system.py +518 -0
  400. pytron/platforms/windows_ops/utils.py +3 -0
  401. pytron/platforms/windows_ops/webview.py +5 -0
  402. pytron/platforms/windows_ops/window.py +361 -0
  403. pytron/plugin.py +467 -0
  404. pytron/rcedit-x64.exe +0 -0
  405. pytron/router.py +146 -0
  406. pytron/serializer.py +240 -0
  407. pytron/shortcuts.py +279 -0
  408. pytron/state.py +76 -0
  409. pytron/tray.py +399 -0
  410. pytron/updater.py +181 -0
  411. pytron/utf8_hook.py +112 -0
  412. pytron/utils.py +44 -0
  413. pytron/webview.py +722 -0
  414. pytron_kit-0.3.12.dist-info/METADATA +131 -0
  415. pytron_kit-0.3.12.dist-info/RECORD +419 -0
  416. pytron_kit-0.3.12.dist-info/WHEEL +5 -0
  417. pytron_kit-0.3.12.dist-info/entry_points.txt +2 -0
  418. pytron_kit-0.3.12.dist-info/licenses/LICENSE +201 -0
  419. pytron_kit-0.3.12.dist-info/top_level.txt +1 -0
@@ -0,0 +1,736 @@
1
+ import os
2
+ import sys
3
+ import glob
4
+ import subprocess
5
+ import shutil
6
+ import tempfile
7
+ import urllib.request
8
+ import ctypes
9
+
10
+ # Optional LIEF import
11
+ try:
12
+ import lief
13
+ except ImportError:
14
+ lief = None
15
+
16
+ # Try to import toml for Rust detection
17
+ try:
18
+ import toml
19
+ except ImportError:
20
+ # Basic fallback or we can try built-in tomllib in 3.11+
21
+ try:
22
+ import tomllib as toml
23
+ except ImportError:
24
+ toml = None
25
+
26
+
27
+ class AndroidBuilder:
28
+ def __init__(self, arch="aarch64", target_dir=None):
29
+ self.arch = arch
30
+ self.target = (
31
+ "aarch64-linux-android" if arch == "aarch64" else f"{arch}-linux-android"
32
+ )
33
+ self.target_dir = target_dir
34
+ self.zig_version = "0.13.0"
35
+
36
+ # Paths
37
+ self.zig_dir = os.path.join(
38
+ os.path.dirname(os.path.abspath(__file__)), "tools", "zig"
39
+ )
40
+ # Lazy initialization for tools
41
+ self.zig_exe = None
42
+ self.ndk_info = None
43
+ self.env = os.environ.copy()
44
+
45
+ # Flattened libs cache (for Dependency Flattening Strategy)
46
+ self.flattened_libs_dir = os.path.join(
47
+ os.path.dirname(self.zig_dir), "flattened_libs", self.arch
48
+ )
49
+ os.makedirs(self.flattened_libs_dir, exist_ok=True)
50
+ self.flattened_libs = set()
51
+
52
+ def _fetch_prebuilt_wheel(self, package, output_dir):
53
+ """Attempts to download a pre-built binary wheel for Android."""
54
+ print(f"[AndroidBuilder] Searching for pre-built wheels for {package}...")
55
+
56
+ # Common Android platform tags
57
+ platforms = []
58
+ if self.arch == "aarch64":
59
+ platforms = [
60
+ "android_24_aarch64",
61
+ "android_21_aarch64",
62
+ "android_24_arm64_v8a",
63
+ "android_21_arm64_v8a",
64
+ ]
65
+ elif self.arch == "x86_64":
66
+ platforms = ["android_24_x86_64", "android_21_x86_64"]
67
+
68
+ # Add BeeWare repository
69
+ extra_indexes = [
70
+ "https://pypi.anaconda.org/beeware/simple",
71
+ ]
72
+
73
+ for platform in platforms:
74
+ try:
75
+ cmd = [
76
+ sys.executable,
77
+ "-m",
78
+ "pip",
79
+ "download",
80
+ package,
81
+ "--dest",
82
+ output_dir,
83
+ "--platform",
84
+ platform,
85
+ "--only-binary",
86
+ ":all:",
87
+ "--no-deps",
88
+ ]
89
+ for url in extra_indexes:
90
+ cmd.extend(["--extra-index-url", url])
91
+
92
+ # Run quietly
93
+ subprocess.check_call(
94
+ cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
95
+ ) # nosec B603
96
+
97
+ # Check if we actually got a wheel
98
+ downloaded = [
99
+ f
100
+ for f in os.listdir(output_dir)
101
+ if f.lower().startswith(package.lower()) and f.endswith(".whl")
102
+ ]
103
+ if downloaded:
104
+ print(f"[AndroidBuilder] Found pre-built wheel: {downloaded[0]}")
105
+ return True
106
+ except subprocess.CalledProcessError:
107
+ continue
108
+
109
+ return False
110
+
111
+ def _ensure_tools(self):
112
+ """Lazy load tools only when needed for compilation."""
113
+ if not self.zig_exe:
114
+ self.zig_exe = self._ensure_zig()
115
+ if not self.ndk_info:
116
+ self.ndk_info = self._find_ndk_info()
117
+ self.env = self._get_cross_env()
118
+
119
+ def repair_wheel(self, wheel_path):
120
+ """
121
+ Implements the 'Dependency Flattening' strategy.
122
+ 1. Extract the wheel.
123
+ 2. Scan for .so files and their internal dependencies.
124
+ 3. Relocate internal dependencies to the flattened folder.
125
+ 4. Patch the .so files to find dependencies in the flat namespace.
126
+ """
127
+ if lief is None:
128
+ print(
129
+ "[AndroidBuilder] Warning: LIEF not installed. Skipping dependency flattening/repair."
130
+ )
131
+ return False
132
+
133
+ import zipfile
134
+
135
+ temp_repair = tempfile.mkdtemp(prefix="pytron_repair_")
136
+
137
+ try:
138
+ with zipfile.ZipFile(wheel_path, "r") as zip_ref:
139
+ zip_ref.extractall(temp_repair)
140
+
141
+ repaired = False
142
+ # Scan for all shared libraries in the wheel
143
+ for root, dirs, files in os.walk(temp_repair):
144
+ for file in files:
145
+ if file.endswith(".so"):
146
+ so_path = os.path.join(root, file)
147
+ if self._patch_so(so_path, temp_repair):
148
+ repaired = True
149
+
150
+ if repaired:
151
+ print(
152
+ f"[AndroidBuilder] Repaired and flattened: {os.path.basename(wheel_path)}"
153
+ )
154
+ # Re-pack the wheel
155
+ os.remove(wheel_path)
156
+ shutil.make_archive(wheel_path.replace(".whl", ""), "zip", temp_repair)
157
+ os.rename(wheel_path.replace(".whl", ".zip"), wheel_path)
158
+
159
+ return True
160
+ finally:
161
+ shutil.rmtree(temp_repair, ignore_errors=True)
162
+
163
+ def _patch_so(self, so_path, wheel_root):
164
+ """Patches an ELF file to fulfill Dependency Flattening."""
165
+ if lief is None:
166
+ return False
167
+ try:
168
+ binary = lief.parse(so_path)
169
+ if not binary:
170
+ return False
171
+
172
+ changed = False
173
+ # List of dependencies to process
174
+ deps_to_fix = [lib for lib in binary.libraries]
175
+
176
+ for dep in deps_to_fix:
177
+ # System libraries white-list (Android Linker Namespace allowed)
178
+ if dep in [
179
+ "libc.so",
180
+ "libm.so",
181
+ "libdl.so",
182
+ "liblog.so",
183
+ "libjnigraphics.so",
184
+ "libandroid.so",
185
+ ]:
186
+ continue
187
+
188
+ # Check if this dependency exists inside the wheel (it might be in a subdir)
189
+ dep_name = os.path.basename(dep)
190
+ dep_search = glob.glob(
191
+ os.path.join(wheel_root, "**", dep_name), recursive=True
192
+ )
193
+
194
+ if dep_search:
195
+ dep_internal_path = dep_search[0]
196
+ # This is a local dependency. Move it to the flattened folder.
197
+ flat_dest = os.path.join(self.flattened_libs_dir, dep_name)
198
+ if not os.path.exists(flat_dest):
199
+ print(f"[AndroidBuilder] Flattening dependency: {dep_name}")
200
+ shutil.copy2(dep_internal_path, flat_dest)
201
+ self.flattened_libs.add(dep_name)
202
+
203
+ # Ensure the reference in the binary is ONLY the filename
204
+ if dep != dep_name:
205
+ # Use lief to replace the dependency path with just the name
206
+ for i, library in enumerate(binary.libraries):
207
+ if library == dep:
208
+ binary.libraries[i] = dep_name
209
+ changed = True
210
+ else:
211
+ # Even if it match, we might want to 'refresh' it or just mark changed
212
+ changed = True
213
+
214
+ # Clear RPATH/RUNPATH as they are unreliable on Android
215
+ if binary.has(lief.ELF.DYNAMIC_TAGS.RUNPATH):
216
+ binary.remove(lief.ELF.DYNAMIC_TAGS.RUNPATH)
217
+ changed = True
218
+ if binary.has(lief.ELF.DYNAMIC_TAGS.RPATH):
219
+ binary.remove(lief.ELF.DYNAMIC_TAGS.RPATH)
220
+ changed = True
221
+
222
+ if changed:
223
+ binary.write(so_path)
224
+ return True
225
+ except Exception as e:
226
+ print(
227
+ f"[AndroidBuilder] Warning: Failed to patch {os.path.basename(so_path)}: {e}"
228
+ )
229
+ return False
230
+
231
+ def _get_short_path(self, long_path):
232
+ if os.name != "nt":
233
+ return long_path
234
+ if not os.path.exists(long_path):
235
+ return long_path
236
+ try:
237
+ size = ctypes.windll.kernel32.GetShortPathNameW(long_path, None, 0)
238
+ if size == 0:
239
+ return long_path
240
+ buf = ctypes.create_unicode_buffer(size)
241
+ ctypes.windll.kernel32.GetShortPathNameW(long_path, buf, size)
242
+ return buf.value
243
+ except:
244
+ return long_path
245
+
246
+ def _norm(self, path):
247
+ if not path:
248
+ return path
249
+ return os.path.normpath(path)
250
+
251
+ def _ensure_zig(self):
252
+ """Checks for Zig compiler, installs if missing."""
253
+ # Check global
254
+ if shutil.which("zig"):
255
+ return "zig"
256
+
257
+ # Check local
258
+ zig_exe_local = self._norm(os.path.join(self.zig_dir, "zig.exe"))
259
+ if os.path.exists(zig_exe_local):
260
+ return self._get_short_path(zig_exe_local)
261
+
262
+ # Install
263
+ print(f"[AndroidBuilder] Zig not found. Installing Zig {self.zig_version}...")
264
+ os.makedirs(os.path.dirname(self.zig_dir), exist_ok=True)
265
+
266
+ # URL for Windows (assuming Windows as per user context)
267
+ if sys.platform == "win32":
268
+ url = f"https://ziglang.org/download/{self.zig_version}/zig-windows-x86_64-{self.zig_version}.zip"
269
+ elif sys.platform == "linux":
270
+ url = f"https://ziglang.org/download/{self.zig_version}/zig-linux-x86_64-{self.zig_version}.tar.xz"
271
+ elif sys.platform == "darwin":
272
+ url = f"https://ziglang.org/download/{self.zig_version}/zig-macos-x86_64-{self.zig_version}.tar.xz"
273
+ else:
274
+ return None
275
+
276
+ zip_path = self._norm(os.path.join(os.path.dirname(self.zig_dir), "zig.zip"))
277
+ try:
278
+ if not url.startswith("https://"):
279
+ raise ValueError("URL must be HTTPS")
280
+
281
+ # nosemgrep
282
+ with urllib.request.urlopen(url) as response, open( # nosec B310
283
+ zip_path, "wb"
284
+ ) as out:
285
+ shutil.copyfileobj(response, out)
286
+
287
+ print("[AndroidBuilder] Extracting Zig...")
288
+ shutil.unpack_archive(zip_path, os.path.dirname(self.zig_dir))
289
+
290
+ # Find extracted folder
291
+ for d in os.listdir(os.path.dirname(self.zig_dir)):
292
+ if d.startswith("zig-") and os.path.isdir(
293
+ os.path.join(os.path.dirname(self.zig_dir), d)
294
+ ):
295
+ extracted = self._norm(
296
+ os.path.join(os.path.dirname(self.zig_dir), d)
297
+ )
298
+ if os.path.exists(self.zig_dir):
299
+ shutil.rmtree(self.zig_dir)
300
+ os.rename(extracted, self.zig_dir)
301
+ break
302
+
303
+ os.remove(zip_path)
304
+ return self._get_short_path(zig_exe_local)
305
+
306
+ except Exception as e:
307
+ print(f"[AndroidBuilder] Failed to install Zig: {e}")
308
+ return None
309
+
310
+ def setup_nano_sysroot(self, cache_dir):
311
+ """Creates a minimal sysroot by downloading essential Android headers."""
312
+ include_dir = os.path.join(cache_dir, "sysroot", "usr", "include")
313
+ os.makedirs(include_dir, exist_ok=True)
314
+
315
+ headers = {
316
+ "jni.h": "https://raw.githubusercontent.com/openjdk/jdk/master/src/java.base/share/native/include/jni.h",
317
+ "jni_md.h": "https://raw.githubusercontent.com/openjdk/jdk/master/src/java.base/unix/native/include/jni_md.h",
318
+ "android/log.h": "https://raw.githubusercontent.com/platform-tools/android_platform_system_core/master/liblog/include/android/log.h",
319
+ }
320
+
321
+ print("[AndroidBuilder] Provisioning Nano-Sysroot (Headers)...")
322
+ for name, url in headers.items():
323
+ dest = os.path.join(include_dir, name)
324
+ os.makedirs(os.path.dirname(dest), exist_ok=True)
325
+ if not os.path.exists(dest):
326
+ try:
327
+ import urllib.request
328
+
329
+ if not url.startswith("https://"):
330
+ raise ValueError("URL must be HTTPS")
331
+
332
+ # nosemgrep
333
+ urllib.request.urlretrieve(url, dest) # nosec B310
334
+ except Exception as e:
335
+ print(f"[AndroidBuilder] Warning: Failed to download {name}: {e}")
336
+
337
+ return os.path.join(cache_dir, "sysroot")
338
+
339
+ def setup_python_target(self, cache_dir):
340
+ """Downloads Android Python headers and libraries for the target ABI."""
341
+ target_dir = os.path.join(cache_dir, f"python-target-{self.arch}")
342
+ if os.path.exists(target_dir):
343
+ return target_dir
344
+
345
+ print(f"[AndroidBuilder] Provisioning Python {self.arch} Support Package...")
346
+ os.makedirs(target_dir, exist_ok=True)
347
+
348
+ # Use the current Python version to match the host environment
349
+ py_ver = f"{sys.version_info.major}.{sys.version_info.minor}"
350
+ # Fallback: if BeeWare hasn't released yet for latest, you might need to adjust this.
351
+ # Using 3.11 as a safe default if 3.14 is not available, or let it fail gracefully
352
+ # BeeWare usually has 3.8-3.12 support.
353
+ if sys.version_info.minor > 12:
354
+ print(
355
+ f"[AndroidBuilder] Warning: Python {py_ver} might not be supported by BeeWare yet. Trying 3.12..."
356
+ )
357
+ py_ver = "3.12"
358
+
359
+ url = f"https://github.com/beeware/Python-Android-support/releases/download/{py_ver}-b1/Python-{py_ver}-Android-support.b1.zip"
360
+ zip_path = os.path.join(cache_dir, "python-android-support.zip")
361
+
362
+ try:
363
+ import urllib.request
364
+
365
+ if not os.path.exists(zip_path):
366
+ if not url.startswith("https://"):
367
+ raise ValueError("URL must be HTTPS")
368
+ print(f"[AndroidBuilder] Downloading {url}...")
369
+ # nosemgrep
370
+ urllib.request.urlretrieve(url, zip_path) # nosec B310
371
+
372
+ import zipfile
373
+
374
+ with zipfile.ZipFile(zip_path, "r") as zip_ref:
375
+ zip_ref.extractall(target_dir)
376
+ except Exception as e:
377
+ print(f"[AndroidBuilder] Error provisioning Python target: {e}")
378
+
379
+ return target_dir
380
+
381
+ def _find_ndk_info(self):
382
+ """Locate NDK or fallback to Nano-Sysroot."""
383
+ ndk_path = os.environ.get("ANDROID_NDK_HOME")
384
+ if not ndk_path:
385
+ android_home = os.environ.get("ANDROID_HOME") or os.environ.get(
386
+ "ANDROID_SDK_ROOT"
387
+ )
388
+ if android_home:
389
+ ndk_root = os.path.join(android_home, "ndk")
390
+ if os.path.exists(ndk_root):
391
+ versions = sorted(os.listdir(ndk_root))
392
+ if versions:
393
+ ndk_path = os.path.join(ndk_root, versions[-1])
394
+
395
+ cache_dir = os.path.join(os.path.dirname(self.zig_dir), "cache")
396
+ os.makedirs(cache_dir, exist_ok=True)
397
+
398
+ if ndk_path and os.path.exists(ndk_path):
399
+ ndk_path = self._norm(ndk_path)
400
+ sysroot = self._norm(
401
+ os.path.join(
402
+ ndk_path,
403
+ "toolchains",
404
+ "llvm",
405
+ "prebuilt",
406
+ "windows-x86_64",
407
+ "sysroot",
408
+ )
409
+ )
410
+ if not os.path.exists(sysroot):
411
+ sysroot_glob = glob.glob(
412
+ os.path.join(
413
+ ndk_path, "toolchains", "llvm", "prebuilt", "*", "sysroot"
414
+ )
415
+ )
416
+ if sysroot_glob:
417
+ sysroot = self._norm(sysroot_glob[0])
418
+
419
+ if os.path.exists(sysroot):
420
+ return {
421
+ "path": ndk_path,
422
+ "sysroot": self._get_short_path(sysroot),
423
+ "include": self._get_short_path(
424
+ self._norm(os.path.join(sysroot, "usr", "include"))
425
+ ),
426
+ "lib": self._get_short_path(
427
+ self._norm(
428
+ os.path.join(sysroot, "usr", "lib", "aarch64-linux-android")
429
+ )
430
+ ),
431
+ }
432
+
433
+ # Fallback to Nano-Sysroot
434
+ print("[AndroidBuilder] NDK not found. Switching to Minimalist Nano-Sysroot...")
435
+ sysroot = self.setup_nano_sysroot(cache_dir)
436
+ py_target = self.setup_python_target(cache_dir)
437
+
438
+ # Locate the specific arch inside the support package
439
+ # BeeWare structure: /python/path/usr/include and /python/path/usr/lib
440
+ py_inc = glob.glob(
441
+ os.path.join(py_target, "**", "usr", "include", "python*"), recursive=True
442
+ )
443
+ py_lib = glob.glob(os.path.join(py_target, "**", "usr", "lib"), recursive=True)
444
+
445
+ return {
446
+ "path": None,
447
+ "sysroot": self._get_short_path(sysroot),
448
+ "include": self._get_short_path(os.path.join(sysroot, "usr", "include")),
449
+ "lib": (
450
+ self._get_short_path(py_lib[0])
451
+ if py_lib
452
+ else self._get_short_path(sysroot)
453
+ ),
454
+ "py_include": self._get_short_path(py_inc[0]) if py_inc else None,
455
+ }
456
+
457
+ def _generate_sysconfig(self, dest_dir):
458
+ """
459
+ Creates a dummy _sysconfigdata file to fool build backends
460
+ into using Android/Linux settings on a Windows host.
461
+ """
462
+ target = self.target
463
+ # Standard naming convention
464
+ sc_name = f"_sysconfigdata__linux_{target}"
465
+ sc_path = os.path.join(dest_dir, f"{sc_name}.py")
466
+
467
+ # Minimal build vars to satisfy setuptools/distutils/meson
468
+ content = f"""
469
+ # Generated by Pytron AndroidBuilder
470
+ build_time_vars = {{
471
+ 'SO': '.so',
472
+ 'EXT_SUFFIX': '.so',
473
+ 'SHLIB_SUFFIX': '.so',
474
+ 'CC': 'zig cc',
475
+ 'CXX': 'zig c++',
476
+ 'AR': 'zig ar',
477
+ 'HOST_GNU_TYPE': '{target}',
478
+ 'MACHDEP': 'linux',
479
+ 'LIBDIR': '.',
480
+ 'INCLUDEPY': '.',
481
+ 'SOABI': 'cpython-314-aarch64-linux-android',
482
+ }}
483
+ """
484
+ with open(sc_path, "w", encoding="utf-8") as f:
485
+ f.write(content)
486
+ return sc_name
487
+
488
+ def _rename_wheel(self, output_dir):
489
+ """Fixes wheel tags to ensure they are recognized as Android-compatible."""
490
+ for whl in os.listdir(output_dir):
491
+ if not whl.endswith(".whl"):
492
+ continue
493
+
494
+ original = whl
495
+ new_name = whl
496
+ # Map host tags to Android tags
497
+ for host_tag in ["win_amd64", "linux_x86_64", "macosx"]:
498
+ if host_tag in whl:
499
+ # e.g. numpy-2.4.0-cp313-cp313-win_amd64.whl -> ...-android_24_aarch64.whl
500
+ new_name = whl.replace(host_tag, f"android_24_{self.arch}")
501
+
502
+ if new_name != original:
503
+ print(f"[AndroidBuilder] Renaming wheel: {original} -> {new_name}")
504
+ os.rename(
505
+ os.path.join(output_dir, original),
506
+ os.path.join(output_dir, new_name),
507
+ )
508
+
509
+ def _create_linker_wrapper(self):
510
+ """Creates a batch wrapper for Zig CC to act as a Linker for Rust/Cargo."""
511
+ if not self.zig_exe:
512
+ return None
513
+ wrapper_dir = self._norm(os.path.join(self.zig_dir, "wrappers"))
514
+ os.makedirs(wrapper_dir, exist_ok=True)
515
+ wrapper_path = self._norm(os.path.join(wrapper_dir, "rust_linker.bat"))
516
+
517
+ # Zig cc as linker. We quote zig path for batch execution.
518
+ cmd = f'"{self.zig_exe}" cc -target {self.target} %*'
519
+ with open(wrapper_path, "w") as f:
520
+ f.write(f"@echo off\n{cmd}")
521
+
522
+ return self._get_short_path(wrapper_path)
523
+
524
+ def _get_cross_env(self, sysconfig_dir=None):
525
+ """Generates the environment variables for build."""
526
+ if not self.zig_exe:
527
+ print("[AndroidBuilder] Zig not available.")
528
+ return os.environ.copy()
529
+
530
+ zig_safe = self._get_short_path(self.zig_exe)
531
+ env = os.environ.copy()
532
+
533
+ # Inject Scripts path for ninja/meson
534
+ scripts = os.path.join(os.path.dirname(sys.executable), "Scripts")
535
+ if scripts not in env.get("PATH", ""):
536
+ env["PATH"] = scripts + os.pathsep + env.get("PATH", "")
537
+
538
+ # --- ZIG COMPILER SETUP ---
539
+ target = self.target
540
+
541
+ env["CC"] = f"{zig_safe} cc -target {target}"
542
+ env["CXX"] = f"{zig_safe} c++ -target {target}"
543
+ env["LD"] = f"{zig_safe} cc -target {target}"
544
+ env["AR"] = f"{zig_safe} ar"
545
+ env["RANLIB"] = f"{zig_safe} ranlib"
546
+
547
+ # Helper for Rust/Cargo linking
548
+ cargo_linker = self._create_linker_wrapper()
549
+ if cargo_linker:
550
+ env["CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER"] = cargo_linker
551
+ env["RUSTFLAGS"] = "-C link-arg=-Wl,--allow-shlib-undefined"
552
+ else:
553
+ env["CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER"] = zig_safe
554
+ env["RUSTFLAGS"] = (
555
+ f"-C linker={zig_safe} -C link-arg=-target -C link-arg={target}"
556
+ )
557
+
558
+ # NDK/Library Paths
559
+ if self.ndk_info:
560
+ env["LIBRARY_PATH"] = self.ndk_info["lib"]
561
+ usr_root = self._norm(os.path.join(self.ndk_info["sysroot"], "usr"))
562
+ env["ZLIB_ROOT"] = usr_root
563
+ env["JPEG_ROOT"] = usr_root
564
+
565
+ # Combine standard Android headers with Python-specific ones
566
+ inc = self.ndk_info["include"]
567
+ py_inc = self.ndk_info.get("py_include")
568
+
569
+ all_inc = inc
570
+ if py_inc:
571
+ all_inc = f"{py_inc}{os.pathsep}{inc}"
572
+
573
+ env["C_INCLUDE_PATH"] = all_inc
574
+ env["CPLUS_INCLUDE_PATH"] = all_inc
575
+
576
+ # Use quotes for CFLAGS to handle short paths/spaces
577
+ env["CFLAGS"] = f'-fPIC -DANDROID -I"{inc}"'
578
+ if py_inc:
579
+ env["CFLAGS"] += f' -I"{py_inc}"'
580
+
581
+ env["LDFLAGS"] = f"-L\"{self.ndk_info['lib']}\" -lz -lm"
582
+
583
+ # Python Config Spoofing
584
+ env["_PYTHON_SYSCONFIGDATA_NAME"] = f"_sysconfigdata__linux_{target}"
585
+ env["_PYTHON_HOST_PLATFORM"] = f"linux-{self.arch}"
586
+
587
+ if sysconfig_dir:
588
+ env["PYTHONPATH"] = (
589
+ f"{sysconfig_dir}{os.pathsep}{env.get('PYTHONPATH', '')}"
590
+ )
591
+
592
+ return env
593
+
594
+ def build_wheel(self, package, output_dir, cpp_include=None):
595
+ """Builds a wheel using the minimalist architecture Logic."""
596
+ # 0. Try to fetch pre-built wheel first
597
+ if self._fetch_prebuilt_wheel(package, output_dir):
598
+ # If found, we still run repair/flattening just in case
599
+ for whl in os.listdir(output_dir):
600
+ if whl.endswith(".whl"):
601
+ self.repair_wheel(os.path.join(output_dir, whl))
602
+ return True
603
+
604
+ self._ensure_tools()
605
+ if not self.zig_exe:
606
+ print("[AndroidBuilder] Zig not initialized.")
607
+ return False
608
+
609
+ temp_dir = tempfile.mkdtemp(prefix="pytron_build_")
610
+ source_dir = None
611
+
612
+ try:
613
+ if os.path.exists(package) and os.path.isdir(package):
614
+ source_dir = package
615
+ else:
616
+ print(f"[AndroidBuilder] Downloading source for {package}...")
617
+ # CRITICAL: Use --no-build-isolation here too to prevent metadata parsing crashes
618
+ subprocess.check_call(
619
+ [
620
+ sys.executable,
621
+ "-m",
622
+ "pip",
623
+ "download",
624
+ package,
625
+ "--no-binary",
626
+ ":all:",
627
+ "--no-deps",
628
+ "--no-build-isolation",
629
+ "--dest",
630
+ temp_dir,
631
+ ]
632
+ ) # nosec B603
633
+ archives = [
634
+ f for f in os.listdir(temp_dir) if f.endswith((".tar.gz", ".zip"))
635
+ ]
636
+ if not archives:
637
+ return False
638
+ shutil.unpack_archive(os.path.join(temp_dir, archives[0]), temp_dir)
639
+ for item in os.listdir(temp_dir):
640
+ if os.path.isdir(os.path.join(temp_dir, item)):
641
+ source_dir = os.path.join(temp_dir, item)
642
+ break
643
+
644
+ if not source_dir:
645
+ return False
646
+
647
+ # 1. Ensure Host Build Tools (Minimalist Requirement)
648
+ print("[AndroidBuilder] Ensuring host build tools...")
649
+ build_deps = [
650
+ "wheel",
651
+ "setuptools",
652
+ "Cython",
653
+ "meson-python",
654
+ "maturin",
655
+ "pybind11",
656
+ "scikit-build-core",
657
+ "ninja",
658
+ "meson",
659
+ ]
660
+ try:
661
+ subprocess.check_call(
662
+ [sys.executable, "-m", "pip", "install"] + build_deps,
663
+ env=os.environ.copy(),
664
+ ) # nosec B603
665
+ except:
666
+ pass
667
+
668
+ # 2. Setup Spoofed Environment
669
+ self._generate_sysconfig(source_dir)
670
+ env = self._get_cross_env(sysconfig_dir=source_dir)
671
+
672
+ if cpp_include:
673
+ env["CFLAGS"] = env.get("CFLAGS", "") + f' -I"{cpp_include}"'
674
+
675
+ # 3. Detect Build System
676
+ is_maturin = False
677
+ pyproject_path = os.path.join(source_dir, "pyproject.toml")
678
+ if os.path.exists(pyproject_path):
679
+ with open(pyproject_path, "r", encoding="utf-8") as f:
680
+ content = f.read()
681
+ if "maturin" in content:
682
+ is_maturin = True
683
+
684
+ # 4. Execute Build
685
+ if is_maturin:
686
+ print(f"[AndroidBuilder] Building {package} with Maturin...")
687
+ subprocess.check_call(
688
+ ["rustup", "target", "add", "aarch64-linux-android"]
689
+ )
690
+ cmd = [
691
+ sys.executable,
692
+ "-m",
693
+ "maturin",
694
+ "build",
695
+ "--release",
696
+ "--target",
697
+ "aarch64-linux-android",
698
+ "--out",
699
+ output_dir,
700
+ "--strip",
701
+ ]
702
+ subprocess.check_call(cmd, cwd=source_dir, env=env)
703
+ else:
704
+ print(
705
+ f"[AndroidBuilder] Building {package} with Pip/Zig (Isolation OFF)..."
706
+ )
707
+ cmd = [
708
+ sys.executable,
709
+ "-m",
710
+ "pip",
711
+ "wheel",
712
+ ".",
713
+ "--no-deps",
714
+ "--no-build-isolation",
715
+ "--wheel-dir",
716
+ output_dir,
717
+ "-v",
718
+ ]
719
+ subprocess.check_call(cmd, cwd=source_dir, env=env)
720
+
721
+ # 5. Fix Wheel Tags (Minimalist Architecture requirement)
722
+ self._rename_wheel(output_dir)
723
+
724
+ # 6. Repaire and Flatten Dependencies (Independent Architecture requirement)
725
+ for whl in os.listdir(output_dir):
726
+ if whl.endswith(".whl"):
727
+ self.repair_wheel(os.path.join(output_dir, whl))
728
+
729
+ return True
730
+
731
+ except Exception as e:
732
+ print(f"[AndroidBuilder] Build failed: {e}")
733
+ return False
734
+ finally:
735
+ if temp_dir and os.path.exists(temp_dir):
736
+ shutil.rmtree(temp_dir, ignore_errors=True)