Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Clean up metadata and fix requirements (#2232)

João Gustavo A. Amorimbd0881a30a8e
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 1cea150d7..43eef7800 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -10,6 +10,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-yaml
+ - id: requirements-txt-fixer
- id: pretty-format-json
exclude: ^$|.devcontainer
@@ -17,14 +18,6 @@ repos:
rev: "0.9.1"
hooks:
- id: pyproject-fmt
- args:
- - --indent
- - "4"
-
- - repo: https://github.com/abravalheri/validate-pyproject
- rev: v0.12.1
- hooks:
- - id: validate-pyproject
- repo: https://github.com/psf/black
rev: 23.1.0
diff --git a/kornia/__init__.py b/kornia/__init__.py
index 67c10fa72..dc164505a 100644
--- a/kornia/__init__.py
+++ b/kornia/__init__.py
@@ -13,11 +13,4 @@ from kornia.testing import xla_is_available
from kornia.utils import eye_like, vec_like, create_meshgrid, image_to_tensor, tensor_to_image
# Version variable
-import sys
-
-if sys.version_info >= (3, 8): # pragma: >=3.8 cover
- import importlib.metadata as importlib_metadata
-else: # pragma: <3.8 cover
- import importlib_metadata
-
-__version__ = importlib_metadata.version('kornia')
+__version__ = "0.6.11.dev"
diff --git a/kornia/utils/_compat.py b/kornia/utils/_compat.py
index 45a20abaf..fcac28497 100644
--- a/kornia/utils/_compat.py
+++ b/kornia/utils/_compat.py
@@ -1,9 +1,8 @@
from typing import TYPE_CHECKING, Callable, ContextManager, List, Optional, Tuple, TypeVar
import torch
-from torch import Tensor
-
from packaging import version
+from torch import Tensor
def torch_version() -> str:
diff --git a/packaging/README.rst b/packaging/README.rst
deleted file mode 100644
index df72f09eb..000000000
--- a/packaging/README.rst
+++ /dev/null
@@ -1,22 +0,0 @@
-Building Kornia packages for release
-====================================
-
-Wheels
-------
-
-Linux
-#####
-
-In order to generate wheels define ```KORNIA_BUILD_VERSION```.
-
-.. code:: bash
-
- KORNIA_BUILD_VERSION=0.x.x ./build_wheel.sh
-
-This will produce a ```*whl``` file under ```OUT_DIR```, by default to ```/tmp```.
-You can upload the wheels using `Twine <https://pypi.org/project/twine/>`_
-
-.. code:: bash
-
- cd /tmp/remote
- python3 -m twine upload *.whl
diff --git a/packaging/build_wheel.sh b/packaging/build_wheel.sh
deleted file mode 100755
index 936bfab94..000000000
--- a/packaging/build_wheel.sh
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/bash -ex
-
-## NOTE: define KORNIA_BUILD_VERSION each release
-## KORNIA_BUILD_VERSION=0.3.0
-## PYTORCH_VERSION=1.5.0
-
-export OUT_DIR="/tmp/remote"
-
-# move to project root and create the wheel
-cd /tmp
-rm -rf kornia/
-git clone https://github.com/kornia/kornia.git
-
-cd /tmp/kornia
-git checkout v$KORNIA_BUILD_VERSION
-python3 setup.py clean
-python3 setup.py bdist_wheel
-
-mkdir -p $OUT_DIR
-cp dist/*.whl $OUT_DIR/
-
-## upload
-## NOTE: to upload install twine
-## Example: python3 -m twine upload dist/*
diff --git a/pyproject.toml b/pyproject.toml
index 2347e225b..ebfdf9b5a 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,164 +1,123 @@
-[build-system]
-build-backend = "setuptools.build_meta"
-requires = [
- "setuptools>=61.2",
-]
-
[project]
name = "kornia"
-version = "0.6.11.dev"
description = "Open Source Differentiable Computer Vision Library for PyTorch"
-[project.readme]
-file = "README.md"
-content-type = "text/markdown"
-
keywords = [
- "computer vision",
- "deep learning",
- "pytorch",
+ "computer vision",
+ "deep learning",
+ "pytorch",
]
license = {text = "Apache-2.0"}
authors = [{name = "Edgar Riba", email = "[email protected]"}]
requires-python = ">=3.7"
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",
- "Programming Language :: Python :: 3 :: Only",
- "Topic :: Scientific/Engineering :: Artificial Intelligence",
- "Topic :: Scientific/Engineering :: Image Processing",
- "Topic :: Software Development :: Libraries",
-]
-dependencies = [
- "packaging",
- "torch>=1.9.1",
-]
-[project.optional-dependencies]
-dev = [
- "isort",
- "kornia-rs==0.0.8",
- "mypy[reports]",
- "numpy",
- "opencv-python",
- "pre-commit>=2",
- "pydocstyle",
- "pytest==7.2.1",
- "pytest-cov==4",
- "scipy",
+ "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",
+ "Programming Language :: Python :: 3 :: Only",
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
+ "Topic :: Scientific/Engineering :: Image Processing",
+ "Topic :: Software Development :: Libraries",
]
-docs = [
- "furo",
- "matplotlib",
- "opencv-python",
- "PyYAML<6.1.0,>=5.1",
- "sphinx>=4",
- "sphinx-autodoc-defaultargs",
- "sphinx-autodoc-typehints",
- "sphinx-copybutton>=0.3",
- "sphinx-design",
- "sphinx-rtd-theme>0.5",
- "sphinxcontrib-bibtex",
- "sphinxcontrib-gtagjs",
- "sphinxcontrib-youtube",
- "torchvision",
-]
-x = [
- "accelerate==0.16",
+dynamic = [
+ "dependencies",
+ "optional-dependencies",
+ "readme",
+ "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"
-"Source Code" = "https://github.com/kornia/kornia"
+ "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"
+ "Source Code" = "https://github.com/kornia/kornia"
+
+[build-system]
+build-backend = "setuptools.build_meta"
+requires = [
+ "setuptools>=61.2",
+]
[tool.setuptools]
-zip-safe = true
-license-files = ["LICENSE"]
-include-package-data = false
+ zip-safe = true
+ license-files = ["LICENSE"]
+ include-package-data = false
+
+[tool.setuptools.dynamic]
+ dependencies = {file = ["requirements/requirements.txt"]}
+ version = {attr = "kornia.__version__"}
+ readme = {file = ["README.md"], content-type = "text/markdown"}
+
+ [tool.setuptools.dynamic.optional-dependencies]
+ dev = {file = "requirements/requirements-dev.txt"}
+ docs = {file = ["requirements/requirements-docs.txt"]}
+ x = {file = ["requirements/requirements-x.txt"]}
[tool.setuptools.packages.find]
exclude = [
"docs*",
- "test",
- "test.*",
+ "test*",
"examples*",
]
namespaces = false
[tool.setuptools.package-data]
-kornia = ["py.typed"]
+ kornia = ["py.typed"]
[tool.black]
-line-length = 120
-skip-string-normalization = true
-skip-magic-trailing-comma = true
+ line-length = 120
+ skip-string-normalization = true
+ skip-magic-trailing-comma = true
[tool.isort]
-multi_line_output=3
-include_trailing_comma = true
-line_length = 120
-profile = "black"
-known_first_party = [
- "examples",
- "kornia",
- "tests",
-]
-skip_glob = []
-skip = [
- "kornia/__init__.py"
-]
+ 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]
-norecursedirs = [
- ".git",
- ".github",
- "dist",
- "build",
-]
-addopts = "--color=yes"
-markers = [
+ addopts = "--color=yes"
+ testpaths = ["test"]
+ markers =[
"jit: mark a test as torchscript test",
"grad: mark a test as gradcheck test",
- "nn: mark a test as module test",
+ "nn: mark a test as module test"
]
-testpaths = ["test"]
[tool.coverage.report]
exclude_lines = [
- "pragma: no cover",
- "def __repr__",
- "if self.debug:",
- "raise",
- "if 0:",
- "if __name__ == .__main__.:",
+ "pragma: no cover",
+ "def __repr__",
+ "if self.debug:",
+ "raise",
+ "if 0:",
+ "if __name__ == .__main__.:",
]
[tool.mypy]
-files = ["kornia/"]
-pretty = true
-check_untyped_defs = true
-disallow_any_generics = true
-disallow_incomplete_defs = true
-show_error_codes = true
-ignore_missing_imports = true
-no_implicit_optional = true
-warn_unused_ignores = true
-warn_redundant_casts = true
+ files = ["kornia/"]
+ pretty = true
+ check_untyped_defs = true
+ disallow_any_generics = true
+ disallow_incomplete_defs = true
+ show_error_codes = true
+ ignore_missing_imports = true
+ no_implicit_optional = true
+ warn_unused_ignores = true
+ warn_redundant_casts = true
[tool.distutils.bdist_wheel]
-universal = true
-
-[tool.aliases]
-test = "pytest"
+ universal = true
[tool.pydocstyle]
match = '.*\.py'
diff --git a/requirements/requirements-dev.txt b/requirements/requirements-dev.txt
new file mode 100644
index 000000000..04edb8d2b
--- /dev/null
+++ b/requirements/requirements-dev.txt
@@ -0,0 +1,10 @@
+isort
+kornia-rs==0.0.8
+mypy[reports]
+numpy
+opencv-python
+pre-commit>=2
+pydocstyle
+pytest==7.2.1
+pytest-cov==4
+scipy
diff --git a/requirements/requirements-docs.txt b/requirements/requirements-docs.txt
new file mode 100644
index 000000000..651d56e7e
--- /dev/null
+++ b/requirements/requirements-docs.txt
@@ -0,0 +1,13 @@
+furo
+matplotlib
+opencv-python
+PyYAML>=5.1
+sphinx>=4
+sphinx-autodoc-defaultargs
+sphinx-autodoc-typehints
+sphinx-copybutton>=0.3
+sphinx-design
+sphinxcontrib-bibtex
+sphinxcontrib-gtagjs
+sphinxcontrib-youtube
+torchvision
diff --git a/requirements/requirements-x.txt b/requirements/requirements-x.txt
new file mode 100644
index 000000000..8526bb438
--- /dev/null
+++ b/requirements/requirements-x.txt
@@ -0,0 +1 @@
+accelerate==0.16
diff --git a/requirements/requirements.txt b/requirements/requirements.txt
new file mode 100644
index 000000000..e14e8c983
--- /dev/null
+++ b/requirements/requirements.txt
@@ -0,0 +1,2 @@
+packaging
+torch>=1.9.1
diff --git a/test/augmentation/test_auto_operation.py b/test/augmentation/test_auto_operation.py
index dac5ab87b..cfb8b0741 100644
--- a/test/augmentation/test_auto_operation.py
+++ b/test/augmentation/test_auto_operation.py
@@ -1,5 +1,4 @@
import inspect
-from test.augmentation.test_container import reproducibility_test
from typing import List
import pytest
@@ -14,6 +13,7 @@ from kornia.augmentation.auto.trivial_augment import TrivialAugment
from kornia.augmentation.container import AugmentationSequential
from kornia.geometry.bbox import bbox_to_mask
from kornia.testing import assert_close
+from test.augmentation.test_container import reproducibility_test
def _find_all_ops() -> List[OperationBase]:
diff --git a/test/color/test_hls.py b/test/color/test_hls.py
index 86615c1ca..b01bc1c9d 100644
--- a/test/color/test_hls.py
+++ b/test/color/test_hls.py
@@ -3,11 +3,11 @@ import warnings
import pytest
import torch
+from packaging import version
from torch.autograd import gradcheck
import kornia
from kornia.testing import BaseTester
-from packaging import version
class TestRgbToHls(BaseTester):
diff --git a/test/color/test_raw.py b/test/color/test_raw.py
index 3e84d6bb4..04f1f1545 100644
--- a/test/color/test_raw.py
+++ b/test/color/test_raw.py
@@ -2,12 +2,12 @@ import warnings
import pytest
import torch
+from packaging import version
from torch.autograd import gradcheck
import kornia
from kornia.testing import BaseTester # test utils
from kornia.testing import assert_close
-from packaging import version
class TestRawToRgb(BaseTester):
diff --git a/test/enhance/test_histogram.py b/test/enhance/test_histogram.py
index f34249cd3..431fe21ff 100644
--- a/test/enhance/test_histogram.py
+++ b/test/enhance/test_histogram.py
@@ -1,11 +1,11 @@
import pytest
import torch
+from packaging import version
from torch.autograd import gradcheck
import kornia
import kornia.testing as utils # test utils
from kornia.testing import assert_close
-from packaging import version
class TestImageHistogram2d:
diff --git a/test/nerf/test_data_utils.py b/test/nerf/test_data_utils.py
index 4953bfd7a..96e9e9d42 100755
--- a/test/nerf/test_data_utils.py
+++ b/test/nerf/test_data_utils.py
@@ -1,11 +1,10 @@
-from test.nerf.test_rays import create_four_cameras
-
import torch
from kornia.core import Device
from kornia.geometry.camera import PinholeCamera
from kornia.nerf.data_utils import ImageTensors, RayDataset, instantiate_ray_dataloader
from kornia.testing import assert_close
+from test.nerf.test_rays import create_four_cameras
def create_random_images_for_cameras(cameras: PinholeCamera) -> ImageTensors:
diff --git a/test/nerf/test_nerf_solver.py b/test/nerf/test_nerf_solver.py
index 8b18c3bb4..2f04dfd2c 100755
--- a/test/nerf/test_nerf_solver.py
+++ b/test/nerf/test_nerf_solver.py
@@ -1,10 +1,9 @@
-from test.nerf.test_data_utils import create_random_images_for_cameras, create_red_images_for_cameras
-from test.nerf.test_rays import create_four_cameras, create_one_camera
-
import torch
from kornia.nerf.nerf_solver import NerfSolver
from kornia.testing import assert_close
+from test.nerf.test_data_utils import create_random_images_for_cameras, create_red_images_for_cameras
+from test.nerf.test_rays import create_four_cameras, create_one_camera
class TestNerfSolver: