1+ #!/usr/bin/env python3
2+ """
3+ Test script for PyPI release process
4+ """
5+
6+ import os
7+ import subprocess
8+ import sys
9+
10+ def run_command (cmd , description ):
11+ """Run a command and handle errors"""
12+ print (f"\n { description } ..." )
13+ print (f"Running: { cmd } " )
14+
15+ try :
16+ result = subprocess .run (cmd , shell = True , check = True , capture_output = True , text = True )
17+ print (f"✓ { description } successful" )
18+ if result .stdout :
19+ print (f"Output: { result .stdout } " )
20+ return True
21+ except subprocess .CalledProcessError as e :
22+ print (f"✗ { description } failed" )
23+ print (f"Error: { e .stderr } " )
24+ return False
25+
26+ def main ():
27+ print ("Testing PyPI release process..." )
28+
29+ # Step 1: Build the package
30+ if not run_command ("python -m build" , "Building package" ):
31+ return False
32+
33+ # Step 2: Check the built files
34+ if not os .path .exists ("dist/" ):
35+ print ("✗ Build directory not found" )
36+ return False
37+
38+ files = os .listdir ("dist/" )
39+ print (f"✓ Built files: { files } " )
40+
41+ # Step 3: Check package with twine
42+ if not run_command ("twine check dist/*" , "Checking package with twine" ):
43+ return False
44+
45+ # Step 4: Test upload to TestPyPI (dry run)
46+ print ("\n Testing upload to TestPyPI (dry run)..." )
47+ print ("Note: This requires TEST_PYPI_API_TOKEN to be set" )
48+
49+ test_pypi_token = os .getenv ("TEST_PYPI_API_TOKEN" )
50+ if not test_pypi_token :
51+ print ("⚠ TEST_PYPI_API_TOKEN not set - skipping upload test" )
52+ print ("To test upload, set TEST_PYPI_API_TOKEN environment variable" )
53+ return True
54+
55+ # Test upload to TestPyPI
56+ upload_cmd = "twine upload --repository testpypi --verbose dist/*"
57+ if not run_command (upload_cmd , "Uploading to TestPyPI" ):
58+ return False
59+
60+ print ("\n ✓ PyPI release process test completed successfully!" )
61+ return True
62+
63+ if __name__ == "__main__" :
64+ success = main ()
65+ sys .exit (0 if success else 1 )
0 commit comments