diff --git a/projects/fal/src/fal/cli/_utils.py b/projects/fal/src/fal/cli/_utils.py index 71bcdcd4..7a5a51e8 100644 --- a/projects/fal/src/fal/cli/_utils.py +++ b/projects/fal/src/fal/cli/_utils.py @@ -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 diff --git a/projects/fal/src/fal/cli/deploy.py b/projects/fal/src/fal/cli/deploy.py index 3a71c70e..e28e1ad2 100644 --- a/projects/fal/src/fal/cli/deploy.py +++ b/projects/fal/src/fal/cli/deploy.py @@ -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 @@ -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: @@ -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 @@ -148,6 +151,7 @@ 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), @@ -155,6 +159,7 @@ def _deploy(args): args, app_auth, app_deployment_strategy, + app_no_scale, ) diff --git a/projects/fal/src/fal/cli/run.py b/projects/fal/src/fal/cli/run.py index 6fc36048..e3fa8b61 100644 --- a/projects/fal/src/fal/cli/run.py +++ b/projects/fal/src/fal/cli/run.py @@ -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 diff --git a/projects/fal/tests/cli/test_deploy.py b/projects/fal/tests/cli/test_deploy.py index 376e8eba..866894a9 100644 --- a/projects/fal/tests/cli/test_deploy.py +++ b/projects/fal/tests/cli/test_deploy.py @@ -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() @@ -43,6 +44,8 @@ def mock_args( args.auth = auth args.strategy = strategy + args.no_scale = no_scale + return args @@ -68,6 +71,7 @@ def test_deploy_with_toml_success( args, "shared", "rolling", + False, ) @@ -93,6 +97,7 @@ def test_deploy_with_toml_no_auth( args, "private", "recreate", + False, ) @@ -186,6 +191,7 @@ def test_deploy_with_toml_deployment_strategy( args, "shared", "rolling", + False, ) @@ -209,6 +215,7 @@ def test_deploy_with_toml_default_deployment_strategy( args, "private", "recreate", + False, ) @@ -230,6 +237,7 @@ def test_deploy_with_cli_auth( args, "shared", None, + False, ) @@ -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, )