-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpublish.py
More file actions
43 lines (34 loc) · 1.21 KB
/
publish.py
File metadata and controls
43 lines (34 loc) · 1.21 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
#!/usr/bin/env python
"""Script to build and publish the package to PyPI using UV."""
import glob
import os
import shutil
import subprocess
import sys
def run_command(command: str) -> subprocess.CompletedProcess:
"""Run a shell command and print output."""
print(f"Running: {command}")
result = subprocess.run(command, shell=True, check=True)
return result
def main() -> None:
"""Build and publish the package using UV."""
# Clean previous builds
for path in ("dist", "build"):
if os.path.isdir(path):
shutil.rmtree(path)
for egg_info in glob.glob("*.egg-info"):
if os.path.isdir(egg_info):
shutil.rmtree(egg_info)
# Build the package using UV
run_command("uv pip build .")
# Check if we should upload to PyPI
if len(sys.argv) > 1 and sys.argv[1] == "--publish":
# Upload to PyPI using UV
dist_files = glob.glob(os.path.join("dist", "*"))
if not dist_files:
raise RuntimeError("No dist artifacts found to publish")
run_command("uv pip publish " + " ".join(dist_files))
else:
print("Package built successfully. Run with --publish to upload to PyPI.")
if __name__ == "__main__":
main()