Repository: bentoml/BentoML
Pull request #4372 (2023-12-28 09:02:39)

chore(bento.yaml): move fields into services


Patch:
diff --git a/src/bentoml/_internal/bento/bento.py b/src/bentoml/_internal/bento/bento.py
index 56b2605e..e52ecbc0 100644
--- a/src/bentoml/_internal/bento/bento.py
+++ b/src/bentoml/_internal/bento/bento.py
@@ -48,7 +48,6 @@ if TYPE_CHECKING:
     from fs.base import FS
 
     from _bentoml_sdk import Service as NewService
-    from _bentoml_sdk.api import APIMethod
     from _bentoml_sdk.service import ServiceConfig
 
     from ..models import Model
@@ -301,16 +300,18 @@ class Bento(StoreItem):
                         m, alias=resolved_aliases.get(m.tag)
                     )
                     for m in models
-                ],
-                config=svc.all_config() if not is_legacy else {},
-                runners=[BentoRunnerInfo.from_runner(r) for r in svc.runners]
+                ]
+                if is_legacy
+                else [],
+                runners=[BentoRunnerInfo.from_runner(r) for r in svc.runners]  # type: ignore # attrs converters do not typecheck
                 if is_legacy
                 else [],
                 apis=[BentoApiInfo.from_inference_api(api) for api in svc.apis.values()]
                 if is_legacy
-                else [BentoApiInfo.from_api_method(api) for api in svc.apis.values()],
-                services=[
-                    BentoDependencyInfo.from_dependency(d.on, seen={svc.name})
+                else [],
+                services=[BentoServiceInfo.from_service(svc)]
+                + [
+                    BentoServiceInfo.from_service(d.on, seen={svc.name})
                     for d in svc.dependencies.values()
                 ]
                 if not is_legacy
@@ -505,14 +506,6 @@ class BentoApiInfo:
             output_type=api.output.__class__.__name__,
         )
 
-    @classmethod
-    def from_api_method(cls, api: APIMethod[..., t.Any]) -> BentoApiInfo:
-        return cls(
-            name=api.name,
-            input_type=api.input_spec.__name__,
-            output_type=api.output_spec.__name__,
-        )
-
 
 @attr.frozen
 class BentoModelInfo:
@@ -534,16 +527,17 @@ class BentoModelInfo:
 
 
 @attr.frozen
-class BentoDependencyInfo:
+class BentoServiceInfo:
     name: str
     service: str
     models: t.List[BentoModelInfo] = attr.field(factory=list)
-    services: t.List[BentoDependencyInfo] = attr.field(factory=list)
+    dependencies: t.List[str] = attr.field(factory=list)
+    config: ServiceConfig = attr.field(factory=dict)
 
     @classmethod
-    def from_dependency(
+    def from_service(
         cls, d: NewService[t.Any], seen: set[str] | None = None
-    ) -> BentoDependencyInfo:
+    ) -> BentoServiceInfo:
         if seen is None:
             seen = set()
         if (name := d.name) in seen:
@@ -552,10 +546,8 @@ class BentoDependencyInfo:
             name=name,
             service=d.import_string,
             models=[BentoModelInfo.from_bento_model(m) for m in d.models],
-            services=[
-                cls.from_dependency(dep.on, seen=seen | {name})
-                for dep in d.dependencies.values()
-            ],
+            dependencies=list(d.dependencies.keys()),
+            config=d.config,
         )
 
 
@@ -590,8 +582,7 @@ class BentoInfo:
     models: t.List[BentoModelInfo] = attr.field(factory=list)
     runners: t.List[BentoRunnerInfo] = attr.field(factory=list)
     # for BentoML 1.2+ SDK
-    services: t.List[BentoDependencyInfo] = attr.field(factory=list)
-    config: ServiceConfig = attr.field(factory=dict)
+    services: t.List[BentoServiceInfo] = attr.field(factory=list)
     apis: t.List[BentoApiInfo] = attr.field(factory=list)
     docker: DockerOptions = attr.field(factory=lambda: DockerOptions().with_defaults())
     python: PythonOptions = attr.field(factory=lambda: PythonOptions().with_defaults())
diff --git a/src/bentoml/_internal/cloud/bentocloud.py b/src/bentoml/_internal/cloud/bentocloud.py
index b28ff735..184c0a20 100644
--- a/src/bentoml/_internal/cloud/bentocloud.py
+++ b/src/bentoml/_internal/cloud/bentocloud.py
@@ -169,7 +169,7 @@ class BentoCloudClient(CloudClient):
             models=models,
             runners=runners,
             size_bytes=bento.total_size(),
-            config=info.config,
+            config=info.config,  # TODO(fog)
         )
         if not remote_bento:
             with self.spin(


Test patch:
diff --git a/tests/unit/_internal/bento/test_bento.py b/tests/unit/_internal/bento/test_bento.py
index 7d2f3aaf..137ea7c5 100644
--- a/tests/unit/_internal/bento/test_bento.py
+++ b/tests/unit/_internal/bento/test_bento.py
@@ -102,7 +102,6 @@ runners:
   resource_config:
     cpu: 2
 services: []
-config: {{}}
 apis:
 - name: predict
   input_type: NumpyNdarray