From 1593accae9e28f609cccfa5cb708e76f2fdd3498 Mon Sep 17 00:00:00 2001 From: Adrian Gonzalez-Martin Date: Fri, 14 Apr 2023 10:49:11 +0200 Subject: [PATCH] Move OpenAPI schemas into Python package (#1095) Co-authored-by: adriangonz --- Dockerfile | 2 ++ MANIFEST.in | 2 +- docs/conf.py | 2 +- mlserver/rest/openapi/__init__.py | 3 +++ mlserver/rest/openapi/dataplane.json | 1 + mlserver/rest/openapi/model_repository.json | 1 + mlserver/rest/{openapi.py => openapi/schema.py} | 4 +--- mlserver/version.py | 2 +- runtimes/alibi-detect/mlserver_alibi_detect/version.py | 2 +- runtimes/alibi-explain/mlserver_alibi_explain/version.py | 2 +- runtimes/huggingface/mlserver_huggingface/version.py | 2 +- runtimes/lightgbm/mlserver_lightgbm/version.py | 2 +- runtimes/mlflow/mlserver_mlflow/version.py | 2 +- runtimes/mllib/mlserver_mllib/version.py | 2 +- runtimes/sklearn/mlserver_sklearn/version.py | 2 +- runtimes/xgboost/mlserver_xgboost/version.py | 2 +- tests/rest/openapi/__init__.py | 0 tests/rest/{test_openapi.py => openapi/test_schema.py} | 2 +- 18 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 mlserver/rest/openapi/__init__.py create mode 120000 mlserver/rest/openapi/dataplane.json create mode 120000 mlserver/rest/openapi/model_repository.json rename mlserver/rest/{openapi.py => openapi/schema.py} (94%) create mode 100644 tests/rest/openapi/__init__.py rename tests/rest/{test_openapi.py => openapi/test_schema.py} (95%) diff --git a/Dockerfile b/Dockerfile index 11e503434..2737de522 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,9 +3,11 @@ SHELL ["/bin/bash", "-l", "-c"] COPY ./hack/build-wheels.sh ./hack/build-wheels.sh COPY ./mlserver ./mlserver +COPY ./openapi ./openapi COPY ./runtimes ./runtimes COPY \ setup.py \ + MANIFEST.in \ README.md \ . diff --git a/MANIFEST.in b/MANIFEST.in index c8964f1dc..80bcc2ff9 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1 @@ -include openapi/*.json +include mlserver/rest/openapi/*.json diff --git a/docs/conf.py b/docs/conf.py index 8e6b014e3..62bef6ccf 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -24,7 +24,7 @@ author = "Seldon Technologies" # The full version, including alpha/beta/rc tags -release = "1.3.0.dev14" +release = "1.3.0.dev15" # -- General configuration --------------------------------------------------- diff --git a/mlserver/rest/openapi/__init__.py b/mlserver/rest/openapi/__init__.py new file mode 100644 index 000000000..92cb17843 --- /dev/null +++ b/mlserver/rest/openapi/__init__.py @@ -0,0 +1,3 @@ +from .schema import get_openapi_schema, get_model_schema, get_model_schema_uri + +__all__ = ["get_openapi_schema", "get_model_schema", "get_model_schema_uri"] diff --git a/mlserver/rest/openapi/dataplane.json b/mlserver/rest/openapi/dataplane.json new file mode 120000 index 000000000..812215f4d --- /dev/null +++ b/mlserver/rest/openapi/dataplane.json @@ -0,0 +1 @@ +../../../openapi/dataplane.json \ No newline at end of file diff --git a/mlserver/rest/openapi/model_repository.json b/mlserver/rest/openapi/model_repository.json new file mode 120000 index 000000000..47a818e36 --- /dev/null +++ b/mlserver/rest/openapi/model_repository.json @@ -0,0 +1 @@ +../../../openapi/model_repository.json \ No newline at end of file diff --git a/mlserver/rest/openapi.py b/mlserver/rest/openapi/schema.py similarity index 94% rename from mlserver/rest/openapi.py rename to mlserver/rest/openapi/schema.py index ed85b3dec..ec04abbce 100644 --- a/mlserver/rest/openapi.py +++ b/mlserver/rest/openapi/schema.py @@ -4,15 +4,13 @@ from typing import Optional, Tuple from importlib_resources import files -OPENAPI_SCHEMA_RELATIVE_PATH = "../openapi/dataplane.json" MODEL_NAME_PARAMETER = "model_name" MODEL_VERSION_PARAMETER = "model_version" @lru_cache def get_openapi_schema() -> dict: - mlserver_package = __package__.split(".")[0] - openapi_schema_path = files(mlserver_package).joinpath(OPENAPI_SCHEMA_RELATIVE_PATH) + openapi_schema_path = files(__package__).joinpath("dataplane.json") return orjson.loads(openapi_schema_path.read_bytes()) diff --git a/mlserver/version.py b/mlserver/version.py index c1cd20fd5..e7750379c 100644 --- a/mlserver/version.py +++ b/mlserver/version.py @@ -1 +1 @@ -__version__ = "1.3.0.dev14" +__version__ = "1.3.0.dev15" diff --git a/runtimes/alibi-detect/mlserver_alibi_detect/version.py b/runtimes/alibi-detect/mlserver_alibi_detect/version.py index c1cd20fd5..e7750379c 100644 --- a/runtimes/alibi-detect/mlserver_alibi_detect/version.py +++ b/runtimes/alibi-detect/mlserver_alibi_detect/version.py @@ -1 +1 @@ -__version__ = "1.3.0.dev14" +__version__ = "1.3.0.dev15" diff --git a/runtimes/alibi-explain/mlserver_alibi_explain/version.py b/runtimes/alibi-explain/mlserver_alibi_explain/version.py index c1cd20fd5..e7750379c 100644 --- a/runtimes/alibi-explain/mlserver_alibi_explain/version.py +++ b/runtimes/alibi-explain/mlserver_alibi_explain/version.py @@ -1 +1 @@ -__version__ = "1.3.0.dev14" +__version__ = "1.3.0.dev15" diff --git a/runtimes/huggingface/mlserver_huggingface/version.py b/runtimes/huggingface/mlserver_huggingface/version.py index c1cd20fd5..e7750379c 100644 --- a/runtimes/huggingface/mlserver_huggingface/version.py +++ b/runtimes/huggingface/mlserver_huggingface/version.py @@ -1 +1 @@ -__version__ = "1.3.0.dev14" +__version__ = "1.3.0.dev15" diff --git a/runtimes/lightgbm/mlserver_lightgbm/version.py b/runtimes/lightgbm/mlserver_lightgbm/version.py index c1cd20fd5..e7750379c 100644 --- a/runtimes/lightgbm/mlserver_lightgbm/version.py +++ b/runtimes/lightgbm/mlserver_lightgbm/version.py @@ -1 +1 @@ -__version__ = "1.3.0.dev14" +__version__ = "1.3.0.dev15" diff --git a/runtimes/mlflow/mlserver_mlflow/version.py b/runtimes/mlflow/mlserver_mlflow/version.py index c1cd20fd5..e7750379c 100644 --- a/runtimes/mlflow/mlserver_mlflow/version.py +++ b/runtimes/mlflow/mlserver_mlflow/version.py @@ -1 +1 @@ -__version__ = "1.3.0.dev14" +__version__ = "1.3.0.dev15" diff --git a/runtimes/mllib/mlserver_mllib/version.py b/runtimes/mllib/mlserver_mllib/version.py index c1cd20fd5..e7750379c 100644 --- a/runtimes/mllib/mlserver_mllib/version.py +++ b/runtimes/mllib/mlserver_mllib/version.py @@ -1 +1 @@ -__version__ = "1.3.0.dev14" +__version__ = "1.3.0.dev15" diff --git a/runtimes/sklearn/mlserver_sklearn/version.py b/runtimes/sklearn/mlserver_sklearn/version.py index c1cd20fd5..e7750379c 100644 --- a/runtimes/sklearn/mlserver_sklearn/version.py +++ b/runtimes/sklearn/mlserver_sklearn/version.py @@ -1 +1 @@ -__version__ = "1.3.0.dev14" +__version__ = "1.3.0.dev15" diff --git a/runtimes/xgboost/mlserver_xgboost/version.py b/runtimes/xgboost/mlserver_xgboost/version.py index c1cd20fd5..e7750379c 100644 --- a/runtimes/xgboost/mlserver_xgboost/version.py +++ b/runtimes/xgboost/mlserver_xgboost/version.py @@ -1 +1 @@ -__version__ = "1.3.0.dev14" +__version__ = "1.3.0.dev15" diff --git a/tests/rest/openapi/__init__.py b/tests/rest/openapi/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/rest/test_openapi.py b/tests/rest/openapi/test_schema.py similarity index 95% rename from tests/rest/test_openapi.py rename to tests/rest/openapi/test_schema.py index 8d2d2c960..02a8dbd1a 100644 --- a/tests/rest/test_openapi.py +++ b/tests/rest/openapi/test_schema.py @@ -2,7 +2,7 @@ from typing import Optional -from mlserver.rest.openapi import ( +from mlserver.rest.openapi.schema import ( get_openapi_schema, get_model_schema, MODEL_VERSION_PARAMETER,