-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpackage.py
28 lines (22 loc) · 1006 Bytes
/
package.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
import os.path
import re
import subprocess
import sys
version = [line for line in open("pyproject.toml", "r").readlines() if line.startswith("version =")][0][11:-2]
if os.path.isdir("dist"):
files = os.listdir("dist")
if len(files) > 0:
match = re.search(r"\w+-(\d+\.\d+\.\d+)", files[0])
if match is not None:
last_build_version = match.group(1)
if version == last_build_version:
input(f"pyproject.toml has same version ({version}) as last build. If PyPi already has this version, "
f"this will cause an error. Continue?")
if sys.platform == "win32":
subprocess.run(["rmdir", "/q", "/s", "dist"], shell=True) # delete 'dist' directory
else:
subprocess.run(["rm", "-rf", "dist"])
print(f"Version {version}")
python = "python" if sys.platform == "win32" else "python3"
subprocess.run([python, "-m", "build"]) # build package
subprocess.run(["twine", "upload", "dist/*"]) # upload package