33# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_core.ipynb.
44
55# %% auto 0
6- __all__ = ['PLASH_CONFIG_HOME' , 'PLASH_DOMAIN' , 'pat' , 'stop ' , 'start ' , 'log_modes ' , 'get_client' , 'mk_auth_req' , 'get_app_id' ,
6+ __all__ = ['PLASH_CONFIG_HOME' , 'PLASH_DOMAIN' , 'pat' , 'log_modes ' , 'stop ' , 'start ' , 'get_client' , 'mk_auth_req' , 'get_app_id' ,
77 'endpoint' , 'is_included' , 'poll_cookies' , 'login' , 'PlashError' , 'validate_app' , 'create_tar_archive' ,
88 'deploy' , 'view' , 'delete' , 'endpoint_func' , 'logs' , 'download' ]
99
1414from pathlib import Path
1515from uuid import uuid4
1616from time import time , sleep
17+ import threading
1718
1819import io , os , re , tarfile , tomllib
1920
@@ -121,6 +122,20 @@ def create_tar_archive(path:Path) -> tuple[io.BytesIO, int]:
121122 return tarz , len (files )
122123
123124# %% ../nbs/00_core.ipynb 24
125+ log_modes = str_enum ('log_modes' , 'build' , 'app' )
126+
127+ # %% ../nbs/00_core.ipynb 25
128+ def _logs_during_deploy (
129+ path :Path , # Path to project
130+ mode :str = 'build' , # 'build' or 'run'
131+ tail :bool = True ): # We always want to tail the logs
132+ # Give the server time to start
133+ sleep (1 )
134+ # Unwrap the logs function to avoid the call_parse decorator so it can be wrapped in a thread
135+ log_thread = threading .Thread (target = logs .__wrapped__ , kwargs = dict (path = path , mode = 'build' , tail = True ))
136+ log_thread .start ()
137+
138+ # %% ../nbs/00_core.ipynb 26
124139@call_parse
125140def deploy (
126141 path :Path = Path ('.' ), # Path to project
@@ -143,8 +158,9 @@ def deploy(
143158 print ('✅ Upload complete! Your app is currently being built.' )
144159 print (f'It will be live at { endpoint (sub = aid )} ' )
145160 else : print (f'Failure: { resp .status_code } \n { resp .text } ' )
161+ _logs_during_deploy (path = path , mode = 'build' , tail = True )
146162
147- # %% ../nbs/00_core.ipynb 26
163+ # %% ../nbs/00_core.ipynb 28
148164@call_parse
149165def view (
150166 path :Path = Path ('.' ), # Path to project
@@ -153,7 +169,7 @@ def view(
153169 print (f"Opening browser to view app :\n { url } \n " )
154170 webbrowser .open (url )
155171
156- # %% ../nbs/00_core.ipynb 28
172+ # %% ../nbs/00_core.ipynb 30
157173@call_parse
158174def delete (
159175 path :Path = Path ('.' ), # Path to project
@@ -170,7 +186,7 @@ def delete(
170186 r = mk_auth_req (endpoint (rt = f"/delete?aid={ aid } " ), "delete" )
171187 return r .text
172188
173- # %% ../nbs/00_core.ipynb 30
189+ # %% ../nbs/00_core.ipynb 32
174190def endpoint_func (endpoint_name ):
175191 'Creates a function for a specific API endpoint'
176192 @call_parse
@@ -191,10 +207,7 @@ def func(
191207stop = endpoint_func ('/stop' )
192208start = endpoint_func ('/start' )
193209
194- # %% ../nbs/00_core.ipynb 32
195- log_modes = str_enum ('log_modes' , 'build' , 'app' )
196-
197- # %% ../nbs/00_core.ipynb 33
210+ # %% ../nbs/00_core.ipynb 34
198211@call_parse
199212def logs (
200213 path :Path = Path ('.' ), # Path to project
@@ -218,7 +231,7 @@ def logs(
218231 r = mk_auth_req (endpoint (rt = f"/logs?aid={ aid } &mode={ mode } " ))
219232 return r .text
220233
221- # %% ../nbs/00_core.ipynb 35
234+ # %% ../nbs/00_core.ipynb 36
222235@call_parse
223236def download (
224237 path :Path = Path ('.' ), # Path to project
0 commit comments