-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathpublish.py
54 lines (43 loc) · 1.4 KB
/
publish.py
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
#!/usr/bin/env python3
import argparse
import subprocess
import sys
def run_command(command):
process = subprocess.run(command, shell=True, check=True)
return process.returncode
def main():
parser = argparse.ArgumentParser(description="Publish package to PyPI or TestPyPI")
parser.add_argument("version", help="Version to publish (e.g., 0.2.0)")
parser.add_argument(
"--production",
"-p",
action="store_true",
help="Publish to PyPI instead of TestPyPI",
)
args = parser.parse_args()
version = args.version
if not version.startswith("v"):
version = f"v{version}"
# Default repository is TestPyPI
twine_command = "twine upload --repository testpypi dist/*"
if args.production:
twine_command = "twine upload dist/*"
commands = [
f"git tag {version}",
f"git push origin {version}",
"rm -rf dist/ build/ *.egg-info",
"python -m build",
twine_command,
]
for command in commands:
print(f"Executing: {command}")
try:
run_command(command)
except subprocess.CalledProcessError as e:
print(f"Error executing command: {command}")
print(f"Error: {e}")
sys.exit(1)
repo = "PyPI" if args.production else "TestPyPI"
print(f"Successfully published version {version} to {repo}")
if __name__ == "__main__":
main()