From c92190d2b7b5ceb79f659ca40eb501ca1a3bdf29 Mon Sep 17 00:00:00 2001
From: Frederik Hennig <frederik.hennig@fau.de>
Date: Mon, 13 Jan 2025 14:59:24 +0100
Subject: [PATCH] Add docs session to nox; adapt CI

---
 .gitlab-ci.yml |  9 +++------
 noxfile.py     | 40 ++++++++++++++++++++++++++++------------
 pyproject.toml |  4 +++-
 3 files changed, 34 insertions(+), 19 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 901eee0ec..0ab7cf354 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -311,14 +311,11 @@ tests-and-coverage:
 
 
 build-documentation:
-  image: i10git.cs.fau.de:5005/pycodegen/pycodegen/full:cupy12.3
+  image: i10git.cs.fau.de:5005/pycodegen/pycodegen/nox:ubuntu24.04-cuda12
   stage: docs
   needs: []
-  before_script:
-    - pip install -e .[doc]
   script:
-    - cd docs
-    - make html SPHINXOPTS="-W --keep-going"
+    - nox --session docs
   tags:
     - docker
     - cuda11
@@ -328,7 +325,7 @@ build-documentation:
 
 
 pages:
-  image: i10git.cs.fau.de:5005/pycodegen/pycodegen/full
+  image: alpine:latest
   stage: deploy
   needs: ["tests-and-coverage", "build-documentation"]
   script:
diff --git a/noxfile.py b/noxfile.py
index 876d7a914..a4b110191 100644
--- a/noxfile.py
+++ b/noxfile.py
@@ -15,7 +15,7 @@ def get_cuda_version() -> None | tuple[int, ...]:
         result = subprocess.run(smi_args, capture_output=True)
     except FileNotFoundError:
         return None
-    
+
     smi_output = str(result.stdout).splitlines()
     cuda_version = smi_output[-1].split(":")[1].strip()
     return tuple(int(v) for v in cuda_version.split("."))
@@ -45,18 +45,16 @@ def typecheck(session: nox.Session):
     session.run("mypy", "src/pystencils")
 
 
-@nox.parametrize(
-    "cupy_version",
-    [None, "12", "13"],
-    ids=["cpu", "cupy12", "cupy13"]
-)
+@nox.parametrize("cupy_version", [None, "12", "13"], ids=["cpu", "cupy12", "cupy13"])
 @nox.session(python="3.10", tags=["test"])
 def testsuite(session: nox.Session, cupy_version: str | None):
     if cupy_version is not None:
         cuda_version = get_cuda_version()
         if cuda_version is None or cuda_version[0] < 11:
-            session.skip("No compatible installation of CUDA found - Need at least CUDA 11")
-        
+            session.skip(
+                "No compatible installation of CUDA found - Need at least CUDA 11"
+            )
+
         cuda_major = cuda_version[0]
         cupy_package = f"cupy-cuda{cuda_major}=={cupy_version}"
         session.install(cupy_package)
@@ -68,12 +66,30 @@ def testsuite(session: nox.Session, cupy_version: str | None):
     session.run(
         "pytest",
         "-v",
-        "-n", str(num_cores),
+        "-n",
+        str(num_cores),
         "--cov-report=term",
         "--cov=.",
-        "-m", "not longrun",
-        "--html", "test-report/index.html",
-        "--junitxml=report.xml"
+        "-m",
+        "not longrun",
+        "--html",
+        "test-report/index.html",
+        "--junitxml=report.xml",
     )
     session.run("coverage", "html")
     session.run("coverage", "xml")
+
+
+@nox.session(python=["3.10"], tags=["docs"])
+def docs(session: nox.Session):
+    """Build the documentation pages"""
+    editable_install(session, ["doc"])
+    session.chdir("docs")
+    session.run(
+        "make",
+        "html",
+        external=True,
+        env={
+            "SPHINXOPTS": "-W --keep-going"
+        }
+    )
diff --git a/pyproject.toml b/pyproject.toml
index 4f4cad8e7..c0404a720 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -57,7 +57,9 @@ doc = [
     'sphinx_autodoc_typehints',
     'pandoc',
     'sphinx_design',
-    'myst-nb'
+    'myst-nb',
+    'matplotlib',
+    'graphviz',
 ]
 testsuite = [
     'pytest',
-- 
GitLab