Skip to content

Commit 66f2300

Browse files
authored
use setuptools instead of hatch (#559)
1 parent 8b7a229 commit 66f2300

3 files changed

Lines changed: 98 additions & 110 deletions

File tree

livekit-rtc/hatch_build.py

Lines changed: 0 additions & 92 deletions
This file was deleted.

livekit-rtc/pyproject.toml

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
[build-system]
2-
requires = ["hatchling", "requests"]
3-
build-backend = "hatchling.build"
2+
requires = [
3+
"setuptools>=61",
4+
"wheel",
5+
"requests",
6+
]
7+
build-backend = "setuptools.build_meta"
48

59
[project]
610
name = "livekit"
@@ -35,28 +39,27 @@ Documentation = "https://docs.livekit.io"
3539
Website = "https://livekit.io/"
3640
Source = "https://github.com/livekit/python-sdks/"
3741

38-
[tool.hatch.version]
39-
path = "livekit/rtc/version.py"
40-
41-
[tool.hatch.build.targets.wheel]
42-
packages = ["livekit"]
43-
artifacts = [
44-
"livekit/rtc/resources/*.so",
45-
"livekit/rtc/resources/*.dylib",
46-
"livekit/rtc/resources/*.dll",
47-
]
42+
[tool.setuptools.dynamic]
43+
version = { attr = "livekit.rtc.version.__version__" }
4844

49-
[tool.hatch.build.targets.wheel.hooks.custom]
50-
path = "hatch_build.py"
45+
[tool.setuptools.packages.find]
46+
include = ["livekit.*"]
5147

52-
[tool.hatch.build.targets.sdist]
53-
include = ["/livekit", "/rust-sdks"]
48+
[tool.setuptools.package-data]
49+
"livekit.rtc" = ["_proto/*.py", "py.typed", "*.pyi", "**/*.pyi"]
50+
"livekit.rtc.resources" = [
51+
"*.so",
52+
"*.dylib",
53+
"*.dll",
54+
"LICENSE.md",
55+
"*.h",
56+
"jupyter-html/index.html",
57+
]
5458

5559
[tool.cibuildwheel]
5660
build = "cp39-*"
5761
skip = "*-musllinux_*" # not supported (libwebrtc requires glibc)
5862
before-build = "pip install requests && python rust-sdks/download_ffi.py --output livekit/rtc/resources"
59-
# Note: manylinux_2_28 is the default in cibuildwheel 3.x, no explicit config needed
6063

6164
# macOS deployment targets must match the FFI binaries (see rust-sdks/.github/workflows/ffi-builds.yml)
6265
# x86_64 supports macOS 10.15+, arm64 requires macOS 11.0+
@@ -66,4 +69,4 @@ environment = { MACOSX_DEPLOYMENT_TARGET = "10.15" }
6669

6770
[[tool.cibuildwheel.overrides]]
6871
select = "*macosx_arm64"
69-
environment = { MACOSX_DEPLOYMENT_TARGET = "11.0" }
72+
environment = { MACOSX_DEPLOYMENT_TARGET = "11.0" }

livekit-rtc/setup.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Copyright 2023 LiveKit, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Custom setup.py for platform-specific wheel tagging.
16+
17+
This file exists solely to customize the wheel platform tag. All package metadata
18+
is defined in pyproject.toml.
19+
20+
The native FFI libraries (.so/.dylib/.dll) require specific platform tags that
21+
respect MACOSX_DEPLOYMENT_TARGET and ARCHFLAGS environment variables set by
22+
cibuildwheel, rather than using sysconfig.get_platform() which returns Python's
23+
compile-time values.
24+
"""
25+
26+
import os
27+
import platform
28+
import sys
29+
30+
import setuptools # type: ignore
31+
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel # type: ignore
32+
33+
34+
def get_platform_tag():
35+
"""Get the wheel platform tag for the current/target platform."""
36+
if sys.platform == "darwin":
37+
# Get deployment target from environment (set by cibuildwheel) or fall back
38+
target = os.environ.get("MACOSX_DEPLOYMENT_TARGET")
39+
if not target:
40+
target = platform.mac_ver()[0]
41+
parts = target.split(".")
42+
target = f"{parts[0]}.{parts[1] if len(parts) > 1 else '0'}"
43+
44+
version_tag = target.replace(".", "_")
45+
46+
# Check ARCHFLAGS for cross-compilation (cibuildwheel sets this)
47+
archflags = os.environ.get("ARCHFLAGS", "")
48+
if "-arch arm64" in archflags:
49+
arch = "arm64"
50+
elif "-arch x86_64" in archflags:
51+
arch = "x86_64"
52+
else:
53+
arch = platform.machine()
54+
55+
return f"macosx_{version_tag}_{arch}"
56+
elif sys.platform == "linux":
57+
return f"linux_{platform.machine()}"
58+
elif sys.platform == "win32":
59+
arch = platform.machine()
60+
if arch == "AMD64":
61+
arch = "amd64"
62+
return f"win_{arch}"
63+
else:
64+
return f"{platform.system().lower()}_{platform.machine()}"
65+
66+
67+
class bdist_wheel(_bdist_wheel):
68+
def finalize_options(self):
69+
self.plat_name = get_platform_tag()
70+
_bdist_wheel.finalize_options(self)
71+
72+
73+
setuptools.setup(
74+
cmdclass={
75+
"bdist_wheel": bdist_wheel,
76+
},
77+
)

0 commit comments

Comments
 (0)