forked from conan-io/conan-center-index
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_import_tools.py
30 lines (25 loc) · 1.1 KB
/
check_import_tools.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
import re
from email.mime import base
from pylint.checkers import BaseChecker
from pylint.interfaces import IAstroidChecker
from astroid import nodes, Const, AssignName
class ImportTools(BaseChecker):
"""
Import tools following pattern 'from conan.tools.xxxx import yyyyy'
"""
__implements__ = IAstroidChecker
name = "conan-import-tools"
msgs = {
"E9011": (
"Import tools following pattern 'from conan.tools.xxxx import yyyyy' (https://docs.conan.io/en/latest/reference/conanfile/tools.html).",
"conan-import-tools",
"Import tools following pattern 'from conan.tools.xxxx import yyyyy' (https://docs.conan.io/en/latest/reference/conanfile/tools.html).",
),
}
def visit_importfrom(self, node: nodes.ImportFrom) -> None:
basename = node.modname
names = [name for name, _ in node.names]
if basename == 'conan' and 'tools' in names:
self.add_message("conan-import-tools", node=node)
elif re.match(r'conan\.tools\.[^.]+\..+', basename):
self.add_message("conan-import-tools", node=node)