forked from conan-io/conan-center-index
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_package_name.py
52 lines (46 loc) · 1.8 KB
/
check_package_name.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from pylint.checkers import BaseChecker
from pylint.interfaces import IAstroidChecker
from astroid import nodes, Const, AssignName
from pathlib import Path
class PackageName(BaseChecker):
"""
All packages must have a lower-case name
"""
__implements__ = IAstroidChecker
name = "conan-package-name"
msgs = {
"E9004": (
"Reference name should be all lowercase",
"conan-bad-name",
"Use only lower-case on the package name: `name = 'foobar'`."
),
"E9005": (
"Missing name attribute",
"conan-missing-name",
"The member attribute `name` must be declared: `name = 'foobar'`."
),
"E9007": (
"No 'name' attribute in test_package conanfile",
"conan-test-no-name",
"No 'name' attribute in test_package conanfile."
),
}
def visit_classdef(self, node: nodes) -> None:
filename = Path(node.root().file)
is_test = filename.match('test_*/*.py')
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 == "name" and \
isinstance(children[1], Const):
if is_test:
self.add_message("conan-test-no-name", node=attr, line=attr.lineno)
return
value = children[1].as_string()
if value.lower() != value:
self.add_message("conan-bad-name", node=attr, line=attr.lineno)
return
if not is_test:
self.add_message("conan-missing-name", node=node)