Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: lint code using pylint #778

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ jobs:
- { python-version: "3.11", session: "flake8", runs-on: "macos-12" }
- { python-version: "3.11", session: "flake8", runs-on: "windows-2022" }
- { python-version: "3.11", session: "safety" }
- { python-version: "3.11", session: "pylint" }
- { python-version: "3.11", session: "pylint", runs-on: "macos-12" }
- { python-version: "3.11", session: "pylint", runs-on: "windows-2022" }
- { python-version: "3.10", session: "pylint" }
- { python-version: "3.9", session: "pylint" }
- { python-version: "3.8", session: "pylint" }
- { python-version: "3.11", session: "mypy" }
- { python-version: "3.11", session: "mypy", runs-on: "macos-12" }
- { python-version: "3.11", session: "mypy", runs-on: "windows-2022" }
Expand Down
3 changes: 3 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

import gptsum

# pylint: disable=invalid-name, redefined-builtin


project = "gptsum"
author = "Nicolas Trangez"
copyright = f"{datetime.now().year}, {author}" # noqa: A001
Expand Down
40 changes: 38 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

from nox_poetry import Session, session

# pylint: disable=redefined-outer-name


PACKAGE = "gptsum"

PYTHON_VERSIONS = [
Expand Down Expand Up @@ -51,6 +54,39 @@ def flake8(session: Session) -> None:
session.run("flake8", *args)


@session(python=PYTHON_VERSIONS)
def pylint(session: Session) -> None:
"""Lint using pylint."""
args = session.posargs or SOURCES

noxdeps = [
"nox-poetry",
]
# Don't use `nox-poetry`'s `Session`, but its inner `nox` `Session`
# Rationale: `nox`, `nox-poetry` and others aren't managed by Poetry, hence
# their versions (and versions of dependencies) aren't tracked in `poetry.lock`.
# Moreover, these can conflict with versions kept in
# `.github/workflows/constraints.txt`. Hence, install the version of `nox-poetry`
# we'd use in CI, by only using the relevant constraints file.
assert hasattr(session.poetry, "session") # Make MyPy happy
session.poetry.session.install(
"--constraint=.github/workflows/constraints.txt", *noxdeps
)

session.install(".")

deps = [
"pylint",
"pytest",
"pytest-mock",
"pytest-benchmark",
]

session.install(*deps)

session.run("pylint", *args)


@session(python=PYTHON_VERSIONS[-1])
def safety(session: Session) -> None:
"""Scan dependencies for insecure packages."""
Expand Down Expand Up @@ -95,7 +131,7 @@ def tests(session: Session) -> None:
env = {
"COVERAGE_FILE": os.environ.get(
"COVERAGE_FILE",
".coverage.{}.py{}.{}".format(session.name, session.python, sys.platform),
f".coverage.{session.name}.py{session.python}.{sys.platform}",
),
}

Expand All @@ -111,7 +147,7 @@ def tests(session: Session) -> None:
def coverage(session: Session) -> None:
"""Produce the coverage report."""
# Do not use session.posargs unless this is the only session.
nsessions = len(session._runner.manifest)
nsessions = len(session._runner.manifest) # pylint: disable=protected-access
has_args = session.posargs and nsessions == 1
args = session.posargs if has_args else ["report"]

Expand Down
Loading