-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_setup.py
More file actions
223 lines (178 loc) · 6.9 KB
/
Copy pathcheck_setup.py
File metadata and controls
223 lines (178 loc) · 6.9 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
"""Diagnostic script to check AutoSpendTracker setup.
Run this to verify your environment is correctly configured.
"""
import os
import sys
from pathlib import Path
from dotenv import load_dotenv
def check_python_version():
"""Check Python version."""
print("=" * 60)
print("Checking Python Version...")
print("=" * 60)
version = sys.version_info
print(f"Python version: {version.major}.{version.minor}.{version.micro}")
if version.major == 3 and version.minor >= 13:
print("✓ Python version is compatible (3.13+)")
return True
else:
print("✗ Python version must be 3.13 or higher")
return False
def check_env_file():
"""Check .env file exists and has required values."""
print("\n" + "=" * 60)
print("Checking .env Configuration...")
print("=" * 60)
env_path = Path(".env")
if not env_path.exists():
print("✗ .env file not found")
print(" → Create .env file from .env.example")
print(" → Command: cp .env.example .env")
return False
print("✓ .env file exists")
# Check for required values
required_vars = ["PROJECT_ID", "SPREADSHEET_ID"]
missing = []
with open(".env", "r") as f:
content = f.read()
for var in required_vars:
if f"{var}=" not in content or f"{var}=your-" in content:
missing.append(var)
if missing:
print(f"✗ Missing or not configured: {', '.join(missing)}")
print(" → Edit .env and set actual values")
return False
print(f"✓ Required variables configured: {', '.join(required_vars)}")
return True
def check_credentials():
"""Check credential files exist."""
print("\n" + "=" * 60)
print("Checking Credential Files...")
print("=" * 60)
load_dotenv()
creds_ok = True
# Check credentials.json (Gmail OAuth)
gmail_creds = Path("credentials.json")
if gmail_creds.exists():
print("✓ credentials.json found (Gmail OAuth)")
else:
print("✗ credentials.json not found")
print(" → Download from Google Cloud Console")
print(" → Enable Gmail API and create OAuth 2.0 credentials")
creds_ok = False
# Check ASTservice.json (Service Account)
service_account_file = os.getenv("SERVICE_ACCOUNT_FILE", "ASTservice.json")
service_creds = Path(service_account_file)
if service_creds.exists():
print(f"✓ {service_account_file} found (Service Account)")
else:
print(f"✗ {service_account_file} not found")
print(" → Download from Google Cloud Console")
print(" → Create Service Account with appropriate permissions")
if service_account_file.startswith("/app/"):
print(" → For local runs, set SERVICE_ACCOUNT_FILE=ASTservice.json in .env")
creds_ok = False
return creds_ok
def check_dependencies():
"""Check required Python packages are installed."""
print("\n" + "=" * 60)
print("Checking Python Dependencies...")
print("=" * 60)
# Map pip package names to their import names
required_packages = {
"google-genai": "google.genai",
"google-api-python-client": "googleapiclient",
"google-auth-oauthlib": "google_auth_oauthlib",
"beautifulsoup4": "bs4",
"python-dotenv": "dotenv",
"pydantic": "pydantic",
"tqdm": "tqdm"
}
missing = []
for package, import_name in required_packages.items():
try:
__import__(import_name)
print(f"✓ {package}")
except ImportError:
print(f"✗ {package} not installed")
missing.append(package)
if missing:
print(f"\n✗ Missing packages: {', '.join(missing)}")
print(" → Install with: uv pip install -e .")
return False
print("\n✓ All required dependencies installed")
return True
def check_package_installation():
"""Check if autospendtracker package is installed."""
print("\n" + "=" * 60)
print("Checking Package Installation...")
print("=" * 60)
try:
import autospendtracker
print("✓ autospendtracker package is importable")
# Check if it's in development mode
package_path = Path(autospendtracker.__file__).parent.parent.parent
if package_path.name == "src":
print("✓ Package installed in development mode")
return True
except ImportError as e:
print("✗ autospendtracker package not importable")
print(f" Error: {e}")
print(" → Install with: uv pip install -e .")
return False
def check_gcp_setup():
"""Check Google Cloud Platform setup."""
print("\n" + "=" * 60)
print("Checking Google Cloud Setup...")
print("=" * 60)
print("Please verify manually:")
print(" □ Gmail API is enabled in your GCP project")
print(" □ Google Sheets API is enabled in your GCP project")
print(" □ Vertex AI API is enabled in your GCP project")
print(" □ Service account has necessary permissions")
print(" □ OAuth consent screen is configured")
print("\n → Visit: https://console.cloud.google.com/apis/dashboard")
def main():
"""Run all diagnostic checks."""
print("\n" + "=" * 70)
print("AutoSpendTracker Diagnostic Tool")
print("=" * 70)
checks = [
("Python Version", check_python_version),
("Environment File", check_env_file),
("Credentials", check_credentials),
("Dependencies", check_dependencies),
("Package Installation", check_package_installation),
]
results = {}
for name, check_func in checks:
results[name] = check_func()
# GCP check (manual verification)
check_gcp_setup()
# Summary
print("\n" + "=" * 70)
print("Summary")
print("=" * 70)
passed = sum(results.values())
total = len(results)
for name, result in results.items():
status = "✓ PASS" if result else "✗ FAIL"
print(f"{status} - {name}")
print("\n" + "=" * 70)
if passed == total:
print("✓ All checks passed! You're ready to run the application.")
print("\nNext steps:")
print(" 1. Verify GCP setup manually (see above)")
print(" 2. Run: uv run autospendtracker")
else:
print(f"✗ {total - passed} check(s) failed. Please fix the issues above.")
print("\nQuick fixes:")
if not results.get("Environment File"):
print(" • cp .env.example .env && nano .env")
if not results.get("Dependencies"):
print(" • uv pip install -e .")
if not results.get("Credentials"):
print(" • Download credentials from Google Cloud Console")
print("=" * 70)
if __name__ == "__main__":
main()