Skip to content

Commit

Permalink
Add code quality CI test (openvinotoolkit#272)
Browse files Browse the repository at this point in the history
* Add Code Quality CI check

Run nbqa flake8 to check for common code quality issues

Move nbqa and nbval from ci-requirements to dev-requirements since they are useful for local development too
Also remove pre-commit since it is not currently used
  • Loading branch information
helena-intel authored Sep 30, 2021
1 parent 800e1b3 commit bbd4c59
Show file tree
Hide file tree
Showing 10 changed files with 416 additions and 386 deletions.
7 changes: 1 addition & 6 deletions .ci/ci-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
-r ../requirements.txt
-r dev-requirements.txt

# Packages for testing/validating notebooks
nbval
nbqa[toolchain]
pandoc
pre-commit

6 changes: 3 additions & 3 deletions .ci/dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Recommended packages for notebook developers

-r ci-requirements.txt # packages for validation of notebooks

# black==21.8 requires typing-extensions>3.10 which is incompatible
# with other packages
-r ../requirements.txt
black==21.7b0 # format Python code
isort # sort imports
jupyterlab-code-formatter # format code in notebooks in Jupyter Lab
jupyterlab-git # checkout and commit code in Jupyter Lab

nbqa[toolchain] # automatic code quality checking
nbval # pytest plugin for automatic notebook testing
47 changes: 47 additions & 0 deletions .github/workflows/codecheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: code_check

on:
workflow_dispatch:
pull_request:
branches:
- 'main'
paths:
- 'notebooks/**.ipynb'
- 'notebooks/**.py'
- 'requirements.txt'
- '.ci/*'
- '.github/workflows/codequality.yml'
push:
branches:
- 'main'
paths:
- 'notebooks/**.ipynb'
- 'notebooks/**.py'
- 'requirements.txt'
- '.ci/*'
- '.github/workflows/codequality.yml'


jobs:
build:
strategy:
fail-fast: false
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r .ci/dev-requirements.txt
python -m ipykernel install --user --name openvino_env
- name: Flake8
run: |
nbqa flake8 --ignore=E124,E203,E266,E402,E501,F821,W503,W291,W293 --nbqa-exclude="(301.*)|(302.*)|(208.*)" notebooks
- name: Check READMEs
run: |
python -m pytest .ci/test_notebooks.py
7 changes: 3 additions & 4 deletions .github/workflows/nbval.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ jobs:
- name: Patch notebooks
run: |
python .ci/patch_notebooks.py
- name: Analysing with nbval
- name: Test Jupyterlab
run: |
jupyter lab notebooks --help
python -m pytest --nbval -x -k "test_ or notebook_utils" --durations 10 --ignore notebooks/208-optical-character-recognition .
- name: Check READMEs
- name: Analysing with nbval
run: |
python -m pytest .ci/test_notebooks.py
python -m pytest --nbval -x -k "test_ or notebook_utils" --durations 10 --ignore notebooks/208-optical-character-recognition .
1 change: 0 additions & 1 deletion notebooks/002-openvino-api/002-openvino-api.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,6 @@
"metadata": {},
"outputs": [],
"source": [
"import shutil\n",
"import time\n",
"from pathlib import Path\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@
"outputs": [],
"source": [
"import json\n",
"import sys\n",
"import time\n",
"from pathlib import Path\n",
"\n",
"import cv2\n",
"import matplotlib.pyplot as plt\n",
"import mo_tf\n",
"import numpy as np\n",
"from IPython.display import Markdown\n",
"from openvino.inference_engine import IECore"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,11 @@
},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"import time\n",
"from pathlib import Path\n",
"\n",
"import cv2\n",
"import matplotlib.pyplot as plt\n",
"import mo_onnx\n",
"import numpy as np\n",
"import torch\n",
"from fastseg import MobileV3Large\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"from compression.graph import load_model, save_model\n",
"from compression.graph.model_utils import compress_model_weights\n",
"from compression.pipeline.initializer import create_pipeline\n",
"from compression.utils.logger import get_logger, init_logger\n",
"from torch.utils.data import TensorDataset\n",
"from transformers import BertForSequenceClassification, BertTokenizer\n",
"from transformers import (\n",
Expand Down Expand Up @@ -134,7 +133,6 @@
" \"attention_mask\": default_input,\n",
" \"token_type_ids\": default_input,\n",
" }\n",
" outputs = model(**inputs)\n",
" symbolic_names = {0: \"batch_size\", 1: \"max_seq_len\"}\n",
" torch.onnx.export(\n",
" model,\n",
Expand Down
2 changes: 1 addition & 1 deletion notebooks/201-vision-monodepth/201-vision-monodepth.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@
"FOURCC = cv2.VideoWriter_fourcc(*\"vp09\")\n",
"\n",
"# Create Path objects for the input video and the resulting video\n",
"output_directory = Path(f\"output\")\n",
"output_directory = Path(\"output\")\n",
"output_directory.mkdir(exist_ok=True)\n",
"result_video_path = output_directory / f\"{Path(VIDEO_FILE).stem}_monodepth.mp4\""
]
Expand Down
Loading

0 comments on commit bbd4c59

Please sign in to comment.