plash-cli 0.3.1__tar.gz → 0.3.3__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.3
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.3"
@@ -10,7 +10,8 @@ d = { 'settings': { 'branch': 'main',
10
10
  'plash_cli.auth._signin_url': ('auth.html#_signin_url', 'plash_cli/auth.py'),
11
11
  'plash_cli.auth.goog_id_from_signin_reply': ('auth.html#goog_id_from_signin_reply', 'plash_cli/auth.py'),
12
12
  'plash_cli.auth.mk_signin_url': ('auth.html#mk_signin_url', 'plash_cli/auth.py')},
13
- 'plash_cli.cli': { 'plash_cli.cli.PlashError': ('cli.html#plasherror', 'plash_cli/cli.py'),
13
+ 'plash_cli.cli': { 'plash_cli.cli.Path._is_dir_empty': ('cli.html#path._is_dir_empty', 'plash_cli/cli.py'),
14
+ 'plash_cli.cli.PlashError': ('cli.html#plasherror', 'plash_cli/cli.py'),
14
15
  'plash_cli.cli._deps': ('cli.html#_deps', 'plash_cli/cli.py'),
15
16
  'plash_cli.cli._endpoint': ('cli.html#_endpoint', 'plash_cli/cli.py'),
16
17
  'plash_cli.cli._gen_app_name': ('cli.html#_gen_app_name', 'plash_cli/cli.py'),
@@ -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', timeout=300., **kwargs):
36
+ r = getattr(_get_client(PLASH_CONFIG_HOME), method)(url, timeout=timeout, **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},
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,20 +232,19 @@ 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
- # %% ../nbs/00_cli.ipynb 43
243
+ # %% ../nbs/00_cli.ipynb 44
244
+ @patch
245
+ def _is_dir_empty(self:Path): return next(self.iterdir(), None) is None
246
+
247
+ # %% ../nbs/00_cli.ipynb 47
250
248
  @call_parse
251
249
  def download(
252
250
  path:Path=Path('.'), # Path to project
@@ -254,20 +252,19 @@ def download(
254
252
  save_path:Path=Path("./download/")): # Save path (optional)
255
253
  'Download your deployed app'
256
254
  if not name: name = _get_app_name(path)
257
- try: save_path.mkdir(exist_ok=False)
258
- except: print(f"ERROR: Save path ({save_path}) already exists. Please rename or delete this folder to avoid accidental overwrites.")
259
- 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}")
255
+ save_path.mkdir(exist_ok=True)
256
+ if not save_path._is_dir_empty(): return print(f'ERROR: Save path ({save_path}) is not empty.')
257
+ if r := _mk_auth_req(_endpoint(rt=f'/download?name={name}')):
258
+ with tarfile.open(fileobj=io.BytesIO(r.content), mode="r:gz") as tar: tar.extractall(path=save_path)
259
+ print(f"Downloaded your app to: {save_path}")
264
260
 
265
- # %% ../nbs/00_cli.ipynb 46
261
+ # %% ../nbs/00_cli.ipynb 50
266
262
  @call_parse
267
263
  def apps(verbose:bool=False):
268
264
  "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]
265
+ r = _mk_auth_req(_endpoint(rt="/user_apps"))
266
+ if r:
267
+ apps = r.json()
268
+ if not apps: return "You don't have any deployed Plash apps."
269
+ if verbose: [print(f"{a['running']} {a['name']}") for a in apps]
270
+ 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.3
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.3
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