Skip to content

Commit 3c08403

Browse files
authored
fix: replace questionary with rich-toolkit (#5460)
Signed-off-by: Frost Ming <[email protected]>
1 parent 822bd80 commit 3c08403

File tree

4 files changed

+33
-60
lines changed

4 files changed

+33
-60
lines changed

pdm.lock

Lines changed: 17 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ dependencies = [
6262
"tomli-w",
6363
"httpx-ws>=0.6.0",
6464
"aiosqlite>=0.20.0",
65-
"questionary>=2.0.1",
6665
"a2wsgi>=1.10.7",
6766
"fsspec>=2025.7.0",
67+
"rich-toolkit>=0.15.1",
6868
]
6969
dynamic = ["version"]
7070
[project.urls]

src/bentoml_cli/cloud.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ def cloud_command():
4949
)
5050
def login(endpoint: str, api_token: str) -> None: # type: ignore (not accessed)
5151
"""Login to BentoCloud."""
52-
import questionary
5352
from rich.prompt import Confirm
53+
from rich.prompt import Prompt
54+
from rich_toolkit.menu import Menu
5455

5556
if not api_token:
56-
choice = questionary.select(
57-
message="How would you like to authenticate BentoML CLI? [Use arrows to move]",
58-
choices=[
57+
choice = Menu(
58+
label="How would you like to authenticate BentoML CLI?",
59+
options=[
5960
{
6061
"name": "Create a new API token with a web browser",
6162
"value": "create",
@@ -104,9 +105,7 @@ def login(endpoint: str, api_token: str) -> None: # type: ignore (not accessed)
104105
)
105106
time.sleep(1)
106107
elif choice == "paste":
107-
api_token = click.prompt(
108-
"? Paste your API token", type=str, hide_input=True
109-
)
108+
api_token = Prompt.ask(":key: Paste your API token", password=True)
110109
try:
111110
cloud_rest_client = RestApiClient(endpoint, api_token)
112111
user = cloud_rest_client.v1.get_current_user()

src/bentoml_cli/deployment.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ def codespace(
261261
262262
$ bentoml code --attach <codespace-name>
263263
"""
264-
import questionary
264+
from rich.prompt import Prompt
265+
from rich_toolkit.menu import Menu
265266

266267
if attach and (env or secret):
267268
raise CLIException("Cannot specify both --attach and --env or --secret")
@@ -288,16 +289,16 @@ def codespace(
288289
]
289290
]
290291

291-
chosen = questionary.select(
292-
message="Select a codespace to attach to or create a new one",
293-
choices=[{"name": d.name, "value": d} for d in deployments]
292+
choice = Menu["t.Literal['new'] | Deployment"](
293+
label="Select a codespace to attach to or create a new one",
294+
options=[{"name": d.name, "value": d} for d in deployments]
294295
+ [{"name": "Create a new codespace", "value": "new"}],
295296
).ask()
296297

297-
if chosen == "new":
298-
name = questionary.text(
298+
if choice == "new":
299+
name = Prompt.ask(
299300
"Enter a name for the new codespace, or leave it blank to get a random name derived from the service"
300-
).ask()
301+
)
301302
deployment = create_deployment(
302303
bento=bento_dir,
303304
name=name or None,
@@ -307,14 +308,12 @@ def codespace(
307308
env=env,
308309
secret=secret,
309310
)
310-
elif chosen is None:
311-
return
312311
else:
313312
if env or secret:
314313
rich.print(
315314
"[yellow]Warning:[/] --env and --secret are ignored when attaching to an existing codespace"
316315
)
317-
deployment = t.cast(Deployment, chosen)
316+
deployment = choice
318317
deployment.watch(bento_dir)
319318

320319

0 commit comments

Comments
 (0)