-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.py
More file actions
312 lines (249 loc) · 9.34 KB
/
Copy pathvalidate.py
File metadata and controls
312 lines (249 loc) · 9.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
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#!/usr/bin/env python
"""
Validation script for GoRequests package before publishing.
"""
import os
import sys
import importlib.util
def check_file_exists(file_path, description):
"""Check if a file exists."""
if os.path.exists(file_path):
size = os.path.getsize(file_path)
print(f"✅ {description}: {file_path} ({size:,} bytes)")
return True
else:
print(f"❌ {description}: {file_path} - NOT FOUND")
return False
def check_directory_structure():
"""Check the package directory structure."""
print("📁 Checking Directory Structure")
print("-" * 40)
required_files = [
("README.md", "Main README"),
("LICENSE", "License file"),
("CHANGELOG.md", "Changelog"),
("CONTRIBUTING.md", "Contributing guide"),
("pyproject.toml", "Modern packaging config"),
("setup.py", "Setup script"),
("MANIFEST.in", "Package manifest"),
("build.py", "Build script"),
("PUBLISHING.md", "Publishing instructions"),
]
required_dirs = [
("gorequests", "Main package directory"),
("tests", "Test directory"),
("examples", "Examples directory"),
("docs", "Documentation directory"),
]
all_good = True
# Check files
for file_path, description in required_files:
if not check_file_exists(file_path, description):
all_good = False
# Check directories
for dir_path, description in required_dirs:
if os.path.isdir(dir_path):
files = len([f for f in os.listdir(dir_path) if os.path.isfile(os.path.join(dir_path, f))])
print(f"✅ {description}: {dir_path}/ ({files} files)")
else:
print(f"❌ {description}: {dir_path}/ - NOT FOUND")
all_good = False
return all_good
def check_package_contents():
"""Check the main package contents."""
print("\n📦 Checking Package Contents")
print("-" * 35)
package_files = [
("gorequests/__init__.py", "Main library code"),
("gorequests/exceptions.py", "Exception classes"),
("gorequests/libgorequests.dll", "Go library (Windows)"),
]
all_good = True
for file_path, description in package_files:
if not check_file_exists(file_path, description):
all_good = False
return all_good
def check_test_files():
"""Check test files."""
print("\n🧪 Checking Test Files")
print("-" * 28)
test_files = [
("tests/conftest.py", "Test configuration"),
("tests/test_basic.py", "Basic tests"),
("tests/test_performance.py", "Performance tests"),
("tests/test_compatibility.py", "Compatibility tests"),
]
all_good = True
for file_path, description in test_files:
if not check_file_exists(file_path, description):
all_good = False
return all_good
def check_example_files():
"""Check example files."""
print("\n📚 Checking Example Files")
print("-" * 30)
example_files = [
("examples/basic_usage.py", "Basic usage example"),
("examples/performance_benchmark.py", "Performance benchmark"),
("examples/session_management.py", "Session management"),
("examples/file_operations.py", "File operations"),
("examples/error_handling.py", "Error handling"),
]
all_good = True
for file_path, description in example_files:
if not check_file_exists(file_path, description):
all_good = False
return all_good
def check_documentation():
"""Check documentation files."""
print("\n📖 Checking Documentation")
print("-" * 32)
doc_files = [
("docs/API.md", "API documentation"),
]
all_good = True
for file_path, description in doc_files:
if not check_file_exists(file_path, description):
all_good = False
return all_good
def check_import_functionality():
"""Check if the package can be imported."""
print("\n🔍 Checking Import Functionality")
print("-" * 40)
try:
# Try to import the main module
spec = importlib.util.spec_from_file_location("gorequests", "gorequests/__init__.py")
if spec and spec.loader:
gorequests = importlib.util.module_from_spec(spec)
spec.loader.exec_module(gorequests)
# Check if basic functions exist
required_functions = ['get', 'post', 'put', 'delete', 'head', 'options', 'patch']
missing_functions = []
for func_name in required_functions:
if hasattr(gorequests, func_name):
print(f"✅ Function '{func_name}' available")
else:
print(f"❌ Function '{func_name}' missing")
missing_functions.append(func_name)
if not missing_functions:
print("✅ All required functions available")
return True
else:
print(f"❌ Missing functions: {missing_functions}")
return False
else:
print("❌ Could not load module spec")
return False
except Exception as e:
print(f"❌ Import failed: {e}")
return False
def check_readme_content():
"""Check README content."""
print("\n📄 Checking README Content")
print("-" * 32)
try:
with open("README.md", "r", encoding="utf-8") as f:
content = f.read()
required_sections = [
"# GoRequests",
"Installation",
"Usage Examples",
"Performance Comparison",
"pip install gorequests",
]
missing_sections = []
for section in required_sections:
if section in content:
print(f"✅ Section found: {section}")
else:
print(f"❌ Section missing: {section}")
missing_sections.append(section)
# Check README length
word_count = len(content.split())
print(f"📊 README word count: {word_count}")
if word_count < 500:
print("⚠️ README might be too short")
elif word_count > 3000:
print("⚠️ README might be too long")
else:
print("✅ README length is good")
return len(missing_sections) == 0
except Exception as e:
print(f"❌ Error reading README: {e}")
return False
def check_version_consistency():
"""Check version consistency across files."""
print("\n🔢 Checking Version Consistency")
print("-" * 38)
versions = {}
# Check pyproject.toml
try:
with open("pyproject.toml", "r") as f:
content = f.read()
for line in content.split('\n'):
if line.strip().startswith('version ='):
version = line.split('=')[1].strip().strip('"').strip("'")
versions['pyproject.toml'] = version
break
except Exception as e:
print(f"⚠️ Could not read pyproject.toml version: {e}")
# Check CHANGELOG.md
try:
with open("CHANGELOG.md", "r") as f:
content = f.read()
for line in content.split('\n'):
if line.strip().startswith('## ['):
version = line.split('[')[1].split(']')[0]
versions['CHANGELOG.md'] = version
break
except Exception as e:
print(f"⚠️ Could not read CHANGELOG.md version: {e}")
# Print versions
for file, version in versions.items():
print(f"📋 {file}: {version}")
# Check consistency
if len(set(versions.values())) == 1:
print("✅ All versions are consistent")
return True
else:
print("❌ Version mismatch found")
return False
def run_validation():
"""Run complete validation."""
print("🔍 GoRequests Package Validation")
print("=" * 45)
checks = [
("Directory Structure", check_directory_structure),
("Package Contents", check_package_contents),
("Test Files", check_test_files),
("Example Files", check_example_files),
("Documentation", check_documentation),
("Import Functionality", check_import_functionality),
("README Content", check_readme_content),
("Version Consistency", check_version_consistency),
]
passed = 0
total = len(checks)
for name, check_func in checks:
try:
if check_func():
passed += 1
except Exception as e:
print(f"❌ {name} check failed with error: {e}")
print("\n" + "=" * 45)
print("📊 VALIDATION SUMMARY")
print("=" * 45)
print(f"Passed: {passed}/{total} checks")
if passed == total:
print("🎉 ALL CHECKS PASSED! Package is ready for publishing.")
print("\nNext steps:")
print(" 1. Run: python build.py")
print(" 2. Test: pip install dist/*.whl")
print(" 3. Upload: twine upload dist/*")
return True
else:
print("❌ Some checks failed. Please fix issues before publishing.")
return False
if __name__ == "__main__":
success = run_validation()
sys.exit(0 if success else 1)