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
6 changes: 6 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ jobs:
- name: Analysing the code with Black
run: |
black --check .
- name: Analysing the code with mypy
run: |
mypy --install-types --non-interactive ./mindee
- name: Analysing the code with pylint
run: |
pylint ./mindee
6 changes: 3 additions & 3 deletions mindee/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}


class Client(object):
class Client:
def __init__(
self,
expense_receipt_token=None,
Expand Down Expand Up @@ -231,7 +231,7 @@ def parse_financial_document(
return self._wrap_response(input_file, response, "financial_document")


class Response(object):
class Response:
def __init__(
self, http_response=None, pages=None, document=None, document_type=None
):
Expand Down Expand Up @@ -311,7 +311,7 @@ def format_response(json_response, document_type, input_file):
raise Exception("Document type not supported.")

# Create page level objects
for page_n, page_prediction in enumerate(
for _, page_prediction in enumerate(
json_response["document"]["inference"]["pages"]
):
pages.append(
Expand Down
4 changes: 3 additions & 1 deletion mindee/documents/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Document(object):
class Document:
def __init__(self, input_file=None):
self.filepath = None
self.filename = None
Expand All @@ -11,6 +11,7 @@ def __init__(self, input_file=None):
self.checklist = {}

def request(self, *args):
"""Make request to the product endpoint"""
raise NotImplementedError()

def _checklist(self, *args):
Expand All @@ -20,4 +21,5 @@ def _reconstruct(self, *args):
pass

def all_checks(self):
"""Return all checks"""
return all(self.checklist)
3 changes: 1 addition & 2 deletions mindee/documents/car_plate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from mindee.documents import Document
from mindee.fields import Field
from mindee.http import make_api_request, make_predict_url
import os


class CarPlate(Document):
Expand Down Expand Up @@ -46,7 +45,7 @@ def build_from_api_prediction(self, api_prediction, page_n=0):
for license_plate in api_prediction["license_plates"]
]

def __str__(self):
def __str__(self) -> str:
return (
"-----Car plate data-----\n"
"Filename: %s\n"
Expand Down
3 changes: 1 addition & 2 deletions mindee/documents/financial_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from mindee.http import make_api_request, make_predict_url
from mindee.documents.invoice import Invoice
from mindee.documents.receipt import Receipt
import os


class FinancialDocument(Document):
Expand Down Expand Up @@ -159,7 +158,7 @@ def build_from_api_prediction(self, api_prediction, input_file, page_n=0):
self.payment_details = []
self.company_number = []

def __str__(self):
def __str__(self) -> str:
return (
"-----Financial Document data-----\n"
"Filename: %s \n"
Expand Down
3 changes: 1 addition & 2 deletions mindee/documents/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from mindee.fields.payment_details import PaymentDetails
from mindee.fields.tax import Tax
from mindee.http import make_api_request, make_predict_url
import os


class Invoice(Document):
Expand Down Expand Up @@ -153,7 +152,7 @@ def build_from_api_prediction(self, api_prediction, page_n=0):
{"value": None, "probability": 0.0}, value_key="value", page_n=page_n
)

def __str__(self):
def __str__(self) -> str:
return (
"-----Invoice data-----\n"
"Filename: %s \n"
Expand Down
5 changes: 2 additions & 3 deletions mindee/documents/passport.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from datetime import datetime
from mindee.documents import Document
from mindee.fields import Field
from mindee.fields.date import Date
from datetime import datetime
from mindee.http import make_api_request, make_predict_url
import os


class Passport(Document):
Expand Down Expand Up @@ -127,7 +126,7 @@ def build_from_api_prediction(self, api_prediction, page_n=0):
self.mrz = Field({"value": None, "probability": 0.0}, page_n=page_n)
self.full_name = Field({"value": None, "probability": 0.0}, page_n=page_n)

def __str__(self):
def __str__(self) -> str:
return (
"-----Passport data-----\n"
"Filename: %s \n"
Expand Down
3 changes: 1 addition & 2 deletions mindee/documents/receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from mindee.fields.orientation import Orientation
from mindee.fields.tax import Tax
from mindee.http import make_api_request, make_predict_url
import os


class Receipt(Document):
Expand Down Expand Up @@ -95,7 +94,7 @@ def __init__(
# Reconstruct extra fields
self._reconstruct()

def __str__(self):
def __str__(self) -> str:
return (
"-----Receipt data-----\n"
"Filename: %s\n"
Expand Down
2 changes: 1 addition & 1 deletion mindee/fields/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Field(object):
class Field:
def __init__(
self,
abstract_prediction,
Expand Down
4 changes: 2 additions & 2 deletions mindee/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

MINDEE_API_URL = "https://api.mindee.net/v1"

platform = get_platform()
PLATFORM = get_platform()


def make_predict_url(product: str, version: str, owner: str = "mindee") -> str:
Expand All @@ -30,7 +30,7 @@ def make_api_request(url: str, input_file, token: str, include_words: bool = Fal
files = {"document": (input_file.filename, input_file.file_object.read())}
headers = {
"Authorization": f"Token {token}",
"User-Agent": f"mindee-api-python@v{__version__} python-v{python_version} {platform}",
"User-Agent": f"mindee-api-python@v{__version__} python-v{python_version} {PLATFORM}",
}

params = {}
Expand Down
6 changes: 3 additions & 3 deletions mindee/inputs.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import fitz
import io
import os
from base64 import decodebytes
from mimetypes import guess_type
import fitz


class Inputs(object):
class Inputs:
def __init__(
self, file, input_type="path", filename=None, cut_pdf=True, n_pdf_pages=3
):
Expand Down Expand Up @@ -119,7 +119,7 @@ def merge_pdf_pages(self, pages_number):
width = spage.MediaBoxSize[0]
height = spage.MediaBoxSize[1]
r = fitz.Rect(0, 0, width, height)
page = doc.newPage(-1, width=width, height=height)
page = doc.new_page(-1, width=width, height=height)
try:
page.showPDFpage(r, src, spage.number)
except:
Expand Down
1 change: 1 addition & 0 deletions mindee/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


def get_platform() -> str:
"""Get the current OS platform."""
platforms = {
"linux": "linux",
"win32": "windows",
Expand Down
31 changes: 30 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,34 @@ line-length = 88
target-version = ['py35', 'py36', 'py37']
include = '\.pyi?$'

[tool.mypy]
[[tool.mypy.overrides]]
module = ['fitz',]
ignore_missing_imports = true

[tool.pylint.'MESSAGES CONTROL']
disable=[
'line-too-long',
'bare-except',
'consider-using-set-comprehension',
'missing-class-docstring',
'missing-module-docstring',
'super-with-arguments',
'no-else-return',
'too-many-instance-attributes',
'too-many-locals',
'too-many-arguments',
'duplicate-code',
'unidiomatic-typecheck',
'arguments-differ',
'inconsistent-return-statements',
'invalid-name',
'super-init-not-called',
'no-else-raise',
'raise-missing-from',
'consider-iterating-dictionary',
'unspecified-encoding',
'use-implicit-booleaness-not-len',
'unnecessary-pass',
'consider-using-f-string',
'consider-using-with',
]
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@


requirements = [
"requests==2.25.1",
"pytz==2021.3",
"PyMuPDF==1.18.17",
"requests==2.25.1",
]

test_requirements = [
Expand All @@ -28,8 +28,10 @@

dev_requirements = [
"black==21.12b0",
"setuptools==49.2.0",
"mypy==0.931",
"pip-tools==6.4.0",
"pylint==2.12.2",
"setuptools==49.2.0",
]

setup(
Expand Down