ansible-core 2.19.0b2__py3-none-any.whl → 2.19.0b4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ansible/_internal/__init__.py +1 -1
- ansible/_internal/_ansiballz.py +1 -4
- ansible/_internal/_json/__init__.py +1 -1
- ansible/_internal/_templating/_datatag.py +3 -4
- ansible/_internal/_templating/_engine.py +6 -1
- ansible/_internal/_templating/_jinja_plugins.py +2 -6
- ansible/_internal/_testing.py +26 -0
- ansible/cli/__init__.py +3 -2
- ansible/cli/arguments/option_helpers.py +10 -3
- ansible/cli/doc.py +0 -1
- ansible/config/base.yml +5 -23
- ansible/config/manager.py +144 -103
- ansible/constants.py +1 -63
- ansible/errors/__init__.py +6 -2
- ansible/executor/module_common.py +11 -7
- ansible/executor/task_executor.py +6 -8
- ansible/galaxy/api.py +1 -1
- ansible/galaxy/collection/__init__.py +3 -3
- ansible/inventory/manager.py +1 -0
- ansible/module_utils/_internal/_ansiballz.py +4 -30
- ansible/module_utils/_internal/_datatag/_tags.py +3 -25
- ansible/module_utils/_internal/_deprecator.py +134 -0
- ansible/module_utils/_internal/_plugin_info.py +25 -0
- ansible/module_utils/_internal/_validation.py +14 -0
- ansible/module_utils/ansible_release.py +1 -1
- ansible/module_utils/basic.py +64 -17
- ansible/module_utils/common/arg_spec.py +8 -3
- ansible/module_utils/common/messages.py +40 -23
- ansible/module_utils/common/process.py +0 -1
- ansible/module_utils/common/respawn.py +0 -7
- ansible/module_utils/common/warnings.py +13 -13
- ansible/module_utils/datatag.py +13 -13
- ansible/module_utils/facts/virtual/linux.py +1 -1
- ansible/module_utils/parsing/convert_bool.py +6 -0
- ansible/modules/assemble.py +4 -4
- ansible/modules/async_status.py +1 -1
- ansible/modules/cron.py +3 -5
- ansible/modules/dnf5.py +2 -1
- ansible/modules/get_url.py +1 -1
- ansible/modules/git.py +1 -6
- ansible/modules/pip.py +2 -4
- ansible/modules/sysvinit.py +3 -3
- ansible/playbook/task.py +0 -2
- ansible/plugins/__init__.py +18 -8
- ansible/plugins/action/__init__.py +7 -15
- ansible/plugins/action/gather_facts.py +2 -4
- ansible/plugins/action/template.py +3 -0
- ansible/plugins/callback/oneline.py +7 -1
- ansible/plugins/callback/tree.py +7 -1
- ansible/plugins/connection/local.py +1 -1
- ansible/plugins/connection/paramiko_ssh.py +9 -2
- ansible/plugins/doc_fragments/action_core.py +1 -1
- ansible/plugins/filter/core.py +4 -1
- ansible/plugins/inventory/__init__.py +2 -2
- ansible/plugins/loader.py +197 -132
- ansible/plugins/lookup/url.py +2 -2
- ansible/plugins/strategy/__init__.py +6 -6
- ansible/release.py +1 -1
- ansible/template/__init__.py +1 -1
- ansible/utils/collection_loader/__init__.py +2 -0
- ansible/utils/collection_loader/_collection_meta.py +5 -3
- ansible/utils/display.py +137 -71
- ansible/utils/plugin_docs.py +2 -1
- ansible/utils/py3compat.py +1 -7
- ansible/utils/ssh_functions.py +4 -1
- ansible/vars/manager.py +18 -10
- ansible/vars/plugins.py +4 -4
- {ansible_core-2.19.0b2.dist-info → ansible_core-2.19.0b4.dist-info}/METADATA +3 -2
- {ansible_core-2.19.0b2.dist-info → ansible_core-2.19.0b4.dist-info}/RECORD +82 -79
- {ansible_core-2.19.0b2.dist-info → ansible_core-2.19.0b4.dist-info}/WHEEL +1 -1
- ansible_test/_internal/commands/sanity/pylint.py +1 -0
- ansible_test/_internal/docker_util.py +4 -3
- ansible_test/_util/controller/sanity/pylint/plugins/deprecated_calls.py +486 -0
- ansible_test/_util/controller/sanity/pylint/plugins/deprecated_comment.py +137 -0
- ansible/module_utils/_internal/_dataclass_annotation_patch.py +0 -64
- ansible/module_utils/_internal/_plugin_exec_context.py +0 -49
- ansible_test/_util/controller/sanity/pylint/plugins/deprecated.py +0 -399
- {ansible_core-2.19.0b2.dist-info → ansible_core-2.19.0b4.dist-info}/entry_points.txt +0 -0
- {ansible_core-2.19.0b2.dist-info → ansible_core-2.19.0b4.dist-info/licenses}/COPYING +0 -0
- {ansible_core-2.19.0b2.dist-info → ansible_core-2.19.0b4.dist-info/licenses/licenses}/Apache-License.txt +0 -0
- {ansible_core-2.19.0b2.dist-info → ansible_core-2.19.0b4.dist-info/licenses/licenses}/BSD-3-Clause.txt +0 -0
- {ansible_core-2.19.0b2.dist-info → ansible_core-2.19.0b4.dist-info/licenses/licenses}/MIT-license.txt +0 -0
- {ansible_core-2.19.0b2.dist-info → ansible_core-2.19.0b4.dist-info/licenses/licenses}/PSF-license.txt +0 -0
- {ansible_core-2.19.0b2.dist-info → ansible_core-2.19.0b4.dist-info/licenses/licenses}/simplified_bsd.txt +0 -0
- {ansible_core-2.19.0b2.dist-info → ansible_core-2.19.0b4.dist-info}/top_level.txt +0 -0
@@ -1,49 +0,0 @@
|
|
1
|
-
from __future__ import annotations
|
2
|
-
|
3
|
-
import typing as t
|
4
|
-
|
5
|
-
from ._ambient_context import AmbientContextBase
|
6
|
-
from ..common.messages import PluginInfo
|
7
|
-
|
8
|
-
|
9
|
-
class HasPluginInfo(t.Protocol):
|
10
|
-
"""Protocol to type-annotate and expose PluginLoader-set values."""
|
11
|
-
|
12
|
-
@property
|
13
|
-
def _load_name(self) -> str:
|
14
|
-
"""The requested name used to load the plugin."""
|
15
|
-
|
16
|
-
@property
|
17
|
-
def ansible_name(self) -> str:
|
18
|
-
"""Fully resolved plugin name."""
|
19
|
-
|
20
|
-
@property
|
21
|
-
def plugin_type(self) -> str:
|
22
|
-
"""Plugin type name."""
|
23
|
-
|
24
|
-
|
25
|
-
class PluginExecContext(AmbientContextBase):
|
26
|
-
"""Execution context that wraps all plugin invocations to allow infrastructure introspection of the currently-executing plugin instance."""
|
27
|
-
|
28
|
-
def __init__(self, executing_plugin: HasPluginInfo) -> None:
|
29
|
-
self._executing_plugin = executing_plugin
|
30
|
-
|
31
|
-
@property
|
32
|
-
def executing_plugin(self) -> HasPluginInfo:
|
33
|
-
return self._executing_plugin
|
34
|
-
|
35
|
-
@property
|
36
|
-
def plugin_info(self) -> PluginInfo:
|
37
|
-
return PluginInfo(
|
38
|
-
requested_name=self._executing_plugin._load_name,
|
39
|
-
resolved_name=self._executing_plugin.ansible_name,
|
40
|
-
type=self._executing_plugin.plugin_type,
|
41
|
-
)
|
42
|
-
|
43
|
-
@classmethod
|
44
|
-
def get_current_plugin_info(cls) -> PluginInfo | None:
|
45
|
-
"""Utility method to extract a PluginInfo for the currently executing plugin (or None if no plugin is executing)."""
|
46
|
-
if ctx := cls.current(optional=True):
|
47
|
-
return ctx.plugin_info
|
48
|
-
|
49
|
-
return None
|
@@ -1,399 +0,0 @@
|
|
1
|
-
"""Ansible specific plyint plugin for checking deprecations."""
|
2
|
-
|
3
|
-
# (c) 2018, Matt Martz <matt@sivel.net>
|
4
|
-
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
5
|
-
# -*- coding: utf-8 -*-
|
6
|
-
from __future__ import annotations
|
7
|
-
|
8
|
-
import datetime
|
9
|
-
import re
|
10
|
-
import shlex
|
11
|
-
import typing as t
|
12
|
-
from tokenize import COMMENT, TokenInfo
|
13
|
-
|
14
|
-
import astroid
|
15
|
-
|
16
|
-
try:
|
17
|
-
from pylint.checkers.utils import check_messages
|
18
|
-
except ImportError:
|
19
|
-
from pylint.checkers.utils import only_required_for_messages as check_messages
|
20
|
-
|
21
|
-
from pylint.checkers import BaseChecker, BaseTokenChecker
|
22
|
-
|
23
|
-
from ansible.module_utils.compat.version import LooseVersion
|
24
|
-
from ansible.release import __version__ as ansible_version_raw
|
25
|
-
from ansible.utils.version import SemanticVersion
|
26
|
-
|
27
|
-
MSGS = {
|
28
|
-
'E9501': ("Deprecated version (%r) found in call to Display.deprecated "
|
29
|
-
"or AnsibleModule.deprecate",
|
30
|
-
"ansible-deprecated-version",
|
31
|
-
"Used when a call to Display.deprecated specifies a version "
|
32
|
-
"less than or equal to the current version of Ansible",
|
33
|
-
{'minversion': (2, 6)}),
|
34
|
-
'E9502': ("Display.deprecated call without a version or date",
|
35
|
-
"ansible-deprecated-no-version",
|
36
|
-
"Used when a call to Display.deprecated does not specify a "
|
37
|
-
"version or date",
|
38
|
-
{'minversion': (2, 6)}),
|
39
|
-
'E9503': ("Invalid deprecated version (%r) found in call to "
|
40
|
-
"Display.deprecated or AnsibleModule.deprecate",
|
41
|
-
"ansible-invalid-deprecated-version",
|
42
|
-
"Used when a call to Display.deprecated specifies an invalid "
|
43
|
-
"Ansible version number",
|
44
|
-
{'minversion': (2, 6)}),
|
45
|
-
'E9504': ("Deprecated version (%r) found in call to Display.deprecated "
|
46
|
-
"or AnsibleModule.deprecate",
|
47
|
-
"collection-deprecated-version",
|
48
|
-
"Used when a call to Display.deprecated specifies a collection "
|
49
|
-
"version less than or equal to the current version of this "
|
50
|
-
"collection",
|
51
|
-
{'minversion': (2, 6)}),
|
52
|
-
'E9505': ("Invalid deprecated version (%r) found in call to "
|
53
|
-
"Display.deprecated or AnsibleModule.deprecate",
|
54
|
-
"collection-invalid-deprecated-version",
|
55
|
-
"Used when a call to Display.deprecated specifies an invalid "
|
56
|
-
"collection version number",
|
57
|
-
{'minversion': (2, 6)}),
|
58
|
-
'E9506': ("No collection name found in call to Display.deprecated or "
|
59
|
-
"AnsibleModule.deprecate",
|
60
|
-
"ansible-deprecated-no-collection-name",
|
61
|
-
"The current collection name in format `namespace.name` must "
|
62
|
-
"be provided as collection_name when calling Display.deprecated "
|
63
|
-
"or AnsibleModule.deprecate (`ansible.builtin` for ansible-core)",
|
64
|
-
{'minversion': (2, 6)}),
|
65
|
-
'E9507': ("Wrong collection name (%r) found in call to "
|
66
|
-
"Display.deprecated or AnsibleModule.deprecate",
|
67
|
-
"wrong-collection-deprecated",
|
68
|
-
"The name of the current collection must be passed to the "
|
69
|
-
"Display.deprecated resp. AnsibleModule.deprecate calls "
|
70
|
-
"(`ansible.builtin` for ansible-core)",
|
71
|
-
{'minversion': (2, 6)}),
|
72
|
-
'E9508': ("Expired date (%r) found in call to Display.deprecated "
|
73
|
-
"or AnsibleModule.deprecate",
|
74
|
-
"ansible-deprecated-date",
|
75
|
-
"Used when a call to Display.deprecated specifies a date "
|
76
|
-
"before today",
|
77
|
-
{'minversion': (2, 6)}),
|
78
|
-
'E9509': ("Invalid deprecated date (%r) found in call to "
|
79
|
-
"Display.deprecated or AnsibleModule.deprecate",
|
80
|
-
"ansible-invalid-deprecated-date",
|
81
|
-
"Used when a call to Display.deprecated specifies an invalid "
|
82
|
-
"date. It must be a string in format `YYYY-MM-DD` (ISO 8601)",
|
83
|
-
{'minversion': (2, 6)}),
|
84
|
-
'E9510': ("Both version and date found in call to "
|
85
|
-
"Display.deprecated or AnsibleModule.deprecate",
|
86
|
-
"ansible-deprecated-both-version-and-date",
|
87
|
-
"Only one of version and date must be specified",
|
88
|
-
{'minversion': (2, 6)}),
|
89
|
-
'E9511': ("Removal version (%r) must be a major release, not a minor or "
|
90
|
-
"patch release (see the specification at https://semver.org/)",
|
91
|
-
"removal-version-must-be-major",
|
92
|
-
"Used when a call to Display.deprecated or "
|
93
|
-
"AnsibleModule.deprecate for a collection specifies a version "
|
94
|
-
"which is not of the form x.0.0",
|
95
|
-
{'minversion': (2, 6)}),
|
96
|
-
}
|
97
|
-
|
98
|
-
|
99
|
-
ANSIBLE_VERSION = LooseVersion('.'.join(ansible_version_raw.split('.')[:3]))
|
100
|
-
|
101
|
-
|
102
|
-
def _get_expr_name(node):
|
103
|
-
"""Function to get either ``attrname`` or ``name`` from ``node.func.expr``
|
104
|
-
|
105
|
-
Created specifically for the case of ``display.deprecated`` or ``self._display.deprecated``
|
106
|
-
"""
|
107
|
-
try:
|
108
|
-
return node.func.expr.attrname
|
109
|
-
except AttributeError:
|
110
|
-
# If this fails too, we'll let it raise, the caller should catch it
|
111
|
-
return node.func.expr.name
|
112
|
-
|
113
|
-
|
114
|
-
def _get_func_name(node):
|
115
|
-
"""Function to get either ``attrname`` or ``name`` from ``node.func``
|
116
|
-
|
117
|
-
Created specifically for the case of ``from ansible.module_utils.common.warnings import deprecate``
|
118
|
-
"""
|
119
|
-
try:
|
120
|
-
return node.func.attrname
|
121
|
-
except AttributeError:
|
122
|
-
return node.func.name
|
123
|
-
|
124
|
-
|
125
|
-
def parse_isodate(value):
|
126
|
-
"""Parse an ISO 8601 date string."""
|
127
|
-
msg = 'Expected ISO 8601 date string (YYYY-MM-DD)'
|
128
|
-
if not isinstance(value, str):
|
129
|
-
raise ValueError(msg)
|
130
|
-
# From Python 3.7 in, there is datetime.date.fromisoformat(). For older versions,
|
131
|
-
# we have to do things manually.
|
132
|
-
if not re.match('^[0-9]{4}-[0-9]{2}-[0-9]{2}$', value):
|
133
|
-
raise ValueError(msg)
|
134
|
-
try:
|
135
|
-
return datetime.datetime.strptime(value, '%Y-%m-%d').date()
|
136
|
-
except ValueError:
|
137
|
-
raise ValueError(msg) from None
|
138
|
-
|
139
|
-
|
140
|
-
class AnsibleDeprecatedChecker(BaseChecker):
|
141
|
-
"""Checks for Display.deprecated calls to ensure that the ``version``
|
142
|
-
has not passed or met the time for removal
|
143
|
-
"""
|
144
|
-
|
145
|
-
name = 'deprecated'
|
146
|
-
msgs = MSGS
|
147
|
-
|
148
|
-
options = (
|
149
|
-
('collection-name', {
|
150
|
-
'default': None,
|
151
|
-
'type': 'string',
|
152
|
-
'metavar': '<name>',
|
153
|
-
'help': 'The collection\'s name used to check collection names in deprecations.',
|
154
|
-
}),
|
155
|
-
('collection-version', {
|
156
|
-
'default': None,
|
157
|
-
'type': 'string',
|
158
|
-
'metavar': '<version>',
|
159
|
-
'help': 'The collection\'s version number used to check deprecations.',
|
160
|
-
}),
|
161
|
-
)
|
162
|
-
|
163
|
-
def _check_date(self, node, date):
|
164
|
-
if not isinstance(date, str):
|
165
|
-
self.add_message('ansible-invalid-deprecated-date', node=node, args=(date,))
|
166
|
-
return
|
167
|
-
|
168
|
-
try:
|
169
|
-
date_parsed = parse_isodate(date)
|
170
|
-
except ValueError:
|
171
|
-
self.add_message('ansible-invalid-deprecated-date', node=node, args=(date,))
|
172
|
-
return
|
173
|
-
|
174
|
-
if date_parsed < datetime.date.today():
|
175
|
-
self.add_message('ansible-deprecated-date', node=node, args=(date,))
|
176
|
-
|
177
|
-
def _check_version(self, node, version, collection_name):
|
178
|
-
if collection_name is None:
|
179
|
-
collection_name = 'ansible.builtin'
|
180
|
-
if not isinstance(version, (str, float)):
|
181
|
-
if collection_name == 'ansible.builtin':
|
182
|
-
symbol = 'ansible-invalid-deprecated-version'
|
183
|
-
else:
|
184
|
-
symbol = 'collection-invalid-deprecated-version'
|
185
|
-
self.add_message(symbol, node=node, args=(version,))
|
186
|
-
return
|
187
|
-
|
188
|
-
version_no = str(version)
|
189
|
-
|
190
|
-
if collection_name == 'ansible.builtin':
|
191
|
-
# Ansible-base
|
192
|
-
try:
|
193
|
-
if not version_no:
|
194
|
-
raise ValueError('Version string should not be empty')
|
195
|
-
loose_version = LooseVersion(str(version_no))
|
196
|
-
if ANSIBLE_VERSION >= loose_version:
|
197
|
-
self.add_message('ansible-deprecated-version', node=node, args=(version,))
|
198
|
-
except ValueError:
|
199
|
-
self.add_message('ansible-invalid-deprecated-version', node=node, args=(version,))
|
200
|
-
elif collection_name:
|
201
|
-
# Collections
|
202
|
-
try:
|
203
|
-
if not version_no:
|
204
|
-
raise ValueError('Version string should not be empty')
|
205
|
-
semantic_version = SemanticVersion(version_no)
|
206
|
-
if collection_name == self.collection_name and self.collection_version is not None:
|
207
|
-
if self.collection_version >= semantic_version:
|
208
|
-
self.add_message('collection-deprecated-version', node=node, args=(version,))
|
209
|
-
if semantic_version.major != 0 and (semantic_version.minor != 0 or semantic_version.patch != 0):
|
210
|
-
self.add_message('removal-version-must-be-major', node=node, args=(version,))
|
211
|
-
except ValueError:
|
212
|
-
self.add_message('collection-invalid-deprecated-version', node=node, args=(version,))
|
213
|
-
|
214
|
-
@property
|
215
|
-
def collection_name(self) -> t.Optional[str]:
|
216
|
-
"""Return the collection name, or None if ansible-core is being tested."""
|
217
|
-
return self.linter.config.collection_name
|
218
|
-
|
219
|
-
@property
|
220
|
-
def collection_version(self) -> t.Optional[SemanticVersion]:
|
221
|
-
"""Return the collection version, or None if ansible-core is being tested."""
|
222
|
-
if self.linter.config.collection_version is None:
|
223
|
-
return None
|
224
|
-
sem_ver = SemanticVersion(self.linter.config.collection_version)
|
225
|
-
# Ignore pre-release for version comparison to catch issues before the final release is cut.
|
226
|
-
sem_ver.prerelease = ()
|
227
|
-
return sem_ver
|
228
|
-
|
229
|
-
@check_messages(*(MSGS.keys()))
|
230
|
-
def visit_call(self, node):
|
231
|
-
"""Visit a call node."""
|
232
|
-
version = None
|
233
|
-
date = None
|
234
|
-
collection_name = None
|
235
|
-
try:
|
236
|
-
funcname = _get_func_name(node)
|
237
|
-
if (funcname == 'deprecated' and 'display' in _get_expr_name(node) or
|
238
|
-
funcname == 'deprecate'):
|
239
|
-
if node.keywords:
|
240
|
-
for keyword in node.keywords:
|
241
|
-
if len(node.keywords) == 1 and keyword.arg is None:
|
242
|
-
# This is likely a **kwargs splat
|
243
|
-
return
|
244
|
-
if keyword.arg == 'version':
|
245
|
-
if isinstance(keyword.value.value, astroid.Name):
|
246
|
-
# This is likely a variable
|
247
|
-
return
|
248
|
-
version = keyword.value.value
|
249
|
-
if keyword.arg == 'date':
|
250
|
-
if isinstance(keyword.value.value, astroid.Name):
|
251
|
-
# This is likely a variable
|
252
|
-
return
|
253
|
-
date = keyword.value.value
|
254
|
-
if keyword.arg == 'collection_name':
|
255
|
-
if isinstance(keyword.value.value, astroid.Name):
|
256
|
-
# This is likely a variable
|
257
|
-
return
|
258
|
-
collection_name = keyword.value.value
|
259
|
-
if not version and not date:
|
260
|
-
try:
|
261
|
-
version = node.args[1].value
|
262
|
-
except IndexError:
|
263
|
-
self.add_message('ansible-deprecated-no-version', node=node)
|
264
|
-
return
|
265
|
-
if version and date:
|
266
|
-
self.add_message('ansible-deprecated-both-version-and-date', node=node)
|
267
|
-
|
268
|
-
if collection_name:
|
269
|
-
this_collection = collection_name == (self.collection_name or 'ansible.builtin')
|
270
|
-
if not this_collection:
|
271
|
-
self.add_message('wrong-collection-deprecated', node=node, args=(collection_name,))
|
272
|
-
elif self.collection_name is not None:
|
273
|
-
self.add_message('ansible-deprecated-no-collection-name', node=node)
|
274
|
-
|
275
|
-
if date:
|
276
|
-
self._check_date(node, date)
|
277
|
-
elif version:
|
278
|
-
self._check_version(node, version, collection_name)
|
279
|
-
except AttributeError:
|
280
|
-
# Not the type of node we are interested in
|
281
|
-
pass
|
282
|
-
|
283
|
-
|
284
|
-
class AnsibleDeprecatedCommentChecker(BaseTokenChecker):
|
285
|
-
"""Checks for ``# deprecated:`` comments to ensure that the ``version``
|
286
|
-
has not passed or met the time for removal
|
287
|
-
"""
|
288
|
-
|
289
|
-
name = 'deprecated-comment'
|
290
|
-
msgs = {
|
291
|
-
'E9601': ("Deprecated core version (%r) found: %s",
|
292
|
-
"ansible-deprecated-version-comment",
|
293
|
-
"Used when a '# deprecated:' comment specifies a version "
|
294
|
-
"less than or equal to the current version of Ansible",
|
295
|
-
{'minversion': (2, 6)}),
|
296
|
-
'E9602': ("Deprecated comment contains invalid keys %r",
|
297
|
-
"ansible-deprecated-version-comment-invalid-key",
|
298
|
-
"Used when a '#deprecated:' comment specifies invalid data",
|
299
|
-
{'minversion': (2, 6)}),
|
300
|
-
'E9603': ("Deprecated comment missing version",
|
301
|
-
"ansible-deprecated-version-comment-missing-version",
|
302
|
-
"Used when a '#deprecated:' comment specifies invalid data",
|
303
|
-
{'minversion': (2, 6)}),
|
304
|
-
'E9604': ("Deprecated python version (%r) found: %s",
|
305
|
-
"ansible-deprecated-python-version-comment",
|
306
|
-
"Used when a '#deprecated:' comment specifies a python version "
|
307
|
-
"less than or equal to the minimum python version",
|
308
|
-
{'minversion': (2, 6)}),
|
309
|
-
'E9605': ("Deprecated comment contains invalid version %r: %s",
|
310
|
-
"ansible-deprecated-version-comment-invalid-version",
|
311
|
-
"Used when a '#deprecated:' comment specifies an invalid version",
|
312
|
-
{'minversion': (2, 6)}),
|
313
|
-
}
|
314
|
-
|
315
|
-
def process_tokens(self, tokens: list[TokenInfo]) -> None:
|
316
|
-
for token in tokens:
|
317
|
-
if token.type == COMMENT:
|
318
|
-
self._process_comment(token)
|
319
|
-
|
320
|
-
def _deprecated_string_to_dict(self, token: TokenInfo, string: str) -> dict[str, str]:
|
321
|
-
valid_keys = {'description', 'core_version', 'python_version'}
|
322
|
-
data = dict.fromkeys(valid_keys)
|
323
|
-
for opt in shlex.split(string):
|
324
|
-
if '=' not in opt:
|
325
|
-
data[opt] = None
|
326
|
-
continue
|
327
|
-
key, _sep, value = opt.partition('=')
|
328
|
-
data[key] = value
|
329
|
-
if not any((data['core_version'], data['python_version'])):
|
330
|
-
self.add_message(
|
331
|
-
'ansible-deprecated-version-comment-missing-version',
|
332
|
-
line=token.start[0],
|
333
|
-
col_offset=token.start[1],
|
334
|
-
)
|
335
|
-
bad = set(data).difference(valid_keys)
|
336
|
-
if bad:
|
337
|
-
self.add_message(
|
338
|
-
'ansible-deprecated-version-comment-invalid-key',
|
339
|
-
line=token.start[0],
|
340
|
-
col_offset=token.start[1],
|
341
|
-
args=(','.join(bad),)
|
342
|
-
)
|
343
|
-
return data
|
344
|
-
|
345
|
-
def _process_python_version(self, token: TokenInfo, data: dict[str, str]) -> None:
|
346
|
-
check_version = '.'.join(map(str, self.linter.config.py_version))
|
347
|
-
|
348
|
-
try:
|
349
|
-
if LooseVersion(data['python_version']) < LooseVersion(check_version):
|
350
|
-
self.add_message(
|
351
|
-
'ansible-deprecated-python-version-comment',
|
352
|
-
line=token.start[0],
|
353
|
-
col_offset=token.start[1],
|
354
|
-
args=(
|
355
|
-
data['python_version'],
|
356
|
-
data['description'] or 'description not provided',
|
357
|
-
),
|
358
|
-
)
|
359
|
-
except (ValueError, TypeError) as exc:
|
360
|
-
self.add_message(
|
361
|
-
'ansible-deprecated-version-comment-invalid-version',
|
362
|
-
line=token.start[0],
|
363
|
-
col_offset=token.start[1],
|
364
|
-
args=(data['python_version'], exc)
|
365
|
-
)
|
366
|
-
|
367
|
-
def _process_core_version(self, token: TokenInfo, data: dict[str, str]) -> None:
|
368
|
-
try:
|
369
|
-
if ANSIBLE_VERSION >= LooseVersion(data['core_version']):
|
370
|
-
self.add_message(
|
371
|
-
'ansible-deprecated-version-comment',
|
372
|
-
line=token.start[0],
|
373
|
-
col_offset=token.start[1],
|
374
|
-
args=(
|
375
|
-
data['core_version'],
|
376
|
-
data['description'] or 'description not provided',
|
377
|
-
)
|
378
|
-
)
|
379
|
-
except (ValueError, TypeError) as exc:
|
380
|
-
self.add_message(
|
381
|
-
'ansible-deprecated-version-comment-invalid-version',
|
382
|
-
line=token.start[0],
|
383
|
-
col_offset=token.start[1],
|
384
|
-
args=(data['core_version'], exc)
|
385
|
-
)
|
386
|
-
|
387
|
-
def _process_comment(self, token: TokenInfo) -> None:
|
388
|
-
if token.string.startswith('# deprecated:'):
|
389
|
-
data = self._deprecated_string_to_dict(token, token.string[13:].strip())
|
390
|
-
if data['core_version']:
|
391
|
-
self._process_core_version(token, data)
|
392
|
-
if data['python_version']:
|
393
|
-
self._process_python_version(token, data)
|
394
|
-
|
395
|
-
|
396
|
-
def register(linter):
|
397
|
-
"""required method to auto register this checker """
|
398
|
-
linter.register_checker(AnsibleDeprecatedChecker(linter))
|
399
|
-
linter.register_checker(AnsibleDeprecatedCommentChecker(linter))
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|