Skip to content

Commit

Permalink
Update loader.py
Browse files Browse the repository at this point in the history
  • Loading branch information
parano committed Nov 9, 2023
1 parent b0ba2ab commit 21ab30e
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/bentoml/_internal/service/loader.py
Expand Up @@ -71,15 +71,15 @@ def recover_standalone_env_change():
os.chdir(prev_cwd)
BentoMLContainer.model_store.set(global_model_store)

try:
if working_dir is not None:
working_dir = os.path.realpath(os.path.expanduser(working_dir))
# Set cwd(current working directory) to the Bento's project directory,
# which allows user code to read files using relative path
os.chdir(working_dir)
else:
working_dir = os.getcwd()
if working_dir is not None:
working_dir = os.path.realpath(os.path.expanduser(working_dir))
# Set cwd(current working directory) to the Bento's project directory,
# which allows user code to read files using relative path
os.chdir(working_dir)
else:
working_dir = os.getcwd()

try:
sys.path.insert(0, working_dir)

if model_store is not global_model_store:
Expand Down Expand Up @@ -169,9 +169,8 @@ def recover_standalone_env_change():
object.__setattr__(instance, "_import_str", f"{module_name}:{attrs_str}")
return instance
except ImportServiceError:
if working_dir:
# Undo changes to sys.path
sys.path.remove(working_dir)
# Undo changes to sys.path
sys.path.remove(working_dir)

recover_standalone_env_change()
raise
Expand Down

0 comments on commit 21ab30e

Please sign in to comment.