Bug 1136366 - make lvm2 Python 3 compatible
Summary: make lvm2 Python 3 compatible
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: lvm2
Version: rawhide
Hardware: Unspecified
OS: Unspecified
high
medium
Target Milestone: ---
Assignee: Zdenek Kabelac
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 1024805
TreeView+ depends on / blocked
 
Reported: 2014-09-02 12:44 UTC by Bohuslav "Slavek" Kabrda
Modified: 2015-05-04 13:10 UTC (History)
15 users (show)

Fixed In Version: lvm2-2.02.119-1.fc23
Doc Type: Enhancement
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-05-04 13:10:36 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
Python 3 compat patch for lvm2 (10.31 KB, text/plain)
2014-09-02 12:44 UTC, Bohuslav "Slavek" Kabrda
no flags Details

Description Bohuslav "Slavek" Kabrda 2014-09-02 12:44:11 UTC
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

Comment 1 Vít Ondruch 2015-04-29 11:55:58 UTC
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.

Comment 2 Bryn M. Reeves 2015-04-29 13:02:02 UTC
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.

Comment 3 Zdenek Kabelac 2015-04-29 13:11:57 UTC
Upstreamed given patch:

https://www.redhat.com/archives/lvm-devel/2015-April/msg00162.html

Comment 4 Alasdair Kergon 2015-04-29 18:31:51 UTC
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.

Comment 5 Bohuslav "Slavek" Kabrda 2015-04-30 09:05:12 UTC
Great, thank you very much!

Comment 6 Peter Rajnoha 2015-05-04 13:10:36 UTC
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.


Note You need to log in before you can comment on or make changes to this bug.