MCPcopy Index your code
hub / github.com/saltstack/salt / warn_until

Function warn_until

salt/utils/versions.py:112–199  ·  view source on GitHub ↗

Helper function to raise a warning, by default, a ``DeprecationWarning``, until the provided ``version``, after which, a ``RuntimeError`` will be raised to remind the developers to remove the warning because the target version has been reached. :param version: The version info

(
    version,
    message,
    category=DeprecationWarning,
    stacklevel=None,
    _version_info_=None,
    _dont_call_warnings=False,
)

Source from the content-addressed store, hash-verified

110
111
112def warn_until(
113 version,
114 message,
115 category=DeprecationWarning,
116 stacklevel=None,
117 _version_info_=None,
118 _dont_call_warnings=False,
119):
120 """
121 Helper function to raise a warning, by default, a ``DeprecationWarning``,
122 until the provided ``version``, after which, a ``RuntimeError`` will
123 be raised to remind the developers to remove the warning because the
124 target version has been reached.
125
126 :param version: The version info or name after which the warning becomes a ``RuntimeError``.
127 For example ``(2019, 2)``, ``3000``, ``Hydrogen`` or an instance of
128 :class:`salt.version.SaltStackVersion` or :class:`salt.version.SaltVersion`.
129 :param message: The warning message to be displayed.
130 :param category: The warning class to be thrown, by default
131 ``DeprecationWarning``
132 :param stacklevel: There should be no need to set the value of
133 ``stacklevel``. Salt should be able to do the right thing.
134 :param _version_info_: In order to reuse this function for other SaltStack
135 projects, they need to be able to provide the
136 version info to compare to.
137 :param _dont_call_warnings: This parameter is used just to get the
138 functionality until the actual error is to be
139 issued. When we're only after the salt version
140 checks to raise a ``RuntimeError``.
141 """
142 if isinstance(version, salt.version.SaltVersion):
143 version = salt.version.SaltStackVersion(*version.info)
144 elif isinstance(version, int):
145 version = salt.version.SaltStackVersion(version)
146 elif isinstance(version, tuple):
147 version = salt.version.SaltStackVersion(*version)
148 elif isinstance(version, str):
149 if version.lower() not in salt.version.SaltStackVersion.LNAMES:
150 raise RuntimeError(
151 "Incorrect spelling for the release name in the warn_utils "
152 "call. Expecting one of these release names: {}".format(
153 [vs.name for vs in salt.version.SaltVersionsInfo.versions()]
154 )
155 )
156 version = salt.version.SaltStackVersion.from_name(version)
157 elif not isinstance(version, salt.version.SaltStackVersion):
158 raise RuntimeError(
159 "The 'version' argument should be passed as a tuple, integer, string or "
160 "an instance of 'salt.version.SaltVersion' or "
161 "'salt.version.SaltStackVersion'."
162 )
163
164 if stacklevel is None:
165 # Attribute the warning to the calling function, not to warn_until()
166 stacklevel = 2
167
168 if _version_info_ is None:
169 _version_info_ = salt.version.__version_info__

Callers 10

__init__Method · 0.90
__init__Method · 0.90
fire_event_asyncMethod · 0.90
factoryMethod · 0.90
factoryMethod · 0.90
factoryMethod · 0.90
factoryMethod · 0.90
factoryMethod · 0.90
__init__Method · 0.85
kwargs_warn_untilFunction · 0.85

Calls 6

formatMethod · 0.80
versionsMethod · 0.80
from_nameMethod · 0.45
getMethod · 0.45
writeMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected