From b65d2cc73fbea07f69661b89390066701968e372 Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Thu, 22 Aug 2024 23:27:33 +0300 Subject: [PATCH 1/3] =?UTF-8?q?ci:=20=F0=9F=91=B7=20retire=20isort=20and?= =?UTF-8?q?=20enable=20ruff's=20isort?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onuralp SEZER --- .pre-commit-config.yaml | 13 ------------- pyproject.toml | 9 +++++---- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5cad9b90..45e733bc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.6.0 hooks: - - id: end-of-file-fixer - id: trailing-whitespace exclude: test/.*\.py - id: check-yaml @@ -19,14 +18,12 @@ repos: - id: check-case-conflict - id: check-added-large-files - id: detect-private-key - - id: forbid-new-submodules - id: pretty-format-json exclude: demo.ipynb args: ['--autofix', '--no-sort-keys', '--indent=4'] - id: end-of-file-fixer - id: mixed-line-ending - - repo: https://github.com/PyCQA/bandit rev: '1.7.9' hooks: @@ -34,16 +31,6 @@ repos: args: ["-c", "pyproject.toml"] additional_dependencies: ["bandit[toml]"] - - repo: https://github.com/pycqa/isort - rev: 5.13.2 - hooks: - - id: isort - name: isort (python) - - id: isort - name: isort (pyi) - types: [pyi] - - - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.6.1 hooks: diff --git a/pyproject.toml b/pyproject.toml index f0ff6d85..0c281c04 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -90,9 +90,6 @@ mkdocs-jupyter = "^0.24.3" mkdocs-git-committers-plugin-2 = "^2.2.3" mkdocs-git-revision-date-localized-plugin = "^1.2.4" -[tool.isort] -line_length = 88 -profile = "black" [tool.bandit] target = ["test", "supervision"] @@ -157,7 +154,7 @@ indent-width = 4 [tool.ruff.lint] # Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default. -select = ["E", "F"] +select = ["E", "F", "I", "A", "Q", "W"] ignore = [] # Allow autofix for all enabled rules (when `--fix`) is provided. fixable = [ @@ -226,6 +223,10 @@ convention = "google" # Flag errors (`C901`) whenever the complexity level exceeds 5. max-complexity = 20 +[tool.ruff.lint.isort] +order-by-type = true +no-sections = false + [tool.ruff.format] # Like Black, use double quotes for strings. quote-style = "double" From a64a2fc243154c2b6cd20ad8ee5da2f8c41e7682 Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Thu, 22 Aug 2024 23:29:13 +0300 Subject: [PATCH 2/3] fix(formatter): apply fixes from ruff and fix minor mypy and pep corrections Signed-off-by: Onuralp SEZER --- demo.ipynb | 2 +- test/annotators/test_utils.py | 2 +- test/dataset/formats/test_pascal_voc.py | 12 ++++++------ test/dataset/test_core.py | 2 +- test/dataset/test_utils.py | 2 +- test/detection/test_core.py | 2 +- test/detection/test_csv.py | 2 +- test/detection/test_json.py | 2 +- test/detection/test_line_counter.py | 2 +- test/detection/test_polygonzone.py | 2 +- test/metrics/test_detection.py | 2 +- test/test_utils.py | 5 +++-- 12 files changed, 19 insertions(+), 18 deletions(-) diff --git a/demo.ipynb b/demo.ipynb index 55d2b7cb..b5aa7c5e 100644 --- a/demo.ipynb +++ b/demo.ipynb @@ -972,7 +972,7 @@ } ], "source": [ - "from supervision.assets import download_assets, VideoAssets\n", + "from supervision.assets import VideoAssets, download_assets\n", "\n", "download_assets(VideoAssets.VEHICLES)\n", "VIDEO_PATH = VideoAssets.VEHICLES.value" diff --git a/test/annotators/test_utils.py b/test/annotators/test_utils.py index 1344d213..588f0242 100644 --- a/test/annotators/test_utils.py +++ b/test/annotators/test_utils.py @@ -1,5 +1,4 @@ from contextlib import ExitStack as DoesNotRaise -from test.test_utils import mock_detections from typing import Optional import numpy as np @@ -7,6 +6,7 @@ import pytest from supervision.annotators.utils import ColorLookup, resolve_color_idx from supervision.detection.core import Detections +from test.test_utils import mock_detections @pytest.mark.parametrize( diff --git a/test/dataset/formats/test_pascal_voc.py b/test/dataset/formats/test_pascal_voc.py index bce29271..80d83cc7 100644 --- a/test/dataset/formats/test_pascal_voc.py +++ b/test/dataset/formats/test_pascal_voc.py @@ -1,16 +1,16 @@ from contextlib import ExitStack as DoesNotRaise -from test.test_utils import mock_detections from typing import List, Optional -import defusedxml.ElementTree as ET import numpy as np import pytest +from defusedxml import ElementTree from supervision.dataset.formats.pascal_voc import ( detections_from_xml_obj, object_to_pascal_voc, parse_polygon_points, ) +from test.test_utils import mock_detections def are_xml_elements_equal(elem1, elem2): @@ -36,7 +36,7 @@ def are_xml_elements_equal(elem1, elem2): np.array([0, 0, 10, 10]), "test", None, - ET.fromstring( + ElementTree.fromstring( """test11 1111""" ), @@ -46,7 +46,7 @@ def are_xml_elements_equal(elem1, elem2): np.array([0, 0, 10, 10]), "test", np.array([[0, 0], [10, 0], [10, 10], [0, 10]]), - ET.fromstring( + ElementTree.fromstring( """test11 1111 1111 @@ -73,7 +73,7 @@ def test_object_to_pascal_voc( "polygon_element, expected_result, exception", [ ( - ET.fromstring( + ElementTree.fromstring( """0010010 10010""" ), @@ -160,6 +160,6 @@ def test_detections_from_xml_obj( xml_string, classes, resolution_wh, force_masks, expected_result, exception ): with exception: - root = ET.fromstring(xml_string) + root = ElementTree.fromstring(xml_string) result, _ = detections_from_xml_obj(root, classes, resolution_wh, force_masks) assert result == expected_result diff --git a/test/dataset/test_core.py b/test/dataset/test_core.py index 4a75225c..fdfe1475 100644 --- a/test/dataset/test_core.py +++ b/test/dataset/test_core.py @@ -1,11 +1,11 @@ from contextlib import ExitStack as DoesNotRaise -from test.test_utils import mock_detections from typing import List, Optional import numpy as np import pytest from supervision import DetectionDataset +from test.test_utils import mock_detections @pytest.mark.parametrize( diff --git a/test/dataset/test_utils.py b/test/dataset/test_utils.py index 41e1da5b..67893abc 100644 --- a/test/dataset/test_utils.py +++ b/test/dataset/test_utils.py @@ -1,5 +1,4 @@ from contextlib import ExitStack as DoesNotRaise -from test.test_utils import mock_detections from typing import Dict, List, Optional, Tuple, TypeVar import numpy as np @@ -15,6 +14,7 @@ from supervision.dataset.utils import ( rle_to_mask, train_test_split, ) +from test.test_utils import mock_detections T = TypeVar("T") diff --git a/test/detection/test_core.py b/test/detection/test_core.py index 300d6dfe..b857250e 100644 --- a/test/detection/test_core.py +++ b/test/detection/test_core.py @@ -1,5 +1,4 @@ from contextlib import ExitStack as DoesNotRaise -from test.test_utils import mock_detections from typing import List, Optional, Union import numpy as np @@ -7,6 +6,7 @@ import pytest from supervision.detection.core import Detections, merge_inner_detection_object_pair from supervision.geometry.core import Position +from test.test_utils import mock_detections PREDICTIONS = np.array( [ diff --git a/test/detection/test_csv.py b/test/detection/test_csv.py index c3444494..e1414424 100644 --- a/test/detection/test_csv.py +++ b/test/detection/test_csv.py @@ -1,11 +1,11 @@ import csv import os -from test.test_utils import mock_detections from typing import Any, Dict, List import pytest import supervision as sv +from test.test_utils import mock_detections @pytest.mark.parametrize( diff --git a/test/detection/test_json.py b/test/detection/test_json.py index 760c2db3..d5f24924 100644 --- a/test/detection/test_json.py +++ b/test/detection/test_json.py @@ -1,11 +1,11 @@ import json import os -from test.test_utils import mock_detections from typing import Any, Dict, List import pytest import supervision as sv +from test.test_utils import mock_detections @pytest.mark.parametrize( diff --git a/test/detection/test_line_counter.py b/test/detection/test_line_counter.py index 66118e97..b7e4d33d 100644 --- a/test/detection/test_line_counter.py +++ b/test/detection/test_line_counter.py @@ -1,11 +1,11 @@ from contextlib import ExitStack as DoesNotRaise -from test.test_utils import mock_detections from typing import List, Optional, Tuple import pytest from supervision import LineZone from supervision.geometry.core import Point, Position, Vector +from test.test_utils import mock_detections @pytest.mark.parametrize( diff --git a/test/detection/test_polygonzone.py b/test/detection/test_polygonzone.py index ed899615..a631ff17 100644 --- a/test/detection/test_polygonzone.py +++ b/test/detection/test_polygonzone.py @@ -1,10 +1,10 @@ from contextlib import ExitStack as DoesNotRaise -from test.test_utils import mock_detections import numpy as np import pytest import supervision as sv +from test.test_utils import mock_detections DETECTION_BOXES = np.array( [ diff --git a/test/metrics/test_detection.py b/test/metrics/test_detection.py index 7cb92c46..b2313bdd 100644 --- a/test/metrics/test_detection.py +++ b/test/metrics/test_detection.py @@ -1,5 +1,4 @@ from contextlib import ExitStack as DoesNotRaise -from test.test_utils import assert_almost_equal, mock_detections from typing import Optional, Union import numpy as np @@ -11,6 +10,7 @@ from supervision.metrics.detection import ( MeanAveragePrecision, detections_to_tensor, ) +from test.test_utils import assert_almost_equal, mock_detections CLASSES = np.arange(80) NUM_CLASSES = len(CLASSES) diff --git a/test/test_utils.py b/test/test_utils.py index b676cb54..ce1bc136 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -1,13 +1,14 @@ from typing import Any, Dict, List, Optional import numpy as np +import numpy.typing as npt from supervision.detection.core import Detections from supervision.keypoint.core import KeyPoints def mock_detections( - xyxy: List[List[float]], + xyxy: npt.NDArray[np.float32], mask: Optional[List[np.ndarray]] = None, confidence: Optional[List[float]] = None, class_id: Optional[List[int]] = None, @@ -32,7 +33,7 @@ def mock_detections( def mock_keypoints( - xy: List[List[float]], + xy: npt.NDArray[np.float32], confidence: Optional[List[float]] = None, class_id: Optional[List[int]] = None, data: Optional[Dict[str, List[Any]]] = None, From 3d7c1ba1ec65bdb0147b02f8ab1e0bfbeb644490 Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Thu, 22 Aug 2024 23:46:30 +0300 Subject: [PATCH 3/3] =?UTF-8?q?feat(mypy):=20=E2=9C=A8=20mypy=20type=20che?= =?UTF-8?q?ck=20libraries=20added=20as=20optional?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onuralp SEZER --- poetry.lock | 75 +++++++++++++++++++++++++++++++++++++++++++++----- pyproject.toml | 9 ++++++ 2 files changed, 77 insertions(+), 7 deletions(-) diff --git a/poetry.lock b/poetry.lock index 9510bb15..0c2d7b54 100644 --- a/poetry.lock +++ b/poetry.lock @@ -3842,19 +3842,19 @@ win32 = ["pywin32"] [[package]] name = "setuptools" -version = "71.0.1" +version = "73.0.1" description = "Easily download, build, install, upgrade, and uninstall Python packages" optional = false python-versions = ">=3.8" files = [ - {file = "setuptools-71.0.1-py3-none-any.whl", hash = "sha256:1eb8ef012efae7f6acbc53ec0abde4bc6746c43087fd215ee09e1df48998711f"}, - {file = "setuptools-71.0.1.tar.gz", hash = "sha256:c51d7fd29843aa18dad362d4b4ecd917022131425438251f4e3d766c964dd1ad"}, + {file = "setuptools-73.0.1-py3-none-any.whl", hash = "sha256:b208925fcb9f7af924ed2dc04708ea89791e24bde0d3020b27df0e116088b34e"}, + {file = "setuptools-73.0.1.tar.gz", hash = "sha256:d59a3e788ab7e012ab2c4baed1b376da6366883ee20d7a5fc426816e3d7b1193"}, ] [package.extras] -core = ["importlib-metadata (>=6)", "importlib-resources (>=5.10.2)", "jaraco.text (>=3.7)", "more-itertools (>=8.8)", "ordered-set (>=3.1.1)", "packaging (>=24)", "platformdirs (>=2.6.2)", "tomli (>=2.0.1)", "wheel (>=0.43.0)"] -doc = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "pyproject-hooks (!=1.1)", "rst.linker (>=1.9)", "sphinx (<7.4)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (>=1,<2)", "sphinx-reredirects", "sphinxcontrib-towncrier"] -test = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "importlib-metadata", "ini2toml[lite] (>=0.14)", "jaraco.develop (>=7.21)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "jaraco.test", "mypy (==1.10.0)", "packaging (>=23.2)", "pip (>=19.1)", "pyproject-hooks (!=1.1)", "pytest (>=6,!=8.1.*)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-home (>=0.5)", "pytest-mypy", "pytest-perf", "pytest-ruff (<0.4)", "pytest-ruff (>=0.2.1)", "pytest-ruff (>=0.3.2)", "pytest-subprocess", "pytest-timeout", "pytest-xdist (>=3)", "tomli", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] +core = ["importlib-metadata (>=6)", "importlib-resources (>=5.10.2)", "jaraco.text (>=3.7)", "more-itertools (>=8.8)", "packaging (>=24)", "platformdirs (>=2.6.2)", "tomli (>=2.0.1)", "wheel (>=0.43.0)"] +doc = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "pyproject-hooks (!=1.1)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (>=1,<2)", "sphinx-reredirects", "sphinxcontrib-towncrier", "towncrier (<24.7)"] +test = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "importlib-metadata", "ini2toml[lite] (>=0.14)", "jaraco.develop (>=7.21)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "jaraco.test", "mypy (==1.11.*)", "packaging (>=23.2)", "pip (>=19.1)", "pyproject-hooks (!=1.1)", "pytest (>=6,!=8.1.*)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-home (>=0.5)", "pytest-mypy", "pytest-perf", "pytest-ruff (<0.4)", "pytest-ruff (>=0.2.1)", "pytest-ruff (>=0.3.2)", "pytest-subprocess", "pytest-timeout", "pytest-xdist (>=3)", "tomli", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel (>=0.44.0)"] [[package]] name = "six" @@ -4073,6 +4073,20 @@ rfc3986 = ">=1.4.0" rich = ">=12.0.0" urllib3 = ">=1.26.0" +[[package]] +name = "types-cffi" +version = "1.16.0.20240331" +description = "Typing stubs for cffi" +optional = false +python-versions = ">=3.8" +files = [ + {file = "types-cffi-1.16.0.20240331.tar.gz", hash = "sha256:b8b20d23a2b89cfed5f8c5bc53b0cb8677c3aac6d970dbc771e28b9c698f5dee"}, + {file = "types_cffi-1.16.0.20240331-py3-none-any.whl", hash = "sha256:a363e5ea54a4eb6a4a105d800685fde596bc318089b025b27dee09849fe41ff0"}, +] + +[package.dependencies] +types-setuptools = "*" + [[package]] name = "types-python-dateutil" version = "2.9.0.20240316" @@ -4084,6 +4098,53 @@ files = [ {file = "types_python_dateutil-2.9.0.20240316-py3-none-any.whl", hash = "sha256:6b8cb66d960771ce5ff974e9dd45e38facb81718cc1e208b10b1baccbfdbee3b"}, ] +[[package]] +name = "types-pyyaml" +version = "6.0.12.20240808" +description = "Typing stubs for PyYAML" +optional = false +python-versions = ">=3.8" +files = [ + {file = "types-PyYAML-6.0.12.20240808.tar.gz", hash = "sha256:b8f76ddbd7f65440a8bda5526a9607e4c7a322dc2f8e1a8c405644f9a6f4b9af"}, + {file = "types_PyYAML-6.0.12.20240808-py3-none-any.whl", hash = "sha256:deda34c5c655265fc517b546c902aa6eed2ef8d3e921e4765fe606fe2afe8d35"}, +] + +[[package]] +name = "types-requests" +version = "2.32.0.20240712" +description = "Typing stubs for requests" +optional = false +python-versions = ">=3.8" +files = [ + {file = "types-requests-2.32.0.20240712.tar.gz", hash = "sha256:90c079ff05e549f6bf50e02e910210b98b8ff1ebdd18e19c873cd237737c1358"}, + {file = "types_requests-2.32.0.20240712-py3-none-any.whl", hash = "sha256:f754283e152c752e46e70942fa2a146b5bc70393522257bb85bd1ef7e019dcc3"}, +] + +[package.dependencies] +urllib3 = ">=2" + +[[package]] +name = "types-setuptools" +version = "73.0.0.20240822" +description = "Typing stubs for setuptools" +optional = false +python-versions = ">=3.8" +files = [ + {file = "types-setuptools-73.0.0.20240822.tar.gz", hash = "sha256:3a060681098eb3fbc2fea0a86f7f6af6aa1ca71906039d88d891ea2cecdd4dbf"}, + {file = "types_setuptools-73.0.0.20240822-py3-none-any.whl", hash = "sha256:b9eba9b68546031317a0fa506d4973641d987d74f79e7dd8369ad4f7a93dea17"}, +] + +[[package]] +name = "types-tqdm" +version = "4.66.0.20240417" +description = "Typing stubs for tqdm" +optional = false +python-versions = ">=3.8" +files = [ + {file = "types-tqdm-4.66.0.20240417.tar.gz", hash = "sha256:16dce9ef522ea8d40e4f5b8d84dd8a1166eefc13ceee7a7e158bf0f1a1421a31"}, + {file = "types_tqdm-4.66.0.20240417-py3-none-any.whl", hash = "sha256:248aef1f9986b7b8c2c12b3cb4399fc17dba0a29e7e3f3f9cd704babb879383d"}, +] + [[package]] name = "typing-extensions" version = "4.12.2" @@ -4304,4 +4365,4 @@ desktop = ["opencv-python"] [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "3335a9dabe490f33be8f9f74bbd199b786f8d7c6959ec853012831606c3abcdd" +content-hash = "c639934a93aca292b212bfc36e4837118595356df08d98eb6e1115d0a1e168c1" diff --git a/pyproject.toml b/pyproject.toml index 0c281c04..8df14e51 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -90,6 +90,15 @@ mkdocs-jupyter = "^0.24.3" mkdocs-git-committers-plugin-2 = "^2.2.3" mkdocs-git-revision-date-localized-plugin = "^1.2.4" +[tool.poetry.group.typecheck] +optional = true + +[tool.poetry.group.typecheck.dependencies] +types-pyyaml = "^6.0.12.20240808" +types-cffi = "^1.16.0.20240331" +types-requests = "^2.32.0.20240712" +types-tqdm = "^4.66.0.20240417" + [tool.bandit] target = ["test", "supervision"]