Skip to content
Snippets Groups Projects
Commit e067b6b6 authored by Frederik Hennig's avatar Frederik Hennig Committed by Christoph Alt
Browse files

Introduce Nox for Test Automation

parent 448e9087
1 merge request!10Introduce Nox for Test Automation
...@@ -4,44 +4,31 @@ stages: ...@@ -4,44 +4,31 @@ stages:
- "Documentation" - "Documentation"
- deploy - deploy
.nox-base:
image: i10git.cs.fau.de:5005/pycodegen/pycodegen/nox:alpine
tags:
- docker
linter: linter:
extends: .nox-base
stage: "Code Quality" stage: "Code Quality"
needs: [] needs: []
except:
variables:
- $ENABLE_NIGHTLY_BUILDS
image: i10git.cs.fau.de:5005/pycodegen/pycodegen/full
script: script:
- flake8 src/pystencilssfg - nox --session lint
tags:
- docker
typechecker: typechecker:
extends: .nox-base
stage: "Code Quality" stage: "Code Quality"
needs: [] needs: []
except:
variables:
- $ENABLE_NIGHTLY_BUILDS
image: i10git.cs.fau.de:5005/pycodegen/pycodegen/full
script: script:
- pip install mypy - nox --session typecheck
- mypy src/pystencilssfg
tags:
- docker
testsuite: testsuite:
extends: .nox-base
stage: "Tests" stage: "Tests"
image: i10git.cs.fau.de:5005/pycodegen/pycodegen/full
needs: [] needs: []
tags:
- docker
before_script:
- pip install "git+https://i10git.cs.fau.de/pycodegen/pystencils.git@v2.0-dev"
- pip install -e .[tests]
script: script:
- pytest -v --cov=src/pystencilssfg --cov-report=term --cov-config=pyproject.toml - nox --session testsuite
- coverage html
- coverage xml
coverage: '/TOTAL.*\s+(\d+%)$/' coverage: '/TOTAL.*\s+(\d+%)$/'
artifacts: artifacts:
when: always when: always
...@@ -54,23 +41,17 @@ testsuite: ...@@ -54,23 +41,17 @@ testsuite:
path: coverage.xml path: coverage.xml
build-documentation: build-documentation:
extends: .nox-base
stage: "Documentation" stage: "Documentation"
image: i10git.cs.fau.de:5005/pycodegen/pycodegen/full
needs: [] needs: []
before_script:
- pip install "git+https://i10git.cs.fau.de/pycodegen/pystencils.git@v2.0-dev"
- pip install -e .[docs]
script: script:
- cd docs - nox --session docs
- make html
tags:
- docker
artifacts: artifacts:
paths: paths:
- docs/build/html - docs/build/html
pages: pages:
image: i10git.cs.fau.de:5005/pycodegen/pycodegen/full image: alpine:latest
stage: deploy stage: deploy
script: script:
- ls -l - ls -l
......
...@@ -13,6 +13,19 @@ As such, any submission of contributions via merge requests is considered as agr ...@@ -13,6 +13,19 @@ As such, any submission of contributions via merge requests is considered as agr
## Developing `pystencils-sfg` ## Developing `pystencils-sfg`
### Prequesites
To develop pystencils-sfg, you will need at least these packages:
- Python 3.10
- Git
- A C++ compiler supporting at least C++20 (gcc >= 10, or clang >= 10)
- GNU Make
- CMake
- Nox
Before continuing, make sure that the above packages are installed on your machine.
### Fork and Clone ### Fork and Clone
To work within the `pystencils-sfg` source tree, first create a *fork* of this repository To work within the `pystencils-sfg` source tree, first create a *fork* of this repository
...@@ -29,28 +42,29 @@ source .venv/bin/activate ...@@ -29,28 +42,29 @@ source .venv/bin/activate
pip install -e . pip install -e .
``` ```
If you have [nox](https://nox.thea.codes/en/stable/) installed, you can also set up your virtual environment
by running `nox --session dev_env`.
### Code Style and Type Checking ### Code Style and Type Checking
To contribute, please adhere to the Python code style set by [PEP 8](https://peps.python.org/pep-0008/). To contribute, please adhere to the Python code style set by [PEP 8](https://peps.python.org/pep-0008/).
For consistency, format all your source files using the [black](https://pypi.org/project/black/) formatter. For consistency, format all your source files using the [black](https://pypi.org/project/black/) formatter,
Use flake8 to check your code style: and check them regularily using the `flake8` linter through Nox:
```shell ```shell
flake8 src/pystencilssfg nox --session lint
``` ```
Further, `pystencils-sfg` is being fully type-checked using [MyPy](https://www.mypy-lang.org/). Further, `pystencils-sfg` is being fully type-checked using [MyPy](https://www.mypy-lang.org/).
All submitted code should contain type annotations ([PEP 484](https://peps.python.org/pep-0484/)) and must be All submitted code should contain type annotations ([PEP 484](https://peps.python.org/pep-0484/)) and must be
correctly statically typed. correctly statically typed.
Before each commit, check your types by calling Regularily check your code for type errors using
```shell ```shell
mypy src/pystencilssfg nox --session typecheck
``` ```
Both `flake8` and `mypy` are also run in the integration pipeline. Both `flake8` and `mypy` are also run in the integration pipeline.
You can automate the code quality checks by running them via a git pre-commit hook.
Such a hook can be installed using the [`install_git_hooks.sh`](install_git_hooks.sh) script located at the project root.
### Test Your Code ### Test Your Code
...@@ -65,3 +79,11 @@ In [tests/generator_scripts](tests/generator_scripts), a framework is provided t ...@@ -65,3 +79,11 @@ In [tests/generator_scripts](tests/generator_scripts), a framework is provided t
for successful execution, correctness, and compilability of their output. for successful execution, correctness, and compilability of their output.
Read the documentation within [test_generator_scripts.py](tests/generator_scripts/test_generator_scripts.py) Read the documentation within [test_generator_scripts.py](tests/generator_scripts/test_generator_scripts.py)
for more information. for more information.
Run the test suite by calling it through Nox:
```shell
nox --session testsuite
```
This will also collect coverage information and produce a coverage report as a HTML site placed in the `htmlcov` folder.
from __future__ import annotations
from typing import Sequence
import nox
nox.options.sessions = ["lint", "typecheck", "testsuite"]
def add_pystencils_git(session: nox.Session):
"""Clone the pystencils 2.0 development branch and install it in the current session"""
cache_dir = session.cache_dir
pystencils_dir = cache_dir / "pystencils"
if not pystencils_dir.exists():
session.run_install(
"git",
"clone",
"--branch",
"v2.0-dev",
"--single-branch",
"https://i10git.cs.fau.de/pycodegen/pystencils.git",
pystencils_dir,
external=True,
)
session.install("-e", str(pystencils_dir))
def editable_install(session: nox.Session, opts: Sequence[str] = ()):
add_pystencils_git(session)
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/pystencilssfg")
@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/pystencilssfg")
@nox.session(python=["3.10"], tags=["tests"])
def testsuite(session: nox.Session):
"""Run the testsuite and measure coverage."""
editable_install(session, ["testsuite"])
session.run(
"pytest",
"-v",
"--cov=src/pystencilssfg",
"--cov-report=term",
"--cov-config=pyproject.toml",
)
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, ["docs"])
session.chdir("docs")
session.run("make", "html", external=True)
@nox.session()
def dev_env(session: nox.Session):
"""Set up the development environment at .venv"""
session.install("virtualenv")
session.run("virtualenv", ".venv", "--prompt", "pystencils-sfg")
session.run(
".venv/bin/pip",
"install",
"git+https://i10git.cs.fau.de/pycodegen/pystencils.git@v2.0-dev",
external=True,
)
session.run(".venv/bin/pip", "install", "-e", ".[dev]", external=True)
...@@ -23,10 +23,15 @@ requires = [ ...@@ -23,10 +23,15 @@ requires = [
build-backend = "setuptools.build_meta" build-backend = "setuptools.build_meta"
[project.optional-dependencies] [project.optional-dependencies]
tests = [ dev = [
"flake8>=6.1.0", "flake8",
"mypy>=1.7.0", "mypy",
"black", "black",
"clang-format",
]
testsuite = [
"pytest",
"pytest-cov",
"pyyaml", "pyyaml",
"requests", "requests",
"fasteners", "fasteners",
...@@ -60,7 +65,7 @@ omit = [ ...@@ -60,7 +65,7 @@ omit = [
[tool.coverage.report] [tool.coverage.report]
exclude_also = [ exclude_also = [
"\\.\\.\\.", "\\.\\.\\.\n",
"if TYPE_CHECKING:", "if TYPE_CHECKING:",
"@(abc\\.)?abstractmethod", "@(abc\\.)?abstractmethod",
] ]
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment