Skip to content
Snippets Groups Projects
Commit 1f5a7b44 authored by Frederik Hennig's avatar Frederik Hennig
Browse files

introduce Nox and refactor CI

parent c5cf38b1
No related branches found
No related tags found
1 merge request!436Introduce Nox for Local and CI Test Automation. Start Writing a Contributors Guide.
Pipeline #71838 failed
__pycache__ __pycache__
.ipynb_checkpoints .ipynb_checkpoints
.coverage* .coverage*
coverage.xml
*.pyc *.pyc
*.vti *.vti
/build /build
......
...@@ -255,30 +255,25 @@ pycodegen-integration: ...@@ -255,30 +255,25 @@ pycodegen-integration:
# -------------------- Code Quality --------------------------------------------------------------------- # -------------------- Code Quality ---------------------------------------------------------------------
.qa-base:
flake8-lint:
stage: "Code Quality" stage: "Code Quality"
image: i10git.cs.fau.de:5005/pycodegen/pycodegen/nox:alpine
needs: []
except: except:
variables: variables:
- $ENABLE_NIGHTLY_BUILDS - $ENABLE_NIGHTLY_BUILDS
image: i10git.cs.fau.de:5005/pycodegen/pycodegen/full
script:
- flake8 src/pystencils
tags: tags:
- docker - docker
mypy-typecheck: lint:
stage: "Code Quality" extends: .qa-base
except:
variables:
- $ENABLE_NIGHTLY_BUILDS
image: i10git.cs.fau.de:5005/pycodegen/pycodegen/full
before_script:
- pip install -e .[tests]
script: script:
- mypy src/pystencils - nox --session lint
tags:
- docker typecheck:
extends: .qa-base
script:
- nox --session typecheck
# -------------------- Unit Tests --------------------------------------------------------------------- # -------------------- Unit Tests ---------------------------------------------------------------------
...@@ -286,18 +281,16 @@ mypy-typecheck: ...@@ -286,18 +281,16 @@ mypy-typecheck:
tests-and-coverage: tests-and-coverage:
stage: "Unit Tests" stage: "Unit Tests"
needs: [] needs: []
image: i10git.cs.fau.de:5005/pycodegen/pycodegen/full:cupy12.3 image: i10git.cs.fau.de:5005/pycodegen/pycodegen/nox:ubuntu24.04-cuda12
before_script: before_script:
- pip install -e .[tests] - pip install -e .[tests]
script: script:
- env - env
- pip list - pip list
- export NUM_CORES=$(nproc --all)
- mkdir -p ~/.config/matplotlib - mkdir -p ~/.config/matplotlib
- echo "backend:template" > ~/.config/matplotlib/matplotlibrc - echo "backend:template" > ~/.config/matplotlib/matplotlibrc
- mkdir public - mkdir public
- pytest -v -n $NUM_CORES --cov-report html --cov-report xml --cov-report term --cov=. -m "not longrun" --html test-report/index.html --junitxml=report.xml - nox --session "testsuite(cupy12)"
- python -m coverage xml
tags: tags:
- docker - docker
- cuda11 - cuda11
......
from __future__ import annotations
from typing import Sequence
import os
import nox
import subprocess
nox.options.sessions = ["lint", "typecheck", "testsuite"]
def get_cuda_version() -> None | tuple[int, ...]:
smi_args = ["nvidia-smi", "--version"]
try:
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("."))
def editable_install(session: nox.Session, opts: Sequence[str] = ()):
if opts:
opts_str = "[" + ",".join(opts) + "]"
else:
opts_str = ""
session.install("-e", f".{opts_str}")
@nox.session(python="3.10", tags=["qa", "code-quality"])
def lint(session: nox.Session):
"""Lint code using flake8"""
session.install("flake8")
session.run("flake8", "src/pystencils")
@nox.session(python="3.10", tags=["qa", "code-quality"])
def typecheck(session: nox.Session):
"""Run MyPy for static type checking"""
editable_install(session)
session.install("mypy")
session.run("mypy", "src/pystencils")
@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")
cuda_major = cuda_version[0]
cupy_package = f"cupy-cuda{cuda_major}=={cupy_version}"
session.install(cupy_package)
editable_install(session, ["alltrafos", "use_cython", "interactive", "testsuite"])
num_cores = os.cpu_count()
session.run(
"pytest",
"-v",
"-n", str(num_cores),
"--cov-report=term",
"--cov=.",
"-m", "not longrun",
"--html", "test-report/index.html",
"--junitxml=report.xml"
)
session.run("coverage", "html")
session.run("coverage", "xml")
...@@ -44,6 +44,11 @@ interactive = [ ...@@ -44,6 +44,11 @@ interactive = [
use_cython = [ use_cython = [
'Cython' 'Cython'
] ]
dev = [
"flake8",
"mypy",
"black",
]
doc = [ doc = [
'sphinx', 'sphinx',
'pydata-sphinx-theme==0.15.4', 'pydata-sphinx-theme==0.15.4',
...@@ -54,7 +59,7 @@ doc = [ ...@@ -54,7 +59,7 @@ doc = [
'sphinx_design', 'sphinx_design',
'myst-nb' 'myst-nb'
] ]
tests = [ testsuite = [
'pytest', 'pytest',
'pytest-cov', 'pytest-cov',
'pytest-html', 'pytest-html',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment