documente_shared 0.1.46__py3-none-any.whl → 0.1.50__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of documente_shared might be problematic. Click here for more details.

@@ -0,0 +1,7 @@
1
+ from datetime import datetime, timezone
2
+
3
+
4
+ def ensure_timezone(dt: datetime, tz=timezone.utc) -> datetime:
5
+ if dt.tzinfo is None:
6
+ return dt.replace(tzinfo=tz)
7
+ return dt
@@ -4,11 +4,11 @@ from decimal import Decimal
4
4
  from typing import Optional, List
5
5
 
6
6
  from documente_shared.application.time_utils import get_datetime_from_data
7
- from documente_shared.domain.entities.document_process_metadata import DocumentProcessMetadata
7
+ from documente_shared.domain.entities.document_metadata import DocumentProcessingMetadata
8
8
  from documente_shared.domain.enums import (
9
- DocumentProcessStatus,
10
- DocumentProcessSubCategory,
11
- DocumentProcessCategory,
9
+ DocumentProcessingStatus,
10
+ DocumentProcessingSubCategory,
11
+ DocumentProcessingCategory,
12
12
  )
13
13
 
14
14
  def remove_slash_from_path(path: str) -> str:
@@ -17,13 +17,13 @@ def remove_slash_from_path(path: str) -> str:
17
17
  return path
18
18
 
19
19
  @dataclass
20
- class DocumentProcess(object):
20
+ class DocumentProcessing(object):
21
21
  digest: str
22
- status: DocumentProcessStatus
22
+ status: DocumentProcessingStatus
23
23
  file_path: Optional[str] = None
24
24
  file_bytes: Optional[bytes] = None
25
- category: Optional[DocumentProcessCategory] = None
26
- sub_category: Optional[DocumentProcessSubCategory] = None
25
+ category: Optional[DocumentProcessingCategory] = None
26
+ sub_category: Optional[DocumentProcessingSubCategory] = None
27
27
  processed_csv_path: Optional[str] = None
28
28
  processed_csv_bytes: Optional[bytes] = None
29
29
  processed_xlsx_path: Optional[str] = None
@@ -39,30 +39,30 @@ class DocumentProcess(object):
39
39
  failed_at: Optional[datetime] = None
40
40
  failed_reason: Optional[str] = None
41
41
  completed_at: Optional[datetime] = None
42
- metadata_items: Optional[List[DocumentProcessMetadata]] = None
42
+ metadata_items: Optional[List[DocumentProcessingMetadata]] = None
43
43
 
44
44
  def __post_init__(self):
45
45
  self.metadata_items = self.metadata_items or []
46
46
 
47
47
  @property
48
48
  def is_pending(self) -> bool:
49
- return self.status == DocumentProcessStatus.PENDING
49
+ return self.status == DocumentProcessingStatus.PENDING
50
50
 
51
51
  @property
52
52
  def is_enqueued(self) -> bool:
53
- return self.status == DocumentProcessStatus.ENQUEUED
53
+ return self.status == DocumentProcessingStatus.ENQUEUED
54
54
 
55
55
  @property
56
56
  def is_processing(self) -> bool:
57
- return self.status == DocumentProcessStatus.PROCESSING
57
+ return self.status == DocumentProcessingStatus.PROCESSING
58
58
 
59
59
  @property
60
60
  def is_completed(self) -> bool:
61
- return self.status == DocumentProcessStatus.COMPLETED
61
+ return self.status == DocumentProcessingStatus.COMPLETED
62
62
 
63
63
  @property
64
64
  def is_failed(self) -> bool:
65
- return self.status == DocumentProcessStatus.FAILED
65
+ return self.status == DocumentProcessingStatus.FAILED
66
66
 
67
67
  @property
68
68
  def is_valid(self) -> bool:
@@ -75,29 +75,29 @@ class DocumentProcess(object):
75
75
  @property
76
76
  def is_finished(self) -> bool:
77
77
  return self.status in [
78
- DocumentProcessStatus.COMPLETED,
79
- DocumentProcessStatus.FAILED,
78
+ DocumentProcessingStatus.COMPLETED,
79
+ DocumentProcessingStatus.FAILED,
80
80
  ]
81
81
 
82
82
  def enqueue(self):
83
- self.status = DocumentProcessStatus.ENQUEUED
83
+ self.status = DocumentProcessingStatus.ENQUEUED
84
84
  self.enqueued_at = datetime.now()
85
85
 
86
86
  def processing(self):
87
- self.status = DocumentProcessStatus.PROCESSING
87
+ self.status = DocumentProcessingStatus.PROCESSING
88
88
  self.started_at = datetime.now()
89
89
 
90
90
  def failed(self, error_message: Optional[str] = None):
91
91
  self.failed_reason = error_message
92
- self.status = DocumentProcessStatus.FAILED
92
+ self.status = DocumentProcessingStatus.FAILED
93
93
  self.failed_at = datetime.now()
94
94
 
95
95
  def completed(self):
96
- self.status = DocumentProcessStatus.COMPLETED
96
+ self.status = DocumentProcessingStatus.COMPLETED
97
97
  self.completed_at = datetime.now()
98
98
 
99
99
  def deleted(self):
100
- self.status = DocumentProcessStatus.DELETED
100
+ self.status = DocumentProcessingStatus.DELETED
101
101
 
102
102
  @property
103
103
  def file_key(self) -> str:
@@ -128,7 +128,7 @@ class DocumentProcess(object):
128
128
  filename_with_extension = self.extended_filename
129
129
  return filename_with_extension.split('.')[0]
130
130
 
131
- def __eq__(self, other: 'DocumentProcess') -> bool:
131
+ def __eq__(self, other: 'DocumentProcessing') -> bool:
132
132
  if not other:
133
133
  return False
134
134
 
@@ -185,7 +185,7 @@ class DocumentProcess(object):
185
185
 
186
186
  def overload(
187
187
  self,
188
- new_instance: 'DocumentProcess',
188
+ new_instance: 'DocumentProcessing',
189
189
  properties: List[str] = None,
190
190
  ):
191
191
  instance_properties = properties or [
@@ -202,6 +202,7 @@ class DocumentProcess(object):
202
202
  'processed_json_path',
203
203
  'processed_json_bytes',
204
204
  'processed_metadata_path',
205
+ 'processed_metadata_bytes',
205
206
  'processing_time',
206
207
  'issued_at',
207
208
  'uploaded_at',
@@ -219,17 +220,17 @@ class DocumentProcess(object):
219
220
  return self
220
221
 
221
222
  @classmethod
222
- def from_dict(cls, data: dict) -> 'DocumentProcess':
223
+ def from_dict(cls, data: dict) -> 'DocumentProcessing':
223
224
  return cls(
224
225
  digest=data.get('digest'),
225
- status=DocumentProcessStatus.from_value(data.get('status')),
226
+ status=DocumentProcessingStatus.from_value(data.get('status')),
226
227
  file_path=data.get('file_path'),
227
228
  category=(
228
- DocumentProcessCategory.from_value(data.get('category'))
229
+ DocumentProcessingCategory.from_value(data.get('category'))
229
230
  if data.get('category') else None
230
231
  ),
231
232
  sub_category=(
232
- DocumentProcessSubCategory.from_value(data.get('sub_category'))
233
+ DocumentProcessingSubCategory.from_value(data.get('sub_category'))
233
234
  if data.get('sub_category') else None
234
235
  ),
235
236
  processed_csv_path=data.get('processed_csv_path'),
@@ -248,7 +249,7 @@ class DocumentProcess(object):
248
249
  failed_reason=data.get('failed_reason'),
249
250
  completed_at=get_datetime_from_data(input_datetime=data.get('completed_at')),
250
251
  metadata_items=[
251
- DocumentProcessMetadata.from_dict(metadata)
252
+ DocumentProcessingMetadata.from_dict(metadata)
252
253
  for metadata in data.get('metadata_items', [])
253
254
  ],
254
255
  )
@@ -4,7 +4,7 @@ from typing import Optional
4
4
 
5
5
 
6
6
  @dataclass
7
- class DocumentProcessMetadata(object):
7
+ class DocumentProcessingMetadata(object):
8
8
  publication_date: Optional[datetime] = None
9
9
  num_circular: Optional[str] = None
10
10
  asfi_identifier: Optional[str] = None
@@ -1,7 +1,7 @@
1
1
  from documente_shared.domain.base_enum import BaseEnum
2
2
 
3
3
 
4
- class DocumentProcessStatus(BaseEnum):
4
+ class DocumentProcessingStatus(BaseEnum):
5
5
  PENDING = 'PENDING'
6
6
  ENQUEUED = 'ENQUEUED'
7
7
  PROCESSING = 'PROCESSING'
@@ -11,20 +11,20 @@ class DocumentProcessStatus(BaseEnum):
11
11
  CANCELLED = 'CANCELLED'
12
12
 
13
13
 
14
- class DocumentProcessCategory(BaseEnum):
14
+ class DocumentProcessingCategory(BaseEnum):
15
15
  CIRCULAR = 'CIRCULAR'
16
16
  DESGRAVAMEN = 'DESGRAVAMEN'
17
17
 
18
18
  @property
19
19
  def is_circular(self):
20
- return self == DocumentProcessCategory.CIRCULAR
20
+ return self == DocumentProcessingCategory.CIRCULAR
21
21
 
22
22
  @property
23
23
  def is_desgravamen(self):
24
- return self == DocumentProcessCategory.DESGRAVAMEN
24
+ return self == DocumentProcessingCategory.DESGRAVAMEN
25
25
 
26
26
 
27
- class DocumentProcessSubCategory(BaseEnum):
27
+ class DocumentProcessingSubCategory(BaseEnum):
28
28
  # Circulares
29
29
  CC_COMBINADA = 'CC_COMBINADA'
30
30
  CC_NORMATIVA = 'CC_NORMATIVA'
@@ -32,5 +32,5 @@ class DocumentProcessSubCategory(BaseEnum):
32
32
  CC_RETENCION_SUSPENSION_REMISION = 'CC_RETENCION_SUSPENSION_REMISION'
33
33
 
34
34
  # Desgravamenes
35
- DS_CREDISEGUROS = 'DS_CREDISEGUROS'
35
+ DS_CREDISEGURO = 'DS_CREDISEGURO'
36
36
 
@@ -1,25 +1,25 @@
1
1
  from abc import ABC, abstractmethod
2
2
  from typing import Optional, List
3
3
 
4
- from documente_shared.domain.entities.document_process import DocumentProcess
5
- from documente_shared.domain.enums import DocumentProcessStatus
4
+ from documente_shared.domain.entities.document import DocumentProcessing
5
+ from documente_shared.domain.enums import DocumentProcessingStatus
6
6
 
7
7
 
8
- class DocumentProcessRepository(ABC):
8
+ class DocumentProcessingRepository(ABC):
9
9
 
10
10
  @abstractmethod
11
- def find(self, digest: str) ->Optional[DocumentProcess]:
11
+ def find(self, digest: str) ->Optional[DocumentProcessing]:
12
12
  raise NotImplementedError
13
13
 
14
14
  @abstractmethod
15
- def persist(self, instance: DocumentProcess) -> DocumentProcess:
15
+ def persist(self, instance: DocumentProcessing) -> DocumentProcessing:
16
16
  raise NotImplementedError
17
17
 
18
18
  @abstractmethod
19
- def remove(self, instance: DocumentProcess):
19
+ def remove(self, instance: DocumentProcessing):
20
20
  raise NotImplementedError
21
21
 
22
22
 
23
23
  @abstractmethod
24
- def filter(self, statuses: List[DocumentProcessStatus]) -> List[DocumentProcess]:
24
+ def filter(self, statuses: List[DocumentProcessingStatus]) -> List[DocumentProcessing]:
25
25
  raise NotImplementedError
@@ -2,31 +2,31 @@ from typing import Optional, List
2
2
 
3
3
  from boto3.dynamodb.conditions import Key
4
4
 
5
- from documente_shared.domain.entities.document_process import DocumentProcess
6
- from documente_shared.domain.enums import DocumentProcessStatus
7
- from documente_shared.domain.repositories import DocumentProcessRepository
5
+ from documente_shared.domain.entities.document import DocumentProcessing
6
+ from documente_shared.domain.enums import DocumentProcessingStatus, DocumentProcessingCategory
7
+ from documente_shared.domain.repositories import DocumentProcessingRepository
8
8
  from documente_shared.infrastructure.dynamo_table import DynamoDBTable
9
9
 
10
10
 
11
11
 
12
- class DynamoDocumentProcessRepository(
12
+ class DynamoDocumentProcessingRepository(
13
13
  DynamoDBTable,
14
- DocumentProcessRepository,
14
+ DocumentProcessingRepository,
15
15
  ):
16
- def find(self, digest: str) -> Optional[DocumentProcess]:
16
+ def find(self, digest: str) -> Optional[DocumentProcessing]:
17
17
  item = self.get(key={'digest': digest})
18
18
  if item:
19
- return DocumentProcess.from_dict(item)
19
+ return DocumentProcessing.from_dict(item)
20
20
  return None
21
21
 
22
- def persist(self, instance: DocumentProcess) -> DocumentProcess:
22
+ def persist(self, instance: DocumentProcessing) -> DocumentProcessing:
23
23
  self.put(instance.to_simple_dict)
24
24
  return instance
25
25
 
26
- def remove(self, instance: DocumentProcess):
26
+ def remove(self, instance: DocumentProcessing):
27
27
  self.delete(key={'digest': instance.digest})
28
28
 
29
- def filter(self, statuses: List[DocumentProcessStatus]) -> List[DocumentProcess]:
29
+ def filter(self, statuses: List[DocumentProcessingStatus]) -> List[DocumentProcessing]:
30
30
  items = []
31
31
 
32
32
  for status in statuses:
@@ -38,6 +38,6 @@ class DynamoDocumentProcessRepository(
38
38
  items.extend(status_items)
39
39
 
40
40
  return [
41
- DocumentProcess.from_dict(item)
41
+ DocumentProcessing.from_dict(item)
42
42
  for item in items
43
43
  ]
@@ -3,7 +3,7 @@ import boto3
3
3
  from dataclasses import dataclass
4
4
  from typing import Optional
5
5
 
6
- from documente_shared.domain.entities.document_process import remove_slash_from_path
6
+ from documente_shared.domain.entities.document import remove_slash_from_path
7
7
 
8
8
 
9
9
  def remove_none_values(data: dict) -> dict: # noqa: WPS110
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: documente_shared
3
- Version: 0.1.46
3
+ Version: 0.1.50
4
4
  Summary: Shared utilities for Documente AI projects
5
5
  License: MIT
6
6
  Author: Tech
@@ -3,18 +3,19 @@ documente_shared/application/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NM
3
3
  documente_shared/application/digest.py,sha256=Um6E8WfFri2_lly4RFWydJyvSfPZGFcOX-opEOzDCWc,172
4
4
  documente_shared/application/exceptions.py,sha256=lQM8m7wmI9OTLGva0gd7s7YT7ldaTk_Ln4t32PpzNf8,654
5
5
  documente_shared/application/time_utils.py,sha256=XDH27cKgoTFO8ad1JgrxKaeT7sZ1fduuJqLkvHUjy-Q,309
6
+ documente_shared/application/timezone.py,sha256=NHpzTzOPD_fWQiJ4BrRqt_TIDs5XyB5ZMR7x8vUk8gQ,183
6
7
  documente_shared/domain/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
8
  documente_shared/domain/base_enum.py,sha256=DojAfn-zQdtjtImeHUpBzE6TBTm07XrbMOdW3h8RVd8,1449
8
9
  documente_shared/domain/entities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- documente_shared/domain/entities/document_process.py,sha256=6UMKMAr2GLfsJiW9MXC2KtwC4lhbFs9L4DKoZJOHznQ,9089
10
- documente_shared/domain/entities/document_process_metadata.py,sha256=rBHkDkoKwrxReKtXIScU1vrCO_6bg2LwWhrtXMcQ8TA,2351
11
- documente_shared/domain/enums.py,sha256=pow_LWNQjdyADiVtpPRxBRtcgC2ZabLEHwSXD9u0PdE,886
12
- documente_shared/domain/repositories.py,sha256=o9_ty3NPxCjb4hHIZbk71ECLqTjoKQI5MKWQje1KEyk,738
10
+ documente_shared/domain/entities/document.py,sha256=HSRz_EpyLBg8icUjGjx2JQojAyiR5UBqzvaKobESz4M,9205
11
+ documente_shared/domain/entities/document_metadata.py,sha256=Oa-c0xJODXaGtFkNxt9k86rSWGxY2LHVDOgu9tQxCGY,2354
12
+ documente_shared/domain/enums.py,sha256=l-u_Zka8TW5mpMabymtEkBCEdavermKZwPLY_hALJww,899
13
+ documente_shared/domain/repositories.py,sha256=g3qLUy2kT8esmvU4VxxSVnDaXeySKKQ7mUvIvxOwh9A,757
13
14
  documente_shared/infrastructure/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
- documente_shared/infrastructure/dynamo_repositories.py,sha256=w_AW3IACVxRU7A3mNma2Elpbx7naRV4wY5mChW1WmZQ,1394
15
+ documente_shared/infrastructure/dynamo_repositories.py,sha256=SEad_HLppp2h_BKDSzb9oo1VlAVRZWelOPvJPlDwbzQ,1453
15
16
  documente_shared/infrastructure/dynamo_table.py,sha256=dK05KgFvIYCmOdMpq9-OV_OBrP6cCngiUikCJrxlwt4,2112
16
- documente_shared/infrastructure/s3_bucket.py,sha256=Nf4bHSC3TJeaKvOQSVtV1hG8dWqEZZnA-JWU0PNTw24,1940
17
+ documente_shared/infrastructure/s3_bucket.py,sha256=vT_yN42RFQXubtUn8ln-j13Os_-25UGClVtXg5Bkv6I,1932
17
18
  documente_shared/infrastructure/sqs_queue.py,sha256=PSiTAnjXvQ-W-9mzLpH2UjbQJTvYkMiaxNaMecF-cR4,1505
18
- documente_shared-0.1.46.dist-info/METADATA,sha256=uK4wazriy3NVx-OgCmvXT8TKRnZwWe3xIGt62X5Ztuo,682
19
- documente_shared-0.1.46.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
20
- documente_shared-0.1.46.dist-info/RECORD,,
19
+ documente_shared-0.1.50.dist-info/METADATA,sha256=J2U35CtrlhdWteSL3VUeKZ-b_Phgc5n4hn6W2DJsERI,682
20
+ documente_shared-0.1.50.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
21
+ documente_shared-0.1.50.dist-info/RECORD,,