[libvirt] [RFC/PATCH python] expose the bindings version to Python

The method getVersion() retrieves the version of the libvirt library that the binaries are linked against but there is no way to retrieve the version of the bindings you are using. In the future if we support new APIs in Python that don't rely on features in the library there needs to be a way for programmers to detect the version. --- I would expect there's a cleaner way to implement this than I've done but I opted for what I saw as the smallest implementation. If anyone has a suggestion for a better way to do this I'm ok with redoing this patch. --- libvirt-override.py | 3 +++ setup.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/libvirt-override.py b/libvirt-override.py index 63f8ecb..ed8f73a 100644 --- a/libvirt-override.py +++ b/libvirt-override.py @@ -2,6 +2,9 @@ # Manually written part of python bindings for libvirt # +__version__ = '@VERSION@' +version = @VER_TUPLE@ + # On cygwin, the DLL is called cygvirtmod.dll import sys diff --git a/setup.py b/setup.py index 24d4cf2..ad4f406 100755 --- a/setup.py +++ b/setup.py @@ -119,6 +119,21 @@ if have_libvirt_lxc: class my_build(build): + def gen_version(self, filename): + os.rename(filename, filename + '.tmp') + + version = self.distribution.get_version() + ver_tuple = tuple(int(x) for x in version.split('.')) + + f1 = open(filename + '.tmp', 'r') + f2 = open(filename, 'w') + for line in f1: + f2.write(line + .replace('@VER_TUPLE@', str(ver_tuple)) + .replace('@VERSION@', version)) + f1.close() + f2.close() + def run(self): apis = get_api_xml_files() @@ -127,6 +142,7 @@ class my_build(build): if have_libvirt_lxc: self.spawn([sys.executable, "generator.py", "libvirt-lxc", apis[2]]) + self.gen_version('build/libvirt.py') build.run(self) class my_sdist(sdist): -- 1.8.3.2

On 12/11/2013 08:43 PM, Doug Goldstein wrote:
The method getVersion() retrieves the version of the libvirt library that the binaries are linked against but there is no way to retrieve the version of the bindings you are using. In the future if we support new APIs in Python that don't rely on features in the library there needs to be a way for programmers to detect the version. --- I would expect there's a cleaner way to implement this than I've done but I opted for what I saw as the smallest implementation. If anyone has a suggestion for a better way to do this I'm ok with redoing this patch.
The idea sounds sane to me.
--- libvirt-override.py | 3 +++ setup.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+)
Alas, my python is too weak to give either a meaningful review to the code, or to suggest an alternative. :( -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Thu, Dec 12, 2013 at 4:29 PM, Eric Blake <eblake@redhat.com> wrote:
On 12/11/2013 08:43 PM, Doug Goldstein wrote:
The method getVersion() retrieves the version of the libvirt library that the binaries are linked against but there is no way to retrieve the version of the bindings you are using. In the future if we support new APIs in Python that don't rely on features in the library there needs to be a way for programmers to detect the version. --- I would expect there's a cleaner way to implement this than I've done but I opted for what I saw as the smallest implementation. If anyone has a suggestion for a better way to do this I'm ok with redoing this patch.
The idea sounds sane to me.
--- libvirt-override.py | 3 +++ setup.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+)
Alas, my python is too weak to give either a meaningful review to the code, or to suggest an alternative. :(
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Ping for some more feedback from others. -- Doug Goldstein

Doug Goldstein wrote:
On Thu, Dec 12, 2013 at 4:29 PM, Eric Blake <eblake@redhat.com> wrote:
On 12/11/2013 08:43 PM, Doug Goldstein wrote:
The method getVersion() retrieves the version of the libvirt library that the binaries are linked against but there is no way to retrieve the version of the bindings you are using. In the future if we support new APIs in Python that don't rely on features in the library there needs to be a way for programmers to detect the version. --- I would expect there's a cleaner way to implement this than I've done but I opted for what I saw as the smallest implementation. If anyone has a suggestion for a better way to do this I'm ok with redoing this patch.
The idea sounds sane to me.
--- libvirt-override.py | 3 +++ setup.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+)
Alas, my python is too weak to give either a meaningful review to the code, or to suggest an alternative. :(
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Ping for some more feedback from others.
A have a shorter but probably a little hacky way to do this: diff --git a/libvirt-override.py b/libvirt-override.py index 63f8ecb..93b6e0a 100644 --- a/libvirt-override.py +++ b/libvirt-override.py @@ -2,6 +2,9 @@ # Manually written part of python bindings for libvirt # +version = (1, 2, 0) +__version__ = '.'.join(str(x) for x in version) + # On cygwin, the DLL is called cygvirtmod.dll import sys diff --git a/setup.py b/setup.py index 24d4cf2..1138e15 100755 --- a/setup.py +++ b/setup.py @@ -278,7 +278,7 @@ class my_clean(clean): remove_tree("build") setup(name = 'libvirt-python', - version = '1.2.0', + version = __import__('libvirt-override').__version__, url = 'http://www.libvirt.org', maintainer = 'Libvirt Maintainers', maintainer_email = 'libvir-list@redhat.com', Roman Bogorodskiy
participants (3)
-
Doug Goldstein
-
Eric Blake
-
Roman Bogorodskiy