115 lines
3 KiB
Python
115 lines
3 KiB
Python
# Copyright (C) 2023 Maxwell G <maxwell@gtmx.me>
|
|
# SPDX-License-Identifier: GPL-1.0-or-later
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Sequence
|
|
from glob import iglob
|
|
from pathlib import Path
|
|
|
|
import nox
|
|
|
|
LINT_SESSIONS = ("static", "formatters", "typing")
|
|
PY_FILES = ("tests", "noxfile.py")
|
|
YAML_FILES = (".builds", "tests/vectors.yaml")
|
|
|
|
nox.options.sessions = (*LINT_SESSIONS, "test")
|
|
|
|
# Helpers
|
|
|
|
|
|
def install(session: nox.Session, *args, **kwargs):
|
|
# nox --no-venv
|
|
if isinstance(session.virtualenv, nox.virtualenv.PassthroughEnv):
|
|
session.warn(f"No venv. Skipping installation of {args}")
|
|
return
|
|
session.install(*args, **kwargs)
|
|
|
|
|
|
def git(session: nox.Session, *args, **kwargs):
|
|
return session.run("git", *args, **kwargs, external=True)
|
|
|
|
|
|
# General
|
|
|
|
|
|
@nox.session(venv_backend="none")
|
|
def lint(session: nox.Session):
|
|
"""
|
|
Run python linters
|
|
"""
|
|
for notify in LINT_SESSIONS:
|
|
session.notify(notify)
|
|
|
|
|
|
@nox.session
|
|
def static(session: nox.Session):
|
|
install(session, "ruff >= 0.2.0", "reuse", "yamllint", "shellcheck-py")
|
|
session.run("ruff", "check", *session.posargs, *PY_FILES)
|
|
session.run("yamllint", *YAML_FILES)
|
|
session.run("shellcheck", *iglob("tools/*.sh"))
|
|
session.run("reuse", "lint")
|
|
|
|
|
|
@nox.session
|
|
def formatters(session: nox.Session, posargs: Sequence[str] | None = None):
|
|
if posargs is None:
|
|
posargs = session.posargs
|
|
install(session, "black", "isort")
|
|
session.run("black", *posargs, *PY_FILES)
|
|
session.run("isort", *posargs, *PY_FILES)
|
|
|
|
|
|
@nox.session
|
|
def formatters_check(session: nox.Session):
|
|
formatters(session, ["--check"])
|
|
|
|
|
|
@nox.session
|
|
def typing(session: nox.Session):
|
|
install(session, "mypy", "nox", "pytest", "pyyaml", "types-pyyaml")
|
|
session.run("mypy", *session.posargs, *PY_FILES)
|
|
|
|
|
|
@nox.session
|
|
def test(session: nox.Session):
|
|
install(session, "pytest", "pyyaml")
|
|
session.run("pytest", *session.posargs)
|
|
|
|
|
|
@nox.session
|
|
def srpm(session: nox.Session, posargs: Sequence[str] | None = None):
|
|
install(session, "fclogr")
|
|
posargs = posargs or session.posargs
|
|
session.run("python3", "-m", "fclogr", "--debug", "dev-srpm", *posargs)
|
|
|
|
|
|
@nox.session
|
|
def mockbuild(session: nox.Session):
|
|
tmp = Path(session.create_tmp())
|
|
srpm(session, ("-o", str(tmp), "--keep"))
|
|
spec_path = tmp / "forge-srpm-macros.spec"
|
|
# fmt: off
|
|
margs = [
|
|
"mock",
|
|
"--spec", str(spec_path),
|
|
"--source", str(tmp),
|
|
*session.posargs,
|
|
]
|
|
# fmt: on
|
|
if not session.interactive:
|
|
margs.append("--verbose")
|
|
session.run(*margs, external=True)
|
|
|
|
|
|
@nox.session
|
|
def bump(session: nox.Session):
|
|
version = session.posargs[0]
|
|
# releaserr >= 0.1.dev115: First release that supports NEWS_FRAGMENT.md
|
|
install(session, "releaserr >= 0.1.dev115", "fclogr")
|
|
session.run("releaserr", "check-tag", version)
|
|
session.run(
|
|
"fclogr", "bump", "--new", version, "--comment", f"Update to {version}."
|
|
)
|
|
git(session, "add", "forge-srpm-macros.spec")
|
|
session.run("releaserr", "clog", version, "--tag")
|