From 3fa5c9b57d7dc7d4f945f65cf2dd1ec97e5e5975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carvalho?= Date: Sun, 17 Jul 2022 19:17:52 +0100 Subject: [PATCH] chore: Fix issues on CI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Carvalho --- .github/workflows/ci.yml | 23 +++++++++++++---------- .github/workflows/docs.yml | 16 +++++++++------- mognet/backend/redis_result_backend.py | 11 +++++++---- mognet/primitives/request.py | 18 +++++++++++++++--- mognet/state/redis_state_backend.py | 8 +++++++- mognet/testing/pytest_integration.py | 7 +++---- 6 files changed, 54 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 039054c..2635da2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,16 +19,15 @@ jobs: python-version: ["3.8", "3.9", "3.10"] steps: - uses: actions/checkout@v3 - - - name: Install poetry - run: pip install poetry - - uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} cache: "pip" cache-dependency-path: "poetry.lock" + - name: Install poetry + run: pip install poetry + - name: Install dependencies run: poetry install @@ -39,19 +38,23 @@ jobs: run: make docker-up - name: Test - run: make test + # Wait for RabbitMQ to start. + run: sleep 10 && make test test-build-docs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Install poetry - run: pip install poetry - - uses: actions/setup-python@v3 + - uses: actions/setup-python@v4 with: - python-version: 3.x + python-version: "3.10" cache: "pip" cache-dependency-path: "poetry.lock" + + - name: Install poetry + run: pip install poetry + - name: Install dependencies run: poetry install - - run: mkdocs build --verbose --clean --strict + + - run: poetry run mkdocs build --verbose --clean --strict diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 7d890ef..27497e5 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -8,7 +8,6 @@ on: env: POETRY_VIRTUALENVS_CREATE: false - jobs: deploy: permissions: @@ -16,14 +15,17 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Install poetry - run: pip install poetry - uses: actions/setup-python@v3 with: - python-version: 3.x - cache: 'pip' - cache-dependency-path: 'poetry.lock' + python-version: "3.10" + cache: "pip" + cache-dependency-path: "poetry.lock" + + - name: Install poetry + run: pip install poetry + - name: Install dependencies run: poetry install + - name: Build and push docs - run: mkdocs gh-deploy --force + run: poetry run mkdocs gh-deploy --force diff --git a/mognet/backend/redis_result_backend.py b/mognet/backend/redis_result_backend.py index 86d43bf..69f050e 100644 --- a/mognet/backend/redis_result_backend.py +++ b/mognet/backend/redis_result_backend.py @@ -5,6 +5,7 @@ import gzip import json import logging +import sys from asyncio import shield from datetime import timedelta from typing import ( @@ -30,7 +31,6 @@ from pydantic.tools import parse_raw_as from redis.asyncio import from_url from redis.exceptions import ConnectionError, TimeoutError -from typing_extensions import TypeAlias from mognet.backend.backend_config import Encoding, ResultBackendConfig from mognet.backend.base_result_backend import AppParameters, BaseResultBackend @@ -40,15 +40,18 @@ from mognet.model.result_state import READY_STATES, ResultState from mognet.tools.urls import censor_credentials +if sys.version_info < (3, 10): + from typing_extensions import TypeAlias +else: + from typing import TypeAlias + if TYPE_CHECKING: from redis.asyncio import Redis # noqa: F401 _log = logging.getLogger(__name__) -_EncodedHSetPayload: TypeAlias = Mapping[ - Union[str, bytes], Union[bytes, float, int, str] -] +_EncodedHSetPayload = Mapping[Union[str, bytes], Union[bytes, float, int, str]] _F = TypeVar("_F", bound=Callable[..., Awaitable[Any]]) _Redis: TypeAlias = "Redis[Any]" diff --git a/mognet/primitives/request.py b/mognet/primitives/request.py index 636f2ab..a136edf 100644 --- a/mognet/primitives/request.py +++ b/mognet/primitives/request.py @@ -1,14 +1,26 @@ from datetime import datetime, timedelta -from typing import Any, Dict, Generic, List, Optional, Tuple, TypeVar, Union +from typing import ( + TYPE_CHECKING, + Any, + Dict, + Generic, + List, + Optional, + Tuple, + TypeVar, + Union, +) from uuid import UUID, uuid4 from pydantic import BaseModel, conint from pydantic.fields import Field -from typing_extensions import TypeAlias TReturn = TypeVar("TReturn") -Priority: TypeAlias = conint(ge=0, le=10) # type: ignore +if TYPE_CHECKING: + Priority = int +else: + Priority = conint(ge=0, le=10) class Request(BaseModel, Generic[TReturn]): diff --git a/mognet/state/redis_state_backend.py b/mognet/state/redis_state_backend.py index de69c36..1139a3f 100644 --- a/mognet/state/redis_state_backend.py +++ b/mognet/state/redis_state_backend.py @@ -2,17 +2,23 @@ import json import logging +import sys from typing import TYPE_CHECKING, Any, Optional, TypeVar, cast from uuid import UUID from redis.asyncio import from_url -from typing_extensions import TypeAlias from mognet.exceptions.base_exceptions import NotConnected from mognet.state.base_state_backend import BaseStateBackend from mognet.state.state_backend_config import StateBackendConfig from mognet.tools.urls import censor_credentials +if sys.version_info < (3, 10): + from typing_extensions import TypeAlias +else: + from typing import TypeAlias + + if TYPE_CHECKING: from redis.asyncio import Redis # noqa: F401 diff --git a/mognet/testing/pytest_integration.py b/mognet/testing/pytest_integration.py index 9a50df5..fb4aa4f 100644 --- a/mognet/testing/pytest_integration.py +++ b/mognet/testing/pytest_integration.py @@ -1,15 +1,14 @@ import asyncio -from typing import AsyncIterable, Callable +from typing import Any, AsyncIterable import pytest_asyncio from mognet import App -def create_app_fixture(app: App) -> Callable[[], App]: +def create_app_fixture(app: App) -> Any: """Create a Pytest fixture for a Mognet application.""" - @pytest_asyncio.fixture # type: ignore async def app_fixture() -> AsyncIterable[App]: async with app: start_task = asyncio.create_task(app.start()) @@ -22,4 +21,4 @@ async def app_fixture() -> AsyncIterable[App]: except BaseException: # pylint: disable=broad-except pass - return app_fixture # type: ignore + return pytest_asyncio.fixture(app_fixture)