Skip to content

fix: add smart sys.path fallback for init_db entrypoint#344

Merged
vcfgv merged 1 commit intoValueCell-ai:mainfrom
Wee7:fix/support-paths-with-spaces
Nov 24, 2025
Merged

fix: add smart sys.path fallback for init_db entrypoint#344
vcfgv merged 1 commit intoValueCell-ai:mainfrom
Wee7:fix/support-paths-with-spaces

Conversation

@Wee7
Copy link
Contributor

@Wee7 Wee7 commented Nov 11, 2025

1. Related Issue

NA

2. Type of Change

Type of Change: Bug Fix

3. Description

Fixes issues when project path contains spaces (e.g., "Mobile Documents" on macOS).

  • Add smart path handling in init_db.py to support direct script execution
  • Add quotes to all path variables in launch.py for space compatibility
  • Manually load .env file and pass via subprocess to avoid shell parsing issues
  • Fixes ModuleNotFoundError when running uv run valuecell/server/db/init_db.py
  • Fixes environment variable loading failure on paths like 'Example Path'

The changes are backward compatible:

  • init_db.py: Only adds path when import fails (try-except pattern)
  • launch.py: Quotes work for both standard and space paths
  • No impact on users with standard installation paths

4. Testing

  • ✅ Tested on macOS with path containing spaces
  • ✅ Backward compatible with standard paths
  • ✅ All services start successfully

5. Checklist

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses issues when the project directory path contains spaces (common on macOS in "Mobile Documents" directories). The changes add path quoting in launch.py and path handling logic in init_db.py to support direct script execution.

Key Changes:

  • Added try-except import pattern in init_db.py to support running the script directly via uv run
  • Added single quotes around all path variables in command strings to handle spaces
  • Implemented manual .env file parsing to pass environment variables via subprocess instead of using --env-file flag

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
python/valuecell/server/db/init_db.py Adds smart path handling to allow direct script execution by conditionally adding the Python package root to sys.path when imports fail
python/scripts/launch.py Adds quotes to path variables and implements manual .env loading to avoid shell parsing issues with spaces in paths

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vcfgv
Copy link
Collaborator

vcfgv commented Nov 15, 2025

Thanks for the Pull Request. Could you please run ⁠make format to ensure the code style is consistent with our project standards?

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
@Wee7 Wee7 force-pushed the fix/support-paths-with-spaces branch 3 times, most recently from 932ccb9 to bd1b042 Compare November 21, 2025 16:34
@Wee7
Copy link
Contributor Author

Wee7 commented Nov 21, 2025

Hi @vcfgv,

I've updated this PR to resolve merge conflicts with the latest main branch.

Current changes:

  • Only modifies python/valuecell/server/db/init_db.py (+12 lines)
  • Adds smart path handling to support project directories containing spaces (e.g., "Mobile Documents" on macOS)
  • Resolves ModuleNotFoundError when running uv run valuecell/server/db/init_db.py from paths with spaces

What happened:
The previous commits modified launch.py, which has since been refactored and removed in the upstream main branch (#401). I've rebased on the latest main and removed those obsolete changes. The PR now only contains the necessary fix for init_db.py.

Implementation:
Uses a try-except import guard pattern that only modifies sys.path when the valuecell package import fails, ensuring backward compatibility with standard installation paths.

The PR is now ready for review. Thank you for your patience!

@vcfgv vcfgv changed the title fix: support paths with spaces in project directory fix: add smart sys.path fallback for init_db entrypoint Nov 22, 2025
Copy link
Collaborator

@vcfgv vcfgv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vcfgv
Copy link
Collaborator

vcfgv commented Nov 22, 2025

I updated the title to better reflect the actual changes. Thanks for the contribution!

@vcfgv vcfgv merged commit a1a5300 into ValueCell-ai:main Nov 24, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants