-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_cli.py
More file actions
167 lines (139 loc) Β· 5.2 KB
/
debug_cli.py
File metadata and controls
167 lines (139 loc) Β· 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env python3
"""
debug_cli.py - Debug the CLI issues step by step
"""
import os
import sys
import subprocess
from pathlib import Path
def debug_step_by_step():
"""Debug CLI issues step by step"""
print("π CLI Debug Session")
print("=" * 50)
project_root = Path(__file__).parent
print(f"π Project root: {project_root}")
print(f"π Python: {sys.executable}")
print(f"π CWD: {os.getcwd()}")
# Step 1: Check file existence
print("\n1οΈβ£ Checking file existence:")
files_to_check = [
'mcp_cli.py',
'config.py',
'notes_mcp_server.py',
'build_index.py',
'requirements.txt'
]
for file in files_to_check:
path = project_root / file
if path.exists():
print(f" β
{file} exists")
else:
print(f" β {file} missing")
# Step 2: Check Python path
print("\n2οΈβ£ Checking Python path:")
print(f" Project in path: {str(project_root) in sys.path}")
# Step 3: Test basic Python execution
print("\n3οΈβ£ Testing basic Python:")
try:
result = subprocess.run([sys.executable, "-c", "print('Hello from Python')"],
capture_output=True, text=True, timeout=5)
if result.returncode == 0:
print(" β
Basic Python works")
else:
print(f" β Basic Python failed: {result.stderr}")
except Exception as e:
print(f" π₯ Basic Python exception: {e}")
# Step 4: Test imports individually
print("\n4οΈβ£ Testing imports:")
sys.path.insert(0, str(project_root))
test_imports = [
'os',
'sys',
'pathlib',
'json',
'config',
'notes_mcp_server',
'build_index'
]
for module in test_imports:
try:
__import__(module)
print(f" β
{module} imported")
except ImportError as e:
print(f" β {module} import failed: {e}")
except Exception as e:
print(f" β οΈ {module} import warning: {e}")
# Step 5: Test CLI script execution directly
print("\n5οΈβ£ Testing CLI script execution:")
cli_path = project_root / "mcp_cli.py"
if cli_path.exists():
print(" CLI script found, testing execution...")
# Test 1: Just run the script without arguments
try:
cmd = [sys.executable, str(cli_path)]
result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
print(f" Return code: {result.returncode}")
if result.stdout:
print(f" STDOUT: {result.stdout[:200]}...")
if result.stderr:
print(f" STDERR:
7980
{result.stderr[:200]}...")
else:
print(" STDERR: (empty)")
except subprocess.TimeoutExpired:
print(" β° Script timed out")
except Exception as e:
print(f" π₯ Script execution failed: {e}")
# Test 2: Try with --help
print(" Testing --help argument...")
try:
cmd = [sys.executable, str(cli_path), "--help"]
result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
print(f" Help return code: {result.returncode}")
if result.returncode == 0:
print(" β
Help command works!")
else:
print(" β Help command failed")
if result.stderr:
print(f" Help error: {result.stderr[:300]}...")
else:
print(" Help error: (empty stderr - this is the issue!)")
except Exception as e:
print(f" π₯ Help test failed: {e}")
else:
print(" β CLI script not found")
# Step 6: Check environment
print("\n6οΈβ£ Environment check:")
print(f" Python version: {sys.version}")
print(f" Platform: {sys.platform}")
# Check for common issues
print("\nπ Common issue detection:")
# Check if we're in virtual environment
in_venv = hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix)
print(f" In virtual environment: {in_venv}")
# Check for missing dependencies
try:
import sentence_transformers
print(" β
sentence-transformers available")
except ImportError:
print(" β sentence-transformers missing - run: pip install sentence-transformers")
try:
import numpy
print(" β
numpy available")
except ImportError:
print(" β numpy missing - run: pip install numpy")
def main():
"""Main debug function"""
debug_step_by_step()
print("\nπ― Debug Summary:")
print("If you're seeing empty error messages, it usually means:")
print("1. Import errors in the CLI script")
print("2. Missing dependencies")
print("3. Path issues")
print("4. Virtual environment problems")
print("\nπ‘ Try these solutions:")
print("1. Run: python quick_fix.py")
print("2. Run: python test_cli_fixed.py")
print("3. Install deps: pip install -r requirements.txt")
print("4. Use fixed CLI: python mcp_cli_fixed.py --help")
if __name__ == "__main__":
main()