diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 44168c64..64a4da0b 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -29,7 +29,7 @@ jobs: uses: actions/cache@v4 with: path: ~/.cache/pip - key: ${{ runner.os }}-docs-${{ hashFiles('setup.cfg') }} + key: ${{ runner.os }}-docs-${{ hashFiles('pyproject.toml') }} restore-keys: | ${{ runner.os }}-docs- diff --git a/.github/workflows/license.yml b/.github/workflows/license.yml index 640fa666..cbad5179 100644 --- a/.github/workflows/license.yml +++ b/.github/workflows/license.yml @@ -13,7 +13,7 @@ jobs: timeout-minutes: 30 strategy: matrix: - python-version: ["3.8"] + python-version: ["3.10"] steps: - uses: actions/checkout@v4 @@ -26,16 +26,16 @@ jobs: uses: actions/cache@v4 with: path: ~/.cache/pip - key: ${{ runner.os }}-lic-${{ hashFiles('**/setup.cfg') }} + key: ${{ runner.os }}-lic-${{ hashFiles('**/pyproject.toml') }} restore-keys: | ${{ runner.os }}-lic- - name: Install dependencies run: | python -m pip install pip - pip install pylic~=2.2 + pip install pylic~=3.6.1 pip install -e . - name: License check run: | - pylic check + pylic check --allow-extra-safe-licenses diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index 0c76dcb4..ef8af7b7 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -25,15 +25,15 @@ jobs: uses: actions/cache@v4 with: path: ~/.cache/pip - key: ${{ runner.os }}-dev-${{ hashFiles('setup.cfg') }} + key: ${{ runner.os }}-lint-${{ hashFiles('pyproject.toml') }} restore-keys: | - ${{ runner.os }}-dev- + ${{ runner.os }}-lint- - name: Install dependencies # We install the full dev requirements to make sure everything installs OK run: | python -m pip install pip - pip install -e .[dev] + pip install -e .[lint] - name: Cache pre-commit uses: actions/cache@v4 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 6a1d3cee..dce88ebe 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -29,7 +29,7 @@ jobs: uses: actions/cache@v4 with: path: ~/.cache/pip - key: ${{ runner.os }}-build-${{ hashFiles('setup.cfg') }} + key: ${{ runner.os }}-build-${{ hashFiles('pyproject.toml') }} restore-keys: | ${{ runner.os }}-build- diff --git a/.github/workflows/test-code-samples.yml b/.github/workflows/test-code-samples.yml index 2adfae32..d4c1a8ad 100644 --- a/.github/workflows/test-code-samples.yml +++ b/.github/workflows/test-code-samples.yml @@ -33,7 +33,7 @@ jobs: uses: actions/cache@v4 with: path: ~/.cache/pip - key: ${{ runner.os }}-samples-${{ hashFiles('**/setup.cfg') }} + key: ${{ runner.os }}-samples-${{ hashFiles('**/pyproject.toml') }} restore-keys: | ${{ runner.os }}-samples- diff --git a/.github/workflows/test-integration.yml b/.github/workflows/test-integration.yml index 1f62e04d..4b0bfd39 100644 --- a/.github/workflows/test-integration.yml +++ b/.github/workflows/test-integration.yml @@ -38,14 +38,14 @@ jobs: uses: actions/cache@v4 with: path: ~/.cache/pip - key: ${{ runner.os }}-dev-${{ hashFiles('setup.cfg') }} + key: ${{ runner.os }}-test-${{ hashFiles('pyproject.toml') }} restore-keys: | - ${{ runner.os }}-dev- + ${{ runner.os }}-test- - name: Install dependencies run: | python -m pip install pip - pip install -e .[dev] + pip install -e .[test] - name: Run Integration Testing env: MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }} diff --git a/.github/workflows/test-regression.yml b/.github/workflows/test-regression.yml index a3932870..d742cc55 100644 --- a/.github/workflows/test-regression.yml +++ b/.github/workflows/test-regression.yml @@ -39,14 +39,14 @@ jobs: uses: actions/cache@v4 with: path: ~/.cache/pip - key: ${{ runner.os }}-dev-${{ hashFiles('setup.cfg') }} + key: ${{ runner.os }}-test-${{ hashFiles('pyproject.toml') }} restore-keys: | - ${{ runner.os }}-dev- + ${{ runner.os }}-test- - name: Install dependencies run: | python -m pip install pip - pip install -e .[dev] + pip install -e .[test] - name: Run Regression Testing env: MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }} diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 4042a754..eb30463e 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -37,14 +37,14 @@ jobs: uses: actions/cache@v4 with: path: ~/.cache/pip - key: ${{ runner.os }}-dev-${{ hashFiles('setup.cfg') }} + key: ${{ runner.os }}-test-${{ hashFiles('setup.cfg') }} restore-keys: | - ${{ runner.os }}-dev- + ${{ runner.os }}-test- - name: Install dependencies run: | python -m pip install pip - pip install -e .[dev] + pip install -e .[test] - name: Unit testing with pytest env: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 50fa2cfb..e1103c73 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,8 +21,13 @@ repos: "--ignore=D10,D212,D203,D401" ] + - repo: https://github.com/gitleaks/gitleaks + rev: v8.18.2 + hooks: + - id: gitleaks + - repo: https://github.com/PyCQA/pylint - rev: v2.17.7 + rev: v3.2.7 hooks: - id: pylint name: pylint diff --git a/examples/auto_multi_receipts_extraction_example.py b/examples/auto_multi_receipts_extraction_example.py index 2d24ea44..aa995f51 100644 --- a/examples/auto_multi_receipts_extraction_example.py +++ b/examples/auto_multi_receipts_extraction_example.py @@ -1,5 +1,3 @@ -import os - from mindee import Client, product from mindee.extraction.multi_receipts_extractor.multi_receipts_extractor import ( extract_receipts, diff --git a/mindee/extraction/common/image_extractor.py b/mindee/extraction/common/image_extractor.py index 0970df8a..2b4869d2 100644 --- a/mindee/extraction/common/image_extractor.py +++ b/mindee/extraction/common/image_extractor.py @@ -5,7 +5,7 @@ from PIL import Image from mindee.error import MindeeError -from mindee.extraction.common import ExtractedImage +from mindee.extraction.common.extracted_image import ExtractedImage from mindee.geometry import Point, get_min_max_x, get_min_max_y from mindee.input import BytesInput, LocalInputSource diff --git a/mindee/input/local_response.py b/mindee/input/local_response.py index d804d1ed..1ac46b69 100644 --- a/mindee/input/local_response.py +++ b/mindee/input/local_response.py @@ -58,7 +58,7 @@ def as_dict(self) -> Dict[str, Any]: @staticmethod def _process_secret_key( - secret_key: Union[str, bytes, bytearray] + secret_key: Union[str, bytes, bytearray], ) -> Union[bytes, bytearray]: """ Processes the secret key as a byte array. diff --git a/mindee/version b/mindee/version deleted file mode 100644 index 01b73abe..00000000 --- a/mindee/version +++ /dev/null @@ -1 +0,0 @@ -4.13.0 \ No newline at end of file diff --git a/mindee/versions.py b/mindee/versions.py index 435003e4..b90e2e07 100644 --- a/mindee/versions.py +++ b/mindee/versions.py @@ -1,9 +1,6 @@ -import os import sys -dir_path = os.path.dirname(os.path.realpath(__file__)) -with open(os.path.join(dir_path, "version"), "r", encoding="utf-8") as version_file: - __version__ = version_file.read().strip() +__version__ = "4.13.0" python_version = f"{sys.version_info[0]}.{sys.version_info[1]}" diff --git a/pyproject.toml b/pyproject.toml index 160764a2..f4cae3e1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,84 @@ +[build-system] +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "mindee" +authors = [ + {name = "Mindee", email = "opensource@mindee.com"}, +] +dynamic = ["version"] +description = "Mindee API helper library for Python" +readme = "README.md" +license = {file = "LICENSE"} +classifiers = [ + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Operating System :: OS Independent", + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "License :: OSI Approved :: MIT License", +] + +requires-python = ">=3.7" + +dependencies = [ + "pypdfium2>=4.0,<5", + "Pillow>=9.5.0", + "pytz>=2023.3", + "requests~=2.31.0", +] + +[project.urls] +Homepage = "https://www.mindee.com" +Documentation = "https://developers.mindee.com/docs/python-sdk" +Repository = "https://github.com/publicMindee/mindee-api-python" +Issues = "https://github.com/mindee/mindee-api-python/issues" +Changelog = "https://github.com/mindee/mindee-api-python/blob/main/CHANGELOG.md" + +[project.optional-dependencies] +lint = [ + "pylint==3.2.7", + "pre-commit~=3.2.2", + "types-pytz>=2023.3", + "types-requests~=2.31", +] +test = [ + "toml~=0.10.2", + "pytest~=7.4", + "pytest-cov~=4.1", +] +docs = [ + "sphinx~=5.3", + "sphinx_rtd_theme~=1.1", + "sphinx-autodoc-typehints~=1.20", +] +build = [ + "setuptools==57.5.0", + "build", + "twine", +] + +[project.scripts] +mindee = "mindee.cli:main" + + +[tool.setuptools] +packages = ["mindee", ] + +[tool.setuptools.dynamic] +version = {attr = "mindee.versions.__version__"} + +[tool.setuptools.package-data] +"mindee" = ["py.typed"] + + [tool.black] line-length = 88 target-version = [ @@ -26,6 +107,7 @@ warn_unreachable = true module = "pypdfium2.*" ignore_missing_imports = true + [tool.pylic] safe_licenses = [ "Apache Software License", @@ -33,9 +115,11 @@ safe_licenses = [ "Mozilla Public License 2.0 (MPL 2.0)", "BSD License", "(Apache-2.0 OR BSD-3-Clause) AND LicenseRef-PdfiumThirdParty", - "Historical Permission Notice and Disclaimer (HPND)" + "Historical Permission Notice and Disclaimer (HPND)", + "CMU License (MIT-CMU)", ] + [tool.pytest.ini_options] addopts = "--pyargs --cov mindee --cov-report term:skip-covered --cov-report term-missing -m 'not regression and not integration'" python_files = "test*.py" diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 57c5f798..00000000 --- a/setup.cfg +++ /dev/null @@ -1,67 +0,0 @@ -[metadata] -name = mindee -author = Mindee -author_email = opensource@mindee.com -description = Mindee API helper library for Python -long_description = file:README.md -long_description_content_type = text/markdown -classifiers= - Programming Language :: Python :: 3 - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 - Programming Language :: Python :: 3.10 - Programming Language :: Python :: 3.11 - Programming Language :: Python :: 3.12 - Operating System :: OS Independent - Development Status :: 5 - Production/Stable - Intended Audience :: Developers - Topic :: Software Development :: Libraries - License :: OSI Approved :: MIT License -url = https://mindee.com/ -project_urls = - Documentation = https://developers.mindee.com/docs/python-sdk - Source = https://github.com/publicMindee/mindee-api-python -license = MIT -license_files = LICENSE -platform = any - -[options] -zip_safe = False -packages = find: -include_package_data = True -python_requires = >=3.7 -install_requires = - pypdfium2>=4.0,<5 - Pillow>=9.5.0 - pytz>=2023.3 - requests~=2.31 - -[options.entry_points] -console_scripts = - mindee-cli = mindee.cli:main - -[options.package_data] -mindee = - version - py.typed - -[options.extras_require] -dev = - pylint==2.17.7 - setuptools==51.3.3 - pre-commit~=2.21.0 - types-pytz~=2023.3 - types-requests~=2.31 - pytest~=7.4 - pytest-cov~=4.1 -docs = - sphinx~=5.3 - sphinx_rtd_theme~=1.1 - sphinx-autodoc-typehints~=1.20 -build = - build - twine - -[options.packages.find] -exclude = tests diff --git a/setup.py b/setup.py deleted file mode 100644 index cfd3811d..00000000 --- a/setup.py +++ /dev/null @@ -1,14 +0,0 @@ -"""Mindee module setup.""" - -import os - -from setuptools import setup - -dir_path = os.path.dirname(os.path.realpath(__file__)) -version_file = os.path.join(dir_path, "mindee", "version") -with open(version_file, "r", encoding="utf-8") as file_p: - __version__ = file_p.read().strip() - -setup( - version=__version__, -) diff --git a/tests/extras/test_extras_integration.py b/tests/extras/test_extras_integration.py index a2006903..f6e5761b 100644 --- a/tests/extras/test_extras_integration.py +++ b/tests/extras/test_extras_integration.py @@ -1,8 +1,6 @@ -import json - import pytest -from mindee import AsyncPredictResponse, Client +from mindee import Client from mindee.product import InternationalIdV2, InvoiceV4 from tests.product import PRODUCT_DATA_DIR diff --git a/tests/mindee_http/test_error.py b/tests/mindee_http/test_error.py index b03b66e3..f9ac9776 100644 --- a/tests/mindee_http/test_error.py +++ b/tests/mindee_http/test_error.py @@ -10,7 +10,6 @@ handle_error, ) from mindee.input.sources import PathInput -from mindee.mindee_http import clean_request_json from tests.test_inputs import FILE_TYPES_DIR from tests.utils import clear_envvars, dummy_envvars diff --git a/tests/product/custom/test_custom_v1_v2.py b/tests/product/custom/test_custom_v1_v2.py index 3e628d03..74be7ab0 100644 --- a/tests/product/custom/test_custom_v1_v2.py +++ b/tests/product/custom/test_custom_v1_v2.py @@ -2,7 +2,6 @@ import pytest -from mindee.error.mindee_error import MindeeProductError from mindee.geometry.quadrilateral import Quadrilateral from mindee.parsing.common.document import Document from mindee.parsing.common.page import Page diff --git a/tests/test_cli.py b/tests/test_cli.py index 41eb9433..1407582f 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,6 +1,5 @@ import json from argparse import Namespace -from sys import api_version import pytest diff --git a/tests/test_pkg_versions.py b/tests/test_pkg_versions.py index e9a1e4f3..7419dabf 100644 --- a/tests/test_pkg_versions.py +++ b/tests/test_pkg_versions.py @@ -1,9 +1,10 @@ """Test to check if style packages are in same versions as pre-commit config.""" -import configparser import re from pathlib import Path +import toml + def _test_version(versions_a, versions_b, key): assert versions_a[key].replace("v", "") == versions_b[key].replace("v", "") @@ -11,11 +12,10 @@ def _test_version(versions_a, versions_b, key): def test_style_pkg_versions(): """Check black, flake8, isort and pydocstyle versions consistency.""" - config = configparser.ConfigParser() - config.read(Path(__file__).parent.parent.joinpath("setup.cfg")) - line_sep = re.compile(r"(==|~=)") + config = toml.load(Path(__file__).parent.parent.joinpath("pyproject.toml")) + line_sep = re.compile(r"(==|~=|>=)") requirements_versions = {} - for line in config["options.extras_require"]["dev"].split(): + for line in config["project"]["optional-dependencies"]["lint"]: split_line = line_sep.split(line.strip()) requirements_versions[split_line[0]] = split_line[2]