truefoundry 0.5.1rc7__py3-none-any.whl → 0.5.1rc8__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.

@@ -1,3 +1,4 @@
1
+ import enum
1
2
  import os
2
3
  from pathlib import Path
3
4
  from typing import Optional
@@ -15,6 +16,11 @@ TFY_INTERNAL_SIGNED_URL_SERVER_HOST_ENV_KEY = "TFY_INTERNAL_SIGNED_URL_SERVER_HO
15
16
  TFY_INTERNAL_SIGNED_URL_SERVER_TOKEN_ENV_KEY = "TFY_INTERNAL_SIGNED_URL_SERVER_TOKEN"
16
17
 
17
18
 
19
+ class PythonPackageManager(str, enum.Enum):
20
+ PIP = "pip"
21
+ UV = "uv"
22
+
23
+
18
24
  class TrueFoundrySdkEnv(BaseSettings):
19
25
  # Note: Every field in this class should have a default value
20
26
  # Never expect the user to set these values
@@ -46,6 +52,9 @@ class TrueFoundrySdkEnv(BaseSettings):
46
52
  # For local development, this enables futher configuration via _TFYServersConfig
47
53
  TFY_CLI_LOCAL_DEV_MODE: bool = False
48
54
 
55
+ TFY_PYTHON_BUILD_PACKAGE_MANAGER: PythonPackageManager = PythonPackageManager.PIP
56
+ TFY_PYTHON_BUILD_UV_IMAGE_URI: str = "ghcr.io/astral-sh/uv:latest"
57
+
49
58
 
50
59
  ENV_VARS = TrueFoundrySdkEnv()
51
60
  API_SERVER_RELATIVE_PATH = "api/svc"
@@ -8,7 +8,7 @@ from truefoundry.deploy.builder.builders.tfy_notebook_buildpack.dockerfile_templ
8
8
  NotebookImageBuild,
9
9
  generate_dockerfile_content,
10
10
  )
11
- from truefoundry.deploy.builder.utils import has_pip_conf_secret
11
+ from truefoundry.deploy.builder.utils import has_python_package_manager_conf_secret
12
12
 
13
13
  __all__ = ["generate_dockerfile_content", "build"]
14
14
 
@@ -38,7 +38,9 @@ def build(
38
38
  build_configuration: NotebookImageBuild,
39
39
  extra_opts: Optional[List[str]] = None,
40
40
  ):
41
- mount_pip_conf_secret = has_pip_conf_secret(extra_opts) if extra_opts else False
41
+ mount_pip_conf_secret = (
42
+ has_python_package_manager_conf_secret(extra_opts) if extra_opts else False
43
+ )
42
44
  with TemporaryDirectory() as local_dir:
43
45
  docker_build_configuration = _convert_to_dockerfile_build_config(
44
46
  build_configuration,
@@ -7,7 +7,7 @@ from truefoundry.deploy.builder.builders import dockerfile
7
7
  from truefoundry.deploy.builder.builders.tfy_python_buildpack.dockerfile_template import (
8
8
  generate_dockerfile_content,
9
9
  )
10
- from truefoundry.deploy.builder.utils import has_pip_conf_secret
10
+ from truefoundry.deploy.builder.utils import has_python_package_manager_conf_secret
11
11
 
12
12
  __all__ = ["generate_dockerfile_content", "build"]
13
13
 
@@ -15,11 +15,11 @@ __all__ = ["generate_dockerfile_content", "build"]
15
15
  def _convert_to_dockerfile_build_config(
16
16
  build_configuration: PythonBuild,
17
17
  dockerfile_path: str,
18
- mount_pip_conf_secret: bool = False,
18
+ mount_python_package_manager_conf_secret: bool = False,
19
19
  ) -> DockerFileBuild:
20
20
  dockerfile_content = generate_dockerfile_content(
21
21
  build_configuration=build_configuration,
22
- mount_pip_conf_secret=mount_pip_conf_secret,
22
+ mount_python_package_manager_conf_secret=mount_python_package_manager_conf_secret,
23
23
  )
24
24
  with open(dockerfile_path, "w", encoding="utf8") as fp:
25
25
  fp.write(dockerfile_content)
@@ -36,12 +36,14 @@ def build(
36
36
  build_configuration: PythonBuild,
37
37
  extra_opts: Optional[List[str]] = None,
38
38
  ):
39
- mount_pip_conf_secret = has_pip_conf_secret(extra_opts) if extra_opts else False
39
+ mount_python_package_manager_conf_secret = (
40
+ has_python_package_manager_conf_secret(extra_opts) if extra_opts else False
41
+ )
40
42
  with TemporaryDirectory() as local_dir:
41
43
  docker_build_configuration = _convert_to_dockerfile_build_config(
42
44
  build_configuration,
43
45
  dockerfile_path=os.path.join(local_dir, "Dockerfile"),
44
- mount_pip_conf_secret=mount_pip_conf_secret,
46
+ mount_python_package_manager_conf_secret=mount_python_package_manager_conf_secret,
45
47
  )
46
48
  dockerfile.build(
47
49
  tag=tag,
@@ -1,13 +1,16 @@
1
1
  import os
2
+ import shlex
2
3
  from typing import Dict, List, Optional
3
4
 
4
5
  from mako.template import Template
5
6
 
6
- from truefoundry.common.constants import ENV_VARS
7
+ from truefoundry.common.constants import ENV_VARS, PythonPackageManager
7
8
  from truefoundry.deploy.auto_gen.models import PythonBuild
8
9
  from truefoundry.deploy.builder.constants import (
9
10
  PIP_CONF_BUILDKIT_SECRET_MOUNT,
10
11
  PIP_CONF_SECRET_MOUNT_AS_ENV,
12
+ UV_CONF_BUILDKIT_SECRET_MOUNT,
13
+ UV_CONF_SECRET_MOUNT_AS_ENV,
11
14
  )
12
15
  from truefoundry.deploy.v2.lib.patched_models import CUDAVersion
13
16
 
@@ -22,8 +25,8 @@ RUN ${apt_install_command}
22
25
  % if requirements_path is not None:
23
26
  COPY ${requirements_path} ${requirements_destination_path}
24
27
  % endif
25
- % if pip_install_command is not None:
26
- RUN ${pip_config_secret_mount} ${pip_install_command}
28
+ % if python_packages_install_command is not None:
29
+ RUN ${package_manager_config_secret_mount} ${python_packages_install_command}
27
30
  % endif
28
31
  COPY . /app
29
32
  WORKDIR /app
@@ -114,44 +117,91 @@ def generate_pip_install_command(
114
117
  mount_pip_conf_secret: bool = False,
115
118
  ) -> Optional[str]:
116
119
  upgrade_pip_command = "python -m pip install -U pip setuptools wheel"
117
- final_pip_install_command = None
118
- pip_install_base_command = "python -m pip install --use-pep517 --no-cache-dir"
120
+ envs = []
121
+ if mount_pip_conf_secret:
122
+ envs.append(PIP_CONF_SECRET_MOUNT_AS_ENV)
123
+
124
+ command = ["python", "-m", "pip", "install", "--use-pep517", "--no-cache-dir"]
125
+ args = []
119
126
  if requirements_path:
120
- final_pip_install_command = f"{pip_install_base_command} -r {requirements_path}"
127
+ args.append("-r")
128
+ args.append(requirements_path)
121
129
 
122
130
  if pip_packages:
123
- final_pip_install_command = (
124
- final_pip_install_command or pip_install_base_command
125
- )
126
- final_pip_install_command += " " + " ".join(
127
- f"'{package}'" for package in pip_packages
128
- )
131
+ args.extend(pip_packages)
129
132
 
130
- if not final_pip_install_command:
133
+ if not args:
131
134
  return None
132
135
 
133
- if mount_pip_conf_secret:
134
- final_pip_install_command = (
135
- f"{PIP_CONF_SECRET_MOUNT_AS_ENV} {final_pip_install_command}"
136
- )
136
+ final_pip_install_command = shlex.join(envs + command + args)
137
+ final_docker_run_command = " && ".join(
138
+ [upgrade_pip_command, final_pip_install_command]
139
+ )
140
+ return final_docker_run_command
137
141
 
138
- return " && ".join([upgrade_pip_command, final_pip_install_command])
142
+
143
+ def generate_uv_pip_install_command(
144
+ requirements_path: Optional[str],
145
+ pip_packages: Optional[List[str]],
146
+ mount_uv_conf_secret: bool = False,
147
+ ) -> Optional[str]:
148
+ upgrade_pip_command = "python -m pip install -U pip setuptools wheel"
149
+ uv_mount = f"--mount=from={ENV_VARS.TFY_PYTHON_BUILD_UV_IMAGE_URI},source=/uv,target=/usr/local/bin/uv"
150
+ envs = [
151
+ "UV_SYSTEM_PYTHON=true",
152
+ "UV_LINK_MODE=copy",
153
+ "UV_PYTHON_DOWNLOADS=never",
154
+ "UV_INDEX_STRATEGY=unsafe-best-match",
155
+ ]
156
+ if mount_uv_conf_secret:
157
+ envs.append(UV_CONF_SECRET_MOUNT_AS_ENV)
158
+
159
+ command = ["uv", "pip", "install", "--no-cache-dir"]
160
+
161
+ args = []
162
+
163
+ if requirements_path:
164
+ args.append("-r")
165
+ args.append(requirements_path)
166
+
167
+ if pip_packages:
168
+ args.extend(pip_packages)
169
+
170
+ if not args:
171
+ return None
172
+
173
+ uv_pip_install_command = shlex.join(envs + command + args)
174
+ shell_commands = " && ".join([upgrade_pip_command, uv_pip_install_command])
175
+ final_docker_run_command = " ".join([uv_mount, shell_commands])
176
+
177
+ return final_docker_run_command
139
178
 
140
179
 
141
180
  def generate_dockerfile_content(
142
181
  build_configuration: PythonBuild,
143
- mount_pip_conf_secret: bool = False,
182
+ package_manager: str = ENV_VARS.TFY_PYTHON_BUILD_PACKAGE_MANAGER,
183
+ mount_python_package_manager_conf_secret: bool = False,
144
184
  ) -> str:
145
185
  # TODO (chiragjn): Handle recursive references to other requirements files e.g. `-r requirements-gpu.txt`
146
186
  requirements_path = resolve_requirements_txt_path(build_configuration)
147
187
  requirements_destination_path = (
148
188
  "/tmp/requirements.txt" if requirements_path else None
149
189
  )
150
- pip_install_command = generate_pip_install_command(
151
- requirements_path=requirements_destination_path,
152
- pip_packages=build_configuration.pip_packages,
153
- mount_pip_conf_secret=mount_pip_conf_secret,
154
- )
190
+ if package_manager == PythonPackageManager.PIP.value:
191
+ python_packages_install_command = generate_pip_install_command(
192
+ requirements_path=requirements_destination_path,
193
+ pip_packages=build_configuration.pip_packages,
194
+ mount_pip_conf_secret=mount_python_package_manager_conf_secret,
195
+ )
196
+ elif package_manager == PythonPackageManager.UV.value:
197
+ python_packages_install_command = generate_uv_pip_install_command(
198
+ requirements_path=requirements_destination_path,
199
+ pip_packages=build_configuration.pip_packages,
200
+ mount_uv_conf_secret=mount_python_package_manager_conf_secret,
201
+ )
202
+ else:
203
+ raise ValueError(f"Unsupported package manager: {package_manager}")
204
+
155
205
  apt_install_command = generate_apt_install_command(
156
206
  apt_packages=build_configuration.apt_packages
157
207
  )
@@ -161,13 +211,22 @@ def generate_dockerfile_content(
161
211
  "apt_install_command": apt_install_command,
162
212
  "requirements_path": requirements_path,
163
213
  "requirements_destination_path": requirements_destination_path,
164
- "pip_install_command": pip_install_command,
214
+ "python_packages_install_command": python_packages_install_command,
165
215
  }
166
216
 
167
- if mount_pip_conf_secret:
168
- template_args["pip_config_secret_mount"] = PIP_CONF_BUILDKIT_SECRET_MOUNT
217
+ if mount_python_package_manager_conf_secret:
218
+ if package_manager == PythonPackageManager.PIP.value:
219
+ template_args["package_manager_config_secret_mount"] = (
220
+ PIP_CONF_BUILDKIT_SECRET_MOUNT
221
+ )
222
+ elif package_manager == PythonPackageManager.UV.value:
223
+ template_args["package_manager_config_secret_mount"] = (
224
+ UV_CONF_BUILDKIT_SECRET_MOUNT
225
+ )
226
+ else:
227
+ raise ValueError(f"Unsupported package manager: {package_manager}")
169
228
  else:
170
- template_args["pip_config_secret_mount"] = ""
229
+ template_args["package_manager_config_secret_mount"] = ""
171
230
 
172
231
  if build_configuration.cuda_version:
173
232
  template = CUDA_DOCKERFILE_TEMPLATE
@@ -5,3 +5,11 @@ PIP_CONF_BUILDKIT_SECRET_MOUNT = (
5
5
  PIP_CONF_SECRET_MOUNT_AS_ENV = (
6
6
  f"PIP_CONFIG_FILE=/run/secrets/{BUILDKIT_SECRET_MOUNT_PIP_CONF_ID}"
7
7
  )
8
+
9
+ BUILDKIT_SECRET_MOUNT_UV_CONF_ID = "uv.toml"
10
+ UV_CONF_BUILDKIT_SECRET_MOUNT = (
11
+ f"--mount=type=secret,id={BUILDKIT_SECRET_MOUNT_UV_CONF_ID}"
12
+ )
13
+ UV_CONF_SECRET_MOUNT_AS_ENV = (
14
+ f"UV_CONFIG_FILE=/run/secrets/{BUILDKIT_SECRET_MOUNT_UV_CONF_ID}"
15
+ )
@@ -1,6 +1,9 @@
1
1
  from typing import List, Optional
2
2
 
3
- from truefoundry.deploy.builder.constants import BUILDKIT_SECRET_MOUNT_PIP_CONF_ID
3
+ from truefoundry.deploy.builder.constants import (
4
+ BUILDKIT_SECRET_MOUNT_PIP_CONF_ID,
5
+ BUILDKIT_SECRET_MOUNT_UV_CONF_ID,
6
+ )
4
7
 
5
8
 
6
9
  def _get_id_from_buildkit_secret_value(value: str) -> Optional[str]:
@@ -19,14 +22,16 @@ def _get_id_from_buildkit_secret_value(value: str) -> Optional[str]:
19
22
  return None
20
23
 
21
24
 
22
- def has_pip_conf_secret(docker_build_extra_args: List[str]) -> bool:
25
+ def has_python_package_manager_conf_secret(docker_build_extra_args: List[str]) -> bool:
23
26
  args = [arg.strip() for arg in docker_build_extra_args]
24
27
  for i, arg in enumerate(docker_build_extra_args):
25
28
  if (
26
29
  arg == "--secret"
27
30
  and i + 1 < len(args)
28
- and _get_id_from_buildkit_secret_value(args[i + 1])
29
- == BUILDKIT_SECRET_MOUNT_PIP_CONF_ID
31
+ and (
32
+ _get_id_from_buildkit_secret_value(args[i + 1])
33
+ in (BUILDKIT_SECRET_MOUNT_PIP_CONF_ID, BUILDKIT_SECRET_MOUNT_UV_CONF_ID)
34
+ )
30
35
  ):
31
36
  return True
32
37
  return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: truefoundry
3
- Version: 0.5.1rc7
3
+ Version: 0.5.1rc8
4
4
  Summary: Truefoundry CLI
5
5
  Author: Abhishek Choudhary
6
6
  Author-email: abhishek@truefoundry.com
@@ -27,7 +27,7 @@ truefoundry/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
27
  truefoundry/cli/__main__.py,sha256=-NkhYlT3mC5MhtekueKAvCw-sWvguj0LJRpXWzvvFjc,727
28
28
  truefoundry/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
29
  truefoundry/common/auth_service_client.py,sha256=RRiGUqITxeVYwKZLc923zJP-61UAvFtVlMaG2HJBvXc,7940
30
- truefoundry/common/constants.py,sha256=OwT8CJxGDhnrfgXCiKG5d5pkGbrd1UGGY-y672Et07Y,2310
30
+ truefoundry/common/constants.py,sha256=z96d99N_tP3om3EayB_MVOsJRmYVeNm4bBbYIW61Ta0,2556
31
31
  truefoundry/common/credential_file_manager.py,sha256=1yEk1Zm2xS4G0VDFwKSZ4w0VUrcPWQ1nJnoBaz9xyKA,4251
32
32
  truefoundry/common/credential_provider.py,sha256=Aht7hFLsnyRgMR34dRbzln7dor0WYSeA8ej8ApNmnKM,4148
33
33
  truefoundry/common/entities.py,sha256=8O-EGPk4PKqnyoFMKUTxISCU19rz0KBnfRDJU695DhY,3797
@@ -40,13 +40,13 @@ truefoundry/deploy/auto_gen/models.py,sha256=8848BDbq2hO8Y75LsBH3cS0vi8qEOKU5x6o
40
40
  truefoundry/deploy/builder/__init__.py,sha256=1qjHMNBE1poRCZW0WrG46dFM1f1IlivD5352qzsioMU,4953
41
41
  truefoundry/deploy/builder/builders/__init__.py,sha256=tlFLXqyDaKLd4iZbo4Hcu_8gOmgtL6drnXpbmQ6x1P8,636
42
42
  truefoundry/deploy/builder/builders/dockerfile.py,sha256=AXXTziCkaqIhuM_bwyD1vT1znOwemN1TKgU7eyo-KuM,1522
43
- truefoundry/deploy/builder/builders/tfy_notebook_buildpack/__init__.py,sha256=UmMcTY-8MrLY3H5owpn6ax-VePQl4MiMTmHlQ9qEtQw,1742
43
+ truefoundry/deploy/builder/builders/tfy_notebook_buildpack/__init__.py,sha256=x_GwRFKz-Kb4-ZlxOFjBlr0mTgUDe_hVeG4dsIbHo8c,1796
44
44
  truefoundry/deploy/builder/builders/tfy_notebook_buildpack/dockerfile_template.py,sha256=rQgdvKmAT9HArVW4TAG5yd2QTKRs3S5LJ9RQbc_EkHE,2518
45
- truefoundry/deploy/builder/builders/tfy_python_buildpack/__init__.py,sha256=XNJ3MKWqyWIbFNnUQMpB8oVC5Pt5Wsm_bRKbvkXRIG8,1696
46
- truefoundry/deploy/builder/builders/tfy_python_buildpack/dockerfile_template.py,sha256=rg6xGLGBUHbB3Col2NLLMP2fXlyTg8YrPFCdnFV5Bko,7327
47
- truefoundry/deploy/builder/constants.py,sha256=eIukBjD6I4KvEmAPpdbPlPPr76yhS-uNr3RVFkzEdgs,257
45
+ truefoundry/deploy/builder/builders/tfy_python_buildpack/__init__.py,sha256=9r1PYahn-HfzpMth6NkvJoycmmHQpSl0vIVZxWF12xI,1864
46
+ truefoundry/deploy/builder/builders/tfy_python_buildpack/dockerfile_template.py,sha256=xa5Y-xf9WzXTJwbp5NnlvJu-g57KeSuy8XNGlW7z9rk,9462
47
+ truefoundry/deploy/builder/constants.py,sha256=amUkHoHvVKzGv0v_knfiioRuKiJM0V0xW0diERgWiI0,508
48
48
  truefoundry/deploy/builder/docker_service.py,sha256=OI8efqK0Gnoii8bcHihpA2StwHVzsMREfBk7NvMR4hY,3950
49
- truefoundry/deploy/builder/utils.py,sha256=9RZnkhoHFTRUt_x3nck0aVz7cLpzA3jiwQH-ZZZrjf8,938
49
+ truefoundry/deploy/builder/utils.py,sha256=D68-bqM0NQx-Elg-56mtkENyVyg9faZ9tgTmBuo1Sjs,1076
50
50
  truefoundry/deploy/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
51
51
  truefoundry/deploy/cli/cli.py,sha256=BuAW-R98oz1wzPDg00fPgrK1UDoCfy0Tu6pWW9Ud1Ns,2887
52
52
  truefoundry/deploy/cli/commands/__init__.py,sha256=-i3ltscehEO0hy-Cf6gPLaiobfv8tZetPKaaCyR9B3M,1364
@@ -370,7 +370,7 @@ truefoundry/workflow/remote_filesystem/tfy_signed_url_client.py,sha256=5mBCIc-ON
370
370
  truefoundry/workflow/remote_filesystem/tfy_signed_url_fs.py,sha256=Hf6Dk6Fu6P7DqsK5ULgraf9DStjgigf-kjaRAMBW-RU,8680
371
371
  truefoundry/workflow/task.py,sha256=ToitYiKcNzFCtOVQwz1W8sRjbR97eVS7vQBdbgUQtKg,1779
372
372
  truefoundry/workflow/workflow.py,sha256=WaTqUjhwfAXDWu4E5ehuwAxrCbDJkoAf1oWmR2E9Qy0,4575
373
- truefoundry-0.5.1rc7.dist-info/METADATA,sha256=p7N_7W876IqUUAqgllMzYDrKisvxTAPUmfib0G30Uwo,2887
374
- truefoundry-0.5.1rc7.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
375
- truefoundry-0.5.1rc7.dist-info/entry_points.txt,sha256=TXvUxQkI6zmqJuycPsyxEIMr3oqfDjgrWj0m_9X12x4,95
376
- truefoundry-0.5.1rc7.dist-info/RECORD,,
373
+ truefoundry-0.5.1rc8.dist-info/METADATA,sha256=0XwCMcuY2axlt1JUfIhogw1uNn0rRn0edV5HUigM6oc,2887
374
+ truefoundry-0.5.1rc8.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
375
+ truefoundry-0.5.1rc8.dist-info/entry_points.txt,sha256=TXvUxQkI6zmqJuycPsyxEIMr3oqfDjgrWj0m_9X12x4,95
376
+ truefoundry-0.5.1rc8.dist-info/RECORD,,