diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-07-12 08:45:38 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-07-12 08:45:42 +0900 |
commit | 4e74666c3f696a306557bf302a5e05d649e03365 (patch) | |
tree | 53d3fa896b1bb5c382c3b1af6099d4b66f7a9be8 /gi/__init__.py | |
parent | 524563d888cea78be703c2fc5684a97843d58e13 (diff) | |
download | pygobject2-4e74666c3f696a306557bf302a5e05d649e03365.tar.gz pygobject2-4e74666c3f696a306557bf302a5e05d649e03365.tar.bz2 pygobject2-4e74666c3f696a306557bf302a5e05d649e03365.zip |
Imported Upstream version 3.21.0
Change-Id: I4e251bc1c49af4a51139f4acc742cce1276663fa
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'gi/__init__.py')
-rw-r--r-- | gi/__init__.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/gi/__init__.py b/gi/__init__.py index caad569..1b139c6 100644 --- a/gi/__init__.py +++ b/gi/__init__.py @@ -85,6 +85,22 @@ def check_version(version): def require_version(namespace, version): + """ Ensures the correct versions are loaded when importing `gi` modules. + + :param namespace: The name of module to require. + :type namespace: str + :param version: The version of module to require. + :type version: str + :raises ValueError: If module/version is already loaded, already required, or unavailable. + + :Example: + + .. code-block:: python + + import gi + gi.require_version('Gtk', '3.0') + + """ repository = Repository.get_default() if namespace in repository.get_loaded_namespaces(): @@ -108,6 +124,23 @@ def require_version(namespace, version): _versions[namespace] = version +def require_versions(requires): + """ Utility function for consolidating multiple `gi.require_version()` calls. + + :param requires: The names and versions of modules to require. + :type requires: dict + + :Example: + + .. code-block:: python + + import gi + gi.require_versions({'Gtk': '3.0', 'GLib': '2.0', 'Gio': '2.0'}) + """ + for module_name, module_version in requires.items(): + require_version(module_name, module_version) + + def get_required_version(namespace): return _versions.get(namespace, None) |