Skip to content

Commit

Permalink
try custom delocate script
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAyd committed Jan 9, 2024
1 parent c8fb371 commit d8c1df3
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ auditwheel repair -w {dest_dir} {wheel} --exclude libtableauhyperapi.so

[tool.cibuildwheel.macos]
repair-wheel-command = """
delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel}
--exclude tableau'
python -m pantab.scripts.custom_delocate_wheel --require-archs {delocate_archs}
-w {dest_dir} -v {wheel}
"""
143 changes: 143 additions & 0 deletions scripts/custom_delocate_wheel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#!/usr/bin/env python3

# CMake is responsible for bundling the tableauhyperapi lib and bin during install
# this script is a customization of delocate to prevent that library from complaining
# about the missing libtableauhyperapi library
# See https://github.com/matthew-brett/delocate/issues/77
# File is adopted from matthe-brett delocate library which is licensed under
# the BSD 2-clause license. A copy of the License is as follows:

# Copyright (c) 2014-2023, Matthew Brett and the Delocate contributors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


""" Copy, relink library dependencies for wheel
Overwrites the wheel in-place by default
"""
# vim: ft=python
from __future__ import annotations

import os
from argparse import ArgumentParser
from os.path import basename, exists, expanduser
from os.path import join as pjoin
from typing import List, Optional, Text

from delocate import delocate_wheel
from delocate.cmd.common import (
common_parser,
delocate_parser,
delocate_values,
glob_paths,
verbosity_config,
)
from delocate.delocating import filter_system_libs

parser = ArgumentParser(description=__doc__, parents=[common_parser, delocate_parser])
parser.add_argument(
"wheels",
nargs="+",
metavar="WHEEL",
type=str,
help="The wheel files to be delocated",
)
parser.add_argument(
"-L",
"--lib-sdir",
action="store",
type=str,
default=".dylibs",
help="Subdirectory in packages to store copied libraries",
)
parser.add_argument(
"-w",
"--wheel-dir",
action="store",
type=str,
help="Directory to store delocated wheels (default is to overwrite input)",
)
parser.add_argument(
"-k",
"--check-archs",
action="store_true",
help="Check architectures of depended libraries",
)
parser.add_argument(
"--require-archs",
metavar="ARCHITECTURES",
action="store",
type=str,
help="Architectures that all wheel libraries should have"
" (from 'intel', 'i386', 'x86_64', 'i386,x86_64', 'universal2',"
" 'x86_64,arm64')",
)


def main() -> None:
args = parser.parse_args()
verbosity_config(args)
wheels = list(glob_paths(args.wheels))
multi = len(wheels) > 1
if args.wheel_dir:
wheel_dir = expanduser(args.wheel_dir)
if not exists(wheel_dir):
os.makedirs(wheel_dir)
else:
wheel_dir = None
require_archs: Optional[List[Text]] = None
if args.require_archs is None:
require_archs = [] if args.check_archs else None
elif "," in args.require_archs:
require_archs = [s.strip() for s in args.require_archs.split(",")]
else:
require_archs = args.require_archs

for wheel in wheels:
if multi or args.verbose:
print("Fixing: " + wheel)
if wheel_dir:
out_wheel = pjoin(wheel_dir, basename(wheel))
else:
out_wheel = wheel

delocate_kwargs = {k: v for k, v in delocate_values(args).items()}
delocate_kwargs["copy_filter_exclude"] = (
lambda name: False if "tableau" in name else filter_system_libs(name)
)
copied = delocate_wheel(
wheel,
out_wheel,
lib_sdir=args.lib_sdir,
require_archs=require_archs,
**delocate_kwargs,
)
if args.verbose and len(copied):
print("Copied to package {0} directory:".format(args.lib_sdir))
copy_lines = [" " + name for name in sorted(copied)]
print("\n".join(copy_lines))


if __name__ == "__main__":
main()

0 comments on commit d8c1df3

Please sign in to comment.