forked from omry/omegaconf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
noxfile.py
100 lines (79 loc) · 3.53 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
88
89
90
91
92
93
94
95
96
97
98
99
100
import os
from typing import Tuple
import nox
from nox import Session
DEFAULT_PYTHON_VERSIONS = ["3.8", "3.9", "3.10", "3.11"]
PYTHON_VERSIONS = os.environ.get(
"NOX_PYTHON_VERSIONS", ",".join(DEFAULT_PYTHON_VERSIONS)
).split(",")
nox.options.error_on_missing_interpreters = True
def deps(
session: Session, editable_install: bool, requirements: str = "requirements/dev.txt"
) -> None:
session.install("--upgrade", "setuptools", "pip")
extra_flags = ["-e"] if editable_install else []
session.install("-r", requirements, *extra_flags, ".", silent=True)
@nox.session(python=PYTHON_VERSIONS) # type: ignore
def omegaconf(session: Session) -> None:
deps(session, editable_install=False) # ensure we test the regular install
session.run("pytest")
@nox.session(python=PYTHON_VERSIONS) # type: ignore
def benchmark(session: Session) -> None:
deps(session, editable_install=True)
session.run("pytest", "benchmark/benchmark.py")
@nox.session # type: ignore
def docs(session: Session) -> None:
deps(session, False, "requirements/docs.txt")
session.chdir("docs")
session.run("sphinx-build", "-W", "-b", "html", "source", "build")
session.install("pytest") # required for `sphinx-build -b doctest`:
session.run("sphinx-build", "-W", "-b", "doctest", "source", "build")
@nox.session(python=PYTHON_VERSIONS) # type: ignore
def coverage(session: Session) -> None:
# For coverage, we must use the editable installation because
# `coverage run -m pytest` prepends `sys.path` with "." (the current
# folder), so that the local code will be used in tests even if we set
# `editable_install=False`. This would cause problems due to potentially
# missing the generated grammar files.
deps(session, editable_install=True)
session.run("coverage", "erase")
session.run("coverage", "run", "--append", "-m", "pytest", silent=True)
session.run("coverage", "report", "--fail-under=100")
# report to coveralls
session.run("coveralls", success_codes=[0, 1])
session.run("coverage", "erase")
def version_string_to_tuple(version: str) -> Tuple[int, ...]:
return tuple(map(int, version.split(".")))
@nox.session(python=PYTHON_VERSIONS) # type: ignore
def lint(session: Session) -> None:
deps(session, editable_install=True)
session.run(
"mypy", ".", "--strict", "--install-types", "--non-interactive", silent=True
)
session.run("isort", ".", "--check", silent=True)
session.run("black", "--check", ".", silent=True)
session.run("flake8")
@nox.session(python=PYTHON_VERSIONS) # type: ignore
def test_jupyter_notebook(session: Session) -> None:
if session.python not in DEFAULT_PYTHON_VERSIONS:
session.skip(
"Not testing Jupyter notebook on Python {}, supports [{}]".format(
session.python, ",".join(DEFAULT_PYTHON_VERSIONS)
)
)
deps(session, editable_install=False)
session.install("jupyter", "nbval")
extra_flags = ["-Wignore::ResourceWarning"]
extra_flags.extend(
[
# Ignore deprecation warnings raised by jupyter_client in Python 3.10
# https://github.com/jupyter/jupyter_client/issues/713
"-Wdefault:There is no current event loop:DeprecationWarning",
# Block warning issued by nbval
# https://github.com/computationalmodelling/nbval/issues/180
"-Wdefault::pytest.PytestRemovedIn8Warning",
]
)
session.run(
"pytest", "--nbval", "docs/notebook/Tutorial.ipynb", *extra_flags, silent=True
)