Skip to content

Commit

Permalink
Run tests for all Python versions in a single nox session
Browse files Browse the repository at this point in the history
Internal-tag: [#53659]
Signed-off-by: Robert Szczepanski <[email protected]>
  • Loading branch information
robertszczepanski committed Feb 23, 2024
1 parent fb2be84 commit 14b1efe
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 83 deletions.
92 changes: 44 additions & 48 deletions .ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,78 +9,74 @@ stages:

lint:
stage: test
image: ubuntu:latest
image: debian:bookworm
before_script:
- apt-get update -qq
- apt-get install -y --no-install-recommends python3-pip python3-venv
- apt-get install -y --no-install-recommends
python3-pip
python3-venv
- python3 -m venv venv
- source venv/bin/activate
- python3 -m pip install -U pip wheel setuptools
script:
- python3 -m pip install -r requirements.txt
- nox -s isort_check black_check flake8

.run_tests:
stage: test
image: ubuntu:latest
.generate_example:
stage: examples
image: debian:bookworm
variables:
GIT_SUBMODULE_STRATEGY: normal
DEBIAN_FRONTEND: noninteractive
PYTHON_VERSION: "3.12"
before_script:
- apt-get update -qq
- apt-get install -y --no-install-recommends
python3-venv
python3-pip
- source .github/scripts/setup_env.sh $PYTHON_VERSION
- install_deps
- configure_python_env
- activate_python_env
- python3 -m venv venv
- source venv/bin/activate
- python3 -m pip install git+https://github.com/antmicro/tuttest
- tuttest README.md | bash -
script:
- nox -s tests_with_report
artifacts:
paths:
- cov_html
- cd examples/$EXAMPLE
- tuttest README.md generate | bash -

.generate_example:
stage: examples
image: ubuntu:latest
run_tests:
stage: test
image: debian:bookworm
variables:
GIT_SUBMODULE_STRATEGY: normal
DEBIAN_FRONTEND: noninteractive
PYTHON_VERSION: "3.12"
before_script:
- source .github/scripts/setup_env.sh $PYTHON_VERSION
- install_deps
- configure_python_env
- activate_python_env
- apt-get update -qq
- apt-get install -y --no-install-recommends
curl
wget
git
python3-dev
python3-venv
python3-pip
make
ninja-build
gcc-riscv64-unknown-elf
bsdextrautils
verilator
libssl-dev
libreadline-dev
libffi-dev
libbz2-dev
libncurses-dev
libsqlite3-dev
liblzma-dev
- python3 -m venv venv
- source venv/bin/activate
- python3 -m pip install nox
- python3 -m pip install git+https://github.com/antmicro/tuttest
- tuttest README.md | bash -
script:
- cd examples/$EXAMPLE
- tuttest README.md generate | bash -

tests_py38:
extends: .run_tests
variables:
PYTHON_VERSION: "3.8"

tests_py39:
extends: .run_tests
variables:
PYTHON_VERSION: "3.9"

tests_py310:
extends: .run_tests
variables:
PYTHON_VERSION: "3.10"

tests_py311:
extends: .run_tests
variables:
PYTHON_VERSION: "3.11"

tests_py312:
extends: .run_tests
variables:
PYTHON_VERSION: "3.12"
- nox -s test_all_in_env

generate_hdmi:
extends: .generate_example
Expand All @@ -98,7 +94,7 @@ generate_pwm:
EXAMPLE: pwm

include:
- project: 'repositories/fpga-topwrap'
- project: 'repositories/topwrap'
ref: internal_ci_yaml
file: '/internal.yml'

Expand Down
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ exclude =
__pycache__,
docs/source/conf.py,
venv,
build,
builds,
kenning-pipeline-manager,
miniconda3,
Expand Down
77 changes: 46 additions & 31 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ on: [pull_request, push, workflow_dispatch]
jobs:
Lint:
runs-on: ubuntu-latest
name: "Run Lint checks on Python sources"
container:
image: debian:bookworm
name: "Run lint checks"

env:
DEBIAN_FRONTEND: noninteractive
Expand All @@ -20,25 +22,22 @@ jobs:

- name: Install dev requirements
run: |
sudo apt-get update -qq
sudo apt-get install -y --no-install-recommends python3-pip python3-venv
apt-get update -qq
apt-get install -y --no-install-recommends python3-pip python3-venv
python3 -m venv venv
source venv/bin/activate
python3 -m pip install -U pip wheel setuptools
python3 -m pip install -r requirements.txt
- name: Run lint checks
run: |
python3 -m pip install -r requirements.txt
nox -s isort_check black_check flake8
Tests:
runs-on: ubuntu-latest
name: "Test Python ${{ matrix.python-version }}"

strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
container:
image: debian:bookworm
name: "Run tests"

env:
DEBIAN_FRONTEND: noninteractive
Expand All @@ -50,27 +49,46 @@ jobs:

- name: Install dev requirements
run: |
source .github/scripts/setup_env.sh ${{ matrix.python-version }}
install_deps
configure_python_env
activate_python_env
apt-get update -qq
apt-get install -y --no-install-recommends \
curl \
wget \
git \
python3-dev \
python3-venv \
python3-pip \
make \
ninja-build \
gcc-riscv64-unknown-elf \
bsdextrautils \
verilator \
libssl-dev \
libreadline-dev \
libffi-dev \
libbz2-dev \
libncurses-dev \
libsqlite3-dev \
liblzma-dev
python3 -m venv venv
source venv/bin/activate
python3 -m pip install nox
python3 -m pip install git+https://github.com/antmicro/tuttest
- name: Build
run: |
source .github/scripts/setup_env.sh ${{ matrix.python-version }}
activate_python_env
source venv/bin/activate
tuttest README.md | bash -
- name: Run pytest with nox
run: |
source .github/scripts/setup_env.sh ${{ matrix.python-version }}
activate_python_env
nox -s tests
source venv/bin/activate
nox -s test_all_in_env
Examples:
runs-on: ubuntu-latest
name: 'Example ${{ matrix.example }}'
container:
image: debian:bookworm
name: 'Generate example ${{ matrix.example }}'

strategy:
fail-fast: false
Expand All @@ -80,29 +98,26 @@ jobs:
- inout
- pwm

env:
PYTHON_VERSION: "3.12"

steps:
- uses: actions/checkout@v3

- name: Install dev requirements
run: |
source .github/scripts/setup_env.sh $PYTHON_VERSION
install_deps
configure_python_env
activate_python_env
apt-get update -qq
apt-get install -y --no-install-recommends \
python3-venv \
python3-pip
python3 -m venv venv
source venv/bin/activate
python3 -m pip install git+https://github.com/antmicro/tuttest
- name: Install fpga-topwrap
run: |
source .github/scripts/setup_env.sh $PYTHON_VERSION
activate_python_env
source venv/bin/activate
tuttest README.md | bash -
- name: Generate sources for example ${{ matrix.example }} setup
run: |
source .github/scripts/setup_env.sh $PYTHON_VERSION
activate_python_env
source venv/bin/activate
cd examples/${{ matrix.example }}
tuttest README.md generate | bash -
66 changes: 62 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# Copyright (c) 2023-2024 Antmicro <www.antmicro.com>
# SPDX-License-Identifier: Apache-2.0

import os
import shutil
import subprocess
import sys

import nox

BLACK_VERSION = "black==23.12.1"
FLAKE8_VERSION = "flake8==7.0.0."
ISORT_VERSION = "isort==5.13.2"
PYTHON_VERSIONS = ["3.8", "3.9", "3.10", "3.11", "3.12"]


@nox.session()
Expand Down Expand Up @@ -50,15 +56,67 @@ def black_check(session):
session.run("black", "--check", ".")


@nox.session
@nox.session(python=PYTHON_VERSIONS)
def tests(session: nox.Session) -> None:
session.install("-e", ".")
session.install("-r", "requirements.txt")
session.run("pytest", "--cov=fpga_topwrap", "tests")
session.run("pytest", "-rs", "--cov=fpga_topwrap", "tests")


@nox.session
@nox.session(python=PYTHON_VERSIONS)
def tests_with_report(session: nox.Session) -> None:
session.install("-e", ".")
session.install("-r", "requirements.txt")
session.run("pytest", "--cov-report", "html:cov_html", "--cov=fpga_topwrap", "tests")
session.run("pytest", "-rs", "--cov-report", "html:cov_html", "--cov=fpga_topwrap", "tests")


@nox.session
def test_all_in_env(session: nox.Session) -> None:
project_dir = os.path.dirname(os.path.abspath(__file__))
pyenv_dir = f"{project_dir}/build/.pyenv"
path = f"{os.path.join(pyenv_dir, 'bin')}:{os.getenv('PATH')}"
if not shutil.which("pyenv", path=path):
p = subprocess.run(
"curl https://pyenv.run | bash",
env={"PYENV_ROOT": pyenv_dir},
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
shell=True,
)
session.log(p.stdout.strip("\n"))
sys.path.insert(0, os.path.join(pyenv_dir, "bin"))

if p.returncode:
session.error()

for ver in PYTHON_VERSIONS:
session.log(f"Installing Python {ver}")
p = subprocess.run(
f"pyenv install {ver}",
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
shell=True,
env={"PATH": path},
)
session.log(p.stdout.strip("\n"))

if p.returncode:
session.error()

session.log(f"Configuring Python {ver}")
p = subprocess.run(
f"pyenv local {ver}",
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
shell=True,
env={"PATH": path},
)
session.log(p.stdout.strip("\n"))

if p.returncode:
session.error()

session.run("nox", "-s", "tests_with_report", external=True)
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exclude = '''
| \.pytest_cache
| __pycache__
| venv
| build
| builds
| kenning-pipeline-manager
| soc_generator
Expand All @@ -36,6 +37,7 @@ skip = [
".pytest_cache",
"__pycache__",
"venv",
"build",
"builds",
"kenning-pipeline-manager",
"miniconda3",
Expand Down

0 comments on commit 14b1efe

Please sign in to comment.