Skip to content

Commit 3c9ea2e

Browse files
Alexandre Brito de Souza RamosAlexandre Brito de Souza Ramos
authored andcommitted
feat: added serializers for objects and applied formatting rules
1 parent ee35d9b commit 3c9ea2e

36 files changed

+2209
-1372
lines changed

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.9.0
1+
3.9

.vscode/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"python.analysis.typeCheckingMode": "basic",
3-
"cloudcode.duetAI.inlineSuggestions.enableAuto": false,
43
"python.testing.pytestArgs": [
54
"tests"
65
],
76
"python.testing.unittestEnabled": false,
87
"python.testing.pytestEnabled": true,
9-
"python.analysis.autoImportCompletions": true
8+
"python.analysis.autoImportCompletions": true,
9+
"editor.formatOnSave": true,
10+
"editor.defaultFormatter": "charliermarsh.ruff"
1011
}

enma/__init__.py

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@
22
from enma.application.core.utils.logger import LogMode, logger
33
from enma.application.use_cases.download_chapter import Threaded
44
from enma.infra.entrypoints.lib import Enma, Sources
5-
from enma.infra.adapters.repositories.nhentai import CloudFlareConfig, NHentai, Sort as NHentaiSort, NhentaiSourceConfig, NHentaiConfig
6-
from enma.infra.adapters.repositories.mangadex import Mangadex, Sort as MangadexSort
5+
from enma.infra.adapters.repositories.nhentai import (
6+
CloudFlareConfig,
7+
NHentai,
8+
Sort as NHentaiSort,
9+
NhentaiSourceConfig,
10+
NHentaiConfig,
11+
)
12+
from enma.infra.adapters.repositories.mangadex import (
13+
Mangadex,
14+
Sort as MangadexSort,
15+
)
716
from enma.infra.adapters.repositories.manganato import Manganato
817
from enma.infra.adapters.downloaders.default import DefaultDownloader
918
from enma.infra.adapters.downloaders.manganato import ManganatoDownloader
10-
from enma.application.core.interfaces.downloader_adapter import IDownloaderAdapter
19+
from enma.application.core.interfaces.downloader_adapter import (
20+
IDownloaderAdapter,
21+
)
1122
from enma.application.core.interfaces.saver_adapter import ISaverAdapter
1223
from enma.infra.adapters.storage.google_drive import GoogleDriveStorage
1324
from enma.infra.adapters.storage.local import LocalStorage
@@ -16,7 +27,7 @@
1627
from enma.domain.entities.pagination import Pagination
1728
from enma.domain.entities.author_page import AuthorPage
1829
from enma.application.core.interfaces.manga_repository import IMangaRepository
19-
from enma._version import __version__
30+
from enma._version import version, version_tuple
2031

2132
package_name = "enma"
2233
python_major = "3"
@@ -27,4 +38,35 @@
2738
try:
2839
assert sys.version_info >= (int(python_major), int(python_minor))
2940
except AssertionError:
30-
raise RuntimeError(f"\033[31m{package_name!r} requires Python {python_major}.{python_minor}+ (You have Python {sys.version})\033[0m")
41+
raise RuntimeError(
42+
f"\033[31m{package_name!r} requires Python {python_major}.{python_minor}+ (You have Python {sys.version})\033[0m"
43+
)
44+
45+
__all__ = [
46+
"Enma",
47+
"NHentai",
48+
"CloudFlareConfig",
49+
"NHentaiSort",
50+
"NHentaiConfig",
51+
"NhentaiSourceConfig",
52+
"Manga",
53+
"Chapter",
54+
"SymbolicLink",
55+
"SearchResult",
56+
"Pagination",
57+
"AuthorPage",
58+
"ManganatoDownloader",
59+
"DefaultDownloader",
60+
"GoogleDriveStorage",
61+
"LocalStorage",
62+
"IDownloaderAdapter",
63+
"ISaverAdapter",
64+
"IMangaRepository",
65+
"Threaded",
66+
"Sources",
67+
"MangadexSort",
68+
"version",
69+
"version_tuple",
70+
"Mangadex",
71+
"Manganato",
72+
]

enma/_version.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
# file generated by setuptools_scm
1+
# file generated by setuptools-scm
22
# don't change, don't track in version control
3+
4+
__all__ = ["__version__", "__version_tuple__", "version", "version_tuple"]
5+
36
TYPE_CHECKING = False
47
if TYPE_CHECKING:
5-
from typing import Tuple, Union
8+
from typing import Tuple
9+
from typing import Union
10+
611
VERSION_TUPLE = Tuple[Union[int, str], ...]
712
else:
813
VERSION_TUPLE = object
@@ -12,5 +17,5 @@
1217
__version_tuple__: VERSION_TUPLE
1318
version_tuple: VERSION_TUPLE
1419

15-
__version__ = version = '2.4.4'
16-
__version_tuple__ = version_tuple = (2, 4, 4)
20+
__version__ = version = '2.4.5.dev15'
21+
__version_tuple__ = version_tuple = (2, 4, 5, 'dev15')

enma/application/core/handlers/error.py

Lines changed: 69 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,101 +3,146 @@ def __init__(self, message: str) -> None:
33
super().__init__(message)
44

55
self.message: str = message
6-
self.code: str = 'SOURCE_NOT_AVAILABLE'
7-
self.desc: str = 'This error occurs when the client chooses nonexistent source.'
6+
self.code: str = "SOURCE_NOT_AVAILABLE"
7+
self.desc: str = (
8+
"This error occurs when the client chooses nonexistent source."
9+
)
810
self.critical: bool = False
911

12+
1013
class Unknown(Exception):
1114
def __init__(self, message: str) -> None:
1215
super().__init__(message)
1316

14-
self.code: str = 'UNKNOWN'
15-
self.desc: str = 'This error occours when was not possible to determine the error root cause.'
17+
self.code: str = "UNKNOWN"
18+
self.desc: str = (
19+
"This error occours when was not possible to "
20+
"determine the error root cause."
21+
)
1622
self.critical: bool = True
1723

24+
1825
class NotFound(Exception):
1926
def __init__(self, message: str) -> None:
2027
super().__init__(message)
2128

22-
self.code: str = 'NOT_FOUND'
23-
self.desc: str = 'This error occours when was not possible to find the requested resource.'
29+
self.code: str = "NOT_FOUND"
30+
self.desc: str = (
31+
"This error occours when was not possible to "
32+
"find the requested resource."
33+
)
2434
self.critical: bool = True
2535

36+
2637
class Forbidden(Exception):
2738
def __init__(self, message: str) -> None:
2839
super().__init__(message)
2940

30-
self.code: str = 'FORBIDDEN'
31-
self.desc: str = 'This error occours when the client can\'t perform a request to the source due lack of credentials.'
41+
self.code: str = "FORBIDDEN"
42+
self.desc: str = (
43+
"This error occours when the client can't perform a request to "
44+
"the source due lack of credentials."
45+
)
3246
self.critical: bool = True
3347

48+
3449
class InvalidRequest(Exception):
3550
def __init__(self, message: str) -> None:
3651
super().__init__(message)
3752

38-
self.code: str = 'INVALID_REQUEST'
39-
self.desc: str = 'This error occours when the client tries to perform an request with wrong data input.'
53+
self.code: str = "INVALID_REQUEST"
54+
self.desc: str = (
55+
"This error occours when the client tries to "
56+
"perform an request with wrong data input."
57+
)
4058
self.critical: bool = True
4159

60+
4261
class InvalidResource(Exception):
4362
def __init__(self, message: str) -> None:
4463
super().__init__(message)
4564

4665
self.message: str = message
47-
self.code: str = 'INVALID_RESOURCE'
48-
self.desc: str = 'This error occurs when the client tries to perform an action with an invalid resource.'
66+
self.code: str = "INVALID_RESOURCE"
67+
self.desc: str = (
68+
"This error occurs when the client tries to "
69+
"perform an action with an invalid resource."
70+
)
4971
self.critical: bool = True
5072

73+
5174
class NhentaiSourceWithoutConfig(Exception):
5275
def __init__(self, message: str) -> None:
5376
super().__init__(message)
5477

5578
self.message: str = message
56-
self.code: str = 'NHENTAI_SOURCE_WITHOUT_CONFIG'
57-
self.desc: str = 'This error occurs when the client tries to use Nhentai source with no cloudflare cookie.'
79+
self.code: str = "NHENTAI_SOURCE_WITHOUT_CONFIG"
80+
self.desc: str = (
81+
"This error occurs when the client tries to "
82+
"use Nhentai source with no cloudflare cookie."
83+
)
5884
self.critical: bool = True
5985

86+
6087
class InvalidConfig(Exception):
6188
def __init__(self, message: str) -> None:
6289
super().__init__(message)
6390

6491
self.message: str = message
65-
self.code: str = 'INVALID_CONFIG'
66-
self.desc: str = 'This error occurs when client tries to set wrong config object.'
92+
self.code: str = "INVALID_CONFIG"
93+
self.desc: str = (
94+
"This error occurs when client tries to set wrong config object."
95+
)
6796
self.critical: bool = True
6897

98+
6999
class InstanceError(Exception):
70100
def __init__(self, message: str) -> None:
71101
super().__init__(message)
72102

73103
self.message: str = message
74-
self.code: str = 'INSTANCE_ERROR'
75-
self.desc: str = 'This error occurs when the client tries to create an instance with wrong type.'
104+
self.code: str = "INSTANCE_ERROR"
105+
self.desc: str = (
106+
"This error occurs when the client tries to "
107+
"create an instance with wrong type."
108+
)
76109
self.critical: bool = True
77110

111+
78112
class SourceWasNotDefined(Exception):
79113
def __init__(self, message: str) -> None:
80114
super().__init__(message)
81115

82116
self.message: str = message
83-
self.code: str = 'SOURCE_WAS_NOT_DEFINED'
84-
self.desc: str = 'This error occurs when the client tries to perform Enma operations before of setting a source.'
117+
self.code: str = "SOURCE_WAS_NOT_DEFINED"
118+
self.desc: str = (
119+
"This error occurs when the client tries to "
120+
"perform Enma operations before of setting a source."
121+
)
85122
self.critical: bool = True
86123

124+
87125
class ExceedRetryCount(Exception):
88126
def __init__(self, message: str) -> None:
89127
super().__init__(message)
90128

91129
self.message: str = message
92-
self.code: str = 'EXCEED_RETRY_COUNT'
93-
self.desc: str = 'This error occurs when enma tries perform some action but something went wrong.'
130+
self.code: str = "EXCEED_RETRY_COUNT"
131+
self.desc: str = (
132+
"This error occurs when enma tries to "
133+
"perform some action but something went wrong."
134+
)
94135
self.critical: bool = True
95136

137+
96138
class ExceedRateLimit(Exception):
97139
def __init__(self, message: str) -> None:
98140
super().__init__(message)
99141

100142
self.message: str = message
101-
self.code: str = 'EXCEED_RATE_EXCEED'
102-
self.desc: str = 'This error occurs when enma perform more requests than a server can handle. Cool down your requests to this source!'
143+
self.code: str = "EXCEED_RATE_EXCEED"
144+
self.desc: str = (
145+
"This error occurs when enma perform more requests than "
146+
"a server can handle. Cool down your requests to this source!"
147+
)
103148
self.critical: bool = False

enma/application/core/interfaces/downloader_adapter.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@
44

55

66
class IDownloaderAdapter(ABC):
7-
87
@abstractmethod
9-
def download(self, page: Image) -> BytesIO:
10-
...
8+
def download(self, page: Image) -> BytesIO: ...
Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,34 @@
11
from abc import ABC, abstractmethod
2-
from typing import Any, Union
2+
from typing import Union
33
from enma.domain.entities.author_page import AuthorPage
44

55
from enma.domain.entities.manga import Chapter, Manga, SymbolicLink
66
from enma.domain.entities.pagination import Pagination
77
from enma.domain.entities.search_result import SearchResult
88

9-
class IMangaRepository(ABC):
109

10+
class IMangaRepository(ABC):
1111
@abstractmethod
12-
def set_config(self,
13-
config: Any) -> None:
14-
...
12+
def set_config(self, config: object) -> None: ...
1513

1614
@abstractmethod
17-
def get(self,
18-
identifier: str,
19-
with_symbolic_links: bool) -> Union[Manga, None]:
20-
...
21-
15+
def get(
16+
self, identifier: str, with_symbolic_links: bool
17+
) -> Union[Manga, None]: ...
18+
2219
@abstractmethod
23-
def search(self,
24-
query: str,
25-
page: int,
26-
**kwargs) -> SearchResult:
27-
...
20+
def search(
21+
self, query: str, page: int, **kwargs: object
22+
) -> SearchResult: ...
2823

2924
@abstractmethod
30-
def paginate(self,
31-
page: int) -> Pagination: ...
32-
25+
def paginate(self, page: int) -> Pagination: ...
26+
3327
@abstractmethod
34-
def random(self) -> Manga:
35-
...
28+
def random(self) -> Manga: ...
3629

3730
@abstractmethod
38-
def author_page(self,
39-
author: str,
40-
page: int) -> AuthorPage:
41-
...
31+
def author_page(self, author: str, page: int) -> AuthorPage: ...
4232

4333
@abstractmethod
44-
def fetch_chapter_by_symbolic_link(self,
45-
link: SymbolicLink) -> Chapter:
46-
...
34+
def fetch_chapter_by_symbolic_link(self, link: SymbolicLink) -> Chapter: ...

enma/application/core/interfaces/saver_adapter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
from dataclasses import dataclass
33
from io import BytesIO
44

5+
56
@dataclass
67
class File:
78
name: str
89
data: BytesIO
910

10-
class ISaverAdapter(ABC):
1111

12+
class ISaverAdapter(ABC):
1213
@abstractmethod
13-
def save(self, path: str, file: File) -> bool:
14-
...
14+
def save(self, path: str, file: File) -> bool: ...

enma/application/core/interfaces/use_case.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
from dataclasses import dataclass
33
from typing import Generic, Optional, TypeVar
44

5-
K = TypeVar('K')
6-
V = TypeVar('V')
5+
K = TypeVar("K")
6+
V = TypeVar("V")
7+
78

89
@dataclass
910
class DTO(Generic[K]):
1011
data: K
1112

13+
1214
class IUseCase(ABC, Generic[K, V]):
1315
@abstractmethod
14-
def execute(self, dto: Optional[DTO[K]] = None) -> V:
15-
...
16+
def execute(self, dto: Optional[DTO[K]] = None) -> V: ...

0 commit comments

Comments
 (0)