forked from conan-io/conan-center-index
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_import_errors.py
77 lines (60 loc) · 2.68 KB
/
check_import_errors.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from pylint.checkers import BaseChecker
from pylint.interfaces import IAstroidChecker
from astroid import nodes, Const, AssignName
class ImportErrors(BaseChecker):
"""
Import errors from new 'conan' module
"""
__implements__ = IAstroidChecker
name = "conan-import-errors"
msgs = {
"E9008": (
"Import errors from new module: `from conan import errors`. Old import is deprecated in Conan v2.",
"conan-import-errors",
"Import errors from new module: `from conan import errors`. Old import is deprecated in Conan v2.",
),
}
def visit_importfrom(self, node: nodes.ImportFrom) -> None:
basename = node.modname
if basename == 'conans':
names = [name for name, _ in node.names]
if 'errors' in names:
self.add_message("conan-import-errors", node=node)
class ImportErrorsConanException(BaseChecker):
"""
Import errors from new 'conan' module
"""
__implements__ = IAstroidChecker
name = "conan-import-error-conanexception"
msgs = {
"E9009": (
"Import ConanException from new module: `from conan.errors import ConanException`. Old import is deprecated in Conan v2.",
"conan-import-error-conanexception",
"Import ConanException from new module: `from conan.errors import ConanException`. Old import is deprecated in Conan v2.",
),
}
def visit_importfrom(self, node: nodes.ImportFrom) -> None:
basename = node.modname
if basename == 'conans.errors':
names = [name for name, _ in node.names]
if 'ConanException' in names:
self.add_message("conan-import-error-conanexception", node=node)
class ImportErrorsConanInvalidConfiguration(BaseChecker):
"""
Import errors from new 'conan' module
"""
__implements__ = IAstroidChecker
name = "conan-import-error-conaninvalidconfiguration"
msgs = {
"E9010": (
"Import ConanInvalidConfiguration from new module: `from conan.errors import ConanInvalidConfiguration`. Old import is deprecated in Conan v2.",
"conan-import-error-conaninvalidconfiguration",
"Import ConanInvalidConfiguration from new module: `from conan.errors import ConanInvalidConfiguration`. Old import is deprecated in Conan v2.",
),
}
def visit_importfrom(self, node: nodes.ImportFrom) -> None:
basename = node.modname
if basename == 'conans.errors':
names = [name for name, _ in node.names]
if 'ConanInvalidConfiguration' in names:
self.add_message("conan-import-error-conaninvalidconfiguration", node=node)