Skip to content

Commit e38708c

Browse files
author
shadeform
committed
fix(setup): run Step 9 demo scripts with project venv and cwd
Same issue as Step 8: CWD-relative env/bin/python missed deps (psycopg, asyncpg). Use get_project_root(), project_root/env Python, absolute script paths, cwd=project_root; optional get_project_root fallback if Step 2/8 not run. Made-with: Cursor
1 parent 1685e47 commit e38708c

1 file changed

Lines changed: 66 additions & 14 deletions

File tree

notebooks/setup/complete_setup_guide.ipynb

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3524,44 +3524,96 @@
35243524
"import sys\n",
35253525
"from pathlib import Path\n",
35263526
"\n",
3527+
"if \"get_project_root\" not in globals():\n",
3528+
" NOTEBOOK_FILENAME = \"complete_setup_guide.ipynb\"\n",
3529+
" PROJECT_ROOT_MARKERS = ((\"src\", \"api\"), (\"scripts\", \"setup\"))\n",
3530+
" NOTEBOOK_SETUP_DIR = \"setup\"\n",
3531+
" NOTEBOOKS_DIR = \"notebooks\"\n",
3532+
"\n",
3533+
" def _has_markers(path: Path) -> bool:\n",
3534+
" return (\n",
3535+
" (path / PROJECT_ROOT_MARKERS[0][0] / PROJECT_ROOT_MARKERS[0][1]).exists()\n",
3536+
" and (path / PROJECT_ROOT_MARKERS[1][0] / PROJECT_ROOT_MARKERS[1][1]).exists()\n",
3537+
" )\n",
3538+
"\n",
3539+
" def get_project_root():\n",
3540+
" \"\"\"Detect repo root (same rules as Step 2) if that cell was not run.\"\"\"\n",
3541+
" import builtins\n",
3542+
" import os\n",
3543+
"\n",
3544+
" if hasattr(builtins, \"__project_root__\"):\n",
3545+
" cached = Path(builtins.__project_root__)\n",
3546+
" if _has_markers(cached):\n",
3547+
" return cached\n",
3548+
" del builtins.__project_root__\n",
3549+
"\n",
3550+
" current = Path.cwd()\n",
3551+
" if _has_markers(current):\n",
3552+
" project_root = current\n",
3553+
" elif current.name == NOTEBOOK_SETUP_DIR and current.parent.name == NOTEBOOKS_DIR:\n",
3554+
" project_root = current.parent.parent\n",
3555+
" elif current.name == NOTEBOOKS_DIR:\n",
3556+
" project_root = current.parent\n",
3557+
" else:\n",
3558+
" project_root = current\n",
3559+
" for parent in current.parents:\n",
3560+
" if _has_markers(parent):\n",
3561+
" project_root = parent\n",
3562+
" break\n",
3563+
"\n",
3564+
" if not _has_markers(project_root):\n",
3565+
" try:\n",
3566+
" for child in sorted(current.iterdir(), key=lambda p: p.name.lower()):\n",
3567+
" if child.is_dir() and _has_markers(child):\n",
3568+
" project_root = child\n",
3569+
" break\n",
3570+
" except (OSError, PermissionError):\n",
3571+
" pass\n",
3572+
"\n",
3573+
" os.chdir(project_root)\n",
3574+
" builtins.__project_root__ = project_root\n",
3575+
" return project_root\n",
3576+
"\n",
35273577
"def generate_demo_data():\n",
35283578
" \"\"\"Generate demo data for testing.\"\"\"\n",
35293579
" print(\"📊 Generating Demo Data\")\n",
35303580
" print(\"=\" * 60)\n",
3531-
" \n",
3532-
" # Determine Python path\n",
3581+
"\n",
3582+
" project_root = get_project_root()\n",
35333583
" if sys.platform == \"win32\":\n",
3534-
" python_path = Path(\"env\") / \"Scripts\" / \"python.exe\"\n",
3584+
" python_path = project_root / \"env\" / \"Scripts\" / \"python.exe\"\n",
35353585
" else:\n",
3536-
" python_path = Path(\"env\") / \"bin\" / \"python\"\n",
3537-
" \n",
3586+
" python_path = project_root / \"env\" / \"bin\" / \"python\"\n",
3587+
"\n",
35383588
" if not python_path.exists():\n",
35393589
" print(f\"❌ Python not found at: {python_path}\")\n",
3590+
" print(\" Make sure virtual environment is set up (Step 3)\")\n",
35403591
" return False\n",
3541-
" \n",
3592+
"\n",
35423593
" scripts = [\n",
35433594
" (\"scripts/data/quick_demo_data.py\", \"Quick demo data (equipment, inventory)\"),\n",
35443595
" (\"scripts/data/generate_historical_demand.py\", \"Historical demand data (for forecasting)\"),\n",
35453596
" ]\n",
3546-
" \n",
3547-
" for script_path, description in scripts:\n",
3548-
" script = Path(script_path)\n",
3597+
"\n",
3598+
" for script_rel, description in scripts:\n",
3599+
" script = project_root / script_rel\n",
35493600
" if not script.exists():\n",
3550-
" print(f\"⚠️ Script not found: {script_path} (skipping)\")\n",
3601+
" print(f\"⚠️ Script not found: {script} (skipping)\")\n",
35513602
" continue\n",
3552-
" \n",
3603+
"\n",
35533604
" print(f\"\\n🔄 {description}...\")\n",
35543605
" result = subprocess.run(\n",
35553606
" [str(python_path), str(script)],\n",
35563607
" capture_output=True,\n",
3557-
" text=True\n",
3608+
" text=True,\n",
3609+
" cwd=str(project_root),\n",
35583610
" )\n",
3559-
" \n",
3611+
"\n",
35603612
" if result.returncode == 0:\n",
35613613
" print(f\"✅ {description} generated\")\n",
35623614
" else:\n",
35633615
" print(f\"⚠️ {description} had issues: {result.stderr[:200]}\")\n",
3564-
" \n",
3616+
"\n",
35653617
" print(\"\\n\" + \"=\" * 60)\n",
35663618
" print(\"✅ Demo data generation complete!\")\n",
35673619
" print(\"\\n💡 You can skip this step if you don't need demo data.\")\n",

0 commit comments

Comments
 (0)