Skip to content

Commit

Permalink
feat(fal-file): convert the app-ref to a path relative to the project…
Browse files Browse the repository at this point in the history
… root (#307)

* feat(fal-file): convert the app-ref to a path relative to the project root

* fix: tests
  • Loading branch information
badayvedat committed Sep 16, 2024
1 parent 6dd4b68 commit a862a5e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
6 changes: 5 additions & 1 deletion projects/fal/src/fal/cli/_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from fal.files import find_pyproject_toml, parse_pyproject_toml
from fal.files import find_project_root, find_pyproject_toml, parse_pyproject_toml


def is_app_name(app_ref: tuple[str, str | None]) -> bool:
Expand Down Expand Up @@ -29,6 +29,10 @@ def get_app_data_from_toml(app_name):
except KeyError:
raise ValueError(f"App {app_name} does not have a ref key in pyproject.toml")

# Convert the app_ref to a path relative to the project root
project_root, _ = find_project_root(None)
app_ref = str(project_root / app_ref)

app_auth = app_data.get("auth", "private")

return app_ref, app_auth
15 changes: 13 additions & 2 deletions projects/fal/tests/cli/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
from fal.cli.deploy import _deploy
from fal.cli.main import parse_args
from fal.files import find_project_root


def test_deploy():
Expand Down Expand Up @@ -53,9 +54,14 @@ def test_deploy_with_toml_success(

_deploy(args)

project_root, _ = find_project_root(None)

# Ensure the correct app is deployed
mock_deploy_ref.assert_called_once_with(
("src/my_app/inference.py", "MyApp"), "my-app", "shared", args
(f"{project_root / 'src/my_app/inference.py'}", "MyApp"),
"my-app",
"shared",
args,
)


Expand All @@ -72,9 +78,14 @@ def test_deploy_with_toml_no_auth(

_deploy(args)

project_root, _ = find_project_root(None)

# Since auth is not provided for "another-app", it should default to "private"
mock_deploy_ref.assert_called_once_with(
("src/another_app/inference.py", "AnotherApp"), "another-app", "private", args
(f"{project_root / 'src/another_app/inference.py'}", "AnotherApp"),
"another-app",
"private",
args,
)


Expand Down
7 changes: 5 additions & 2 deletions projects/fal/tests/cli/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest
from fal.cli.main import parse_args
from fal.cli.run import _run
from fal.files import find_project_root


def test_run():
Expand Down Expand Up @@ -60,9 +61,11 @@ def test_run_with_toml_success(

_run(args)

# Ensure the correct app is deployed
project_root, _ = find_project_root(None)

# Ensure the correct app is ran
mock_load_function_from.assert_called_once_with(
host, "src/my_app/inference.py", "MyApp"
host, f"{project_root / 'src/my_app/inference.py'}", "MyApp"
)


Expand Down

0 comments on commit a862a5e

Please sign in to comment.