Skip to content

Commit 62c0421

Browse files
Only package the libraries relevant to the platform (based on user feedback)
1 parent f943d14 commit 62c0421

4 files changed

Lines changed: 63 additions & 4 deletions

File tree

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
*.zip
2-
*.pyc
2+
*.pyc
3+
build
4+
dist
5+
lib3mf.egg-info

MANIFEST.in

Lines changed: 0 additions & 3 deletions
This file was deleted.

build_wheels.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import json
2+
import platform
3+
import subprocess
4+
import os
5+
6+
MANIFEST_FILE = "manifest.json"
7+
TEMP_MANIFEST_IN = "MANIFEST.in"
8+
9+
def get_platform_tag():
10+
"""Return the appropriate platform tag for wheel building."""
11+
system = platform.system()
12+
if system == "Linux":
13+
return "manylinux2014_x86_64"
14+
elif system == "Windows":
15+
return "win_amd64"
16+
elif system == "Darwin":
17+
return "macosx_10_9_universal2"
18+
else:
19+
raise RuntimeError(f"Unsupported platform: {system}")
20+
21+
def create_manifest():
22+
"""Generate MANIFEST.in with the relevant platform-specific file."""
23+
with open(MANIFEST_FILE, "r") as f:
24+
data = json.load(f)
25+
26+
system = platform.system().lower()
27+
file_to_include = data.get(system)
28+
29+
if not file_to_include:
30+
raise RuntimeError(f"No relevant file found for platform: {system}")
31+
32+
with open(TEMP_MANIFEST_IN, "w") as f:
33+
f.write(f"include {file_to_include}\n")
34+
35+
def build_wheel():
36+
"""Build the wheel using the platform-specific command with --python-tag py3."""
37+
plat_name = get_platform_tag()
38+
command = f"python setup.py bdist_wheel --python-tag py3 --plat-name {plat_name}"
39+
40+
print(f"Running: {command}")
41+
subprocess.run(command, shell=True, check=True)
42+
43+
def cleanup():
44+
"""Remove the MANIFEST.in file after building."""
45+
if os.path.exists(TEMP_MANIFEST_IN):
46+
os.remove(TEMP_MANIFEST_IN)
47+
print(f"Removed {TEMP_MANIFEST_IN}")
48+
49+
if __name__ == "__main__":
50+
create_manifest()
51+
try:
52+
build_wheel()
53+
finally:
54+
cleanup()

manifest.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"linux": "lib3mf/lib3mf.so",
3+
"windows": "lib3mf/lib3mf.dll",
4+
"macos": "lib3mf/lib3mf.dylib"
5+
}

0 commit comments

Comments
 (0)