From bd1b04256ee9421b7b5384514d7f1cca47915bab Mon Sep 17 00:00:00 2001 From: "QM.Y" Date: Tue, 11 Nov 2025 16:30:52 +0100 Subject: [PATCH] fix: support paths with spaces in project directory Add smart path handling in init_db.py to resolve ModuleNotFoundError when project path contains spaces (e.g. 'Mobile Documents'). The script now: - Attempts to import valuecell first - Only adds project root to sys.path if import fails - Works both as standalone script and installed package This fix allows running: uv run valuecell/server/db/init_db.py from paths containing spaces without ModuleNotFoundError. Fixes: ModuleNotFoundError in init_db.py with space-containing paths --- python/valuecell/server/db/init_db.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/python/valuecell/server/db/init_db.py b/python/valuecell/server/db/init_db.py index 24211e041..b0a9f9f95 100644 --- a/python/valuecell/server/db/init_db.py +++ b/python/valuecell/server/db/init_db.py @@ -6,6 +6,18 @@ from pathlib import Path from typing import Optional +# Smart path handling: try import first, add path only if needed +# This allows running the script directly: uv run valuecell/server/db/init_db.py +try: + import valuecell # noqa: F401 +except ImportError: + # If import fails, add the Python package root to sys.path + # Calculate path: init_db.py -> db -> server -> valuecell -> python (root) + _current_file = Path(__file__).resolve() + _python_root = _current_file.parent.parent.parent.parent + if str(_python_root) not in sys.path: + sys.path.insert(0, str(_python_root)) + from sqlalchemy import inspect, text from sqlalchemy.exc import SQLAlchemyError