Skip to content

Commit 8ee14d3

Browse files
dev-swarupclaude
andcommitted
build: ship one zip for every platform
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 35c4985 commit 8ee14d3

3 files changed

Lines changed: 34 additions & 66 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ jobs:
3131
run: |
3232
pip install uv
3333
python scripts/vendor_wheels.py
34-
- name: Build per-platform zips
34+
- name: Build the zip
3535
run: python scripts/build.py --blender "$BLENDER"
3636
- uses: actions/upload-artifact@v4
3737
with:
38-
name: blender_ai-zips
38+
name: blender_ai-zip
3939
path: dist/*.zip
4040
if-no-files-found: error
4141
- name: Attach to the GitHub release

‎scripts/build.py‎

Lines changed: 32 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
"""Build the installable extension zips with Blender's own builder.
1+
"""Build the installable extension zip with Blender's own builder: one zip for every platform.
22
3-
python scripts/build.py # every platform -> dist/
4-
python scripts/build.py --platform windows-x64 # one platform, for local testing
3+
python scripts/build.py # -> dist/blender_ai-<version>.zip
4+
python scripts/build.py --vendor # download the wheels first
55
python scripts/build.py --blender "C:/Program Files/Blender Foundation/Blender 5.2/blender.exe"
66
7-
Steps: stage src/ into build/, write the `wheels` list for the bundled wheels into the
8-
staged manifest, then run `blender --command extension build --split-platforms` and validate.
7+
Steps: stage src/ into build/, list every bundled wheel in the staged manifest (with the platforms those
8+
wheels cover), then run `blender --command extension build` and validate. On install, Blender extracts
9+
only the wheels that match the user's platform and Python version.
910
"""
1011

1112
from __future__ import annotations
@@ -19,24 +20,16 @@
1920
import zipfile
2021
from pathlib import Path
2122

23+
from vendor_wheels import PLATFORM_TAGS
24+
2225
ROOT = Path(__file__).resolve().parent.parent
2326
SOURCE = ROOT / "src"
2427
STAGE = ROOT / "build" / "blender_ai"
2528
DIST = ROOT / "dist"
2629

27-
sys.path.insert(0, str(ROOT / "scripts"))
28-
from vendor_wheels import PLATFORM_TAGS
29-
3030
WINDOWS_SITE_PACKAGES_LEN = 110
3131
WINDOWS_MAX_PATH = 259
3232

33-
WHEEL_PLATFORM_MARKERS = {
34-
"windows-x64": ("win_amd64",),
35-
"linux-x64": ("manylinux", "linux_x86_64"),
36-
"macos-arm64": ("arm64", "universal2"),
37-
"macos-x64": ("x86_64", "universal2"),
38-
}
39-
4033

4134
def find_blender(explicit: str | None) -> str:
4235
candidates = [explicit, os.environ.get("BLENDER")]
@@ -52,79 +45,56 @@ def find_blender(explicit: str | None) -> str:
5245
raise SystemExit("Blender not found; pass --blender or set BLENDER.")
5346

5447

55-
def wheel_matches(name: str, platforms: list[str]) -> bool:
56-
tag = name[:-4].split("-")[-1]
57-
if tag == "any":
58-
return True
59-
for platform in platforms:
60-
markers = WHEEL_PLATFORM_MARKERS[platform]
61-
if platform == "macos-x64" and "macosx" not in tag:
62-
continue
63-
if platform == "macos-arm64" and "macosx" not in tag:
64-
continue
65-
if any(m in tag for m in markers):
66-
return True
67-
return False
48+
def covered_platforms(wheels: list[str]) -> list[str]:
49+
tags = [name[:-4].split("-")[-1] for name in wheels if name.startswith("pydantic_core-")]
50+
return [platform for platform, markers in PLATFORM_TAGS.items() if any(m in tag for tag in tags for m in markers)]
6851

6952

70-
def stage(platforms: list[str]) -> list[str]:
53+
def stage() -> tuple[list[str], list[str]]:
7154
if STAGE.exists():
7255
shutil.rmtree(STAGE)
73-
shutil.copytree(SOURCE, STAGE, ignore=shutil.ignore_patterns("__pycache__", "*.pyc", "*.whl"))
74-
wheels = sorted(p for p in (SOURCE / "wheels").glob("*.whl") if wheel_matches(p.name, platforms))
75-
if not wheels:
76-
raise SystemExit("No wheels vendored; run scripts/vendor_wheels.py first.")
77-
(STAGE / "wheels").mkdir(exist_ok=True)
78-
for whl in wheels:
79-
shutil.copy2(whl, STAGE / "wheels" / whl.name)
80-
56+
shutil.copytree(SOURCE, STAGE, ignore=shutil.ignore_patterns("__pycache__", "*.pyc"))
57+
wheels = sorted(p.name for p in (STAGE / "wheels").glob("*.whl"))
58+
platforms = covered_platforms(wheels)
59+
if not platforms:
60+
raise SystemExit("No wheels vendored for a supported platform; run scripts/vendor_wheels.py first.")
61+
listing = "".join(f' "./wheels/{name}",\n' for name in wheels)
62+
block = "platforms = [" + ", ".join(f'"{p}"' for p in platforms) + "]\nwheels = [\n" + listing + "]\n"
8163
manifest = (STAGE / "blender_manifest.toml").read_text(encoding="utf-8")
82-
listing = "wheels = [\n" + "".join(f' "./wheels/{w.name}",\n' for w in wheels) + "]\n"
83-
manifest = re.sub(r"(?m)^# The `wheels` list is written by scripts/build\.py.*\n", listing, manifest)
84-
manifest = re.sub(r"(?m)^platforms = \[.*\]$", "platforms = [" + ", ".join(f'"{p}"' for p in platforms) + "]", manifest)
64+
manifest = re.sub(r"(?m)^platforms = \[.*\]\n", lambda _match: block, manifest, count=1)
8565
(STAGE / "blender_manifest.toml").write_text(manifest, encoding="utf-8")
86-
return [w.name for w in wheels]
66+
return wheels, platforms
8767

8868

8969
def warn_long_paths(wheels: list[str]) -> None:
9070
longest, member = 0, ""
9171
for name in wheels:
92-
with zipfile.ZipFile(SOURCE / "wheels" / name) as zf:
72+
with zipfile.ZipFile(STAGE / "wheels" / name) as zf:
9373
for item in zf.namelist():
9474
if len(item) > longest:
9575
longest, member = len(item), item
96-
room = WINDOWS_MAX_PATH - WINDOWS_SITE_PACKAGES_LEN - longest
97-
if room < 25:
76+
if WINDOWS_MAX_PATH - WINDOWS_SITE_PACKAGES_LEN - longest < 25:
9877
print(f"WARNING: {member} is {longest} characters; Windows users with long profile paths may fail to install.")
9978

10079

10180
def main() -> int:
10281
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
103-
parser.add_argument("--platform", choices=sorted(PLATFORM_TAGS), action="append")
10482
parser.add_argument("--blender")
10583
parser.add_argument("--vendor", action="store_true", help="download wheels first")
10684
args = parser.parse_args()
107-
108-
platforms = args.platform or sorted(PLATFORM_TAGS)
10985
if args.vendor:
110-
cmd = [sys.executable, str(ROOT / "scripts" / "vendor_wheels.py")]
111-
for p in platforms:
112-
cmd += ["--platform", p]
113-
subprocess.run(cmd, check=True)
114-
86+
subprocess.run([sys.executable, str(ROOT / "scripts" / "vendor_wheels.py")], check=True)
11587
blender = find_blender(args.blender)
116-
wheels = stage(platforms)
88+
wheels, platforms = stage()
11789
print(f"Staged {len(wheels)} wheels for {', '.join(platforms)}")
118-
if "windows-x64" in platforms:
119-
warn_long_paths(wheels)
90+
warn_long_paths(wheels)
12091
DIST.mkdir(exist_ok=True)
121-
build = [blender, "--factory-startup", "--command", "extension", "build", "--source-dir", str(STAGE), "--output-dir", str(DIST)]
122-
if len(platforms) > 1 or args.platform:
123-
build.append("--split-platforms")
124-
subprocess.run(build, check=True)
125-
for zip_path in sorted(DIST.glob("blender_ai-*.zip")):
126-
subprocess.run([blender, "--factory-startup", "--command", "extension", "validate", str(zip_path)], check=True)
127-
print(f"Built {zip_path.relative_to(ROOT)} ({zip_path.stat().st_size / 1e6:.1f} MB)")
92+
for old in DIST.glob("blender_ai-*.zip"):
93+
old.unlink()
94+
subprocess.run([blender, "--factory-startup", "--command", "extension", "build", "--source-dir", str(STAGE), "--output-dir", str(DIST)], check=True)
95+
zip_path = next(DIST.glob("blender_ai-*.zip"))
96+
subprocess.run([blender, "--factory-startup", "--command", "extension", "validate", str(zip_path)], check=True)
97+
print(f"Built {zip_path.relative_to(ROOT)} ({zip_path.stat().st_size / 1e6:.1f} MB)")
12898
return 0
12999

130100

‎src/blender_manifest.toml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ copyright = ["2026 Swarup B."]
1616

1717
platforms = ["windows-x64", "macos-arm64", "macos-x64", "linux-x64"]
1818

19-
# The `wheels` list is written by scripts/build.py from the wheels vendored for each platform.
20-
2119
[permissions]
2220
network = "Talk to your AI provider, generate images, fetch models, use MCP"
2321
files = "Save textures and downloaded models, start your MCP servers"

0 commit comments

Comments
 (0)