From 7c66e8cf3d2194820ef54cbcd1797323e8b8b8b8 Mon Sep 17 00:00:00 2001 From: Mark Cohen Date: Fri, 19 Jan 2024 16:17:32 -0500 Subject: [PATCH] Use .pylintrc files (#654) * switched pylint to a .pylintrc based config Signed-off-by: Mark Cohen * added invalid-name pylint disable instruction because the framework requires camel case instead of snake case Signed-off-by: Mark Cohen --------- Signed-off-by: Mark Cohen --- .pylintrc | 7 ++ noxfile.py | 64 ++----------------- opensearchpy/.pylintrc | 5 ++ test_opensearchpy/.pylintrc | 10 +++ .../test_security_plugin.py | 2 +- 5 files changed, 29 insertions(+), 59 deletions(-) create mode 100644 .pylintrc create mode 100644 opensearchpy/.pylintrc create mode 100644 test_opensearchpy/.pylintrc diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 00000000..2e58f1d5 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,7 @@ +[MESSAGES CONTROL] +disable=all +enable=line-too-long,invalid-name,pointless-statement,unspecified-encoding, + missing-function-docstring,missing-param-doc,differing-param-doc +max-line-length=240 +good-names-rgxs=^[_a-z][_a-z0-9]?$ + diff --git a/noxfile.py b/noxfile.py index a2834692..e0cbe53f 100644 --- a/noxfile.py +++ b/noxfile.py @@ -25,7 +25,7 @@ # under the License. -from typing import Any, List +from typing import Any import nox @@ -102,7 +102,11 @@ def lint(session: Any) -> None: session.run("black", "--check", *SOURCE_FILES) session.run("flake8", *SOURCE_FILES) - lint_per_folder(session) + pylint_overrides = ["opensearchpy/", "test_opensearchpy/"] + pylint_defaults = [file for file in SOURCE_FILES if file not in pylint_overrides] + for file in pylint_overrides: + session.run("pylint", "--rcfile", f"{file}.pylintrc", f"{file}") + session.run("pylint", "--rcfile", ".pylintrc", *pylint_defaults) session.run("python", "utils/license_headers.py", "check", *SOURCE_FILES) @@ -122,62 +126,6 @@ def lint(session: Any) -> None: session.run("mypy", "--strict", "test_opensearchpy/test_types/sync_types.py") -def lint_per_folder(session: Any) -> None: - """ - allows configuration of pylint rules per folder and runs a pylint command for each folder - :param session: the current nox session - """ - - # any paths that should not be run through pylint - exclude_path_from_linting: List[str] = [] - - # all paths not referenced in override_enable will run these lints - default_enable = [ - "line-too-long", - "invalid-name", - "pointless-statement", - "unspecified-encoding", - "missing-function-docstring", - "missing-param-doc", - "differing-param-doc", - ] - override_enable = { - "test_opensearchpy/": [ - "line-too-long", - # "invalid-name", lots of short functions with one or two character names - "pointless-statement", - "unspecified-encoding", - "missing-param-doc", - "differing-param-doc", - # "missing-function-docstring", test names usually are, self describing - ], - "opensearchpy/": [ - "line-too-long", - "invalid-name", - "pointless-statement", - "unspecified-encoding", - ], - } - - for source_file in SOURCE_FILES: - if source_file in exclude_path_from_linting: - continue - - args = [ - "--disable=all", - "--max-line-length=240", - "--good-names-rgxs=^[_a-z][_a-z0-9]?$", - "--load-plugins", - "pylint.extensions.docparams", - ] - if source_file in override_enable: - args.append(f"--enable={','.join(override_enable[source_file])}") - else: - args.append(f"--enable={','.join(default_enable)}") - args.append(source_file) - session.run("pylint", *args) - - @nox.session() # type: ignore def docs(session: Any) -> None: """ diff --git a/opensearchpy/.pylintrc b/opensearchpy/.pylintrc new file mode 100644 index 00000000..f9f7b38f --- /dev/null +++ b/opensearchpy/.pylintrc @@ -0,0 +1,5 @@ +[MESSAGES CONTROL] +disable=all +enable=line-too-long,invalid-name,pointless-statement,unspecified-encoding +max-line-length=240 +good-names-rgxs=^[_a-z][_a-z0-9]?$ \ No newline at end of file diff --git a/test_opensearchpy/.pylintrc b/test_opensearchpy/.pylintrc new file mode 100644 index 00000000..1e223125 --- /dev/null +++ b/test_opensearchpy/.pylintrc @@ -0,0 +1,10 @@ +[MESSAGES CONTROL] +disable=all +enable=line-too-long, + invalid-name, + pointless-statement, + unspecified-encoding, + missing-param-doc, + differing-param-doc +max-line-length=240 +good-names-rgxs=^[_a-z][_a-z0-9]?$ \ No newline at end of file diff --git a/test_opensearchpy/test_async/test_server_secured/test_security_plugin.py b/test_opensearchpy/test_async/test_server_secured/test_security_plugin.py index 926bade9..acf3d849 100644 --- a/test_opensearchpy/test_async/test_server_secured/test_security_plugin.py +++ b/test_opensearchpy/test_async/test_server_secured/test_security_plugin.py @@ -48,7 +48,7 @@ async def asyncSetUp(self) -> None: await add_connection("default", self.client) async def asyncTearDown(self) -> None: - # pylint disable=invalid-name + # pylint: disable=invalid-name if self.client: await self.client.close()