-
Notifications
You must be signed in to change notification settings - Fork 47
/
noxfile.py
107 lines (82 loc) · 3.08 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
101
102
103
104
105
106
107
import itertools
import shutil
from pathlib import Path
import nox
from nox.sessions import Session
nox.options.sessions = ["tests", "lint", "docs"]
nox.options.reuse_existing_virtualenvs = True
# Run tests with (at least) the oldest and newest versions we support.
# If these are modified, also modify .github/workflows/tests.yml and the list of supported versions
# in setup.py.
@nox.session(python=["3.7", "3.10"])
def tests(session: Session) -> None:
session.install(".", "pytest")
session.run("pytest", *session.posargs)
LINTED_PATHS = {
str(p.resolve())
for p in itertools.chain(
# All top-level Python files.
Path(".").glob("*.py"),
# Plus Python files in these specified directories.
*(Path(d).glob("**/*.py") for d in ("pygdbmi", "tests"))
)
}
ISORT_OPTIONS = ["--profile", "black", "--lines-after-imports", "2"]
# `format` is a builtin so the function is named differently.
@nox.session(name="format")
def format_(session: Session) -> None:
"""Re-format all Python source files or, if positionals are passed, only the
specified files."""
files = LINTED_PATHS
if session.posargs:
# Only use positional arguments which are linted files.
files = files & {str(Path(f).resolve()) for f in session.posargs}
session.install("isort", "black", "flake8", "mypy", "check-manifest")
session.run("isort", *ISORT_OPTIONS, *files)
session.run("black", *files)
@nox.session()
def lint(session: Session) -> None:
session.install(
# Packages needed as they are used directly.
"black",
"check-manifest",
"flake8",
"isort",
"mypy",
# Packages needed to provide types for mypy.
"nox",
"pytest",
)
session.run("isort", "--check-only", *ISORT_OPTIONS, *LINTED_PATHS)
session.run("black", "--check", *LINTED_PATHS)
session.run("flake8", *LINTED_PATHS)
session.run("mypy", *LINTED_PATHS)
session.run("check-manifest")
session.run("python", "setup.py", "check", "--metadata", "--strict")
def install_mkdoc_dependencies(session: Session) -> None:
session.install("-r", "mkdoc_requirements.txt")
@nox.session
def docs(session: Session) -> None:
install_mkdoc_dependencies(session)
session.run("mkdocs", "build")
@nox.session
def serve_docs(session: Session) -> None:
install_mkdoc_dependencies(session)
session.run("mkdocs", "serve")
@nox.session
def publish_docs(session: Session) -> None:
install_mkdoc_dependencies(session)
session.run("mkdocs", "gh-deploy")
@nox.session(python="3.7")
def build(session: Session) -> None:
session.install("setuptools", "wheel", "twine")
shutil.rmtree("dist", ignore_errors=True)
shutil.rmtree("build", ignore_errors=True)
session.run("python", "setup.py", "--quiet", "sdist", "bdist_wheel")
session.run("twine", "check", "dist/*")
@nox.session(python="3.7")
def publish(session: Session) -> None:
build(session)
print("REMINDER: Has the changelog been updated?")
session.run("python", "-m", "twine", "upload", "dist/*")
publish_docs(session)