flyte 0.0.1b0__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.

Potentially problematic release.


This version of flyte might be problematic. Click here for more details.

Files changed (390) hide show
  1. flyte/__init__.py +62 -0
  2. flyte/_api_commons.py +3 -0
  3. flyte/_bin/__init__.py +0 -0
  4. flyte/_bin/runtime.py +126 -0
  5. flyte/_build.py +25 -0
  6. flyte/_cache/__init__.py +12 -0
  7. flyte/_cache/cache.py +146 -0
  8. flyte/_cache/defaults.py +9 -0
  9. flyte/_cache/policy_function_body.py +42 -0
  10. flyte/_cli/__init__.py +0 -0
  11. flyte/_cli/_common.py +287 -0
  12. flyte/_cli/_create.py +42 -0
  13. flyte/_cli/_delete.py +23 -0
  14. flyte/_cli/_deploy.py +140 -0
  15. flyte/_cli/_get.py +235 -0
  16. flyte/_cli/_run.py +152 -0
  17. flyte/_cli/main.py +72 -0
  18. flyte/_code_bundle/__init__.py +8 -0
  19. flyte/_code_bundle/_ignore.py +113 -0
  20. flyte/_code_bundle/_packaging.py +187 -0
  21. flyte/_code_bundle/_utils.py +339 -0
  22. flyte/_code_bundle/bundle.py +178 -0
  23. flyte/_context.py +146 -0
  24. flyte/_datastructures.py +342 -0
  25. flyte/_deploy.py +202 -0
  26. flyte/_doc.py +29 -0
  27. flyte/_docstring.py +32 -0
  28. flyte/_environment.py +43 -0
  29. flyte/_group.py +31 -0
  30. flyte/_hash.py +23 -0
  31. flyte/_image.py +760 -0
  32. flyte/_initialize.py +634 -0
  33. flyte/_interface.py +84 -0
  34. flyte/_internal/__init__.py +3 -0
  35. flyte/_internal/controllers/__init__.py +115 -0
  36. flyte/_internal/controllers/_local_controller.py +118 -0
  37. flyte/_internal/controllers/_trace.py +40 -0
  38. flyte/_internal/controllers/pbhash.py +39 -0
  39. flyte/_internal/controllers/remote/__init__.py +40 -0
  40. flyte/_internal/controllers/remote/_action.py +141 -0
  41. flyte/_internal/controllers/remote/_client.py +43 -0
  42. flyte/_internal/controllers/remote/_controller.py +361 -0
  43. flyte/_internal/controllers/remote/_core.py +402 -0
  44. flyte/_internal/controllers/remote/_informer.py +361 -0
  45. flyte/_internal/controllers/remote/_service_protocol.py +50 -0
  46. flyte/_internal/imagebuild/__init__.py +11 -0
  47. flyte/_internal/imagebuild/docker_builder.py +416 -0
  48. flyte/_internal/imagebuild/image_builder.py +241 -0
  49. flyte/_internal/imagebuild/remote_builder.py +0 -0
  50. flyte/_internal/resolvers/__init__.py +0 -0
  51. flyte/_internal/resolvers/_task_module.py +54 -0
  52. flyte/_internal/resolvers/common.py +31 -0
  53. flyte/_internal/resolvers/default.py +28 -0
  54. flyte/_internal/runtime/__init__.py +0 -0
  55. flyte/_internal/runtime/convert.py +199 -0
  56. flyte/_internal/runtime/entrypoints.py +135 -0
  57. flyte/_internal/runtime/io.py +136 -0
  58. flyte/_internal/runtime/resources_serde.py +138 -0
  59. flyte/_internal/runtime/task_serde.py +210 -0
  60. flyte/_internal/runtime/taskrunner.py +190 -0
  61. flyte/_internal/runtime/types_serde.py +54 -0
  62. flyte/_logging.py +124 -0
  63. flyte/_protos/__init__.py +0 -0
  64. flyte/_protos/common/authorization_pb2.py +66 -0
  65. flyte/_protos/common/authorization_pb2.pyi +108 -0
  66. flyte/_protos/common/authorization_pb2_grpc.py +4 -0
  67. flyte/_protos/common/identifier_pb2.py +71 -0
  68. flyte/_protos/common/identifier_pb2.pyi +82 -0
  69. flyte/_protos/common/identifier_pb2_grpc.py +4 -0
  70. flyte/_protos/common/identity_pb2.py +48 -0
  71. flyte/_protos/common/identity_pb2.pyi +72 -0
  72. flyte/_protos/common/identity_pb2_grpc.py +4 -0
  73. flyte/_protos/common/list_pb2.py +36 -0
  74. flyte/_protos/common/list_pb2.pyi +69 -0
  75. flyte/_protos/common/list_pb2_grpc.py +4 -0
  76. flyte/_protos/common/policy_pb2.py +37 -0
  77. flyte/_protos/common/policy_pb2.pyi +27 -0
  78. flyte/_protos/common/policy_pb2_grpc.py +4 -0
  79. flyte/_protos/common/role_pb2.py +37 -0
  80. flyte/_protos/common/role_pb2.pyi +53 -0
  81. flyte/_protos/common/role_pb2_grpc.py +4 -0
  82. flyte/_protos/common/runtime_version_pb2.py +28 -0
  83. flyte/_protos/common/runtime_version_pb2.pyi +24 -0
  84. flyte/_protos/common/runtime_version_pb2_grpc.py +4 -0
  85. flyte/_protos/logs/dataplane/payload_pb2.py +96 -0
  86. flyte/_protos/logs/dataplane/payload_pb2.pyi +168 -0
  87. flyte/_protos/logs/dataplane/payload_pb2_grpc.py +4 -0
  88. flyte/_protos/secret/definition_pb2.py +49 -0
  89. flyte/_protos/secret/definition_pb2.pyi +93 -0
  90. flyte/_protos/secret/definition_pb2_grpc.py +4 -0
  91. flyte/_protos/secret/payload_pb2.py +62 -0
  92. flyte/_protos/secret/payload_pb2.pyi +94 -0
  93. flyte/_protos/secret/payload_pb2_grpc.py +4 -0
  94. flyte/_protos/secret/secret_pb2.py +38 -0
  95. flyte/_protos/secret/secret_pb2.pyi +6 -0
  96. flyte/_protos/secret/secret_pb2_grpc.py +198 -0
  97. flyte/_protos/secret/secret_pb2_grpc_grpc.py +198 -0
  98. flyte/_protos/validate/validate/validate_pb2.py +76 -0
  99. flyte/_protos/workflow/node_execution_service_pb2.py +26 -0
  100. flyte/_protos/workflow/node_execution_service_pb2.pyi +4 -0
  101. flyte/_protos/workflow/node_execution_service_pb2_grpc.py +32 -0
  102. flyte/_protos/workflow/queue_service_pb2.py +106 -0
  103. flyte/_protos/workflow/queue_service_pb2.pyi +141 -0
  104. flyte/_protos/workflow/queue_service_pb2_grpc.py +172 -0
  105. flyte/_protos/workflow/run_definition_pb2.py +128 -0
  106. flyte/_protos/workflow/run_definition_pb2.pyi +310 -0
  107. flyte/_protos/workflow/run_definition_pb2_grpc.py +4 -0
  108. flyte/_protos/workflow/run_logs_service_pb2.py +41 -0
  109. flyte/_protos/workflow/run_logs_service_pb2.pyi +28 -0
  110. flyte/_protos/workflow/run_logs_service_pb2_grpc.py +69 -0
  111. flyte/_protos/workflow/run_service_pb2.py +133 -0
  112. flyte/_protos/workflow/run_service_pb2.pyi +175 -0
  113. flyte/_protos/workflow/run_service_pb2_grpc.py +412 -0
  114. flyte/_protos/workflow/state_service_pb2.py +58 -0
  115. flyte/_protos/workflow/state_service_pb2.pyi +71 -0
  116. flyte/_protos/workflow/state_service_pb2_grpc.py +138 -0
  117. flyte/_protos/workflow/task_definition_pb2.py +72 -0
  118. flyte/_protos/workflow/task_definition_pb2.pyi +65 -0
  119. flyte/_protos/workflow/task_definition_pb2_grpc.py +4 -0
  120. flyte/_protos/workflow/task_service_pb2.py +44 -0
  121. flyte/_protos/workflow/task_service_pb2.pyi +31 -0
  122. flyte/_protos/workflow/task_service_pb2_grpc.py +104 -0
  123. flyte/_resources.py +226 -0
  124. flyte/_retry.py +32 -0
  125. flyte/_reusable_environment.py +25 -0
  126. flyte/_run.py +411 -0
  127. flyte/_secret.py +61 -0
  128. flyte/_task.py +367 -0
  129. flyte/_task_environment.py +200 -0
  130. flyte/_timeout.py +47 -0
  131. flyte/_tools.py +27 -0
  132. flyte/_trace.py +128 -0
  133. flyte/_utils/__init__.py +20 -0
  134. flyte/_utils/asyn.py +119 -0
  135. flyte/_utils/coro_management.py +25 -0
  136. flyte/_utils/file_handling.py +72 -0
  137. flyte/_utils/helpers.py +108 -0
  138. flyte/_utils/lazy_module.py +54 -0
  139. flyte/_utils/uv_script_parser.py +49 -0
  140. flyte/_version.py +21 -0
  141. flyte/connectors/__init__.py +0 -0
  142. flyte/errors.py +143 -0
  143. flyte/extras/__init__.py +5 -0
  144. flyte/extras/_container.py +273 -0
  145. flyte/io/__init__.py +11 -0
  146. flyte/io/_dataframe.py +0 -0
  147. flyte/io/_dir.py +448 -0
  148. flyte/io/_file.py +468 -0
  149. flyte/io/pickle/__init__.py +0 -0
  150. flyte/io/pickle/transformer.py +117 -0
  151. flyte/io/structured_dataset/__init__.py +129 -0
  152. flyte/io/structured_dataset/basic_dfs.py +219 -0
  153. flyte/io/structured_dataset/structured_dataset.py +1061 -0
  154. flyte/py.typed +0 -0
  155. flyte/remote/__init__.py +25 -0
  156. flyte/remote/_client/__init__.py +0 -0
  157. flyte/remote/_client/_protocols.py +131 -0
  158. flyte/remote/_client/auth/__init__.py +12 -0
  159. flyte/remote/_client/auth/_authenticators/__init__.py +0 -0
  160. flyte/remote/_client/auth/_authenticators/base.py +397 -0
  161. flyte/remote/_client/auth/_authenticators/client_credentials.py +73 -0
  162. flyte/remote/_client/auth/_authenticators/device_code.py +118 -0
  163. flyte/remote/_client/auth/_authenticators/external_command.py +79 -0
  164. flyte/remote/_client/auth/_authenticators/factory.py +200 -0
  165. flyte/remote/_client/auth/_authenticators/pkce.py +516 -0
  166. flyte/remote/_client/auth/_channel.py +184 -0
  167. flyte/remote/_client/auth/_client_config.py +83 -0
  168. flyte/remote/_client/auth/_default_html.py +32 -0
  169. flyte/remote/_client/auth/_grpc_utils/__init__.py +0 -0
  170. flyte/remote/_client/auth/_grpc_utils/auth_interceptor.py +288 -0
  171. flyte/remote/_client/auth/_grpc_utils/default_metadata_interceptor.py +151 -0
  172. flyte/remote/_client/auth/_keyring.py +143 -0
  173. flyte/remote/_client/auth/_token_client.py +260 -0
  174. flyte/remote/_client/auth/errors.py +16 -0
  175. flyte/remote/_client/controlplane.py +95 -0
  176. flyte/remote/_console.py +18 -0
  177. flyte/remote/_data.py +155 -0
  178. flyte/remote/_logs.py +116 -0
  179. flyte/remote/_project.py +86 -0
  180. flyte/remote/_run.py +873 -0
  181. flyte/remote/_secret.py +132 -0
  182. flyte/remote/_task.py +227 -0
  183. flyte/report/__init__.py +3 -0
  184. flyte/report/_report.py +178 -0
  185. flyte/report/_template.html +124 -0
  186. flyte/storage/__init__.py +24 -0
  187. flyte/storage/_remote_fs.py +34 -0
  188. flyte/storage/_storage.py +251 -0
  189. flyte/storage/_utils.py +5 -0
  190. flyte/types/__init__.py +13 -0
  191. flyte/types/_interface.py +25 -0
  192. flyte/types/_renderer.py +162 -0
  193. flyte/types/_string_literals.py +120 -0
  194. flyte/types/_type_engine.py +2210 -0
  195. flyte/types/_utils.py +80 -0
  196. flyte-0.0.1b0.dist-info/METADATA +179 -0
  197. flyte-0.0.1b0.dist-info/RECORD +390 -0
  198. flyte-0.0.1b0.dist-info/WHEEL +5 -0
  199. flyte-0.0.1b0.dist-info/entry_points.txt +3 -0
  200. flyte-0.0.1b0.dist-info/top_level.txt +1 -0
  201. union/__init__.py +54 -0
  202. union/_api_commons.py +3 -0
  203. union/_bin/__init__.py +0 -0
  204. union/_bin/runtime.py +113 -0
  205. union/_build.py +25 -0
  206. union/_cache/__init__.py +12 -0
  207. union/_cache/cache.py +141 -0
  208. union/_cache/defaults.py +9 -0
  209. union/_cache/policy_function_body.py +42 -0
  210. union/_cli/__init__.py +0 -0
  211. union/_cli/_common.py +263 -0
  212. union/_cli/_create.py +40 -0
  213. union/_cli/_delete.py +23 -0
  214. union/_cli/_deploy.py +120 -0
  215. union/_cli/_get.py +162 -0
  216. union/_cli/_params.py +579 -0
  217. union/_cli/_run.py +150 -0
  218. union/_cli/main.py +72 -0
  219. union/_code_bundle/__init__.py +8 -0
  220. union/_code_bundle/_ignore.py +113 -0
  221. union/_code_bundle/_packaging.py +187 -0
  222. union/_code_bundle/_utils.py +342 -0
  223. union/_code_bundle/bundle.py +176 -0
  224. union/_context.py +146 -0
  225. union/_datastructures.py +295 -0
  226. union/_deploy.py +185 -0
  227. union/_doc.py +29 -0
  228. union/_docstring.py +26 -0
  229. union/_environment.py +43 -0
  230. union/_group.py +31 -0
  231. union/_hash.py +23 -0
  232. union/_image.py +760 -0
  233. union/_initialize.py +585 -0
  234. union/_interface.py +84 -0
  235. union/_internal/__init__.py +3 -0
  236. union/_internal/controllers/__init__.py +77 -0
  237. union/_internal/controllers/_local_controller.py +77 -0
  238. union/_internal/controllers/pbhash.py +39 -0
  239. union/_internal/controllers/remote/__init__.py +40 -0
  240. union/_internal/controllers/remote/_action.py +131 -0
  241. union/_internal/controllers/remote/_client.py +43 -0
  242. union/_internal/controllers/remote/_controller.py +169 -0
  243. union/_internal/controllers/remote/_core.py +341 -0
  244. union/_internal/controllers/remote/_informer.py +260 -0
  245. union/_internal/controllers/remote/_service_protocol.py +44 -0
  246. union/_internal/imagebuild/__init__.py +11 -0
  247. union/_internal/imagebuild/docker_builder.py +416 -0
  248. union/_internal/imagebuild/image_builder.py +243 -0
  249. union/_internal/imagebuild/remote_builder.py +0 -0
  250. union/_internal/resolvers/__init__.py +0 -0
  251. union/_internal/resolvers/_task_module.py +31 -0
  252. union/_internal/resolvers/common.py +24 -0
  253. union/_internal/resolvers/default.py +27 -0
  254. union/_internal/runtime/__init__.py +0 -0
  255. union/_internal/runtime/convert.py +163 -0
  256. union/_internal/runtime/entrypoints.py +121 -0
  257. union/_internal/runtime/io.py +136 -0
  258. union/_internal/runtime/resources_serde.py +134 -0
  259. union/_internal/runtime/task_serde.py +202 -0
  260. union/_internal/runtime/taskrunner.py +179 -0
  261. union/_internal/runtime/types_serde.py +53 -0
  262. union/_logging.py +124 -0
  263. union/_protos/__init__.py +0 -0
  264. union/_protos/common/authorization_pb2.py +66 -0
  265. union/_protos/common/authorization_pb2.pyi +106 -0
  266. union/_protos/common/authorization_pb2_grpc.py +4 -0
  267. union/_protos/common/identifier_pb2.py +71 -0
  268. union/_protos/common/identifier_pb2.pyi +82 -0
  269. union/_protos/common/identifier_pb2_grpc.py +4 -0
  270. union/_protos/common/identity_pb2.py +48 -0
  271. union/_protos/common/identity_pb2.pyi +72 -0
  272. union/_protos/common/identity_pb2_grpc.py +4 -0
  273. union/_protos/common/list_pb2.py +36 -0
  274. union/_protos/common/list_pb2.pyi +69 -0
  275. union/_protos/common/list_pb2_grpc.py +4 -0
  276. union/_protos/common/policy_pb2.py +37 -0
  277. union/_protos/common/policy_pb2.pyi +27 -0
  278. union/_protos/common/policy_pb2_grpc.py +4 -0
  279. union/_protos/common/role_pb2.py +37 -0
  280. union/_protos/common/role_pb2.pyi +51 -0
  281. union/_protos/common/role_pb2_grpc.py +4 -0
  282. union/_protos/common/runtime_version_pb2.py +28 -0
  283. union/_protos/common/runtime_version_pb2.pyi +24 -0
  284. union/_protos/common/runtime_version_pb2_grpc.py +4 -0
  285. union/_protos/logs/dataplane/payload_pb2.py +96 -0
  286. union/_protos/logs/dataplane/payload_pb2.pyi +168 -0
  287. union/_protos/logs/dataplane/payload_pb2_grpc.py +4 -0
  288. union/_protos/secret/definition_pb2.py +49 -0
  289. union/_protos/secret/definition_pb2.pyi +93 -0
  290. union/_protos/secret/definition_pb2_grpc.py +4 -0
  291. union/_protos/secret/payload_pb2.py +62 -0
  292. union/_protos/secret/payload_pb2.pyi +94 -0
  293. union/_protos/secret/payload_pb2_grpc.py +4 -0
  294. union/_protos/secret/secret_pb2.py +38 -0
  295. union/_protos/secret/secret_pb2.pyi +6 -0
  296. union/_protos/secret/secret_pb2_grpc.py +198 -0
  297. union/_protos/validate/validate/validate_pb2.py +76 -0
  298. union/_protos/workflow/node_execution_service_pb2.py +26 -0
  299. union/_protos/workflow/node_execution_service_pb2.pyi +4 -0
  300. union/_protos/workflow/node_execution_service_pb2_grpc.py +32 -0
  301. union/_protos/workflow/queue_service_pb2.py +75 -0
  302. union/_protos/workflow/queue_service_pb2.pyi +103 -0
  303. union/_protos/workflow/queue_service_pb2_grpc.py +172 -0
  304. union/_protos/workflow/run_definition_pb2.py +100 -0
  305. union/_protos/workflow/run_definition_pb2.pyi +256 -0
  306. union/_protos/workflow/run_definition_pb2_grpc.py +4 -0
  307. union/_protos/workflow/run_logs_service_pb2.py +41 -0
  308. union/_protos/workflow/run_logs_service_pb2.pyi +28 -0
  309. union/_protos/workflow/run_logs_service_pb2_grpc.py +69 -0
  310. union/_protos/workflow/run_service_pb2.py +133 -0
  311. union/_protos/workflow/run_service_pb2.pyi +173 -0
  312. union/_protos/workflow/run_service_pb2_grpc.py +412 -0
  313. union/_protos/workflow/state_service_pb2.py +58 -0
  314. union/_protos/workflow/state_service_pb2.pyi +69 -0
  315. union/_protos/workflow/state_service_pb2_grpc.py +138 -0
  316. union/_protos/workflow/task_definition_pb2.py +72 -0
  317. union/_protos/workflow/task_definition_pb2.pyi +65 -0
  318. union/_protos/workflow/task_definition_pb2_grpc.py +4 -0
  319. union/_protos/workflow/task_service_pb2.py +44 -0
  320. union/_protos/workflow/task_service_pb2.pyi +31 -0
  321. union/_protos/workflow/task_service_pb2_grpc.py +104 -0
  322. union/_resources.py +226 -0
  323. union/_retry.py +32 -0
  324. union/_reusable_environment.py +25 -0
  325. union/_run.py +374 -0
  326. union/_secret.py +61 -0
  327. union/_task.py +354 -0
  328. union/_task_environment.py +186 -0
  329. union/_timeout.py +47 -0
  330. union/_tools.py +27 -0
  331. union/_utils/__init__.py +11 -0
  332. union/_utils/asyn.py +119 -0
  333. union/_utils/file_handling.py +71 -0
  334. union/_utils/helpers.py +46 -0
  335. union/_utils/lazy_module.py +54 -0
  336. union/_utils/uv_script_parser.py +49 -0
  337. union/_version.py +21 -0
  338. union/connectors/__init__.py +0 -0
  339. union/errors.py +128 -0
  340. union/extras/__init__.py +5 -0
  341. union/extras/_container.py +263 -0
  342. union/io/__init__.py +11 -0
  343. union/io/_dataframe.py +0 -0
  344. union/io/_dir.py +425 -0
  345. union/io/_file.py +418 -0
  346. union/io/pickle/__init__.py +0 -0
  347. union/io/pickle/transformer.py +117 -0
  348. union/io/structured_dataset/__init__.py +122 -0
  349. union/io/structured_dataset/basic_dfs.py +219 -0
  350. union/io/structured_dataset/structured_dataset.py +1057 -0
  351. union/py.typed +0 -0
  352. union/remote/__init__.py +23 -0
  353. union/remote/_client/__init__.py +0 -0
  354. union/remote/_client/_protocols.py +129 -0
  355. union/remote/_client/auth/__init__.py +12 -0
  356. union/remote/_client/auth/_authenticators/__init__.py +0 -0
  357. union/remote/_client/auth/_authenticators/base.py +391 -0
  358. union/remote/_client/auth/_authenticators/client_credentials.py +73 -0
  359. union/remote/_client/auth/_authenticators/device_code.py +120 -0
  360. union/remote/_client/auth/_authenticators/external_command.py +77 -0
  361. union/remote/_client/auth/_authenticators/factory.py +200 -0
  362. union/remote/_client/auth/_authenticators/pkce.py +515 -0
  363. union/remote/_client/auth/_channel.py +184 -0
  364. union/remote/_client/auth/_client_config.py +83 -0
  365. union/remote/_client/auth/_default_html.py +32 -0
  366. union/remote/_client/auth/_grpc_utils/__init__.py +0 -0
  367. union/remote/_client/auth/_grpc_utils/auth_interceptor.py +204 -0
  368. union/remote/_client/auth/_grpc_utils/default_metadata_interceptor.py +144 -0
  369. union/remote/_client/auth/_keyring.py +154 -0
  370. union/remote/_client/auth/_token_client.py +258 -0
  371. union/remote/_client/auth/errors.py +16 -0
  372. union/remote/_client/controlplane.py +86 -0
  373. union/remote/_data.py +149 -0
  374. union/remote/_logs.py +74 -0
  375. union/remote/_project.py +86 -0
  376. union/remote/_run.py +820 -0
  377. union/remote/_secret.py +132 -0
  378. union/remote/_task.py +193 -0
  379. union/report/__init__.py +3 -0
  380. union/report/_report.py +178 -0
  381. union/report/_template.html +124 -0
  382. union/storage/__init__.py +24 -0
  383. union/storage/_remote_fs.py +34 -0
  384. union/storage/_storage.py +247 -0
  385. union/storage/_utils.py +5 -0
  386. union/types/__init__.py +11 -0
  387. union/types/_renderer.py +162 -0
  388. union/types/_string_literals.py +120 -0
  389. union/types/_type_engine.py +2131 -0
  390. union/types/_utils.py +80 -0
@@ -0,0 +1,54 @@
1
+ import inspect
2
+ import os
3
+ import pathlib
4
+ import sys
5
+ from typing import Tuple
6
+
7
+ from flyte._task import AsyncFunctionTaskTemplate, TaskTemplate
8
+
9
+
10
+ def extract_task_module(task: TaskTemplate, /, source_dir: pathlib.Path | None = None) -> Tuple[str, str]:
11
+ """
12
+ Extract the task module from the task template.
13
+
14
+ :param task: The task template to extract the module from.
15
+ :param source_dir: The source directory to use for relative paths.
16
+ :return: A tuple containing the entity name, module
17
+ """
18
+ entity_name = task.name
19
+ if isinstance(task, AsyncFunctionTaskTemplate):
20
+ entity_module = inspect.getmodule(task.func)
21
+ if entity_module is None:
22
+ raise ValueError(f"Task {entity_name} has no module.")
23
+
24
+ fp = entity_module.__file__
25
+ if fp is None:
26
+ raise ValueError(f"Task {entity_name} has no module.")
27
+
28
+ file_path = pathlib.Path(fp)
29
+ # Get the relative path to the current directory
30
+ # Will raise ValueError if the file is not in the source directory
31
+ relative_path = file_path.relative_to(str(source_dir))
32
+
33
+ if relative_path == pathlib.Path("."):
34
+ entity_module_name = entity_module.__name__
35
+ else:
36
+ # Replace file separators with dots and remove the '.py' extension
37
+ dotted_path = os.path.splitext(str(relative_path))[0].replace(os.sep, ".")
38
+ entity_module_name = dotted_path
39
+
40
+ entity_name = task.func.__name__
41
+ else:
42
+ raise NotImplementedError(f"Task module {entity_name} not implemented.")
43
+
44
+ if entity_module_name == "__main__":
45
+ """
46
+ This case is for the case in which the task is run from the main module.
47
+ """
48
+ fp = sys.modules["__main__"].__file__
49
+ if fp is None:
50
+ raise ValueError(f"Task {entity_name} has no module.")
51
+ main_path = pathlib.Path(fp)
52
+ entity_module_name = main_path.stem
53
+
54
+ return entity_name, entity_module_name
@@ -0,0 +1,31 @@
1
+ from asyncio import Protocol
2
+ from pathlib import Path
3
+ from typing import List, Optional
4
+
5
+ from flyte._task import TaskTemplate
6
+
7
+
8
+ class Resolver(Protocol):
9
+ """
10
+ Resolver interface for loading tasks. This interface should be implemented by Resolvers.
11
+ """
12
+
13
+ @property
14
+ def import_path(self) -> str:
15
+ """
16
+ The import path of the resolver. This should be a valid python import path.
17
+ """
18
+ return ""
19
+
20
+ def load_task(self, loader_args: List[str]) -> TaskTemplate:
21
+ """
22
+ Given the set of identifier keys, should return one TaskTemplate or raise an error if not found
23
+ """
24
+ raise NotImplementedError
25
+
26
+ def loader_args(self, t: TaskTemplate, root_dir: Optional[Path]) -> List[str]:
27
+ """
28
+ Return a list of strings that can help identify the parameter TaskTemplate. Each string should not have
29
+ spaces or special characters. This is used to identify the task in the resolver.
30
+ """
31
+ return []
@@ -0,0 +1,28 @@
1
+ import importlib
2
+ from pathlib import Path
3
+ from typing import List, Optional
4
+
5
+ from flyte._internal.resolvers._task_module import extract_task_module
6
+ from flyte._internal.resolvers.common import Resolver
7
+ from flyte._task import TaskTemplate
8
+
9
+
10
+ class DefaultTaskResolver(Resolver):
11
+ """
12
+ Please see the notes in the TaskResolverMixin as it describes this default behavior.
13
+ """
14
+
15
+ @property
16
+ def import_path(self) -> str:
17
+ return "flyte._internal.resolvers.default.DefaultTaskResolver"
18
+
19
+ def load_task(self, loader_args: List[str]) -> TaskTemplate:
20
+ _, task_module, _, task_name, *_ = loader_args
21
+
22
+ task_module = importlib.import_module(name=task_module) # type: ignore
23
+ task_def = getattr(task_module, task_name)
24
+ return task_def
25
+
26
+ def loader_args(self, task: TaskTemplate, root_dir: Optional[Path] = None) -> List[str]: # type:ignore
27
+ t, m = extract_task_module(task, root_dir)
28
+ return ["mod", m, "instance", t]
File without changes
@@ -0,0 +1,199 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from typing import Any, Dict, Tuple, Union
5
+
6
+ from flyteidl.core import execution_pb2, literals_pb2
7
+
8
+ import flyte.errors
9
+ import flyte.storage as storage
10
+ from flyte._datastructures import ActionID, NativeInterface, TaskContext
11
+ from flyte._internal.controllers import pbhash
12
+ from flyte._protos.workflow import run_definition_pb2
13
+ from flyte.types import TypeEngine
14
+
15
+
16
+ @dataclass(frozen=True)
17
+ class Inputs:
18
+ proto_inputs: run_definition_pb2.Inputs
19
+
20
+ @classmethod
21
+ def empty(cls) -> "Inputs":
22
+ return cls(proto_inputs=run_definition_pb2.Inputs())
23
+
24
+
25
+ @dataclass(frozen=True)
26
+ class Outputs:
27
+ proto_outputs: run_definition_pb2.Outputs
28
+
29
+
30
+ @dataclass
31
+ class Error:
32
+ err: execution_pb2.ExecutionError
33
+
34
+
35
+ # ------------------------------- CONVERT Methods ------------------------------- #
36
+
37
+
38
+ def _clean_error_code(code: str) -> Tuple[str, str | None]:
39
+ """
40
+ The error code may have a server injected code and is of the form `RetriesExhausedError|<code>` or `<code>`.
41
+
42
+ :param code:
43
+ :return: "user code", optional server code
44
+ """
45
+ if "|" in code:
46
+ server_code, user_code = code.split("|", 1)
47
+ return user_code.strip(), server_code.strip()
48
+ return code.strip(), None
49
+
50
+
51
+ async def convert_inputs_to_native(inputs: Inputs, python_interface: NativeInterface) -> Dict[str, Any]:
52
+ literals = {named_literal.name: named_literal.value for named_literal in inputs.proto_inputs.literals}
53
+ native_vals = await TypeEngine.literal_map_to_kwargs(
54
+ literals_pb2.LiteralMap(literals=literals), python_interface.get_input_types()
55
+ )
56
+ return native_vals
57
+
58
+
59
+ async def convert_from_native_to_inputs(interface: NativeInterface, *args, **kwargs) -> Inputs:
60
+ kwargs = interface.convert_to_kwargs(*args, **kwargs)
61
+ if len(kwargs) == 0:
62
+ return Inputs.empty()
63
+ if len(kwargs) < len(interface.inputs):
64
+ raise ValueError(
65
+ f"Received {len(kwargs)} inputs but interface has {len(interface.inputs)}. "
66
+ f"Please provide all required inputs."
67
+ )
68
+ literal_map = await TypeEngine.dict_to_literal_map(kwargs, interface.get_input_types())
69
+ return Inputs(
70
+ proto_inputs=run_definition_pb2.Inputs(
71
+ literals=[run_definition_pb2.NamedLiteral(name=k, value=v) for k, v in literal_map.literals.items()]
72
+ )
73
+ )
74
+
75
+
76
+ async def convert_from_native_to_outputs(o: Any, interface: NativeInterface) -> Outputs:
77
+ # Always make it a tuple even if it's just one item to simplify logic below
78
+ if not isinstance(o, tuple):
79
+ o = (o,)
80
+
81
+ assert len(interface.outputs) == len(interface.outputs), (
82
+ f"Received {len(o)} outputs but interface has {len(interface.outputs)}"
83
+ )
84
+ named = []
85
+ for (output_name, python_type), v in zip(interface.outputs.items(), o):
86
+ lit = await TypeEngine.to_literal(v, python_type, TypeEngine.to_literal_type(python_type))
87
+ named.append(run_definition_pb2.NamedLiteral(name=output_name, value=lit))
88
+
89
+ return Outputs(proto_outputs=run_definition_pb2.Outputs(literals=named))
90
+
91
+
92
+ async def convert_outputs_to_native(interface: NativeInterface, outputs: Outputs) -> Union[Any, Tuple[Any, ...]]:
93
+ lm = literals_pb2.LiteralMap(
94
+ literals={named_literal.name: named_literal.value for named_literal in outputs.proto_outputs.literals}
95
+ )
96
+ kwargs = await TypeEngine.literal_map_to_kwargs(lm, interface.outputs)
97
+ if len(kwargs) == 0:
98
+ return None
99
+ elif len(kwargs) == 1:
100
+ return next(iter(kwargs.values()))
101
+ else:
102
+ # Return as tuple if multiple outputs, make sure to order correctly as it seems proto maps can change ordering
103
+ return tuple(kwargs[k] for k in interface.outputs.keys())
104
+
105
+
106
+ def convert_error_to_native(err: execution_pb2.ExecutionError | Exception | Error) -> Exception | None:
107
+ if not err:
108
+ return None
109
+
110
+ if isinstance(err, Exception):
111
+ return err
112
+
113
+ if isinstance(err, Error):
114
+ err = err.err
115
+
116
+ user_code, server_code = _clean_error_code(err.code)
117
+ match err.kind:
118
+ case execution_pb2.ExecutionError.UNKNOWN:
119
+ return flyte.errors.RuntimeUnknownError(code=user_code, message=err.message, worker=err.worker)
120
+ case execution_pb2.ExecutionError.USER:
121
+ if "OOM" in err.code.upper():
122
+ return flyte.errors.OOMError(code=user_code, message=err.message, worker=err.worker)
123
+ elif "Interrupted" in err.code:
124
+ return flyte.errors.TaskInterruptedError(code=user_code, message=err.message, worker=err.worker)
125
+ elif "PrimaryContainerNotFound" in err.code:
126
+ return flyte.errors.PrimaryContainerNotFoundError(
127
+ code=user_code, message=err.message, worker=err.worker
128
+ )
129
+ elif "RetriesExhausted" in err.code:
130
+ return flyte.errors.RetriesExhaustedError(code=user_code, message=err.message, worker=err.worker)
131
+ elif "Unknown" in err.code:
132
+ return flyte.errors.RuntimeUnknownError(code=user_code, message=err.message, worker=err.worker)
133
+ elif "InvalidImageName" in err.code:
134
+ return flyte.errors.InvalidImageNameError(code=user_code, message=err.message, worker=err.worker)
135
+ elif "ImagePullBackOff" in err.code:
136
+ return flyte.errors.ImagePullBackOffError(code=user_code, message=err.message, worker=err.worker)
137
+ return flyte.errors.RuntimeUserError(code=user_code, message=err.message, worker=err.worker)
138
+ case execution_pb2.ExecutionError.SYSTEM:
139
+ return flyte.errors.RuntimeSystemError(code=user_code, message=err.message, worker=err.worker)
140
+ return None
141
+
142
+
143
+ def convert_from_native_to_error(err: BaseException) -> Error:
144
+ if isinstance(err, flyte.errors.RuntimeUnknownError):
145
+ return Error(
146
+ err=execution_pb2.ExecutionError(
147
+ kind=execution_pb2.ExecutionError.UNKNOWN,
148
+ code=err.code,
149
+ message=str(err),
150
+ worker=err.worker,
151
+ )
152
+ )
153
+ elif isinstance(err, flyte.errors.RuntimeUserError):
154
+ return Error(
155
+ err=execution_pb2.ExecutionError(
156
+ kind=execution_pb2.ExecutionError.USER,
157
+ code=err.code,
158
+ message=str(err),
159
+ worker=err.worker,
160
+ )
161
+ )
162
+ elif isinstance(err, flyte.errors.RuntimeSystemError):
163
+ return Error(
164
+ err=execution_pb2.ExecutionError(
165
+ kind=execution_pb2.ExecutionError.SYSTEM,
166
+ code=err.code,
167
+ message=str(err),
168
+ worker=err.worker,
169
+ )
170
+ )
171
+ else:
172
+ return Error(
173
+ err=execution_pb2.ExecutionError(
174
+ kind=execution_pb2.ExecutionError.UNKNOWN,
175
+ code=type(err).__name__,
176
+ message=str(err),
177
+ worker="UNKNOWN",
178
+ )
179
+ )
180
+
181
+
182
+ def generate_sub_action_id_and_output_path(tctx: TaskContext, task_name: str, inputs: Inputs) -> Tuple[ActionID, str]:
183
+ """
184
+ Generate a sub-action ID and output path based on the current task context, task name, and inputs.
185
+ :param tctx:
186
+ :param task_name:
187
+ :param inputs:
188
+ :return:
189
+ """
190
+ current_action_id = tctx.action
191
+ current_output_path = tctx.run_base_dir
192
+ inputs_hash = pbhash.compute_hash_string(inputs.proto_inputs)
193
+ sub_action_id = current_action_id.new_sub_action_from(
194
+ task_name=task_name,
195
+ input_hash=inputs_hash,
196
+ group=tctx.group_data.name if tctx.group_data else None,
197
+ )
198
+ sub_run_output_path = storage.join(current_output_path, sub_action_id.name)
199
+ return sub_action_id, sub_run_output_path
@@ -0,0 +1,135 @@
1
+ from typing import List, Optional, Tuple
2
+
3
+ import flyte.errors
4
+ from flyte._code_bundle import download_bundle
5
+ from flyte._context import contextual_run
6
+ from flyte._datastructures import ActionID, Checkpoints, CodeBundle, RawDataPath
7
+ from flyte._internal import Controller
8
+ from flyte._internal.imagebuild.image_builder import ImageCache
9
+ from flyte._logging import log, logger
10
+ from flyte._task import TaskTemplate
11
+
12
+ from .convert import Error, Inputs, Outputs
13
+ from .task_serde import load_task
14
+ from .taskrunner import (
15
+ convert_and_run,
16
+ extract_download_run_upload,
17
+ )
18
+
19
+
20
+ async def direct_dispatch(
21
+ task: TaskTemplate,
22
+ *,
23
+ action: ActionID,
24
+ raw_data_path: RawDataPath,
25
+ controller: Controller,
26
+ version: str,
27
+ output_path: str,
28
+ run_base_dir: str,
29
+ checkpoints: Checkpoints | None = None,
30
+ code_bundle: CodeBundle | None = None,
31
+ inputs: Inputs | None = None,
32
+ ) -> Tuple[Optional[Outputs], Optional[Error]]:
33
+ """
34
+ This method is used today by the local_controller and is positioned to be used by a rust core in the future.
35
+ The caller, loads the task and invokes this method. This method is used to convert the inputs to native types,
36
+ The reason for this is that the rust entrypoint will not have access to the python context, and
37
+ will not be able to run the tasks in the context tree.
38
+ """
39
+ return await contextual_run(
40
+ convert_and_run,
41
+ task=task,
42
+ inputs=inputs or Inputs.empty(),
43
+ action=action,
44
+ raw_data_path=raw_data_path,
45
+ checkpoints=checkpoints,
46
+ code_bundle=code_bundle,
47
+ controller=controller,
48
+ version=version,
49
+ output_path=output_path,
50
+ run_base_dir=run_base_dir,
51
+ )
52
+
53
+
54
+ async def _download_and_load_task(
55
+ code_bundle: CodeBundle | None, resolver: str | None = None, resolver_args: List[str] | None = None
56
+ ) -> TaskTemplate:
57
+ if code_bundle and (code_bundle.tgz or code_bundle.pkl):
58
+ logger.debug(f"Downloading {code_bundle}")
59
+ downloaded_path = await download_bundle(code_bundle)
60
+ code_bundle = code_bundle.with_downloaded_path(downloaded_path)
61
+ if code_bundle.pkl:
62
+ try:
63
+ logger.debug(f"Loading task from pkl: {code_bundle.downloaded_path}")
64
+ import gzip
65
+
66
+ import cloudpickle
67
+
68
+ with gzip.open(str(code_bundle.downloaded_path), "rb") as f:
69
+ return cloudpickle.load(f)
70
+ except Exception as e:
71
+ logger.exception(f"Failed to load pickled task from {code_bundle.downloaded_path}. Reason: {e!s}")
72
+ raise
73
+
74
+ if not resolver or not resolver_args:
75
+ raise flyte.errors.RuntimeSystemError(
76
+ "MalformedCommand", "Resolver and resolver args are required. for task"
77
+ )
78
+ logger.debug(
79
+ f"Loading task from tgz: {code_bundle.downloaded_path}, resolver: {resolver}, args: {resolver_args}"
80
+ )
81
+ return load_task(resolver, *resolver_args)
82
+ if not resolver or not resolver_args:
83
+ raise flyte.errors.RuntimeSystemError("MalformedCommand", "Resolver and resolver args are required. for task")
84
+ logger.debug(f"No code bundle provided, loading task from resolver: {resolver}, args: {resolver_args}")
85
+ return load_task(resolver, *resolver_args)
86
+
87
+
88
+ @log
89
+ async def load_and_run_task(
90
+ action: ActionID,
91
+ raw_data_path: RawDataPath,
92
+ output_path: str,
93
+ run_base_dir: str,
94
+ version: str,
95
+ controller: Controller,
96
+ resolver: str,
97
+ resolver_args: List[str],
98
+ checkpoints: Checkpoints | None = None,
99
+ code_bundle: CodeBundle | None = None,
100
+ input_path: str | None = None,
101
+ image_cache: ImageCache | None = None,
102
+ ):
103
+ """
104
+ This method is invoked from the runtime/CLI and is used to run a task. This creates the context tree,
105
+ for the tasks to run in. It also handles the loading of the task.
106
+
107
+ :param controller: Controller to use for the task.
108
+ :param resolver: The resolver to use to load the task.
109
+ :param resolver_args: The arguments to pass to the resolver.
110
+ :param action: The ActionID to use for the task.
111
+ :param raw_data_path: The raw data path to use for the task.
112
+ :param output_path: The output path to use for the task.
113
+ :param run_base_dir: Base output directory to pass down to child tasks.
114
+ :param version: The version of the task to run.
115
+ :param checkpoints: The checkpoints to use for the task.
116
+ :param code_bundle: The code bundle to use for the task.
117
+ :param input_path: The input path to use for the task.
118
+ :param image_cache: Mappings of Image identifiers to image URIs.
119
+ """
120
+ task = await _download_and_load_task(code_bundle, resolver, resolver_args)
121
+
122
+ await contextual_run(
123
+ extract_download_run_upload,
124
+ task,
125
+ action=action,
126
+ version=version,
127
+ controller=controller,
128
+ raw_data_path=raw_data_path,
129
+ output_path=output_path,
130
+ run_base_dir=run_base_dir,
131
+ checkpoints=checkpoints,
132
+ code_bundle=code_bundle,
133
+ input_path=input_path,
134
+ image_cache=image_cache,
135
+ )
@@ -0,0 +1,136 @@
1
+ """
2
+ This module contains the methods for uploading and downloading inputs and outputs.
3
+ It uses the storage module to handle the actual uploading and downloading of files.
4
+
5
+ TODO: Convert to use streaming apis
6
+ """
7
+
8
+ import logging
9
+
10
+ from flyteidl.core import errors_pb2, execution_pb2
11
+
12
+ import flyte.storage as storage
13
+ from flyte._protos.workflow import run_definition_pb2
14
+
15
+ from ..._logging import log
16
+ from .convert import Inputs, Outputs, _clean_error_code
17
+
18
+ # ------------------------------- CONSTANTS ------------------------------- #
19
+ _INPUTS_FILE_NAME = "inputs.pb"
20
+ _OUTPUTS_FILE_NAME = "outputs.pb"
21
+ _CHECKPOINT_FILE_NAME = "_flytecheckpoints"
22
+ _ERROR_FILE_NAME = "error.pb"
23
+ _REPORT_FILE_NAME = "report.html"
24
+ _PKL_FILE_NAME = "code_bundle.pkl.gz"
25
+
26
+
27
+ def pkl_path(base_path: str) -> str:
28
+ return storage.join(base_path, _PKL_FILE_NAME)
29
+
30
+
31
+ def inputs_path(base_path: str) -> str:
32
+ return storage.join(base_path, _INPUTS_FILE_NAME)
33
+
34
+
35
+ def outputs_path(base_path: str) -> str:
36
+ return storage.join(base_path, _OUTPUTS_FILE_NAME)
37
+
38
+
39
+ def error_path(base_path: str) -> str:
40
+ return storage.join(base_path, _ERROR_FILE_NAME)
41
+
42
+
43
+ def report_path(base_path: str) -> str:
44
+ return storage.join(base_path, _REPORT_FILE_NAME)
45
+
46
+
47
+ # ------------------------------- UPLOAD Methods ------------------------------- #
48
+
49
+
50
+ async def upload_inputs(inputs: Inputs, input_path: str):
51
+ """
52
+ :param Inputs inputs: Inputs
53
+ :param str input_path: The path to upload the input file.
54
+ """
55
+ await storage.put_stream(data_iterable=inputs.proto_inputs.SerializeToString(), to_path=input_path)
56
+
57
+
58
+ async def upload_outputs(outputs: Outputs, output_path: str):
59
+ """
60
+ :param outputs: Outputs
61
+ :param output_path: The path to upload the output file.
62
+ """
63
+ output_uri = outputs_path(output_path)
64
+ await storage.put_stream(data_iterable=outputs.proto_outputs.SerializeToString(), to_path=output_uri)
65
+
66
+
67
+ async def upload_error(err: execution_pb2.ExecutionError, output_prefix: str):
68
+ """
69
+ :param err: execution_pb2.ExecutionError
70
+ :param output_prefix: The output prefix of the remote uri.
71
+ """
72
+ # TODO - clean this up + conditionally set kind
73
+ error_document = errors_pb2.ErrorDocument(
74
+ error=errors_pb2.ContainerError(
75
+ code=err.code,
76
+ message=err.message,
77
+ kind=errors_pb2.ContainerError.RECOVERABLE,
78
+ origin=err.kind,
79
+ timestamp=err.timestamp,
80
+ worker=err.worker,
81
+ )
82
+ )
83
+ error_uri = error_path(output_prefix)
84
+ await storage.put_stream(data_iterable=error_document.SerializeToString(), to_path=error_uri)
85
+
86
+
87
+ # ------------------------------- DOWNLOAD Methods ------------------------------- #
88
+ @log(level=logging.INFO)
89
+ async def load_inputs(path: str) -> Inputs:
90
+ """
91
+ :param path: Input file to be downloaded
92
+ :return: Inputs object
93
+ """
94
+ lm = run_definition_pb2.Inputs()
95
+ proto_str = b"".join([c async for c in storage.get_stream(path=path)])
96
+ lm.ParseFromString(proto_str)
97
+ return Inputs(proto_inputs=lm)
98
+
99
+
100
+ async def load_outputs(path: str) -> Outputs:
101
+ """
102
+ :param path: output file to be loaded
103
+ :return: Outputs object
104
+ """
105
+ lm = run_definition_pb2.Outputs()
106
+ proto_str = b"".join([c async for c in storage.get_stream(path=path)])
107
+ lm.ParseFromString(proto_str)
108
+ return Outputs(proto_outputs=lm)
109
+
110
+
111
+ async def load_error(path: str) -> execution_pb2.ExecutionError:
112
+ """
113
+ :param path: error file to be downloaded
114
+ :return: execution_pb2.ExecutionError
115
+ """
116
+ err = errors_pb2.ErrorDocument()
117
+ proto_str = b"".join([c async for c in storage.get_stream(path=path)])
118
+ err.ParseFromString(proto_str)
119
+
120
+ if err.error is not None:
121
+ user_code, server_code = _clean_error_code(err.error.code)
122
+ return execution_pb2.ExecutionError(
123
+ code=user_code,
124
+ message=err.error.message,
125
+ kind=err.error.origin,
126
+ error_uri=path,
127
+ timestamp=err.error.timestamp,
128
+ worker=err.error.worker,
129
+ )
130
+
131
+ return execution_pb2.ExecutionError(
132
+ code="Unknown",
133
+ message=f"Received unloadable error from path {path}",
134
+ kind=execution_pb2.ExecutionError.SYSTEM,
135
+ error_uri=path,
136
+ )