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__)
27 from ._gi import _API, Repository
29 # Force loading the GObject typelib so we have available the wrappers for
30 # base classes such as GInitiallyUnowned
34 _API = _API # pyflakes
39 _overridesdir = os.path.join(os.path.dirname(__file__), 'overrides')
41 version_info = gi._gobject.pygobject_version[:]
42 __version__ = "{0}.{1}.{2}".format(*version_info)
45 def check_version(version):
46 if isinstance(version, str):
47 version_list = tuple(map(int, version.split(".")))
49 version_list = version
51 if version_list > version_info:
53 "pygobject's version %s required, and available version "
54 "%s is not recent enough") % (version, __version__)
58 def require_version(namespace, version):
59 repository = Repository.get_default()
61 if namespace in repository.get_loaded_namespaces():
62 loaded_version = repository.get_version(namespace)
63 if loaded_version != version:
64 raise ValueError('Namespace %s is already loaded with version %s' %
65 (namespace, loaded_version))
67 if namespace in _versions and _versions[namespace] != version:
68 raise ValueError('Namespace %s already requires version %s' %
69 (namespace, _versions[namespace]))
71 available_versions = repository.enumerate_versions(namespace)
72 if not available_versions:
73 raise ValueError('Namespace %s not available' % namespace)
75 if version not in available_versions:
76 raise ValueError('Namespace %s not available for version %s' %
79 _versions[namespace] = version
82 def get_required_version(namespace):
83 return _versions.get(namespace, None)
86 # note, DeprecationWarning would be more suitable as a base, but this
87 # unhelpfully isn't shown by default and thus useless
88 class PyGIDeprecationWarning(RuntimeWarning):