Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
Add requirements of serializers to server (#516)
Browse files Browse the repository at this point in the history
relates to #509
  • Loading branch information
mike0sv authored Dec 6, 2022
1 parent 8092b17 commit ff340ad
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions mlem/contrib/docker/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,9 @@ def run_container(
"The container died unexpectedly.", log
)
else:
state.container_id = None
state.container_name = None
self.update_state(state)
# Can't get logs from removed container
raise DeploymentError(
"The container died unexpectedly. Try to run the container "
Expand Down
8 changes: 7 additions & 1 deletion mlem/contrib/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
from starlette.responses import JSONResponse, Response, StreamingResponse

from mlem.core.data_type import DataTypeSerializer
from mlem.core.requirements import LibRequirementsMixin
from mlem.core.requirements import LibRequirementsMixin, Requirements
from mlem.runtime.interface import (
Interface,
InterfaceArgument,
InterfaceMethod,
)
from mlem.runtime.server import Server
from mlem.ui import EMOJI_NAILS, echo
from mlem.utils.module import get_object_requirements

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -203,6 +204,11 @@ def serve(self, interface: Interface):
echo(f"Checkout openapi docs at <http://{self.host}:{self.port}/docs>")
uvicorn.run(app, host=self.host, port=self.port)

def get_requirements(self) -> Requirements:
return super().get_requirements() + get_object_requirements(
[self.request_serializer, self.response_serializer, self.methods]
)


class _SpooledFileIOWrapper:
"""https://stackoverflow.com/questions/47160211/why-doesnt-tempfile-spooledtemporaryfile-implement-readable-writable-seekable
Expand Down
8 changes: 8 additions & 0 deletions mlem/core/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import shlex
import sys
from collections import defaultdict
from inspect import isabstract
from typing import (
Expand Down Expand Up @@ -43,6 +44,7 @@ def load_impl_ext(
...


# pylint: disable=too-many-branches
def load_impl_ext(
abs_name: str, type_name: Optional[str], raise_on_missing: bool = True
) -> Optional[Type["MlemABC"]]:
Expand All @@ -62,12 +64,18 @@ def load_impl_ext(

if type_name is not None and "." in type_name:
try:
# this is needed because if run from cli curdir is not checked for
# modules to import
sys.path.append(".")

obj = import_string(type_name)
if not issubclass(obj, MlemABC):
raise ValueError(f"{obj} is not subclass of MlemABC")
return obj
except ImportError:
pass
finally:
sys.path.remove(".")

eps = load_entrypoints()
for ep in eps.values():
Expand Down

0 comments on commit ff340ad

Please sign in to comment.