Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: loading service from an absolute path #4415

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading