forked from ServiceStack/llms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish.py
More file actions
executable file
·142 lines (126 loc) · 4.45 KB
/
Copy pathpublish.py
File metadata and controls
executable file
·142 lines (126 loc) · 4.45 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python3
"""
Script to help publish the llms-py package to PyPI.
Usage:
python publish.py --test # Upload to TestPyPI
python publish.py --prod # Upload to PyPI
python publish.py --build # Just build the package
"""
import subprocess
import sys
import os
import argparse
def run_command(cmd, check=True):
"""Run a shell command and return the result."""
print(f"Running: {cmd}")
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
if check and result.returncode != 0:
print(f"Error running command: {cmd}")
print(f"stdout: {result.stdout}")
print(f"stderr: {result.stderr}")
sys.exit(1)
return result
def clean_build():
"""Clean previous build artifacts."""
print("Cleaning previous build artifacts...")
run_command("rm -rf build/ dist/ *.egg-info/", check=False)
def build_package():
"""Build the package."""
print("Building package...")
run_command("python -m build")
def upload_to_testpypi():
"""Upload to TestPyPI."""
print("Uploading to TestPyPI...")
run_command("python -m twine upload --repository testpypi dist/* --verbose")
def upload_to_pypi():
"""Upload to PyPI."""
print("Uploading to PyPI...")
run_command("python -m twine upload dist/*")
def check_dependencies():
"""Check if required tools are installed."""
try:
import build
import twine
except ImportError as e:
print(f"Missing dependency: {e}")
print("Please install required dependencies:")
print("pip install build twine")
sys.exit(1)
def bump_version():
"""
Bump the package version.
This function should implement version bumping logic by
- extracting version from pyproject.toml
- incrementing patch version
- Use string search/replace to replace old version with new version in:
- llms/ui/ai.mjs
- llms/main.py
- setup.py
- pyproject.toml
"""
print("Bumping package version...")
import re
version_file = "pyproject.toml"
with open(version_file, "r") as f:
content = f.read()
version = re.search(r"version = \"(\d+\.\d+\.\d+)\"", content).group(1)
print(f"Current version: {version}")
major, minor, patch = map(int, version.split("."))
patch += 1
new_version = f"{major}.{minor}.{patch}"
print(f"New version: {new_version}")
content = content.replace(version, new_version)
with open(version_file, "w") as f:
f.write(content)
# Update other files
files_to_update = [
"llms/ui/ai.mjs",
"llms/main.py",
"setup.py"
]
for file in files_to_update:
with open(file, "r") as f:
content = f.read()
content = content.replace(version, new_version)
with open(file, "w") as f:
f.write(content)
print("Version bumped successfully.")
# Create git commit and tag
run_command(f'git commit -am "Bump version to {new_version}"')
run_command(f'git tag v{new_version}')
run_command("git push --tags")
run_command("git push")
def main():
parser = argparse.ArgumentParser(description="Publish llms-py package to PyPI")
parser.add_argument("--bump", action="store_true", help="Bump the package version")
parser.add_argument("--test", action="store_true", help="Upload to TestPyPI")
parser.add_argument("--prod", action="store_true", help="Upload to PyPI")
parser.add_argument("--build", action="store_true", help="Just build the package")
args = parser.parse_args()
if not any([args.bump, args.test, args.prod, args.build]):
parser.print_help()
sys.exit(1)
check_dependencies()
clean_build()
build_package()
if args.bump:
bump_version()
elif args.test:
upload_to_testpypi()
print("\nPackage uploaded to TestPyPI!")
print("You can test install with:")
print("pip install --index-url https://test.pypi.org/simple/ llms-py")
elif args.prod:
upload_to_pypi()
print("\nPackage uploaded to PyPI!")
print("You can install with:")
print("pip install llms-py")
print("\nUpgrade with:")
print("pip install llms-py --upgrade")
else:
print("\nPackage built successfully!")
print("Files created in dist/:")
for file in os.listdir("dist"):
print(f" {file}")
if __name__ == "__main__":
main()