-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload_pypi.py
53 lines (41 loc) · 1.44 KB
/
upload_pypi.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
import datetime
import os
import pytz
import re
import sys
def fix_version():
with open("pyproject.toml", "rt") as file:
pyproject = file.read()
with open("mpone/__init__.py", "rt") as file:
mpone = file.read()
pattern = "(?<=(__version__ = \")).*?(?=(\"))"
NOW_VERSION = re.search(pattern, mpone).group()
with open("pyproject.toml", "wt") as file:
pattern = "(?<=(version = \")).*?(?=(\"))"
if sys.platform.startswith("win32"):
pyproject = re.sub(pattern, NOW_VERSION, pyproject, count=1)
file.write(pyproject)
elif sys.platform.startswith("linux"):
version = datetime.datetime.now(tz=pytz.timezone('Asia/Shanghai')).strftime(".dev%Y%m%d%H%M")
pyproject = re.sub(pattern, NOW_VERSION + version, pyproject, count=1)
file.write(pyproject)
else:
raise NotImplementedError
def upload_win():
print("del old dist")
os.system("rmdir /q/s dist")
print("run: python -m build")
os.system("python -m build")
print("run: upload to pypi")
os.system("twine upload --repository pypi dist/*")
def upload_linux():
print("run: python -m build")
os.system("python -m build")
if __name__ == "__main__":
fix_version()
if sys.platform.startswith("win32"):
upload_win()
elif sys.platform.startswith("linux"):
upload_linux()
else:
raise NotImplementedError