diff --git a/linter/check_no_test_package_name.py b/linter/check_no_test_package_name.py deleted file mode 100644 index 6a927475b4bb9d..00000000000000 --- a/linter/check_no_test_package_name.py +++ /dev/null @@ -1,30 +0,0 @@ -from pylint.checkers import BaseChecker -from pylint.interfaces import IAstroidChecker -from astroid import nodes, Const, AssignName - - -class NoPackageName(BaseChecker): - """ - Conanfile used for testing a package should NOT provide a name - """ - - __implements__ = IAstroidChecker - - name = "conan-test-package-name" - msgs = { - "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: - 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): - self.add_message("conan-test-no-name", node=attr, line=attr.lineno) diff --git a/linter/check_package_name.py b/linter/check_package_name.py index d2901a6144fd16..9068241f96b18a 100644 --- a/linter/check_package_name.py +++ b/linter/check_package_name.py @@ -1,6 +1,7 @@ from pylint.checkers import BaseChecker from pylint.interfaces import IAstroidChecker from astroid import nodes, Const, AssignName +from pathlib import Path class PackageName(BaseChecker): @@ -21,10 +22,18 @@ class PackageName(BaseChecker): "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_package/*.py') or filename.match('test_v1_package/*.py') + if node.basenames == ['ConanFile']: for attr in node.body: children = list(attr.get_children()) @@ -32,8 +41,12 @@ def visit_classdef(self, node: nodes) -> None: 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 - self.add_message("conan-missing-name", node=node) + if not is_test: + self.add_message("conan-missing-name", node=node) diff --git a/linter/conanv2_test_transition.py b/linter/conanv2_test_transition.py deleted file mode 100644 index 105891a947bd05..00000000000000 --- a/linter/conanv2_test_transition.py +++ /dev/null @@ -1,20 +0,0 @@ -""" - -Pylint plugin/rules for test_package folder in Conan Center Index - -""" - -from pylint.lint import PyLinter -from linter.check_import_conanfile import ImportConanFile -from linter.check_no_test_package_name import NoPackageName -from linter.check_import_errors import ImportErrorsConanException, ImportErrorsConanInvalidConfiguration, ImportErrors -from linter.check_import_tools import ImportTools - - -def register(linter: PyLinter) -> None: - linter.register_checker(NoPackageName(linter)) - linter.register_checker(ImportConanFile(linter)) - linter.register_checker(ImportErrors(linter)) - linter.register_checker(ImportErrorsConanException(linter)) - linter.register_checker(ImportErrorsConanInvalidConfiguration(linter)) - linter.register_checker(ImportTools(linter)) diff --git a/linter/pylintrc_testpackage b/linter/pylintrc_testpackage index 70d2a6ad148643..94930dfb9465e1 100644 --- a/linter/pylintrc_testpackage +++ b/linter/pylintrc_testpackage @@ -1,7 +1,8 @@ [MASTER] -load-plugins=linter.conanv2_test_transition, +load-plugins=linter.conanv2_transition, linter.transform_conanfile, linter.transform_imports + py-version=3.6 recursive=no suggestion-mode=yes