mirror of
https://github.com/conan-io/conan-center-index.git
synced 2025-08-15 02:58:22 +00:00
(#11627) linter - check ConanFile import and cross_building
* linter - check ConanFile import and cross_building * remove unused code * Add docs * improve docs * example - abseil * md syntax * revert uneeded changes * Update docs/v2_linter.md Co-authored-by: Daniel <danimanzaneque@gmail.com> Co-authored-by: Daniel <danimanzaneque@gmail.com>
This commit is contained in:
28
linter/check_import_conanfile.py
Normal file
28
linter/check_import_conanfile.py
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
from pylint.checkers import BaseChecker
|
||||
from pylint.interfaces import IAstroidChecker
|
||||
from astroid import nodes, Const, AssignName
|
||||
|
||||
|
||||
class ImportConanFile(BaseChecker):
|
||||
"""
|
||||
Import ConanFile from new 'conan' module
|
||||
"""
|
||||
|
||||
__implements__ = IAstroidChecker
|
||||
|
||||
name = "conan-import-conanfile"
|
||||
msgs = {
|
||||
"W9006": (
|
||||
"Import ConanFile from new module: `from conan import ConanFile`. Old import is deprecated in Conan v2.",
|
||||
"conan-import-conanfile",
|
||||
"Import ConanFile from new module: `from conan import ConanFile`. 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 'ConanFile' in names:
|
||||
self.add_message("conan-import-conanfile", node=node)
|
@@ -1,7 +1,9 @@
|
||||
"""Pylint plugin for Conan Center Index"""
|
||||
from pylint.lint import PyLinter
|
||||
from linter.package_name import PackageName
|
||||
from linter.check_package_name import PackageName
|
||||
from linter.check_import_conanfile import ImportConanFile
|
||||
|
||||
|
||||
def register(linter: PyLinter) -> None:
|
||||
linter.register_checker(PackageName(linter))
|
||||
linter.register_checker(ImportConanFile(linter))
|
||||
|
@@ -1,6 +1,8 @@
|
||||
[MASTER]
|
||||
load-plugins=linter.conanv2_transition,
|
||||
linter.conanfile_transform
|
||||
linter.transform_conanfile,
|
||||
linter.transform_imports
|
||||
|
||||
py-version=3.6
|
||||
recursive=no
|
||||
suggestion-mode=yes
|
||||
@@ -17,7 +19,8 @@ disable=fixme,
|
||||
import-outside-toplevel # TODO: Remove
|
||||
|
||||
enable=conan-bad-name,
|
||||
conan-missing-name
|
||||
conan-missing-name,
|
||||
conan-import-conanfile
|
||||
|
||||
[REPORTS]
|
||||
evaluation=max(0, 0 if fatal else 10.0 - ((float(5 * error) / statement) * 10))
|
||||
|
@@ -1,6 +1,7 @@
|
||||
[MASTER]
|
||||
load-plugins=linter.conanv2_transition,
|
||||
linter.conanfile_transform
|
||||
linter.transform_conanfile,
|
||||
linter.transform_imports
|
||||
py-version=3.6
|
||||
recursive=no
|
||||
suggestion-mode=yes
|
||||
|
25
linter/transform_imports.py
Normal file
25
linter/transform_imports.py
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
import astroid
|
||||
from pylint.lint import PyLinter
|
||||
|
||||
"""
|
||||
Here we are transforming the imports to mimic future Conan v2 release. With
|
||||
these changes, built-in checks in Pylint will raise with different errors, so
|
||||
we are modifying the messages to point users in the right direction.
|
||||
"""
|
||||
|
||||
|
||||
def register(linter: PyLinter):
|
||||
msge1101 = linter.msgs_store._messages_definitions["E1101"]
|
||||
msge1101.msg += ". Please, check https://github.com/conan-io/conan-center-index/blob/master/docs/v2_linter.md"
|
||||
linter.msgs_store.register_message(msge1101)
|
||||
|
||||
def transform_tools(module):
|
||||
""" Transform import module """
|
||||
if 'cross_building' in module.locals:
|
||||
del module.locals['cross_building']
|
||||
|
||||
|
||||
astroid.MANAGER.register_transform(
|
||||
astroid.Module, transform_tools,
|
||||
lambda node: node.qname() == "conans.tools")
|
Reference in New Issue
Block a user