plash-cli 0.3.1__tar.gz → 0.3.2__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plash_cli
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Summary: CLI for the Plash hosting service
5
5
  Home-page: https://github.com/AnswerDotAI/plash_cli
6
6
  Author: Jeremy Howard
@@ -0,0 +1 @@
1
+ __version__ = "0.3.2"
@@ -32,7 +32,10 @@ def _get_client(cookie_file):
32
32
  return client
33
33
 
34
34
  # %% ../nbs/00_cli.ipynb 8
35
- def _mk_auth_req(url:str, method:str='get', **kwargs): return getattr(_get_client(PLASH_CONFIG_HOME), method)(url, **kwargs)
35
+ def _mk_auth_req(url:str, method:str='get', **kwargs):
36
+ r = getattr(_get_client(PLASH_CONFIG_HOME), method)(url, **kwargs)
37
+ if r.status_code == 200: return r
38
+ else: print(f'Failure: {r.headers["X-Plash-Error"]}')
36
39
 
37
40
  # %% ../nbs/00_cli.ipynb 9
38
41
  def _get_app_name(path:Path):
@@ -164,12 +167,11 @@ def deploy(
164
167
  plash_app.write_text(f'export PLASH_APP_NAME={name}')
165
168
 
166
169
  tarz, _ = create_tar_archive(path, force_data)
167
- resp = _mk_auth_req(_endpoint(rt="/upload"), "post", files={'file': tarz}, timeout=300.0,
168
- data={'name': name, 'force_data': force_data})
169
- if resp.status_code == 200:
170
+ r = _mk_auth_req(_endpoint(rt="/upload"), "post", files={'file': tarz}, timeout=300.0,
171
+ data={'name': name, 'force_data': force_data})
172
+ if r:
170
173
  print('✅ Upload complete! Your app is currently being built.')
171
174
  print(f'It will be live at {name if "." in name else _endpoint(sub=name)}')
172
- else: print(f'Failure: {resp.status_code}\n{resp.text}')
173
175
 
174
176
  # %% ../nbs/00_cli.ipynb 27
175
177
  @call_parse
@@ -198,24 +200,21 @@ def delete(
198
200
  return
199
201
 
200
202
  print(f"Deleting app '{name}'...")
201
- r = _mk_auth_req(_endpoint(rt=f"/delete?name={name}"), "delete")
202
- return r.text
203
+ if r := _mk_auth_req(_endpoint(rt=f"/delete?name={name}"), "delete"): return r.text
203
204
 
204
205
  # %% ../nbs/00_cli.ipynb 33
205
206
  @call_parse
206
207
  def start(path:Path=Path('.'), name:str=None):
207
208
  "Start your deployed app"
208
209
  if not name: name = _get_app_name(path)
209
- r = _mk_auth_req(_endpoint(rt=f"/start?name={name}"))
210
- return r.text
210
+ if r := _mk_auth_req(_endpoint(rt=f"/start?name={name}")): return r.text
211
211
 
212
212
  # %% ../nbs/00_cli.ipynb 36
213
213
  @call_parse
214
214
  def stop(path:Path=Path('.'), name:str=None):
215
215
  "Stop your deployed app"
216
216
  if not name: name = _get_app_name(path)
217
- r = _mk_auth_req(_endpoint(rt=f"/stop?name={name}"))
218
- return r.text
217
+ if r := _mk_auth_req(_endpoint(rt=f"/stop?name={name}")): return r.text
219
218
 
220
219
  # %% ../nbs/00_cli.ipynb 39
221
220
  log_modes = str_enum('log_modes', 'build', 'app')
@@ -233,18 +232,13 @@ def logs(
233
232
  text = ''
234
233
  while True:
235
234
  try:
236
- r = _mk_auth_req(_endpoint(rt=f"/logs?name={name}&mode={mode}"))
237
- if r.status_code == 200:
235
+ if r := _mk_auth_req(_endpoint(rt=f"/logs?name={name}&mode={mode}")):
238
236
  print(r.text[len(text):], end='') # Only print updates
239
237
  text = r.text
240
238
  if mode == 'build' and 'Build End Time:' in r.text: break
241
239
  sleep(1)
242
- else:
243
- print(f"Error: {r.status_code}")
244
- except KeyboardInterrupt:
245
- return "\nExiting"
246
- r = _mk_auth_req(endpoint(rt=f"/logs?name={name}&mode={mode}"))
247
- return r.text
240
+ except KeyboardInterrupt: return "\nExiting"
241
+ if r := _mk_auth_req(_endpoint(rt=f"/logs?name={name}&mode={mode}")): return r.text
248
242
 
249
243
  # %% ../nbs/00_cli.ipynb 43
250
244
  @call_parse
@@ -257,17 +251,18 @@ def download(
257
251
  try: save_path.mkdir(exist_ok=False)
258
252
  except: print(f"ERROR: Save path ({save_path}) already exists. Please rename or delete this folder to avoid accidental overwrites.")
259
253
  else:
260
- response = mk_auth_req(_endpoint(rt=f'/download?name={name}')).raise_for_status()
261
- file_bytes = io.BytesIO(response.content)
262
- with tarfile.open(fileobj=file_bytes, mode="r:gz") as tar: tar.extractall(path=save_path)
263
- print(f"Downloaded your app to: {save_path}")
254
+ if r := _mk_auth_req(_endpoint(rt=f'/download?name={name}')):
255
+ file_bytes = io.BytesIO(r.content)
256
+ with tarfile.open(fileobj=file_bytes, mode="r:gz") as tar: tar.extractall(path=save_path)
257
+ print(f"Downloaded your app to: {save_path}")
264
258
 
265
259
  # %% ../nbs/00_cli.ipynb 46
266
260
  @call_parse
267
261
  def apps(verbose:bool=False):
268
262
  "List your deployed apps (verbose shows status table: 1=running, 0=stopped)"
269
- r = _mk_auth_req(_endpoint(rt="/user_apps")).raise_for_status()
270
- apps = r.json()
271
- if not apps: return "You don't have any deployed Plash apps."
272
- if verbose: [print(f"{a['running']} {a['name']}") for a in apps]
273
- else: [print(a['name']) for a in apps]
263
+ r = _mk_auth_req(_endpoint(rt="/user_apps"))
264
+ if r:
265
+ apps = r.json()
266
+ if not apps: return "You don't have any deployed Plash apps."
267
+ if verbose: [print(f"{a['running']} {a['name']}") for a in apps]
268
+ else: [print(a['name']) for a in apps]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plash_cli
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Summary: CLI for the Plash hosting service
5
5
  Home-page: https://github.com/AnswerDotAI/plash_cli
6
6
  Author: Jeremy Howard
@@ -2,7 +2,7 @@
2
2
  jupyter_hooks = False
3
3
  repo = plash_cli
4
4
  lib_name = plash_cli
5
- version = 0.3.1
5
+ version = 0.3.2
6
6
  min_python = 3.11
7
7
  license = apache2
8
8
  black_formatting = False
@@ -1 +0,0 @@
1
- __version__ = "0.3.1"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes