Skip to content

Commit

Permalink
fix object comparison
Browse files Browse the repository at this point in the history
Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming committed Sep 24, 2024
1 parent b206950 commit b643f4a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/bentoml/_internal/bento/bento.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from ..utils import encode_path_for_uri
from ..utils import normalize_labels_value
from .build_config import BentoBuildConfig
from .build_config import BentoEnvSchema
from .build_config import BentoPathSpec
from .build_config import CondaOptions
from .build_config import DockerOptions
Expand Down Expand Up @@ -680,7 +681,7 @@ class BentoInfo:
# for BentoML 1.2+ SDK
entry_service: str = attr.field(factory=str)
services: t.List[BentoServiceInfo] = attr.field(factory=list)
envs: t.List[t.Dict[str, str]] = attr.field(factory=list)
envs: t.List[BentoEnvSchema] = attr.field(factory=list)
schema: t.Dict[str, t.Any] = attr.field(factory=dict)

apis: t.List[BentoApiInfo] = attr.field(factory=list)
Expand Down
9 changes: 8 additions & 1 deletion src/bentoml/_internal/bento/build_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,13 @@ def _model_spec_structure_hook(
return cls.from_item(d)


@attr.define(eq=True)
class BentoEnvSchema:
__forbid_extra_keys__ = False
name: str
value: str = ""


bentoml_cattr.register_structure_hook(ModelSpec, _model_spec_structure_hook)


Expand Down Expand Up @@ -829,7 +836,7 @@ class BentoBuildConfig:
models: t.List[ModelSpec] = attr.field(
factory=list, converter=convert_models_config
)
envs: t.List[t.Dict[str, str]] = attr.field(factory=list)
envs: t.List[BentoEnvSchema] = attr.field(factory=list)

if t.TYPE_CHECKING:
# NOTE: This is to ensure that BentoBuildConfig __init__
Expand Down
19 changes: 2 additions & 17 deletions src/bentoml/_internal/cloud/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,9 +822,7 @@ def watch_filter(change: watchfiles.Change, path: str) -> bool:
if (
target is None
or target.bento is None
or not _is_bento_manifest_equal(
target.bento.manifest, bento_info.get_manifest()
)
or target.bento.manifest != bento_info.get_manifest()
):
console.print("✨ [green bold]Bento change detected[/]")
spinner.update("🔄 Pushing Bento to BentoCloud")
Expand Down Expand Up @@ -866,9 +864,7 @@ def watch_filter(change: watchfiles.Change, path: str) -> bool:
if (
target is None
or target.bento is None
or not _is_bento_manifest_equal(
target.bento.manifest, bento_info.get_manifest()
)
or target.bento.manifest != bento_info.get_manifest()
):
# stop log tail and reset the deployment
break
Expand Down Expand Up @@ -1377,14 +1373,3 @@ def _build_requirements_txt(bento_dir: str, config: BentoBuildConfig) -> bytes:
bentoml_requirement = f"-e ./{EDITABLE_BENTOML_DIR}"
content += f"{bentoml_requirement}\n".encode("utf8")
return content


def _is_bento_manifest_equal(
source: BentoManifestSchema, target: BentoManifestSchema
) -> bool:
source_data = bentoml_cattr.unstructure(source)
target_data = bentoml_cattr.unstructure(target)

config_merger.merge(source_data, target_data)
new_source = bentoml_cattr.structure(source_data, BentoManifestSchema)
return new_source == source
3 changes: 2 additions & 1 deletion src/bentoml/_internal/cloud/schemas/modelschemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import attr

from ...bento.bento import BentoServiceInfo
from ...bento.build_config import BentoEnvSchema
from ...cloud.schemas.utils import dict_options_converter
from ...tag import Tag

Expand Down Expand Up @@ -82,7 +83,7 @@ class BentoManifestSchema:
models: t.List[str] = attr.field(factory=list, eq=False)
runners: t.Optional[t.List[BentoRunnerSchema]] = attr.field(factory=list)
services: t.List[BentoServiceInfo] = attr.field(factory=dict)
envs: t.List[t.Dict[str, str]] = attr.field(factory=list)
envs: t.List[BentoEnvSchema] = attr.field(factory=list)
schema: t.Dict[str, t.Any] = attr.field(factory=dict)
version: t.Optional[str] = attr.field(default=None, eq=False)

Expand Down

0 comments on commit b643f4a

Please sign in to comment.