π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
Replace bandit, flake8, isort, pyupgrade, and yesqa with ruff (#2292)
Christian Clauss64bd78719fcd
diff --git a/.flake8 b/.flake8deleted file mode 100644index 094739282..000000000--- a/.flake8+++ /dev/null@@ -1,11 +0,0 @@-[flake8]-max-line-length = 120-exclude =- docs-per-file-ignores =- __init__.py: F401, F403- docs/generate_example_images.py: E402-verbose = 2-ignore =- W503- E203diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yamlindex 3f61f556a..b800f088a 100644--- a/.pre-commit-config.yaml+++ b/.pre-commit-config.yaml@@ -19,6 +19,12 @@ repos:hooks:- id: pyproject-fmt+ - repo: https://github.com/charliermarsh/ruff-pre-commit+ rev: v0.0.259+ hooks:+ - id: ruff+ args: [--fix, --exit-non-zero-on-fix]+- repo: https://github.com/psf/blackrev: 23.3.0hooks:@@ -34,45 +40,8 @@ repos:- --skip- "*.bib,*.ipynb"- - repo: https://github.com/PyCQA/isort- rev: 5.12.0- hooks:- - id: isort-- - repo: https://github.com/PyCQA/flake8- rev: 6.0.0- hooks:- - id: flake8-- - repo: https://github.com/asottile/pyupgrade- rev: v3.3.1- hooks:- - id: pyupgrade- args: [--py37-plus]-- - repo: https://github.com/PyCQA/bandit- rev: 1.7.5- hooks:- - id: bandit- name: bandit excluding the test directory- language_version: python3- exclude: ^test/- - id: bandit- name: bandit only the test directory- language_version: python3- files: ^test/- args:- - --skip- - "B101,B311"-- repo: https://github.com/PyCQA/docformatterrev: v1.6.1-rc1hooks:- id: docformatterargs: [--in-place, --wrap-summaries=115, --wrap-descriptions=120]-- - repo: https://github.com/asottile/yesqa- rev: v1.4.0- hooks:- - id: yesqa- name: Unused noqadiff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 88e1f30e9..87979b8d6 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -288,7 +288,7 @@ test that:- Typing with [mypy](http://mypy-lang.org) type checks the Python code.- If the docs can be generated successfully- [pre-commit ci](https://pre-commit.ci)- - [flake8](https://pypi.org/project/flake8/) accepts the code style (our guidelines are based on PEP8).+ - [ruff](https://pypi.org/project/ruff/) accepts the code style (our guidelines are based on PEP8).- [black](https://black.readthedocs.io/en/stable/) checks if the code is well formatted- [docformatter](https://pypi.org/project/docformatter/) checks if the code docstrings are well formatted- and some other checks. Check our [pre-commit config](./.pre-commit-config.yaml)diff --git a/Makefile b/Makefileindex 3fefb27d8..a93cd9358 100644--- a/Makefile+++ b/Makefile@@ -33,7 +33,7 @@ test-slow: FORCEpytest -v --device all --dtype all -m "(jit or grad or nn)"lint: FORCE- pre-commit run flake8 --all-files+ pre-commit run ruff --all-filesmypy: FORCEmypydiff --git a/kornia/contrib/image_stitching.py b/kornia/contrib/image_stitching.pyindex 5a7bae84b..6aef55a52 100644--- a/kornia/contrib/image_stitching.py+++ b/kornia/contrib/image_stitching.py@@ -83,7 +83,7 @@ class ImageStitcher(Module):def preprocess(self, image_1: Tensor, image_2: Tensor) -> Dict[str, Tensor]:"""Preprocess input to the required format."""# TODO: probably perform histogram matching here.- if isinstance(self.matcher, LoFTR) or isinstance(self.matcher, LocalFeatureMatcher):+ if isinstance(self.matcher, (LoFTR, LocalFeatureMatcher)):input_dict = { # LofTR works on grayscale images only"image0": rgb_to_grayscale(image_1),"image1": rgb_to_grayscale(image_2),diff --git a/kornia/geometry/conversions.py b/kornia/geometry/conversions.pyindex a315fd2c2..64f9d6a09 100644--- a/kornia/geometry/conversions.py+++ b/kornia/geometry/conversions.py@@ -9,7 +9,6 @@ from kornia.constants import pifrom kornia.core import Tensor, concatenate, pad, stack, tensor, wherefrom kornia.core.check import KORNIA_CHECK, KORNIA_CHECK_SHAPEfrom kornia.utils.helpers import _torch_inverse_cast-from kornia.utils.misc import eye_like__all__ = ["rad2deg",diff --git a/kornia/geometry/epipolar/fundamental.py b/kornia/geometry/epipolar/fundamental.pyindex ad602dc11..5f7101f31 100644--- a/kornia/geometry/epipolar/fundamental.py+++ b/kornia/geometry/epipolar/fundamental.py@@ -89,7 +89,7 @@ def find_fundamental(raise AssertionError(points1.shape, points2.shape)if points1.shape[1] < 8:raise AssertionError(points1.shape)- if not (weights is None):+ if weights is not None:if not (len(weights.shape) == 2 and weights.shape[1] == points1.shape[1]):raise AssertionError(weights.shape)diff --git a/kornia/geometry/linalg.py b/kornia/geometry/linalg.pyindex c897ad327..aad59f377 100644--- a/kornia/geometry/linalg.py+++ b/kornia/geometry/linalg.py@@ -217,7 +217,7 @@ def point_line_distance(point: Tensor, line: Tensor, eps: float = 1e-9) -> TensoKORNIA_CHECK_IS_TENSOR(point)KORNIA_CHECK_IS_TENSOR(line)- if not point.shape[-1] in (2, 3):+ if point.shape[-1] not in (2, 3):raise ValueError(f"pts must be a (*, 2 or 3) tensor. Got {point.shape}")if not line.shape[-1] == 3:diff --git a/kornia/nerf/camera_utils.py b/kornia/nerf/camera_utils.pyindex 05283e7e7..72482d881 100755--- a/kornia/nerf/camera_utils.py+++ b/kornia/nerf/camera_utils.py@@ -67,7 +67,7 @@ def parse_colmap_output(# Read line with camera quaternionline = line.strip()- if line.endswith('png') or line.endswith('jpg\n'):+ if line.endswith(('jpg', 'png')):split_line = line.split(' ')qw = float(split_line[1])qx = float(split_line[2])diff --git a/pyproject.toml b/pyproject.tomlindex ebfdf9b5a..58c63d487 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -76,15 +76,6 @@ namespaces = falseskip-string-normalization = trueskip-magic-trailing-comma = true-[tool.isort]- multi_line_output=3- include_trailing_comma = true- line_length = 120- profile = "black"- known_first_party = ["examples", "kornia","test"]- skip_glob = []- skip = ["kornia/__init__.py"]-[tool.pytest.ini_options]addopts = "--color=yes"testpaths = ["test"]@@ -129,3 +120,53 @@ D204D213D406D407"""++[tool.ruff]+select = [+ "C9",+ "E",+ "F",+ "I",+ "PL",+ "S",+ "UP",+ "W",+ "YTT",+]+ignore = [+ "E402",+ "F403",+ "PLR0402",+ "PLR1711",+ "PLR5501",+ "PLR2004",+ "PLW2901"+]+line-length = 120+target-version = "py37"++[tool.ruff.isort]+ known-first-party = ["examples", "kornia", "test"]++[tool.ruff.mccabe]+max-complexity = 39++[tool.ruff.pylint]+max-args = 16+max-branches = 45+max-returns = 13+max-statements = 258++[tool.ruff.per-file-ignores]+"*/__init__.py" = ["F401"]+"docs/*" = ["S101", "S113"]+"docs/generate_example_images.py" = ["C901", "PLR0912", "PLR0915"]+"examples/train/object_detection/main.py" = ["E741"]+"kornia/__init__.py" = ["I001"]+"kornia/augmentation/container/base.py" = ["PLC1901"]+"kornia/color/hls.py" = ["E741"]+"kornia/contrib/models/sam/architecture/image_encoder.py" = ["PLR0913"]+"kornia/enhance/equalization.py" = ["E741"]+"test/*" = ["PLR0402", "S101"]+"test/enhance/test_core.py" = ["S311"]+"test/nerf/test_camera_utils.py" = ["S310"]diff --git a/requirements/requirements-dev.txt b/requirements/requirements-dev.txtindex d0e7024ca..fce1ffa74 100644--- a/requirements/requirements-dev.txt+++ b/requirements/requirements-dev.txt@@ -1,4 +1,3 @@-isortkornia-rs==0.0.8mypy[reports]numpydiff --git a/test/color/test_raw.py b/test/color/test_raw.pyindex 04f1f1545..b9ecce761 100644--- a/test/color/test_raw.py+++ b/test/color/test_raw.py@@ -6,8 +6,7 @@ from packaging import versionfrom torch.autograd import gradcheckimport kornia-from kornia.testing import BaseTester # test utils-from kornia.testing import assert_close+from kornia.testing import BaseTester, assert_close # test utilsclass TestRawToRgb(BaseTester):