diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..f807625d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{json,txt,toml}] +indent_style = space +indent_size = 2 + +[*.{md,markdown}] +trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes index f951c57d..7ce9c6ee 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,6 +4,7 @@ # These files are always considered text and should use LF. # See core.whitespace @ https://git-scm.com/docs/git-config for whitespace flags. *.py text eol=lf whitespace=blank-at-eol,space-before-tab,tab-in-indent,tabwidth=4 diff=python +*.json text eol=lf whitespace=blank-at-eol,space-before-tab,tab-in-indent,tabwidth=2 *.sh text eol=lf whitespace=blank-at-eol diff=bash *.md text eol=lf whitespace=blank-at-eol diff=markdown *.rst text eol=lf whitespace=blank-at-eol diff --git a/.github/workflows/_static-analysis.yml b/.github/workflows/_static-analysis.yml index fd49edea..b5b2df6c 100644 --- a/.github/workflows/_static-analysis.yml +++ b/.github/workflows/_static-analysis.yml @@ -15,6 +15,14 @@ jobs: python-version: ["3.12"] steps: - uses: actions/checkout@v7 + with: + fetch-depth: 0 + + - name: Run Betterleaks + uses: dortort/betterleaks-action@v0.1.0 + with: + version: "v1.9.0" + github-token: ${{ secrets.GITHUB_TOKEN }} - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v7 @@ -33,21 +41,17 @@ jobs: run: | python -m pip install pip pip install pylic~=3.6.1 - pip install -e '.' + pip install -e '.[lint]' - name: License check run: | pylic check --allow-extra-safe-licenses - - name: Install lint dependencies - run: | - pip install -e '.[lint]' - - name: Cache pre-commit uses: actions/cache@v6 with: - path: ~/.cache/pre-commit - key: ${{ runner.os }}-prec-${{ hashFiles('.pre-commit-config.yaml') }} + path: ~/.cache/prek + key: ${{ runner.os }}-prec-${{ hashFiles('prek.toml') }} restore-keys: | ${{ runner.os }}-prec- @@ -55,4 +59,4 @@ jobs: env: SKIP: sphinx-html,sphinx-linkcheck run: | - pre-commit run --all-files + prek run --all-files diff --git a/.github/workflows/_test-integrations.yml b/.github/workflows/_test-integrations.yml index 68ec9bc2..75985619 100644 --- a/.github/workflows/_test-integrations.yml +++ b/.github/workflows/_test-integrations.yml @@ -100,7 +100,7 @@ jobs: - name: Install dependencies run: | - pip install toml + pip install 'tomli~=2.4.1' 'tomli-w~=1.2.0' python scripts/generate_lite_toml.py mv -f pyproject-lite.toml pyproject.toml pip install -e '.[test]' diff --git a/.github/workflows/_test-units.yml b/.github/workflows/_test-units.yml index 770f17e0..5d7972ed 100644 --- a/.github/workflows/_test-units.yml +++ b/.github/workflows/_test-units.yml @@ -81,11 +81,12 @@ jobs: - name: Install dependencies run: | - pip install toml + pip install 'tomli~=2.4.1' 'tomli-w~=1.2.0' python scripts/generate_lite_toml.py mv -f pyproject-lite.toml pyproject.toml pip install -e '.[test]' shell: bash + - name: Unit testing with pytest run: | pytest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index da826bd5..00000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,61 +0,0 @@ -repos: - - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.15.22 - hooks: - - id: ruff-check - args: [ --fix, --exit-non-zero-on-fix] - - id: ruff-format - - - repo: https://github.com/betterleaks/betterleaks - rev: v1.6.1 - hooks: - - id: betterleaks - - - repo: https://github.com/PyCQA/pylint - rev: v4.0.6 - hooks: - - id: pylint - name: pylint - entry: pylint - language: system - types: [python] - args: [ - "-j2" - ] - - repo: https://github.com/pypa/pip-audit - rev: v2.10.1 - hooks: - - id: pip-audit - args: ["."] - files: ^(requirements.*\.txt|setup\.cfg|setup\.py|pyproject\.toml)$ - stages: [pre-push] - - - repo: https://github.com/pre-commit/mirrors-mypy - rev: v2.3.0 - hooks: - - id: mypy - args: [] - exclude: "tests/|examples/|docs/" - additional_dependencies: - - httpx - - types-setuptools - - importlib-metadata - - types-Pillow - - types-toml - - repo: local - hooks: - - id: sphinx-html - name: Sphinx HTML build - entry: make -C docs html - language: system - pass_filenames: false - files: ^docs/.*$|^mindee/.*\.py$ - stages: [pre-push] - - - id: sphinx-linkcheck - name: Sphinx Linkcheck - entry: make -C docs linkcheck - language: system - pass_filenames: false - files: ^docs/.*$|^mindee/.*\.py$ - stages: [pre-push] diff --git a/mindee/v2/__init__.py b/mindee/v2/__init__.py index 0dc220c7..c36e8245 100644 --- a/mindee/v2/__init__.py +++ b/mindee/v2/__init__.py @@ -34,7 +34,6 @@ "SplitParameters", "SplitResponse", "extract_multiple_crops", - "extract_multiple_crops", "extract_multiple_splits", "extract_single_crop", ] diff --git a/mindee/v2/file_operations/__init__.py b/mindee/v2/file_operations/__init__.py index 3553e6d7..72961ff8 100644 --- a/mindee/v2/file_operations/__init__.py +++ b/mindee/v2/file_operations/__init__.py @@ -5,7 +5,6 @@ from mindee.v2.file_operations.split import extract_multiple_splits __all__ = [ - "extract_multiple_crops", "extract_multiple_crops", "extract_multiple_splits", "extract_single_crop", diff --git a/mindee/v2/product/crop/__init__.py b/mindee/v2/product/crop/__init__.py index 39a3ea20..99970c60 100644 --- a/mindee/v2/product/crop/__init__.py +++ b/mindee/v2/product/crop/__init__.py @@ -7,7 +7,6 @@ __all__ = [ "CropInference", "CropItem", - "CropItem", "CropParameters", "CropResponse", "CropResult", diff --git a/prek.toml b/prek.toml new file mode 100644 index 00000000..55914957 --- /dev/null +++ b/prek.toml @@ -0,0 +1,92 @@ +# Configuration file for `prek`, a git hook framework written in Rust. +# See https://prek.j178.dev for more information. +#:schema https://www.schemastore.org/prek.json + +[[repos]] +repo = "https://github.com/astral-sh/ruff-pre-commit" +rev = "v0.16.9" +hooks = [ + { + id = "ruff-check", + args = [ + "--fix", + "--exit-non-zero-on-fix", + ] + }, + { id = "ruff-format" } +] + +[[repos]] +repo = "https://github.com/betterleaks/betterleaks" +rev = "v1.9.0" +hooks = [ + { id = "betterleaks" } +] + +[[repos]] +repo = "https://github.com/PyCQA/pylint" +rev = "v4.1.1" +hooks = [ + { + id = "pylint", + name = "pylint", + entry = "pylint", + language = "system", + types = ["python"], + args = ["-j2"], + } +] + +[[repos]] +repo = "https://github.com/pypa/pip-audit" +rev = "v2.10.1" +hooks = [ + { + id = "pip-audit", + args = ["."], + files = '^(requirements.*\.txt|setup\.cfg|setup\.py|pyproject\.toml)$', + stages = ["pre-push"], + } +] + +[[repos]] +repo = "https://github.com/pre-commit/mirrors-mypy" +rev = "v2.3.1" +hooks = [ + { + id = "mypy", + args = [ ], + exclude = "tests/|examples/|docs/", + additional_dependencies = [ + "httpx", + "types-setuptools", + "importlib-metadata", + "types-Pillow", + "tomli", + "tomli_w", + ] + } +] + +[[repos]] +repo = "local" +hooks = [ + { + id = "sphinx-html", + name = "Sphinx HTML build", + entry = "make -C docs html", + language = "system", + pass_filenames = false, + files = '^docs/.*$|^mindee/.*\.py$', + stages = ["pre-push"], + }, + { + id = "sphinx-linkcheck", + name = "Sphinx Linkcheck", + entry = "make -C docs linkcheck", + language = "system", + pass_filenames = false, + files = '^docs/.*$|^mindee/.*\.py$', + stages = ["pre-push"], + } +] diff --git a/pyproject.toml b/pyproject.toml index 8d5df091..6eea23d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,12 +42,12 @@ Changelog = "https://github.com/mindee/mindee-api-python/blob/main/CHANGELOG.md" [project.optional-dependencies] lint = [ - "pylint==4.0.6", - "pre-commit~=4.6.0", + "pylint==4.1.1", + "prek~=0.5.4", "pip-audit==2.10.1", ] test = [ - "toml~=0.10.2", + "tomli~=2.4.1", "pytest>=9.0.3,<9.2.0", "pytest-cov~=7.1.0", "respx~=0.23.1" @@ -60,7 +60,8 @@ docs = [ build = [ "build", "twine", - "toml" + "tomli~=2.4.1", + "tomli-w~=1.2.0" ] [project.scripts] diff --git a/scripts/generate_lite_toml.py b/scripts/generate_lite_toml.py index 637150d1..6cecf604 100644 --- a/scripts/generate_lite_toml.py +++ b/scripts/generate_lite_toml.py @@ -1,12 +1,13 @@ from typing import Any -import toml +import tomli +import tomli_w def generate_lite() -> None: """Generates the mindee-lite version of pyproject.toml""" - with open("pyproject.toml", encoding="utf-8") as file_data: - data: dict[str, Any] = toml.load(file_data) + with open("pyproject.toml", encoding="utf-8") as read_handle: + data: dict[str, Any] = tomli.loads(read_handle.read()) data["project"]["name"] = "mindee-lite" data["project"]["description"] = ( @@ -32,8 +33,8 @@ def generate_lite() -> None: "ini_options" ]["addopts"].replace(" lite", " pypdfium2 and not pillow") - with open("pyproject-lite.toml", "w", encoding="utf-8") as file_data: - toml.dump(data, file_data) + with open("pyproject-lite.toml", "w", encoding="utf-8") as write_handle: + write_handle.write(tomli_w.dumps(data)) print("Successfully generated pyproject-lite.toml") diff --git a/tests/data b/tests/data index 5037ffc3..8b8423d2 160000 --- a/tests/data +++ b/tests/data @@ -1 +1 @@ -Subproject commit 5037ffc3c443ec0c93ed673acd22d6ae1c65771a +Subproject commit 8b8423d239a360f7a8ac72d77e53fb644a76e345 diff --git a/tests/test_pkg_versions.py b/tests/test_pkg_versions.py index 7419dabf..52f03f25 100644 --- a/tests/test_pkg_versions.py +++ b/tests/test_pkg_versions.py @@ -3,7 +3,7 @@ import re from pathlib import Path -import toml +import tomli def _test_version(versions_a, versions_b, key): @@ -12,7 +12,9 @@ def _test_version(versions_a, versions_b, key): def test_style_pkg_versions(): """Check black, flake8, isort and pydocstyle versions consistency.""" - config = toml.load(Path(__file__).parent.parent.joinpath("pyproject.toml")) + config = tomli.loads( + Path(__file__).parent.parent.joinpath("pyproject.toml").read_text() + ) line_sep = re.compile(r"(==|~=|>=)") requirements_versions = {} for line in config["project"]["optional-dependencies"]["lint"]: @@ -21,14 +23,13 @@ def test_style_pkg_versions(): # Get pre-commit versions pre_commit_versions = {} - pre_commit_path = Path(__file__).parent.parent.joinpath(".pre-commit-config.yaml") - with open(pre_commit_path, encoding="utf-8") as file_p: - lines = file_p.readlines() - for idx, line in enumerate(lines): - if "repo:" in line: - pkg_name = line.strip().split("/")[-1].strip().replace("mirrors-", "") - pkg_version = lines[idx + 1].strip().split(":")[-1].strip() - pre_commit_versions[pkg_name] = pkg_version + config = tomli.loads(Path(__file__).parent.parent.joinpath("prek.toml").read_text()) + for repo in config["repos"]: + if not repo.get("rev"): + continue + pkg_name = repo["repo"].strip().split("/")[-1].strip().replace("mirrors-", "") + pkg_version = repo["rev"].strip().split(":")[-1].strip() + pre_commit_versions[pkg_name] = pkg_version for req in ("pylint",): _test_version(requirements_versions, pre_commit_versions, req)