Skip to content

Commit a058f63

Browse files
abrichrclaude
andcommitted
Add robust path handling for OmniMCP standalone package
- Create a dedicated pathing.py module for OpenAdapt path management - Add descriptive error messages for troubleshooting import issues - Centralize path setup logic with proper error handling - Update importing modules to use the new path handling 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0a4c658 commit a058f63

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

omnimcp/omnimcp/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"""OmniMCP - Model Control Protocol for UI Automation."""
22

3+
# Setup path to include OpenAdapt modules
4+
from . import pathing
5+
36
# Import from OpenAdapt modules
47
from openadapt.omnimcp import OmniMCP
58
from openadapt.run_omnimcp import main

omnimcp/omnimcp/pathing.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Setup Python path to include OpenAdapt modules."""
2+
3+
import os
4+
import sys
5+
6+
def ensure_openadapt_in_path():
7+
"""
8+
Add the OpenAdapt parent directory to sys.path so we can import modules.
9+
10+
This function ensures that the OpenAdapt modules can be imported without
11+
requiring a full OpenAdapt installation.
12+
"""
13+
# Add the OpenAdapt parent directory to sys.path
14+
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
15+
if parent_dir not in sys.path:
16+
sys.path.insert(0, parent_dir)
17+
print(f"Added {parent_dir} to Python path")
18+
19+
# Test if openadapt is importable now
20+
try:
21+
import openadapt
22+
return True
23+
except ImportError as e:
24+
print(f"Error importing OpenAdapt modules: {e}")
25+
print(f"Current sys.path: {sys.path}")
26+
print(f"Looking for OpenAdapt in: {parent_dir}")
27+
print("Make sure you are running this from within the OpenAdapt repository")
28+
raise
29+
30+
# Automatically configure path when this module is imported
31+
ensure_openadapt_in_path()

omnimcp/omnimcp/run_omnimcp.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"""Entry point for OmniMCP CLI."""
22

3+
# Setup path to include OpenAdapt modules
4+
from . import pathing
5+
36
# Import from OpenAdapt module
47
from openadapt.run_omnimcp import main
58

0 commit comments

Comments
 (0)