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

chore: add support for MacOS arm64 architecture #471

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 8 additions & 3 deletions telegram/tdjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def _get_tdjson_lib_path() -> str:
return system_library

if platform.system().lower() == "darwin":
lib_name = "darwin/libtdjson.dylib"
platform_architecture = platform.machine()
lib_name = f"darwin/{platform_architecture}/libtdjson.dylib"
else:
lib_name = "linux/libtdjson.so"

Expand All @@ -32,7 +33,9 @@ def __init__(self, library_path: Optional[str] = None, verbosity: int = 2) -> No
self._build_client(library_path, verbosity)

def __del__(self) -> None:
if hasattr(self, "_tdjson") and hasattr(self._tdjson, "_td_json_client_destroy"):
if hasattr(self, "_tdjson") and hasattr(
self._tdjson, "_td_json_client_destroy"
):
self.stop()

def _build_client(self, library_path: str, verbosity: int) -> None:
Expand Down Expand Up @@ -77,7 +80,9 @@ def _build_client(self, library_path: str, verbosity: int) -> None:

fatal_error_callback_type = CFUNCTYPE(None, c_char_p)

self._td_set_log_fatal_error_callback = self._tdjson.td_set_log_fatal_error_callback
self._td_set_log_fatal_error_callback = (
self._tdjson.td_set_log_fatal_error_callback
)
self._td_set_log_fatal_error_callback.restype = None
self._td_set_log_fatal_error_callback.argtypes = [fatal_error_callback_type]

Expand Down
40 changes: 40 additions & 0 deletions tests/test_tdjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,46 @@


class TestGetTdjsonTdlibPath:
def test_for_darwin_x86_64(self):
mocked_system = Mock(return_value="Darwin")
mocked_machine_name = Mock(return_value="x86_64")
mocked_resource = Mock()
mocked_find_library = Mock(return_value=None)

with patch("telegram.tdjson.platform.system", mocked_system):
with patch("telegram.tdjson.platform.machine", mocked_machine_name):
with patch(
"telegram.tdjson.pkg_resources.resource_filename", mocked_resource
):
with patch(
"telegram.tdjson.ctypes.util.find_library", mocked_find_library
):
_get_tdjson_lib_path()

mocked_resource.assert_called_once_with(
"telegram", "lib/darwin/x86_64/libtdjson.dylib"
)

def test_for_darwin_arm64(self):
mocked_system = Mock(return_value="Darwin")
mocked_machine_name = Mock(return_value="arm64")
mocked_resource = Mock()
mocked_find_library = Mock(return_value=None)

with patch("telegram.tdjson.platform.system", mocked_system):
with patch("telegram.tdjson.platform.machine", mocked_machine_name):
with patch(
"telegram.tdjson.pkg_resources.resource_filename", mocked_resource
):
with patch(
"telegram.tdjson.ctypes.util.find_library", mocked_find_library
):
_get_tdjson_lib_path()

mocked_resource.assert_called_once_with(
"telegram", "lib/darwin/arm64/libtdjson.dylib"
)

def test_for_darwin(self):
mocked_system = Mock(return_value="Darwin")
mocked_files = Mock()
Expand Down
Loading