Skip to content

Commit

Permalink
chore: add support for MacOS arm64 architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
gasaichandesu committed Jun 4, 2024
1 parent d7aa536 commit d9bd6c1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def get_version(package):
],
package_data={
'telegram': [
'lib/darwin/*',
'lib/darwin/x86_64/*',
'lib/darwin/arm64/*',
'lib/linux/*',
'py.typed',
],
Expand Down
Binary file added telegram/lib/darwin/arm64/libtdjson.dylib
Binary file not shown.
File renamed without changes.
3 changes: 2 additions & 1 deletion telegram/tdjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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 Down
26 changes: 21 additions & 5 deletions tests/test_tdjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,33 @@


class TestGetTdjsonTdlibPath:
def test_for_darwin(self):
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.pkg_resources.resource_filename', mocked_resource):
with patch('telegram.tdjson.ctypes.util.find_library', mocked_find_library):
_get_tdjson_lib_path()
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/libtdjson.dylib')
mocked_resource.assert_called_once_with('telegram', 'lib/darwin/arm64/libtdjson.dylib')

def test_for_linux(self):
mocked_system = Mock(return_value='Linux')
Expand Down

0 comments on commit d9bd6c1

Please sign in to comment.