truefoundry 0.3.4rc1__py3-none-any.whl → 0.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

Files changed (253) hide show
  1. truefoundry/__init__.py +2 -0
  2. truefoundry/autodeploy/agents/developer.py +1 -1
  3. truefoundry/autodeploy/agents/project_identifier.py +2 -2
  4. truefoundry/autodeploy/agents/tester.py +1 -1
  5. truefoundry/autodeploy/cli.py +1 -1
  6. truefoundry/autodeploy/tools/list_files.py +1 -1
  7. truefoundry/cli/__main__.py +3 -17
  8. truefoundry/common/__init__.py +0 -0
  9. truefoundry/{deploy/lib/auth → common}/auth_service_client.py +50 -40
  10. truefoundry/common/constants.py +12 -0
  11. truefoundry/{deploy/lib/auth → common}/credential_file_manager.py +7 -7
  12. truefoundry/{deploy/lib/auth → common}/credential_provider.py +10 -23
  13. truefoundry/common/entities.py +124 -0
  14. truefoundry/common/exceptions.py +12 -0
  15. truefoundry/common/request_utils.py +84 -0
  16. truefoundry/common/servicefoundry_client.py +91 -0
  17. truefoundry/common/utils.py +56 -0
  18. truefoundry/deploy/auto_gen/models.py +4 -6
  19. truefoundry/deploy/cli/cli.py +3 -1
  20. truefoundry/deploy/cli/commands/apply_command.py +1 -1
  21. truefoundry/deploy/cli/commands/build_command.py +1 -1
  22. truefoundry/deploy/cli/commands/deploy_command.py +1 -1
  23. truefoundry/deploy/cli/commands/login_command.py +2 -2
  24. truefoundry/deploy/cli/commands/patch_application_command.py +1 -1
  25. truefoundry/deploy/cli/commands/patch_command.py +1 -1
  26. truefoundry/deploy/cli/commands/terminate_comand.py +1 -1
  27. truefoundry/deploy/cli/util.py +1 -1
  28. truefoundry/deploy/function_service/remote/remote.py +1 -1
  29. truefoundry/deploy/lib/auth/servicefoundry_session.py +2 -2
  30. truefoundry/deploy/lib/clients/servicefoundry_client.py +120 -159
  31. truefoundry/deploy/lib/const.py +1 -35
  32. truefoundry/deploy/lib/exceptions.py +0 -16
  33. truefoundry/deploy/lib/model/entity.py +1 -112
  34. truefoundry/deploy/lib/session.py +14 -42
  35. truefoundry/deploy/lib/util.py +0 -37
  36. truefoundry/{python_deploy_codegen.py → deploy/python_deploy_codegen.py} +2 -2
  37. truefoundry/deploy/v2/lib/deploy.py +3 -3
  38. truefoundry/deploy/v2/lib/deployable_patched_models.py +1 -1
  39. truefoundry/langchain/truefoundry_chat.py +1 -1
  40. truefoundry/langchain/truefoundry_embeddings.py +1 -1
  41. truefoundry/langchain/truefoundry_llm.py +1 -1
  42. truefoundry/langchain/utils.py +0 -41
  43. truefoundry/ml/__init__.py +37 -6
  44. truefoundry/ml/artifact/__init__.py +0 -0
  45. truefoundry/ml/artifact/truefoundry_artifact_repo.py +1161 -0
  46. truefoundry/ml/autogen/__init__.py +0 -0
  47. truefoundry/ml/autogen/client/__init__.py +370 -0
  48. truefoundry/ml/autogen/client/api/__init__.py +16 -0
  49. truefoundry/ml/autogen/client/api/auth_api.py +184 -0
  50. truefoundry/ml/autogen/client/api/deprecated_api.py +605 -0
  51. truefoundry/ml/autogen/client/api/experiments_api.py +1944 -0
  52. truefoundry/ml/autogen/client/api/health_api.py +299 -0
  53. truefoundry/ml/autogen/client/api/metrics_api.py +371 -0
  54. truefoundry/ml/autogen/client/api/mlfoundry_artifacts_api.py +7213 -0
  55. truefoundry/ml/autogen/client/api/python_deployment_config_api.py +201 -0
  56. truefoundry/ml/autogen/client/api/run_artifacts_api.py +231 -0
  57. truefoundry/ml/autogen/client/api/runs_api.py +2919 -0
  58. truefoundry/ml/autogen/client/api_client.py +822 -0
  59. truefoundry/ml/autogen/client/api_response.py +30 -0
  60. truefoundry/ml/autogen/client/configuration.py +489 -0
  61. truefoundry/ml/autogen/client/exceptions.py +161 -0
  62. truefoundry/ml/autogen/client/models/__init__.py +341 -0
  63. truefoundry/ml/autogen/client/models/add_custom_metrics_to_model_version_request_dto.py +69 -0
  64. truefoundry/ml/autogen/client/models/add_features_to_model_version_request_dto.py +83 -0
  65. truefoundry/ml/autogen/client/models/agent.py +125 -0
  66. truefoundry/ml/autogen/client/models/agent_app.py +118 -0
  67. truefoundry/ml/autogen/client/models/agent_open_api_tool.py +143 -0
  68. truefoundry/ml/autogen/client/models/agent_open_api_tool_with_fqn.py +144 -0
  69. truefoundry/ml/autogen/client/models/agent_with_fqn.py +127 -0
  70. truefoundry/ml/autogen/client/models/artifact_dto.py +115 -0
  71. truefoundry/ml/autogen/client/models/artifact_response_dto.py +75 -0
  72. truefoundry/ml/autogen/client/models/artifact_type.py +39 -0
  73. truefoundry/ml/autogen/client/models/artifact_version_dto.py +141 -0
  74. truefoundry/ml/autogen/client/models/artifact_version_response_dto.py +77 -0
  75. truefoundry/ml/autogen/client/models/artifact_version_status.py +35 -0
  76. truefoundry/ml/autogen/client/models/assistant_message.py +89 -0
  77. truefoundry/ml/autogen/client/models/authorize_user_for_model_request_dto.py +69 -0
  78. truefoundry/ml/autogen/client/models/authorize_user_for_model_version_request_dto.py +69 -0
  79. truefoundry/ml/autogen/client/models/blob_storage_reference.py +93 -0
  80. truefoundry/ml/autogen/client/models/body_get_search_runs_get.py +72 -0
  81. truefoundry/ml/autogen/client/models/chat_prompt.py +156 -0
  82. truefoundry/ml/autogen/client/models/chat_prompt_messages_inner.py +171 -0
  83. truefoundry/ml/autogen/client/models/columns_dto.py +73 -0
  84. truefoundry/ml/autogen/client/models/content.py +153 -0
  85. truefoundry/ml/autogen/client/models/content1.py +153 -0
  86. truefoundry/ml/autogen/client/models/content2.py +174 -0
  87. truefoundry/ml/autogen/client/models/content2_any_of_inner.py +150 -0
  88. truefoundry/ml/autogen/client/models/create_artifact_request_dto.py +74 -0
  89. truefoundry/ml/autogen/client/models/create_artifact_response_dto.py +65 -0
  90. truefoundry/ml/autogen/client/models/create_artifact_version_request_dto.py +74 -0
  91. truefoundry/ml/autogen/client/models/create_artifact_version_response_dto.py +65 -0
  92. truefoundry/ml/autogen/client/models/create_dataset_request_dto.py +76 -0
  93. truefoundry/ml/autogen/client/models/create_experiment_request_dto.py +94 -0
  94. truefoundry/ml/autogen/client/models/create_experiment_response_dto.py +67 -0
  95. truefoundry/ml/autogen/client/models/create_model_version_request_dto.py +95 -0
  96. truefoundry/ml/autogen/client/models/create_multi_part_upload_for_dataset_request_dto.py +73 -0
  97. truefoundry/ml/autogen/client/models/create_multi_part_upload_for_dataset_response_dto.py +79 -0
  98. truefoundry/ml/autogen/client/models/create_multi_part_upload_request_dto.py +73 -0
  99. truefoundry/ml/autogen/client/models/create_python_deployment_config_request_dto.py +72 -0
  100. truefoundry/ml/autogen/client/models/create_python_deployment_config_response_dto.py +67 -0
  101. truefoundry/ml/autogen/client/models/create_run_request_dto.py +97 -0
  102. truefoundry/ml/autogen/client/models/create_run_response_dto.py +75 -0
  103. truefoundry/ml/autogen/client/models/dataset_dto.py +112 -0
  104. truefoundry/ml/autogen/client/models/dataset_response_dto.py +75 -0
  105. truefoundry/ml/autogen/client/models/delete_artifact_versions_request_dto.py +65 -0
  106. truefoundry/ml/autogen/client/models/delete_dataset_request_dto.py +74 -0
  107. truefoundry/ml/autogen/client/models/delete_model_version_request_dto.py +65 -0
  108. truefoundry/ml/autogen/client/models/delete_run_request.py +65 -0
  109. truefoundry/ml/autogen/client/models/delete_tag_request_dto.py +68 -0
  110. truefoundry/ml/autogen/client/models/experiment_dto.py +127 -0
  111. truefoundry/ml/autogen/client/models/experiment_id_request_dto.py +67 -0
  112. truefoundry/ml/autogen/client/models/experiment_response_dto.py +75 -0
  113. truefoundry/ml/autogen/client/models/experiment_tag_dto.py +69 -0
  114. truefoundry/ml/autogen/client/models/feature_dto.py +68 -0
  115. truefoundry/ml/autogen/client/models/feature_value_type.py +35 -0
  116. truefoundry/ml/autogen/client/models/file_info_dto.py +76 -0
  117. truefoundry/ml/autogen/client/models/finalize_artifact_version_request_dto.py +101 -0
  118. truefoundry/ml/autogen/client/models/get_experiment_response_dto.py +88 -0
  119. truefoundry/ml/autogen/client/models/get_latest_run_log_response_dto.py +75 -0
  120. truefoundry/ml/autogen/client/models/get_metric_history_response.py +79 -0
  121. truefoundry/ml/autogen/client/models/get_signed_url_for_dataset_write_request_dto.py +68 -0
  122. truefoundry/ml/autogen/client/models/get_signed_urls_for_artifact_version_read_request_dto.py +68 -0
  123. truefoundry/ml/autogen/client/models/get_signed_urls_for_artifact_version_read_response_dto.py +81 -0
  124. truefoundry/ml/autogen/client/models/get_signed_urls_for_artifact_version_write_request_dto.py +69 -0
  125. truefoundry/ml/autogen/client/models/get_signed_urls_for_artifact_version_write_response_dto.py +83 -0
  126. truefoundry/ml/autogen/client/models/get_signed_urls_for_dataset_read_request_dto.py +68 -0
  127. truefoundry/ml/autogen/client/models/get_signed_urls_for_dataset_read_response_dto.py +81 -0
  128. truefoundry/ml/autogen/client/models/get_signed_urls_for_dataset_write_response_dto.py +81 -0
  129. truefoundry/ml/autogen/client/models/get_tenant_id_response_dto.py +73 -0
  130. truefoundry/ml/autogen/client/models/http_validation_error.py +82 -0
  131. truefoundry/ml/autogen/client/models/image_content_part.py +87 -0
  132. truefoundry/ml/autogen/client/models/image_url.py +75 -0
  133. truefoundry/ml/autogen/client/models/internal_metadata.py +180 -0
  134. truefoundry/ml/autogen/client/models/latest_run_log_dto.py +78 -0
  135. truefoundry/ml/autogen/client/models/list_artifact_versions_request_dto.py +107 -0
  136. truefoundry/ml/autogen/client/models/list_artifact_versions_response_dto.py +87 -0
  137. truefoundry/ml/autogen/client/models/list_artifacts_request_dto.py +96 -0
  138. truefoundry/ml/autogen/client/models/list_artifacts_response_dto.py +86 -0
  139. truefoundry/ml/autogen/client/models/list_colums_response_dto.py +75 -0
  140. truefoundry/ml/autogen/client/models/list_datasets_request_dto.py +78 -0
  141. truefoundry/ml/autogen/client/models/list_datasets_response_dto.py +86 -0
  142. truefoundry/ml/autogen/client/models/list_experiments_response_dto.py +86 -0
  143. truefoundry/ml/autogen/client/models/list_files_for_artifact_version_request_dto.py +76 -0
  144. truefoundry/ml/autogen/client/models/list_files_for_artifact_versions_response_dto.py +82 -0
  145. truefoundry/ml/autogen/client/models/list_files_for_dataset_request_dto.py +76 -0
  146. truefoundry/ml/autogen/client/models/list_files_for_dataset_response_dto.py +82 -0
  147. truefoundry/ml/autogen/client/models/list_latest_run_logs_response_dto.py +82 -0
  148. truefoundry/ml/autogen/client/models/list_metric_history_request_dto.py +69 -0
  149. truefoundry/ml/autogen/client/models/list_metric_history_response_dto.py +84 -0
  150. truefoundry/ml/autogen/client/models/list_model_version_response_dto.py +87 -0
  151. truefoundry/ml/autogen/client/models/list_model_versions_request_dto.py +93 -0
  152. truefoundry/ml/autogen/client/models/list_models_request_dto.py +89 -0
  153. truefoundry/ml/autogen/client/models/list_models_response_dto.py +84 -0
  154. truefoundry/ml/autogen/client/models/list_run_artifacts_response_dto.py +84 -0
  155. truefoundry/ml/autogen/client/models/list_run_logs_response_dto.py +82 -0
  156. truefoundry/ml/autogen/client/models/list_seed_experiments_response_dto.py +81 -0
  157. truefoundry/ml/autogen/client/models/log_batch_request_dto.py +106 -0
  158. truefoundry/ml/autogen/client/models/log_metric_request_dto.py +80 -0
  159. truefoundry/ml/autogen/client/models/log_param_request_dto.py +76 -0
  160. truefoundry/ml/autogen/client/models/method.py +37 -0
  161. truefoundry/ml/autogen/client/models/metric_collection_dto.py +82 -0
  162. truefoundry/ml/autogen/client/models/metric_dto.py +76 -0
  163. truefoundry/ml/autogen/client/models/mime_type.py +37 -0
  164. truefoundry/ml/autogen/client/models/model_configuration.py +103 -0
  165. truefoundry/ml/autogen/client/models/model_dto.py +122 -0
  166. truefoundry/ml/autogen/client/models/model_response_dto.py +75 -0
  167. truefoundry/ml/autogen/client/models/model_schema_dto.py +85 -0
  168. truefoundry/ml/autogen/client/models/model_version_dto.py +170 -0
  169. truefoundry/ml/autogen/client/models/model_version_response_dto.py +75 -0
  170. truefoundry/ml/autogen/client/models/multi_part_upload_dto.py +107 -0
  171. truefoundry/ml/autogen/client/models/multi_part_upload_response_dto.py +79 -0
  172. truefoundry/ml/autogen/client/models/multi_part_upload_storage_provider.py +34 -0
  173. truefoundry/ml/autogen/client/models/notify_artifact_version_failure_dto.py +65 -0
  174. truefoundry/ml/autogen/client/models/openapi_spec.py +152 -0
  175. truefoundry/ml/autogen/client/models/param_dto.py +66 -0
  176. truefoundry/ml/autogen/client/models/parameters.py +84 -0
  177. truefoundry/ml/autogen/client/models/prediction_type.py +34 -0
  178. truefoundry/ml/autogen/client/models/resolve_agent_app_response_dto.py +75 -0
  179. truefoundry/ml/autogen/client/models/restore_run_request_dto.py +65 -0
  180. truefoundry/ml/autogen/client/models/run_data_dto.py +104 -0
  181. truefoundry/ml/autogen/client/models/run_dto.py +84 -0
  182. truefoundry/ml/autogen/client/models/run_info_dto.py +105 -0
  183. truefoundry/ml/autogen/client/models/run_log_dto.py +90 -0
  184. truefoundry/ml/autogen/client/models/run_log_input_dto.py +80 -0
  185. truefoundry/ml/autogen/client/models/run_response_dto.py +75 -0
  186. truefoundry/ml/autogen/client/models/run_tag_dto.py +66 -0
  187. truefoundry/ml/autogen/client/models/search_runs_request_dto.py +94 -0
  188. truefoundry/ml/autogen/client/models/search_runs_response_dto.py +84 -0
  189. truefoundry/ml/autogen/client/models/set_experiment_tag_request_dto.py +73 -0
  190. truefoundry/ml/autogen/client/models/set_tag_request_dto.py +76 -0
  191. truefoundry/ml/autogen/client/models/signed_url_dto.py +69 -0
  192. truefoundry/ml/autogen/client/models/stop.py +152 -0
  193. truefoundry/ml/autogen/client/models/store_run_logs_request_dto.py +83 -0
  194. truefoundry/ml/autogen/client/models/system_message.py +89 -0
  195. truefoundry/ml/autogen/client/models/text.py +153 -0
  196. truefoundry/ml/autogen/client/models/text_content_part.py +84 -0
  197. truefoundry/ml/autogen/client/models/update_artifact_version_request_dto.py +74 -0
  198. truefoundry/ml/autogen/client/models/update_dataset_request_dto.py +74 -0
  199. truefoundry/ml/autogen/client/models/update_experiment_request_dto.py +74 -0
  200. truefoundry/ml/autogen/client/models/update_model_version_request_dto.py +93 -0
  201. truefoundry/ml/autogen/client/models/update_run_request_dto.py +78 -0
  202. truefoundry/ml/autogen/client/models/update_run_response_dto.py +75 -0
  203. truefoundry/ml/autogen/client/models/url.py +153 -0
  204. truefoundry/ml/autogen/client/models/user_message.py +89 -0
  205. truefoundry/ml/autogen/client/models/validation_error.py +87 -0
  206. truefoundry/ml/autogen/client/models/validation_error_loc_inner.py +154 -0
  207. truefoundry/ml/autogen/client/rest.py +426 -0
  208. truefoundry/ml/autogen/client_README.md +320 -0
  209. truefoundry/ml/cli/__init__.py +0 -0
  210. truefoundry/ml/cli/cli.py +18 -0
  211. truefoundry/ml/cli/commands/__init__.py +3 -0
  212. truefoundry/ml/cli/commands/download.py +87 -0
  213. truefoundry/ml/clients/__init__.py +0 -0
  214. truefoundry/ml/clients/entities.py +8 -0
  215. truefoundry/ml/clients/servicefoundry_client.py +45 -0
  216. truefoundry/ml/clients/utils.py +122 -0
  217. truefoundry/ml/constants.py +84 -0
  218. truefoundry/ml/entities.py +62 -0
  219. truefoundry/ml/enums.py +70 -0
  220. truefoundry/ml/env_vars.py +9 -0
  221. truefoundry/ml/exceptions.py +8 -0
  222. truefoundry/ml/git_info.py +60 -0
  223. truefoundry/ml/internal_namespace.py +52 -0
  224. truefoundry/ml/log_types/__init__.py +4 -0
  225. truefoundry/ml/log_types/artifacts/artifact.py +431 -0
  226. truefoundry/ml/log_types/artifacts/constants.py +33 -0
  227. truefoundry/ml/log_types/artifacts/dataset.py +384 -0
  228. truefoundry/ml/log_types/artifacts/general_artifact.py +110 -0
  229. truefoundry/ml/log_types/artifacts/model.py +611 -0
  230. truefoundry/ml/log_types/artifacts/model_extras.py +48 -0
  231. truefoundry/ml/log_types/artifacts/utils.py +161 -0
  232. truefoundry/ml/log_types/image/__init__.py +3 -0
  233. truefoundry/ml/log_types/image/constants.py +8 -0
  234. truefoundry/ml/log_types/image/image.py +357 -0
  235. truefoundry/ml/log_types/image/image_normalizer.py +102 -0
  236. truefoundry/ml/log_types/image/types.py +68 -0
  237. truefoundry/ml/log_types/plot.py +281 -0
  238. truefoundry/ml/log_types/pydantic_base.py +10 -0
  239. truefoundry/ml/log_types/utils.py +12 -0
  240. truefoundry/ml/logger.py +17 -0
  241. truefoundry/ml/mlfoundry_api.py +1575 -0
  242. truefoundry/ml/mlfoundry_run.py +1203 -0
  243. truefoundry/ml/run_utils.py +93 -0
  244. truefoundry/ml/session.py +168 -0
  245. truefoundry/ml/validation_utils.py +346 -0
  246. truefoundry/pydantic_v1.py +8 -1
  247. truefoundry/workflow/__init__.py +16 -1
  248. {truefoundry-0.3.4rc1.dist-info → truefoundry-0.4.0.dist-info}/METADATA +21 -14
  249. truefoundry-0.4.0.dist-info/RECORD +344 -0
  250. truefoundry/deploy/lib/clients/utils.py +0 -41
  251. truefoundry-0.3.4rc1.dist-info/RECORD +0 -136
  252. {truefoundry-0.3.4rc1.dist-info → truefoundry-0.4.0.dist-info}/WHEEL +0 -0
  253. {truefoundry-0.3.4rc1.dist-info → truefoundry-0.4.0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,91 @@
1
+ from __future__ import annotations
2
+
3
+ import functools
4
+ from urllib.parse import urlparse
5
+
6
+ import requests
7
+ from packaging import version
8
+
9
+ from truefoundry.common.constants import (
10
+ SERVICEFOUNDRY_CLIENT_MAX_RETRIES,
11
+ VERSION_PREFIX,
12
+ )
13
+ from truefoundry.common.entities import (
14
+ PythonSDKConfig,
15
+ TenantInfo,
16
+ )
17
+ from truefoundry.common.request_utils import request_handling, requests_retry_session
18
+ from truefoundry.common.utils import (
19
+ append_servicefoundry_path_to_base_url,
20
+ timed_lru_cache,
21
+ )
22
+ from truefoundry.logger import logger
23
+ from truefoundry.version import __version__
24
+
25
+
26
+ def check_min_cli_version(fn):
27
+ @functools.wraps(fn)
28
+ def inner(*args, **kwargs):
29
+ if __version__ != "0.0.0":
30
+ client: "ServiceFoundryServiceClient" = args[0]
31
+ # "0.0.0" indicates dev version
32
+ # noinspection PyProtectedMember
33
+ min_cli_version_required = client._min_cli_version_required
34
+ if version.parse(__version__) < version.parse(min_cli_version_required):
35
+ raise Exception(
36
+ "You are using an outdated version of `truefoundry`.\n"
37
+ f"Run `pip install truefoundry>={min_cli_version_required}` to install the supported version.",
38
+ )
39
+ else:
40
+ logger.debug("Ignoring minimum cli version check")
41
+
42
+ return fn(*args, **kwargs)
43
+
44
+ return inner
45
+
46
+
47
+ def session_with_retries() -> requests.Session:
48
+ return requests_retry_session(retries=SERVICEFOUNDRY_CLIENT_MAX_RETRIES)
49
+
50
+
51
+ @timed_lru_cache(seconds=30 * 60)
52
+ def _cached_get_tenant_info(api_server_url: str) -> TenantInfo:
53
+ res = session_with_retries().get(
54
+ url=f"{api_server_url}/{VERSION_PREFIX}/tenant-id",
55
+ params={"hostName": urlparse(api_server_url).netloc},
56
+ )
57
+ res = request_handling(res)
58
+ return TenantInfo.parse_obj(res)
59
+
60
+
61
+ @timed_lru_cache(seconds=30 * 60)
62
+ def _cached_get_python_sdk_config(api_server_url: str) -> PythonSDKConfig:
63
+ res = session_with_retries().get(
64
+ url=f"{api_server_url}/{VERSION_PREFIX}/min-cli-version"
65
+ )
66
+ res = request_handling(res)
67
+ return PythonSDKConfig.parse_obj(res)
68
+
69
+
70
+ class ServiceFoundryServiceClient:
71
+ def __init__(self, base_url: str):
72
+ self._base_url = base_url.strip("/")
73
+ self._api_server_url = append_servicefoundry_path_to_base_url(self._base_url)
74
+
75
+ @property
76
+ def base_url(self) -> str:
77
+ return self._base_url
78
+
79
+ @property
80
+ def tenant_info(self) -> TenantInfo:
81
+ return _cached_get_tenant_info(self._api_server_url)
82
+
83
+ @property
84
+ def python_sdk_config(self) -> PythonSDKConfig:
85
+ return _cached_get_python_sdk_config(self._api_server_url)
86
+
87
+ @functools.cached_property
88
+ def _min_cli_version_required(self) -> str:
89
+ return _cached_get_python_sdk_config(
90
+ self._api_server_url
91
+ ).truefoundry_cli_min_version
@@ -0,0 +1,56 @@
1
+ import os
2
+ import time
3
+ from functools import lru_cache, wraps
4
+ from time import monotonic_ns
5
+ from typing import Callable, Generator, Optional, TypeVar
6
+ from urllib.parse import urljoin, urlsplit
7
+
8
+ from truefoundry.common.constants import (
9
+ API_SERVER_RELATIVE_PATH,
10
+ SERVICEFOUNDRY_SERVER_URL_ENV_KEY,
11
+ TFY_HOST_ENV_KEY,
12
+ )
13
+
14
+ T = TypeVar("T")
15
+
16
+
17
+ def timed_lru_cache(
18
+ seconds: int = 300, maxsize: Optional[int] = None
19
+ ) -> Callable[[Callable[..., T]], Callable[..., T]]:
20
+ def wrapper_cache(func: Callable[..., T]) -> Callable[..., T]:
21
+ func = lru_cache(maxsize=maxsize)(func)
22
+ func.delta = seconds * 10**9
23
+ func.expiration = monotonic_ns() + func.delta
24
+
25
+ @wraps(func)
26
+ def wrapped_func(*args, **kwargs):
27
+ if monotonic_ns() >= func.expiration:
28
+ func.cache_clear()
29
+ func.expiration = monotonic_ns() + func.delta
30
+ return func(*args, **kwargs)
31
+
32
+ return wrapped_func
33
+
34
+ return wrapper_cache
35
+
36
+
37
+ def poll_for_function(
38
+ func: Callable[..., T], poll_after_secs: int = 5, *args, **kwargs
39
+ ) -> Generator[T, None, None]:
40
+ while True:
41
+ yield func(*args, **kwargs)
42
+ time.sleep(poll_after_secs)
43
+
44
+
45
+ def resolve_base_url(host: Optional[str] = None) -> str:
46
+ if not host and not os.getenv(TFY_HOST_ENV_KEY):
47
+ raise ValueError(
48
+ f"Either `host` should be provided by --host <value>, or `{TFY_HOST_ENV_KEY}` env must be set"
49
+ )
50
+ return host or os.getenv(TFY_HOST_ENV_KEY)
51
+
52
+
53
+ def append_servicefoundry_path_to_base_url(base_url: str):
54
+ if urlsplit(base_url).netloc.startswith("localhost"):
55
+ return os.getenv(SERVICEFOUNDRY_SERVER_URL_ENV_KEY)
56
+ return urljoin(base_url, API_SERVER_RELATIVE_PATH)
@@ -1,6 +1,6 @@
1
1
  # generated by datamodel-codegen:
2
2
  # filename: application.json
3
- # timestamp: 2024-09-19T11:05:06+00:00
3
+ # timestamp: 2024-09-29T10:28:22+00:00
4
4
 
5
5
  from __future__ import annotations
6
6
 
@@ -310,9 +310,7 @@ class GcpTPU(BaseModel):
310
310
 
311
311
 
312
312
  class GitHelmRepo(BaseModel):
313
- type: constr(regex=r"^git-helm-repo$") = Field(
314
- ..., description="+value=git-helm-repo"
315
- )
313
+ type: Literal["git-helm-repo"] = Field(..., description="+value=git-helm-repo")
316
314
  repo_url: constr(
317
315
  regex=r"^(((https?|wss):\/\/)?(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*))$"
318
316
  ) = Field(
@@ -357,7 +355,7 @@ class GitSource(BaseModel):
357
355
 
358
356
 
359
357
  class HelmRepo(BaseModel):
360
- type: constr(regex=r"^helm-repo$") = Field(..., description="+value=helm-repo")
358
+ type: Literal["helm-repo"] = Field(..., description="+value=helm-repo")
361
359
  repo_url: constr(
362
360
  regex=r"^(((https?|wss):\/\/)?(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*))$"
363
361
  ) = Field(
@@ -647,7 +645,7 @@ class OCIRepo(BaseModel):
647
645
  +label=OCIRepo
648
646
  """
649
647
 
650
- type: constr(regex=r"^oci-repo$") = Field(..., description="+value=oci-repo")
648
+ type: Literal["oci-repo"] = Field(..., description="+value=oci-repo")
651
649
  oci_chart_url: constr(
652
650
  regex=r"^(((oci):\/\/)?(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*))$"
653
651
  ) = Field(..., description="+label=OCI chart URL\n+message=Need to be a valid URL.")
@@ -13,6 +13,7 @@ from truefoundry.deploy.cli.commands import (
13
13
  get_logout_command,
14
14
  get_patch_application_command,
15
15
  get_patch_command,
16
+ get_terminate_command,
16
17
  get_trigger_command,
17
18
  )
18
19
  from truefoundry.deploy.cli.config import CliConfig
@@ -24,7 +25,7 @@ from truefoundry.version import __version__
24
25
  click.rich_click.USE_RICH_MARKUP = True
25
26
 
26
27
 
27
- def create_truefoundry_cli():
28
+ def create_truefoundry_cli() -> click.MultiCommand:
28
29
  """Generates CLI by combining all subcommands into a main CLI and returns in
29
30
 
30
31
  Returns:
@@ -38,6 +39,7 @@ def create_truefoundry_cli():
38
39
  cli.add_command(get_patch_application_command())
39
40
  cli.add_command(get_delete_command())
40
41
  cli.add_command(get_trigger_command())
42
+ cli.add_command(get_terminate_command())
41
43
 
42
44
  if not (sys.platform.startswith("win32") or sys.platform.startswith("cygwin")):
43
45
  cli.add_command(get_patch_command())
@@ -17,7 +17,7 @@ from truefoundry.deploy.lib.model.entity import ApplyResult
17
17
  name="apply",
18
18
  cls=GROUP_CLS,
19
19
  invoke_without_command=True,
20
- help="Create resources by appling manifest locally from Truefoundry spec",
20
+ help="Create resources by applying manifest locally from TrueFoundry spec",
21
21
  context_settings={"ignore_unknown_options": True, "allow_interspersed_args": True},
22
22
  )
23
23
  @click.option(
@@ -13,7 +13,7 @@ from truefoundry.version import __version__
13
13
  name="build",
14
14
  cls=GROUP_CLS,
15
15
  invoke_without_command=True,
16
- help="Build docker image locally from Truefoundry spec",
16
+ help="Build docker image locally from TrueFoundry spec",
17
17
  context_settings={"ignore_unknown_options": True, "allow_interspersed_args": True},
18
18
  )
19
19
  @click.option(
@@ -29,7 +29,7 @@ def _get_default_spec_file():
29
29
  name="deploy",
30
30
  cls=GROUP_CLS,
31
31
  invoke_without_command=True,
32
- help="Deploy application to Truefoundry",
32
+ help="Deploy application to TrueFoundry",
33
33
  )
34
34
  @click.option(
35
35
  "-f",
@@ -1,18 +1,18 @@
1
1
  import rich_click as click
2
2
 
3
+ from truefoundry.common.constants import TFY_HOST_ENV_KEY
3
4
  from truefoundry.deploy.cli.const import COMMAND_CLS
4
5
  from truefoundry.deploy.cli.util import (
5
6
  _prompt_if_no_value_and_supported,
6
7
  handle_exception_wrapper,
7
8
  )
8
9
  from truefoundry.deploy.io.rich_output_callback import RichOutputCallBack
9
- from truefoundry.deploy.lib.const import HOST_ENV_NAME
10
10
  from truefoundry.deploy.lib.session import login
11
11
 
12
12
 
13
13
  @click.command(name="login", cls=COMMAND_CLS)
14
14
  @click.option("--relogin", type=click.BOOL, is_flag=True, default=False)
15
- @click.option("--host", type=click.STRING, required=True, envvar=HOST_ENV_NAME)
15
+ @click.option("--host", type=click.STRING, required=True, envvar=TFY_HOST_ENV_KEY)
16
16
  @click.option(
17
17
  "--api-key",
18
18
  "--api_key",
@@ -12,7 +12,7 @@ from truefoundry.deploy.lib.dao import application as application_lib
12
12
  name="patch-application",
13
13
  cls=GROUP_CLS,
14
14
  invoke_without_command=True,
15
- help="Deploy application with patches to Truefoundry",
15
+ help="Deploy application with patches to TrueFoundry",
16
16
  )
17
17
  @click.option(
18
18
  "-f",
@@ -12,7 +12,7 @@ from truefoundry.deploy.io.rich_output_callback import RichOutputCallBack
12
12
  name="patch",
13
13
  cls=GROUP_CLS,
14
14
  invoke_without_command=True,
15
- help="Patch parts of servicefoundry.yaml file",
15
+ help="Patch parts of truefoundry.yaml file",
16
16
  )
17
17
  @click.option(
18
18
  "-f",
@@ -9,7 +9,7 @@ from truefoundry.deploy.lib.dao import application as application_lib
9
9
  @click.group(name="terminate", cls=GROUP_CLS)
10
10
  def terminate_command():
11
11
  """
12
- Terminate the job
12
+ Terminate Job Runs
13
13
  """
14
14
  pass
15
15
 
@@ -10,9 +10,9 @@ from rich.padding import Padding
10
10
  from rich.panel import Panel
11
11
  from rich.table import Table
12
12
 
13
+ from truefoundry.common.exceptions import BadRequestException
13
14
  from truefoundry.deploy.cli.console import console
14
15
  from truefoundry.deploy.lib.exceptions import (
15
- BadRequestException,
16
16
  ConfigurationException,
17
17
  )
18
18
  from truefoundry.deploy.lib.util import is_debug_env_set
@@ -66,7 +66,7 @@ class RemoteClass(Remote):
66
66
  # methods in the class, but internally doing network call.
67
67
  # But I am sticking with this now because not all the concepts of a python
68
68
  # class right now, will work in both remote and local. Examples, you cannot
69
- # access arbitary attributes, properties etc. I want to keep the behaviour
69
+ # access arbitrary attributes, properties etc. I want to keep the behaviour
70
70
  # identical for now.
71
71
  absent = object()
72
72
  methods = inspect.getmembers(class_, predicate=inspect.isfunction)
@@ -2,12 +2,12 @@ from __future__ import annotations
2
2
 
3
3
  from typing import Optional
4
4
 
5
- from truefoundry.deploy.lib.auth.credential_provider import (
5
+ from truefoundry.common.credential_provider import (
6
6
  CredentialProvider,
7
7
  EnvCredentialProvider,
8
8
  FileCredentialProvider,
9
9
  )
10
- from truefoundry.deploy.lib.model.entity import UserInfo
10
+ from truefoundry.common.entities import UserInfo
11
11
  from truefoundry.logger import logger
12
12
 
13
13
  ACTIVE_SESSION: Optional[ServiceFoundrySession] = None