"""Helper for warning about deprecations"""importinspectimportosimportsysimportwarningsimportpackaging.versionfromsaltext.vaultimport__version__
[docs]defwarn_until(version,message,category=DeprecationWarning,):""" Warn about deprecations until the specified version is reached, after which raise a RuntimeError to remind developers about removal. Loosely based on ``salt.utils.versions.warn_until``. version The version at which the warning turns into an error. Can be specified as a string, float, int or iterable with items castable to integers. message The warning message to show. category The warning class to be thrown, by default ``DeprecationWarning``. """version=_parse_version(version)saltext_version=_parse_version(__version__)# Attribute the warning to the calling function, not to warn_until()stacklevel=2ifsaltext_version>=version:caller=inspect.getframeinfo(sys._getframe(stacklevel-1))raiseRuntimeError(f"The warning triggered on filename '{caller.filename}', line number "f"{caller.lineno}, is supposed to be shown until version "f"{version} is released. Current version is now "f"{saltext_version}. Please remove the warning.")ifos.environ.get("PYTHONWARNINGS")!="ignore":warnings.warn(message.format(version=version),category,stacklevel=stacklevel,)
def_parse_version(version):ifisinstance(version,str):passelifisinstance(version,(float,int)):version=str(version)else:try:version=".".join(str(x)forxinversion)exceptTypeErroraserr:raiseRuntimeError("`version` must be a string, integer, float or an iterable")fromerrreturnVersion(version)