-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild_release.py
More file actions
64 lines (50 loc) · 2.03 KB
/
build_release.py
File metadata and controls
64 lines (50 loc) · 2.03 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
import os
import shutil
import re
import subprocess
import sys
def build_release():
print("Starting Production Build...")
# 1. Backup local README
if os.path.exists("README.md"):
shutil.copy2("README.md", "README.md.bak")
print("Backed up README.md")
try:
# 2. Prepare PyPI README
with open("README.md", "r", encoding="utf-8") as f:
content = f.read()
# Base URL for assets
base_url = "https://github.com/oop7/OrChat/raw/main/branding/"
# Function to fix paths matches by regex
def path_fixer(match):
full_match = match.group(0)
# Convert backslashes to forward slashes for URL compatibility
fixed = full_match.replace("\\", "/")
# Prepend the absolute URL
return fixed.replace("branding/", base_url)
# Regex: matches "branding" followed by backslash or slash, then characters until quote, closing paren, or space
# This captures paths like: branding\screenshots\main.png
pattern = r"branding[\\/][^\"')\s]+"
new_content = re.sub(pattern, path_fixer, content)
with open("README.md", "w", encoding="utf-8") as f:
f.write(new_content)
print("Modified README.md for PyPI (Absolute URLs)")
# 3. Clean previous builds
for folder in ["dist", "build", "orchat.egg-info"]:
if os.path.exists(folder):
shutil.rmtree(folder)
# 4. Run Build
print("Building Wheel...")
subprocess.check_call([sys.executable, "-m", "build"])
except Exception as e:
print(f"Error during build: {e}")
sys.exit(1)
finally:
# 5. Restore README
if os.path.exists("README.md.bak"):
# Force move back, overwriting the modified one
shutil.move("README.md.bak", "README.md")
print("Restored original README.md")
print("Build Complete. Artifacts are in the /dist folder.")
if __name__ == "__main__":
build_release()