From ea4b0eb60f90685c864bd485284852c9a89adb9d Mon Sep 17 00:00:00 2001 From: Alex Maystrenko Date: Wed, 4 Jan 2023 21:18:37 +0100 Subject: [PATCH 1/3] determine test_package folder in the lint rule --- linter/check_package_name.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/linter/check_package_name.py b/linter/check_package_name.py index d2901a6144fd1..9068241f96b18 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) From 3fbdb1658c6f476044c739975f38982abf2cc625 Mon Sep 17 00:00:00 2001 From: Chris Mc Date: Mon, 17 Apr 2023 13:00:10 -0700 Subject: [PATCH 2/3] delete old test specific linter config + update github workflow --- .github/workflows/linter-conan-v2.yml | 4 ++-- linter/check_no_test_package_name.py | 30 --------------------------- linter/conanv2_test_transition.py | 20 ------------------ linter/pylintrc_testpackage | 27 ------------------------ 4 files changed, 2 insertions(+), 79 deletions(-) delete mode 100644 linter/check_no_test_package_name.py delete mode 100644 linter/conanv2_test_transition.py delete mode 100644 linter/pylintrc_testpackage diff --git a/.github/workflows/linter-conan-v2.yml b/.github/workflows/linter-conan-v2.yml index 9b437a26e46d8..aaf0585f42575 100644 --- a/.github/workflows/linter-conan-v2.yml +++ b/.github/workflows/linter-conan-v2.yml @@ -53,7 +53,7 @@ jobs: if: steps.changed_files.outputs.any_changed == 'true' run: | echo '## Linter summary (test_package)' >> $GITHUB_STEP_SUMMARY - pylint --rcfile=linter/pylintrc_testpackage `ls recipes/*/*/test_package/conanfile.py | shuf -n 500` --output-format=json --output=recipes.json --exit-zero + pylint --rcfile=linter/pylintrc_recipe `ls recipes/*/*/test_package/conanfile.py | shuf -n 500` --output-format=json --output=recipes.json --exit-zero jq '[map( select(.type=="error")) | group_by (.message)[] | {message: .[0].message, length: length}] | sort_by(.length) | reverse' recipes.json > recipes2.json jq -r '.[] | " * \(.message): \(.length)"' recipes2.json >> $GITHUB_STEP_SUMMARY @@ -120,5 +120,5 @@ jobs: run: | echo "::add-matcher::linter/recipe_linter.json" for file in ${{ steps.changed-files.outputs.all_changed_files }}; do - pylint --rcfile=linter/pylintrc_testpackage --ignore-paths="recipes/[^/]*/[^/]*/test_v1[^/]*/conanfile.py" --output-format=parseable ${file} + pylint --rcfile=linter/pylintrc_recipe --ignore-paths="recipes/[^/]*/[^/]*/test_v1[^/]*/conanfile.py" --output-format=parseable ${file} done diff --git a/linter/check_no_test_package_name.py b/linter/check_no_test_package_name.py deleted file mode 100644 index 6a927475b4bb9..0000000000000 --- 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/conanv2_test_transition.py b/linter/conanv2_test_transition.py deleted file mode 100644 index 105891a947bd0..0000000000000 --- 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 deleted file mode 100644 index 70d2a6ad14864..0000000000000 --- a/linter/pylintrc_testpackage +++ /dev/null @@ -1,27 +0,0 @@ -[MASTER] -load-plugins=linter.conanv2_test_transition, - linter.transform_conanfile, - linter.transform_imports -py-version=3.6 -recursive=no -suggestion-mode=yes -unsafe-load-any-extension=no - -[MESSAGES CONTROL] -disable=fixme, - line-too-long, - missing-module-docstring, - missing-function-docstring, - missing-class-docstring, - invalid-name, - wrong-import-order, # TODO: Remove - import-outside-toplevel # TODO: Remove - -enable=conan-test-no-name, - conan-import-conanfile - -[REPORTS] -evaluation=max(0, 0 if fatal else 10.0 - ((float(5 * error) / statement) * 10)) -output-format=text -reports=no -score=no From cdddf12c8a240664bc38bf42b77919cfca472602 Mon Sep 17 00:00:00 2001 From: Chris Mc Date: Mon, 17 Apr 2023 13:29:10 -0700 Subject: [PATCH 3/3] fixup: put bad specific config --- .github/workflows/linter-conan-v2.yml | 4 ++-- linter/pylintrc_testpackage | 28 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 linter/pylintrc_testpackage diff --git a/.github/workflows/linter-conan-v2.yml b/.github/workflows/linter-conan-v2.yml index aaf0585f42575..9b437a26e46d8 100644 --- a/.github/workflows/linter-conan-v2.yml +++ b/.github/workflows/linter-conan-v2.yml @@ -53,7 +53,7 @@ jobs: if: steps.changed_files.outputs.any_changed == 'true' run: | echo '## Linter summary (test_package)' >> $GITHUB_STEP_SUMMARY - pylint --rcfile=linter/pylintrc_recipe `ls recipes/*/*/test_package/conanfile.py | shuf -n 500` --output-format=json --output=recipes.json --exit-zero + pylint --rcfile=linter/pylintrc_testpackage `ls recipes/*/*/test_package/conanfile.py | shuf -n 500` --output-format=json --output=recipes.json --exit-zero jq '[map( select(.type=="error")) | group_by (.message)[] | {message: .[0].message, length: length}] | sort_by(.length) | reverse' recipes.json > recipes2.json jq -r '.[] | " * \(.message): \(.length)"' recipes2.json >> $GITHUB_STEP_SUMMARY @@ -120,5 +120,5 @@ jobs: run: | echo "::add-matcher::linter/recipe_linter.json" for file in ${{ steps.changed-files.outputs.all_changed_files }}; do - pylint --rcfile=linter/pylintrc_recipe --ignore-paths="recipes/[^/]*/[^/]*/test_v1[^/]*/conanfile.py" --output-format=parseable ${file} + pylint --rcfile=linter/pylintrc_testpackage --ignore-paths="recipes/[^/]*/[^/]*/test_v1[^/]*/conanfile.py" --output-format=parseable ${file} done diff --git a/linter/pylintrc_testpackage b/linter/pylintrc_testpackage new file mode 100644 index 0000000000000..94930dfb9465e --- /dev/null +++ b/linter/pylintrc_testpackage @@ -0,0 +1,28 @@ +[MASTER] +load-plugins=linter.conanv2_transition, + linter.transform_conanfile, + linter.transform_imports + +py-version=3.6 +recursive=no +suggestion-mode=yes +unsafe-load-any-extension=no + +[MESSAGES CONTROL] +disable=fixme, + line-too-long, + missing-module-docstring, + missing-function-docstring, + missing-class-docstring, + invalid-name, + wrong-import-order, # TODO: Remove + import-outside-toplevel # TODO: Remove + +enable=conan-test-no-name, + conan-import-conanfile + +[REPORTS] +evaluation=max(0, 0 if fatal else 10.0 - ((float(5 * error) / statement) * 10)) +output-format=text +reports=no +score=no