Extensions: fix building packages containing macos universal wheels

This commit is contained in:
Campbell Barton
2024-11-26 17:32:11 +11:00
parent 64b9dbe198
commit 093cb8bf43
2 changed files with 29 additions and 13 deletions

View File

@@ -2133,7 +2133,7 @@ def platform_from_this_system() -> str:
)
def blender_platform_from_wheel_platform(wheel_platform: str) -> str:
def blender_platforms_from_wheel_platform(wheel_platform: str) -> list[str]:
"""
Convert a wheel to a Blender compatible platform: e.g.
- ``linux_x86_64`` -> ``linux-x64``.
@@ -2142,13 +2142,14 @@ def blender_platform_from_wheel_platform(wheel_platform: str) -> str:
- ``win_amd64`` -> ``windows-x64``.
- ``macosx_11_0_arm64`` -> ``macos-arm64``.
- ``manylinux2014_x86_64`` -> ``linux-x64``.
- ``macosx_10_9_universal2`` -> ``macos-x64``, ``macos-arm64``.
"""
i = wheel_platform.find("_")
if i == -1:
# WARNING: this should never or almost never happen.
# Return the result as we don't have a better alternative.
return wheel_platform
return [wheel_platform]
head = wheel_platform[:i]
tail = wheel_platform[i + 1:]
@@ -2175,15 +2176,21 @@ def blender_platform_from_wheel_platform(wheel_platform: str) -> str:
# (only `x86_64` at the moment).
tail = tail.rpartition("_")[2]
return "{:s}-{:s}".format(head, tail)
if (head == "macos") and (tail == "universal2"):
tails = ["x64", "arm64"]
else:
tails = [tail]
return ["{:s}-{:s}".format(head, tail) for tail in tails]
def blender_platform_compatible_with_wheel_platform(platform: str, wheel_platform: str) -> bool:
assert platform
if wheel_platform == "any":
return True
platform_blender = blender_platform_from_wheel_platform(wheel_platform)
return platform == platform_blender
platforms_blender = blender_platforms_from_wheel_platform(wheel_platform)
return platform in platforms_blender
def blender_platform_compatible_with_wheel_platform_from_filepath(platform: str, wheel_filepath: str) -> bool:

View File

@@ -368,13 +368,22 @@ class TestCLI_Build(unittest.TestCase):
wheels = [
# Must be included in all packages.
"my_portable_package-3.0.1-py3-none-any.whl",
# Each package must include only one.
"my_platform_package-10.3.0-cp311-cp311-macosx_11_0_arm64.whl",
"my_platform_package-10.3.0-cp311-cp311-macosx_11_0_x86_64.whl",
"my_platform_package-10.3.0-cp311-cp311-manylinux_2_28_aarch64.whl",
"my_platform_package-10.3.0-cp311-cp311-manylinux_2_28_x86_64.whl",
"my_platform_package-10.3.0-cp311-cp311-win_amd64.whl",
"my_platform_package-10.3.0-cp311-cp311-win_arm64.whl",
# Include two versions (B may be a "universal" package) for platforms that support it.
"my_platform_package_A-10.3.0-cp311-cp311-macosx_11_0_arm64.whl",
"my_platform_package_A-10.3.0-cp311-cp311-macosx_11_0_x86_64.whl",
"my_platform_package_B-10.3.0-cp311-cp311-macosx_11_0_universal2.whl",
"my_platform_package_A-10.3.0-cp311-cp311-manylinux_2_28_aarch64.whl",
"my_platform_package_B-10.3.0-cp311-cp311-manylinux_2_28_aarch64.whl",
"my_platform_package_A-10.3.0-cp311-cp311-manylinux_2_28_x86_64.whl",
"my_platform_package_B-10.3.0-cp311-cp311-manylinux_2_28_x86_64.whl",
"my_platform_package_A-10.3.0-cp311-cp311-win_amd64.whl",
"my_platform_package_B-10.3.0-cp311-cp311-win_amd64.whl",
"my_platform_package_A-10.3.0-cp311-cp311-win_arm64.whl",
"my_platform_package_B-10.3.0-cp311-cp311-win_arm64.whl",
]
pkg_idname = "my_test"
@@ -431,8 +440,8 @@ class TestCLI_Build(unittest.TestCase):
filename = "{:s}-{:s}{:s}".format(pkg_idname, platform.replace("-", "_"), PKG_EXT)
value = packages_dict.get(filename)
assert isinstance(value, list)
# A check here that gives a better error would be nice, for now, check there are always 4 files.
self.assertEqual(len(value), 4)
# A check here that gives a better error would be nice, for now, check there are always 5 files.
self.assertEqual(len(value), 5)
manifest_dict = manifest_dict_from_archive(os.path.join(self.dirpath, filename))