diff --git a/kilroy_module_client_py_sdk/poetry.lock b/kilroy_module_client_py_sdk/poetry.lock index 084b720..6bf6c7c 100644 --- a/kilroy_module_client_py_sdk/poetry.lock +++ b/kilroy_module_client_py_sdk/poetry.lock @@ -8,17 +8,17 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" [[package]] name = "attrs" -version = "21.4.0" +version = "22.1.0" description = "Classes Without Boilerplate" category = "main" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +python-versions = ">=3.5" [package.extras] -dev = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface", "furo", "sphinx", "sphinx-notfound-page", "pre-commit", "cloudpickle"] +dev = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "mypy (>=0.900,!=0.940)", "pytest-mypy-plugins", "zope.interface", "furo", "sphinx", "sphinx-notfound-page", "pre-commit", "cloudpickle"] docs = ["furo", "sphinx", "zope.interface", "sphinx-notfound-page"] -tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface", "cloudpickle"] -tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "cloudpickle"] +tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "mypy (>=0.900,!=0.940)", "pytest-mypy-plugins", "zope.interface", "cloudpickle"] +tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "mypy (>=0.900,!=0.940)", "pytest-mypy-plugins", "cloudpickle"] [[package]] name = "colorama" @@ -38,7 +38,7 @@ python-versions = "*" [[package]] name = "jsonschema" -version = "4.7.2" +version = "4.8.0" description = "An implementation of JSON Schema validation for Python" category = "main" optional = false @@ -52,22 +52,54 @@ pyrsistent = ">=0.14.0,<0.17.0 || >0.17.0,<0.17.1 || >0.17.1,<0.17.2 || >0.17.2" format = ["fqdn", "idna", "isoduration", "jsonpointer (>1.13)", "rfc3339-validator", "rfc3987", "uri-template", "webcolors (>=1.11)"] format-nongpl = ["fqdn", "idna", "isoduration", "jsonpointer (>1.13)", "rfc3339-validator", "rfc3986-validator (>0.1.0)", "uri-template", "webcolors (>=1.11)"] +[[package]] +name = "kilroy-module-py-shared" +version = "0.2.1" +description = "shared code for kilroy module SDKs in Python 🤝" +category = "main" +optional = false +python-versions = ">=3.9,<4.0" + +[package.dependencies] +jsonschema = ">=4.7,<5.0" +pydantic = ">=1.9,<2.0" +pyhumps = ">=3.7,<4.0" + +[package.extras] +dev = ["pytest (>=7.0,<8.0)"] +test = ["pytest (>=7.0,<8.0)"] + [[package]] name = "kilroy-ws-client-py-sdk" -version = "0.4.2" +version = "0.4.3" description = "SDK for WebSocket clients in Python 🧰" category = "main" optional = false python-versions = ">=3.9,<4.0" +[package.dependencies] +kilroy-ws-py-shared = ">=0.2,<0.3" + +[package.extras] +dev = ["pytest-asyncio (>=0.19,<0.20)", "pytest (>=7.0,<8.0)"] +test = ["pytest-asyncio (>=0.19,<0.20)", "pytest (>=7.0,<8.0)"] + +[[package]] +name = "kilroy-ws-py-shared" +version = "0.2.0" +description = "shared code for WebSocket SDKs in Python 🤝" +category = "main" +optional = false +python-versions = ">=3.9,<4.0" + [package.dependencies] pydantic = ">=1.9,<2.0" pyhumps = ">=3.7,<4.0" websockets = ">=10.3,<11.0" [package.extras] -dev = ["pytest-asyncio (>=0.19,<0.20)", "pytest (>=7.0,<8.0)"] -test = ["pytest-asyncio (>=0.19,<0.20)", "pytest (>=7.0,<8.0)"] +dev = ["pytest (>=7.0,<8.0)"] +test = ["pytest (>=7.0,<8.0)"] [[package]] name = "packaging" @@ -194,15 +226,15 @@ test = ["pytest"] [metadata] lock-version = "1.1" python-versions = "^3.9" -content-hash = "65a8d58b20e2abab8f611e1509023367d0d22b42aebd0a704b819a2d35e663a6" +content-hash = "19853552ad54be0b596e90e27519bee69b0d8f69387954f0a75832fb4984c42c" [metadata.files] atomicwrites = [ {file = "atomicwrites-1.4.1.tar.gz", hash = "sha256:81b2c9071a49367a7f770170e5eec8cb66567cfbbc8c73d20ce5ca4a8d71cf11"}, ] attrs = [ - {file = "attrs-21.4.0-py2.py3-none-any.whl", hash = "sha256:2d27e3784d7a565d36ab851fe94887c5eccd6a463168875832a1be79c82828b4"}, - {file = "attrs-21.4.0.tar.gz", hash = "sha256:626ba8234211db98e869df76230a137c4c40a12d72445c45d5f5b716f076e2fd"}, + {file = "attrs-22.1.0-py2.py3-none-any.whl", hash = "sha256:86efa402f67bf2df34f51a335487cf46b1ec130d02b8d39fd248abfd30da551c"}, + {file = "attrs-22.1.0.tar.gz", hash = "sha256:29adc2665447e5191d0e7c568fde78b21f9672d344281d0c6e1ab085429b22b6"}, ] colorama = [ {file = "colorama-0.4.5-py2.py3-none-any.whl", hash = "sha256:854bf444933e37f5824ae7bfc1e98d5bce2ebe4160d46b5edf346a89358e99da"}, @@ -213,12 +245,20 @@ iniconfig = [ {file = "iniconfig-1.1.1.tar.gz", hash = "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"}, ] jsonschema = [ - {file = "jsonschema-4.7.2-py3-none-any.whl", hash = "sha256:c7448a421b25e424fccfceea86b4e3a8672b4436e1988ccbde92c80828d4f085"}, - {file = "jsonschema-4.7.2.tar.gz", hash = "sha256:73764f461d61eb97a057c929368610a134d1d1fffd858acfe88864ee94f1f1d3"}, + {file = "jsonschema-4.8.0-py3-none-any.whl", hash = "sha256:58bb77251318cef5e1179e33dd6e7a008a3c6c638487ab4d943c2f370cc31a1a"}, + {file = "jsonschema-4.8.0.tar.gz", hash = "sha256:c1d410e379b210ba903bee6adf3fce6d5204cea4c2b622d63f914d2dbfef0993"}, +] +kilroy-module-py-shared = [ + {file = "kilroy-module-py-shared-0.2.1.tar.gz", hash = "sha256:7f940b5580e8ef3bd8046f71c0b6af3e36e0567bfd57b7f768eb7d16d695e7a3"}, + {file = "kilroy_module_py_shared-0.2.1-py3-none-any.whl", hash = "sha256:91c76d6f350e87267d5dd21aa9ee738891d5a65ea66530fa45bff831596fbd41"}, ] kilroy-ws-client-py-sdk = [ - {file = "kilroy-ws-client-py-sdk-0.4.2.tar.gz", hash = "sha256:456941005fb90cb6c9179137a93b81bd7a8c505c54d44d311732ee9c0c0e201a"}, - {file = "kilroy_ws_client_py_sdk-0.4.2-py3-none-any.whl", hash = "sha256:15539127822a0491ffdcf5ebd3b44e80aae0653a7d96758d445ed317190ced23"}, + {file = "kilroy-ws-client-py-sdk-0.4.3.tar.gz", hash = "sha256:c42715fe7f98e89c6ef19a68d7d64dd698eba44ff5fe936a2b34dc2ac65f8f99"}, + {file = "kilroy_ws_client_py_sdk-0.4.3-py3-none-any.whl", hash = "sha256:4005f4f1abb9eba7597353f95cf8e7ed84ac5de17ba3f4fc2715cb5270c36091"}, +] +kilroy-ws-py-shared = [ + {file = "kilroy-ws-py-shared-0.2.0.tar.gz", hash = "sha256:7517f4beb3586761a839d375943811128c4014544141e647a7df87607f095627"}, + {file = "kilroy_ws_py_shared-0.2.0-py3-none-any.whl", hash = "sha256:2cf2a8592a8a3b6a5fcb1c9b669fea1e3dec8d1f949ea460371f578d2c0e6dd8"}, ] packaging = [ {file = "packaging-21.3-py3-none-any.whl", hash = "sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522"}, diff --git a/kilroy_module_client_py_sdk/pyproject.toml b/kilroy_module_client_py_sdk/pyproject.toml index 30cefad..832e7e8 100644 --- a/kilroy_module_client_py_sdk/pyproject.toml +++ b/kilroy_module_client_py_sdk/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "kilroy-module-client-py-sdk" -version = "0.3.1" +version = "0.4.0" description = "SDK for kilroy module clients in Python 🧰" readme = "README.md" authors = ["kilroy "] @@ -11,9 +11,8 @@ documentation = "https://kilroybot.github.io/kilroy-module-client-py-sdk" [tool.poetry.dependencies] python = "^3.9" -kilroy-ws-client-py-sdk = "^0.4" -pydantic = "^1.9" -jsonschema = "^4.7" +kilroy-ws-client-py-sdk = "~0.4" +kilroy-module-py-shared = "~0.2" # dev diff --git a/kilroy_module_client_py_sdk/src/kilroy_module_client_py_sdk/__init__.py b/kilroy_module_client_py_sdk/src/kilroy_module_client_py_sdk/__init__.py index e9753e3..2c73aea 100644 --- a/kilroy_module_client_py_sdk/src/kilroy_module_client_py_sdk/__init__.py +++ b/kilroy_module_client_py_sdk/src/kilroy_module_client_py_sdk/__init__.py @@ -1,5 +1,5 @@ from kilroy_module_client_py_sdk.client import ModuleClient -from kilroy_module_client_py_sdk.models import ( +from kilroy_module_py_shared import ( Config, ConfigNotification, ConfigSchema, diff --git a/kilroy_module_client_py_sdk/src/kilroy_module_client_py_sdk/client.py b/kilroy_module_client_py_sdk/src/kilroy_module_client_py_sdk/client.py index c0c90c5..f7cd949 100644 --- a/kilroy_module_client_py_sdk/src/kilroy_module_client_py_sdk/client.py +++ b/kilroy_module_client_py_sdk/src/kilroy_module_client_py_sdk/client.py @@ -1,11 +1,7 @@ import json from typing import AsyncIterable, Iterable, Type, TypeVar, Union -from kilroy_ws_client_py_sdk import Client, JSON -from kilroy_ws_client_py_sdk.utils import asyncify -from pydantic import BaseModel - -from kilroy_module_client_py_sdk.models import ( +from kilroy_module_py_shared import ( Config, ConfigNotification, ConfigSchema, @@ -25,6 +21,9 @@ StepReply, StepRequest, ) +from kilroy_ws_client_py_sdk import Client, JSON +from kilroy_ws_py_shared import asyncify +from pydantic import BaseModel M = TypeVar("M", bound=BaseModel) diff --git a/kilroy_module_client_py_sdk/src/kilroy_module_client_py_sdk/models.py b/kilroy_module_client_py_sdk/src/kilroy_module_client_py_sdk/models.py deleted file mode 100644 index 6ce0575..0000000 --- a/kilroy_module_client_py_sdk/src/kilroy_module_client_py_sdk/models.py +++ /dev/null @@ -1,185 +0,0 @@ -from abc import ABC -from datetime import datetime -from enum import Enum -from typing import Annotated, Dict, List, Literal, Union -from uuid import UUID - -from humps import camelize -from jsonschema.exceptions import SchemaError -from jsonschema.validators import Draft202012Validator -from kilroy_ws_client_py_sdk import JSON -from pydantic import BaseModel, Field - - -class JSONSchema(dict): - @classmethod - def __get_validators__(cls): - yield cls.validate - - @classmethod - def validate(cls, schema: JSON) -> JSON: - try: - Draft202012Validator.check_schema(schema) - except SchemaError as e: - raise ValueError( - "Schema is not a valid JSON Schema 2020-12." - ) from e - if "type" not in schema: - raise ValueError("Schema should have a type field.") - elif schema["type"] != "object": - raise ValueError("Only object types are allowed.") - return schema - - -class BaseModuleModel(BaseModel, ABC): - def json(self, *args, by_alias: bool = True, **kwargs) -> str: - return super().json(*args, by_alias=by_alias, **kwargs) - - class Config: - allow_population_by_field_name = True - alias_generator = camelize - - -class PostSchema(BaseModuleModel): - post_schema: JSONSchema - - -class StatusEnum(str, Enum): - loading = "loading" - ready = "ready" - - -class Status(BaseModuleModel): - status: StatusEnum - - -class StatusNotification(BaseModuleModel): - old: Status - new: Status - - -class Config(BaseModuleModel): - config: JSON - - -class ConfigSchema(BaseModuleModel): - config_schema: JSONSchema - ui_schema: JSON = {} - - -class ConfigNotification(BaseModuleModel): - old: Config - new: Config - - -class ConfigSetRequest(BaseModuleModel): - set: Config - - -class ConfigSetReply(BaseModuleModel): - old: Config - new: Config - - -class GenerateRequest(BaseModuleModel): - number_of_posts: int - - -class GenerateReply(BaseModuleModel): - post_number: int - post_id: UUID - post: JSON - - -class FitPostsRequest(BaseModuleModel): - post_number: int - post: JSON - - -class FitPostsReply(BaseModuleModel): - success: Literal[True] - - -class PostScore(BaseModuleModel): - post_id: UUID - score: float - - -class FitScoresRequest(BaseModuleModel): - scores: List[PostScore] - - -class FitScoresReply(BaseModuleModel): - success: Literal[True] - - -class StepRequest(BaseModuleModel): - pass - - -class StepReply(BaseModuleModel): - success: Literal[True] - - -class MetricTypeEnum(str, Enum): - series = "series" - timeseries = "timeseries" - - -class BaseMetricInfo(BaseModuleModel): - label: str - - -class BaseSeriesMetricInfo(BaseMetricInfo): - step_label: str - value_label: str - - -class SeriesMetricInfo(BaseSeriesMetricInfo): - type: Literal[MetricTypeEnum.series] = MetricTypeEnum.series - step_type: Literal["int", "float"] - value_type: Literal["int", "float"] - - -class TimeseriesMetricInfo(BaseSeriesMetricInfo): - type: Literal[MetricTypeEnum.timeseries] = MetricTypeEnum.timeseries - value_type: Literal["int", "float"] - - -MetricInfo = Annotated[ - Union[ - SeriesMetricInfo, - TimeseriesMetricInfo, - ], - Field(discriminator="type"), -] - - -class MetricsInfo(BaseModuleModel): - metrics: Dict[str, MetricInfo] - - -class SeriesMetricNotificationData(BaseModuleModel): - type: Literal[MetricTypeEnum.series] = MetricTypeEnum.series - step: float - value: float - - -class TimeseriesMetricNotificationData(BaseModuleModel): - type: Literal[MetricTypeEnum.timeseries] = MetricTypeEnum.timeseries - step: datetime = Field(default_factory=datetime.utcnow) - value: float - - -MetricNotificationData = Annotated[ - Union[ - SeriesMetricNotificationData, - TimeseriesMetricNotificationData, - ], - Field(discriminator="type"), -] - - -class MetricsNotification(BaseModuleModel): - name: str - data: MetricNotificationData diff --git a/pyproject.toml b/pyproject.toml index f4c3487..951203c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ [tool.poetry] name = "kilroy-module-client-py-sdk" -version = "0.3.1" +version = "0.4.0" description = "SDK for kilroy module clients in Python 🧰" readme = "kilroy_module_client_py_sdk/README.md" authors = ["kilroy "] @@ -15,9 +15,8 @@ packages = [{ include = "kilroy-module-client-py-sdk", from = "kilroy_module_cli [tool.poetry.dependencies] python = "^3.9" -kilroy-ws-client-py-sdk = "^0.4" -pydantic = "^1.9" -jsonschema = "^4.7" +kilroy-ws-client-py-sdk = "~0.4" +kilroy-module-py-shared = "~0.2" # dev