|
1 | | -import typing as t |
| 1 | +from __future__ import annotations |
| 2 | + |
2 | 3 | from typing import TYPE_CHECKING |
3 | 4 |
|
4 | | -from ..filesystem import calc_dir_size |
5 | 5 | from .schemas import BentoBuildEvent |
6 | 6 |
|
7 | 7 | if TYPE_CHECKING: |
|
11 | 11 | def _cli_bentoml_build_event( |
12 | 12 | cmd_group: str, |
13 | 13 | cmd_name: str, |
14 | | - return_value: "t.Optional[Bento]", |
| 14 | + return_value: Bento | None, |
15 | 15 | ) -> BentoBuildEvent: # pragma: no cover |
16 | | - if return_value is not None: |
17 | | - bento = return_value |
18 | | - return BentoBuildEvent( |
19 | | - cmd_group=cmd_group, |
20 | | - cmd_name=cmd_name, |
21 | | - bento_creation_timestamp=bento.info.creation_time, |
22 | | - bento_size_in_kb=calc_dir_size(bento.path_of("/")) / 1024, |
23 | | - model_size_in_kb=calc_dir_size(bento.path_of("/models")) / 1024, |
24 | | - num_of_models=len(bento.info.all_models), |
25 | | - num_of_runners=len(bento.info.runners), |
26 | | - model_types=[m.module for m in bento.info.all_models], |
27 | | - runnable_types=[r.runnable_type for r in bento.info.runners], |
28 | | - ) |
| 16 | + from ...bento.bento import BentoInfo |
| 17 | + from ...bento.bento import BentoInfoV2 |
| 18 | + |
| 19 | + if return_value is None: |
| 20 | + return BentoBuildEvent(cmd_group=cmd_group, cmd_name=cmd_name) |
| 21 | + bento = return_value |
| 22 | + total_size = bento.total_size() |
| 23 | + if isinstance(bento.info, BentoInfoV2): |
| 24 | + num_of_runners = len(bento.info.services) - 1 |
| 25 | + elif isinstance(bento.info, BentoInfo): |
| 26 | + num_of_runners = len(bento.info.runners) |
29 | 27 | else: |
30 | | - return BentoBuildEvent( |
31 | | - cmd_group=cmd_group, |
32 | | - cmd_name=cmd_name, |
33 | | - ) |
| 28 | + num_of_runners = 0 |
| 29 | + return BentoBuildEvent( |
| 30 | + cmd_group=cmd_group, |
| 31 | + cmd_name=cmd_name, |
| 32 | + bento_creation_timestamp=bento.info.creation_time, |
| 33 | + bento_size_in_kb=bento.file_size / 1024, |
| 34 | + model_size_in_kb=(total_size - bento.file_size) / 1024, |
| 35 | + num_of_models=len(bento.info.all_models), |
| 36 | + num_of_runners=num_of_runners, |
| 37 | + model_types=[m.module or "" for m in bento.info.all_models], |
| 38 | + ) |
34 | 39 |
|
35 | 40 |
|
36 | | -cli_events_map = {"cli": {"build": _cli_bentoml_build_event}} |
| 41 | +cli_events_map = {"bentos": {"build": _cli_bentoml_build_event}} |
0 commit comments