Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Python linting: Add more ruff rules (#2441)

Christian Claussf830963e63fe
diff --git a/conftest.py b/conftest.py
index ec0c5461a..0aca17104 100644
--- a/conftest.py
+++ b/conftest.py
@@ -2,7 +2,7 @@ import sys
from itertools import product
from typing import Dict
-import numpy
+import numpy as np
import pytest
import torch
@@ -105,7 +105,7 @@ def pytest_addoption(parser):
@pytest.fixture(autouse=True)
def add_doctest_deps(doctest_namespace):
- doctest_namespace["np"] = numpy
+ doctest_namespace["np"] = np
doctest_namespace["torch"] = torch
doctest_namespace["kornia"] = kornia
diff --git a/docs/generate_examples.py b/docs/generate_examples.py
index d042a78ef..7ae4758c1 100644
--- a/docs/generate_examples.py
+++ b/docs/generate_examples.py
@@ -6,7 +6,7 @@ import os
from pathlib import Path
import cv2
-import matplotlib
+import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import requests
@@ -16,7 +16,7 @@ from kornia_moons.feature import visualize_LAF
import kornia as K
from kornia.core import Tensor
-matplotlib.use("Agg")
+mpl.use("Agg")
def download_tutorials_examples(download_infos: dict[str, str], directory: Path):
diff --git a/kornia/constants.py b/kornia/constants.py
index 4dbfa5bdc..81a10ade7 100644
--- a/kornia/constants.py
+++ b/kornia/constants.py
@@ -118,7 +118,7 @@ class DType(Enum, metaclass=_KORNIA_EnumMeta):
elif data == DType.FLOAT64:
return torch.float64
- raise ValueError()
+ raise ValueError
# TODO: (low-priority) add INPUT3D, MASK3D, BBOX3D, LAFs etc.
diff --git a/kornia/feature/loftr/utils/coarse_matching.py b/kornia/feature/loftr/utils/coarse_matching.py
index 611ead675..a1ef3b017 100644
--- a/kornia/feature/loftr/utils/coarse_matching.py
+++ b/kornia/feature/loftr/utils/coarse_matching.py
@@ -86,7 +86,7 @@ class CoarseMatching(Module):
self.skh_iters = config['skh_iters']
self.skh_prefilter = config['skh_prefilter']
else:
- raise NotImplementedError()
+ raise NotImplementedError
def forward(
self,
diff --git a/kornia/nerf/nerf_solver.py b/kornia/nerf/nerf_solver.py
index 17d24a529..512416cad 100755
--- a/kornia/nerf/nerf_solver.py
+++ b/kornia/nerf/nerf_solver.py
@@ -178,7 +178,7 @@ class NerfSolver:
epoch_psnr = self._train_one_epoch()
if i_epoch % 10 == 0:
- current_time = datetime.now().strftime("%H:%M:%S")
+ current_time = datetime.now().strftime("%H:%M:%S") # noqa: DTZ005
print(f'Epoch: {i_epoch}: epoch_psnr = {epoch_psnr}; time: {current_time}')
def render_views(self, cameras: PinholeCamera) -> ImageTensors:
diff --git a/pyproject.toml b/pyproject.toml
index 7a4ad5f71..f192a3fb1 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -78,7 +78,64 @@ requires = [
[tool.ruff]
line-length = 120
target-version = "py38"
- select = ["C9", "E", "F", "I", "PL", "S", "UP", "W", "YTT", "BLE", "C4", "RUF"]
+ select = [
+ "AIR", # Airflow
+ "ASYNC", # flake8-async
+ "BLE", # flake8-blind-except
+ "C4", # flake8-comprehensions
+ "C90", # McCabe cyclomatic complexity
+ "CPY", # Copyright-related rules
+ "DTZ", # flake8-datetimez
+ "E", # pycodestyle
+ "F", # Pyflakes
+ "FLY", # flynt
+ "I", # isort
+ "ICN", # flake8-import-conventions
+ "INT", # flake8-gettext
+ "NPY", # NumPy-specific rules
+ "PL", # Pylint
+ "PYI", # flake8-pyi
+ "RSE", # flake8-raise
+ "RUF", # Ruff-specific rules
+ "S", # flake8-bandit
+ "SLOT", # flake8-slots
+ "T10", # flake8-debugger
+ "TID", # flake8-tidy-imports
+ "UP", # pyupgrade
+ "W", # pycodestyle
+ "YTT", # flake8-2020
+ # "A", # flake8-builtins
+ # "ANN", # flake8-annotations
+ # "ARG", # flake8-unused-arguments
+ # "B", # flake8-bugbear
+ # "COM", # flake8-commas
+ # "D", # pydocstyle
+ # "DJ", # flake8-django
+ # "EM", # flake8-errmsg
+ # "ERA", # eradicate
+ # "EXE", # flake8-executable
+ # "FA", # flake8-future-annotations
+ # "FBT", # flake8-boolean-trap
+ # "FIX", # flake8-fixme
+ # "G", # flake8-logging-format
+ # "INP", # flake8-no-pep420
+ # "ISC", # flake8-implicit-str-concat
+ # "N", # pep8-naming
+ # "PD", # pandas-vet
+ # "PERF", # Perflint
+ # "PGH", # pygrep-hooks
+ # "PIE", # flake8-pie
+ # "PT", # flake8-pytest-style
+ # "PTH", # flake8-use-pathlib
+ # "Q", # flake8-quotes
+ # "RET", # flake8-return
+ # "SIM", # flake8-simplify
+ # "SLF", # flake8-self
+ # "T20", # flake8-print
+ # "TCH", # flake8-type-checking
+ # "TD", # flake8-todos
+ # "TRY", # tryceratops
+ ]
ignore = [
"PLW2901", # Allow overwritten values on loops
]
diff --git a/test/io/test_load_image.py b/test/io/test_load_image.py
index 1cf3f4184..b2170bcdf 100644
--- a/test/io/test_load_image.py
+++ b/test/io/test_load_image.py
@@ -22,7 +22,7 @@ def available_package() -> bool:
def create_random_img8(height: int, width: int, channels: int) -> np.ndarray:
- return (np.random.rand(height, width, channels) * 255).astype(np.uint8)
+ return (np.random.rand(height, width, channels) * 255).astype(np.uint8) # noqa: NPY002
@pytest.mark.skipif(not available_package(), reason="kornia_rs only supports python >=3.7 and pt >= 1.10.0")