File size: 1,600 Bytes
c4a8691 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | """
Where to find standards/ and engine/.
In the repository the backend sits beside them:
nawi-build/
backend/ <- here
standards/
engine/
On a Hugging Face Space everything is uploaded flat, so they sit inside:
/home/user/app/
app.py <- here
standards/
engine/
Both layouts are checked rather than assumed, so the same code runs in
either place with nothing to edit at deploy time.
"""
import os
import sys
HERE = os.path.dirname(os.path.abspath(__file__))
def _find(name: str) -> str:
"""Return the first existing candidate for a sibling or child directory."""
for candidate in (os.path.join(HERE, name), # flat (Space)
os.path.join(HERE, "..", name)): # beside (repo)
if os.path.isdir(candidate):
return os.path.abspath(candidate)
raise FileNotFoundError(
f"cannot find '{name}/'. It must sit either beside {HERE} "
f"(the repository layout) or inside it (the Space layout). "
f"Upload standards/ and engine/ alongside the backend files."
)
STANDARDS_DIR = _find("standards")
ENGINE_DIR = _find("engine")
if ENGINE_DIR not in sys.path:
sys.path.insert(0, ENGINE_DIR)
def seed_file() -> str:
"""The synthetic dataset, used only by test_local.py. Not on the Space."""
for candidate in (os.path.join(HERE, "seed", "out", "evaluations.json"),
os.path.join(HERE, "..", "seed", "out", "evaluations.json")):
if os.path.isfile(candidate):
return os.path.abspath(candidate)
return ""
|