summaryrefslogtreecommitdiff
path: root/noxfile.py
blob: d1337f4646723d7acf6b45782711b4cfa95f49e6 (plain)
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
import nox
import urllib.request
import re
from pathlib import Path

nox.options.sessions = ["lint", "tests"]

ALL_PYTHONS = ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]

@nox.session
def lint(session: nox.Session) -> None:
    """
    Run the linter.
    """
    session.install("pre-commit")
    session.run(
        "pre-commit", "run", "--all-files", "--hook-stage=manual", *session.posargs
    )


@nox.session
def build(session: nox.Session) -> None:
    """
    Build an SDist and wheel.
    """

    session.install("build")
    session.run("python", "-m", "build")


@nox.session
def update(session: nox.Session) -> None:
    """
    Get the latest (or given) version of CMake and update the copy with it.
    """

    if session.posargs:
        (version,) = session.posargs
    else:
        session.install("lastversion")
        version = session.run(
            "lastversion", "kitware/cmake", log=False, silent=True
        ).strip()
        session.log(f"CMake {version}")

    cmake_url = f"https://raw.githubusercontent.com/Kitware/CMake/v{version}/Utilities/Sphinx/cmake.py"
    colors_url = f"https://raw.githubusercontent.com/Kitware/CMake/v{version}/Utilities/Sphinx/colors.py"

    urllib.request.urlretrieve(cmake_url, "sphinxcontrib/moderncmakedomain/cmake.py")
    urllib.request.urlretrieve(colors_url, "sphinxcontrib/moderncmakedomain/colors.py")

    init_file = Path("sphinxcontrib/moderncmakedomain/__init__.py")
    txt = init_file.read_text(encoding="utf_8")
    txt_new = re.sub(r'__version__ = ".*"', f'__version__ = "{version}"', txt)
    init_file.write_text(txt_new, encoding="utf_8")


@nox.session(python=ALL_PYTHONS)
def tests(session):
    """
    Run the unit and regular tests.
    """
    # Setuptools is required due to sphinx installing sphinxcontrib extensions that use pkg_resources (fixed upstream but not released yet)
    session.install(".", "pytest", "setuptools")
    session.run("pytest", *session.posargs)