Skip to content

Commit

Permalink
fix: loading service from an absolute path (#4415)
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming authored Jan 18, 2024
1 parent 84edd85 commit fc95886
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/_bentoml_sdk/service/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import math
import os
import pathlib
import sys
import typing as t
from functools import lru_cache
Expand Down Expand Up @@ -168,6 +169,18 @@ def import_string(self) -> str:
if import_module == "__main__":
if hasattr(sys.modules["__main__"], "__file__"):
import_module = sys.modules["__main__"].__file__
assert isinstance(import_module, str)
try:
import_module_path = pathlib.Path(import_module).relative_to(
pathlib.Path(self.working_dir)
)
except ValueError:
raise BentoMLException(
"Failed to get service import origin, service object defined in __main__ module is not supported"
)
import_module = str(import_module_path.with_suffix("")).replace(
os.path.sep, "."
)
else:
raise BentoMLException(
"Failed to get service import origin, service object defined interactively in console or notebook is not supported"
Expand Down

0 comments on commit fc95886

Please sign in to comment.