Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
dunkmann00 committed Apr 22, 2024
1 parent 8a5a11a commit 80e121c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion delocate/cmd/delocate_fuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"--retag",
action="store_true",
help="Retag the fused wheel. This includes updating its filename and"
" dist-info (Only works when fusing to make a universal2 wheel)"
" dist-info (Only works when fusing to make a universal2 wheel)",
)


Expand Down
27 changes: 18 additions & 9 deletions delocate/fuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@

import os
import shutil
from os.path import abspath, basename, dirname, exists, relpath, splitext
from os.path import abspath, basename, exists, relpath, splitext
from os.path import dirname as pdirname
from os.path import join as pjoin

from packaging.utils import parse_wheel_filename

from .pkginfo import read_pkg_info, write_pkg_info
from .tmpdirs import InTemporaryDirectory
from .tools import (
chmod_perms,
Expand All @@ -27,13 +31,12 @@
zip2dir,
)
from .wheeltools import rewrite_record
from .pkginfo import read_pkg_info, write_pkg_info

from packaging.utils import parse_wheel_filename

class RetagWheelError(Exception):
"""Errors raised when trying to retag a wheel."""


def _copyfile(in_fname, out_fname):
# Copies files without read / write permission
perms = chmod_perms(in_fname)
Expand All @@ -43,6 +46,7 @@ def _copyfile(in_fname, out_fname):
fobj.write(contents)
os.chmod(out_fname, perms)


def retag_wheel(to_wheel, from_wheel, to_tree):
"""Update the name and dist-info to reflect a univeral2 wheel.
Expand Down Expand Up @@ -75,9 +79,13 @@ def retag_wheel(to_wheel, from_wheel, to_tree):
elif wheel.endswith("arm64.whl"):
arm64_wheel = wheel
if x86_64_wheel is None or arm64_wheel is None:
raise RetagWheelError("Must have an x86_64 and an arm64 wheel to retag for universal2.")
raise RetagWheelError(
"Must have an x86_64 and an arm64 wheel to retag for universal2."
)

name, version, _, x86_64_wheel_tags = parse_wheel_filename(basename(x86_64_wheel))
name, version, _, x86_64_wheel_tags = parse_wheel_filename(
basename(x86_64_wheel)
)
_, _, _, arm64_wheel_tags = parse_wheel_filename(basename(arm64_wheel))

if len(x86_64_wheel_tags) != 1 or len(arm64_wheel_tags) != 1:
Expand All @@ -88,9 +96,7 @@ def retag_wheel(to_wheel, from_wheel, to_tree):
err_msg += f" The arm64 wheel has {len(arm64_wheel_tags)} tags."
raise RetagWheelError(err_msg)

x86_64_wheel_tag = list(x86_64_wheel_tags)[0]
arm64_wheel_tag = list(arm64_wheel_tags)[0]
x86_64_wheel_macos_version = x86_64_wheel_tag.platform.split("_")[1:3]
arm64_wheel_macos_version = arm64_wheel_tag.platform.split("_")[1:3]

# Use the x86_64 wheel's platform version when the arm64 wheel's platform
Expand All @@ -103,7 +109,9 @@ def retag_wheel(to_wheel, from_wheel, to_tree):
retag_name += "universal2.whl"

normalized_name = name.replace("-", "_")
info_path = pjoin(to_tree, f"{normalized_name}-{version}.dist-info", "WHEEL")
info_path = pjoin(
to_tree, f"{normalized_name}-{version}.dist-info", "WHEEL"
)
_, _, _, retag_tags = parse_wheel_filename(retag_name)
retag_tag = list(retag_tags)[0]
info = read_pkg_info(info_path)
Expand All @@ -113,6 +121,7 @@ def retag_wheel(to_wheel, from_wheel, to_tree):

return retag_name


def fuse_trees(to_tree, from_tree, lib_exts=(".so", ".dylib", ".a")):
"""Fuse path `from_tree` into path `to_tree`.
Expand Down Expand Up @@ -188,7 +197,7 @@ def fuse_wheels(to_wheel, from_wheel, out_wheel, retag):
fuse_trees("to_wheel", "from_wheel")
if retag:
out_wheel_name = retag_wheel(to_wheel, from_wheel, "to_wheel")
out_wheel = pjoin(dirname(out_wheel), out_wheel_name)
out_wheel = pjoin(pdirname(out_wheel), out_wheel_name)
rewrite_record("to_wheel")
dir2zip("to_wheel", out_wheel)
return out_wheel

0 comments on commit 80e121c

Please sign in to comment.