diff options
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 fb711c3..ed20606 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) |