-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvalidate.py
More file actions
170 lines (148 loc) · 5.69 KB
/
Copy pathvalidate.py
File metadata and controls
170 lines (148 loc) · 5.69 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
#!/usr/bin/env python3
"""
Pre-deployment validation script for BinomoAPI
This script checks if the package is ready for PyPI deployment.
"""
import os
import sys
import json
import subprocess
from pathlib import Path
def check_file_exists(filepath, description):
"""Check if a file exists"""
if os.path.exists(filepath):
print(f"✅ {description}: {filepath}")
return True
else:
print(f"❌ {description}: {filepath} (MISSING)")
return False
def check_python_syntax(filepath):
"""Check Python syntax"""
try:
with open(filepath, 'r', encoding='utf-8') as f:
compile(f.read(), filepath, 'exec')
return True
except SyntaxError as e:
print(f"❌ Syntax error in {filepath}: {e}")
return False
def run_command_check(command, description):
"""Run a command and check if it succeeds"""
try:
result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
print(f"✅ {description}")
return True
except subprocess.CalledProcessError as e:
print(f"❌ {description}: {e.stderr.strip()}")
return False
def validate_package():
"""Main validation function"""
print("🔍 BinomoAPI PyPI Deployment Validation")
print("=" * 50)
errors = []
# Check essential files
print("\n📁 Checking essential files...")
essential_files = [
("pyproject.toml", "Modern Python package configuration"),
("setup.py", "Legacy setup file"),
("README.md", "Package documentation"),
("LICENSE", "License file"),
("MANIFEST.in", "Package manifest"),
("requirements-clean.txt", "Clean runtime dependencies"),
("requirements-dev.txt", "Development dependencies"),
("BinomoAPI/__init__.py", "Package init file"),
("BinomoAPI/api.py", "Main API module"),
]
for filepath, description in essential_files:
if not check_file_exists(filepath, description):
errors.append(f"Missing file: {filepath}")
# Check Python syntax
print("\n🐍 Checking Python syntax...")
python_files = [
"setup.py",
"deploy.py",
"BinomoAPI/__init__.py",
"BinomoAPI/api.py",
]
for filepath in python_files:
if os.path.exists(filepath):
if not check_python_syntax(filepath):
errors.append(f"Syntax error in: {filepath}")
# Check version consistency
print("\n🔢 Checking version consistency...")
try:
# Read version from pyproject.toml
pyproject_version = None
with open("pyproject.toml", "r") as f:
for line in f:
if line.startswith("version = "):
pyproject_version = line.split('"')[1]
break
# Read version from __init__.py
init_version = None
with open("BinomoAPI/__init__.py", "r") as f:
for line in f:
if line.startswith("__version__ = "):
init_version = line.split('"')[1]
break
if pyproject_version and init_version:
if pyproject_version == init_version:
print(f"✅ Version consistency: {pyproject_version}")
else:
print(f"❌ Version mismatch: pyproject.toml={pyproject_version}, __init__.py={init_version}")
errors.append("Version mismatch between pyproject.toml and __init__.py")
else:
print("❌ Could not find version information")
errors.append("Version information not found")
except Exception as e:
print(f"❌ Error checking versions: {e}")
errors.append("Error checking version information")
# Check if build tools are available
print("\n🔧 Checking build tools...")
build_tools = [
("python -m build --help", "Build tool availability"),
("python -m twine --help", "Twine availability"),
]
for command, description in build_tools:
if not run_command_check(command, description):
errors.append(f"Build tool not available: {command}")
# Try building the package
print("\n🏗️ Testing package build...")
if run_command_check("python -m build --outdir test-dist", "Package build test"):
# Clean up test build
if os.path.exists("test-dist"):
import shutil
shutil.rmtree("test-dist")
print(" Cleaned up test build directory")
else:
errors.append("Package build failed")
# Check package structure
print("\n📦 Checking package structure...")
required_dirs = [
"BinomoAPI",
"BinomoAPI/config",
"BinomoAPI/wss",
]
for dir_path in required_dirs:
if os.path.exists(dir_path) and os.path.isdir(dir_path):
print(f"✅ Directory exists: {dir_path}")
else:
print(f"❌ Directory missing: {dir_path}")
errors.append(f"Missing directory: {dir_path}")
# Summary
print("\n" + "=" * 50)
if errors:
print(f"❌ Validation failed with {len(errors)} error(s):")
for error in errors:
print(f" • {error}")
print("\nPlease fix these issues before deploying to PyPI.")
return False
else:
print("✅ All validation checks passed!")
print("\nYour package is ready for PyPI deployment.")
print("You can now run:")
print(" python deploy.py test # Deploy to Test PyPI")
print(" python deploy.py prod # Deploy to Production PyPI")
return True
if __name__ == "__main__":
success = validate_package()
sys.exit(0 if success else 1)