-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathvalidate_setup.py
More file actions
171 lines (138 loc) · 5.34 KB
/
validate_setup.py
File metadata and controls
171 lines (138 loc) · 5.34 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
#!/usr/bin/env python3
"""
Quick validation script to verify project setup.
Run this to check if everything is working correctly.
"""
import subprocess
import sys
from pathlib import Path
def print_header(title):
"""Print a formatted header."""
print(f"\n{'=' * 70}")
print(f" {title}")
print("=" * 70)
def check_item(description, condition, details=None):
"""Check an item and print result."""
status = "✓" if condition else "✗"
print(f"{status} {description}")
if details:
print(f" → {details}")
return condition
def run_command(cmd):
"""Run a command and return success status."""
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
return result.returncode == 0, result.stdout.strip(), result.stderr.strip()
def main():
"""Run validation checks."""
print_header("CUSTOMHYS PROJECT VALIDATION")
all_passed = True
# Check Python version
print_header("Python Environment")
python_version = f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
all_passed &= check_item("Python 3.10+", sys.version_info >= (3, 10), f"Version: {python_version}")
# Check UV installation
print_header("Build Tools")
uv_installed, uv_version, _ = run_command("uv --version")
all_passed &= check_item(
"UV installed (optional but recommended)",
uv_installed,
uv_version if uv_installed else "Not installed - using pip",
)
make_installed, _, _ = run_command("command -v make")
all_passed &= check_item(
"Make available", make_installed, "Makefile commands available" if make_installed else "Install make"
)
# Check project files
print_header("Project Files")
# Get the actual project root (parent of this script)
project_root = Path(__file__).parent
critical_files = {
"pyproject.toml": "Project configuration",
"setup.py": "Setup script",
"requirements.txt": "Dependencies",
"Makefile": "Build commands",
"README.md": "Documentation",
}
for filename, description in critical_files.items():
exists = (project_root / filename).exists()
all_passed &= check_item(f"{filename}", exists, description)
# Check optional files
optional_files = {
"uv.lock": "UV lockfile (for reproducibility)",
"CHANGELOG.md": "Version history",
"CONTRIBUTING.md": "Contribution guidelines",
}
print()
for filename, description in optional_files.items():
exists = (project_root / filename).exists()
check_item(f"{filename} (optional)", exists, description)
# Check imports
print_header("Package Imports")
try:
import customhys
check_item("customhys package", True, f"Version {customhys.__version__}")
# Test core modules
modules = ["benchmark_func", "population", "operators", "metaheuristic"]
for module in modules:
try:
exec(f"from customhys import {module}")
check_item(f"customhys.{module}", True)
except ImportError:
check_item(f"customhys.{module}", False)
all_passed = False
except ImportError as e:
check_item("customhys package", False, str(e))
all_passed = False
# Check dependencies (with error handling)
print_header("Core Dependencies")
core_deps = ["numpy", "scipy", "matplotlib", "pandas", "sklearn"]
for dep in core_deps:
try:
__import__(dep)
check_item(dep, True)
except (ImportError, ValueError):
# ValueError can occur with numpy/pandas version mismatch
check_item(dep, False, "Import error (may need reinstall)")
if dep in ["numpy", "pandas"]:
print(f" ℹ Hint: Try 'uv sync' or 'pip install --upgrade {dep}'")
# Check optional dependencies
print()
optional_deps = {
"tensorflow": "Machine Learning",
"pytest": "Testing",
"black": "Code Formatting",
"ruff": "Linting",
}
for dep, description in optional_deps.items():
try:
__import__(dep)
check_item(f"{dep} (optional)", True, description)
except ImportError:
check_item(f"{dep} (optional)", False, f"{description} - not installed")
# Test Makefile
if make_installed:
print_header("Makefile Commands")
success, output, _ = run_command("make help")
check_item("make help", success, "Help command works")
success, output, _ = run_command("make check-uv")
check_item("make check-uv", success, output)
# Summary
print_header("VALIDATION SUMMARY")
if all_passed:
print("✅ All critical checks passed!")
print("\nYou can now:")
print(" • Run tests: make test")
print(" • Format code: make format")
print(" • Check code: make lint")
print(" • See all commands: make help")
return 0
else:
print("⚠ Some checks failed!")
print("\nTo fix:")
if not uv_installed:
print(" • Install UV: curl -LsSf https://astral.sh/uv/install.sh | sh")
print(" • Install dependencies: make sync (or make install-dev)")
print(" • Check documentation: README.md")
return 1
if __name__ == "__main__":
sys.exit(main())