forked from GuiPimenta-Dev/lambda-forge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.py
57 lines (44 loc) · 1.75 KB
/
deploy.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
55
56
57
import os
import re
import shutil
import subprocess
def read_version():
"""Reads the version from setup.py."""
with open("setup.py", "r") as file:
content = file.read()
version_match = re.search(r"version=['\"]([^'\"]+)['\"]", content)
if version_match:
return version_match[1]
return None
def increment_version(version):
"""Increments the patch number in the version."""
major, minor, patch = map(int, version.split("."))
return f"{major}.{minor}.{patch + 1}"
def update_setup_py(new_version):
"""Updates the setup.py file with the new version."""
with open("setup.py", "r") as file:
content = file.read()
content = re.sub(r"(version=['\"])([^'\"]+)(['\"])", rf"\g<1>{new_version}\3", content)
with open("setup.py", "w") as file:
file.write(content)
def build_and_upload():
# Check if the dist directory exists and remove it
dist_path = "dist"
if os.path.exists(dist_path) and os.path.isdir(dist_path):
shutil.rmtree(dist_path)
print(f"Removed existing {dist_path} directory.")
"""Builds the package and uploads it to TestPyPI."""
subprocess.run(["python", "setup.py", "sdist", "bdist_wheel"], check=True)
subprocess.run(["twine", "upload", "--repository", "pypi", "dist/*"], check=True)
def main():
current_version = read_version()
if current_version is None:
raise Exception("Could not read the current version from setup.py.")
new_version = increment_version(current_version)
print(f"Updating version: {current_version} -> {new_version}")
update_setup_py(new_version)
print("Building and uploading the package to TestPyPI...")
build_and_upload()
print("Done.")
if __name__ == "__main__":
main()