1 # -*- Mode: Python; py-indent-offset: 4 -*-
2 # vim: tabstop=4 shiftwidth=4 expandtab
4 # Copyright (C) 2005-2009 Johan Dahlin <johan@gnome.org>
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
21 from __future__ import absolute_import
23 # support overrides in different directories than our gi module
24 from pkgutil import extend_path
25 __path__ = extend_path(__path__, __name__)
28 from ._gi import Repository
29 from ._gi import PyGIDeprecationWarning
31 # Force loading the GObject typelib so we have available the wrappers for
32 # base classes such as GInitiallyUnowned
36 _API = _API # pyflakes
37 PyGIDeprecationWarning = PyGIDeprecationWarning
42 _overridesdir = os.path.join(os.path.dirname(__file__), 'overrides')
44 version_info = gi._gobject.pygobject_version[:]
45 __version__ = "{0}.{1}.{2}".format(*version_info)
48 def check_version(version):
49 if isinstance(version, str):
50 version_list = tuple(map(int, version.split(".")))
52 version_list = version
54 if version_list > version_info:
56 "pygobject's version %s required, and available version "
57 "%s is not recent enough") % (version, __version__)
61 def require_version(namespace, version):
62 repository = Repository.get_default()
64 if namespace in repository.get_loaded_namespaces():
65 loaded_version = repository.get_version(namespace)
66 if loaded_version != version:
67 raise ValueError('Namespace %s is already loaded with version %s' %
68 (namespace, loaded_version))
70 if namespace in _versions and _versions[namespace] != version:
71 raise ValueError('Namespace %s already requires version %s' %
72 (namespace, _versions[namespace]))
74 available_versions = repository.enumerate_versions(namespace)
75 if not available_versions:
76 raise ValueError('Namespace %s not available' % namespace)
78 if version not in available_versions:
79 raise ValueError('Namespace %s not available for version %s' %
82 _versions[namespace] = version
85 def get_required_version(namespace):
86 return _versions.get(namespace, None)