WolfDavid commited on
Commit
e3ebc72
·
1 Parent(s): 6eeb816

fix(01-05): put src/ on sys.path so the Space can import the package

Browse files

Second deploy (6eeb816) built cleanly and then died at startup with
`ModuleNotFoundError: No module named 'japanese_avatar'`. A Space installs
requirements.txt and nothing else - this repository is never pip-installed there -
so the src/ layout package was invisible to `python app.py`. Locally the dev venv
has it installed as editable, which is why every test passed.

Bootstrapped in app.py rather than through a PYTHONPATH Space variable: an env var
would make a clean checkout silently unrunnable and would not travel with the repo.

Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -13,10 +13,22 @@ Python - which is what ``test_no_remount`` measures the avatar against.
13
 
14
  import html
15
  import os
 
 
16
 
17
  import gradio as gr
18
 
19
- from japanese_avatar.ui.avatar_component import StatusLine, VrmStage
 
 
 
 
 
 
 
 
 
 
20
 
21
  # Serves avatar/ straight off disk, bypassing the Gradio cache, which is how the
22
  # browser reaches avatar.js, stage.html and tutor.vrm. Deliberately one dedicated
 
13
 
14
  import html
15
  import os
16
+ import sys
17
+ from pathlib import Path
18
 
19
  import gradio as gr
20
 
21
+ # The Space runs `python app.py` with only requirements.txt installed - it never
22
+ # pip-installs this repository - so the src/ layout package is not on sys.path there and
23
+ # the import below raised ModuleNotFoundError on the first deploy (RUNTIME_ERROR on
24
+ # 6eeb816). Locally the dev venv has the project installed and this is a no-op. Doing it
25
+ # here rather than through a PYTHONPATH Space variable keeps the app runnable from a
26
+ # clean checkout with no platform configuration to lose.
27
+ _SRC = Path(__file__).resolve().parent / "src"
28
+ if str(_SRC) not in sys.path:
29
+ sys.path.insert(0, str(_SRC))
30
+
31
+ from japanese_avatar.ui.avatar_component import StatusLine, VrmStage # noqa: E402
32
 
33
  # Serves avatar/ straight off disk, bypassing the Gradio cache, which is how the
34
  # browser reaches avatar.js, stage.html and tutor.vrm. Deliberately one dedicated