Skip to content

Commit

Permalink
hooks: add hook for dbus_fast
Browse files Browse the repository at this point in the history
Add hook for `dbus_fast` in order to collect submodules that are
imported from cythonized extensions.
  • Loading branch information
rokm committed May 18, 2024
1 parent 73b06e5 commit c51bf27
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions news/600.new.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add hook for ``dbus_fast`` in order to collect submodules that are imported
from cythonized extensions.
3 changes: 3 additions & 0 deletions requirements-test-libraries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ schwifty==2024.5.3

# ------------------- Platform (OS) specifics

# dbus-fast has pre-built wheels only for Linux; and D-Bus is available only there, anyway.
dbus-fast==2.21.2; sys_platform == 'linux'

# PyEnchant only pre-builds macOS and Windows
pyenchant==3.2.2; sys_platform == 'darwin' or sys_platform == 'win32'

Expand Down
16 changes: 16 additions & 0 deletions src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-dbus_fast.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# ------------------------------------------------------------------
# Copyright (c) 2024 PyInstaller Development Team.
#
# This file is distributed under the terms of the GNU General Public
# License (version 2.0 or later).
#
# The full license is available in LICENSE.GPL.txt, distributed with
# this software.
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ------------------------------------------------------------------

from PyInstaller.utils.hooks import collect_submodules

# Collect all submodules to handle imports made from cythonized extensions.
hiddenimports = collect_submodules('dbus_fast')
40 changes: 40 additions & 0 deletions src/_pyinstaller_hooks_contrib/tests/test_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2036,3 +2036,43 @@ def test_schwifty(pyi_builder):
print(iban.bank_code)
print(iban.account_code)
""")


@importorskip('dbus_fast')
def test_dbus_fast(pyi_builder):
pyi_builder.test_source("""
import os
import sys
import asyncio
import json
from dbus_fast import Message, MessageType
from dbus_fast.aio import MessageBus
async def main():
# Connect to bus
try:
bus = await MessageBus().connect()
except Exception as e:
print(f"Could not connect to bus: {e}")
return
# List all available names
reply = await bus.call(
Message(
destination="org.freedesktop.DBus",
path="/org/freedesktop/DBus",
interface="org.freedesktop.DBus",
member="ListNames",
)
)
if reply.message_type == MessageType.ERROR:
raise Exception(reply.body[0])
print(json.dumps(reply.body[0], indent=2))
asyncio.run(main())
""")

0 comments on commit c51bf27

Please sign in to comment.