Skip to content

deprecation: warn for deprecation - Lambda model-predictor #2692

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

Merged
merged 12 commits into from
Oct 20, 2021
Merged
62 changes: 62 additions & 0 deletions src/sagemaker/deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,46 @@ def renamed_warning(phrase):
_warn(f"{phrase} has been renamed")


def deprecation_warn(name, date, msg=None):
"""Raise a warning for soon to be deprecated feature in sagemaker>=2

Args:
name (str): Name of the feature
date (str): the date when the feature will be deprecated
msg (str): the prefix phrase of the warning message.
"""
_warn(f"{name} will be deprecated on {date}.{msg}")


def deprecation_warning(date, msg=None):
"""Decorator for raising deprecation warning for a feature in sagemaker>=2

Args:
date (str): the date when the feature will be deprecated
msg (str): the prefix phrase of the warning message.

Usage:
@deprecation_warning(msg="message", date="date")
def sample_function():
print("xxxx....")

@deprecation_warning(msg="message", date="date")
class SampleClass():
def __init__(self):
print("xxxx....")

"""

def deprecate(obj):
def wrapper(*args, **kwargs):
deprecation_warn(obj.__name__, date, msg)
return obj(*args, **kwargs)

return wrapper

return deprecate


def renamed_kwargs(old_name, new_name, value, kwargs):
"""Checks if the deprecated argument is in kwargs

Expand Down Expand Up @@ -106,6 +146,28 @@ def func(*args, **kwargs): # pylint: disable=W0613
return func


def deprecated(obj):
"""Decorator for raising deprecated warning for a feature in sagemaker>=2

Usage:
@deprecated
def sample_function():
print("xxxx....")

@deprecated
class SampleClass():
def __init__(self):
print("xxxx....")

"""

def wrapper(*args, **kwargs):
removed_warning(obj.__name__)
return obj(*args, **kwargs)

return wrapper


def deprecated_function(func, name):
"""Wrap a function with a deprecation warning.

Expand Down
7 changes: 6 additions & 1 deletion src/sagemaker/serverless/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@
import botocore

from sagemaker.model import ModelBase

from sagemaker.deprecations import deprecation_warning
from .predictor import LambdaPredictor


@deprecation_warning(
msg="Based on customer experience and feedback an"
" alternative support will be added in near future",
date="10/29/2021",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are giving only 15 days for people to stop using this functionality. I think we should give more time.
PR LGTM.

)
class LambdaModel(ModelBase):
"""A model that can be deployed to Lambda."""

Expand Down
6 changes: 6 additions & 0 deletions src/sagemaker/serverless/predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@

from sagemaker import deserializers, serializers
from sagemaker.predictor import PredictorBase
from sagemaker.deprecations import deprecation_warning


@deprecation_warning(
msg="Based on customer experience and feedback an"
" alternative support will be added in near future",
date="10/29/2021",
)
class LambdaPredictor(PredictorBase):
"""A deployed model hosted on Lambda."""

Expand Down
102 changes: 102 additions & 0 deletions tests/unit/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
removed_function,
removed_kwargs,
renamed_kwargs,
deprecation_warning,
deprecated,
)


Expand Down Expand Up @@ -60,6 +62,106 @@ def test_removed_kwargs():
removed_kwargs("b", kwarg)


def test_deprecation_warning_for_function():
@deprecation_warning(msg="message", date="date")
def sample_function():
return "xxxx...."

with pytest.warns(DeprecationWarning) as w:
output = sample_function()
assert output == "xxxx...."
msg = (
"sample_function will be deprecated on date.message in sagemaker>=2.\n"
"See: https://sagemaker.readthedocs.io/en/stable/v2.html for details."
)
assert str(w[-1].message) == msg


def test_deprecation_warning_for_class():
@deprecation_warning(msg="message", date="date")
class SampleClass:
def __init__(self):
pass

with pytest.warns(DeprecationWarning) as w:
SampleClass()
msg = (
"SampleClass will be deprecated on date.message in sagemaker>=2.\n"
"See: https://sagemaker.readthedocs.io/en/stable/v2.html for details."
)
assert str(w[-1].message) == msg


def test_deprecation_warning_for_class_method():
class SampleClass:
def __init__(self):
pass

@deprecation_warning(msg="message", date="date")
def sample_method(self):
return "xxxx...."

s = SampleClass()
with pytest.warns(DeprecationWarning) as w:
output = s.sample_method()
assert output == "xxxx...."
msg = (
"sample_method will be deprecated on date.message in sagemaker>=2.\n"
"See: https://sagemaker.readthedocs.io/en/stable/v2.html for details."
)
assert str(w[-1].message) == msg


def test_deprecated_for_function():
@deprecated
def sample_function():
return "xxxx...."

with pytest.warns(DeprecationWarning) as w:
output = sample_function()
assert output == "xxxx...."
msg = (
"sample_function is a no-op in sagemaker>=2.\n"
"See: https://sagemaker.readthedocs.io/en/stable/v2.html for details."
)
assert str(w[-1].message) == msg


def test_deprecated_for_class():
@deprecated
class SampleClass:
def __init__(self):
pass

with pytest.warns(DeprecationWarning) as w:
SampleClass()
msg = (
"SampleClass is a no-op in sagemaker>=2.\n"
"See: https://sagemaker.readthedocs.io/en/stable/v2.html for details."
)
assert str(w[-1].message) == msg


def test_deprecated_for_class_method():
class SampleClass:
def __init__(self):
pass

@deprecated
def sample_method(self):
return "xxxx...."

s = SampleClass()
with pytest.warns(DeprecationWarning) as w:
output = s.sample_method()
assert output == "xxxx...."
msg = (
"sample_method is a no-op in sagemaker>=2.\n"
"See: https://sagemaker.readthedocs.io/en/stable/v2.html for details."
)
assert str(w[-1].message) == msg


def test_removed_function():
removed = removed_function("foo")
with pytest.warns(DeprecationWarning):
Expand Down