-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpypi_upload.py
More file actions
executable file
·45 lines (37 loc) · 1.09 KB
/
pypi_upload.py
File metadata and controls
executable file
·45 lines (37 loc) · 1.09 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
import glob
import os
import subprocess
import sys
from pypi_helper import uncommitted_changes
def main():
if uncommitted_changes():
return
# Load environment variables from .env
with open(".env") as f:
for line in f:
line = line.strip()
if not line or line.startswith("#"):
continue
if "=" in line:
key, value = line.split("=", 1)
os.environ[key] = value
# Remove all files in dist/
dist_files = glob.glob("dist/*")
for file in dist_files:
os.remove(file)
# Build the package
try:
subprocess.run([sys.executable, "-m", "build"], check=True)
except subprocess.CalledProcessError as e:
sys.exit(e.returncode)
# Upload the package to PyPI
dist_files = glob.glob("dist/*")
if dist_files:
subprocess.run(
[sys.executable, "-m", "twine", "upload"] + dist_files, check=True
)
subprocess.run(["git", "push"])
else:
print("No files found in dist/ to upload.")
if __name__ == "__main__":
main()