truefoundry 0.4.4rc10__py3-none-any.whl → 0.4.4rc12__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.

@@ -92,7 +92,7 @@ class SignedURLClient:
92
92
  retries=self.max_retries, backoff_factor=self.retry_backoff_factor
93
93
  )
94
94
 
95
- @log_time
95
+ @log_time(prefix=LOG_PREFIX)
96
96
  def _make_request(
97
97
  self,
98
98
  endpoint: str,
@@ -111,6 +111,7 @@ class SignedURLClient:
111
111
  except RequestException as e:
112
112
  raise RuntimeError(f"Error during request to {url}: {e}") from e
113
113
 
114
+ @log_time(prefix=LOG_PREFIX)
114
115
  def _make_server_api_call(
115
116
  self,
116
117
  endpoint: SignedURLServerEndpoint,
@@ -124,7 +125,7 @@ class SignedURLClient:
124
125
  endpoint=endpoint_with_params, method="GET", payload=None, headers=headers
125
126
  )
126
127
 
127
- @log_time
128
+ @log_time(prefix=LOG_PREFIX)
128
129
  def _upload_data(self, signed_url: str, data: Any) -> None:
129
130
  """
130
131
  Upload data to the specified storage path using a signed URL.
@@ -144,6 +145,7 @@ class SignedURLClient:
144
145
  except Exception as e:
145
146
  raise RuntimeError(f"Failed to upload data: {e}") from e
146
147
 
148
+ @log_time(prefix=LOG_PREFIX)
147
149
  def upload_from_bytes(self, data: bytes, storage_uri: str) -> str:
148
150
  """Upload bytes to the specified storage path using a signed URL."""
149
151
  signed_object = self._make_server_api_call(
@@ -155,7 +157,7 @@ class SignedURLClient:
155
157
  self._upload_data(pre_signed_object_dto.signed_url, data)
156
158
  return storage_uri
157
159
 
158
- @log_time
160
+ @log_time(prefix=LOG_PREFIX)
159
161
  def upload(self, file_path: str, storage_uri: str) -> str:
160
162
  """Upload a file to the specified storage path using a signed URL."""
161
163
  logger.info(f"{LOG_PREFIX} Uploading {file_path} to {storage_uri}")
@@ -169,7 +171,7 @@ class SignedURLClient:
169
171
  self._upload_data(pre_signed_object_dto.signed_url, file)
170
172
  return storage_uri
171
173
 
172
- @log_time
174
+ @log_time(prefix=LOG_PREFIX)
173
175
  def _download_file(
174
176
  self, signed_url: str, local_path: Optional[str] = None
175
177
  ) -> Optional[bytes]:
@@ -191,7 +193,7 @@ class SignedURLClient:
191
193
  except RequestException as e:
192
194
  raise RuntimeError(f"Failed to download file from {signed_url}: {e}") from e
193
195
 
194
- @log_time
196
+ @log_time(prefix=LOG_PREFIX)
195
197
  def download(self, storage_uri: str, local_path: str) -> Optional[str]:
196
198
  """Download a file from the specified storage path to a local path using a signed URL."""
197
199
  logger.info(f"{LOG_PREFIX} Downloading {storage_uri} to {local_path}")
@@ -204,6 +206,7 @@ class SignedURLClient:
204
206
  self._download_file(presigned_object.signed_url, local_path)
205
207
  return local_path
206
208
 
209
+ @log_time(prefix=LOG_PREFIX)
207
210
  def download_to_bytes(self, storage_uri: str) -> bytes:
208
211
  """Download a file from the specified storage path and return it as bytes."""
209
212
  response = self._make_server_api_call(
@@ -214,6 +217,7 @@ class SignedURLClient:
214
217
  presigned_object = SignedURLAPIResponseDto.parse_obj(response)
215
218
  return self._download_file(presigned_object.signed_url)
216
219
 
220
+ @log_time(prefix=LOG_PREFIX)
217
221
  def exists(self, uri: str) -> bool:
218
222
  """Check if a file exists at the specified path."""
219
223
  response = self._make_server_api_call(
@@ -223,6 +227,7 @@ class SignedURLClient:
223
227
  )
224
228
  return SignedURLExistsAPIResponseDto.parse_obj(response).exists
225
229
 
230
+ @log_time(prefix=LOG_PREFIX)
226
231
  def is_directory(self, uri: str) -> bool:
227
232
  """Check if the specified URI is a directory."""
228
233
  response = self._make_server_api_call(
@@ -236,7 +241,7 @@ class SignedURLClient:
236
241
  logger.info(f"{LOG_PREFIX} Path {uri} is a directory: {is_directory}")
237
242
  return is_directory
238
243
 
239
- @log_time
244
+ @log_time(prefix=LOG_PREFIX)
240
245
  def list_files(
241
246
  self, path: str, detail: bool = False, max_results: int = 1000
242
247
  ) -> Union[List[FileInfo], List[str]]:
@@ -8,7 +8,7 @@ from typing import Optional
8
8
  from fsspec.spec import DEFAULT_CALLBACK, AbstractBufferedFile, AbstractFileSystem
9
9
 
10
10
  from truefoundry.common.constants import ENV_VARS
11
- from truefoundry.common.tfy_signed_url_client import SignedURLClient
11
+ from truefoundry.common.tfy_signed_url_client import LOG_PREFIX, SignedURLClient
12
12
  from truefoundry.common.utils import log_time
13
13
 
14
14
 
@@ -21,12 +21,12 @@ class SignedURLFileSystem(AbstractFileSystem):
21
21
  token = token or ENV_VARS.TFY_INTERNAL_SIGNED_URL_SERVER_TOKEN
22
22
  self.client = SignedURLClient(base_url, token)
23
23
 
24
- @log_time
24
+ @log_time(prefix=LOG_PREFIX)
25
25
  def exists(self, path, **kwargs):
26
26
  """Check if a file exists at the given path."""
27
27
  return self.client.exists(path)
28
28
 
29
- @log_time
29
+ @log_time(prefix=LOG_PREFIX)
30
30
  def get(
31
31
  self,
32
32
  rpath,
@@ -87,7 +87,7 @@ class SignedURLFileSystem(AbstractFileSystem):
87
87
  Path(os.path.dirname(target_local_path)).mkdir(parents=True, exist_ok=True)
88
88
  self.client.download(storage_uri=rpath, local_path=target_local_path)
89
89
 
90
- @log_time
90
+ @log_time(prefix=LOG_PREFIX)
91
91
  def put(
92
92
  self,
93
93
  lpath,
@@ -134,7 +134,7 @@ class SignedURLFileSystem(AbstractFileSystem):
134
134
  rpath = os.path.join(rpath, local_path.name)
135
135
  return self.client.upload(file_path=lpath, storage_uri=rpath)
136
136
 
137
- @log_time
137
+ @log_time(prefix=LOG_PREFIX)
138
138
  def isdir(self, path):
139
139
  """Is this entry directory-like?"""
140
140
  return self.client.is_directory(path)
@@ -170,6 +170,7 @@ class SignedURLFileSystem(AbstractFileSystem):
170
170
  # Wrapping the buffer to automatically upload on close
171
171
  return io.BufferedWriter(buffer, on_close)
172
172
 
173
+ @log_time(prefix=LOG_PREFIX)
173
174
  def write(self, path, data, **kwargs):
174
175
  """
175
176
  Write data to the file at the specified path (this could be tied to open's close).
@@ -185,7 +186,7 @@ class SignedURLFileSystem(AbstractFileSystem):
185
186
  # Upload the content to the remote file system
186
187
  self.client.upload_from_bytes(content, storage_uri=path)
187
188
 
188
- @log_time
189
+ @log_time(prefix=LOG_PREFIX)
189
190
  def ls(self, path, detail=True, **kwargs):
190
191
  """List objects at path."""
191
192
  return self.client.list_files(path, detail=detail)
@@ -10,6 +10,7 @@ from truefoundry.common.constants import (
10
10
  MLFOUNDRY_SERVER_RELATIVE_PATH,
11
11
  TFY_HOST_ENV_KEY,
12
12
  )
13
+ from truefoundry.logger import logger
13
14
  from truefoundry.pydantic_v1 import BaseSettings
14
15
 
15
16
  T = TypeVar("T")
@@ -104,15 +105,18 @@ def resolve_tfy_host(tfy_host: Optional[str] = None) -> str:
104
105
  return tfy_host
105
106
 
106
107
 
107
- def log_time(func):
108
+ def log_time(prefix: str = ""):
108
109
  """Decorator to log the time taken by I/O operations."""
109
110
 
110
- @wraps(func)
111
- def wrapper(*args, **kwargs):
112
- start_time = time.time()
113
- result = func(*args, **kwargs)
114
- elapsed_time = time.time() - start_time
115
- print(f"{func.__name__} took {elapsed_time:.2f} seconds")
116
- return result
111
+ def decorator(func):
112
+ @wraps(func)
113
+ def wrapper(*args, **kwargs):
114
+ start_time = time.time()
115
+ result = func(*args, **kwargs)
116
+ elapsed_time = time.time() - start_time
117
+ logger.info(f"{prefix}{func.__name__} took {elapsed_time:.2f} seconds")
118
+ return result
119
+
120
+ return wrapper
117
121
 
118
- return wrapper
122
+ return decorator