craft-ai-sdk 0.53.0rc1__tar.gz → 0.54.0__tar.gz

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 (22) hide show
  1. {craft_ai_sdk-0.53.0rc1 → craft_ai_sdk-0.54.0}/PKG-INFO +1 -1
  2. {craft_ai_sdk-0.53.0rc1 → craft_ai_sdk-0.54.0}/craft_ai_sdk/__init__.py +1 -1
  3. {craft_ai_sdk-0.53.0rc1 → craft_ai_sdk-0.54.0}/craft_ai_sdk/core/pipelines.py +30 -24
  4. {craft_ai_sdk-0.53.0rc1 → craft_ai_sdk-0.54.0}/craft_ai_sdk/core/steps.py +1 -37
  5. {craft_ai_sdk-0.53.0rc1 → craft_ai_sdk-0.54.0}/craft_ai_sdk/sdk.py +1 -1
  6. {craft_ai_sdk-0.53.0rc1 → craft_ai_sdk-0.54.0}/craft_ai_sdk/utils.py +26 -0
  7. {craft_ai_sdk-0.53.0rc1 → craft_ai_sdk-0.54.0}/documentation.pdf +0 -0
  8. {craft_ai_sdk-0.53.0rc1 → craft_ai_sdk-0.54.0}/pyproject.toml +5 -2
  9. {craft_ai_sdk-0.53.0rc1 → craft_ai_sdk-0.54.0}/LICENSE +0 -0
  10. {craft_ai_sdk-0.53.0rc1 → craft_ai_sdk-0.54.0}/README.md +0 -0
  11. {craft_ai_sdk-0.53.0rc1 → craft_ai_sdk-0.54.0}/craft_ai_sdk/constants.py +0 -0
  12. {craft_ai_sdk-0.53.0rc1 → craft_ai_sdk-0.54.0}/craft_ai_sdk/core/data_store.py +0 -0
  13. {craft_ai_sdk-0.53.0rc1 → craft_ai_sdk-0.54.0}/craft_ai_sdk/core/deployments.py +0 -0
  14. {craft_ai_sdk-0.53.0rc1 → craft_ai_sdk-0.54.0}/craft_ai_sdk/core/endpoints.py +0 -0
  15. {craft_ai_sdk-0.53.0rc1 → craft_ai_sdk-0.54.0}/craft_ai_sdk/core/environment_variables.py +0 -0
  16. {craft_ai_sdk-0.53.0rc1 → craft_ai_sdk-0.54.0}/craft_ai_sdk/core/pipeline_executions.py +0 -0
  17. {craft_ai_sdk-0.53.0rc1 → craft_ai_sdk-0.54.0}/craft_ai_sdk/core/pipeline_metrics.py +0 -0
  18. {craft_ai_sdk-0.53.0rc1 → craft_ai_sdk-0.54.0}/craft_ai_sdk/core/resource_metrics.py +0 -0
  19. {craft_ai_sdk-0.53.0rc1 → craft_ai_sdk-0.54.0}/craft_ai_sdk/core/users.py +0 -0
  20. {craft_ai_sdk-0.53.0rc1 → craft_ai_sdk-0.54.0}/craft_ai_sdk/exceptions.py +0 -0
  21. {craft_ai_sdk-0.53.0rc1 → craft_ai_sdk-0.54.0}/craft_ai_sdk/io.py +0 -0
  22. {craft_ai_sdk-0.53.0rc1 → craft_ai_sdk-0.54.0}/craft_ai_sdk/warnings.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: craft-ai-sdk
3
- Version: 0.53.0rc1
3
+ Version: 0.54.0
4
4
  Summary: Craft AI MLOps platform SDK
5
5
  Home-page: https://www.craft.ai/
6
6
  License: Apache-2.0
@@ -14,4 +14,4 @@ from .io import ( # noqa: F401
14
14
  )
15
15
 
16
16
 
17
- __version__ = "0.53.0rc1"
17
+ __version__ = "0.54.0"
@@ -11,13 +11,12 @@ from ..utils import (
11
11
  handle_data_store_response,
12
12
  remove_keys_from_dict,
13
13
  _datetime_to_timestamp_in_ms,
14
+ _wait_create_until_ready,
14
15
  )
15
16
  from .steps import (
16
- _add_inputs_outputs_in_message,
17
17
  _validate_create_step_parameters,
18
18
  _prepare_create_step_data,
19
19
  _prepare_create_step_files,
20
- _wait_create_until_ready,
21
20
  )
22
21
 
23
22
 
@@ -43,6 +42,7 @@ def create_pipeline(
43
42
  container_config=None,
44
43
  inputs=None,
45
44
  outputs=None,
45
+ wait_for_completion=True,
46
46
  timeout_s=None,
47
47
  **kwargs,
48
48
  ):
@@ -114,8 +114,11 @@ def create_pipeline(
114
114
  :obj:`dict` with the name of the output as keys and the value of the
115
115
  output as values. Each output should be specified as an instance
116
116
  of :class:`Output` via this parameter `outputs`.
117
+ wait_for_completion (:obj:`bool`, optional): Whether to wait for the pipeline
118
+ to be created. Defaults to ``True``.
117
119
  timeout_s (:obj:`int`): Maximum time (in seconds) to wait for the pipeline to
118
- be created. 3min (180s) by default, and at least 2min (120s).
120
+ be created. Set to None to wait indefinitely. Defaults to None.
121
+ Only applicable if ``wait_for_completion`` is ``True``.
119
122
 
120
123
  Returns:
121
124
  :obj:`dict`: Created pipeline represented as :obj:`dict` with the following
@@ -214,7 +217,6 @@ def create_pipeline(
214
217
 
215
218
  # Otherwise, the pipeline is created with a "hidden" step
216
219
  container_config = {} if container_config is None else container_config.copy()
217
- timeout_s = 3 * 60 if timeout_s is None else timeout_s
218
220
  _validate_create_step_parameters(inputs, outputs, timeout_s)
219
221
 
220
222
  url = f"{sdk.base_environment_api_url}/pipelines"
@@ -235,31 +237,23 @@ def create_pipeline(
235
237
  "This may take a while...",
236
238
  )
237
239
 
238
- start_time = sdk._get_time()
239
- created_pipeline, response = sdk._post(
240
- url, data=multipartify(data), files=files, get_response=True
241
- )
240
+ sdk._post(url, data=multipartify(data), files=files, allow_redirects=False)
242
241
 
243
- if response.status_code != 206:
244
- message = _add_inputs_outputs_in_message(
245
- f'Pipeline "{pipeline_name}" created',
246
- created_pipeline.get("inputs", []),
247
- created_pipeline.get("outputs", []),
248
- )
249
- log_action(sdk, message)
250
- return remove_keys_from_dict(created_pipeline, {"is_archived", "pipeline_id"})
242
+ return get_pipeline(sdk, pipeline_name, wait_for_completion, timeout_s)
251
243
 
252
- # The pipeline is still building. Keep checking its status until it is ready
253
- return _wait_create_until_ready(
254
- sdk, pipeline_name, get_pipeline, timeout_s, start_time, get_pipeline_logs
255
- )
256
244
 
257
-
258
- def get_pipeline(sdk: BaseCraftAiSdk, pipeline_name):
245
+ def get_pipeline(
246
+ sdk: BaseCraftAiSdk, pipeline_name, wait_for_completion=False, timeout_s=None
247
+ ):
259
248
  """Get a single pipeline if it exists.
260
249
 
261
250
  Args:
262
251
  pipeline_name (:obj:`str`): Name of the pipeline to get.
252
+ wait_for_completion (:obj:`bool`, optional): Whether to wait for the pipeline
253
+ to be created. Defaults to ``False``.
254
+ timeout_s (:obj:`int`): Maximum time (in seconds) to wait for the pipeline to
255
+ be created. Set to None to wait indefinitely. Defaults to None.
256
+ Only applicable if ``wait_for_completion`` is ``True``.
263
257
 
264
258
  Returns:
265
259
  None if the pipeline does not exist, otherwise pipeline information, with
@@ -322,8 +316,20 @@ def get_pipeline(sdk: BaseCraftAiSdk, pipeline_name):
322
316
  ``"git_repository"`` or ``"local"``.
323
317
  """
324
318
  try:
325
- url = f"{sdk.base_environment_api_url}/pipelines/{pipeline_name}"
326
- pipeline = sdk._get(url)
319
+ base_url = f"{sdk.base_environment_api_url}/pipelines/{pipeline_name}"
320
+ if wait_for_completion:
321
+ pipeline = _wait_create_until_ready(
322
+ sdk,
323
+ pipeline_name,
324
+ lambda sdk, _: sdk._get(
325
+ f"{base_url}?wait_for_completion=true", allow_redirects=False
326
+ ),
327
+ timeout_s,
328
+ sdk._get_time(),
329
+ get_pipeline_logs,
330
+ )
331
+ else:
332
+ pipeline = sdk._get(base_url)
327
333
  except SdkException as error:
328
334
  if error.status_code == 404:
329
335
  return None
@@ -1,4 +1,3 @@
1
- import time
2
1
  import tarfile
3
2
  import io
4
3
  import os
@@ -6,7 +5,6 @@ import requests
6
5
 
7
6
  from ..sdk import BaseCraftAiSdk
8
7
  from ..io import Input, Output
9
- from ..exceptions import SdkException
10
8
  from ..utils import (
11
9
  log_func_result,
12
10
  log_action,
@@ -15,8 +13,8 @@ from ..utils import (
15
13
  remove_none_values,
16
14
  handle_data_store_response,
17
15
  _datetime_to_timestamp_in_ms,
16
+ _wait_create_until_ready,
18
17
  )
19
- from ..constants import CREATION_REQUESTS_RETRY_INTERVAL
20
18
 
21
19
 
22
20
  def _compress_folder_to_memory(local_folder, include):
@@ -120,40 +118,6 @@ def _remove_id_from_step(step):
120
118
  return step
121
119
 
122
120
 
123
- def _wait_create_until_ready(sdk, name, get_func, timeout_s, start_time, get_log_func):
124
- elapsed_time = sdk._get_time() - start_time
125
- status = "creation_pending"
126
- while status == "creation_pending" and (
127
- timeout_s is None or elapsed_time < timeout_s
128
- ):
129
- time.sleep(CREATION_REQUESTS_RETRY_INTERVAL)
130
- created_obj = get_func(sdk, name)
131
- if created_obj is None:
132
- raise SdkException(
133
- f'The creation of "{name}" has failed. Please try creating the '
134
- "resource again. If this error keeps happening, please contact the "
135
- "support team.",
136
- name="UnexpectedError",
137
- )
138
- status = created_obj.get("creation_info", {}).get("status", None)
139
- elapsed_time = sdk._get_time() - start_time
140
-
141
- if status == "creation_failed":
142
- raise SdkException(
143
- f'The creation of "{name}" has failed. You can check the logs with '
144
- f'the "{get_log_func.__name__}" function.',
145
- name="CreationFailed",
146
- )
147
- if status != "ready":
148
- raise SdkException(
149
- f'The creation of "{name}" was not ready in time. It is still being '
150
- "created but this function stopped trying. Please check its status with "
151
- f'"{get_func.__name__}".',
152
- name="TimeoutException",
153
- )
154
- return created_obj
155
-
156
-
157
121
  @log_func_result("Steps creation")
158
122
  def create_step(
159
123
  sdk: BaseCraftAiSdk,
@@ -130,7 +130,7 @@ class CraftAiSdk(BaseCraftAiSdk):
130
130
  os.environ.get("CRAFT_AI__MULTIPART_PART_SIZE__B", str(38 * 256 * 1024))
131
131
  )
132
132
  _access_token_margin = timedelta(seconds=30)
133
- _version = "0.53.0rc1" # Would be better to share it somewhere
133
+ _version = "0.54.0" # Would be better to share it somewhere
134
134
 
135
135
  def __init__(
136
136
  self,
@@ -322,3 +322,29 @@ def multipartify(data, parent_key=None) -> dict:
322
322
  converted.append((current_key, formatter(value)))
323
323
 
324
324
  return dict(converted)
325
+
326
+
327
+ def _wait_create_until_ready(sdk, name, get_func, timeout_s, start_time, get_log_func):
328
+ elapsed_time = sdk._get_time() - start_time
329
+ status = "creation_pending"
330
+ while status == "creation_pending" and (
331
+ timeout_s is None or elapsed_time < timeout_s
332
+ ):
333
+ created_obj = get_func(sdk, name)
334
+ status = created_obj.get("creation_info", {}).get("status", None)
335
+ elapsed_time = sdk._get_time() - start_time
336
+
337
+ if status == "creation_failed":
338
+ raise SdkException(
339
+ f'The creation of "{name}" has failed. You can check the logs with '
340
+ f'the "{get_log_func.__name__}" function.',
341
+ name="CreationFailed",
342
+ )
343
+ if status != "ready":
344
+ raise SdkException(
345
+ f'The creation of "{name}" was not ready in time. It is still being '
346
+ "created but this function stopped trying. Please check its status with "
347
+ f'"{get_func.__name__}".',
348
+ name="TimeoutException",
349
+ )
350
+ return created_obj
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "craft-ai-sdk"
3
- version = "0.53.0rc1"
3
+ version = "0.54.0"
4
4
  description = "Craft AI MLOps platform SDK"
5
5
  license = "Apache-2.0"
6
6
  authors = ["Craft AI <contact@craft.ai>"]
@@ -34,7 +34,10 @@ StrEnum = "^0.4.9"
34
34
  ipython = "^8.0.1"
35
35
  ipykernel = "^6.9.1"
36
36
  black = "^22.1.0"
37
- flake8 = "^4.0.1"
37
+ flake8 = [
38
+ { version = "^4.0.1", python = "3.8" },
39
+ { version = "^7.1.1", python = ">=3.9,<4.0" },
40
+ ]
38
41
  pylint = "^2.12.2"
39
42
  python-dotenv = "^1.0.0"
40
43
  pytest = "^7.0.1"
File without changes