[pygobject] [API add] Add API for checking pygobject's version
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] [API add] Add API for checking pygobject's version
- Date: Thu, 19 Jul 2012 13:51:11 +0000 (UTC)
commit a3aae2e152c0b955037b7b85e16d14d00881d870
Author: Joe R. Nassimian <placidrage gmail com>
Date: Thu Jul 19 15:48:20 2012 +0200
[API add] Add API for checking pygobject's version
Add a gi.__version__ attribute for the textual version, and gi.version_info for
a version triple similar to sys.version_info.
Also add a gi.require_version(<minimum_version>) which raises an exception if
the pygobject version is older.
https://bugzilla.gnome.org/show_bug.cgi?id=680176
Signed-off-by: Martin Pitt <martinpitt gnome org>
gi/__init__.py | 16 ++++++++++++++++
tests/test_gi.py | 16 ++++++++++++++++
2 files changed, 32 insertions(+), 0 deletions(-)
---
diff --git a/gi/__init__.py b/gi/__init__.py
index c1aba69..b816612 100644
--- a/gi/__init__.py
+++ b/gi/__init__.py
@@ -34,6 +34,22 @@ import os
_versions = {}
_overridesdir = os.path.join(os.path.dirname(__file__), 'overrides')
+version_info = gi._gobject.pygobject_version[:]
+__version__ = "{0}.{1}.{2}".format(*version_info)
+
+
+def check_version(version):
+ if isinstance(version, str):
+ version_list = tuple(map(int, version.split(".")))
+ else:
+ version_list = version
+
+ if version_list > version_info:
+ raise ValueError((
+ "pygobject's version %s required, and available version "
+ "%s is not recent enough") % (version, __version__)
+ )
+
def require_version(namespace, version):
repository = Repository.get_default()
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 4348c29..f8ccfc8 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -12,6 +12,7 @@ import locale
import subprocess
from io import StringIO, BytesIO
+import gi
from gi.repository import GObject, GLib
from gi.repository import GIMarshallingTests
@@ -2292,3 +2293,18 @@ class TestModule(unittest.TestCase):
self.assertTrue('SimpleStruct' in output, output)
self.assertTrue('Interface2' in output, output)
self.assertTrue('method_array_inout' in output, output)
+
+
+class TestProjectVersion(unittest.TestCase):
+ def test_version_str(self):
+ self.assertGreaterEqual(gi.__version__, "3.3.5")
+
+ def test_version_info(self):
+ self.assertEqual(len(gi.version_info), 3)
+ self.assertGreaterEqual(gi.version_info, (3, 3, 5))
+
+ def test_check_version(self):
+ self.assertRaises(ValueError, gi.check_version, (99, 0, 0))
+ self.assertRaises(ValueError, gi.check_version, "99.0.0")
+ gi.check_version((3, 3, 5))
+ gi.check_version("3.3.5")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]