mvp-factory-openhands/test-scripts/diagnose_project.py

177 lines
5.8 KiB
Python

#!/usr/bin/env python3
"""
Diagnostic script to explore the project structure and identify build requirements.
"""
import os
import subprocess
import sys
def run_command(cmd, description=""):
"""Run a command and return its output."""
print(f"\n=== {description} ===")
try:
result = subprocess.run(cmd, shell=True, capture_output=True, text=True, cwd=os.getcwd())
print(f"Command: {cmd}")
print(f"Return code: {result.returncode}")
if result.stdout:
print(f"STDOUT:\n{result.stdout}")
if result.stderr:
print(f"STDERR:\n{result.stderr}")
return result
except Exception as e:
print(f"Error running command: {e}")
return None
def check_git_status():
"""Check git repository status."""
print("🔍 Checking git repository...")
# Check if .git exists
if os.path.exists('.git'):
print("✅ .git directory found")
else:
print("❌ No .git directory found")
return
# Check git status
run_command("git status", "Git Status")
run_command("git branch", "Current Branch")
run_command("git log --oneline -5", "Recent Commits")
run_command("git remote -v", "Git Remotes")
def find_project_files():
"""Search for common project files."""
print("\n🔍 Searching for project files...")
# Common project files to look for
project_files = [
"package.json", # Node.js
"requirements.txt", # Python
"setup.py", # Python
"pyproject.toml", # Python
"pom.xml", # Java Maven
"build.gradle", # Java Gradle
"go.mod", # Go
"Cargo.toml", # Rust
"composer.json", # PHP
"Makefile", # Make
"Dockerfile", # Docker
"*.sln", # .NET
"*.csproj", # .NET
]
found_files = []
for root, dirs, files in os.walk('.'):
# Skip .git directory
if '.git' in dirs:
dirs.remove('.git')
for file in files:
for pattern in project_files:
if file == pattern or (pattern.startswith('*') and file.endswith(pattern[1:])):
found_files.append(os.path.join(root, file))
if found_files:
print("📁 Project files found:")
for f in found_files:
print(f"{f}")
else:
print("📭 No common project files found")
return found_files
def check_build_tools():
"""Check for available build tools."""
print("\n🔧 Checking available build tools...")
tools = {
'node': ['node --version', 'npm --version'],
'python': ['python3 --version', 'pip3 --version'],
'java': ['java -version', 'javac -version'],
'maven': ['mvn --version'],
'gradle': ['gradle --version'],
'go': ['go version'],
'rust': ['cargo --version'],
'make': ['make --version'],
'docker': ['docker --version'],
'git': ['git --version']
}
available_tools = {}
for tool, commands in tools.items():
print(f"\nChecking {tool}:")
for cmd in commands:
try:
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
if result.returncode == 0:
version_line = result.stdout.strip().split('\n')[0]
print(f"{cmd.split()[0]}: {version_line}")
available_tools[tool] = True
break
else:
print(f"{cmd}: not available")
except Exception as e:
print(f"{cmd}: error - {e}")
return available_tools
def main():
"""Main diagnostic function."""
print("🚀 Project Diagnostic Tool")
print("=" * 50)
# Check current directory
cwd = os.getcwd()
print(f"Current working directory: {cwd}")
try:
contents = os.listdir('.')
print(f"Directory contents ({len(contents)} items):")
for item in sorted(contents):
if os.path.isdir(item):
print(f" 📁 {item}/")
else:
size = os.path.getsize(item)
print(f" 📄 {item} ({size} bytes)")
except Exception as e:
print(f"Error listing directory: {e}")
# Run diagnostics
check_git_status()
project_files = find_project_files()
available_tools = check_build_tools()
# Summary
print("\n" + "=" * 50)
print("📊 DIAGNOSTIC SUMMARY")
print("=" * 50)
print(f"Project files found: {len(project_files)}")
print(f"Available build tools: {len(available_tools)}")
if project_files:
print("\n🎯 Recommended next steps based on project files:")
for file in project_files:
if file.endswith('package.json'):
print(" • npm install && npm run build && npm test")
elif file.endswith('requirements.txt') or file.endswith('setup.py') or file.endswith('pyproject.toml'):
print(" • pip install -r requirements.txt && python -m pytest")
elif file.endswith('pom.xml'):
print(" • mvn clean install")
elif file.endswith('build.gradle'):
print(" • gradle build")
elif file.endswith('go.mod'):
print(" • go mod download && go build && go test")
elif file.endswith('Cargo.toml'):
print(" • cargo build && cargo test")
elif file.endswith('Makefile'):
print(" • make build && make test")
else:
print("\n⚠️ No common project files detected.")
print("This might be a custom project or the files are in a different location.")
if __name__ == "__main__":
main()