Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

Commit

Permalink
fix: re-organise to avoid config read related
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinNitroG committed Jan 9, 2025
1 parent d407184 commit 11eca21
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 47 deletions.
16 changes: 8 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ name = "check-phat-nguoi"
version = "0.1.0-dev.1"
requires-python = ">=3.10"
dependencies = [
"aiohttp[speedups]>=3.11.11",
"pydantic>=2.10.4",
"truststore>=0.10.0",
"aiohttp[speedups]>=3.11.11",
"pydantic>=2.10.4",
"truststore>=0.10.0",
]

[project.scripts]
check-phat-nguoi = "check_phat_nguoi:main"
check-phat-nguoi = "check_phat_nguoi:__main__.main"
generate-schemas = "generate_schemas:__main__.main"
generate-config-schema = "generate_schemas:generate_config_schema"
generate-schemas = "generate_schemas:main"

[build-system]
requires = ["hatchling"]
Expand All @@ -25,7 +25,7 @@ build-backend = "hatchling.build"
[dependency-groups]
dev = ["pre-commit>=4.0.1"]
build-website = [
"json-schema-for-humans>=1.3.4",
"mkdocs-include-markdown-plugin>=7.1.2",
"mkdocs-material>=9.5.49",
"json-schema-for-humans>=1.3.4",
"mkdocs-include-markdown-plugin>=7.1.2",
"mkdocs-material>=9.5.49",
]
28 changes: 2 additions & 26 deletions src/check_phat_nguoi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
import asyncio
from logging import getLogger
from .config import ConfigDTO

from truststore import inject_into_ssl

from check_phat_nguoi.config_reader import config
from check_phat_nguoi.get_data import GetData
from check_phat_nguoi.notify import SendNotifications

from .utils.setup_logger import setup_logger

logger = getLogger(__name__)


async def async_main() -> None:
inject_into_ssl()
setup_logger()
logger.debug(f"Config read: {config}")
await GetData().get_data()
await SendNotifications().send()


def main() -> None:
asyncio.run(async_main())


__all__ = ["main"]
__all__ = ["ConfigDTO"]
28 changes: 25 additions & 3 deletions src/check_phat_nguoi/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
from check_phat_nguoi import main
import asyncio
from logging import getLogger

from truststore import inject_into_ssl

from check_phat_nguoi.config.config_reader import config
from check_phat_nguoi.get_data import GetData
from check_phat_nguoi.notify import SendNotifications

from .utils.setup_logger import setup_logger

logger = getLogger(__name__)


async def async_main() -> None:
inject_into_ssl()
setup_logger()
logger.debug(f"Config read: {config}")
await GetData().get_data()
await SendNotifications().send()


def main() -> None:
asyncio.run(async_main())


if __name__ == "__main__":
main()

__all__ = []
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

from check_phat_nguoi.constants.config import CONFIG_PATHS

from .config.dto import ConfigDTO
from .config.exceptions import NoConfigFoundException
from .dto import ConfigDTO
from .exceptions import NoConfigFoundException


def _config_reader() -> ConfigDTO:
Expand Down
2 changes: 1 addition & 1 deletion src/check_phat_nguoi/get_data/engines/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from aiohttp.typedefs import LooseHeaders

from check_phat_nguoi.config import PlateInfoDTO
from check_phat_nguoi.config_reader import config
from check_phat_nguoi.config.config_reader import config
from check_phat_nguoi.context import PlateInfoModel

logger = getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion src/check_phat_nguoi/get_data/get_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from logging import getLogger

from check_phat_nguoi.config import ApiEnum, PlateInfoDTO
from check_phat_nguoi.config_reader import config
from check_phat_nguoi.config.config_reader import config
from check_phat_nguoi.context import (
PlateInfoModel,
plates_context,
Expand Down
2 changes: 1 addition & 1 deletion src/check_phat_nguoi/notify/engines/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from aiohttp import ClientSession, ClientTimeout
from aiohttp.typedefs import LooseHeaders

from check_phat_nguoi.config_reader import config
from check_phat_nguoi.config.config_reader import config

logger = getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from check_phat_nguoi.config_reader import config
from check_phat_nguoi.config.config_reader import config
from check_phat_nguoi.constants import (
MESSAGE_MARKDOWN_PATTERN,
RESOLUTION_LOCATION_MARKDOWN_PATTERN,
Expand Down
2 changes: 1 addition & 1 deletion src/check_phat_nguoi/notify/send_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from logging import getLogger

from check_phat_nguoi.config import BaseNotificationDTO, TelegramNotificationDTO
from check_phat_nguoi.config_reader import config
from check_phat_nguoi.config.config_reader import config
from check_phat_nguoi.context import plates_context

from .engines.telegram import TelegramNotificationEngine
Expand Down
2 changes: 1 addition & 1 deletion src/check_phat_nguoi/utils/setup_logger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from logging import basicConfig

from check_phat_nguoi.config_reader import config
from check_phat_nguoi.config.config_reader import config
from check_phat_nguoi.constants.config import (
DETAIL_LOG_MESSAGE,
SIMPLE_LOG_MESSAGE,
Expand Down
9 changes: 8 additions & 1 deletion src/generate_schemas/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
from generate_schemas import main
from generate_schemas.modules import generate_config_schema


def main() -> None:
generate_config_schema()


__all__ = ["generate_config_schema"]

if __name__ == "__main__":
main()
Expand Down
2 changes: 1 addition & 1 deletion src/generate_schemas/modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pydantic import TypeAdapter

from check_phat_nguoi.config import ConfigDTO
from check_phat_nguoi import ConfigDTO
from generate_schemas.utils.constants import CONFIG_SCHEMA_PATH


Expand Down

0 comments on commit 11eca21

Please sign in to comment.