truefoundry 0.5.3rc4__py3-none-any.whl → 0.5.3rc5__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.
- truefoundry/__init__.py +10 -1
- truefoundry/autodeploy/cli.py +2 -2
- truefoundry/cli/__main__.py +0 -4
- truefoundry/cli/util.py +12 -3
- truefoundry/common/auth_service_client.py +7 -4
- truefoundry/common/constants.py +3 -1
- truefoundry/common/credential_provider.py +7 -8
- truefoundry/common/exceptions.py +11 -7
- truefoundry/common/request_utils.py +96 -14
- truefoundry/common/servicefoundry_client.py +31 -29
- truefoundry/common/session.py +93 -0
- truefoundry/common/storage_provider_utils.py +331 -0
- truefoundry/common/utils.py +9 -9
- truefoundry/common/warnings.py +21 -0
- truefoundry/deploy/builder/builders/tfy_python_buildpack/dockerfile_template.py +8 -20
- truefoundry/deploy/cli/commands/deploy_command.py +4 -4
- truefoundry/deploy/lib/clients/servicefoundry_client.py +13 -14
- truefoundry/deploy/lib/dao/application.py +2 -2
- truefoundry/deploy/lib/dao/workspace.py +1 -1
- truefoundry/deploy/lib/session.py +1 -1
- truefoundry/deploy/v2/lib/deploy.py +2 -2
- truefoundry/deploy/v2/lib/deploy_workflow.py +1 -1
- truefoundry/deploy/v2/lib/patched_models.py +70 -4
- truefoundry/deploy/v2/lib/source.py +2 -1
- truefoundry/gateway/cli/cli.py +1 -22
- truefoundry/gateway/lib/entities.py +3 -8
- truefoundry/gateway/lib/models.py +0 -38
- truefoundry/ml/artifact/truefoundry_artifact_repo.py +33 -297
- truefoundry/ml/clients/servicefoundry_client.py +36 -15
- truefoundry/ml/exceptions.py +2 -1
- truefoundry/ml/log_types/artifacts/artifact.py +3 -2
- truefoundry/ml/log_types/artifacts/model.py +6 -5
- truefoundry/ml/log_types/artifacts/utils.py +2 -2
- truefoundry/ml/mlfoundry_api.py +6 -38
- truefoundry/ml/mlfoundry_run.py +6 -15
- truefoundry/ml/model_framework.py +2 -1
- truefoundry/ml/session.py +69 -97
- truefoundry/workflow/remote_filesystem/tfy_signed_url_client.py +42 -9
- truefoundry/workflow/remote_filesystem/tfy_signed_url_fs.py +126 -7
- {truefoundry-0.5.3rc4.dist-info → truefoundry-0.5.3rc5.dist-info}/METADATA +1 -1
- {truefoundry-0.5.3rc4.dist-info → truefoundry-0.5.3rc5.dist-info}/RECORD +43 -44
- truefoundry/deploy/lib/auth/servicefoundry_session.py +0 -61
- truefoundry/gateway/lib/client.py +0 -51
- truefoundry/ml/clients/entities.py +0 -8
- truefoundry/ml/clients/utils.py +0 -122
- {truefoundry-0.5.3rc4.dist-info → truefoundry-0.5.3rc5.dist-info}/WHEEL +0 -0
- {truefoundry-0.5.3rc4.dist-info → truefoundry-0.5.3rc5.dist-info}/entry_points.txt +0 -0
truefoundry/ml/clients/utils.py
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
from contextlib import contextmanager
|
|
3
|
-
from typing import Any, Optional
|
|
4
|
-
from urllib.parse import urljoin
|
|
5
|
-
|
|
6
|
-
import requests
|
|
7
|
-
|
|
8
|
-
from truefoundry.common.request_utils import requests_retry_session
|
|
9
|
-
from truefoundry.ml.clients.entities import HostCreds
|
|
10
|
-
from truefoundry.ml.exceptions import MlFoundryException
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
# TODO: This will be moved later to truefoundry.common.request_utils
|
|
14
|
-
def _make_url(host: str, endpoint: str) -> str:
|
|
15
|
-
if endpoint.startswith("/"):
|
|
16
|
-
raise ValueError("`endpoint` must not start with a leading slash (/)")
|
|
17
|
-
return urljoin(host, endpoint)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def _http_request(
|
|
21
|
-
*, method: str, url: str, token: Optional[str] = None, session=requests, **kwargs
|
|
22
|
-
) -> requests.Response:
|
|
23
|
-
headers = kwargs.pop("headers", {}) or {}
|
|
24
|
-
if token is not None:
|
|
25
|
-
headers["Authorization"] = f"Bearer {token}"
|
|
26
|
-
return session.request(method=method, url=url, headers=headers, **kwargs)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def http_request(
|
|
30
|
-
*, method: str, host_creds: HostCreds, endpoint: str, session=requests, **kwargs
|
|
31
|
-
) -> requests.Response:
|
|
32
|
-
url = _make_url(host=host_creds.host, endpoint=endpoint)
|
|
33
|
-
return _http_request(
|
|
34
|
-
method=method, url=url, token=host_creds.token, session=session, **kwargs
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def http_request_safe(
|
|
39
|
-
*, method: str, host_creds: HostCreds, endpoint: str, session=requests, **kwargs
|
|
40
|
-
) -> Any:
|
|
41
|
-
url = _make_url(host=host_creds.host, endpoint=endpoint)
|
|
42
|
-
try:
|
|
43
|
-
response = _http_request(
|
|
44
|
-
method=method, url=url, token=host_creds.token, session=session, **kwargs
|
|
45
|
-
)
|
|
46
|
-
response.raise_for_status()
|
|
47
|
-
try:
|
|
48
|
-
return response.json()
|
|
49
|
-
except json.JSONDecodeError as je:
|
|
50
|
-
raise MlFoundryException(
|
|
51
|
-
f"Failed to parse response as json. Response: {response.text}"
|
|
52
|
-
) from je
|
|
53
|
-
except requests.exceptions.ConnectionError as ce:
|
|
54
|
-
raise MlFoundryException("Failed to connect to TrueFoundry") from ce
|
|
55
|
-
except requests.exceptions.Timeout as te:
|
|
56
|
-
raise MlFoundryException(f"Request to {url} timed out") from te
|
|
57
|
-
except requests.exceptions.HTTPError as he:
|
|
58
|
-
raise MlFoundryException(
|
|
59
|
-
f"Request to {url} with status code {he.response.status_code}. Response: {he.response.text}",
|
|
60
|
-
status_code=he.response.status_code,
|
|
61
|
-
) from he
|
|
62
|
-
except Exception as e:
|
|
63
|
-
raise MlFoundryException(
|
|
64
|
-
f"Request to {url} failed with an unknown error"
|
|
65
|
-
) from e
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
@contextmanager
|
|
69
|
-
def cloud_storage_http_request(
|
|
70
|
-
*,
|
|
71
|
-
method,
|
|
72
|
-
url,
|
|
73
|
-
session=None,
|
|
74
|
-
timeout=None,
|
|
75
|
-
**kwargs,
|
|
76
|
-
):
|
|
77
|
-
"""
|
|
78
|
-
Performs an HTTP PUT/GET request using Python's `requests` module with automatic retry.
|
|
79
|
-
"""
|
|
80
|
-
session = session or requests_retry_session(retries=5, backoff_factor=0.5)
|
|
81
|
-
kwargs["headers"] = kwargs.get("headers", {}) or {}
|
|
82
|
-
if "blob.core.windows.net" in url:
|
|
83
|
-
kwargs["headers"].update({"x-ms-blob-type": "BlockBlob"})
|
|
84
|
-
if method.lower() not in ("put", "get"):
|
|
85
|
-
raise ValueError(f"Illegal http method: {method}")
|
|
86
|
-
try:
|
|
87
|
-
yield _http_request(
|
|
88
|
-
method=method, url=url, session=session, timeout=timeout, **kwargs
|
|
89
|
-
)
|
|
90
|
-
except Exception as e:
|
|
91
|
-
raise MlFoundryException(
|
|
92
|
-
f"API request failed with exception {str(e)}"
|
|
93
|
-
) from None
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
def augmented_raise_for_status(response):
|
|
97
|
-
try:
|
|
98
|
-
response.raise_for_status()
|
|
99
|
-
except requests.exceptions.HTTPError as he:
|
|
100
|
-
raise MlFoundryException(
|
|
101
|
-
f"Request with status code {he.response.status_code}. Response: {he.response.text}",
|
|
102
|
-
status_code=he.response.status_code,
|
|
103
|
-
) from he
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
def download_file_using_http_uri(http_uri, download_path, chunk_size=100_000_000):
|
|
107
|
-
"""
|
|
108
|
-
Downloads a file specified using the `http_uri` to a local `download_path`. This function
|
|
109
|
-
uses a `chunk_size` to ensure an OOM error is not raised a large file is downloaded.
|
|
110
|
-
|
|
111
|
-
Note : This function is meant to download files using presigned urls from various cloud
|
|
112
|
-
providers.
|
|
113
|
-
"""
|
|
114
|
-
with cloud_storage_http_request(
|
|
115
|
-
method="get", url=http_uri, stream=True
|
|
116
|
-
) as response:
|
|
117
|
-
augmented_raise_for_status(response)
|
|
118
|
-
with open(download_path, "wb") as output_file:
|
|
119
|
-
for chunk in response.iter_content(chunk_size=chunk_size):
|
|
120
|
-
if not chunk:
|
|
121
|
-
break
|
|
122
|
-
output_file.write(chunk)
|
|
File without changes
|
|
File without changes
|