Skip to content

Commit 9bc261f

Browse files
authored
v0.7.1.dev0, fix #136 & don't run builds outside of cibuildwheel (#138)
1 parent d879342 commit 9bc261f

File tree

6 files changed

+14
-35
lines changed

6 files changed

+14
-35
lines changed

livekit-rtc/livekit/rtc/_ffi_client.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
# limitations under the License.
1414

1515
import asyncio
16+
from contextlib import ExitStack
1617
import ctypes
1718
import importlib.resources
1819
import logging
1920
import os
2021
import platform
22+
import atexit
2123
import threading
2224
from typing import Generic, List, Optional, TypeVar
2325

@@ -26,6 +28,9 @@
2628

2729
logger = logging.getLogger("livekit")
2830

31+
_resource_files = ExitStack()
32+
atexit.register(_resource_files.close)
33+
2934

3035
def get_ffi_lib():
3136
# allow to override the lib path using an env var
@@ -45,12 +50,10 @@ def get_ffi_lib():
4550
Set LIVEKIT_LIB_PATH to specify a the lib path"
4651
)
4752

48-
with importlib.resources.files("livekit.rtc.resources").joinpath(
49-
libname
50-
) as lib_path:
51-
# Convert the Traversable object to a string path for ctypes
52-
ffi_lib = ctypes.CDLL(str(lib_path))
53-
return ffi_lib
53+
res = importlib.resources.files("livekit.rtc.resources") / libname
54+
ctx = importlib.resources.as_file(res)
55+
path = _resource_files.enter_context(ctx)
56+
return ctypes.CDLL(str(path))
5457

5558

5659
ffi_lib = get_ffi_lib()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
""" Used by importlib.resources and setuptools """

livekit-rtc/livekit/rtc/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.7.0"
1+
__version__ = "0.7.1.dev0"

livekit-rtc/pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ build-backend = "setuptools.build_meta"
1010
build = "cp39-*"
1111
skip = "*-musllinux_*" # not supported (libwebrtc is using glibc)
1212

13+
before-build = "pip install requests && python rust-sdks/download_ffi.py --output livekit/rtc/resources"
14+
1315
manylinux-x86_64-image = "manylinux_2_28"
1416
manylinux-i686-image = "manylinux_2_28"
1517
manylinux-aarch64-image = "manylinux_2_28"

livekit-rtc/rust-sdks

livekit-rtc/setup.py

-27
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
import os
1616
import pathlib
17-
import subprocess
18-
1917
import setuptools
2018
import setuptools.command.build_py
2119
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
@@ -33,30 +31,6 @@ def finalize_options(self):
3331
_bdist_wheel.finalize_options(self)
3432

3533

36-
class BuildPyCommand(setuptools.command.build_py.build_py):
37-
"""Download a prebuilt version of livekit_ffi"""
38-
39-
def run(self):
40-
download_script = here / "rust-sdks" / "download_ffi.py"
41-
output = here / "livekit" / "rtc" / "resources"
42-
cmd = [
43-
"python3",
44-
str(download_script.absolute()),
45-
"--output",
46-
str(output.absolute()),
47-
]
48-
49-
# cibuildwheel is crosscompiling to arm64 on macos, make sure we download the
50-
# right binary (kind of a hack here...)
51-
if os.environ.get("CIBUILDWHEEL") == "1" and "arm64" in os.environ.get(
52-
"ARCHFLAGS", ""
53-
):
54-
cmd += ["--arch", "arm64"]
55-
56-
subprocess.run(cmd, check=True)
57-
setuptools.command.build_py.build_py.run(self)
58-
59-
6034
setuptools.setup(
6135
name="livekit",
6236
version=about["__version__"],
@@ -66,7 +40,6 @@ def run(self):
6640
url="https://github.com/livekit/python-sdks",
6741
cmdclass={
6842
"bdist_wheel": bdist_wheel,
69-
"build_py": BuildPyCommand,
7043
},
7144
classifiers=[
7245
"Intended Audience :: Developers",

0 commit comments

Comments
 (0)