Move canonical sample scripts to a sibling folder of code/ and lib/ so user projects stay separate from shipped examples. Backend seeding, writable paths, and docs follow the new layout. Co-authored-by: Cursor <cursoragent@cursor.com>
39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
import os
|
|
from pathlib import Path
|
|
|
|
|
|
# Application package lives under `src/`; repo root is one level up (for `.env`, default workspace).
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
PROJECT_ROOT = BASE_DIR.parent
|
|
STATIC_DIR = BASE_DIR / "static"
|
|
|
|
|
|
def load_env_file(env_path: Path) -> None:
|
|
"""Load KEY=VALUE entries from a local .env file (does not override existing os.environ)."""
|
|
if not env_path.exists():
|
|
return
|
|
|
|
for line in env_path.read_text(encoding="utf-8").splitlines():
|
|
stripped = line.strip()
|
|
if not stripped or stripped.startswith("#") or "=" not in stripped:
|
|
continue
|
|
key, value = stripped.split("=", 1)
|
|
key = key.strip()
|
|
value = value.strip().strip('"').strip("'")
|
|
if key and key not in os.environ:
|
|
os.environ[key] = value
|
|
|
|
|
|
load_env_file(PROJECT_ROOT / ".env")
|
|
|
|
_default_workspace = PROJECT_ROOT / "workspace"
|
|
WORKSPACE_ROOT = Path(os.environ.get("WORKSPACE_ROOT", str(_default_workspace))).resolve()
|
|
|
|
# Canonical demo bundle root (`manifest.json` lives here). Sample `.py`
|
|
# sources live under `demo/` (same idea as `bundled-lib/` for shared modules).
|
|
# They ship with the static bundle (`/static/bundled-demos/...`) so a
|
|
# static-only host also exposes them. `workspace/` is intentionally NOT used
|
|
# for canonical data — it is treated as runtime/user state and is gitignored.
|
|
BUNDLED_DEMOS_DIR = STATIC_DIR / "bundled-demos"
|
|
BUNDLED_DEMOS_CODE_DIR = BUNDLED_DEMOS_DIR / "demo"
|