Skip to content

Commit

Permalink
Use .pylintrc files (opensearch-project#654)
Browse files Browse the repository at this point in the history
* switched pylint to a .pylintrc based config

Signed-off-by: Mark Cohen <markcoh@amazon.com>

* added invalid-name pylint disable instruction because the framework requires camel case instead of snake case

Signed-off-by: Mark Cohen <markcoh@amazon.com>

---------

Signed-off-by: Mark Cohen <markcoh@amazon.com>
  • Loading branch information
macohen authored Jan 19, 2024
1 parent 0ddbf8c commit 7c66e8c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 59 deletions.
7 changes: 7 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -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]?$

64 changes: 6 additions & 58 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# under the License.


from typing import Any, List
from typing import Any

import nox

Expand Down Expand Up @@ -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)

Expand All @@ -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:
"""
Expand Down
5 changes: 5 additions & 0 deletions opensearchpy/.pylintrc
Original file line number Diff line number Diff line change
@@ -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]?$
10 changes: 10 additions & 0 deletions test_opensearchpy/.pylintrc
Original file line number Diff line number Diff line change
@@ -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]?$
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 7c66e8c

Please sign in to comment.