-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewBuild.py
75 lines (60 loc) · 2.42 KB
/
newBuild.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# flake8: noqa: E501
# create a new build for the project
import os
import re
def updated_version(old_version):
# old_version = old_version.split('.')
major_release, minor_release, revision = (int(i) for i in old_version.split("."))
# if revision < 30:
# revision += 1
# else:
# revision = 0
# if minor_release < 30:
# minor_release += 1
# else:
# minor_release = 0
# major_release += 1
revision += 1
return f"{major_release}.{minor_release}.{revision}"
# update the version in the setup.py file
with open("setup.py", "r") as f:
data = f.read()
# read the version number from the setup.py file
VERSION = re.search(r'VERSION = "(.*?)"', data).group(1)
print("[info]", "old version", VERSION)
FOLDER_NAME = re.search(r'name="(.*?)"', data).group(1)
print("[info]", "FOLDER_NAME ", FOLDER_NAME)
# update the version number
NEW_VERSION = updated_version(VERSION)
print("[info]", "new version", NEW_VERSION)
data = data.replace(f'VERSION = "{VERSION}"', f'VERSION = "{NEW_VERSION}"')
isUpdated = re.search(r'VERSION = "(.*?)"', data).group(1)
print("[info]", "updated version", isUpdated)
# update the package list
all_packages_old = re.search(r"install_requires=\[([\s\S]*?)\]", data).group(1)
# print(all_packages_old)
install_requires = [
i.replace("\n", "").replace("==", ">=")
for i in open("requirements.txt", "r").readlines()
]
data = data.replace(
f"install_requires=[{all_packages_old}]", f"install_requires={install_requires}"
)
with open("setup.py", "w") as f:
f.write(data)
# remove the old build from the dist folder
print(
"[info]", "deleting old build", f"{os.getcwd()}/dist/{FOLDER_NAME}-{VERSION}.tar.gz"
)
os.system(f"rm {os.getcwd()}/dist/{FOLDER_NAME}-{VERSION}.tar.gz")
# convert the README.md to README.rst
print("[info]", "converting README.md to README.rst")
os.system("pandoc --from=markdown --to=rst --output=README.rst README.md")
# create a new build
print("[info]", "creating new build")
os.system(f"python3 setup.py sdist")
# upload to test pypi using twine
print("[info]", "uploading to test pypi")
# os.system(f'twine upload --repository testpypi dist/{FOLDER_NAME}-{NEW_VERSION}.tar.gz')
# os.system(f"twine upload dist/{FOLDER_NAME}-{NEW_VERSION}.tar.gz --verbose")
os.system(f"twine upload dist/{FOLDER_NAME}-{NEW_VERSION}.tar.gz ")