Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] Exclude relocating packages in homebrew #210

Merged
merged 8 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ if (CCACHE_FOUND)
endif (CCACHE_FOUND)

add_compile_options(-Wall -Wextra -fPIC)
add_link_options(-o linker-signed)

if (CMAKE_BUILD_TYPE STREQUAL Debug)
SET(LANCE_BUILD_BENCHMARKS ON)
Expand Down
11 changes: 4 additions & 7 deletions python/lance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import platform
from pathlib import Path
from typing import List, Optional, Union
from typing import Union

import pyarrow as pa
import pyarrow.compute as pc
Expand All @@ -24,15 +23,13 @@

__version__ = version.__version__

from lance.lib import BuildScanner, LanceFileFormat, WriteTable, _wrap_dataset
from lance.lib import LanceFileFormat, WriteTable, _wrap_dataset
from lance.types import register_extension_types

if platform.system() == "Linux":
# TODO enable on MacOS
register_extension_types()

__all__ = ["dataset", "write_table", "scanner", "LanceFileFormat", "__version__"]

register_extension_types()


def dataset(uri: str, **kwargs) -> ds.FileSystemDataset:
"""
Expand Down
5 changes: 0 additions & 5 deletions python/lance/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@

import os
import pickle
import platform

import numpy as np
import pyarrow as pa
import pytest

import lance
from lance.types import (
Expand All @@ -38,9 +36,6 @@
is_image_type,
)

if platform.system() != "Linux":
pytest.skip(allow_module_level=True)


def test_image(tmp_path):
data = [f"s3://bucket/{x}.jpg" for x in ["a", "b", "c"]]
Expand Down
3 changes: 0 additions & 3 deletions python/lance/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Extension types for computer vision"""
import platform

import pyarrow as pa
from pyarrow import ArrowKeyError
Expand All @@ -33,8 +32,6 @@


def register_extension_types():
if platform.system() != "Linux":
raise NotImplementedError("Extension types are only supported on Linux for now")
types = [
ImageUriType(),
ImageBinaryType(),
Expand Down
4 changes: 4 additions & 0 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ before-build = [
[tool.cibuildwheel.macos]
# We only support native build for now, because homebrew only installs native libarrow and protobuf.
archs = ["native"]
repair-wheel-command = [
"delocate-listdeps {wheel}",
"./python/tools/delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel}",
]

[tool.cibuildwheel.macos.environment]
MACOSX_DEPLOYMENT_TARGET = "10.15"
2 changes: 1 addition & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
library_dirs=[lance_libs] + arrow_library_dirs,
language="c++",
extra_compile_args=["-Wall", "-std=c++20", "-O3"],
extra_link_args=["-Wl,-rpath", lance_libs, "-Wl,-rpath", arrow_library_dirs[0]],
extra_link_args=["-Wl,-rpath", lance_libs] #, "-Wl,-rpath", arrow_library_dirs[0]],
)
]

Expand Down
69 changes: 69 additions & 0 deletions python/tools/delocate-wheel
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env python

"""Customized Delocate that

1. Delocate *.dylibs other than arrow
2. Set arrow rpath to be able to load pyarrow installation.

See
https://github.com/matthew-brett/delocate/blob/master/delocate/cmd/delocate_wheel.py
"""

import glob
import os
import shutil
from argparse import ArgumentParser

from delocate import wheel_libs
from delocate.delocating import filter_system_libs
from delocate.tools import add_rpath, get_install_names, set_install_name
from delocate.wheeltools import InWheelCtx


def main():
parser = ArgumentParser()
parser.add_argument("--require-archs", metavar="ARCH")
parser.add_argument("-w", "--wheel-dir", required=True)
parser.add_argument("wheel", nargs="+")

args = parser.parse_args()
for wheel in args.wheel:
out_dir = args.wheel_dir
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if out_dir is None? Should this be required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

out_wheel = wheel
if out_dir:
os.makedirs(out_dir, exist_ok=True)
out_wheel = os.path.join(out_dir, os.path.basename(wheel))

lance_lib = [
p for p in wheel_libs(wheel, ignore_missing=True).keys() if "liblance." in p
][0]

with InWheelCtx(wheel, out_wheel):
lance_dylib_path = None
lance_dylib_path = os.path.join("lance", os.path.basename(lance_lib))
shutil.copy(lance_lib, lance_dylib_path)

install_names = get_install_names(lance_dylib_path)
for name in install_names:
if filter_system_libs(name):
if "protobuf" in name:
shutil.copy(name, os.path.join("lance", os.path.basename(name)))
set_install_name(
lance_dylib_path,
name,
f"@loader_path/{os.path.basename(name)}",
)
else:
set_install_name(
lance_dylib_path, name, f"@rpath/{os.path.basename(name)}"
)
add_rpath(lance_dylib_path, "@rpath/../pyarrow")

cython_so = glob.glob("lance/lib.cpython*.so")[0]
set_install_name(
cython_so, "@rpath/liblance.dylib", "@loader_path/liblance.dylib"
)


if __name__ == "__main__":
main()