From 08022de6eb85c52fda85c42083194e0a31a6f2a3 Mon Sep 17 00:00:00 2001 From: sanderegg <35365065+sanderegg@users.noreply.github.com> Date: Mon, 15 May 2023 13:18:14 +0200 Subject: [PATCH] @pcrespov review: use a type alias --- .../dask_task_models_library/container_tasks/events.py | 5 +---- .../src/models_library/rabbitmq_messages.py | 5 +---- packages/service-library/src/servicelib/logging_utils.py | 1 + packages/service-library/tests/test_logging_utils.py | 8 +++++--- .../computational_sidecar/core.py | 3 +-- .../computational_sidecar/docker_utils.py | 7 ++----- .../src/simcore_service_dask_sidecar/dask_utils.py | 5 +---- .../src/simcore_service_dask_sidecar/file_utils.py | 3 ++- services/dask-sidecar/tests/unit/test_docker_utils.py | 3 +-- .../core/docker_compose_utils.py | 5 +---- .../src/simcore_service_dynamic_sidecar/core/rabbitmq.py | 5 +---- 11 files changed, 17 insertions(+), 33 deletions(-) diff --git a/packages/dask-task-models-library/src/dask_task_models_library/container_tasks/events.py b/packages/dask-task-models-library/src/dask_task_models_library/container_tasks/events.py index f08cf98eea09..11a8ba5ae3b4 100644 --- a/packages/dask-task-models-library/src/dask_task_models_library/container_tasks/events.py +++ b/packages/dask-task-models-library/src/dask_task_models_library/container_tasks/events.py @@ -4,10 +4,7 @@ from distributed.worker import get_worker from pydantic import BaseModel, Extra, NonNegativeFloat -from servicelib.logging_utils import LogLevelInt -from simcore_service_dask_sidecar.computational_sidecar.docker_utils import ( - LogMessageStr, -) +from servicelib.logging_utils import LogLevelInt, LogMessageStr class BaseTaskEvent(BaseModel, ABC): diff --git a/packages/models-library/src/models_library/rabbitmq_messages.py b/packages/models-library/src/models_library/rabbitmq_messages.py index 18f95424c9bf..047979dbd8db 100644 --- a/packages/models-library/src/models_library/rabbitmq_messages.py +++ b/packages/models-library/src/models_library/rabbitmq_messages.py @@ -10,10 +10,7 @@ from models_library.utils.enums import StrAutoEnum from pydantic import BaseModel, Field from pydantic.types import NonNegativeFloat -from servicelib.logging_utils import LogLevelInt -from simcore_service_dask_sidecar.computational_sidecar.docker_utils import ( - LogMessageStr, -) +from servicelib.logging_utils import LogLevelInt, LogMessageStr class RabbitEventMessageType(str, Enum): diff --git a/packages/service-library/src/servicelib/logging_utils.py b/packages/service-library/src/servicelib/logging_utils.py index e8791698a301..77886ca52db3 100644 --- a/packages/service-library/src/servicelib/logging_utils.py +++ b/packages/service-library/src/servicelib/logging_utils.py @@ -250,6 +250,7 @@ def get_log_record_extra(*, user_id: int | str | None = None) -> LogExtra | None LogLevelInt: TypeAlias = int +LogMessageStr: TypeAlias = str def guess_message_log_level(message: str) -> LogLevelInt: diff --git a/packages/service-library/tests/test_logging_utils.py b/packages/service-library/tests/test_logging_utils.py index c8fcf8531dad..3337544d6007 100644 --- a/packages/service-library/tests/test_logging_utils.py +++ b/packages/service-library/tests/test_logging_utils.py @@ -5,11 +5,13 @@ import pytest from pytest import LogCaptureFixture -from servicelib.logging_utils import LogLevelInt, guess_message_log_level, log_decorator -from servicelib.utils import logged_gather -from simcore_service_dask_sidecar.computational_sidecar.docker_utils import ( +from servicelib.logging_utils import ( + LogLevelInt, LogMessageStr, + guess_message_log_level, + log_decorator, ) +from servicelib.utils import logged_gather logger = logging.getLogger(__name__) diff --git a/services/dask-sidecar/src/simcore_service_dask_sidecar/computational_sidecar/core.py b/services/dask-sidecar/src/simcore_service_dask_sidecar/computational_sidecar/core.py index d0da5d634617..d5fb2b4270bc 100644 --- a/services/dask-sidecar/src/simcore_service_dask_sidecar/computational_sidecar/core.py +++ b/services/dask-sidecar/src/simcore_service_dask_sidecar/computational_sidecar/core.py @@ -24,7 +24,7 @@ from packaging import version from pydantic import ValidationError from pydantic.networks import AnyUrl -from servicelib.logging_utils import LogLevelInt +from servicelib.logging_utils import LogLevelInt, LogMessageStr from settings_library.s3 import S3Settings from yarl import URL @@ -32,7 +32,6 @@ from ..file_utils import pull_file_from_remote, push_file_to_remote from ..settings import Settings from .docker_utils import ( - LogMessageStr, create_container_config, get_computational_shared_data_mount_point, get_integration_version, diff --git a/services/dask-sidecar/src/simcore_service_dask_sidecar/computational_sidecar/docker_utils.py b/services/dask-sidecar/src/simcore_service_dask_sidecar/computational_sidecar/docker_utils.py index 53b8c7503a84..1ea0fad078ab 100644 --- a/services/dask-sidecar/src/simcore_service_dask_sidecar/computational_sidecar/docker_utils.py +++ b/services/dask-sidecar/src/simcore_service_dask_sidecar/computational_sidecar/docker_utils.py @@ -14,7 +14,6 @@ Awaitable, Callable, Coroutine, - TypeAlias, cast, ) @@ -33,6 +32,7 @@ from servicelib.docker_utils import to_datetime from servicelib.logging_utils import ( LogLevelInt, + LogMessageStr, guess_message_log_level, log_catch, log_context, @@ -56,7 +56,7 @@ from .task_shared_volume import TaskSharedVolumes logger = create_dask_worker_logger(__name__) -LogPublishingCB = Callable[[str, int], Awaitable[None]] +LogPublishingCB = Callable[[LogMessageStr, LogLevelInt], Awaitable[None]] async def create_container_config( @@ -162,9 +162,6 @@ def _guess_progress_value(progress_match: re.Match[str]) -> float: return value -LogMessageStr: TypeAlias = str - - async def _parse_line( line: str, ) -> tuple[LogType, datetime.datetime, LogMessageStr, LogLevelInt]: diff --git a/services/dask-sidecar/src/simcore_service_dask_sidecar/dask_utils.py b/services/dask-sidecar/src/simcore_service_dask_sidecar/dask_utils.py index 27cf4ee1c5bf..5f4e3186c76b 100644 --- a/services/dask-sidecar/src/simcore_service_dask_sidecar/dask_utils.py +++ b/services/dask-sidecar/src/simcore_service_dask_sidecar/dask_utils.py @@ -15,10 +15,7 @@ from dask_task_models_library.container_tasks.io import TaskCancelEventName from distributed.worker import get_worker from distributed.worker_state_machine import TaskState -from servicelib.logging_utils import LogLevelInt -from simcore_service_dask_sidecar.computational_sidecar.docker_utils import ( - LogMessageStr, -) +from servicelib.logging_utils import LogLevelInt, LogMessageStr def create_dask_worker_logger(name: str) -> logging.Logger: diff --git a/services/dask-sidecar/src/simcore_service_dask_sidecar/file_utils.py b/services/dask-sidecar/src/simcore_service_dask_sidecar/file_utils.py index 41cd8656c6c8..206dfbd3eefc 100644 --- a/services/dask-sidecar/src/simcore_service_dask_sidecar/file_utils.py +++ b/services/dask-sidecar/src/simcore_service_dask_sidecar/file_utils.py @@ -13,6 +13,7 @@ import fsspec from pydantic import ByteSize, FileUrl, parse_obj_as from pydantic.networks import AnyUrl +from servicelib.logging_utils import LogLevelInt, LogMessageStr from settings_library.s3 import S3Settings from yarl import URL @@ -24,7 +25,7 @@ S3_FILE_SYSTEM_SCHEMES: Final = ["s3", "s3a"] -LogPublishingCB = Callable[[str, int], Awaitable[None]] +LogPublishingCB = Callable[[LogMessageStr, LogLevelInt], Awaitable[None]] def _file_progress_cb( diff --git a/services/dask-sidecar/tests/unit/test_docker_utils.py b/services/dask-sidecar/tests/unit/test_docker_utils.py index 1a11abce1021..6732c6a0c787 100644 --- a/services/dask-sidecar/tests/unit/test_docker_utils.py +++ b/services/dask-sidecar/tests/unit/test_docker_utils.py @@ -13,9 +13,8 @@ import pytest from models_library.services_resources import BootMode from pytest_mock.plugin import MockerFixture -from servicelib.logging_utils import LogLevelInt +from servicelib.logging_utils import LogLevelInt, LogMessageStr from simcore_service_dask_sidecar.computational_sidecar.docker_utils import ( - LogMessageStr, LogType, _parse_line, create_container_config, diff --git a/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/core/docker_compose_utils.py b/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/core/docker_compose_utils.py index 227b7001f9ec..fb84fca82538 100644 --- a/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/core/docker_compose_utils.py +++ b/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/core/docker_compose_utils.py @@ -11,11 +11,8 @@ from fastapi import FastAPI from models_library.rabbitmq_messages import ProgressType from servicelib.async_utils import run_sequentially_in_context -from servicelib.logging_utils import LogLevelInt +from servicelib.logging_utils import LogLevelInt, LogMessageStr from settings_library.basic_types import LogLevel -from simcore_service_dask_sidecar.computational_sidecar.docker_utils import ( - LogMessageStr, -) from simcore_service_dynamic_sidecar.core.rabbitmq import ( post_progress_message, post_sidecar_log_message, diff --git a/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/core/rabbitmq.py b/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/core/rabbitmq.py index 79be15228eb9..eeb4c1102f66 100644 --- a/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/core/rabbitmq.py +++ b/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/core/rabbitmq.py @@ -12,12 +12,9 @@ RabbitMessageBase, ) from pydantic import NonNegativeFloat -from servicelib.logging_utils import LogLevelInt, log_catch, log_context +from servicelib.logging_utils import LogLevelInt, LogMessageStr, log_catch, log_context from servicelib.rabbitmq import RabbitMQClient from servicelib.rabbitmq_utils import wait_till_rabbitmq_responsive -from simcore_service_dask_sidecar.computational_sidecar.docker_utils import ( - LogMessageStr, -) from ..core.settings import ApplicationSettings