From e465ab5ea0762f86c5110ed3697f9767eff5dae2 Mon Sep 17 00:00:00 2001 From: Stefan Verhoeven Date: Fri, 23 Feb 2024 08:22:14 +0100 Subject: [PATCH] Support Python 3.9 Fixes #82 and haddock3 also requires 3.9 --- pyproject.toml | 2 +- src/bartender/config.py | 18 +++++++++--------- src/bartender/web/api/job/interactive_apps.py | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index bd3cb22..5b623b8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ readme = "README.md" packages = [{include = "bartender", from = "src"}] [tool.poetry.dependencies] -python = "^3.10" +python = "^3.9" # TODO upgrade to pydantic v2 fastapi = "^0.99.0" uvicorn = {version = "^0.21.1", extras = ["standard"]} diff --git a/src/bartender/config.py b/src/bartender/config.py index 4ab9434..e977cf9 100644 --- a/src/bartender/config.py +++ b/src/bartender/config.py @@ -3,7 +3,7 @@ from pathlib import Path from tempfile import gettempdir -from typing import Annotated, Any +from typing import Annotated, Any, Union from fastapi import Depends, Request from jsonschema import Draft202012Validator @@ -41,17 +41,17 @@ class ApplicatonConfiguration(BaseModel): """ command_template: str - input_schema: dict[Any, Any] | None = None - summary: str | None = None - description: str | None = None + input_schema: Union[dict[Any, Any], None] = None + summary: Union[str, None] = None + description: Union[str, None] = None upload_needs: list[str] = [] allowed_roles: list[str] = [] @validator("input_schema") def check_input_schema( cls, # noqa: N805 - v: dict[Any, Any] | None, # noqa: WPS111 - ) -> dict[Any, Any] | None: + v: Union[dict[Any, Any], None], # noqa: WPS111 + ) -> Union[dict[Any, Any], None]: """Validate input schema. Args: @@ -128,10 +128,10 @@ class InteractiveApplicationConfiguration(BaseModel): command_template: str input_schema: dict[Any, Any] - summary: str | None = None - description: str | None = None + summary: Union[str, None] = None + description: Union[str, None] = None timeout: confloat(gt=0, le=60) = 30.0 # type: ignore - job_application: str | None = None + job_application: Union[str, None] = None @validator("input_schema") def check_input_schema( diff --git a/src/bartender/web/api/job/interactive_apps.py b/src/bartender/web/api/job/interactive_apps.py index bbb2de9..6550886 100644 --- a/src/bartender/web/api/job/interactive_apps.py +++ b/src/bartender/web/api/job/interactive_apps.py @@ -5,7 +5,7 @@ from contextlib import asynccontextmanager from os.path import join from pathlib import Path -from typing import Any, AsyncGenerator, Literal +from typing import Any, AsyncGenerator, Literal, Union from aiofiles import open from aiofiles.tempfile import TemporaryDirectory @@ -75,10 +75,10 @@ def build_command( return template.render(**payload) -MediaEncoding = Literal["base64"] | Literal["utf-8"] # -- 3.10>= union type +MediaEncoding = Union[Literal["base64"], Literal["utf-8"]] -def encoding_of_prop(prop: dict[Any, Any]) -> MediaEncoding | None: +def encoding_of_prop(prop: dict[Any, Any]) -> Union[MediaEncoding, None]: """ Determines the encoding of a property. @@ -147,7 +147,7 @@ async def write_file(encoded_data: str, encoding: MediaEncoding, fn: str) -> Non await fh.write(decoded_data) -def get_path_in_payload(data: dict[Any, Any], path: str) -> Any | None: +def get_path_in_payload(data: dict[Any, Any], path: str) -> Union[Any, None]: """ Get the value at the specified path in the given dictionary.