Skip to content

Commit

Permalink
feat(fal-file): add no scale argument (#362)
Browse files Browse the repository at this point in the history
* feat(fal-file): add no scale

* feat(fal-file-no-scale): add tests

* fix: test

---------

Co-authored-by: Matteo Ferrando <[email protected]>
  • Loading branch information
badayvedat and chamini2 authored Jan 7, 2025
1 parent 1571b28 commit 8b6740c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
3 changes: 2 additions & 1 deletion projects/fal/src/fal/cli/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ def get_app_data_from_toml(app_name):

app_auth = app_data.get("auth", "private")
app_deployment_strategy = app_data.get("deployment_strategy", "recreate")
app_no_scale = app_data.get("no_scale", False)

return app_ref, app_auth, app_deployment_strategy
return app_ref, app_auth, app_deployment_strategy, app_no_scale
9 changes: 7 additions & 2 deletions projects/fal/src/fal/cli/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def _deploy_from_reference(
args,
auth: Optional[Literal["public", "shared", "private"]] = None,
deployment_strategy: Optional[Literal["recreate", "rolling"]] = None,
no_scale: bool = False,
):
from fal.api import FalServerlessError, FalServerlessHost
from fal.utils import load_function_from
Expand Down Expand Up @@ -106,7 +107,7 @@ def _deploy_from_reference(
application_auth_mode=app_auth,
metadata=isolated_function.options.host.get("metadata", {}),
deployment_strategy=deployment_strategy,
scale=not args.no_scale,
scale=not no_scale,
)

if app_id:
Expand Down Expand Up @@ -139,7 +140,9 @@ def _deploy(args):
raise ValueError("Cannot use --app-name or --auth with app name reference.")

app_name = args.app_ref[0]
app_ref, app_auth, app_deployment_strategy = get_app_data_from_toml(app_name)
app_ref, app_auth, app_deployment_strategy, app_no_scale = (
get_app_data_from_toml(app_name)
)
file_path, func_name = RefAction.split_ref(app_ref)

# path/to/myfile.py::MyApp
Expand All @@ -148,13 +151,15 @@ def _deploy(args):
app_name = args.app_name
app_auth = args.auth
app_deployment_strategy = args.strategy
app_no_scale = args.no_scale

_deploy_from_reference(
(file_path, func_name),
app_name,
args,
app_auth,
app_deployment_strategy,
app_no_scale,
)


Expand Down
2 changes: 1 addition & 1 deletion projects/fal/src/fal/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def _run(args):

if is_app_name(args.func_ref):
app_name = args.func_ref[0]
app_ref, _, _ = get_app_data_from_toml(app_name)
app_ref, *_ = get_app_data_from_toml(app_name)
file_path, func_name = RefAction.split_ref(app_ref)
else:
file_path, func_name = args.func_ref
Expand Down
53 changes: 53 additions & 0 deletions projects/fal/tests/cli/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def mock_args(
app_name: Optional[str] = None,
auth: Optional[str] = None,
strategy: Optional[str] = None,
no_scale: bool = False,
):
args = MagicMock()

Expand All @@ -43,6 +44,8 @@ def mock_args(
args.auth = auth
args.strategy = strategy

args.no_scale = no_scale

return args


Expand All @@ -68,6 +71,7 @@ def test_deploy_with_toml_success(
args,
"shared",
"rolling",
False,
)


Expand All @@ -93,6 +97,7 @@ def test_deploy_with_toml_no_auth(
args,
"private",
"recreate",
False,
)


Expand Down Expand Up @@ -186,6 +191,7 @@ def test_deploy_with_toml_deployment_strategy(
args,
"shared",
"rolling",
False,
)


Expand All @@ -209,6 +215,7 @@ def test_deploy_with_toml_default_deployment_strategy(
args,
"private",
"recreate",
False,
)


Expand All @@ -230,6 +237,7 @@ def test_deploy_with_cli_auth(
args,
"shared",
None,
False,
)


Expand All @@ -251,4 +259,49 @@ def test_deploy_with_cli_deployment_strategy(
args,
None,
"rolling",
False,
)


@patch("fal.cli._utils.find_pyproject_toml", return_value="pyproject.toml")
@patch("fal.cli._utils.parse_pyproject_toml")
@patch("fal.cli.deploy._deploy_from_reference")
def test_deploy_with_cli_no_scale(
mock_deploy_ref, mock_parse_toml, mock_find_toml, mock_parse_pyproject_toml
):
mock_parse_toml.return_value = mock_parse_pyproject_toml

args = mock_args(app_ref=("src/my_app/inference.py", "MyApp"), no_scale=True)

_deploy(args)

mock_deploy_ref.assert_called_once_with(
("src/my_app/inference.py", "MyApp"),
None,
args,
None,
None,
True,
)


@patch("fal.cli._utils.find_pyproject_toml", return_value="pyproject.toml")
@patch("fal.cli._utils.parse_pyproject_toml")
@patch("fal.cli.deploy._deploy_from_reference")
def test_deploy_with_cli_scale(
mock_deploy_ref, mock_parse_toml, mock_find_toml, mock_parse_pyproject_toml
):
mock_parse_toml.return_value = mock_parse_pyproject_toml

args = mock_args(app_ref=("src/my_app/inference.py", "MyApp"))

_deploy(args)

mock_deploy_ref.assert_called_once_with(
("src/my_app/inference.py", "MyApp"),
None,
args,
None,
None,
False,
)

0 comments on commit 8b6740c

Please sign in to comment.