Repository navigation
Expand file tree
/
Copy pathbuild_release.py
More file actions
78 lines (61 loc) · 2.3 KB
/
Copy pathbuild_release.py
File metadata and controls
78 lines (61 loc) · 2.3 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
""" This is essentially a makefile for the carat release artifact(s) """
import os
import shutil
# --- Configuration ---
RELEASE_NAME = "Carat_Beta_4.1"
DIST_DIR = "dist"
BUILD_DIR = os.path.join(DIST_DIR, RELEASE_NAME)
FILES_TO_INCLUDE = [
"carat.bat",
"carat.command",
"requirements.txt",
"LICENSE",
"README.md"
]
DIRS_TO_INCLUDE = ["src"]
def clean_build_environment():
"""Wipes the old dist folder to ensure a clean build."""
print(f"[*] Cleaning old build directory: {DIST_DIR}/")
if os.path.exists(DIST_DIR):
shutil.rmtree(DIST_DIR)
os.makedirs(BUILD_DIR)
def copy_release_assets():
"""Copies only the whitelisted files/folders, ignoring python cache."""
print("[*] Copying release assets...")
for file in FILES_TO_INCLUDE:
if os.path.exists(file):
shutil.copy2(file, BUILD_DIR)
print(f" + Copied {file}")
else:
print(f" - Warning: {file} not found, skipping.")
for d in DIRS_TO_INCLUDE:
if os.path.exists(d):
# Extract just the folder name (e.g., 'src') for the destination
dest_dir = os.path.join(BUILD_DIR, os.path.basename(d))
shutil.copytree(
d,
dest_dir,
ignore=shutil.ignore_patterns(
'__pycache__',
'*.pyc',
'.DS_Store',
'dist', # <-- Prevents recursion if dist is nested
'.venv' # <-- Prevents copying the massive virtual env
)
)
print(f" + Copied {os.path.basename(d)}/ directory")
def create_zip_archive():
"""Zips the build directory into a redistributable file."""
zip_filename = os.path.join(DIST_DIR, RELEASE_NAME)
print(f"[*] Compressing into {zip_filename}.zip...")
# make_archive automatically adds the .zip extension
shutil.make_archive(zip_filename, 'zip', DIST_DIR, RELEASE_NAME)
if __name__ == "__main__":
print("==================================")
print(" Building Carat Release Zip")
print("==================================")
clean_build_environment()
copy_release_assets()
create_zip_archive()
print("==================================")
print(f"[SUCCESS] Release ready at: {DIST_DIR}/{RELEASE_NAME}.zip")