2
2
3
3
import asyncio
4
4
import json
5
- import re
6
5
import subprocess # noqa: S404
7
6
import sys
8
- from dataclasses import dataclass
9
7
from enum import Enum
10
- from textwrap import dedent
11
8
from typing import TYPE_CHECKING
12
9
from urllib .parse import urljoin , urlparse
13
10
14
11
import click
15
12
import gql
16
13
import websockets .client as websockets
17
- from typing_extensions import Self
18
14
19
15
from latch .utils import current_workspace
20
16
from latch_sdk_config .latch import NUCLEUS_URL
@@ -54,24 +50,6 @@ class InstanceSize(str, Enum):
54
50
# g6e_48xlarge_task = "g6e_48xlarge_task"
55
51
56
52
57
- @dataclass
58
- class ImageInfo :
59
- image : str
60
- version : str
61
-
62
- __expr = re .compile (
63
- r"^(?:812206152185.dkr.ecr.us-west-2.amazonaws.com/)?(?P<image>[^:]+):(?P<version>[^:]+)"
64
- )
65
-
66
- @classmethod
67
- def from_str (cls , image_str : str ) -> Self :
68
- match = cls .__expr .match (image_str )
69
- if match is None :
70
- raise ValueError (f"invalid image name: { image_str } " )
71
-
72
- return cls (match ["image" ], match ["version" ])
73
-
74
-
75
53
def workflow_name (pkg_root : Path ) -> str :
76
54
name_path = pkg_root / latch_constants .pkg_workflow_name
77
55
if not name_path .exists ():
@@ -84,7 +62,7 @@ def workflow_name(pkg_root: Path) -> str:
84
62
return name_path .read_text ().strip ()
85
63
86
64
87
- def get_image_name (pkg_root : Path ) -> str :
65
+ def get_image (pkg_root : Path ) -> str :
88
66
ws_id = current_workspace ()
89
67
wf_name = workflow_name (pkg_root )
90
68
@@ -99,7 +77,7 @@ def get_image_name(pkg_root: Path) -> str:
99
77
return f"{ prefix } _{ suffix } "
100
78
101
79
102
- def get_image_info (pkg_root : Path ) -> ImageInfo :
80
+ def get_latest_registered_version (pkg_root : Path ) -> str :
103
81
ws_id = current_workspace ()
104
82
105
83
wf_name = workflow_name (pkg_root )
@@ -127,9 +105,7 @@ def get_image_info(pkg_root: Path) -> ImageInfo:
127
105
)
128
106
raise click .exceptions .Exit (1 )
129
107
130
- latest_version = res ["nodes" ][0 ]["version" ]
131
-
132
- return ImageInfo (get_image_name (pkg_root ), latest_version )
108
+ return res ["nodes" ][0 ]["version" ]
133
109
134
110
135
111
async def rsync (pkg_root : Path , ip : str ):
@@ -151,7 +127,6 @@ async def rsync(pkg_root: Path, ip: str):
151
127
stderr = subprocess .DEVNULL ,
152
128
)
153
129
154
- # todo(ayush): use inotify or something instead of running on a fixed interval
155
130
await asyncio .sleep (0.5 )
156
131
157
132
@@ -264,7 +239,6 @@ def local_development(
264
239
* ,
265
240
size : InstanceSize ,
266
241
skip_confirm_dialog : bool ,
267
- image : str | None ,
268
242
wf_version : str | None ,
269
243
disable_sync : bool ,
270
244
):
@@ -283,15 +257,13 @@ def local_development(
283
257
)
284
258
raise click .exceptions .Exit (1 ) from e
285
259
286
- if image is not None :
287
- image_info = ImageInfo .from_str (image )
288
- elif wf_version is not None :
289
- image_info = ImageInfo (get_image_name (pkg_root ), wf_version )
290
- else :
291
- image_info = get_image_info (pkg_root )
260
+ image = get_image (pkg_root )
261
+ if wf_version is None :
262
+ wf_version = get_latest_registered_version (pkg_root )
292
263
293
264
click .secho ("Initiating local development session" , fg = "blue" )
294
- click .echo (click .style ("Selected image: " , fg = "blue" ) + image_info .image )
265
+ click .echo (click .style ("Selected image: " , fg = "blue" ) + image )
266
+ click .echo (click .style ("Selected version: " , fg = "blue" ) + wf_version )
295
267
click .echo (click .style ("Selected instance size: " , fg = "blue" ) + size )
296
268
297
269
if skip_confirm_dialog :
@@ -307,12 +279,5 @@ def local_development(
307
279
)
308
280
309
281
asyncio .run (
310
- session (
311
- pkg_root ,
312
- image_info .image ,
313
- image_info .version ,
314
- ssh .public_key ,
315
- size ,
316
- disable_sync ,
317
- )
282
+ session (pkg_root , image , wf_version , ssh .public_key , size , disable_sync )
318
283
)
0 commit comments