From eb8d3ba4127ba6ba8552c6b5373139fb5d9842e5 Mon Sep 17 00:00:00 2001 From: paugier Date: Tue, 16 Jan 2024 15:36:46 +0100 Subject: [PATCH] CI Github with 3.12 + better noxfile + coverage xml --- .github/workflows/ci-linux.yml | 9 ++-- .gitlab-ci.yml | 18 +++++--- noxfile.py | 76 +++++++++++++++++++++------------- pyproject.toml | 2 +- 4 files changed, 68 insertions(+), 37 deletions(-) diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index 6241949..165fb4f 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.9", "3.10", "3.11"] + python-version: ["3.9", "3.10", "3.11", "3.12"] steps: - name: apt install @@ -23,10 +23,13 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install pdm nox + pip install pdm nox coverage - name: Test with nox run: | - nox -s test_without_pythran test_with_pythran + nox -s "test(with_pythran=0, with_cython=0)" "test(with_pythran=1, with_cython=0)" "test(with_pythran=0, with_cython=1)" + coverage combine + coverage report + coverage xml - uses: codecov/codecov-action@v3 with: token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9b3fde7..4a9ee58 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -75,23 +75,31 @@ step_without_pythran: - job: "image:build" optional: true script: - - nox -s test_without_pythran + - nox -s "test(with_pythran=0, with_cython=0)" -step_pythran_then_cython: +step_with_pythran: stage: test needs: - job: "image:build" optional: true script: - - nox -s test_with_pythran test_with_cython + - nox -s "test(with_pythran=1, with_cython=0)" -step_pythran_cython: +step_with_cython: stage: test needs: - job: "image:build" optional: true script: - - nox -s test_with_pythran_cython + - nox -s "test(with_pythran=0, with_cython=1)" + +step_with_pythran_cython: + stage: test + needs: + - job: "image:build" + optional: true + script: + - nox -s "test(with_pythran=1, with_cython=1)" pages: diff --git a/noxfile.py b/noxfile.py index a2b44e3..bcb97f4 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,48 +1,68 @@ import os import sys from packaging import version +from pathlib import Path import nox os.environ.update({"PDM_IGNORE_SAVED_PYTHON": "1"}) -def _test(session): - session.run("make", "tests_ipynb", external=True) - session.run("make", "tests_coverage", external=True) - - -def _install_base(session): +@nox.parametrize("with_cython", [0, 1]) +@nox.parametrize("with_pythran", [0, 1]) +@nox.session +def test(session, with_pythran, with_cython): command = "pdm sync -G base_test" session.run_always(*command.split(), external=True) - py_version = session.python if session.python is not None else sys.version.split(maxsplit=1)[0] + py_version = ( + session.python + if session.python is not None + else sys.version.split(maxsplit=1)[0] + ) if version.parse(py_version) < version.parse("3.12"): session.install("numba") + else: + session.install("setuptools") + if with_pythran: + session.install("pythran") + if with_cython: + session.install("cython") -@nox.session -def test_without_pythran(session): - _install_base(session) - _test(session) - - -@nox.session -def test_with_pythran(session): - _install_base(session) - session.install("pythran") - _test(session) + if version.parse(py_version) < version.parse("3.12"): + for backend in ("python", "pythran"): + print(f"TRANSONIC_BACKEND={backend}") + session.run( + "pytest", + "--nbval-lax", + "data_tests/ipynb", + env={"TRANSONIC_BACKEND": backend}, + ) + path_coverage = Path(".coverage") + path_coverage.mkdir(exist_ok=True) -@nox.session -def test_with_cython(session): - _install_base(session) - session.install("cython") - _test(session) + code_dependencies = 10 * with_pythran + with_cython + for backend in ("python", "pythran", "numba", "cython"): + print(f"TRANSONIC_BACKEND={backend}") + session.run( + "pytest", + "--cov", + "--cov-config=pyproject.toml", + "tests", + env={ + "COVERAGE_FILE": f".coverage/coverage{code_dependencies}.{backend}", + "TRANSONIC_BACKEND": backend, + }, + ) -@nox.session -def test_with_pythran_cython(session): - _install_base(session) - session.install("pythran", "cython") - _test(session) + command = "mpirun -np 2 coverage run --rcfile=pyproject.toml -m mpi4py -m pytest tests" + session.run( + *command.split(), + external=True, + env={ + "TRANSONIC_BACKEND": "pythran", + }, + ) diff --git a/pyproject.toml b/pyproject.toml index cbb92f0..bfd2067 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -81,7 +81,7 @@ target-version = ['py38'] [tool.coverage.run] branch = true -source = ["src/transonic", "src/transonic_cl", "./tests"] +source = ["./src/transonic", "./src/transonic_cl", "./tests"] data_file = ".coverage/coverage" omit = [ "*/try_*.py",