From e6b54d893b41d6572d548f242263ec8f0aff1d66 Mon Sep 17 00:00:00 2001 From: David Revay Date: Thu, 9 Jun 2022 13:46:40 +1000 Subject: [PATCH] chore: add pre-commit --- .pre-commit-config.yaml | 50 +++++++++++++++++++ README.md | 6 ++- nuclio_lighting_flash/flash_model_handler.py | 2 +- .../flash_model_handler_in_memory.py | 1 - .../nuclio_detection_labels_output.py | 4 +- 5 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..b4e03d6 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,50 @@ +# To use: +# +# pre-commit run -a +# +# Or: +# +# pre-commit install # (runs every time you commit in git) +# +# To update this file: +# +# pre-commit autoupdate +# +# See https://github.com/pre-commit/pre-commit + +repos: + # Standard hooks + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.1.0 + hooks: + - id: check-added-large-files + - id: check-ast + - id: check-case-conflict + - id: check-docstring-first + - id: check-merge-conflict + - id: check-symlinks + - id: check-xml + - id: check-yaml + - id: debug-statements + - id: mixed-line-ending + - id: trailing-whitespace + - id: fix-byte-order-marker + + # Python hooks + - repo: https://github.com/asottile/pyupgrade + rev: v2.31.0 + hooks: + - id: pyupgrade + args: [--py36-plus] + + - repo: https://github.com/psf/black + rev: 22.3.0 + hooks: + - id: black + args: ["--line-length=99"] + + - repo: https://github.com/pycqa/flake8 + rev: 4.0.1 + hooks: + - id: flake8 + args: ["--ignore=E203, E266, E501, W503, F403, F401 --max-line-length = 99"] diff --git a/README.md b/README.md index bb23551..af1beb3 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ nuctl deploy --project-name cvat \ ### Get started -In order to develop you'll want a nuclio instance running on your local machine... +In order to develop you'll want a nuclio instance running on your local machine... * `docker-compose up` to start nuclio. * `./scripts/build.sh` to build `ghcr.io/greenroom-robotics/nuclio_lighting_flash:latest` @@ -30,6 +30,10 @@ nuctl deploy --project-name cvat \ --platform local ``` +### Run tests + +* `./scripts/build.sh && docker run ghcr.io/greenroom-robotics/nuclio_lighting_flash:latest` to build and run pytests + ### Release a version * Run the [Release](./.github/workflows/release.yml) workflow on github \ No newline at end of file diff --git a/nuclio_lighting_flash/flash_model_handler.py b/nuclio_lighting_flash/flash_model_handler.py index 66a0d0f..76d6cf3 100644 --- a/nuclio_lighting_flash/flash_model_handler.py +++ b/nuclio_lighting_flash/flash_model_handler.py @@ -36,4 +36,4 @@ def infer(self, image: Image, threshold: float = 0.0): ) if predictions is None: return [] - return predictions[0][0] \ No newline at end of file + return predictions[0][0] diff --git a/nuclio_lighting_flash/flash_model_handler_in_memory.py b/nuclio_lighting_flash/flash_model_handler_in_memory.py index f119627..9948b73 100644 --- a/nuclio_lighting_flash/flash_model_handler_in_memory.py +++ b/nuclio_lighting_flash/flash_model_handler_in_memory.py @@ -5,7 +5,6 @@ from flash.core.data.io.output import Output from flash.core.data.io.input import DataKeys from flash.core.data.data_module import DataModule -from flash.core.data.io.input import DataKeys from flash.core.data.io.output_transform import OutputTransform from flash.core.trainer import Trainer from flash.core.utilities.stages import RunningStage diff --git a/nuclio_lighting_flash/nuclio_detection_labels_output.py b/nuclio_lighting_flash/nuclio_detection_labels_output.py index 45d9157..54c9e8e 100644 --- a/nuclio_lighting_flash/nuclio_detection_labels_output.py +++ b/nuclio_lighting_flash/nuclio_detection_labels_output.py @@ -34,9 +34,7 @@ def transform(self, sample: Dict[str, Any]) -> List[Dict[str, Any]]: preds = sample[DataKeys.PREDS] - for bbox, label, score in zip( - preds["bboxes"], preds["labels"], preds["scores"] - ): + for bbox, label, score in zip(preds["bboxes"], preds["labels"], preds["scores"]): confidence = score.tolist() if self.threshold is not None and confidence < self.threshold: