-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.py
More file actions
85 lines (67 loc) · 2.14 KB
/
setup.py
File metadata and controls
85 lines (67 loc) · 2.14 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
import setuptools
import re
import requests
from bs4 import BeautifulSoup
package_name = "dimo-sdk"
def curr_version():
# 方法1:通过文件临时存储版本号
# with open('VERSION') as f:
# version_str = f.read()
# 方法2:从官网获取版本号
url = f"https://pypi.org/project/{package_name}/"
response = requests.get(url)
soup = BeautifulSoup(response.content, "html.parser")
latest_version = soup.select_one(".release__version").text.strip()
return str(latest_version)
def get_version():
# to integer
match = re.search(r"(\d+)\.(\d+)\.(\d+)", curr_version())
major = int(match.group(1))
minor = int(match.group(2))
patch = int(match.group(3))
# plus one
patch += 1
if patch > 9:
patch = 0
minor += 1
if minor > 9:
minor = 0
major += 1
new_version_str = f"{major}.{minor}.{patch}"
return new_version_str
def upload():
with open("README.md", "r") as fh:
long_description = fh.read()
with open('requirements.txt') as f:
required = f.read().splitlines()
setuptools.setup(
name=package_name,
version=get_version(),
author="moss",
author_email="yydfjt@gmail.com",
description="dimo sdk",
long_description=long_description,
long_description_content_type="text/markdown",
url=f"https://pypi.org/project/{package_name}/",
packages=setuptools.find_packages(),
data_files=["requirements.txt"],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.6',
install_requires=required,
)
def write_now_version():
print("Current VERSION:", get_version())
with open("VERSION", "w") as version_f:
version_f.write(get_version())
def main():
try:
upload()
print("Upload success , Current VERSION:", curr_version())
except Exception as e:
raise Exception("Upload package error", e)
if __name__ == '__main__':
main()