From 723172387bbd42401015403a5eaa0080a712992b Mon Sep 17 00:00:00 2001 From: Crystal Melting Dot Date: Sun, 21 Feb 2021 00:43:41 +0300 Subject: [PATCH] this should probably make relative imports work --- apps/Dockerfile-tgbot | 2 +- apps/tgbot/{tgbot => }/bot.py | 4 ++-- apps/tgbot/test/__init__.py | 1 + apps/tgbot/{tgbot => }/test/test_port_parsers.py | 4 ++-- apps/tgbot/tgbot/handlers/base.py | 4 ++-- apps/tgbot/tgbot/handlers/default/icmp.py | 2 +- apps/tgbot/tgbot/handlers/default/ipcalc.py | 4 ++-- apps/tgbot/tgbot/handlers/default/minecraft.py | 4 ++-- apps/tgbot/tgbot/handlers/default/start.py | 6 +++--- apps/tgbot/tgbot/handlers/default/tcp.py | 6 +++--- apps/tgbot/tgbot/handlers/default/whois.py | 8 ++++---- apps/tgbot/tgbot/handlers/helpers.py | 4 ++-- apps/tgbot/tgbot/handlers/metrics.py | 2 +- apps/tgbot/tgbot/middlewares/__init__.py | 8 ++++---- apps/tgbot/tgbot/middlewares/userdata.py | 2 +- apps/tgbot/tgbot/middlewares/write_command_metric.py | 4 ++-- apps/tgbot/tgbot/test/__init__.py | 1 - 17 files changed, 33 insertions(+), 33 deletions(-) rename apps/tgbot/{tgbot => }/bot.py (95%) create mode 100644 apps/tgbot/test/__init__.py rename apps/tgbot/{tgbot => }/test/test_port_parsers.py (95%) delete mode 100644 apps/tgbot/tgbot/test/__init__.py diff --git a/apps/Dockerfile-tgbot b/apps/Dockerfile-tgbot index d6a583f..61dce7b 100644 --- a/apps/Dockerfile-tgbot +++ b/apps/Dockerfile-tgbot @@ -8,6 +8,6 @@ RUN apk update \ && apk add gcc python3-dev musl-dev libffi-dev openssl-dev make cargo COPY . . -WORKDIR tgbot/tgbot +WORKDIR tgbot RUN pip install --upgrade pip; pip install poetry; poetry config virtualenvs.create false; poetry install CMD poetry shell; python bot.py diff --git a/apps/tgbot/tgbot/bot.py b/apps/tgbot/bot.py similarity index 95% rename from apps/tgbot/tgbot/bot.py rename to apps/tgbot/bot.py index e1ac336..38d73c6 100644 --- a/apps/tgbot/tgbot/bot.py +++ b/apps/tgbot/bot.py @@ -5,8 +5,8 @@ from tortoise import Tortoise from tortoise.exceptions import DBConnectionError from loguru import logger from asyncio import sleep -import config -import handlers +import tgbot.config as config +import tgbot.handlers as handlers storage = MemoryStorage() telegram_bot = Bot(token=config.TELEGRAM_BOT_TOKEN) diff --git a/apps/tgbot/test/__init__.py b/apps/tgbot/test/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/apps/tgbot/test/__init__.py @@ -0,0 +1 @@ + diff --git a/apps/tgbot/tgbot/test/test_port_parsers.py b/apps/tgbot/test/test_port_parsers.py similarity index 95% rename from apps/tgbot/tgbot/test/test_port_parsers.py rename to apps/tgbot/test/test_port_parsers.py index 926e674..c07bb2e 100644 --- a/apps/tgbot/tgbot/test/test_port_parsers.py +++ b/apps/tgbot/test/test_port_parsers.py @@ -1,7 +1,7 @@ from unittest import TestCase -from ..handlers.default.tcp import TCPCheckerHandler -from ..handlers.base import process_args_for_host_port,\ +from tgbot.handlers.default.tcp import TCPCheckerHandler +from tgbot.handlers.base import process_args_for_host_port,\ NotEnoughArgs, InvalidPort diff --git a/apps/tgbot/tgbot/handlers/base.py b/apps/tgbot/tgbot/handlers/base.py index c8b9538..141a7e1 100644 --- a/apps/tgbot/tgbot/handlers/base.py +++ b/apps/tgbot/tgbot/handlers/base.py @@ -1,7 +1,7 @@ from aiogram.types import Message from typing import Tuple, Any, List -from tgbot.nodes import nodes as all_nodes +from ..nodes import nodes as all_nodes from httpx import Response from aiogram.bot import Bot from datetime import datetime @@ -9,7 +9,7 @@ from core.coretypes import APINodeInfo from .helpers import send_api_requests from .errors import NotEnoughArgs, InvalidPort, LocalhostForbidden from .validators import BaseValidator, LocalhostValidator -from tgbot.middlewares.throttling import rate_limit +from ..middlewares.throttling import rate_limit from loguru import logger from uuid import uuid4 from time import time diff --git a/apps/tgbot/tgbot/handlers/default/icmp.py b/apps/tgbot/tgbot/handlers/default/icmp.py index a79a3c4..47a8e69 100644 --- a/apps/tgbot/tgbot/handlers/default/icmp.py +++ b/apps/tgbot/tgbot/handlers/default/icmp.py @@ -3,7 +3,7 @@ from httpx import Response from core.coretypes import ErrorPayload, ICMPCheckerResponse, ResponseStatus from ..base import CheckerBaseHandler, NotEnoughArgs, LocalhostForbidden from ..metrics import push_status_metric -from tgbot.middlewares.throttling import rate_limit +from ...middlewares.throttling import rate_limit icmp_help_message = """ ❓ Производит проверку хоста по протоколу ICMP. diff --git a/apps/tgbot/tgbot/handlers/default/ipcalc.py b/apps/tgbot/tgbot/handlers/default/ipcalc.py index 83d18a4..79a45fc 100644 --- a/apps/tgbot/tgbot/handlers/default/ipcalc.py +++ b/apps/tgbot/tgbot/handlers/default/ipcalc.py @@ -2,8 +2,8 @@ from aiogram.types import Message from typing import Union import ipaddress -from tgbot.handlers.base import SimpleCommandHandler, NotEnoughArgs -from tgbot.middlewares.throttling import rate_limit +from ..base import SimpleCommandHandler, NotEnoughArgs +from ...middlewares.throttling import rate_limit ipcalc_help_message = """ ❓ Калькулятор IP подсетей. diff --git a/apps/tgbot/tgbot/handlers/default/minecraft.py b/apps/tgbot/tgbot/handlers/default/minecraft.py index cdbf9c4..4e75cab 100644 --- a/apps/tgbot/tgbot/handlers/default/minecraft.py +++ b/apps/tgbot/tgbot/handlers/default/minecraft.py @@ -1,8 +1,8 @@ from core.coretypes import ResponseStatus, ErrorPayload, MinecraftResponse from httpx import Response -from tgbot.handlers.base import CheckerTargetPortHandler, process_args_for_host_port -from tgbot.handlers.metrics import push_status_metric +from ..base import CheckerTargetPortHandler, process_args_for_host_port +from ..metrics import push_status_metric minecraft_help_message = """ ❓ Получает статистику о Minecraft сервере diff --git a/apps/tgbot/tgbot/handlers/default/start.py b/apps/tgbot/tgbot/handlers/default/start.py index 3b1e54c..f6e8a1e 100644 --- a/apps/tgbot/tgbot/handlers/default/start.py +++ b/apps/tgbot/tgbot/handlers/default/start.py @@ -1,7 +1,7 @@ from aiogram.types import Message -from tgbot.models.user import User -from tgbot.middlewares.throttling import rate_limit -from tgbot.middlewares.userdata import userdata_required +from ...models.user import User +from ...middlewares.throttling import rate_limit +from ...middlewares.userdata import userdata_required start_message = """ diff --git a/apps/tgbot/tgbot/handlers/default/tcp.py b/apps/tgbot/tgbot/handlers/default/tcp.py index 29549dc..a71e35c 100644 --- a/apps/tgbot/tgbot/handlers/default/tcp.py +++ b/apps/tgbot/tgbot/handlers/default/tcp.py @@ -3,9 +3,9 @@ from aiogram.types import Message from core.coretypes import ResponseStatus, ErrorPayload, PortResponse from httpx import Response -from tgbot.handlers.base import CheckerTargetPortHandler, NotEnoughArgs, InvalidPort, parse_host_port -from tgbot.handlers.metrics import push_status_metric -from tgbot.middlewares.throttling import rate_limit +from ..base import CheckerTargetPortHandler, NotEnoughArgs, InvalidPort, parse_host_port +from ..metrics import push_status_metric +from ...middlewares.throttling import rate_limit tcp_help_message = """ ❓ Производит проверку TCP порта, открыт ли он или нет diff --git a/apps/tgbot/tgbot/handlers/default/whois.py b/apps/tgbot/tgbot/handlers/default/whois.py index 98188e8..687ac3c 100644 --- a/apps/tgbot/tgbot/handlers/default/whois.py +++ b/apps/tgbot/tgbot/handlers/default/whois.py @@ -6,10 +6,10 @@ from dataclasses import dataclass from whois_vu.api import WhoisSource from whois_vu.errors import IncorrectZone, QueryNotMatchRegexp -from tgbot.handlers.whois_zones import ZONES -from tgbot.handlers.base import SimpleCommandHandler -from tgbot.handlers.errors import NotEnoughArgs, LocalhostForbidden -from tgbot.middlewares.throttling import rate_limit +from ..whois_zones import ZONES +from ..base import SimpleCommandHandler +from ..errors import NotEnoughArgs, LocalhostForbidden +from ...middlewares.throttling import rate_limit whois_help_message = """ ❓ Вернёт информацию о домене. diff --git a/apps/tgbot/tgbot/handlers/helpers.py b/apps/tgbot/tgbot/handlers/helpers.py index f20db15..63b4d92 100644 --- a/apps/tgbot/tgbot/handlers/helpers.py +++ b/apps/tgbot/tgbot/handlers/helpers.py @@ -5,8 +5,8 @@ from ipaddress import ip_address from contextlib import suppress from loguru import logger from aiogram.bot import Bot -from tgbot.handlers.metrics import push_api_request_status -from tgbot.config import NOTIFICATION_BOT_TOKEN, NOTIFICATION_USERS +from .metrics import push_api_request_status +from ..config import NOTIFICATION_BOT_TOKEN, NOTIFICATION_USERS from traceback import format_exc import asyncio diff --git a/apps/tgbot/tgbot/handlers/metrics.py b/apps/tgbot/tgbot/handlers/metrics.py index 3f33bc5..3943be7 100644 --- a/apps/tgbot/tgbot/handlers/metrics.py +++ b/apps/tgbot/tgbot/handlers/metrics.py @@ -1,6 +1,6 @@ from aioinflux import InfluxDBClient from typing import Dict -from tgbot.config import INFLUX_DB, INFLUX_HOST, INFLUX_PORT, INFLUX_PASSWORD, INFLUX_USERNAME +from ..config import INFLUX_DB, INFLUX_HOST, INFLUX_PORT, INFLUX_PASSWORD, INFLUX_USERNAME async def push_metric(measurement, tags: Dict, fields: Dict): diff --git a/apps/tgbot/tgbot/middlewares/__init__.py b/apps/tgbot/tgbot/middlewares/__init__.py index e923a5f..498c6e6 100644 --- a/apps/tgbot/tgbot/middlewares/__init__.py +++ b/apps/tgbot/tgbot/middlewares/__init__.py @@ -1,4 +1,4 @@ -from tgbot.middlewares.write_command_metric import WriteCommandMetric -from tgbot.middlewares.logging import LoggingMiddleware -from tgbot.middlewares.throttling import ThrottlingMiddleware -from tgbot.middlewares.userdata import UserMiddleware +from .write_command_metric import WriteCommandMetric +from .logging import LoggingMiddleware +from .throttling import ThrottlingMiddleware +from .userdata import UserMiddleware diff --git a/apps/tgbot/tgbot/middlewares/userdata.py b/apps/tgbot/tgbot/middlewares/userdata.py index 99fb07e..2a6e559 100644 --- a/apps/tgbot/tgbot/middlewares/userdata.py +++ b/apps/tgbot/tgbot/middlewares/userdata.py @@ -2,7 +2,7 @@ from aiogram.dispatcher.handler import current_handler from aiogram.dispatcher.middlewares import BaseMiddleware from aiogram.types import Message, CallbackQuery -from tgbot.models import User +from ..models import User def userdata_required(func): diff --git a/apps/tgbot/tgbot/middlewares/write_command_metric.py b/apps/tgbot/tgbot/middlewares/write_command_metric.py index 67d1053..13b0ac5 100644 --- a/apps/tgbot/tgbot/middlewares/write_command_metric.py +++ b/apps/tgbot/tgbot/middlewares/write_command_metric.py @@ -1,7 +1,7 @@ from aiogram.dispatcher.middlewares import BaseMiddleware from aiogram.types import Message -from tgbot.handlers.metrics import push_metric -from tgbot.models import User, UserCheckRequests +from ..handlers.metrics import push_metric +from ..models import User, UserCheckRequests class WriteCommandMetric(BaseMiddleware): diff --git a/apps/tgbot/tgbot/test/__init__.py b/apps/tgbot/tgbot/test/__init__.py deleted file mode 100644 index aec7c3e..0000000 --- a/apps/tgbot/tgbot/test/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .test_port_parsers import *