-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathpublish.py
More file actions
executable file
·186 lines (152 loc) · 5.76 KB
/
publish.py
File metadata and controls
executable file
·186 lines (152 loc) · 5.76 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/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 argparse
import os
import subprocess
import sys
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 get_current_version():
"""Get the current version from pyproject.toml."""
import re
version_file = "pyproject.toml"
with open(version_file, encoding="utf-8") as f:
content = f.read()
version = re.search(r"version = \"(\d+\.\d+\.\d+)\"", content).group(1)
return version
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, encoding="utf-8") 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", encoding="utf-8") 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, encoding="utf-8") as f:
content = f.read()
content = content.replace(version, new_version)
with open(file, "w", encoding="utf-8") 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 create_release():
"""
Create a GitHub Release using the latest version.
This should be run after bump_version().
"""
print("Creating GitHub Release...")
version = get_current_version()
tag = f"v{version}"
print(f"Creating release for version {version} (tag: {tag})")
# Create GitHub release using gh CLI
# The release notes will be auto-generated from commits
release_cmd = f'gh release create {tag} --title "Release {version}" --generate-notes'
run_command(release_cmd)
print(f"GitHub Release {version} created successfully!")
print(f"View at: https://github.com/ServiceStack/llms/releases/tag/{tag}")
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("--release", action="store_true", help="Create a GitHub Release (run after bump)")
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.release, args.test, args.prod, args.build]):
parser.print_help()
sys.exit(1)
# Release doesn't need build steps
if args.release:
create_release()
return
# revert ollama and lmstudio to disabled before release
run_command("./llms.sh --disable ollama lmstudio")
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()