Skip to content

Commit

Permalink
fix: loading service from an absolute path
Browse files Browse the repository at this point in the history
Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming committed Jan 18, 2024
1 parent 09343fc commit efd34b7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
16 changes: 10 additions & 6 deletions src/_bentoml_impl/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def normalize_identifier(
- my_service:a7ab819 # bentoml serve built bentos
- package.py:Service
- package.py:Service.dependency
- /path/to/package.py:Service
- .
"""
if working_dir is not None:
Expand Down Expand Up @@ -70,20 +71,23 @@ def normalize_identifier(

# TODO(jiang): bento store configs are sdk configs, should be moved to sdk in the future
from bentoml._internal.configuration.containers import BentoMLContainer
from bentoml.exceptions import NotFound
from bentoml.exceptions import BentoMLException

bento_store = BentoMLContainer.bento_store.get()

try:
bento = bento_store.get(service_identifier)
except NotFound:
except BentoMLException:
# a python import str
return normalize_package(service_identifier), pathlib.Path(
working_dir if working_dir is not None else "."
)
module_spec, _, service_path = service_identifier.partition(":")
module_path = pathlib.Path(module_spec)
if not module_path.suffix:
return service_identifier, pathlib.Path(working_dir or ".")
if not module_path.is_absolute():
module_path = pathlib.Path(working_dir or ".").joinpath(module_path)
return f"{module_path.stem}:{service_path}", module_path.parent
else:
# a built bento in bento store

yaml_path = pathlib.Path(bento.path).joinpath(BENTO_YAML_FILENAME)
with open(yaml_path, "r") as f:
bento_yaml = yaml.safe_load(f)
Expand Down
2 changes: 1 addition & 1 deletion src/_bentoml_impl/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ async def handle_validation_error(self, req: Request, exc: Exception) -> Respons
assert isinstance(exc, pydantic.ValidationError)

data = {
"error": f"{exc.error_count} validation error for {exc.title}",
"error": f"{exc.error_count()} validation error for {exc.title}",
"detail": exc.errors(),
}
return JSONResponse(data, status_code=400)
Expand Down
7 changes: 1 addition & 6 deletions src/_bentoml_impl/server/serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import json
import logging
import os
import pathlib
import platform
import shutil
import socket
Expand Down Expand Up @@ -98,7 +97,6 @@ def create_dependency_watcher(
uds_path: str | None,
port_stack: contextlib.ExitStack,
backlog: int,
dependency_map: dict[str, str],
scheduler: ResourceAllocator,
working_dir: str | None = None,
) -> tuple[Watcher, CircusSocket, str]:
Expand Down Expand Up @@ -169,12 +167,10 @@ def serve_http(
prometheus_dir = ensure_prometheus_dir()
if isinstance(bento_identifier, Service):
svc = bento_identifier
bento_identifier = svc.import_string
bento_identifier, bento_path = normalize_identifier(svc.import_string)
assert (
working_dir is None
), "working_dir should not be set when passing a service in process"
# use cwd
bento_path = pathlib.Path(".")
else:
bento_identifier, bento_path = normalize_identifier(
bento_identifier, working_dir
Expand Down Expand Up @@ -209,7 +205,6 @@ def serve_http(
uds_path,
stack,
backlog,
dependency_map,
allocator,
str(bento_path.absolute()),
)
Expand Down

0 comments on commit efd34b7

Please sign in to comment.