truefoundry 0.11.1rc1__py3-none-any.whl → 0.11.2__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.

@@ -16,6 +16,7 @@ from truefoundry.common.constants import (
16
16
  API_SERVER_RELATIVE_PATH,
17
17
  ENV_VARS,
18
18
  MLFOUNDRY_SERVER_RELATIVE_PATH,
19
+ TFY_API_KEY_ENV_KEY,
19
20
  TFY_DEBUG_ENV_KEY,
20
21
  TFY_HOST_ENV_KEY,
21
22
  TFY_INTERNAL_ENV_KEY,
@@ -113,9 +114,14 @@ def validate_tfy_host(tfy_host: str) -> None:
113
114
  def resolve_tfy_host(tfy_host: Optional[str] = None) -> str:
114
115
  tfy_host = tfy_host or ENV_VARS.TFY_HOST
115
116
  if not tfy_host:
116
- raise ValueError(
117
- f"Either `host` should be provided using `--host <value>`, or `{TFY_HOST_ENV_KEY}` env must be set"
118
- )
117
+ if ENV_VARS.TFY_API_KEY:
118
+ raise ValueError(
119
+ f"TFY_HOST` env must be set since `{TFY_API_KEY_ENV_KEY}` env is set. Either set `{TFY_HOST_ENV_KEY}` or unset `{TFY_API_KEY_ENV_KEY}` and login"
120
+ )
121
+ else:
122
+ raise ValueError(
123
+ f"Either `host` should be provided using `--host <value>`, or `{TFY_HOST_ENV_KEY}` env must be set"
124
+ )
119
125
  tfy_host = tfy_host.strip("/")
120
126
  validate_tfy_host(tfy_host)
121
127
  return tfy_host
@@ -45,16 +45,9 @@ def upload_file_to_s3(file_path, bucket_name, s3_key):
45
45
  # Use s3proxy for pushing data to s3
46
46
  # The JWT token is already available in the pod
47
47
  aws_access_key_id = os.environ.get("SPARK_APPLICATION_EVENT_LOG_JWT_TOKEN")
48
- aws_secret_access_key = "__token__"
48
+ aws_secret_access_key = os.environ.get("TFY_NOTEBOOK_OUTPUT_S3_SECRET_KEY")
49
49
  s3_endpoint_url = os.environ.get("S3_PROXY_URL")
50
50
 
51
- if not aws_access_key_id:
52
- raise ValueError(
53
- "SPARK_APPLICATION_EVENT_LOG_JWT_TOKEN environment variable is not set"
54
- )
55
- if not s3_endpoint_url:
56
- raise ValueError("S3_PROXY_URL environment variable is not set")
57
-
58
51
  # Needed for the issue https://github.com/gaul/s3proxy/issues/765
59
52
  s3_config = Config(
60
53
  request_checksum_calculation="when_required",
@@ -106,7 +99,22 @@ def execute_notebook(notebook_path, output_path="/tmp/output.ipynb", parameters=
106
99
  stderr_file=sys.stderr,
107
100
  )
108
101
  print(f"Successfully executed notebook: {notebook_path}")
109
- return output_path
102
+
103
+
104
+ def validate_env_vars():
105
+ keys = [
106
+ "TFY_NOTEBOOK_OUTPUT_S3_KEY",
107
+ "TFY_NOTEBOOK_OUTPUT_S3_BUCKET",
108
+ "SPARK_APPLICATION_EVENT_LOG_JWT_TOKEN",
109
+ "TFY_NOTEBOOK_OUTPUT_S3_SECRET_KEY",
110
+ ]
111
+ unset_keys = [key for key in keys if not os.environ.get(key)]
112
+ if unset_keys:
113
+ raise ValueError(
114
+ f"Environment variables {unset_keys} are not set."
115
+ f"Contact you tenant-admin to configure storage bucket on the control plane "
116
+ f"to enable uploading spark notebook outputs."
117
+ )
110
118
 
111
119
 
112
120
  if __name__ == "__main__":
@@ -116,35 +124,31 @@ if __name__ == "__main__":
116
124
  parser.add_argument("notebook_path", help="Path to the notebook file to execute")
117
125
  args = parser.parse_args()
118
126
 
127
+ # Since failure to upload is considered a job failure, fail the job even before it run if uploads cannot happen
128
+ validate_env_vars()
129
+
119
130
  output_notebook_path = "/tmp/output.ipynb"
120
131
 
121
132
  # This would be the same as the default bucket used by servicefoundry-server
122
133
  s3_bucket = os.environ.get("TFY_NOTEBOOK_OUTPUT_S3_BUCKET")
123
- # This would be something like sparkjob-events/<tenant-id>
124
- s3_key_prefix = os.environ.get("TFY_NOTEBOOK_OUTPUT_S3_KEY_PREFIX")
134
+ # This would be something like sparkjob-events/<tenant-id>/output-notebooks/<application-id>/<jobrun-name>/output.html
135
+ s3_key = os.environ.get("TFY_NOTEBOOK_OUTPUT_S3_KEY")
125
136
 
126
137
  try:
127
- executed_notebook_path = execute_notebook(
128
- args.notebook_path, output_path=output_notebook_path
129
- )
138
+ execute_notebook(args.notebook_path, output_path=output_notebook_path)
130
139
 
131
140
  # The following may also be modeled as an entrypoint
132
141
  # https://papermill.readthedocs.io/en/latest/extending-entry-points.html
133
142
  # Will take that up with next iteration where we save the executed notebook periodically
134
- if s3_bucket and s3_key_prefix:
135
- print("Converting notebook to HTML and uploading to S3...")
136
- html_output_path = "/tmp/output.html"
137
- convert_notebook_to_html(
138
- notebook_path=executed_notebook_path, output_html_path=html_output_path
139
- )
140
-
141
- # Construct S3 key: use the original notebook name for the HTML file
142
- notebook_name = os.path.basename(args.notebook_path)
143
- s3_html_key = f"{s3_key_prefix}/output.html"
144
- upload_file_to_s3(
145
- file_path=html_output_path, bucket_name=s3_bucket, s3_key=s3_html_key
146
- )
147
- print(f"Successfully uploaded HTML to s3://{s3_bucket}/{s3_html_key}")
143
+ print("Converting notebook to HTML and uploading to S3...")
144
+ html_output_path = "/tmp/output.html"
145
+ convert_notebook_to_html(
146
+ notebook_path=output_notebook_path, output_html_path=html_output_path
147
+ )
148
+ upload_file_to_s3(
149
+ file_path=html_output_path, bucket_name=s3_bucket, s3_key=s3_key
150
+ )
151
+ print(f"Successfully uploaded HTML to s3://{s3_bucket}/{s3_key}")
148
152
 
149
153
  except Exception as e:
150
154
  print(f"Error executing notebook {args.notebook_path}: {e}")
@@ -6,17 +6,7 @@ import uuid
6
6
  from concurrent.futures import FIRST_EXCEPTION, Future, ThreadPoolExecutor, wait
7
7
  from shutil import rmtree
8
8
  from threading import Event
9
- from typing import (
10
- Any,
11
- Callable,
12
- Dict,
13
- Iterator,
14
- List,
15
- Optional,
16
- Sequence,
17
- Tuple,
18
- Union,
19
- )
9
+ from typing import Any, Callable, Dict, Iterator, List, Optional, Sequence, Tuple
20
10
  from urllib.parse import unquote
21
11
  from urllib.request import pathname2url
22
12
 
@@ -31,6 +21,7 @@ from rich.progress import (
31
21
  )
32
22
  from tqdm.utils import CallbackIOWrapper
33
23
  from truefoundry_sdk import (
24
+ FileInfo,
34
25
  MultiPartUploadResponse,
35
26
  MultiPartUploadStorageProvider,
36
27
  Operation,
@@ -52,11 +43,6 @@ from truefoundry.common.storage_provider_utils import (
52
43
  )
53
44
  from truefoundry.ml._autogen.client import ( # type: ignore[attr-defined]
54
45
  ApiClient,
55
- FileInfoDto,
56
- ListFilesForArtifactVersionRequestDto,
57
- ListFilesForArtifactVersionsResponseDto,
58
- ListFilesForDatasetRequestDto,
59
- ListFilesForDatasetResponseDto,
60
46
  MlfoundryArtifactsApi,
61
47
  RunArtifactsApi,
62
48
  )
@@ -592,44 +578,23 @@ class MlFoundryArtifactsRepository:
592
578
  progress=progress,
593
579
  )
594
580
 
595
- def _list_files(
596
- self, artifact_identifier: ArtifactIdentifier, path, page_size, page_token
597
- ) -> Union[ListFilesForDatasetResponseDto, ListFilesForArtifactVersionsResponseDto]:
598
- if artifact_identifier.dataset_fqn:
599
- return self._mlfoundry_artifacts_api.list_files_for_dataset_post(
600
- list_files_for_dataset_request_dto=ListFilesForDatasetRequestDto(
601
- dataset_fqn=artifact_identifier.dataset_fqn,
602
- path=path,
603
- max_results=page_size,
604
- page_token=page_token,
605
- )
606
- )
607
- else:
608
- return self._mlfoundry_artifacts_api.list_files_for_artifact_version_post(
609
- list_files_for_artifact_version_request_dto=ListFilesForArtifactVersionRequestDto(
610
- id=str(artifact_identifier.artifact_version_id),
611
- path=path,
612
- max_results=page_size,
613
- page_token=page_token,
614
- )
615
- )
616
-
617
581
  def list_artifacts(
618
582
  self, path=None, page_size=_LIST_FILES_PAGE_SIZE, **kwargs
619
- ) -> Iterator[FileInfoDto]:
620
- page_token = None
621
- started = False
622
- while not started or page_token is not None:
623
- started = True
624
- page = self._list_files(
625
- artifact_identifier=self.artifact_identifier,
583
+ ) -> Iterator[FileInfo]:
584
+ if self.artifact_identifier.dataset_id:
585
+ for file_info in client.data_directories.list_files(
586
+ id=str(self.artifact_identifier.dataset_id),
626
587
  path=path,
627
- page_size=page_size,
628
- page_token=page_token,
629
- )
630
- for file_info in page.files:
588
+ limit=page_size,
589
+ ):
590
+ yield file_info
591
+ else:
592
+ for file_info in client.artifact_versions.list_files(
593
+ id=str(self.artifact_identifier.artifact_version_id),
594
+ path=path,
595
+ limit=page_size,
596
+ ):
631
597
  yield file_info
632
- page_token = page.next_page_token
633
598
 
634
599
  def _is_directory(self, artifact_path):
635
600
  # TODO: Ideally server should return a flag to indicate if it is a directory
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: truefoundry
3
- Version: 0.11.1rc1
3
+ Version: 0.11.2
4
4
  Summary: TrueFoundry CLI
5
5
  Author-email: TrueFoundry Team <abhishek@truefoundry.com>
6
6
  Requires-Python: <3.14,>=3.8.1
@@ -50,7 +50,7 @@ truefoundry/common/servicefoundry_client.py,sha256=2fYhdVPSvLXz5C5tosOq86JD8WM3I
50
50
  truefoundry/common/session.py,sha256=d9l3TEBpqVP4mr4mTGY1qVxc815skzMlNNdw14otg34,2923
51
51
  truefoundry/common/storage_provider_utils.py,sha256=yURhMw8k0FLFvaviRHDiifhvc6GnuQwGMC9Qd2uM440,10934
52
52
  truefoundry/common/types.py,sha256=BMJFCsR1lPJAw66IQBSvLyV4I6o_x5oj78gVsUa9si8,188
53
- truefoundry/common/utils.py,sha256=j3QP0uOsaGD_VmDDR68JTwoYE1okkAq6OqpVkzVf48Q,6424
53
+ truefoundry/common/utils.py,sha256=P0FuAadoJGdpieUORLSN-PiFnkyoGO-K2cS4OPITBWg,6714
54
54
  truefoundry/common/warnings.py,sha256=xDMhR_-ZGC40Ycaj6nlFb5MYPexn8WbKCHd4FlflTXQ,705
55
55
  truefoundry/deploy/__init__.py,sha256=PVbGPU9S3-dTFn5LvLwaEnfsp2RrGT9iiM7_15kOV84,2837
56
56
  truefoundry/deploy/python_deploy_codegen.py,sha256=k19_m5DGsUyjOUCSKwIVP8vDna2sq01tHABsUfoVpW4,8019
@@ -67,7 +67,7 @@ truefoundry/deploy/builder/builders/tfy_python_buildpack/__init__.py,sha256=_fjq
67
67
  truefoundry/deploy/builder/builders/tfy_python_buildpack/dockerfile_template.py,sha256=f4l3fH21E2b8W3-JotMKc0AdPcCxV7LRPxxYJa7z_UQ,9134
68
68
  truefoundry/deploy/builder/builders/tfy_spark_buildpack/__init__.py,sha256=NEPlM6_vTVxp4ITa18B8DBbgYCn1q5d8be21lbgu5oY,2888
69
69
  truefoundry/deploy/builder/builders/tfy_spark_buildpack/dockerfile_template.py,sha256=2zohUaW8Yw_QREHlpRW7Pooomt19HJh44fHjlsiDmwM,6064
70
- truefoundry/deploy/builder/builders/tfy_spark_buildpack/tfy_execute_notebook.py,sha256=tTx-GZDVf5iB1Pyz2z5c2LH1yrb7lErFbJcr-giAIuI,5734
70
+ truefoundry/deploy/builder/builders/tfy_spark_buildpack/tfy_execute_notebook.py,sha256=QvawKw30dcHROJ05XQU2KgwH3gtUmEGSkuLxiuPNJ2c,5899
71
71
  truefoundry/deploy/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
72
72
  truefoundry/deploy/cli/commands/__init__.py,sha256=qv818jxqSAygJ3h-6Ul8t-5VOgR_UrSgsVtNCl3e5G0,1408
73
73
  truefoundry/deploy/cli/commands/apply_command.py,sha256=DmXmKVokkauyKIiJDtErTwbJ5_LvQeJbTQsG5BjyKpo,2427
@@ -347,7 +347,7 @@ truefoundry/ml/_autogen/models/schema.py,sha256=a_bp42MMPUbwO3407m0UW2W8EOhnxZXf
347
347
  truefoundry/ml/_autogen/models/signature.py,sha256=rBjpxUIsEeWM0sIyYG5uCJB18DKHR4k5yZw8TzuoP48,4987
348
348
  truefoundry/ml/_autogen/models/utils.py,sha256=c7RtSLXhOLcP8rjuUtfnMdaKVTZvvbsmw98gPAkAFrs,24371
349
349
  truefoundry/ml/artifact/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
350
- truefoundry/ml/artifact/truefoundry_artifact_repo.py,sha256=ocX5EIcLQa8Uc_C3NxxgNorpxc-z1Yp4TLvmzSORPpw,36862
350
+ truefoundry/ml/artifact/truefoundry_artifact_repo.py,sha256=hbgLxSoihkLVuICzRueuh8iAIc-yruCW5TuMXYQ-aCU,35692
351
351
  truefoundry/ml/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
352
352
  truefoundry/ml/cli/cli.py,sha256=MwpY7z_NEeJE_XIP7XbZELjNeu2vpMmohttHCKDRk54,335
353
353
  truefoundry/ml/cli/utils.py,sha256=j6_mZ4Spn114mz3P4QQ8jx0tmorXIuyQnHXVUSDvZi4,1035
@@ -380,7 +380,7 @@ truefoundry/workflow/remote_filesystem/__init__.py,sha256=LQ95ViEjJ7Ts4JcCGOxMPs
380
380
  truefoundry/workflow/remote_filesystem/logger.py,sha256=em2l7D6sw7xTLDP0kQSLpgfRRCLpN14Qw85TN7ujQcE,1022
381
381
  truefoundry/workflow/remote_filesystem/tfy_signed_url_client.py,sha256=xcT0wQmQlgzcj0nP3tJopyFSVWT1uv3nhiTIuwfXYeg,12342
382
382
  truefoundry/workflow/remote_filesystem/tfy_signed_url_fs.py,sha256=nSGPZu0Gyd_jz0KsEE-7w_BmnTD8CVF1S8cUJoxaCbc,13305
383
- truefoundry-0.11.1rc1.dist-info/METADATA,sha256=jIzJR7W9qc5D4a-WuEne8Y8BUotdhjnc_CEcz-Bdp78,2508
384
- truefoundry-0.11.1rc1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
385
- truefoundry-0.11.1rc1.dist-info/entry_points.txt,sha256=xVjn7RMN-MW2-9f7YU-bBdlZSvvrwzhpX1zmmRmsNPU,98
386
- truefoundry-0.11.1rc1.dist-info/RECORD,,
383
+ truefoundry-0.11.2.dist-info/METADATA,sha256=7n9RCZ9gGKy-q0nVRgja-FIyJEBcgo4eXtbrCPpfIFk,2505
384
+ truefoundry-0.11.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
385
+ truefoundry-0.11.2.dist-info/entry_points.txt,sha256=xVjn7RMN-MW2-9f7YU-bBdlZSvvrwzhpX1zmmRmsNPU,98
386
+ truefoundry-0.11.2.dist-info/RECORD,,