Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: name in bentofile.yaml #3604

Merged
merged 2 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/bentoml/_internal/bento/bento.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,19 @@ def create(
svc = import_service(
build_config.service, working_dir=build_ctx, standalone_load=True
)
# Apply default build options
build_config = build_config.with_defaults()

tag = Tag(svc.name, version)
bento_name = build_config.name if build_config.name is not None else svc.name
tag = Tag(bento_name, version)
if version is None:
tag = tag.make_new_version()

logger.info(
'Building BentoML service "%s" from build context "%s".', tag, build_ctx
)

bento_fs = fs.open_fs(f"temp://bentoml_bento_{svc.name}")
bento_fs = fs.open_fs(f"temp://bentoml_bento_{bento_name}")
ctx_fs = fs.open_fs(build_ctx)

models: t.Set[Model] = set()
Expand All @@ -208,8 +211,6 @@ def create(
logger.info('Packing model "%s"', model.tag)
model.save(bento_model_store)

# Apply default build options
build_config = build_config.with_defaults()
# create ignore specs
specs = BentoPathSpec(build_config.include, build_config.exclude) # type: ignore (unfinished attrs converter type)

Expand Down Expand Up @@ -410,7 +411,6 @@ def from_bento_model(cls, bento_model: Model) -> BentoModelInfo:

@attr.frozen(repr=False)
class BentoInfo:

# for backward compatibility in case new fields are added to BentoInfo.
__forbid_extra_keys__ = False
# omit field in yaml file if it is not provided by the user.
Expand Down
4 changes: 4 additions & 0 deletions src/bentoml/_internal/bento/build_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ class BentoBuildConfig:
__omit_if_default__ = False

service: str
name: t.Optional[str] = None
description: t.Optional[str] = None
labels: t.Optional[t.Dict[str, t.Any]] = None
include: t.Optional[t.List[str]] = None
Expand All @@ -748,6 +749,7 @@ class BentoBuildConfig:
def __init__(
self,
service: str,
name: str | None = ...,
description: str | None = ...,
labels: dict[str, t.Any] | None = ...,
include: list[str] | None = ...,
Expand Down Expand Up @@ -804,6 +806,7 @@ def with_defaults(self) -> FilledBentoBuildConfig:
"""
return FilledBentoBuildConfig(
self.service,
self.name,
self.description,
{} if self.labels is None else self.labels,
["*"] if self.include is None else self.include,
Expand Down Expand Up @@ -883,6 +886,7 @@ def from_path(self, path: str) -> t.Generator[t.Tuple[str, PathSpec], None, None

class FilledBentoBuildConfig(BentoBuildConfig):
service: str
name: t.Optional[str]
description: t.Optional[str]
labels: t.Dict[str, t.Any]
include: t.List[str]
Expand Down
30 changes: 16 additions & 14 deletions src/bentoml/bentos.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,16 @@ def pull(
def build(
service: str,
*,
labels: t.Optional[t.Dict[str, str]] = None,
description: t.Optional[str] = None,
include: t.Optional[t.List[str]] = None,
exclude: t.Optional[t.List[str]] = None,
docker: t.Optional[t.Dict[str, t.Any]] = None,
python: t.Optional[t.Dict[str, t.Any]] = None,
conda: t.Optional[t.Dict[str, t.Any]] = None,
version: t.Optional[str] = None,
build_ctx: t.Optional[str] = None,
name: str | None = None,
labels: dict[str, str] | None = None,
description: str | None = None,
include: list[str] | None = None,
exclude: list[str] | None = None,
docker: dict[str, t.Any] | None = None,
python: dict[str, t.Any] | None = None,
conda: dict[str, t.Any] | None = None,
version: str | None = None,
build_ctx: str | None = None,
_bento_store: BentoStore = Provide[BentoMLContainer.bento_store],
) -> "Bento":
"""
Expand All @@ -282,15 +283,15 @@ def build(
labels: optional immutable labels for carrying contextual info
description: optional description string in markdown format
include: list of file paths and patterns specifying files to include in Bento,
default is all files under build_ctx, beside the ones excluded from the
exclude parameter or a :code:`.bentoignore` file for a given directory
default is all files under build_ctx, beside the ones excluded from the
exclude parameter or a :code:`.bentoignore` file for a given directory
exclude: list of file paths and patterns to exclude from the final Bento archive
docker: dictionary for configuring Bento's containerization process, see details
in :class:`bentoml._internal.bento.build_config.DockerOptions`
in :class:`bentoml._internal.bento.build_config.DockerOptions`
python: dictionary for configuring Bento's python dependencies, see details in
:class:`bentoml._internal.bento.build_config.PythonOptions`
:class:`bentoml._internal.bento.build_config.PythonOptions`
conda: dictionary for configuring Bento's conda dependencies, see details in
:class:`bentoml._internal.bento.build_config.CondaOptions`
:class:`bentoml._internal.bento.build_config.CondaOptions`
version: Override the default auto generated version str
build_ctx: Build context directory, when used as
_bento_store: save Bento created to this BentoStore
Expand Down Expand Up @@ -335,6 +336,7 @@ def build(
"""
build_config = BentoBuildConfig(
service=service,
name=name,
description=description,
labels=labels,
include=include,
Expand Down