Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 deletions .github/workflows/_static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,26 +41,22 @@ 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-

- name: Run all static analysis
env:
SKIP: sphinx-html,sphinx-linkcheck
run: |
pre-commit run --all-files
prek run --all-files
2 changes: 1 addition & 1 deletion .github/workflows/_test-integrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]'
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/_test-units.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 0 additions & 61 deletions .pre-commit-config.yaml

This file was deleted.

1 change: 0 additions & 1 deletion mindee/v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"SplitParameters",
"SplitResponse",
"extract_multiple_crops",
"extract_multiple_crops",
"extract_multiple_splits",
"extract_single_crop",
]
1 change: 0 additions & 1 deletion mindee/v2/file_operations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion mindee/v2/product/crop/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
__all__ = [
"CropInference",
"CropItem",
"CropItem",
"CropParameters",
"CropResponse",
"CropResult",
Expand Down
92 changes: 92 additions & 0 deletions prek.toml
Original file line number Diff line number Diff line change
@@ -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"
Comment thread
ianardee marked this conversation as resolved.
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"],
}
]
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -60,7 +60,8 @@ docs = [
build = [
"build",
"twine",
"toml"
"tomli~=2.4.1",
"tomli-w~=1.2.0"
]

[project.scripts]
Expand Down
11 changes: 6 additions & 5 deletions scripts/generate_lite_toml.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from typing import Any

import toml
import tomli
import tomli_w
Comment thread
ianardee marked this conversation as resolved.


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"] = (
Expand All @@ -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")

Expand Down
21 changes: 11 additions & 10 deletions tests/test_pkg_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re
from pathlib import Path

import toml
import tomli


def _test_version(versions_a, versions_b, key):
Expand All @@ -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"]:
Expand All @@ -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)
Loading