-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate_setup.py
More file actions
executable file
·281 lines (218 loc) · 8.3 KB
/
validate_setup.py
File metadata and controls
executable file
·281 lines (218 loc) · 8.3 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#!/usr/bin/env python3
"""
Validate Setup Script
Run this before pushing to verify everything is configured correctly.
Usage:
python scripts/validate_setup.py
"""
import json
import sys
from pathlib import Path
# Color codes for terminal output
GREEN = "\033[92m"
RED = "\033[91m"
YELLOW = "\033[93m"
BLUE = "\033[94m"
RESET = "\033[0m"
def check_mark(passed: bool) -> str:
return f"{GREEN}✓{RESET}" if passed else f"{RED}✗{RESET}"
def print_header(text: str):
print(f"\n{BLUE}{'=' * 70}")
print(f"{text}")
print(f"{'=' * 70}{RESET}\n")
def print_section(text: str):
print(f"\n{YELLOW}{text}{RESET}")
print("-" * 70)
def validate_sponsor_links() -> bool:
"""Check if sponsor links have been updated."""
print_section("Checking Sponsor Links")
issues = []
# Check FUNDING.yml
funding_file = Path(".github/FUNDING.yml")
if funding_file.exists():
content = funding_file.read_text()
if "YOUR_KOFI_USERNAME" in content:
issues.append(" - .github/FUNDING.yml still has placeholder 'YOUR_KOFI_USERNAME'")
if "YOUR_GITHUB_USERNAME" in content:
issues.append(" - .github/FUNDING.yml still has placeholder 'YOUR_GITHUB_USERNAME'")
if "YOUR_PATREON_USERNAME" in content:
issues.append(" - .github/FUNDING.yml still has placeholder 'YOUR_PATREON_USERNAME'")
if "YOUR_USERNAME" in content:
issues.append(" - .github/FUNDING.yml still has placeholder 'YOUR_USERNAME'")
else:
issues.append(" - .github/FUNDING.yml not found")
# Check README.md
readme_file = Path("README.md")
if readme_file.exists():
content = readme_file.read_text()
if "YOUR_USERNAME" in content or "YOUR_KOFI_USERNAME" in content:
issues.append(" - README.md still has sponsor link placeholders")
else:
issues.append(" - README.md not found")
if issues:
print(f"{check_mark(False)} Sponsor links need updating:")
for issue in issues:
print(issue)
return False
else:
print(f"{check_mark(True)} Sponsor links are configured")
return True
def validate_documentation_files() -> bool:
"""Check if required documentation files exist."""
print_section("Checking Documentation Files")
required_files = [
"docs/conf.py",
"docs/index.rst",
".readthedocs.yml",
"README.md",
"CLEAN_API_REFACTOR.md",
"SCHEMA_INTROSPECTION.md",
]
optional_docs = [
"docs/installation.rst",
"docs/quickstart.rst",
"docs/usage.rst",
"docs/testing.rst",
"docs/contributing.rst",
"docs/architecture.rst",
"docs/changelog.rst",
"docs/license.rst",
]
missing_required = []
missing_optional = []
for file in required_files:
if not Path(file).exists():
missing_required.append(file)
for file in optional_docs:
if not Path(file).exists():
missing_optional.append(file)
if missing_required:
print(f"{check_mark(False)} Missing required documentation files:")
for file in missing_required:
print(f" - {file}")
if missing_optional:
print(f"{YELLOW}⚠{RESET} Missing optional documentation files (needed for ReadTheDocs):")
for file in missing_optional:
print(f" - {file}")
print("\nRun the RST file creation commands from NEXT_STEPS.md to create these.")
if not missing_required:
print(f"{check_mark(True)} Required documentation files exist")
return len(missing_required) == 0
def validate_configuration_files() -> bool:
"""Check if required configuration files exist."""
print_section("Checking Configuration Files")
required_configs = {
".github/workflows/ci-cd.yml": "GitHub Actions CI/CD",
".github/FUNDING.yml": "Sponsor links",
".readthedocs.yml": "ReadTheDocs config",
"pyproject.toml": "Project configuration",
"Makefile": "Build automation",
".pre-commit-config.yaml": "Pre-commit hooks",
}
all_exist = True
for file, description in required_configs.items():
exists = Path(file).exists()
print(f"{check_mark(exists)} {description}: {file}")
if not exists:
all_exist = False
return all_exist
def validate_code_structure() -> bool:
"""Check if key code files exist."""
print_section("Checking Code Structure")
key_files = [
"pymlb_statsapi/model/factory.py",
"pymlb_statsapi/model/registry.py",
"pymlb_statsapi/utils/schema_loader.py",
"features/steps/statsapi_steps.py",
"examples/clean_api_demo.py",
"examples/schema_introspection_example.py",
]
all_exist = True
for file in key_files:
exists = Path(file).exists()
print(f"{check_mark(exists)} {file}")
if not exists:
all_exist = False
return all_exist
def validate_examples() -> bool:
"""Try to import and basic syntax check of examples."""
print_section("Validating Examples")
try:
# Try basic import
from pymlb_statsapi import api
print(f"{check_mark(True)} Can import pymlb_statsapi.model.registry.api")
# Check endpoint access
schedule = api.Schedule
print(
f"{check_mark(True)} Can access api.Schedule endpoint: {json.dumps(schedule, default=str)}"
)
# Check method access
method = api.Schedule.get_method("schedule")
print(f"{check_mark(True)} Can get method metadata: {json.dumps(method, default=str)}")
# Check schema access
schema = method.get_schema()
print(
f"{check_mark(True)} Can access original schema JSON: {json.dump(schema, default=str)}"
)
return True
except Exception as e:
print(f"{check_mark(False)} Import/access error: {e}")
return False
def check_git_status():
"""Check git status."""
print_section("Checking Git Status")
try:
import subprocess # nosec B404 - Safe: only used for git commands
# Check if in git repo. nosec is for B603 & B607 which are excepted as we are using git with hardcoded args
result = subprocess.run( # nosec
["git", "status", "--porcelain"], capture_output=True, text=True, check=True
)
if result.stdout.strip():
print(f"{YELLOW}⚠{RESET} You have uncommitted changes:")
print(result.stdout)
print("\nConsider committing before pushing.")
else:
print(f"{check_mark(True)} No uncommitted changes")
except subprocess.CalledProcessError:
print(f"{YELLOW}⚠{RESET} Not in a git repository or git not available")
except FileNotFoundError:
print(f"{YELLOW}⚠{RESET} Git not found in PATH")
def main():
"""Run all validation checks."""
print_header("PyMLB StatsAPI Setup Validation")
print("This script checks if your setup is ready for deployment.\n")
results = {
"Sponsor Links": validate_sponsor_links(),
"Documentation Files": validate_documentation_files(),
"Configuration Files": validate_configuration_files(),
"Code Structure": validate_code_structure(),
"Examples/Imports": validate_examples(),
}
check_git_status()
# Summary
print_header("Validation Summary")
all_passed = all(results.values())
for check, passed in results.items():
status = f"{GREEN}PASS{RESET}" if passed else f"{RED}FAIL{RESET}"
print(f"{status} {check}")
print()
if all_passed:
print(f"{GREEN}{'=' * 70}")
print("✅ All validation checks passed!")
print("=" * 70)
print("\nNext steps:")
print("1. Commit and push: git add . && git commit -m 'feat: ...' && git push")
print("2. Set up Codecov: https://codecov.io/")
print("3. Set up ReadTheDocs: https://readthedocs.org/")
print(f"{'=' * 70}{RESET}")
return 0
else:
print(f"{RED}{'=' * 70}")
print("❌ Some validation checks failed")
print("=" * 70)
print("\nPlease fix the issues above before pushing.")
print("See NEXT_STEPS.md for detailed guidance.")
print(f"{'=' * 70}{RESET}")
return 1
if __name__ == "__main__":
sys.exit(main())