Skip to content

Commit 20a4407

Browse files
authored
feat: support --name option for bentoml build and bentoml code (#5297)
Signed-off-by: Frost Ming <me@frostming.com>
1 parent 81ba376 commit 20a4407

File tree

5 files changed

+21
-15
lines changed

5 files changed

+21
-15
lines changed

src/bentoml/_internal/bento/build_config.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import psutil
1818
import yaml
1919
from pathspec import PathSpec
20-
from typing_extensions import NotRequired
21-
from typing_extensions import TypedDict
2220

2321
from ...exceptions import BentoMLException
2422
from ...exceptions import InvalidArgument
@@ -48,11 +46,6 @@
4846
logger = logging.getLogger(__name__)
4947

5048

51-
class EnvironmentEntry(TypedDict):
52-
name: str
53-
value: NotRequired[str]
54-
55-
5649
# Docker defaults
5750
DEFAULT_CUDA_VERSION = "11.6.2"
5851
DEFAULT_CONTAINER_DISTRO = "debian"

src/bentoml/bentos.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import logging
88
import typing as t
99

10+
import attr
1011
from simple_di import Provide
1112
from simple_di import inject
1213

@@ -25,9 +26,9 @@
2526
from _bentoml_sdk import Service as NewService
2627

2728
from ._internal.bento import BentoStore
29+
from ._internal.bento.build_config import BentoEnvSchema
2830
from ._internal.bento.build_config import CondaOptions
2931
from ._internal.bento.build_config import DockerOptions
30-
from ._internal.bento.build_config import EnvironmentEntry
3132
from ._internal.bento.build_config import ModelSpec
3233
from ._internal.bento.build_config import PythonOptions
3334
from ._internal.cloud import BentoCloudClient
@@ -279,7 +280,7 @@ def build(
279280
description: str | None = None,
280281
include: t.List[str] | None = None,
281282
exclude: t.List[str] | None = None,
282-
envs: t.List[EnvironmentEntry] | None = None,
283+
envs: t.List[BentoEnvSchema] | None = None,
283284
docker: DockerOptions | dict[str, t.Any] | None = None,
284285
python: PythonOptions | dict[str, t.Any] | None = None,
285286
conda: CondaOptions | dict[str, t.Any] | None = None,
@@ -378,6 +379,7 @@ def build_bentofile(
378379
bentofile: str | None = None,
379380
*,
380381
service: str | None = None,
382+
name: str | None = None,
381383
version: str | None = None,
382384
labels: dict[str, str] | None = None,
383385
build_ctx: str | None = None,
@@ -421,10 +423,14 @@ def build_bentofile(
421423
else:
422424
build_config = BentoBuildConfig(service=service or "")
423425

426+
new_attrs = {}
427+
if name is not None:
428+
new_attrs["name"] = name
424429
if labels:
425-
if not build_config.labels:
426-
object.__setattr__(build_config, "labels", labels)
427-
build_config.labels.update(labels)
430+
new_attrs["labels"] = {**(build_config.labels or {}), **labels}
431+
432+
if new_attrs:
433+
build_config = attr.evolve(build_config, **new_attrs)
428434

429435
bento = Bento.create(
430436
build_config=build_config,

src/bentoml_cli/bentos.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ def push(
362362
@click.option(
363363
"-f", "--bentofile", help="Path to bentofile. Default to 'bentofile.yaml'"
364364
)
365+
@click.option("--name", help="Bento name")
365366
@click.option(
366367
"--version",
367368
type=click.STRING,
@@ -412,6 +413,7 @@ def push(
412413
def build( # type: ignore (not accessed)
413414
build_ctx: str,
414415
bentofile: str | None,
416+
name: str | None,
415417
version: str | None,
416418
labels: tuple[str, ...],
417419
output: t.Literal["tag", "default"],
@@ -442,6 +444,7 @@ def build( # type: ignore (not accessed)
442444
bento = build_bentofile(
443445
bentofile,
444446
service=service,
447+
name=name,
445448
version=version,
446449
labels=labels_dict or None,
447450
build_ctx=build_ctx,

src/bentoml_cli/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ def create_bentoml_cli() -> click.Command:
1010
from bentoml_cli.bentos import bento_command
1111
from bentoml_cli.cloud import cloud_command
1212
from bentoml_cli.containerize import containerize_command
13+
from bentoml_cli.deployment import codespace
1314
from bentoml_cli.deployment import deploy_command
1415
from bentoml_cli.deployment import deployment_command
15-
from bentoml_cli.deployment import develop_command
1616
from bentoml_cli.env import env_command
1717
from bentoml_cli.models import model_command
1818
from bentoml_cli.secret import secret_command
@@ -47,7 +47,7 @@ def bentoml_cli():
4747
bentoml_cli.add_subcommands(serve_command)
4848
bentoml_cli.add_command(containerize_command)
4949
bentoml_cli.add_command(deploy_command)
50-
bentoml_cli.add_command(develop_command)
50+
bentoml_cli.add_command(codespace)
5151
bentoml_cli.add_command(deployment_command)
5252
bentoml_cli.add_command(secret_command)
5353
# Load commands from extensions

src/bentoml_cli/deployment.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def decorate(f: t.Callable[..., t.Any]) -> t.Callable[..., t.Any]:
240240
)
241241
@shared_decorator
242242
@inject
243-
def develop_command(
243+
def codespace(
244244
bento_dir: str,
245245
cluster: str | None,
246246
attach: str | None,
@@ -292,8 +292,12 @@ def develop_command(
292292
).ask()
293293

294294
if chosen == "new":
295+
name = questionary.text(
296+
"Enter a name for the new codespace, or leave it blank to get a random name derived from the service"
297+
).ask()
295298
deployment = create_deployment(
296299
bento=bento_dir,
300+
name=name or None,
297301
cluster=cluster,
298302
dev=True,
299303
wait=False,

0 commit comments

Comments
 (0)