Skip to content

Commit

Permalink
add linting and testing with nox
Browse files Browse the repository at this point in the history
  • Loading branch information
shadycuz committed Jun 6, 2022
1 parent 44088a2 commit 8a3ceef
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ select = ANN,B,B9,BLK,C,D,DAR,E,F,I,S,W
ignore = E203,E501,W503
max-line-length = 120
max-complexity = 10
application-import-names = hypermodern_python,tests
application-import-names = cf2tf,tests
import-order-style = google
docstring-convention = google
per-file-ignores = tests/*:S101
7 changes: 7 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[mypy]

[mypy-nox.*]
ignore_missing_imports = True

[mypy-click_log.*]
ignore_missing_imports = True
90 changes: 90 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"""Nox sessions."""

import nox
import sys
from pathlib import Path

from textwrap import dedent

try:
from nox_poetry import Session
from nox_poetry import session
except ImportError:
message = f"""\
Nox failed to import the 'nox-poetry' package.
Please install it using the following command:
{sys.executable} -m pip install nox-poetry"""
raise SystemExit(dedent(message)) from None


python_versions = ["3.10", "3.9", "3.8", "3.7"]

nox.options.sessions = (
# "pre-commit",
# "safety",
# "mypy",
"black",
"lint",
"mypy",
"tests",
# "typeguard",
# "xdoctest",
# "docs-build",
)

locations = "src", "tests", "noxfile.py"


@session(python=python_versions[1])
def black(session):
args = session.posargs or locations
session.install("black")
session.run("black", *args)


@session(python=python_versions[1])
def lint(session):
args = session.posargs or locations
session.install("flake8")
session.run("flake8", *args)


@session(python=python_versions[1])
def mypy(session: Session) -> None:
"""Type-check using mypy."""
args = session.posargs or [
"--install-types",
"--non-interactive",
"src",
"tests",
]
session.install(".")
session.install("mypy", "pytest")
session.run("mypy", *args)
if not session.posargs:
session.run("mypy", f"--python-executable={sys.executable}", "noxfile.py")


@session(python=python_versions)
def tests(session: Session) -> None:
"""Run the test suite."""
session.install(".")
session.install("coverage[toml]", "pytest", "pygments")
try:
session.run("coverage", "run", "--parallel", "-m", "pytest", *session.posargs)
finally:
if session.interactive:
session.notify("coverage", posargs=[])


@session(python=python_versions[1])
def coverage(session: Session) -> None:
"""Produce the coverage report."""
args = session.posargs or ["report"]

session.install("coverage[toml]")

if not session.posargs and any(Path().glob(".coverage.*")):
session.run("coverage", "combine")

session.run("coverage", *args)

0 comments on commit 8a3ceef

Please sign in to comment.