forked from conan-io/conan-center-index
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_version_attribute.py
33 lines (28 loc) · 1.2 KB
/
check_version_attribute.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from pylint.checkers import BaseChecker
from pylint.interfaces import IAstroidChecker
from astroid import nodes, Const, AssignName
class VersionAttribute(BaseChecker):
"""
All packages should not enforce a specific version in the recipe
"""
__implements__ = IAstroidChecker
name = "conan-attr-version"
msgs = {
"E9014": (
"Recipe should not contain version attribute",
"conan-forced-version",
"Do not enforce a specific version in your recipe. Keep it generic for any version."
),
}
def visit_classdef(self, node: nodes) -> None:
if node.basenames == ['ConanFile']:
for attr in node.body:
children = list(attr.get_children())
if len(children) == 2 and \
isinstance(children[0], AssignName) and \
children[0].name == "version" and \
isinstance(children[1], Const):
value = children[1].as_string().replace('"', "").replace("'", "")
if value and value != "system":
self.add_message("conan-forced-version", node=attr, line=attr.lineno)
return