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to PyPI.
|
| 4 |
+
|
| 5 |
+
Prerequisites:
|
| 6 |
+
pip install build twine
|
| 7 |
+
|
| 8 |
+
Usage:
|
| 9 |
+
python build_and_publish.py # Build + publish
|
| 10 |
+
python build_and_publish.py --build-only # Build only, don't publish
|
| 11 |
+
python build_and_publish.py --check # Build + twine check, don't publish
|
| 12 |
+
|
| 13 |
+
Environment:
|
| 14 |
+
PYPI_TOKEN β PyPI API token (or pass as argument)
|
| 15 |
+
"""
|
| 16 |
+
import os
|
| 17 |
+
import sys
|
| 18 |
+
import shutil
|
| 19 |
+
import subprocess
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def run(cmd, **kwargs):
|
| 23 |
+
"""Run a command and check for errors."""
|
| 24 |
+
print(f" $ {cmd}")
|
| 25 |
+
result = subprocess.run(cmd, shell=True, **kwargs)
|
| 26 |
+
if result.returncode != 0:
|
| 27 |
+
print(f" β Command failed with exit code {result.returncode}")
|
| 28 |
+
sys.exit(1)
|
| 29 |
+
return result
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def main():
|
| 33 |
+
build_only = "--build-only" in sys.argv
|
| 34 |
+
check_only = "--check" in sys.argv
|
| 35 |
+
|
| 36 |
+
# Get PyPI token
|
| 37 |
+
pypi_token = os.environ.get("PYPI_TOKEN", "")
|
| 38 |
+
if not build_only and not check_only:
|
| 39 |
+
# Try to get from command line args
|
| 40 |
+
for arg in sys.argv:
|
| 41 |
+
if arg.startswith("pypi-"):
|
| 42 |
+
pypi_token = arg
|
| 43 |
+
break
|
| 44 |
+
if not pypi_token:
|
| 45 |
+
print("β οΈ No PyPI token found. Set PYPI_TOKEN env var or pass as argument.")
|
| 46 |
+
print(" Usage: python build_and_publish.py pypi-AgE...")
|
| 47 |
+
if not build_only:
|
| 48 |
+
sys.exit(1)
|
| 49 |
+
|
| 50 |
+
# Verify version
|
| 51 |
+
print("\nβββ Step 1: Verify version βββ")
|
| 52 |
+
sys.path.insert(0, ".")
|
| 53 |
+
import purpose_agent
|
| 54 |
+
version = purpose_agent.__version__
|
| 55 |
+
print(f" Version: {version}")
|
| 56 |
+
if version != "3.0.0":
|
| 57 |
+
print(f" β Version is {version}, expected 3.0.0!")
|
| 58 |
+
sys.exit(1)
|
| 59 |
+
print(f" β
Version confirmed: {version}")
|
| 60 |
+
|
| 61 |
+
# Verify imports
|
| 62 |
+
print("\nβββ Step 2: Verify imports βββ")
|
| 63 |
+
missing = [n for n in purpose_agent.__all__ if not hasattr(purpose_agent, n)]
|
| 64 |
+
if missing:
|
| 65 |
+
print(f" β Missing exports: {missing}")
|
| 66 |
+
sys.exit(1)
|
| 67 |
+
print(f" β
All {len(purpose_agent.__all__)} exports importable")
|
| 68 |
+
|
| 69 |
+
# Clean old builds
|
| 70 |
+
print("\nβββ Step 3: Clean old builds βββ")
|
| 71 |
+
for path in ["dist", "build", "*.egg-info"]:
|
| 72 |
+
if os.path.exists(path):
|
| 73 |
+
shutil.rmtree(path)
|
| 74 |
+
print(f" Removed: {path}")
|
| 75 |
+
# Also clean any .egg-info in current dir
|
| 76 |
+
for item in os.listdir("."):
|
| 77 |
+
if item.endswith(".egg-info"):
|
| 78 |
+
shutil.rmtree(item)
|
| 79 |
+
print(f" Removed: {item}")
|
| 80 |
+
print(" β
Cleaned")
|
| 81 |
+
|
| 82 |
+
# Build
|
| 83 |
+
print("\nβββ Step 4: Build sdist + wheel βββ")
|
| 84 |
+
run("python -m build")
|
| 85 |
+
|
| 86 |
+
# List artifacts
|
| 87 |
+
print("\n Artifacts:")
|
| 88 |
+
if os.path.exists("dist"):
|
| 89 |
+
for f in os.listdir("dist"):
|
| 90 |
+
size = os.path.getsize(os.path.join("dist", f))
|
| 91 |
+
print(f" {f} ({size:,} bytes)")
|
| 92 |
+
|
| 93 |
+
# Twine check
|
| 94 |
+
print("\nβββ Step 5: Twine check βββ")
|
| 95 |
+
run("twine check dist/*")
|
| 96 |
+
|
| 97 |
+
if check_only:
|
| 98 |
+
print("\n β
Build + check complete. Not publishing (use without --check).")
|
| 99 |
+
return
|
| 100 |
+
|
| 101 |
+
if build_only:
|
| 102 |
+
print("\n β
Build complete. Not publishing (use without --build-only).")
|
| 103 |
+
return
|
| 104 |
+
|
| 105 |
+
# Publish
|
| 106 |
+
print("\nβββ Step 6: Publish to PyPI βββ")
|
| 107 |
+
print(f" Package: purpose-agent=={version}")
|
| 108 |
+
print(f" Target: https://pypi.org/project/purpose-agent/")
|
| 109 |
+
print()
|
| 110 |
+
|
| 111 |
+
run(
|
| 112 |
+
f'twine upload dist/* '
|
| 113 |
+
f'--username __token__ '
|
| 114 |
+
f'--password "{pypi_token}"'
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
# Verify
|
| 118 |
+
print("\nβββ Step 7: Verify on PyPI βββ")
|
| 119 |
+
print(f" Waiting 10s for PyPI to index...")
|
| 120 |
+
subprocess.run(["sleep", "10"])
|
| 121 |
+
|
| 122 |
+
print(f" Installing from PyPI...")
|
| 123 |
+
run(f'pip install purpose-agent=={version}')
|
| 124 |
+
|
| 125 |
+
result = subprocess.run(
|
| 126 |
+
['python', '-c', f'''
|
| 127 |
+
import purpose_agent as pa
|
| 128 |
+
print(f" v{{pa.__version__}} β {{len(pa.__all__)}} exports")
|
| 129 |
+
assert pa.__version__ == "{version}", f"Version mismatch: {{pa.__version__}}"
|
| 130 |
+
'''],
|
| 131 |
+
capture_output=True, text=True,
|
| 132 |
+
)
|
| 133 |
+
print(result.stdout)
|
| 134 |
+
if result.returncode != 0:
|
| 135 |
+
print(f" β οΈ Verification failed: {result.stderr}")
|
| 136 |
+
else:
|
| 137 |
+
print(" β
PyPI install verified!")
|
| 138 |
+
|
| 139 |
+
print(f"\n{'='*60}")
|
| 140 |
+
print(f" β
purpose-agent=={version} PUBLISHED TO PYPI!")
|
| 141 |
+
print(f" π¦ https://pypi.org/project/purpose-agent/{version}/")
|
| 142 |
+
print(f" π¦ https://huggingface.co/Rohan03/purpose-agent")
|
| 143 |
+
print(f"{'='*60}")
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
if __name__ == "__main__":
|
| 147 |
+
main()
|