Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| """ | |
| Simple validation script for TransitApp MCP Server | |
| Checks code structure without running full tests | |
| """ | |
| import os | |
| import sys | |
| import ast | |
| def validate_file_exists(filename): | |
| """Check if required file exists""" | |
| if os.path.exists(filename): | |
| print(f"β {filename} exists") | |
| return True | |
| else: | |
| print(f"β {filename} missing") | |
| return False | |
| def validate_python_syntax(filename): | |
| """Check if Python file has valid syntax""" | |
| try: | |
| with open(filename, 'r') as f: | |
| ast.parse(f.read()) | |
| print(f"β {filename} has valid syntax") | |
| return True | |
| except SyntaxError as e: | |
| print(f"β {filename} has syntax error: {e}") | |
| return False | |
| def check_readme_requirements(): | |
| """Check README has required elements""" | |
| try: | |
| with open('README.md', 'r') as f: | |
| content = f.read() | |
| checks = { | |
| 'sdk: gradio': 'sdk: gradio' in content, | |
| 'mcp-server-track tag': 'mcp-server-track' in content, | |
| 'emoji': 'emoji:' in content, | |
| 'title': 'title:' in content, | |
| } | |
| for name, passed in checks.items(): | |
| if passed: | |
| print(f"β README has {name}") | |
| else: | |
| print(f"β README missing {name}") | |
| return all(checks.values()) | |
| except Exception as e: | |
| print(f"β Error checking README: {e}") | |
| return False | |
| def check_app_structure(): | |
| """Check app.py has required functions""" | |
| try: | |
| with open('app.py', 'r') as f: | |
| content = f.read() | |
| required_functions = [ | |
| 'get_nearby_transit', | |
| 'plan_trip', | |
| 'get_realtime_vehicle_location', | |
| 'get_service_alerts', | |
| 'compare_trip_modes', | |
| 'search_stops_and_stations' | |
| ] | |
| for func in required_functions: | |
| if f'def {func}' in content: | |
| print(f"β Function {func} exists") | |
| else: | |
| print(f"β Function {func} missing") | |
| return False | |
| return True | |
| except Exception as e: | |
| print(f"β Error checking app.py: {e}") | |
| return False | |
| def main(): | |
| """Run all validation checks""" | |
| print("=" * 60) | |
| print("TransitApp MCP Server - Structure Validation") | |
| print("=" * 60) | |
| print() | |
| checks = [] | |
| # Check required files exist | |
| print("Checking required files...") | |
| checks.append(validate_file_exists('app.py')) | |
| checks.append(validate_file_exists('requirements.txt')) | |
| checks.append(validate_file_exists('README.md')) | |
| checks.append(validate_file_exists('.env.example')) | |
| print() | |
| # Check Python syntax | |
| print("Checking Python syntax...") | |
| checks.append(validate_python_syntax('app.py')) | |
| if os.path.exists('test_server.py'): | |
| checks.append(validate_python_syntax('test_server.py')) | |
| print() | |
| # Check README requirements | |
| print("Checking README requirements...") | |
| checks.append(check_readme_requirements()) | |
| print() | |
| # Check app structure | |
| print("Checking app.py structure...") | |
| checks.append(check_app_structure()) | |
| print() | |
| # Summary | |
| print("=" * 60) | |
| print("VALIDATION SUMMARY") | |
| print("=" * 60) | |
| passed = sum(checks) | |
| total = len(checks) | |
| print(f"Checks Passed: {passed}/{total}") | |
| print(f"Success Rate: {passed/total*100:.1f}%") | |
| print() | |
| if passed == total: | |
| print("β All validation checks passed!") | |
| print(" Your project is ready for HuggingFace Spaces deployment!") | |
| print() | |
| print("Next steps:") | |
| print("1. Deploy to HuggingFace Spaces") | |
| print("2. Record demo video") | |
| print("3. Submit to hackathon") | |
| return 0 | |
| else: | |
| print(f"β οΈ {total - passed} check(s) failed.") | |
| print(" Review errors above and fix issues.") | |
| return 1 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |