diff options
author | Tomeu Vizoso <tomeu.vizoso@collabora.co.uk> | 2011-02-16 11:53:18 +0100 |
---|---|---|
committer | Tomeu Vizoso <tomeu.vizoso@collabora.co.uk> | 2011-02-22 17:16:03 +0100 |
commit | 76758efb6579752237a0dc4d56cf9518de6c6e55 (patch) | |
tree | 59ea05f0fe63a5007297711c1cf2aedc214f6ca6 /gi/__init__.py | |
parent | 96f7d1aed732db09a74cd463ed894b7347dbcb15 (diff) | |
download | pygobject-76758efb6579752237a0dc4d56cf9518de6c6e55.tar.gz |
Load typelibs at import time, add gi.require_version()
also adds Repository.get_loaded_namespaces()
https://bugzilla.gnome.org/show_bug.cgi?id=642305
Diffstat (limited to 'gi/__init__.py')
-rw-r--r-- | gi/__init__.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/gi/__init__.py b/gi/__init__.py index fb711c38..ed206063 100644 --- a/gi/__init__.py +++ b/gi/__init__.py @@ -20,8 +20,35 @@ from __future__ import absolute_import -from ._gi import _API +from ._gi import _API, Repository # Force loading the GObject typelib so we have available the wrappers for # base classes such as GInitiallyUnowned from gi.repository import GObject + +_versions = {} + +def require_version(namespace, version): + repository = Repository.get_default() + + if namespace in repository.get_loaded_namespaces(): + if repository.get_version(namespace) != version: + raise ValueError('Namespace %s is already loaded with version %s' % \ + (namespace, loaded_version)) + + if namespace in _versions and _versions[namespace] != version: + raise ValueError('Namespace %s already requires version %s' % \ + (namespace, _versions[namespace])) + + available_versions = repository.enumerate_versions(namespace) + if not available_versions: + raise ValueError('Namespace %s not available' % namespace) + + if version not in available_versions: + raise ValueError('Namespace %s not available for version %s' % \ + (namespace, version)) + + _versions[namespace] = version + +def get_required_version(namespace): + return _versions.get(namespace, None) |