Skip to content

Commit

Permalink
fix(cli): expands working_dir with default path (#3127)
Browse files Browse the repository at this point in the history
User should be able to do `bentoml serve my/bento` without having to pass in `--working-dir`

Co-authored-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com>
  • Loading branch information
qu8n and aarnphm committed Oct 25, 2022
1 parent 62a100c commit 5b7bcaa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
16 changes: 13 additions & 3 deletions src/bentoml_cli/serve.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import os
import sys
import logging

Expand Down Expand Up @@ -69,7 +70,7 @@ def add_serve_command(cli: click.Group) -> None:
"--working-dir",
type=click.Path(),
help="When loading from source code, specify the directory to find the Service instance",
default=".",
default=None,
show_default=True,
)
@click.option(
Expand Down Expand Up @@ -172,7 +173,11 @@ def serve( # type: ignore (unused warning)
- all model store changes will also trigger a restart (new model saved or existing model removed)
"""
configure_server_logging()

if working_dir is None:
if os.path.isdir(os.path.expanduser(bento)):
working_dir = os.path.expanduser(bento)
else:
working_dir = "."
if sys.path[0] != working_dir:
sys.path.insert(0, working_dir)

Expand Down Expand Up @@ -273,7 +278,7 @@ def serve( # type: ignore (unused warning)
"--working-dir",
type=click.Path(),
help="When loading from source code, specify the directory to find the Service instance",
default=".",
default=None,
show_default=True,
)
@click.option(
Expand Down Expand Up @@ -369,6 +374,11 @@ def serve_grpc( # type: ignore (unused warning)
- all model store changes will also trigger a restart (new model saved or existing model removed)
"""
configure_server_logging()
if working_dir is None:
if os.path.isdir(os.path.expanduser(bento)):
working_dir = os.path.expanduser(bento)
else:
working_dir = "."
if production:
if reload:
logger.warning(
Expand Down
22 changes: 19 additions & 3 deletions src/bentoml_cli/start.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import os
import sys
import json
import logging
Expand Down Expand Up @@ -71,7 +72,7 @@ def add_start_command(cli: click.Group) -> None:
"--working-dir",
type=click.Path(),
help="When loading from source code, specify the directory to find the Service instance",
default=".",
default=None,
show_default=True,
)
@click.option(
Expand Down Expand Up @@ -138,6 +139,11 @@ def start_http_server( # type: ignore (unused warning)
"""
Start a HTTP API server standalone. This will be used inside Yatai.
"""
if working_dir is None:
if os.path.isdir(os.path.expanduser(bento)):
working_dir = os.path.expanduser(bento)
else:
working_dir = "."
if sys.path[0] != working_dir:
sys.path.insert(0, working_dir)

Expand Down Expand Up @@ -218,7 +224,7 @@ def start_http_server( # type: ignore (unused warning)
"--working-dir",
type=click.Path(),
help="When loading from source code, specify the directory to find the Service instance",
default=".",
default=None,
show_default=True,
)
@add_experimental_docstring
Expand All @@ -234,6 +240,11 @@ def start_runner_server( # type: ignore (unused warning)
"""
Start Runner server standalone. This will be used inside Yatai.
"""
if working_dir is None:
if os.path.isdir(os.path.expanduser(bento)):
working_dir = os.path.expanduser(bento)
else:
working_dir = "."
if sys.path[0] != working_dir:
sys.path.insert(0, working_dir)

Expand Down Expand Up @@ -289,7 +300,7 @@ def start_runner_server( # type: ignore (unused warning)
"--working-dir",
type=click.Path(),
help="When loading from source code, specify the directory to find the Service instance",
default=".",
default=None,
show_default=True,
)
@click.option(
Expand Down Expand Up @@ -356,6 +367,11 @@ def start_grpc_server( # type: ignore (unused warning)
"""
Start a gRPC API server standalone. This will be used inside Yatai.
"""
if working_dir is None:
if os.path.isdir(os.path.expanduser(bento)):
working_dir = os.path.expanduser(bento)
else:
working_dir = "."
if sys.path[0] != working_dir:
sys.path.insert(0, working_dir)

Expand Down

0 comments on commit 5b7bcaa

Please sign in to comment.