From 82e2b4188b7971549ca3b462cb0b7e3985ddce78 Mon Sep 17 00:00:00 2001 From: Kate Generalova Date: Thu, 22 Apr 2021 11:03:49 +0300 Subject: [PATCH] feat: add checks for Py samples (#5339) --- .github/workflows/py_checks.yml | 33 +++++++++++++++++++ .../classification_sample_async.py | 2 +- .../hello_classification.py | 2 +- .../hello_query_device/hello_query_device.py | 2 +- .../hello_reshape_ssd/hello_reshape_ssd.py | 2 +- .../ngraph_function_creation_sample.py | 13 ++++---- .../object_detection_sample_ssd.py | 2 +- .../python/sample/requirements_dev.txt | 26 +++++++++++++++ .../ie_bridges/python/sample/setup.cfg | 12 +++++++ .../style_transfer_sample.py | 2 +- 10 files changed, 84 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/py_checks.yml create mode 100644 inference-engine/ie_bridges/python/sample/requirements_dev.txt create mode 100644 inference-engine/ie_bridges/python/sample/setup.cfg diff --git a/.github/workflows/py_checks.yml b/.github/workflows/py_checks.yml new file mode 100644 index 00000000000..9b7c4a7a94b --- /dev/null +++ b/.github/workflows/py_checks.yml @@ -0,0 +1,33 @@ +name: IE Python Checks +# TODO: add for IE API, wheels +on: + workflow_dispatch: + push: + paths: + - 'inference-engine/ie_bridges/python/sample/**' + pull_request: + paths: + - 'inference-engine/ie_bridges/python/sample/**' +jobs: + linters: + runs-on: ubuntu-18.04 + steps: + - name: Code checkout + uses: actions/checkout@v2 + with: + submodules: recursive + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.6' + - name: Install dependencies + run: python -m pip install -r inference-engine/ie_bridges/python/sample/requirements_dev.txt + - name: Run Flake + run: python -m flake8 ./ --config=setup.cfg --show-source + working-directory: inference-engine/ie_bridges/python/sample + - name: Run MyPy + run: python -m mypy ./ --config-file ./setup.cfg --show-error-context --show-column-numbers --pretty + working-directory: inference-engine/ie_bridges/python/sample + - name: Run Bandit + run: python -m bandit -r ./ -f screen + working-directory: inference-engine/ie_bridges/python/sample \ No newline at end of file diff --git a/inference-engine/ie_bridges/python/sample/classification_sample_async/classification_sample_async.py b/inference-engine/ie_bridges/python/sample/classification_sample_async/classification_sample_async.py index b592856ab1a..099997045da 100755 --- a/inference-engine/ie_bridges/python/sample/classification_sample_async/classification_sample_async.py +++ b/inference-engine/ie_bridges/python/sample/classification_sample_async/classification_sample_async.py @@ -12,7 +12,7 @@ from openvino.inference_engine import IECore, StatusCode def parse_args() -> argparse.Namespace: - '''Parse and return command line arguments''' + """Parse and return command line arguments""" parser = argparse.ArgumentParser(add_help=False) args = parser.add_argument_group('Options') args.add_argument('-h', '--help', action='help', help='Show this help message and exit.') diff --git a/inference-engine/ie_bridges/python/sample/hello_classification/hello_classification.py b/inference-engine/ie_bridges/python/sample/hello_classification/hello_classification.py index 03933310efa..0c74f281379 100755 --- a/inference-engine/ie_bridges/python/sample/hello_classification/hello_classification.py +++ b/inference-engine/ie_bridges/python/sample/hello_classification/hello_classification.py @@ -12,7 +12,7 @@ from openvino.inference_engine import IECore def parse_args() -> argparse.Namespace: - '''Parse and return command line arguments''' + """Parse and return command line arguments""" parser = argparse.ArgumentParser(add_help=False) args = parser.add_argument_group('Options') args.add_argument('-h', '--help', action='help', help='Show this help message and exit.') diff --git a/inference-engine/ie_bridges/python/sample/hello_query_device/hello_query_device.py b/inference-engine/ie_bridges/python/sample/hello_query_device/hello_query_device.py index 3fbd1d045f2..c478d6d6b71 100755 --- a/inference-engine/ie_bridges/python/sample/hello_query_device/hello_query_device.py +++ b/inference-engine/ie_bridges/python/sample/hello_query_device/hello_query_device.py @@ -9,7 +9,7 @@ from openvino.inference_engine import IECore def param_to_string(metric) -> str: - '''Convert a list / tuple of parameters returned from IE to a string''' + """Convert a list / tuple of parameters returned from IE to a string""" if isinstance(metric, (list, tuple)): return ', '.join([str(x) for x in metric]) else: diff --git a/inference-engine/ie_bridges/python/sample/hello_reshape_ssd/hello_reshape_ssd.py b/inference-engine/ie_bridges/python/sample/hello_reshape_ssd/hello_reshape_ssd.py index b6053ba4245..6b5bdfc09c1 100755 --- a/inference-engine/ie_bridges/python/sample/hello_reshape_ssd/hello_reshape_ssd.py +++ b/inference-engine/ie_bridges/python/sample/hello_reshape_ssd/hello_reshape_ssd.py @@ -12,7 +12,7 @@ from openvino.inference_engine import IECore def parse_args() -> argparse.Namespace: - '''Parse and return command line arguments''' + """Parse and return command line arguments""" parser = argparse.ArgumentParser(add_help=False) args = parser.add_argument_group('Options') args.add_argument('-h', '--help', action='help', help='Show this help message and exit.') diff --git a/inference-engine/ie_bridges/python/sample/ngraph_function_creation_sample/ngraph_function_creation_sample.py b/inference-engine/ie_bridges/python/sample/ngraph_function_creation_sample/ngraph_function_creation_sample.py index fb3378e60ce..86ab98b3053 100755 --- a/inference-engine/ie_bridges/python/sample/ngraph_function_creation_sample/ngraph_function_creation_sample.py +++ b/inference-engine/ie_bridges/python/sample/ngraph_function_creation_sample/ngraph_function_creation_sample.py @@ -6,6 +6,7 @@ import argparse import logging as log import struct as st import sys +import typing from functools import reduce import cv2 @@ -15,7 +16,7 @@ from openvino.inference_engine import IECore, IENetwork def parse_args() -> argparse.Namespace: - '''Parse and return command line arguments''' + """Parse and return command line arguments""" parser = argparse.ArgumentParser(add_help=False) args = parser.add_argument_group('Options') args.add_argument('-h', '--help', action='help', help='Show this help message and exit.') @@ -33,7 +34,7 @@ def parse_args() -> argparse.Namespace: def read_image(image_path: str) -> np.ndarray: - '''Read and return an image as grayscale (one channel)''' + """Read and return an image as grayscale (one channel)""" image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE) # Try to open image as ubyte @@ -54,9 +55,9 @@ def read_image(image_path: str) -> np.ndarray: def create_ngraph_function(args: argparse.Namespace) -> ngraph.impl.Function: - '''Create a network on the fly from the source code using ngraph''' + """Create a network on the fly from the source code using ngraph""" - def shape_and_length(shape: list) -> (list, int): + def shape_and_length(shape: list) -> typing.Tuple[list, int]: length = reduce(lambda x, y: x * y, shape) return shape, length @@ -204,8 +205,8 @@ def main(): image = read_image(args.input[i]) light_pixel_count = np.count_nonzero(image > 127) - darK_pixel_count = np.count_nonzero(image < 127) - is_light_image = (light_pixel_count - darK_pixel_count) > 0 + dark_pixel_count = np.count_nonzero(image < 127) + is_light_image = (light_pixel_count - dark_pixel_count) > 0 if is_light_image: log.warning(f'Image {args.input[i]} is inverted to white over black') diff --git a/inference-engine/ie_bridges/python/sample/object_detection_sample_ssd/object_detection_sample_ssd.py b/inference-engine/ie_bridges/python/sample/object_detection_sample_ssd/object_detection_sample_ssd.py index 73c7e883193..ab7ec523b39 100755 --- a/inference-engine/ie_bridges/python/sample/object_detection_sample_ssd/object_detection_sample_ssd.py +++ b/inference-engine/ie_bridges/python/sample/object_detection_sample_ssd/object_detection_sample_ssd.py @@ -12,7 +12,7 @@ from openvino.inference_engine import IECore def parse_args() -> argparse.Namespace: - '''Parse and return command line arguments''' + """Parse and return command line arguments""" parser = argparse.ArgumentParser(add_help=False) args = parser.add_argument_group('Options') args.add_argument('-h', '--help', action='help', help='Show this help message and exit.') diff --git a/inference-engine/ie_bridges/python/sample/requirements_dev.txt b/inference-engine/ie_bridges/python/sample/requirements_dev.txt new file mode 100644 index 00000000000..e57ed73f1e1 --- /dev/null +++ b/inference-engine/ie_bridges/python/sample/requirements_dev.txt @@ -0,0 +1,26 @@ +bandit +flake8 +flake8-annotations-complexity +flake8-bandit +flake8-broken-line +flake8-bugbear +flake8-class-attributes-order +flake8-comprehensions +flake8-debugger +flake8-eradicate +flake8-executable +flake8-expression-complexity +flake8-print +flake8-pytest-style +flake8-rst-docstrings +flake8-string-format +flake8-variables-names +flake8_builtins +flake8_coding +flake8_commas +flake8_pep3101 +flake8_quotes +import-order +mypy +Pep8-naming +radon \ No newline at end of file diff --git a/inference-engine/ie_bridges/python/sample/setup.cfg b/inference-engine/ie_bridges/python/sample/setup.cfg new file mode 100644 index 00000000000..da434c2a303 --- /dev/null +++ b/inference-engine/ie_bridges/python/sample/setup.cfg @@ -0,0 +1,12 @@ +[flake8] +max-line-length = 120 +max-parameters-amount = 8 +show_source = True +docstring-convention = google +enable-extensions=G + +[pydocstyle] +convention = google + +[mypy] +ignore_missing_imports = True \ No newline at end of file diff --git a/inference-engine/ie_bridges/python/sample/style_transfer_sample/style_transfer_sample.py b/inference-engine/ie_bridges/python/sample/style_transfer_sample/style_transfer_sample.py index 03311a74de7..736fa288a85 100755 --- a/inference-engine/ie_bridges/python/sample/style_transfer_sample/style_transfer_sample.py +++ b/inference-engine/ie_bridges/python/sample/style_transfer_sample/style_transfer_sample.py @@ -12,7 +12,7 @@ from openvino.inference_engine import IECore def parse_args() -> argparse.Namespace: - '''Parse and return command line arguments''' + """Parse and return command line arguments""" parser = argparse.ArgumentParser(add_help=False) args = parser.add_argument_group('Options') args.add_argument('-h', '--help', action='help', help='Show this help message and exit.')