Created attachment 933756 [details] Python 3 compat patch for lvm2 Hi, I'm attaching a patch that makes lvm2 compatible with Python 3, while maintaining compatibility with Python 2.6 and 2.7. As I understand it, you use Bugzilla as an upstream tracker, so I'm submitting here. It'd be great if you could accept the patch and also build a python3 version of bindings in Fedora (thus creating lvm2-python3-libs), ideally both in rawhide and F21. To build with python3, one must apply the patch and run configure with "--enable-applib --enable-python_bindings PYTHON=/usr/bin/python3 PYTHON_CONFIG=/usr/bin/python3-config". (To see how this is done in similar cases, I suggest seeing how libpwquality has done this [1]). Feel free to reach out to me if you have questions/comments on my patch. Thanks! [1] http://pkgs.fedoraproject.org/cgit/libpwquality.git/commit/?id=c57e81ff0077f481fa98a5d98f6d406c7deab9d0
Ping? Any progress here? Can somebody review this patch? mock-lvm depends on this and this troubles me when trying to update to F22/Rawhide.
The changes to python/example.py are trivial and correct (print statement to function conversions). The changes to liblvm.c introduce a set of compatibility macros to handle the differences between integer and string type operations in py2 vs. py3; most of the remaining changes to this file simply replace the hard-coded python2 type calls with their wrapped macro equivalents. There are a couple of changes to use PyVarObject_HEAD_INIT() instead of PyObject_HEAD_INIT; this avoids compiler warnings for py3 builds but the PyVarObject* versions are available since py2.6 so this is not made conditional on python version (although it does restrict lvm2 builds to python runtimes >= 2.6). There is some further macro usage to handle py2 vs. py3 library initialisation; the return types (void vs. PyObject*) and passing of the method table, module name and description are different. These look a little ugly but I'm not sure it's worth the effort to do clean up and the method used is similar to that used by other C projects with python bindings. The remaining changes switch from PyObject_IsInstance() checks to the corresponding Py{Int,Long}_Check using the macros to select appropriately for 2 vs. 3. The final set of changes are to the python lvm2 unit tests. This introduces an alias for the int vs. long changes and replaces a handrolled sort comparator (compare_pv) with a lambda expression on the object name. I've not tested these changes but they seem correct and relatively simple - just shimming for renames and mapping the remaining things to interfaces that are the same in python 2 & 3.
Upstreamed given patch: https://www.redhat.com/archives/lvm-devel/2015-April/msg00162.html
Yes, sorry we lost this one, but I'm aiming for an upstream lvm2 release which will include this at the end of the week which we'll build for fedora next week.
Great, thank you very much!
OK, there's a separate lvm2-python3-libs lvm2 subpackage now which has those python3 bindings included. Though configuring and compiling the whole lvm2 source again just to add another version of python bindings is a bit odd - the code still stays the same, it's just the python binding part which changes, not counting with the fact that it makes the spec file a bit messy. We should provide a separate configure option for this later on probably so the code is configured and compiled only once.