Skip to content

Commit 1b02251

Browse files
committed
ensure relative to /data
1 parent c442793 commit 1b02251

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

projects/fal/src/fal/app.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,10 @@ async def lifespan(self, app: fastapi.FastAPI):
811811
sys.path.insert(0, "")
812812

813813
for directory in self.host_kwargs.get("data_dirs", []):
814-
warm_dir(directory)
814+
warm_path = Path(directory).expanduser()
815+
if not warm_path.is_absolute():
816+
warm_path = Path("/data") / warm_path
817+
warm_dir(os.fspath(warm_path))
815818

816819
_print_python_packages()
817820
setup_started_at = time.perf_counter()

projects/fal/tests/unit/test_app.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,38 @@ def setup(self):
402402
]
403403

404404

405+
@pytest.mark.asyncio
406+
async def test_app_lifespan_resolves_relative_data_dirs_from_data(
407+
isolate_agent_env, monkeypatch: pytest.MonkeyPatch
408+
):
409+
import fal.app as fal_app_module
410+
411+
calls: list[tuple[str, str | None]] = []
412+
413+
monkeypatch.setattr(
414+
fal_app_module,
415+
"warm_dir",
416+
lambda directory: calls.append(("warm", str(directory))),
417+
)
418+
419+
class WarmedApp(App):
420+
data_dirs = ["models", "nested/tokenizer"]
421+
422+
def setup(self):
423+
calls.append(("setup", None))
424+
425+
app = WarmedApp()
426+
427+
async with app.lifespan(FastAPI()):
428+
pass
429+
430+
assert calls == [
431+
("warm", "/data/models"),
432+
("warm", "/data/nested/tokenizer"),
433+
("setup", None),
434+
]
435+
436+
405437
def test_wrap_app_allows_resolver_with_container_kind():
406438
from fal.app import wrap_app
407439

0 commit comments

Comments
 (0)