-
Notifications
You must be signed in to change notification settings - Fork 3
/
noxfile.py
74 lines (52 loc) · 2.64 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
"""Nox file."""
from __future__ import annotations
import logging
import pathlib
import typing
import nox
nox.options.sessions = ["reformat", "lint", "type-check"]
nox.options.reuse_existing_virtualenvs = True
PACKAGE = "arkprtserver"
GENERAL_TARGETS = ["./arkprtserver", "./noxfile.py"]
PYRIGHT_ENV = {"PYRIGHT_PYTHON_FORCE_VERSION": "latest"}
LOGGER = logging.getLogger("nox")
def isverbose() -> bool:
"""Whether the verbose flag is set."""
return LOGGER.getEffectiveLevel() == logging.DEBUG - 1
def verbose_args() -> typing.Sequence[str]:
"""Return --verbose if the verbose flag is set."""
return ["--verbose"] if isverbose() else []
def install_requirements(session: nox.Session, *requirements: str, literal: bool = False) -> None:
"""Install requirements."""
if not literal and all(requirement.isalpha() for requirement in requirements):
files = ["requirements.txt"]
files += [f"./dev-requirements/{requirement}.txt" for requirement in requirements]
requirements = tuple(arg for file in files for arg in ("-r", file))
session.install("--upgrade", "pip", *requirements, silent=not isverbose())
@nox.session()
def lint(session: nox.Session) -> None:
"""Run this project's modules against ruff."""
install_requirements(session, "lint")
session.run("python", "-m", "ruff", "check", *GENERAL_TARGETS, *verbose_args())
session.run("python", "-m", "slotscheck", "-m", PACKAGE, *verbose_args())
@nox.session()
def reformat(session: nox.Session) -> None:
"""Reformat this project's modules to fit the standard style."""
install_requirements(session, "reformat")
session.run("python", "-m", "black", *GENERAL_TARGETS, *verbose_args())
session.run("python", "-m", "ruff", "check", "--fix-only", "--fixable", "ALL", *GENERAL_TARGETS, *verbose_args())
session.log("sort-all")
LOGGER.disabled = True
session.run("sort-all", *map(str, pathlib.Path(PACKAGE).glob("**/*.py")), success_codes=[0, 1])
LOGGER.disabled = False
@nox.session(name="type-check")
def type_check(session: nox.Session) -> None:
"""Statically analyse and veirfy this project using pyright and mypy."""
install_requirements(session, "typecheck")
session.run("pyright", PACKAGE, *verbose_args(), env=PYRIGHT_ENV)
@nox.session(name="verify-types")
def verify_types(session: nox.Session) -> None:
"""Verify the "type completeness" of types exported by the library using pyright."""
install_requirements(session, ".", "--force-reinstall", "--no-deps")
install_requirements(session, "typecheck")
session.run("pyright", "--verifytypes", PACKAGE, "--ignoreexternal", *verbose_args(), env=PYRIGHT_ENV)