Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

16.1 KB
Raw Blame
[project]
name = "kornia"
description = "Open Source Differentiable Computer Vision Library for PyTorch"
readme = "README.md"
requires-python = ">=3.11"
license = { text = "Apache-2.0" }
authors = [{ name = "Edgar Riba", email = "[email protected]" }]
keywords = ["computer vision", "deep learning", "pytorch"]
classifiers = [
  "Development Status :: 4 - Beta",
  "Environment :: Console",
  "Environment :: GPU",
  "Intended Audience :: Developers",
  "Intended Audience :: Education",
  "Intended Audience :: Information Technology",
  "Intended Audience :: Science/Research",
  "License :: OSI Approved :: Apache Software License",
  "Natural Language :: English",
  "Operating System :: OS Independent",
  "Programming Language :: Python :: 3 :: Only",
  "Programming Language :: Python :: 3.11",
  "Programming Language :: Python :: 3.12",
  "Programming Language :: Python :: 3.13",
  "Topic :: Scientific/Engineering :: Artificial Intelligence",
  "Topic :: Scientific/Engineering :: Image Processing",
  "Topic :: Software Development :: Libraries",
]
dependencies = ["kornia_rs>=0.2.0", "numpy>=1.21", "torch>=2.5.1"]
dynamic = ["version"]

[project.urls]
"Bug Tracker" = "https://github.com/kornia/kornia/issues"
Documentation = "https://kornia.readthedocs.io/en/latest"
Download = "https://github.com/kornia/kornia"
Homepage = "https://www.kornia.org/"
Issues = "https://github.com/kornia/kornia/issues"
"Source Code" = "https://github.com/kornia/kornia"

[project.optional-dependencies]
dev = [
  "coverage",
  "kornia[onnx]",
  "pillow",
  "pre-commit",
  "pytest>=7",
  "pytest-timeout",
  "setuptools",  # torch.compile / triton on py3.11 + torch 2.5.1, which does not declare it there
]
docs = [
  "pydata-sphinx-theme>=0.21,<0.24",  # _static/css/pydata.css and js/custom.js target theme internals
  "matplotlib",
  # kornia.core.mixin.onnx annotates public members with ``onnx.ModelProto``; without onnx the
  # lazy loader raises ImportError while autodoc resolves them and the build dies. onnxruntime is
  # not needed: no documented member resolves an ``onnxruntime`` annotation.
  "onnx",
  "pillow",  # docs/generate_examples.py decodes and writes the generated figures with PIL
  "sphinx",
  "sphinx-autodoc-defaultargs",
  "sphinx-autodoc-typehints",
  "sphinx-copybutton>=0.3",
  "sphinx-design",
  "sphinx-notfound-page",
  "sphinxcontrib-bibtex",
  "sphinxcontrib-gtagjs",
  "sphinxcontrib-youtube",
]
image = ["pillow"]
onnx = ["onnx", "onnxruntime", "onnxscript"]
sd = ["diffusers", "transformers"]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

# =============================================================================
# uv configuration
# =============================================================================
# PyTorch: Use standard PyPI version (simpler, more compatible)
# For CUDA: pixi run -e cuda install
# PyPI's Linux wheels are CUDA builds; on Windows that task reinstalls torch from the index below
# Note: uv doesn't support per-environment sources

# torch is installed from standard PyPI (no custom index needed)

[tool.codespell]
ignore-words-list = "ans,hist,laf,cofusion"
skip = "*.bib,*.ipynb,docs/source/_data/dependents.json"

[tool.coverage.run]
branch = true
source = ["kornia/"]
omit = [
  "*/__main__.py",
  "*/setup.py",
  "kornia/models/sam/*",
  "kornia/models/siglip2/*",
  "kornia/models/paligemma/*",
  "kornia/models/kimi_vl/*",
  "kornia/models/qwen25/*",
  "kornia/models/smolvlm2/*",
  "kornia/models/efficient_vit/*",
  "kornia/models/rt_detr/*",
  "kornia/models/depth_estimation/*",
  "kornia/models/_hf_models/*",
  "kornia/models/processors/*",
  "kornia/models/vit.py",
  "kornia/models/vit_mobile.py",
  "kornia/models/tiny_vit.py",
  # Feature internals (limited-coverage vendored/adapted code; public entry points stay measured)
  "kornia/feature/adalam/core.py",
  "kornia/feature/adalam/ransac.py",
  "kornia/feature/adalam/utils.py",
  "kornia/feature/dedode/transformer/*",
  "kornia/feature/dedode/dedode_models.py",
  "kornia/feature/dedode/vgg.py",
  "kornia/feature/loftr/loftr_module/*",
  "kornia/feature/loftr/backbone/*",
  "kornia/feature/loftr/utils/*",
  "kornia/feature/sold2/backbones.py",
  "kornia/feature/lightglue_onnx/utils/*",
  "kornia/feature/aliked/deform_conv2d.py",
  "kornia/feature/disk/_unets/*",
  # DexiNed vendored architecture (building blocks only; high-level API in kornia/contrib/edge_detection.py is kept)
  "kornia/models/dexined.py",
  # HuggingFace diffusers wrapper β€” requires diffusers as optional dep, not unit-testable as a filter
  "kornia/filters/dissolving.py",
]

[tool.coverage.report]
show_missing = true
skip_covered = true
fail_under = 84
exclude_lines = [
  # Based into the covdefaults plugin config
  # a more strict default pragma
  '\# pragma: no cover\b',
  # allow defensive code
  '^\s*raise AssertionError\b',
  '^\s*raise NotImplementedError\b',
  '^\s*return NotImplemented\b',
  '^\s*raise$',
  # typing-related code
  '^\s*if (False|TYPE_CHECKING):',
  ': \.\.\.(\s*#.*)?$',
  '^ +\.\.\.$',
  # ----------------------------
  "def __repr__",
  "if __name__ == .__main__.:",
  "if 0:",
  "if self.debug:",
]
partial_branches = [
  # a more strict default pragma
  '\# pragma: no cover\b',
]

[tool.hatch.version]
path = "kornia/__init__.py"

[tool.hatch.build.targets.wheel]
packages = ["kornia"]
exclude = ["**/*.md"]  # Exclude markdown files from wheel

[tool.hatch.build.targets.sdist]
include = ["kornia/", "LICENSE", "README.md"]

[tool.pydocstyle]
match = '.*\.py'

[tool.pytest.ini_options]
addopts = "--color=yes"
filterwarnings = [
  "ignore::DeprecationWarning:onnxscript.converter",
]
markers = [
  "device_agnostic: run CPU-only test logic once in a CPU-containing device matrix",
  "compile_conformance: torch.compile conformance of the promised operators (#5819); deselected unless --compile-conformance selects packages",
  "onnx_conformance: ONNX conformance of the promised operators (#5819); deselected unless --onnx-conformance selects packages",
  "slow: mark test as slow to run",
  "tf32: mark a test as sensitive to TF32 (TensorFloat-32) CUDA matmul and cuDNN precision; xfail by default, run with --tf32 to activate",
]
testpaths = ["tests"]
# Test configuration via environment variables:
# KORNIA_TEST_DEVICE: cpu, cuda, mps (default: cpu)
# KORNIA_TEST_DTYPE: float32, float64, float16, bfloat16 (default: float32)
# KORNIA_TEST_OPTIMIZER: inductor, jit, etc. (default: inductor)
# KORNIA_TEST_RUNSLOW: true/false (default: false)

[tool.ruff]
target-version = "py311"
line-length = 120

[tool.ruff.format]
skip-magic-trailing-comma = false

[tool.ruff.lint]
select = [
  "AIR",  # Airflow
  "ASYNC",  # flake8-async
  "B",  # flake8-bugbear
  "BLE",  # flake8-blind-except
  "C4",  # flake8-comprehensions
  "C90",  # McCabe cyclomatic complexity
  # "CPY",    # Copyright-related rules. No: the add-license-header pre-commit hook already writes the headers
  "DTZ",  # flake8-datetimez
  "E",  # pycodestyle
  "F",  # Pyflakes
  "FLY",  # flynt
  "I",  # isort
  "ICN",  # flake8-import-conventions
  "INT",  # flake8-gettext
  "NPY",  # NumPy-specific rules
  "PGH004",  # blanket-noqa
  "PIE",  # flake8-pie
  "PL",  # Pylint
  "PT001",  # flake8-pytest-style: fixture parentheses
  "PT007",  # flake8-pytest-style: parametrization value containers
  "PT012",  # flake8-pytest-style: one simple statement in pytest.raises blocks
  "PT013",  # flake8-pytest-style: pytest imports
  "PT014",  # flake8-pytest-style: duplicate parametrized cases
  "PT017",  # flake8-pytest-style: assertions in exception handlers
  "PT018",  # flake8-pytest-style: composite assertions
  "PT022",  # flake8-pytest-style: useless yield fixtures
  "PT023",  # flake8-pytest-style: mark parentheses
  "PT030",  # flake8-pytest-style: specific warning matches
  "PYI",  # flake8-pyi
  "RET",  # flake8-return
  "RSE",  # flake8-raise
  "RUF",  # Ruff-specific rules
  "S",  # flake8-bandit
  "SIM102",  # collapsible-if
  "SIM103",  # needless-bool
  "SIM105",  # suppressible-exception
  "SIM108",  # if-else-block-instead-of-if-exp
  "SIM114",  # if-with-same-arms
  "SIM115",  # open-file-with-context-handler
  "SIM117",  # multiple-with-statements
  "SIM118",  # in-dict-keys
  "SIM201",  # negate-equal-op
  "SIM210",  # if-expr-with-true-false
  "SIM211",  # if-expr-with-false-true
  "SIM222",  # expr-or-true
  "SIM401",  # if-else-block-instead-of-dict-get
  "SIM910",  # dict-get-with-none-default
  "SLOT",  # flake8-slots
  "T10",  # flake8-debugger
  "T201",  # flake8-print: print in the library; see the per-file ignore below
  "TC004",  # runtime-import-in-type-checking-block
  "TC005",  # empty-type-checking-block
  "TID",  # flake8-tidy-imports
  "TRY002",  # raise-vanilla-class
  "UP",  # pyupgrade
  "W",  # pycodestyle
  "YTT",  # flake8-2020
  # The families still commented out were assessed in #2445, which gives the reasons in full.
  # "No" means the family is not wanted: please do not open a PR that enables it.
  # "Partial" names the rules of that family that are still wanted.
  # "A",    # flake8-builtins. No: public parameters such as `input` shadow builtins; renaming breaks the API
  # "ANN",  # flake8-annotations. No: ty checks the types
  # "ARG",  # flake8-unused-arguments. No: unused arguments keep interface signatures such as `forward`
  # "COM",  # flake8-commas. No: ruff format already handles trailing commas
  "D",  # pydocstyle
  "D400",  # missing-trailing-period
  # "DJ",   # flake8-django. No: kornia does not use Django
  # "EM",   # flake8-errmsg. No: f-strings stay inline in `raise`
  # "ERA",  # eradicate. No: also flags math and shape notes such as `# u = fx * X + cx`
  "EXE",  # flake8-executable
  # "FA",   # flake8-future-annotations. No: does nothing for target-version py311
  # "FBT",  # flake8-boolean-trap. No: keyword-only booleans would break public signatures
  # "FIX",  # flake8-fixme. No: TODO comments are allowed
  # "G",    # flake8-logging-format. No: f-strings are preferred in logging calls
  # "INP",  # flake8-no-pep420. No: test, benchmark and script directories are not packages
  "ISC",  # flake8-implicit-str-concat
  # "N",    # pep8-naming. No: math names such as `R`, `K` and `H` stay
  # "PD",   # pandas-vet. No: kornia does not use pandas
  # "PERF", # Perflint. No: PERF401 rewrites append loops as comprehensions
  # "PGH",  # pygrep-hooks. Partial: PGH004 is enabled above. No: PGH003, ty ignores the code in `type: ignore[x]`
  # "PT",   # flake8-pytest-style. Partial: the PT rules above. No: PT006, PT011
  # "PTH",  # flake8-use-pathlib. No: os.path to pathlib churn
  # "Q",    # flake8-quotes. No: ruff format handles quotes
  # "SIM",  # flake8-simplify. Partial: the SIM rules above. No: SIM300, it reads names such as `H` as constants
  # "SLF",  # flake8-self. No: tests check private members on purpose
  # "T20",  # flake8-print. Partial: T201 is enabled above for `kornia/` only
  # "TC",   # flake8-type-checking. Partial: TC004 and TC005 are enabled above. No: TC001-TC003, TC006
  # "TD",   # flake8-todos. No: the TODO format is not checked
  # "TRY",  # tryceratops. Partial: TRY002 is enabled above. No: TRY003 (as EM), TRY004 (changes exception classes)
]
ignore = [
  "B905",  # `zip()` without explicit `strict=` - too many to fix, not a bug
  "RUF007",  # Prefer `itertools.pairwise()` over `zip()` - style preference
  "PLR0915",  # Allow condition check in list comprehension
  "PLC0415",  # `import` should be at the top-level of a file
  "PLW2901",  # Allow overwritten values on loops
  "PLW1641",  # Object does not implement `__hash__` method
  "PIE796",  # Enums intentionally use duplicate values as aliases (e.g. DataKey.IMAGE/INPUT)
  "UP007",  # Prefer Optional[], Union[] over | due to torch jit scripting
  "UP006",  # Prefer List[], over list due to torch jit scripting
  "UP035",  # Ignore deprecated typing because of jit scripting
  "UP045",  # Use `X | None` for type annotations
  "RUF005",  # Consider `(*points_in_cam_canonical.shape[:-1], 1)` instead of concatenation. Note: breaks JIT.
  "D100",  # Allow Undocumented public module
  "D104",  # TODO: Undocumented public package
  "D105",  # Allow Undocumented magic method
  "D107",  # Allow Undocumented public init: the class docstring documents the constructor
]

[tool.ruff.lint.flake8-import-conventions.aliases]
# Pinned to ruff 0.16's defaults, so a ruff update cannot require new aliases (0.17 added `datetime as dt`).
altair = "alt"
holoviews = "hv"
matplotlib = "mpl"
"matplotlib.pyplot" = "plt"
networkx = "nx"
numpy = "np"
"numpy.typing" = "npt"
pandas = "pd"
panel = "pn"
"plotly.express" = "px"
polars = "pl"
pyarrow = "pa"
seaborn = "sns"
tensorflow = "tf"
tkinter = "tk"
"xml.etree.ElementTree" = "ET"

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.lint.isort]
forced-separate = ["testing", "tests"]
known-first-party = ["kornia"]
split-on-trailing-comma = true

[tool.ruff.lint.mccabe]
max-complexity = 20

[tool.ruff.lint.pylint]
allow-magic-value-types = ["bytes", "float", "int", "str"]
max-args = 30  # Recommended: 5
max-branches = 21  # Recommended: 12
max-returns = 13  # Recommended: 6
max-statements = 64  # Recommended: 50

[tool.ruff.lint.per-file-ignores]
"!kornia/**" = ["T201"]  # T201 applies to the library only
"*/__init__.py" = ["F401", "F403"]  # Allow unused imports and star imports
"benchmarks/*" = [
  "BLE",
  "RUF005",
  "RUF012",
  "S101",
  "S311",
  "S603",
  "D",
]  # allow assert, random, subprocess calls, ignore BLE, mutable class attr
"docs/*" = [
  "PLR0912",
  "PLR0915",
  "S101",
  "D",
]  # allow assert, ignore max branches and statements
"docs/generate_examples.py" = ["C901"]  # Allow too complex function
"docs/export_support/*" = [
  "BLE",
  "E741",
  "PLC3002",
  "PLR0911",
  "S603",
  "S607",
]  # survey harness: subprocess workers, inline lambdas that build case inputs
"kornia/__init__.py" = ["I001"]  # Allow unsorted imports
"kornia/feature/dedode/*" = [
  "C408",
  "F401",
  "F841",
  "FLY002",
  "PLR1714",
]  # allow DINOv2 things
"testing/*" = [
  "S101",  # allow assert
  "D",  # Don't enforce documentation rules
]
"tests/*" = [
  "BLE",
  "RUF005",
  "RUF012",
  "S101",
  "S311",
  "B017",  # Check for Exception since KORNIA_CHECK raises it
  "D",  # Don't enforce documentation rules
]  # allow assert, random, ignore BLE, mutable class attr

# Changelog fragments are assembled only when preparing a release.
[tool.towncrier]
directory = "changelog.d"
filename = "CHANGELOG.md"
title_format = "## [{version}] - {project_date}"
issue_format = "[#{issue}](https://github.com/kornia/kornia/pull/{issue})"
# Setting ignore enables strict filename validation; tolerate Finder metadata only.
ignore = [".DS_Store"]
issue_pattern = "[0-9]+"

[[tool.towncrier.type]]
directory = "added"
name = "Added"

[[tool.towncrier.type]]
directory = "fixed"
name = "Bug fixes"

[[tool.towncrier.type]]
directory = "breaking"
name = "Breaking changes"

[tool.ty.src]
include = ["kornia"]
exclude = ["tests", "docs", "conftest.py"]

[tool.ty.rules]
# A `type: ignore` that suppresses nothing is an error, so dead ones do not pile up again (#2445)
unused-ignore-comment = "error"

[[tool.ty.overrides]]
include = ["kornia"]

[tool.ty.overrides.rules]
unresolved-import = "ignore"
unresolved-attribute = "ignore"
call-non-callable = "ignore"
invalid-argument-type = "ignore"
invalid-method-override = "ignore"
invalid-type-form = "ignore"
no-matching-overload = "ignore"
unsupported-operator = "ignore"
possibly-missing-attribute = "ignore"
not-subscriptable = "ignore"
# Silenced because ty has issues with:
# - Iterator[Enum] from metaclass __iter__ returning Iterator[object]
# - Scalar wrapper return types in geometry/plane.py
invalid-return-type = "ignore"
# Silenced because ty doesn't understand star unpacking with union types
# e.g., `[-i for i in unpadding]` where unpadding is int | tuple
# or `*images.shape, images.device` unpacking
not-iterable = "ignore"
# Silenced because ty struggles with:
# - Star unpacking assignments like `b, c, h, w, device = *tensor.shape, tensor.device`
# - dict containing partial() alongside type[nn.Module]
# - Attribute assignments with getattr fallback to None
invalid-assignment = "ignore"
# Silenced because KORNIA_UNWRAP intentionally uses cast for type narrowing
redundant-cast = "ignore"

[[tool.uv.index]]
name = "pytorch-cu132"
url = "https://download.pytorch.org/whl/cu132"
explicit = true