Skip to content

Commit

Permalink
--wip-- [skip ci]
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com>
  • Loading branch information
aarnphm committed Oct 26, 2022
1 parent 85e7fa3 commit 13d8d68
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/bentoml/_internal/utils/__init__.py
Expand Up @@ -69,22 +69,31 @@
_EXPERIMENTAL_APIS: set[str] = set()


def _warn_experimental(f: t.Any):
api_name = f.__name__ if inspect.isfunction(f) else repr(f)
def _warn_experimental(api_name: str) -> None:
if api_name not in _EXPERIMENTAL_APIS:
_EXPERIMENTAL_APIS.add(api_name)
msg = "'%s' is an EXPERIMENTAL API and is currently not yet stable. Proceed with caution!"
logger = logging.getLogger(f.__module__)
logger = logging.getLogger(__name__)
logger.warning(msg, api_name)


def experimental(f: t.Callable[P, t.Any]) -> t.Callable[P, t.Any]:
@functools.wraps(f)
def wrapper(*args: P.args, **kwargs: P.kwargs) -> t.Any:
_warn_experimental(f)
return f(*args, **kwargs)
def experimental(
f: t.Callable[P, t.Any] | None = None, *, api_name: str | None = None
) -> t.Callable[..., t.Any]:
if api_name is None:
api_name = f.__name__ if inspect.isfunction(f) else repr(f)

return wrapper
def decorator(func: t.Callable[..., t.Any]) -> t.Callable[P, t.Any]:
@functools.wraps(func)
def wrapper(*args: P.args, **kwargs: P.kwargs) -> t.Any:
_warn_experimental(api_name)
return func(*args, **kwargs)

return wrapper

if f is None:
return decorator
return decorator(f)


def add_experimental_docstring(f: t.Callable[P, t.Any]) -> t.Callable[P, t.Any]:
Expand Down
7 changes: 7 additions & 0 deletions src/bentoml/metrics.py
Expand Up @@ -7,6 +7,9 @@
from simple_di import inject
from simple_di import Provide

from ._internal.utils import _warn_experimental
from ._internal.utils import add_experimental_docstring

if TYPE_CHECKING:
from ._internal.server.metrics.prometheus import PrometheusClient

Expand All @@ -28,7 +31,11 @@ def __init__(self, attr: t.Any):
self._args: tuple[t.Any, ...] = ()
self._kwargs: dict[str, t.Any] = {}

@add_experimental_docstring
def __call__(self, *args: t.Any, **kwargs: t.Any) -> t.Any:
"""
Lazily initialize the metrics object.
"""
# This is where we lazy load the proxy object.
self._args = args
self._kwargs = kwargs
Expand Down

0 comments on commit 13d8d68

Please sign in to comment.