File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ()
Original file line number Diff line number Diff 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+
405437def test_wrap_app_allows_resolver_with_container_kind ():
406438 from fal .app import wrap_app
407439
You can’t perform that action at this time.
0 commit comments