Skip to content

Commit 4facbe8

Browse files
committed
fixes #70
1 parent 4a53813 commit 4facbe8

2 files changed

Lines changed: 32 additions & 35 deletions

File tree

‎nbs/00_cli.ipynb‎

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@
190190
" while time()-start < timeout:\n",
191191
" resp = client.get(url).raise_for_status()\n",
192192
" if resp.text.strip(): return dict(client.cookies)\n",
193-
" sleep(interval)\n",
194-
" "
193+
" sleep(interval)"
195194
]
196195
},
197196
{
@@ -213,7 +212,7 @@
213212
" return print(PLASH_CONFIG_HOME.read_json().get(\"session_\", \"\"), end='')\n",
214213
" if token:\n",
215214
" PLASH_CONFIG_HOME.write_text(json.dumps({\"session_\": token.strip()}))\n",
216-
" return print(f\"Token saved to {PLASH_CONFIG_HOME}\")\n",
215+
" return f\"Token saved to {PLASH_CONFIG_HOME}\"\n",
217216
" paircode = secrets.token_urlsafe(16)\n",
218217
" login_url = httpx.get(_endpoint(rt=f\"/cli_login?paircode={paircode}\")).text\n",
219218
" print(f\"Opening browser for authentication:\\n{login_url}\\n\")\n",
@@ -222,8 +221,8 @@
222221
" cookies = _poll_cookies(paircode)\n",
223222
" if cookies:\n",
224223
" PLASH_CONFIG_HOME.write_text(json.dumps(cookies))\n",
225-
" print(f\"Authentication successful! Config saved to {PLASH_CONFIG_HOME}\")\n",
226-
" else: print(\"Authentication timed out.\")"
224+
" return f\"Authentication successful! Config saved to {PLASH_CONFIG_HOME}\"\n",
225+
" else: return \"Authentication timed out.\""
227226
]
228227
},
229228
{
@@ -284,7 +283,7 @@
284283
"#| export\n",
285284
"pat = r'(?m)^# /// (?P<type>[a-zA-Z0-9-]+)$\\s(?P<content>(^#(| .*)$\\s)+)^# ///$'\n",
286285
"\n",
287-
"def _deps(script: bytes | str) -> dict | None:\n",
286+
"def _deps(script: bytes | str):\n",
288287
" 'Get the dependencies from the script. From: https://peps.python.org/pep-0723/'\n",
289288
" name = 'script'\n",
290289
" if isinstance(script, bytes): script = script.decode('utf-8')\n",
@@ -418,8 +417,9 @@
418417
" r = _mk_auth_req(_endpoint(rt=\"/upload\"), \"post\", files={'file': tarz},\n",
419418
" data={'name': name, 'force_data': force_data})\n",
420419
" if r:\n",
421-
" print('✅ Upload complete! Your app is currently being built.')\n",
422-
" print(f'It will be live at {name if \".\" in name else _endpoint(sub=name)}')"
420+
" return ('✅ Upload complete! Your app is currently being built.\\n' +\n",
421+
" f'It will be live at {name if \".\" in name else _endpoint(sub=name)}')\n",
422+
" else: return 'Unknown failure'"
423423
]
424424
},
425425
{
@@ -794,11 +794,11 @@
794794
" text = ''\n",
795795
" while True:\n",
796796
" try:\n",
797-
" if r := _mk_auth_req(_endpoint(rt=f\"/logs?name={name}&mode={mode}\")):\n",
798-
" print(r.text[len(text):], end='') # Only print updates\n",
799-
" text = r.text\n",
800-
" if mode == 'build' and 'Build End Time:' in r.text: break\n",
801-
" sleep(1)\n",
797+
" r = _mk_auth_req(_endpoint(rt=f\"/logs?name={name}&mode={mode}\"))\n",
798+
" print(r.text[len(text):], end='') # Only print updates\n",
799+
" text = r.text\n",
800+
" if mode == 'build' and 'Build End Time:' in r.text: return\n",
801+
" sleep(1)\n",
802802
" except KeyboardInterrupt: return \"\\nExiting\"\n",
803803
" if r := _mk_auth_req(_endpoint(rt=f\"/logs?name={name}&mode={mode}\")): return r.text"
804804
]
@@ -925,7 +925,7 @@
925925
" save_path.mkdir(exist_ok=True)\n",
926926
" if not save_path._is_dir_empty(): return print(f'ERROR: Save path ({save_path}) is not empty.')\n",
927927
" if r := _mk_auth_req(_endpoint(rt=f'/download?name={name}')):\n",
928-
" with tarfile.open(fileobj=io.BytesIO(r.content), mode=\"r:gz\") as tar: tar.extractall(path=save_path)\n",
928+
" with tarfile.open(fileobj=io.BytesIO(r.content), mode=\"r:gz\") as tar: tar.extractall(path=save_path, filter='data')\n",
929929
" print(f\"Downloaded your app to: {save_path}\") "
930930
]
931931
},
@@ -1000,8 +1000,8 @@
10001000
" if r:\n",
10011001
" apps = r.json()\n",
10021002
" if not apps: return \"You don't have any deployed Plash apps.\"\n",
1003-
" if verbose: [print(f\"{a['running']} {a['name']}\") for a in apps]\n",
1004-
" else: [print(a['name']) for a in apps]"
1003+
" if verbose: return [(f\"{a['running']} {a['name']}\") for a in apps]\n",
1004+
" else: return [(a['name']) for a in apps]"
10051005
]
10061006
},
10071007
{
@@ -1066,10 +1066,7 @@
10661066
]
10671067
}
10681068
],
1069-
"metadata": {
1070-
"solveit_dialog_mode": "learning",
1071-
"solveit_ver": 2
1072-
},
1069+
"metadata": {},
10731070
"nbformat": 4,
10741071
"nbformat_minor": 5
10751072
}

‎plash_cli/cli.py‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ def _poll_cookies(paircode, interval=1, timeout=180):
7777
resp = client.get(url).raise_for_status()
7878
if resp.text.strip(): return dict(client.cookies)
7979
sleep(interval)
80-
8180

8281
# %% ../nbs/00_cli.ipynb 14
8382
@call_parse
@@ -91,7 +90,7 @@ def login(
9190
return print(PLASH_CONFIG_HOME.read_json().get("session_", ""), end='')
9291
if token:
9392
PLASH_CONFIG_HOME.write_text(json.dumps({"session_": token.strip()}))
94-
return print(f"Token saved to {PLASH_CONFIG_HOME}")
93+
return f"Token saved to {PLASH_CONFIG_HOME}"
9594
paircode = secrets.token_urlsafe(16)
9695
login_url = httpx.get(_endpoint(rt=f"/cli_login?paircode={paircode}")).text
9796
print(f"Opening browser for authentication:\n{login_url}\n")
@@ -100,13 +99,13 @@ def login(
10099
cookies = _poll_cookies(paircode)
101100
if cookies:
102101
PLASH_CONFIG_HOME.write_text(json.dumps(cookies))
103-
print(f"Authentication successful! Config saved to {PLASH_CONFIG_HOME}")
104-
else: print("Authentication timed out.")
102+
return f"Authentication successful! Config saved to {PLASH_CONFIG_HOME}"
103+
else: return "Authentication timed out."
105104

106105
# %% ../nbs/00_cli.ipynb 17
107106
pat = r'(?m)^# /// (?P<type>[a-zA-Z0-9-]+)$\s(?P<content>(^#(| .*)$\s)+)^# ///$'
108107

109-
def _deps(script: bytes | str) -> dict | None:
108+
def _deps(script: bytes | str):
110109
'Get the dependencies from the script. From: https://peps.python.org/pep-0723/'
111110
name = 'script'
112111
if isinstance(script, bytes): script = script.decode('utf-8')
@@ -171,8 +170,9 @@ def deploy(
171170
r = _mk_auth_req(_endpoint(rt="/upload"), "post", files={'file': tarz},
172171
data={'name': name, 'force_data': force_data})
173172
if r:
174-
print('✅ Upload complete! Your app is currently being built.')
175-
print(f'It will be live at {name if "." in name else _endpoint(sub=name)}')
173+
return ('✅ Upload complete! Your app is currently being built.\n' +
174+
f'It will be live at {name if "." in name else _endpoint(sub=name)}')
175+
else: return 'Unknown failure'
176176

177177
# %% ../nbs/00_cli.ipynb 26
178178
@call_parse
@@ -233,11 +233,11 @@ def logs(
233233
text = ''
234234
while True:
235235
try:
236-
if r := _mk_auth_req(_endpoint(rt=f"/logs?name={name}&mode={mode}")):
237-
print(r.text[len(text):], end='') # Only print updates
238-
text = r.text
239-
if mode == 'build' and 'Build End Time:' in r.text: break
240-
sleep(1)
236+
r = _mk_auth_req(_endpoint(rt=f"/logs?name={name}&mode={mode}"))
237+
print(r.text[len(text):], end='') # Only print updates
238+
text = r.text
239+
if mode == 'build' and 'Build End Time:' in r.text: return
240+
sleep(1)
241241
except KeyboardInterrupt: return "\nExiting"
242242
if r := _mk_auth_req(_endpoint(rt=f"/logs?name={name}&mode={mode}")): return r.text
243243

@@ -256,7 +256,7 @@ def download(
256256
save_path.mkdir(exist_ok=True)
257257
if not save_path._is_dir_empty(): return print(f'ERROR: Save path ({save_path}) is not empty.')
258258
if r := _mk_auth_req(_endpoint(rt=f'/download?name={name}')):
259-
with tarfile.open(fileobj=io.BytesIO(r.content), mode="r:gz") as tar: tar.extractall(path=save_path)
259+
with tarfile.open(fileobj=io.BytesIO(r.content), mode="r:gz") as tar: tar.extractall(path=save_path, filter='data')
260260
print(f"Downloaded your app to: {save_path}")
261261

262262
# %% ../nbs/00_cli.ipynb 48
@@ -267,5 +267,5 @@ def apps(verbose:bool=False):
267267
if r:
268268
apps = r.json()
269269
if not apps: return "You don't have any deployed Plash apps."
270-
if verbose: [print(f"{a['running']} {a['name']}") for a in apps]
271-
else: [print(a['name']) for a in apps]
270+
if verbose: return [(f"{a['running']} {a['name']}") for a in apps]
271+
else: return [(a['name']) for a in apps]

0 commit comments

Comments
 (0)