Skip to content

Commit 76c7329

Browse files
ianardeefharper
authored andcommitted
🎨 fixes to import order (isort) and documentation (pydocstyle).
1 parent 489483e commit 76c7329

28 files changed

+206
-114
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repos:
1818
additional_dependencies: [toml]
1919
exclude: .*(test|__init__|version).*\.py
2020
args: [
21-
--ignore=D10
21+
"--ignore=D10,D212,D203,D401"
2222
]
2323

2424
- repo: https://github.com/PyCQA/pylint

mindee/__main__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import argparse
2-
from argparse import Namespace
32
import json
4-
from typing import Dict, Any
3+
from argparse import Namespace
4+
from typing import Any, Dict
55

66
from mindee import Client
77

@@ -97,7 +97,7 @@ def call_endpoint(args: Namespace):
9797

9898

9999
def _parse_args() -> Namespace:
100-
"""Parse command line arguments"""
100+
"""Parse command line arguments."""
101101
parser = argparse.ArgumentParser(description="Mindee API")
102102
parser.add_argument(
103103
"-E",

mindee/client.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
import json
22
from typing import Dict
33

4+
from mindee.document_config import DocumentConfig, DocumentConfigDict
5+
from mindee.documents.custom_document import CustomDocument
6+
from mindee.documents.financial_document import FinancialDocument
7+
from mindee.documents.invoice import Invoice
8+
from mindee.documents.passport import Passport
9+
from mindee.documents.receipt import Receipt
10+
from mindee.http import (
11+
CustomEndpoint,
12+
HTTPException,
13+
InvoiceEndpoint,
14+
PassportEndpoint,
15+
ReceiptEndpoint,
16+
)
417
from mindee.inputs import (
5-
InputDocument,
618
Base64Document,
719
BytesDocument,
820
FileDocument,
21+
InputDocument,
922
PathDocument,
1023
)
1124
from mindee.logger import logger
12-
from mindee.response import format_response, DocumentResponse
13-
from mindee.http import (
14-
HTTPException,
15-
CustomEndpoint,
16-
InvoiceEndpoint,
17-
ReceiptEndpoint,
18-
PassportEndpoint,
19-
)
20-
from mindee.document_config import DocumentConfig, DocumentConfigDict
21-
from mindee.documents.receipt import Receipt
22-
from mindee.documents.financial_document import FinancialDocument
23-
from mindee.documents.invoice import Invoice
24-
from mindee.documents.passport import Passport
25-
from mindee.documents.custom_document import CustomDocument
25+
from mindee.response import DocumentResponse, format_response
2626

2727

2828
class DocumentClient:
@@ -44,6 +44,8 @@ def parse(
4444
self, document_type: str, username: str = None, include_words: bool = False
4545
):
4646
"""
47+
Call prediction API on the document and parse the results.
48+
4749
:param document_type: Document type to parse
4850
:param username:
4951
:param include_words: Bool, extract all words into http_response
@@ -118,6 +120,8 @@ class Client:
118120

119121
def __init__(self, raise_on_error: bool = True):
120122
"""
123+
Mindee API Client.
124+
121125
:param raise_on_error: Raise an Exception on HTTP errors
122126
"""
123127
self._doc_configs: Dict[tuple, DocumentConfig] = {}

mindee/document_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Dict, List
22

3-
from mindee.http import Endpoint
43
from mindee.documents.base import TypeDocument
4+
from mindee.http import Endpoint
55

66

77
class DocumentConfig:

mindee/documents/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Type, Optional
1+
from typing import List, Optional, Type
22

33
# from mindee.inputs import InputDocument
44
from mindee.http import Endpoint
@@ -31,11 +31,11 @@ def __init__(
3131

3232
@staticmethod
3333
def request(endpoints: List[Endpoint], input_file, include_words: bool = False):
34-
"""Make request to the product endpoint"""
34+
"""Make request to the product endpoint."""
3535
raise NotImplementedError()
3636

3737
def build_from_api_prediction(self, api_prediction: dict, page_n):
38-
"""Build the document from an API response JSON"""
38+
"""Build the document from an API response JSON."""
3939
raise NotImplementedError()
4040

4141
def _checklist(self) -> None:
@@ -45,7 +45,7 @@ def _reconstruct(self) -> None:
4545
pass
4646

4747
def all_checks(self) -> bool:
48-
"""Return all checks"""
48+
"""Return all checks."""
4949
return all(self.checklist)
5050

5151

mindee/documents/financial_document.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from typing import List, Optional
22

3-
from mindee.fields import Field
4-
from mindee.fields.orientation import Orientation
5-
from mindee.fields.locale import Locale
6-
from mindee.http import Endpoint
73
from mindee.documents.base import Document
84
from mindee.documents.invoice import Invoice
95
from mindee.documents.receipt import Receipt
6+
from mindee.fields import Field
7+
from mindee.fields.locale import Locale
8+
from mindee.fields.orientation import Orientation
9+
from mindee.http import Endpoint
1010

1111

1212
class FinancialDocument(Document):
@@ -22,6 +22,8 @@ def __init__(
2222
document_type="financial_doc",
2323
):
2424
"""
25+
Union of `Invoice` and `Receipt`.
26+
2527
:param api_prediction: Raw prediction from HTTP response
2628
:param input_file: Input object
2729
:param page_n: Page number for multi pages pdf input
@@ -55,6 +57,8 @@ def __init__(
5557

5658
def build_from_api_prediction(self, api_prediction, page_n=0):
5759
"""
60+
Build the document from an API response JSON.
61+
5862
:param api_prediction: Raw prediction from HTTP response
5963
:param page_n: Page number for multi pages pdf input
6064
:return: (void) set the object attributes with api prediction values
@@ -133,7 +137,8 @@ def __str__(self) -> str:
133137
@staticmethod
134138
def request(endpoints: List[Endpoint], input_file, include_words=False):
135139
"""
136-
Make request to expense_receipts endpoint
140+
Make request to prediction endpoint.
141+
137142
:param input_file: Input object
138143
:param endpoints: Endpoints config
139144
:param include_words: Include Mindee vision words in http_response
@@ -146,15 +151,14 @@ def request(endpoints: List[Endpoint], input_file, include_words=False):
146151
return endpoints[index].predict_request(input_file, include_words)
147152

148153
def _checklist(self) -> None:
149-
"""
150-
:return: Set of validation rules
151-
"""
154+
"""Set the validation rules."""
152155
self.checklist = {"taxes_match_total_incl": self.__taxes_match_total_incl()}
153156

154157
# Checks
155158
def __taxes_match_total_incl(self) -> bool:
156159
"""
157-
Check invoice rule of matching between taxes and total_incl
160+
Check invoice rule of matching between taxes and total_incl.
161+
158162
:return: True if rule matches, False otherwise
159163
"""
160164
# Check taxes and total_incl exist

mindee/documents/invoice.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
from mindee.documents.base import Document
44
from mindee.fields import Field
5-
from mindee.fields.date import Date
65
from mindee.fields.amount import Amount
6+
from mindee.fields.date import Date
77
from mindee.fields.locale import Locale
88
from mindee.fields.orientation import Orientation
99
from mindee.fields.payment_details import PaymentDetails
@@ -38,6 +38,8 @@ def __init__(
3838
document_type="invoice",
3939
):
4040
"""
41+
Invoice document.
42+
4143
:param api_prediction: Raw prediction from HTTP response
4244
:param input_file: Input object
4345
:param page_n: Page number for multi pages pdf input
@@ -51,6 +53,8 @@ def __init__(
5153

5254
def build_from_api_prediction(self, api_prediction: dict, page_n=0):
5355
"""
56+
Build the object from the prediction API JSON.
57+
5458
:param api_prediction: Raw prediction from HTTP response
5559
:param page_n: Page number for multi pages pdf input
5660
:return: (void) set the object attributes with api prediction values
@@ -126,26 +130,23 @@ def __str__(self) -> str:
126130
@staticmethod
127131
def request(endpoints: List[Endpoint], input_file, include_words=False):
128132
"""
129-
Make request to expense_receipts endpoint
133+
Make request to prediction endpoint.
134+
130135
:param input_file: Input object
131136
:param endpoints: Endpoints config
132137
:param include_words: Include Mindee vision words in http_response
133138
"""
134139
return endpoints[0].predict_request(input_file, include_words)
135140

136141
def _reconstruct(self) -> None:
137-
"""
138-
Call fields reconstruction methods
139-
"""
142+
"""Call fields reconstruction methods."""
140143
self.__reconstruct_total_tax_from_tax_lines()
141144
self.__reconstruct_total_excl_from_tcc_and_taxes()
142145
self.__reconstruct_total_incl_from_taxes_plus_excl()
143146
self.__reconstruct_total_tax_from_incl_and_excl()
144147

145148
def _checklist(self) -> None:
146-
"""
147-
Call check methods
148-
"""
149+
"""Call check methods."""
149150
self.checklist = {
150151
"taxes_match_total_incl": self.__taxes_match_total_incl(),
151152
"taxes_match_total_excl": self.__taxes_match_total_excl(),
@@ -155,7 +156,8 @@ def _checklist(self) -> None:
155156
# Checks
156157
def __taxes_match_total_incl(self) -> bool:
157158
"""
158-
Check invoice rule of matching between taxes and total_incl
159+
Check invoice matching rule between taxes and total_incl.
160+
159161
:return: True if rule matches, False otherwise
160162
"""
161163
# Ensure taxes and total_incl exist
@@ -191,7 +193,8 @@ def __taxes_match_total_incl(self) -> bool:
191193

192194
def __taxes_match_total_excl(self) -> bool:
193195
"""
194-
Check invoice rule of matching between taxes and total_excl
196+
Check invoice matching rule between taxes and total_excl.
197+
195198
:return: True if rule matches, False otherwise
196199
"""
197200
# Check taxes and total excl exist
@@ -228,7 +231,9 @@ def __taxes_match_total_excl(self) -> bool:
228231

229232
def __taxes_plus_total_excl_match_total_incl(self) -> bool:
230233
"""
231-
Check invoice rule of matching : sum(taxes) + total_excluding_taxes = total_including_taxes
234+
Check invoice matching rule.
235+
236+
Rule is: sum(taxes) + total_excluding_taxes = total_including_taxes
232237
:return: True if rule matches, False otherwise
233238
"""
234239
# Check total_tax, total excl and total incl exist
@@ -267,7 +272,8 @@ def __taxes_plus_total_excl_match_total_incl(self) -> bool:
267272
# Reconstruct
268273
def __reconstruct_total_incl_from_taxes_plus_excl(self) -> None:
269274
"""
270-
Set self.total_incl with Amount object
275+
Set self.total_incl with Amount object.
276+
271277
The total_incl Amount value is the sum of total_excl and sum of taxes
272278
The total_incl Amount confidence is the product of self.taxes probabilities
273279
multiplied by total_excl confidence
@@ -292,7 +298,8 @@ def __reconstruct_total_incl_from_taxes_plus_excl(self) -> None:
292298

293299
def __reconstruct_total_excl_from_tcc_and_taxes(self) -> None:
294300
"""
295-
Set self.total_excl with Amount object
301+
Set self.total_excl with Amount object.
302+
296303
The total_excl Amount value is the difference between total_incl and sum of taxes
297304
The total_excl Amount confidence is the product of self.taxes probabilities
298305
multiplied by total_incl confidence
@@ -317,7 +324,8 @@ def __reconstruct_total_excl_from_tcc_and_taxes(self) -> None:
317324

318325
def __reconstruct_total_tax_from_tax_lines(self) -> None:
319326
"""
320-
Set self.total_tax with Amount object
327+
Set self.total_tax with Amount object.
328+
321329
The total_tax Amount value is the sum of all self.taxes value
322330
The total_tax Amount confidence is the product of self.taxes probabilities
323331
"""
@@ -335,7 +343,8 @@ def __reconstruct_total_tax_from_tax_lines(self) -> None:
335343

336344
def __reconstruct_total_tax_from_incl_and_excl(self) -> None:
337345
"""
338-
Set self.total_tax with Amount object
346+
Set self.total_tax with Amount object.
347+
339348
Check if the total tax was already set
340349
If not, set thta total tax amount to the diff of incl and excl
341350
"""

0 commit comments

Comments
 (0)