From 6ec9132df659b575182f8d8cfc7732db6b1f3ddb Mon Sep 17 00:00:00 2001 From: Songki Choi Date: Thu, 9 May 2024 14:34:39 +0900 Subject: [PATCH 1/4] Add tox.ini w/ pre-commit & pytest env --- openvino_xai/__init__.py | 62 ++++++++++++++++++++++++++++++++++++++++ tox.ini | 22 ++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 tox.ini diff --git a/openvino_xai/__init__.py b/openvino_xai/__init__.py index d4b949d3..e8d842c2 100644 --- a/openvino_xai/__init__.py +++ b/openvino_xai/__init__.py @@ -10,3 +10,65 @@ __all__ = [ "insert_xai", ] + + +##------------------------ +# +# from enum import Enum +# from abc import ABC +# from abc import abstractmethod +# import numpy as np +# import openvino.runtime as ov +# +# +# class XAI: +# +# class Task(Enum): +# CLASSIFICATION = "Classification" +# DETECTION = "Detection" +# +# class Mode(Enum): +# WHITEBOX = "whitebox" +# BLACKBOX = "blackbox" +# AUTO = "auto" +# +# class Target(Enum): +# IMAGE = "image" +# ALL = "all" +# CUSTOM = "custom" +# +# class Algorithm(ABC): +# @abstractmethod +# def run(self, image: np.ndarray): +# +# def __init__( +# self, +# model: ov.Model, +# ): +# pass +# +# def explain( +# self, +# image: np.ndarray, +# ): +# pass +# +# +# +# +##------------------------- +# +# from openvino_xai import XAI +##from openvino_xai.prepostproc import PreProcessor +##from openvino_xai.prepostproc import PostProcessor +# +# +# model = ov.Model() +# image = np.ndarray() +# +# xai = XAI(model) +# result = xai.explain(image) +# result = xai(image) +# +# explainer = Explainer(model) +# result = explainer(image) diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..4c265e21 --- /dev/null +++ b/tox.ini @@ -0,0 +1,22 @@ +[tox] +isolated_build = true +skip_missing_interpreters = true + +[testenv] +setenv = + TOX_WORK_DIR={toxworkdir} +passenv = + HTTP_PROXY + HTTPS_PROXY + +[testenv:pre-commit] +deps = + pre-commit==3.7.0 +skip_install = true +commands = + pre-commit run --all-files + +[testenv:pytest-{py310, py311}] +extras = dev,dev_timm +commands = + pytest -ra --showlocals {posargs:tests/} From 1d80f03433dda127061cf1c28aee7806445db26a Mon Sep 17 00:00:00 2001 From: Songki Choi Date: Thu, 9 May 2024 17:11:31 +0900 Subject: [PATCH 2/4] Add pre-merge.yml for PR check --- .github/workflows/pre_merge.yml | 84 +++++++++++++++++++++++++++++++++ openvino_xai/__init__.py | 62 ------------------------ 2 files changed, 84 insertions(+), 62 deletions(-) create mode 100644 .github/workflows/pre_merge.yml diff --git a/.github/workflows/pre_merge.yml b/.github/workflows/pre_merge.yml new file mode 100644 index 00000000..7b5ce4b4 --- /dev/null +++ b/.github/workflows/pre_merge.yml @@ -0,0 +1,84 @@ +name: Pre-Merge Checks + +on: + push: + branches: + - develop + - releases/** + pull_request: + types: + - opened + - reopened + - synchronize + workflow_dispatch: # run on request (no need for PR) + +# Declare default permissions as read only. +permissions: read-all + +jobs: + Code-Quality-Checks: + # This is what will cancel the job concurrency + concurrency: + group: ${{ github.workflow }}-Linting-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + - name: Set up Python + uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0 + with: + python-version: "3.10" + - name: Install tox + run: python -m pip install tox==4.4.6 + - name: Code quality checks + run: tox -vv -e pre-commit + + Unit-Test: + runs-on: ubuntu-22.04 + needs: Code-Quality-Checks + timeout-minutes: 120 + strategy: + fail-fast: false + matrix: + include: + - python-version: "3.10" + tox-env: "py310" + - python-version: "3.11.8" + tox-env: "py311" + name: Unit-Test-${{ matrix.tox-env }} + # This is what will cancel the job concurrency + concurrency: + group: ${{ github.workflow }}-Unit-${{ github.event.pull_request.number || github.ref }}-${{ matrix.tox-env }} + cancel-in-progress: true + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + - name: Install Python + uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0 + with: + python-version: ${{ matrix.python-version }} + - name: Install tox + run: python -m pip install tox==4.4.6 + - name: Run unit test + run: tox -vv -e pytest-${{ matrix.tox-env }} -- tests/unit --cov=openvino_xai + + Integration-Test: + runs-on: ubuntu-22.04 + needs: Unit-Test + name: Integration-Test-py310 + # This is what will cancel the job concurrency + concurrency: + group: ${{ github.workflow }}-Integration-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + - name: Install Python + uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0 + with: + python-version: "3.10" + - name: Install tox + run: python -m pip install --require-hashes --no-deps -r .ci/requirements/tox/requirements.txt + - name: Run Integration Test + run: tox -vv -e pytest-py310 -- tests/integration diff --git a/openvino_xai/__init__.py b/openvino_xai/__init__.py index e8d842c2..d4b949d3 100644 --- a/openvino_xai/__init__.py +++ b/openvino_xai/__init__.py @@ -10,65 +10,3 @@ __all__ = [ "insert_xai", ] - - -##------------------------ -# -# from enum import Enum -# from abc import ABC -# from abc import abstractmethod -# import numpy as np -# import openvino.runtime as ov -# -# -# class XAI: -# -# class Task(Enum): -# CLASSIFICATION = "Classification" -# DETECTION = "Detection" -# -# class Mode(Enum): -# WHITEBOX = "whitebox" -# BLACKBOX = "blackbox" -# AUTO = "auto" -# -# class Target(Enum): -# IMAGE = "image" -# ALL = "all" -# CUSTOM = "custom" -# -# class Algorithm(ABC): -# @abstractmethod -# def run(self, image: np.ndarray): -# -# def __init__( -# self, -# model: ov.Model, -# ): -# pass -# -# def explain( -# self, -# image: np.ndarray, -# ): -# pass -# -# -# -# -##------------------------- -# -# from openvino_xai import XAI -##from openvino_xai.prepostproc import PreProcessor -##from openvino_xai.prepostproc import PostProcessor -# -# -# model = ov.Model() -# image = np.ndarray() -# -# xai = XAI(model) -# result = xai.explain(image) -# result = xai(image) -# -# explainer = Explainer(model) -# result = explainer(image) From 4cea0dab64a0970ad33f488074500461bc795f3b Mon Sep 17 00:00:00 2001 From: Songki Choi Date: Mon, 3 Jun 2024 10:18:02 +0900 Subject: [PATCH 3/4] Add artifacts upload --- .github/workflows/pre_merge.yml | 25 +++++++++++++++++++++---- pyproject.toml | 1 + 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pre_merge.yml b/.github/workflows/pre_merge.yml index 7b5ce4b4..34eed52c 100644 --- a/.github/workflows/pre_merge.yml +++ b/.github/workflows/pre_merge.yml @@ -61,12 +61,22 @@ jobs: - name: Install tox run: python -m pip install tox==4.4.6 - name: Run unit test - run: tox -vv -e pytest-${{ matrix.tox-env }} -- tests/unit --cov=openvino_xai + run: tox -vv -e pytest-${{ matrix.tox-env }} -- tests/unit --csv=.tox/pytest-${{ matrix.tox-env }}/unit-test.csv + --cov=openvino_xai --cov-report term --cov-report xml:.tox/pytest-${{ matrix.tox-env }}/unit-test-coverage.xml + - name: Upload artifacts + uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 + with: + name: unit-test-results-${{ matrix.tox-env }} + path: | + .tox/pytest-${{ matrix.tox-env }}/*.csv + .tox/pytest-${{ matrix.tox-env }}/*.xml + # Use always() to always run this step to publish test results when there are test failures + if: ${{ always() }} Integration-Test: runs-on: ubuntu-22.04 needs: Unit-Test - name: Integration-Test-py310 + name: Integration-Test # This is what will cancel the job concurrency concurrency: group: ${{ github.workflow }}-Integration-${{ github.event.pull_request.number || github.ref }} @@ -79,6 +89,13 @@ jobs: with: python-version: "3.10" - name: Install tox - run: python -m pip install --require-hashes --no-deps -r .ci/requirements/tox/requirements.txt + run: python -m pip install tox==4.4.6 - name: Run Integration Test - run: tox -vv -e pytest-py310 -- tests/integration + run: tox -vv -e pytest-py310 -- tests/integration --csv=.tox/pytest-py310/intg-test.csv + - name: Upload artifacts + uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 + with: + name: intg-test-results + path: .tox/pytest-py310/*.csv + # Use always() to always run this step to publish test results when there are test failures + if: ${{ always() }} diff --git a/pyproject.toml b/pyproject.toml index 913103e9..c5d109d8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,6 +34,7 @@ classifiers = [ dev = [ "pytest", "pytest-cov", + "pytest-csv", "pre-commit==3.7.0", "addict", ] From b6bbf912b8a85cf621715136a42d3a74c4b70260 Mon Sep 17 00:00:00 2001 From: Songki Choi Date: Mon, 3 Jun 2024 13:44:29 +0900 Subject: [PATCH 4/4] Add enable codecov upload --- .github/workflows/pre_merge.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/pre_merge.yml b/.github/workflows/pre_merge.yml index 34eed52c..eaf3ed28 100644 --- a/.github/workflows/pre_merge.yml +++ b/.github/workflows/pre_merge.yml @@ -72,6 +72,11 @@ jobs: .tox/pytest-${{ matrix.tox-env }}/*.xml # Use always() to always run this step to publish test results when there are test failures if: ${{ always() }} + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + with: + files: .tox/pytest-${{ matrix.tox-env }}/unit-test-coverage.xml + flags: pytest-${{ matrix.tox-env }} Integration-Test: runs-on: ubuntu-22.04