Python 3.7 compatibility

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I'm trying to build PJSIP and its Python bindings on Arch Linux. The
former builds successfully, but the latter fails.

Arch has Python 3.7 in its repos, but the bindings' Makefile expects
Python 3.6. I have attached a patch which addresses this issue by
asking the actual python executable (either `python2` or `python3`)
which version it has.

The second hunk of the attached patch makes the installation process
honor the `DESTDIR` variable. This is most often used by packaging
tools, which is why I simply disallow the "uninstall" target if DESTDIR
is non-empty - uninstalling makes no sense in that context. Adding `
--optimize=1` here is recommended by Arch's python packaging
guidelines, as it allows the package manager to track the compiled
files.

The next problem lies within the bindings themselves. Python 3.7
introduces the keyword "async", which means this can no longer be used
as variable name. Attempting to do so results in the following error
(both with release 2.8 as well as latest SVN):

make[1]: Entering directory '/build/pjproject-svn/src/pjproject/pjsip-apps/src/swig/python'
if [ "/build/pjproject-svn/pkg/python-pjproject-svn" ]; then \
  python3 setup.py install --root="/build/pjproject-svn/pkg/python-pjproject-svn/" --optimize=1; \
else \
  python3 setup.py install --user; \
fi
running install
running build
running build_py
running build_ext
running install_lib
creating /build/pjproject-svn/pkg/python-pjproject-svn/usr
creating /build/pjproject-svn/pkg/python-pjproject-svn/usr/lib
creating /build/pjproject-svn/pkg/python-pjproject-svn/usr/lib/python3.7
creating /build/pjproject-svn/pkg/python-pjproject-svn/usr/lib/python3.7/site-packages
copying build/lib.linux-x86_64-3.7/pjsua2.py -> /build/pjproject-svn/pkg/python-pjproject-svn/usr/lib/python3.7/site-packages
copying build/lib.linux-x86_64-3.7/_pjsua2.cpython-37m-x86_64-linux-gnu.so -> /build/pjproject-svn/pkg/python-pjproject-svn/usr/lib/python3.7/site-packages
byte-compiling /build/pjproject-svn/pkg/python-pjproject-svn/usr/lib/python3.7/site-packages/pjsua2.py to pjsua2.cpython-37.pyc
writing byte-compilation script '/tmp/tmpakk7h67h.py'
/usr/bin/python3 /tmp/tmpakk7h67h.py
  File "usr/lib/python3.7/site-packages/pjsua2.py", line 7595
    async = _swig_property(_pjsua2.OnCallRxReinviteParam_async_get, _pjsua2.OnCallRxReinviteParam_async_set)
          ^
SyntaxError: invalid syntax

removing /tmp/tmpakk7h67h.py
running install_egg_info
Writing /build/pjproject-svn/pkg/python-pjproject-svn/usr/lib/python3.7/site-packages/pjsua2-2.8_svn-py3.7.egg-info
  File "usr/lib/python3.7/site-packages/pjsua2.py", line 7595
    async = _swig_property(_pjsua2.OnCallRxReinviteParam_async_get, _pjsua2.OnCallRxReinviteParam_async_set)
          ^
SyntaxError: invalid syntax

make[1]: Leaving directory '/build/pjproject-svn/src/pjproject/pjsip-apps/src/swig/python'

I hope that this can be resolved quickly; don't hesitate to ask if you
need any more information.
~ Wüstengecko
--- pjsip-apps/src/swig/python/Makefile.orig	2018-11-20 17:12:11.300969259 +0100
+++ pjsip-apps/src/swig/python/Makefile	2018-11-20 18:06:01.840963323 +0100
@@ -3,13 +3,14 @@
 USE_PYTHON3?=1
 
 ifeq ($(USE_PYTHON3),1)
-  PYTHON_EXE=python3.6
-  PYTHON_PKG_DIR=$(HOME)/.local/lib/python3.6/site-packages
+  PYTHON_EXE=python3
 else
-  PYTHON_EXE=python2.7
-  PYTHON_PKG_DIR=$(HOME)/.local/lib/python2.7/site-packages
+  PYTHON_EXE=python2
 endif
 
+PYTHON_VERSION := $(shell $(PYTHON_EXE) -c 'import sys; print(".".join(str(v) for v in sys.version_info[0:2]))')
+PYTHON_PKG_DIR := $(HOME)/.local/lib/python$(PYTHON_VERSION)/site-packages
+
 #PYTHON_SETUP_FLAGS = --inplace 
 ifeq ($(OS),Windows_NT)
   PYTHON_SETUP_FLAGS += --compiler=mingw32
@@ -40,9 +41,17 @@
 	rm -f gcc.exe g++.exe
 
 install:
-	$(PYTHON_EXE) setup.py install --user
+	if [ "$(DESTDIR)" ]; then \
+	  $(PYTHON_EXE) setup.py install --root="$(DESTDIR)/" --optimize=1; \
+	else \
+	  $(PYTHON_EXE) setup.py install --user; \
+	fi
 
 uninstall:
+	if [ "$(DESTDIR)" ]; then \
+	  echo "Uninstallation is not supported if DESTDIR is used"; \
+	  exit 1; \
+	fi
 	rm -f $(PYTHON_PKG_DIR)/pjsua2*
 	rm -f $(PYTHON_PKG_DIR)/_pjsua2*
 
_______________________________________________
Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@xxxxxxxxxxxxxxx
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux