Repository navigation
Expand file tree
/
Copy pathsetup_dev.py
More file actions
173 lines (147 loc) · 5 KB
/
Copy pathsetup_dev.py
File metadata and controls
173 lines (147 loc) · 5 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
#!/usr/bin/env python3
"""
Computer Vision CNC Manufacturing Platform - Development Setup
This script sets up the development environment for testing and development
"""
import os
import sys
import subprocess
import platform
from pathlib import Path
def print_header():
"""Print setup header"""
print("=" * 70)
print("🚀 CV CNC Manufacturing Platform - Development Setup")
print("=" * 70)
print()
def check_python_version():
"""Check if Python version is compatible"""
version = sys.version_info
if version < (3, 8):
print("❌ Python 3.8 or higher is required")
print(f" Current version: {version.major}.{version.minor}.{version.micro}")
return False
print(f"✅ Python {version.major}.{version.minor}.{version.micro} detected")
return True
def create_venv():
"""Create virtual environment"""
venv_path = Path(".venv")
if venv_path.exists():
print("✅ Virtual environment already exists")
return True
print("📦 Creating virtual environment...")
try:
subprocess.run([sys.executable, "-m", "venv", ".venv"], check=True)
print("✅ Virtual environment created successfully")
return True
except subprocess.CalledProcessError as e:
print(f"❌ Failed to create virtual environment: {e}")
return False
def get_activation_command():
"""Get the command to activate virtual environment"""
if platform.system() == "Windows":
return ".venv\\Scripts\\activate"
else:
return "source .venv/bin/activate"
def install_packages():
"""Install required packages"""
print("📥 Installing packages...")
# Determine the pip executable
if platform.system() == "Windows":
pip_exe = ".venv\\Scripts\\pip.exe"
else:
pip_exe = ".venv/bin/pip"
try:
# Upgrade pip first
subprocess.run([pip_exe, "install", "--upgrade", "pip"], check=True)
# Install minimal requirements
subprocess.run([pip_exe, "install", "-r", "requirements-minimal.txt"], check=True)
print("✅ Packages installed successfully")
return True
except subprocess.CalledProcessError as e:
print(f"❌ Failed to install packages: {e}")
return False
def test_installation():
"""Test the installation"""
print("🧪 Testing installation...")
# Determine the python executable
if platform.system() == "Windows":
python_exe = ".venv\\Scripts\\python.exe"
else:
python_exe = ".venv/bin/python"
try:
# Test imports
test_script = """
import fastapi
import uvicorn
import psycopg2
import redis
import pydantic
print("✅ All essential packages imported successfully")
"""
result = subprocess.run([python_exe, "-c", test_script],
capture_output=True, text=True, check=True)
print(result.stdout.strip())
return True
except subprocess.CalledProcessError as e:
print(f"❌ Package test failed: {e}")
print(f"Error output: {e.stderr}")
return False
def check_docker():
"""Check if Docker is available"""
try:
result = subprocess.run(["docker", "--version"],
capture_output=True, text=True, check=True)
print(f"✅ Docker available: {result.stdout.strip()}")
return True
except (subprocess.CalledProcessError, FileNotFoundError):
print("⚠️ Docker not available (optional for development)")
return False
def show_next_steps():
"""Show next steps to the user"""
activation_cmd = get_activation_command()
print("\n" + "=" * 70)
print("🎉 Setup Complete!")
print("=" * 70)
print("\n📋 Next Steps:")
print()
print("1. Activate virtual environment:")
print(f" {activation_cmd}")
print()
print("2. Start Docker services (optional):")
print(" docker-compose -f docker-compose.simple.yml up -d")
print()
print("3. Run the application:")
print(" python main.py")
print()
print("4. Access the API:")
print(" • API: http://localhost:8000")
print(" • Documentation: http://localhost:8000/docs")
print(" • Health Check: http://localhost:8000/health")
print()
print("5. Test endpoints:")
print(" curl http://localhost:8000/api/manufacturing/status")
print(" curl http://localhost:8000/api/cnc/machines")
print(" curl http://localhost:8000/api/vision/models")
print()
def main():
"""Main setup function"""
print_header()
# Check Python version
if not check_python_version():
sys.exit(1)
# Create virtual environment
if not create_venv():
sys.exit(1)
# Install packages
if not install_packages():
sys.exit(1)
# Test installation
if not test_installation():
sys.exit(1)
# Check Docker (optional)
check_docker()
# Show next steps
show_next_steps()
if __name__ == "__main__":
main()