Adding dbus-python package

Hi!

I try to add dbus-python package. It is needed for interfaces with dbus. My target is a simple bluetooth agent, thus allowing audio transmission to the device. The setup.py calls make on it's own. I removed that, but it still looks like some important defines are missing in the when make is called.

#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=python3-dbus
PKG_VERSION:=1.2.16
PKG_RELEASE:=1

PYPI_NAME:=dbus-python
PKG_HASH:=11238f1d86c995d8aed2e22f04a1e3779f0d70e587caffeab4857f3c662ed5a4

PKG_MAINTAINER:=Andre Valentin <avalentin@marcant.net>
PKG_LICENSE:=GPL-2.0-or-later Apache-2.0
PKG_LICENSE_FILES:=LICENSE.GPL.v2 LICENSE.Apache.v2
PKG_FIXUP:=autoreconf
PYTHON3_PKG_BUILD:=1


include $(TOPDIR)/package/feeds/packages/python3/../pypi.mk
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/nls.mk
include $(TOPDIR)/package/feeds/packages/python3/../python3-package.mk

define Package/python3-dbus
  SUBMENU:=Python
  SECTION:=lang
  CATEGORY:=Languages
  TITLE:=Python dbus library
  URL:=https://dbus.freedesktop.org/
  DEPENDS:= +python3-light $(INTL_DEPENDS) +glib2 +libdbus 
endef

define Package/python3-dbus/description
  Python module for interfacing with dbus
endef


TARGET_CFLAGS += \
	-I$(PKG_BUILD_DIR) \
	-I$(PKG_BUILD_DIR)/include \
	-I$(STAGING_DIR)/usr/include/dbus-1.0 \
	-I$(STAGING_DIR)/usr/lib/dbus-1.0/include \
	-I$(STAGING_DIR)/usr/include/glib-2.0

#	-include $(PKG_BUILD_DIR)/config.h
#	-DPACKAGE_VERSION=1

CONFIGURE_ARGS += \
	PYTHON_VERSION=$(PYTHON3_VERSION) \
	PYTHON_LIBS="-L$(STAGING_DIR)/usr/lib -lpython$(PYTHON3_VERSION)"



$(eval $(call Py3Package,python3-dbus))
$(eval $(call BuildPackage,python3-dbus))
#$(eval $(call BuildPackage,python3-dbus-src))

The patch I have for setup.py

diff -uNrp dbus-python-1.2.16.orig/setup.py dbus-python-1.2.16/setup.py
--- dbus-python-1.2.16.orig/setup.py	2020-07-10 00:58:13.561025384 +0200
+++ dbus-python-1.2.16/setup.py	2020-07-10 00:58:38.772953744 +0200
@@ -103,10 +103,5 @@ setup(
         'Programming Language :: Python :: Implementation :: CPython',
         'Topic :: Software Development :: Object Brokering',
     ],
-    cmdclass={
-        'build': Build,
-        'build_py': BuildPy,
-        'build_ext': BuildExt,
-    },
     tests_require=['tap.py'],
 )
diff -uNrp a/config.h b/config.h

Perhaps somebody has a hint for me ?

Thanks,

André

As far as I know, there is no dbus in OpenWrt

There is a dbus package in the package repo. If you want to use bluetooth audio, you need that.

dbus_bindings/module.c: In function 'PyInit__dbus_bindings':
dbus_bindings/module.c:407:36: error: 'PACKAGE_VERSION' undeclared (first use in this function); did you mean 'PY_VERSION'?
                                    PACKAGE_VERSION) < 0) goto init_error;
                                    ^~~~~~~~~~~~~~~
                                    PY_VERSION

:frowning:

Has added to Makefile

define Package/python3-dbus/extra_provides
    echo "libpython3.8.so.1.0"
endef

and include config.h to module.c

package is built. But not work:

import dbus
  File "/usr/lib/python3.8/site-packages/dbus/__init__.py", line 73, in <module>
  File "/usr/lib/python3.8/site-packages/dbus/types.py", line 8, in <module>
ImportError: Error relocating /usr/lib/python3.8/site-packages/_dbus_bindings.cpython-38.so: dbus_py_init_byte_types: symbol not found

@Spider84 @avalentin were you able to compile it. My compilation is failing with below error:

++++++++++++++++++++++++++++++++++++++++++
checking consistency of all components of python development environment... no
configure: error: in `/home/kishan/s2//build_dir/target-mipsel_24kc_musl/python3-dbus-python-1.2.16':
configure: error: 
  Could not link test program to Python. Maybe the main Python library has been
  installed in some non-standard library path. If so, pass it to configure,
  via the LIBS environment variable.
  Example: ./configure LIBS="-L/usr/non-standard-path/python/lib"

   ERROR!
   You probably have to install the development version of the Python package
   for your distribution.  The exact name of this package varies among them.


See `config.log' for more details
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

I have enabled python3-dev as dependency by no luck.

Makefile:

#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=python3-dbus
PKG_VERSION:=1.2.16
PKG_RELEASE:=$(AUTORELEASE)

PYPI_NAME:=dbus-python
PKG_HASH:=11238f1d86c995d8aed2e22f04a1e3779f0d70e587caffeab4857f3c662ed5a4

PKG_MAINTAINER:=Andre Valentin <avalentin@marcant.net>
PKG_LICENSE:=GPL-2.0-or-later Apache-2.0
PKG_LICENSE_FILES:=LICENSE.GPL.v2 LICENSE.Apache.v2

PKG_FIXUP:=autoreconf
PKG_INSTALL:=1

PKG_BUILD_DEPENDS:=python3 python3/host libdbus/host

include $(TOPDIR)/feeds/packages/lang/python/pypi.mk
include $(INCLUDE_DIR)/package.mk
include $(TOPDIR)/feeds/packages/lang/python/python3-package.mk

define Package/python3-dbus
  SUBMENU:=Python
  SECTION:=lang
  CATEGORY:=Languages
  TITLE:=Python dbus library
  URL:=https://dbus.freedesktop.org/
  DEPENDS:=+glib2 +libdbus
endef

define Package/python3-dbus/description
  Python module for interfacing with dbus
endef

define Package/python3-dbus/extra_provides
    echo "libpython3.9.so.1.0"
endef

CONFIGURE_ARGS += \
    PYTHON_VERSION=$(PYTHON3_VERSION) \
    PYTHON_LIBS="-L$(STAGING_DIR)/usr/lib -lpython$(PYTHON3_VERSION)" \

TARGET_CFLAGS += \
    -I$(PKG_BUILD_DIR) \
    -I$(PKG_BUILD_DIR)/include \
    -I$(STAGING_DIR)/usr/include/dbus-1.0 \
    -I$(STAGING_DIR)/usr/lib/dbus-1.0/include \
    -I$(STAGING_DIR)/usr/include/glib-2.0

$(eval $(call Py3Package,python3-dbus))
$(eval $(call BuildPackage,python3-dbus))
#$(eval $(call BuildPackage,python3-dbus-src))

patches/001-setup_py.patch:

--- a/setup.py
+++ b/setup.py
@@ -25,13 +25,13 @@
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 # DEALINGS IN THE SOFTWARE.

-from distutils.dir_util import copy_tree, mkpath
-from distutils.file_util import copy_file
-from setuptools.dist import Distribution
-from setuptools import setup, Extension
 import os
 import subprocess
 import sys
+from setuptools.dist import Distribution
+from setuptools import setup, Extension
+from distutils.dir_util import copy_tree, mkpath
+from distutils.file_util import copy_file

 if os.path.exists('.version'):
     version = open('.version').read().strip()
@@ -103,10 +103,5 @@
         'Programming Language :: Python :: Implementation :: CPython',
         'Topic :: Software Development :: Object Brokering',
     ],
-    cmdclass={
-        'build': Build,
-        'build_py': BuildPy,
-        'build_ext': BuildExt,
-    },
     tests_require=['tap.py'],
 )

Thankyou for providing makefile and patch but it's still giving same error. Not sure why. I'm using OpenWRT 18 branch as I have to and pypi.mk is not available so I'm just using old method to download, everything else remains same.

Error is coming in configure stage. Below is error from config.log. Please check and help if you can.

In file included from /home/kishan/s2/repo/staging_dir/hostpkg/include/python3.6/Python.h:53:0,
                 from conftest.c:32:
/home/kishan/s2/repo/staging_dir/hostpkg/include/python3.6/pyport.h:686:2: error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
 #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
  ^~~~~
configure:9489: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "dbus-python"
| #define PACKAGE_TARNAME "dbus-python"
| #define PACKAGE_VERSION "1.2.16"
| #define PACKAGE_STRING "dbus-python 1.2.16"
| #define PACKAGE_BUGREPORT "http://bugs.freedesktop.org/enter_bug.cgi?product=dbus&component=python"
| #define PACKAGE_URL ""
| #define DBUS_PYTHON_MAJOR_VERSION 1
| #define DBUS_PYTHON_MINOR_VERSION 2
| #define DBUS_PYTHON_MICRO_VERSION 16
| #define STDC_HEADERS 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define HAVE_MEMORY_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_UNISTD_H 1
| #define __EXTENSIONS__ 1
| #define _ALL_SOURCE 1
| #define _GNU_SOURCE 1
| #define _POSIX_PTHREAD_SEMANTICS 1
| #define _TANDEM_SOURCE 1
| #define PACKAGE "dbus-python"
| #define VERSION "1.2.16"
| #define HAVE_DLFCN_H 1
| #define LT_OBJDIR ".libs/"
| /* end confdefs.h.  */
|
|               #include <Python.h>
| int
| main ()
| {
| Py_Initialize();
|   ;
|   return 0;
| }
|
configure:9507: result: no
configure:9511: error: in `/home/kishan/s2/repo/build_dir/target-mipsel_24kc_musl/dbus-python-1.2.16':
configure:9513: error:

@Spider84 were you able to solve below error?

import dbus
  File "/usr/lib/python3.8/site-packages/dbus/__init__.py", line 73, in <module>
  File "/usr/lib/python3.8/site-packages/dbus/types.py", line 8, in <module>
ImportError: Error relocating /usr/lib/python3.8/site-packages/_dbus_bindings.cpython-38.so: dbus_py_init_byte_types: symbol not found

NO :frowning: I can't

Hello,

Try this.

Makefile

include $(TOPDIR)/rules.mk

PKG_NAME:=dbus-python
PKG_VERSION:=1.2.18
PKG_BUILD_DIR:=$(BUILD_DIR)/${PKG_NAME}-$(PKG_VERSION)

PYPI_NAME:=dbus-python
PKG_HASH:=92bdd1e68b45596c833307a5ff4b217ee6929a1502f5341bae28fd120acf7260

PKG_INSTALL:=1


include ../pypi.mk
include $(INCLUDE_DIR)/package.mk
include ../python3-package.mk

define Package/dbus-python
  SECTION:=lang
  CATEGORY:=Languages
  SUBMENU:=Python
  TITLE:=Python bindings for libdbus
  URL:=http://www.freedesktop.org/wiki/Software/DBusBindings/#python
  DEPENDS:= \
    +glib2 \
    +python3 \
    +libdbus
endef

define Package/dbus-python/description
  dbus-python is the original Python binding for dbus, the reference implementation of the D-Bus protocol
endef

TARGET_LDFLAGS += \
  -lpython3.9

define Build/Compile
	$(MAKE) -C $(PKG_BUILD_DIR)
endef

$(eval $(call Py3Package,dbus-python))
$(eval $(call BuildPackage,dbus-python))
$(eval $(call BuildPackage,dbus-python-src))

Works on my OpenWRT v21.02.0.

Also please fix the Python version:

include ../python3-version.mk
TARGET_LDFLAGS += \
  -lpython$(PYTHON3_VERSION)

Created pull request to upstream: