152 lines
4 KiB
Python
152 lines
4 KiB
Python
#!/usr/bin/env python
|
|
"""Build wheel distribution for Agravity Client.
|
|
|
|
This script builds wheel and source distributions for the Agravity Client package.
|
|
It requires setuptools and wheel to be installed.
|
|
|
|
Usage:
|
|
python build_wheel.py
|
|
|
|
Output:
|
|
- Wheels saved to dist/ directory
|
|
- Source distribution (sdist) also created for reference
|
|
"""
|
|
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def main() -> int:
|
|
"""Build wheel distribution.
|
|
|
|
Returns:
|
|
Exit code (0 for success, 1 for failure)
|
|
"""
|
|
project_root = Path(__file__).parent
|
|
dist_dir = project_root / "dist"
|
|
|
|
print("=" * 70)
|
|
print("Agravity Client - Wheel Builder")
|
|
print("=" * 70)
|
|
|
|
# Clean previous builds
|
|
print("\nCleaning previous builds...")
|
|
if dist_dir.exists():
|
|
try:
|
|
shutil.rmtree(dist_dir)
|
|
print(f"✓ Removed {dist_dir}")
|
|
except OSError as e:
|
|
print(f"✗ Failed to remove {dist_dir}: {e}")
|
|
return 1
|
|
|
|
build_dir = project_root / "build"
|
|
if build_dir.exists():
|
|
try:
|
|
shutil.rmtree(build_dir)
|
|
print(f"✓ Removed {build_dir}")
|
|
except OSError as e:
|
|
print(f"✗ Failed to remove {build_dir}: {e}")
|
|
return 1
|
|
|
|
egg_info_dir = project_root / "agravity_client.egg-info"
|
|
if egg_info_dir.exists():
|
|
try:
|
|
shutil.rmtree(egg_info_dir)
|
|
print(f"✓ Removed {egg_info_dir}")
|
|
except OSError as e:
|
|
print(f"✗ Failed to remove {egg_info_dir}: {e}")
|
|
return 1
|
|
|
|
# Build wheel and sdist
|
|
print("\n" + "-" * 70)
|
|
print("Building distributions...")
|
|
print("-" * 70 + "\n")
|
|
|
|
try:
|
|
# Use python -m build for modern approach
|
|
result = subprocess.run(
|
|
[sys.executable, "-m", "build"],
|
|
cwd=project_root,
|
|
check=False
|
|
)
|
|
|
|
if result.returncode != 0:
|
|
print("\n✗ Build failed")
|
|
print("\nTrying alternative build method...")
|
|
|
|
# Fallback to direct setuptools invocation
|
|
result = subprocess.run(
|
|
[sys.executable, "setup.py", "sdist", "bdist_wheel"],
|
|
cwd=project_root,
|
|
check=False
|
|
)
|
|
|
|
if result.returncode != 0:
|
|
print("\n✗ Build failed with fallback method")
|
|
return 1
|
|
except FileNotFoundError:
|
|
# If 'build' module not available, use setup.py
|
|
print("Using setuptools directly...\n")
|
|
result = subprocess.run(
|
|
[sys.executable, "setup.py", "sdist", "bdist_wheel"],
|
|
cwd=project_root,
|
|
check=False
|
|
)
|
|
|
|
if result.returncode != 0:
|
|
print("\n✗ Build failed")
|
|
return 1
|
|
|
|
# Verify build output
|
|
print("\n" + "-" * 70)
|
|
print("Build Results")
|
|
print("-" * 70 + "\n")
|
|
|
|
if not dist_dir.exists():
|
|
print("✗ dist directory not created")
|
|
return 1
|
|
|
|
wheels = list(dist_dir.glob("*.whl"))
|
|
sdists = list(dist_dir.glob("*.tar.gz"))
|
|
|
|
if not wheels and not sdists:
|
|
print("✗ No distributions created")
|
|
return 1
|
|
|
|
print("✓ Build successful!\n")
|
|
|
|
if wheels:
|
|
print("Wheels:")
|
|
for wheel in wheels:
|
|
size_mb = wheel.stat().st_size / (1024 * 1024)
|
|
print(f" • {wheel.name} ({size_mb:.2f} MB)")
|
|
|
|
if sdists:
|
|
print("\nSource Distributions:")
|
|
for sdist in sdists:
|
|
size_mb = sdist.stat().st_size / (1024 * 1024)
|
|
print(f" • {sdist.name} ({size_mb:.2f} MB)")
|
|
|
|
print(f"\n✓ Distributions saved to: {dist_dir}")
|
|
|
|
# Installation instructions
|
|
print("\n" + "-" * 70)
|
|
print("Installation Instructions")
|
|
print("-" * 70 + "\n")
|
|
|
|
if wheels:
|
|
wheel = wheels[0]
|
|
print(f"Install the wheel locally:\n")
|
|
print(f" pip install {dist_dir / wheel.name}\n")
|
|
|
|
print(f"Or upload to PyPI:\n")
|
|
print(f" pip install twine")
|
|
print(f" twine upload dist/*\n")
|
|
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|