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

chore: provides shim for bentoctl #3322

Merged
merged 3 commits into from Dec 7, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/bentoml/_internal/bento/gen.py
@@ -0,0 +1,39 @@
"""
This module is shim for bentoctl. NOT FOR DIRECT USE.
"""
from __future__ import annotations

import logging
import warnings
from typing import TYPE_CHECKING

import fs

from ..container.generate import generate_containerfile

if TYPE_CHECKING:
from .build_config import DockerOptions

__all__ = ["generate_dockerfile"]

logger = logging.getLogger(__name__)

warnings.warn(
"%s is deprecated. Make sure to use 'bentoml.container.build' and 'bentoml.container.health' instead."
% __name__,
DeprecationWarning,
stacklevel=4,
)


def generate_dockerfile(docker: DockerOptions, context_path: str, *, use_conda: bool):
from ..bento import Bento

bento = Bento.from_fs(fs.open_fs(context_path))
logger.debug("'use_conda' is deprecated and will not be used.")
return generate_containerfile(
docker,
bento.path,
conda=bento.info.conda,
bento_fs=bento._fs,
)
1 change: 1 addition & 0 deletions src/bentoml/_internal/container/base.py
Expand Up @@ -49,6 +49,7 @@ def construct_args(self, args: t.Any, opt: str = ""):

@construct_args.register(type(None))
@construct_args.register(tuple)
@construct_args.register(list)
def _(self, args: ArgType, opt: str = ""):
if args is not None:
self.extend(
Expand Down
2 changes: 1 addition & 1 deletion src/bentoml/_internal/container/generate.py
Expand Up @@ -113,7 +113,7 @@ def generate_containerfile(

.. note::

You should use ``construct_dockerfile`` instead of this function.
You should use ``construct_containerfile`` instead of this function.

Returns:
str: The rendered Dockerfile string.
Expand Down
38 changes: 38 additions & 0 deletions src/bentoml/_internal/utils/buildx.py
@@ -0,0 +1,38 @@
"""
This module is shim for bentoctl. NOT FOR DIRECT USE.
Make sure to use 'bentoml.container.build' and 'bentoml.container.health' instead.
"""

from __future__ import annotations

import typing as t
import warnings

from ..container import health as _internal_container_health
from ..container import get_backend

__all__ = ["build", "health"]

_buildx_backend = get_backend("buildx")

warnings.warn(
"%s is deprecated. Make sure to use 'bentoml.container.build' and 'bentoml.container.health' instead."
% __name__,
DeprecationWarning,
stacklevel=4,
)


def health():
return _internal_container_health("buildx")


def build(**kwargs: t.Any):
# subprocess_env from bentoctl will be handle by buildx, so it is safe to pop this out.
kwargs.pop("subprocess_env")
kwargs["tag"] = kwargs.pop("tags")
context_path = kwargs.pop("cwd", None)
for key, value in kwargs.items():
if not value:
kwargs[key] = None
_buildx_backend.build(context_path=context_path, **kwargs)
10 changes: 10 additions & 0 deletions src/bentoml_cli/utils.py
Expand Up @@ -114,6 +114,16 @@ def validate_container_tag(
raise BentoMLException(f"Invalid tag type. Got {type(tag)}")


# NOTE: shim for bentoctl
def validate_docker_tag(
ctx: Context, param: Parameter, tag: str | tuple[str] | None
) -> str | tuple[str] | None:
logger.warning(
"'validate_docker_tag' is now deprecated, use 'validate_container_tag' instead."
)
return validate_container_tag(ctx, param, tag)


class BentoMLCommandGroup(click.Group):
"""
Click command class customized for BentoML CLI, allow specifying a default
Expand Down