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

Bug#1024048: pyliblo: diff for NMU version 0.10.0-5.1



Control: tags 1024048 + patch
Control: tags 1024048 + pending

Dear maintainer,

I've prepared an NMU for pyliblo (versioned as 0.10.0-5.1) and
uploaded it to DELAYED/5. Please feel free to tell me if I
should delay it longer.

Regards.

SR
diff -Nru pyliblo-0.10.0/debian/changelog pyliblo-0.10.0/debian/changelog
--- pyliblo-0.10.0/debian/changelog	2021-11-21 17:07:07.000000000 +0200
+++ pyliblo-0.10.0/debian/changelog	2022-11-18 20:04:17.000000000 +0200
@@ -1,3 +1,10 @@
+pyliblo (0.10.0-5.1) unstable; urgency=medium
+
+  * Non-maintainer upload.
+  * Patch: Python 3.11 support (Closes: #1024048)
+
+ -- Stefano Rivera <stefanor@debian.org>  Fri, 18 Nov 2022 20:04:17 +0200
+
 pyliblo (0.10.0-5) unstable; urgency=medium
 
   * Team upload
diff -Nru pyliblo-0.10.0/debian/patches/python3.11.patch pyliblo-0.10.0/debian/patches/python3.11.patch
--- pyliblo-0.10.0/debian/patches/python3.11.patch	1970-01-01 02:00:00.000000000 +0200
+++ pyliblo-0.10.0/debian/patches/python3.11.patch	2022-11-18 20:03:57.000000000 +0200
@@ -0,0 +1,164 @@
+Merge branch 'callable-callback'
+
+Includes migrating to inspect.getfullargspec() in Python 3.
+
+Origin: https://github.com/dsacre/pyliblo/commit/33999ca8178a01c720e99856df769f1986c7e912
+--- a/src/liblo.pyx
++++ b/src/liblo.pyx
+@@ -23,6 +23,7 @@
+ from liblo cimport *
+ 
+ import inspect as _inspect
++import functools as _functools
+ import weakref as _weakref
+ 
+ 
+@@ -249,7 +250,6 @@
+     free(url)
+ 
+     cb = <object>cb_data
+-    func = cb.func.func
+ 
+     func_args = (_decode(<char*>path),
+                  args,
+@@ -257,20 +257,42 @@
+                  src,
+                  cb.user_data)
+ 
+-    # call function
+-    if _inspect.getargspec(func)[1] == None:
+-        # determine number of arguments to call the function with
+-        n = len(_inspect.getargspec(func)[0])
+-        if _inspect.ismethod(func):
+-            n -= 1  # self doesn't count
+-        r = cb.func(*func_args[0:n])
+-    else:
+-        # function has argument list, pass all arguments
+-        r = cb.func(*func_args)
++    # call the function
++    r = cb.func(*func_args[:cb.nargs])
+ 
+     return r if r != None else 0
+ 
+ 
++cdef int _callback_num_args(func):
++    """
++    Return the number of arguments that should be passed to callback *func*.
++    """
++    getargspec = (_inspect.getargspec if PY_VERSION_HEX < 0x03000000
++             else _inspect.getfullargspec)
++
++    if isinstance(func, _functools.partial):
++        # before Python 3.4, getargspec() did't work for functools.partial,
++        # so it needs to be handled separately
++        argspec = getargspec(func.func)
++        nargs = len(argspec.args) - len(func.args)
++        if func.keywords is not None:
++            nargs -= len(func.keywords)
++    else:
++        if (hasattr(func, '__call__') and
++                not (_inspect.ismethod(func) or _inspect.isfunction(func))):
++            func = func.__call__
++
++        argspec = getargspec(func)
++        nargs = len(argspec.args)
++
++        if _inspect.ismethod(func):
++            nargs -= 1  # self doesn't count
++
++    # use all 5 arguments (path, args, types, src, user_data) if the
++    # function has a variable argument list
++    return nargs if argspec.varargs is None else 5
++
++
+ cdef int _bundle_start_callback(lo_timetag t, void *cb_data) with gil:
+     cb = <object>cb_data
+     r = cb.start_func(_timetag_to_double(t), cb.user_data)
+@@ -446,11 +468,16 @@
+ 
+         self._check()
+ 
++        # determine the number of arguments to call the function with
++        nargs = _callback_num_args(func)
++
+         # use a weak reference if func is a method, to avoid circular
+         # references in cases where func is a method of an object that also
+         # has a reference to the server (e.g. when deriving from the Server
+         # class)
+-        cb = struct(func=_weakref_method(func), user_data=user_data)
++        cb = struct(func=_weakref_method(func),
++                    user_data=user_data,
++                    nargs=nargs)
+         # keep a reference to the callback data around
+         self._keep_refs.append(cb)
+ 
+--- a/test/test_liblo.py
++++ b/test/test_liblo.py
+@@ -15,6 +15,7 @@
+ import re
+ import time
+ import sys
++import functools
+ import liblo
+ 
+ 
+@@ -24,7 +25,7 @@
+ 
+ 
+ class Arguments:
+-    def __init__(self, path, args, types, src, data):
++    def __init__(self, path, args, types=None, src=None, data=None):
+         self.path = path
+         self.args = args
+         self.types = types
+@@ -178,6 +179,50 @@
+         with self.assertRaises(RuntimeError):
+             self.server.recv()
+ 
++    def testCallbackVarargs(self):
++        def foo(path, args, *varargs):
++            self.cb = Arguments(path, args)
++            self.cb_varargs = varargs
++        self.server.add_method('/foo', 'f', foo, user_data='spam')
++        self.server.send(1234, '/foo', 123.456)
++        self.assertTrue(self.server.recv())
++        self.assertEqual(self.cb.path, '/foo')
++        self.assertAlmostEqual(self.cb.args[0], 123.456, places=3)
++        self.assertEqual(self.cb_varargs[0], 'f')
++        self.assertIsInstance(self.cb_varargs[1], liblo.Address)
++        self.assertEqual(self.cb_varargs[2], 'spam')
++
++    def testCallbackCallable(self):
++        class Foo:
++            def __init__(self):
++                self.a = None
++            def __call__(self, path, args):
++                self.a = args[0]
++        foo = Foo()
++        self.server.add_method('/foo', 'i', foo)
++        self.server.send(1234, '/foo', 23)
++        self.assertTrue(self.server.recv())
++        self.assertEqual(foo.a, 23)
++
++    def testCallbackPartial(self):
++        def foo(partarg, path, args, types, src, data):
++            self.cb = Arguments(path, args, types, src, data)
++            self.cb_partarg = partarg
++        self.server.add_method('/foo', 'i', functools.partial(foo, 'blubb'))
++        self.server.send(1234, '/foo', 23)
++        self.assertTrue(self.server.recv())
++        self.assertEqual(self.cb_partarg, 'blubb')
++        self.assertEqual(self.cb.path, '/foo')
++        self.assertEqual(self.cb.args[0], 23)
++
++        self.server.add_method('/foo2', 'i', functools.partial(foo, 'bla', data='blubb'))
++        self.server.send(1234, '/foo2', 42)
++        self.assertTrue(self.server.recv())
++        self.assertEqual(self.cb_partarg, 'bla')
++        self.assertEqual(self.cb.path, '/foo2')
++        self.assertEqual(self.cb.args[0], 42)
++        self.assertEqual(self.cb.data, 'blubb')
++
+     def testBundleCallbacksFire(self):
+         def bundle_start_cb(timestamp, user_data):
+             self.assertIsInstance(timestamp, float)
diff -Nru pyliblo-0.10.0/debian/patches/series pyliblo-0.10.0/debian/patches/series
--- pyliblo-0.10.0/debian/patches/series	2021-11-21 17:06:55.000000000 +0200
+++ pyliblo-0.10.0/debian/patches/series	2022-11-18 19:59:47.000000000 +0200
@@ -1,2 +1,3 @@
 test-hostname.patch
 sphinx-4.2.patch
+python3.11.patch

Reply to: