-
Notifications
You must be signed in to change notification settings - Fork 1
/
noxfile.py
87 lines (74 loc) · 2.79 KB
/
noxfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"""Script for nox sessions."""
import sys
from pathlib import Path
from textwrap import dedent
import nox
try:
# uses poetry inside nox to ensure replicable
# if not then only testing local installation of package
# rather than testing by downloading the .whl and installing as per
# pyproject.toml and then running tests
# more info at official docs here:
# https://github.com/cjolowicz/nox-poetry#why
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
# package name and to set which versions to run locally
# when run in github actions the following is passed
# --python=${{ matrix.python-version }}
# which dictates which version of python is run on each runner
package = "tennisim"
python_versions = ["3.9", "3.8", "3.7"]
nox.needs_version = ">= 2021.6.6"
# options for nox sessions
# again, github actions will pass one of these through the following lines
# env:
# NOXSESSION: ${{ matrix.session }}
nox.options.sessions = ("mypy", "tests")
# type checks code
@session(python=python_versions)
def mypy(session: Session) -> None:
"""Type-check using mypy."""
args = session.posargs or ["src", "tests"]
session.install(".")
session.install("mypy", "pytest", "types-toml")
session.run("mypy", *args)
if not session.posargs:
session.run(
"mypy", f"--python-executable={sys.executable}", "noxfile.py"
)
# runs test suite using pytest
# also returns coverage report
@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 being run by human and not CI process (GitHub Actions)
if session.interactive:
# then run the coverage (below) nox session
session.notify("coverage", posargs=[])
# session to check coverage of tests
@session
def coverage(session: Session) -> None:
"""Produce the coverage report."""
args = session.posargs or ["report"]
session.install("coverage[toml]")
# usually coverage tests run on different machines
# when they run they dump coverage data into .coverage. path
# this ensures that when run it combines all the files
# see here:
# https://coverage.readthedocs.io/en/stable/cmd.html#cmd-combine
if not session.posargs and any(Path().glob(".coverage.*")):
session.run("coverage", "combine")
session.run("coverage", *args)