Skip to content

Commit 0fc5711

Browse files
authored
fix: accept bento type as the bento argument for deployment APIs (#5385)
1 parent dce5d3a commit 0fc5711

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

src/_bentoml_sdk/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from .decorators import api, on_shutdown, on_startup, asgi_app, on_deployment, task
1818
from .service import get_current_service
1919
from .service import depends
20+
from .service.dependency import Dependency
2021
from .service import Service, ServiceConfig
2122
from .service import service
2223
from .service import runner_service
@@ -38,6 +39,7 @@ def mount_asgi_app(
3839
"on_shutdown",
3940
"on_startup",
4041
"on_deployment",
42+
"Dependency",
4143
"asgi_app",
4244
"mount_asgi_app",
4345
"depends",

src/bentoml/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"api": "_bentoml_sdk:api",
5353
"task": "_bentoml_sdk:task",
5454
"depends": "_bentoml_sdk:depends",
55+
"Dependency": "_bentoml_sdk:Dependency",
5556
"on_shutdown": "_bentoml_sdk:on_shutdown",
5657
"on_startup": "_bentoml_sdk:on_startup",
5758
"on_deployment": "_bentoml_sdk:on_deployment",
@@ -144,6 +145,7 @@
144145
from _bentoml_impl.client import AsyncHTTPClient
145146
from _bentoml_impl.client import SyncHTTPClient
146147
from _bentoml_impl.loader import importing
148+
from _bentoml_sdk import Dependency
147149
from _bentoml_sdk import IODescriptor
148150
from _bentoml_sdk import Service
149151
from _bentoml_sdk import api
@@ -385,6 +387,7 @@ def __getattr__(name: str) -> Any:
385387
"on_startup",
386388
"on_deployment",
387389
"depends",
390+
"Dependency",
388391
"IODescriptor",
389392
"validators",
390393
"Field",

src/bentoml/deployment.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from simple_di import Provide
1111
from simple_di import inject
1212

13+
from ._internal.bento import Bento
1314
from ._internal.cloud.deployment import Deployment
1415
from ._internal.cloud.deployment import DeploymentConfigParameters
1516
from ._internal.cloud.schemas.modelschemas import EnvItemSchema
@@ -21,13 +22,15 @@
2122
if t.TYPE_CHECKING:
2223
from ._internal.cloud import BentoCloudClient
2324

25+
BentoType = t.Union[str, Tag, Bento]
26+
2427

2528
@t.overload
2629
def create(
2730
name: str | None = ...,
2831
path_context: str | None = ...,
2932
*,
30-
bento: Tag | str | None = ...,
33+
bento: BentoType | None = ...,
3134
cluster: str | None = ...,
3235
access_authorization: bool | None = ...,
3336
scaling_min: int | None = ...,
@@ -44,7 +47,7 @@ def create(
4447
name: str | None = ...,
4548
path_context: str | None = ...,
4649
*,
47-
bento: Tag | str | None = ...,
50+
bento: BentoType | None = ...,
4851
config_file: str | None = ...,
4952
) -> Deployment: ...
5053

@@ -54,7 +57,7 @@ def create(
5457
name: str | None = ...,
5558
path_context: str | None = ...,
5659
*,
57-
bento: Tag | str | None = ...,
60+
bento: BentoType | None = ...,
5861
config_dict: dict[str, t.Any] | None = ...,
5962
) -> Deployment: ...
6063

@@ -64,7 +67,7 @@ def create(
6467
name: str | None = None,
6568
path_context: str | None = None,
6669
*,
67-
bento: Tag | str | None = None,
70+
bento: BentoType | None = None,
6871
cluster: str | None = None,
6972
access_authorization: bool | None = None,
7073
scaling_min: int | None = None,
@@ -85,7 +88,7 @@ def create(
8588
config_params = DeploymentConfigParameters(
8689
name=name,
8790
path_context=path_context,
88-
bento=bento,
91+
bento=bento.tag if isinstance(bento, Bento) else bento,
8992
cluster=cluster,
9093
access_authorization=access_authorization,
9194
scaling_max=scaling_max,
@@ -120,7 +123,7 @@ def update(
120123
context: str | None = ...,
121124
cluster: str | None = ...,
122125
*,
123-
bento: Tag | str | None = ...,
126+
bento: BentoType | None = ...,
124127
access_authorization: bool | None = ...,
125128
scaling_min: int | None = ...,
126129
scaling_max: int | None = ...,
@@ -139,7 +142,7 @@ def update(
139142
context: str | None = ...,
140143
cluster: str | None = None,
141144
*,
142-
bento: Tag | str | None = ...,
145+
bento: BentoType | None = ...,
143146
config_file: str | None = ...,
144147
) -> Deployment: ...
145148

@@ -151,7 +154,7 @@ def update(
151154
context: str | None = ...,
152155
cluster: str | None = None,
153156
*,
154-
bento: Tag | str | None = ...,
157+
bento: BentoType | None = ...,
155158
config_dict: dict[str, t.Any] | None = ...,
156159
) -> Deployment: ...
157160

@@ -162,7 +165,7 @@ def update(
162165
path_context: str | None = None,
163166
cluster: str | None = None,
164167
*,
165-
bento: Tag | str | None = None,
168+
bento: BentoType | None = None,
166169
access_authorization: bool | None = None,
167170
scaling_min: int | None = None,
168171
scaling_max: int | None = None,
@@ -183,7 +186,7 @@ def update(
183186
config_params = DeploymentConfigParameters(
184187
name=name,
185188
path_context=path_context,
186-
bento=bento,
189+
bento=bento.tag if isinstance(bento, Bento) else bento,
187190
cluster=cluster,
188191
access_authorization=access_authorization,
189192
scaling_max=scaling_max,
@@ -241,15 +244,15 @@ def apply(
241244
cluster: str | None = None,
242245
path_context: str | None = None,
243246
*,
244-
bento: Tag | str | None = None,
247+
bento: BentoType | None = None,
245248
config_dict: dict[str, t.Any] | None = None,
246249
config_file: str | None = None,
247250
_cloud_client: BentoCloudClient = Provide[BentoMLContainer.bentocloud_client],
248251
) -> Deployment:
249252
config_params = DeploymentConfigParameters(
250253
name=name,
251254
path_context=path_context,
252-
bento=bento,
255+
bento=bento.tag if isinstance(bento, Bento) else bento,
253256
cluster=cluster,
254257
config_dict=config_dict,
255258
config_file=config_file,

0 commit comments

Comments
 (0)