summaryrefslogtreecommitdiff
path: root/gi/importer.py
Commit message (Collapse)AuthorAgeFilesLines
* Implement DynamicImporter.find_spec()Miro Hrončok2021-09-191-5/+10
| | | | | | | | | | | | | | | | | | | | | | On Python 3.10, the code raised an ImportWarning: ImportWarning: DynamicImporter.find_spec() not found; falling back to find_module() See https://docs.python.org/3.10/whatsnew/3.10.html#deprecated > Starting in this release, there will be a concerted effort to begin cleaning > up old import semantics that were kept for Python 2.7 compatibility. > Specifically, find_loader()/find_module() (superseded by find_spec()), > load_module() (superseded by exec_module()), module_repr() > (which the import system takes care of for you), > the __package__ attribute (superseded by __spec__.parent), > the __loader__ attribute (superseded by __spec__.loader), > and the __cached__ attribute (superseded by __spec__.cached) > will slowly be removed (as well as other classes and methods in importlib). > ImportWarning and/or DeprecationWarning will be raised as appropriate to help > identify code which needs updating during this transition. Fixes https://gitlab.gnome.org/GNOME/pygobject/-/issues/473
* Remove all Python 2 Python codeChristoph Reiter2020-04-151-1/+0
|
* importer: raise ImportError in load_module() and not find_module(). See #213Christoph Reiter2018-05-031-9/+9
| | | | | | | | | find_module() should either return None or a loader, but we raised ImportError there in case we already knew that the namespace was missing. Move that check to load_module() instead. While there shouldn't be any functional difference, raising in find_module() under Python 3 resulted in a chained exception with an unrelated error message printed first.
* Fix import warnings pointing to the wrong code with CPython 3.3/3.5Christoph Reiter2015-11-121-5/+23
| | | | | | | | | | | | | | | | | | For making warnings point to the code doing the import, the stack frames of the import system need to be skipped. The frame count number varries between CPython versions and in 3.5 all frames of the import system are skipped for warnings (https://bugs.python.org/issue24305). This hardcodes the frame counts for all supported CPython versions which fixes the import warning output for CPython 3.3 and 3.5. This also fixes/works around a bug in CPython 3 where if a too large stacklevel value was passed to warn(), CPython would try to interpret a file called "sys" in the same directory of the executed script (https://bugs.python.org/issue25493 and https://bugzilla.gnome.org/show_bug.cgi?id=757184). https://bugzilla.gnome.org/show_bug.cgi?id=757184
* Don't leak internal RepositoryError on import.Christoph Reiter2015-10-261-2/+5
| | | | | | | | | | In case a dependency of the imported namespace has a version conflict with an already loaded version, import would raise RepositoryError. This fixes it to raise an ImportError instead. https://bugzilla.gnome.org/show_bug.cgi?id=756033
* Import dependencies when importing typelibs from gi.repositoryChristoph Reiter2015-10-261-1/+11
| | | | | | | | | | | | Recursively import a modules dependencies when importing from gi.repository. This fixes the case where a library depends on initialization code of dependency overrides. For example libwnck expects gdk_init to be called before using its API and gdk_init gets called in the Gdk overrrides. https://bugzilla.gnome.org/show_bug.cgi?id=656314
* Don't emit require_version warning if namespace was loaded previously using ↵Christoph Reiter2015-09-221-69/+24
| | | | | | | | | | | | | | | | | | | g_irepository_require Instead of tracking loaded dependencies ourself to hide warnings if they were loaded by a previous import just look if the namespace was loaded before the import. This (a) makes the implementation much simpler and (b) also takes into account namespaces loaded outside of Python/PyGObject using the libgirepository C API (as is common in applications using libpeas with Python plugins) This also introduces a new Python wrapper for g_irepository_is_registered() to allow checking the loading state of namespaces before imports. This fixes unnecessary require_version warnings in gedit, gnome-builder, totem, rhythmbox etc. https://bugzilla.gnome.org/show_bug.cgi?id=754491
* Add gi.PyGIWarning and use it instead of PyGIDeprecationWarning in case the ↵Christoph Reiter2015-06-021-1/+2
| | | | | | | | | version to import wasn't specified. This makes the warning visible by default. See commit ef3bff4e570363e4f383d4cdae9cecd4073b03d8 for more info on the warning. https://bugzilla.gnome.org/show_bug.cgi?id=727379
* Emit ImportWarning when gi.require_version() is not usedChristoph Reiter2015-01-241-2/+97
| | | | | | | | | gi tries to import the latest version of typelibs which can cause existing code to break when a newer typelib is released. Emit an ImportWarning when gi.require_version() is not used to give developers this awareness so they can future proof their code. https://bugzilla.gnome.org/show_bug.cgi?id=727379
* Refactor overrides import/modulesChristoph Reiter2015-01-241-5/+6
| | | | | | | | Removes Registry and DynamicModule in favor of a simple module wrapper that contains only overrides and falls back to the introspection module. Moves all the overrides logic into gi.overrides; Speeds up module attribute access https://bugzilla.gnome.org/show_bug.cgi?id=736678
* Raise ImportError when importing modules not found in repositorySimon Feltman2014-03-241-5/+4
| | | | | | | | | Raise an ImportError with extra information noting the typelib was not found. This removes the need to log a similar message which adds output noise when attempting controlled imports within try/except statements. In Python 2, the additional information is lost but in Python 3 it shows up. https://bugzilla.gnome.org/show_bug.cgi?id=726877
* Remove DynamicGLibModule and DynamicGObjectModuleSimon Feltman2012-11-061-10/+2
| | | | | | | | | | Move final bits of _glib static binding imports directly into the GLib override. Change _glib/option use the .so directly rather than the staged variables in _glib/__init__.py. Remove DynamicGLibModule and DynamicGObjectModule and update unittest. https://bugzilla.gnome.org/show_bug.cgi?id=687488
* Remove all tabs and fix indentationJohan Dahlin2012-03-221-1/+0
| | | | | By running the whole source tree via the indent.py script found in the Python distribution.
* Correct pyflakes warnings/errorsJohan Dahlin2012-03-211-1/+1
| | | | | | And add a target to make check that runs pyflakes. https://bugzilla.gnome.org/show_bug.cgi?id=672578
* make GObject and GLib able to take overridesJohn (J5) Palmieri2011-08-111-6/+5
| | | | | | * derive directly from DynamicModule instead of InterfaceModule https://bugzilla.gnome.org/show_bug.cgi?id=642048
* add DynamicGLibModule which works like DynamicGObjectModuleJohn (J5) Palmieri2011-08-111-2/+5
| | | | https://bugzilla.gnome.org/show_bug.cgi?id=642048
* refactor gi module to import and use internal _gobject moduleJohn (J5) Palmieri2011-08-111-2/+0
| | | | https://bugzilla.gnome.org/show_bug.cgi?id=642048
* [gi] Remove DyanmicModule.load() to _load() to prevent overriding GI attrs.Laszlo Pandy2011-02-241-1/+1
|
* Don't force loading of DynamicModule until set in sys.modulesLaszlo Pandy2011-02-231-1/+1
| | | | | | | | This fixes Tomeu's previous commit, which removed lazy loading. Forcing the loading of a module before it is installed in sys.modules prevents some overrides from being registered (namely Gtk.main_quit). https://bugzilla.gnome.org/show_bug.cgi?id=642305
* Load typelibs at import time, add gi.require_version()Tomeu Vizoso2011-02-221-0/+1
| | | | | | also adds Repository.get_loaded_namespaces() https://bugzilla.gnome.org/show_bug.cgi?id=642305
* Adapt to API changes: g_irepository_enumerate_versionsTomeu Vizoso2010-07-281-1/+1
|
* Allow specifying a version when loading a typelibTomeu Vizoso2010-07-271-17/+9
| | | | | | | | * gi/importer.py: Defer loading the typelib until first usage. * gi/module.py: Load the typelib in IntrospectionModule(). * gi/overrides/*.py: Adapt to API change. * gi/pygi-repository.c: Add wrappers for g_irepository_enumerate and g_irepository_get_version.
* Adjust to API break in GObject-Introspection=?UTF-8?q?Florian=20M=C3=BCllner?=2010-07-121-3/+4
| | | | | | | | | | | | | | As of commit 5cb925b20, many type_tags for standard C types have been removed - namely machine-dependent integer types and derived types (size_t, time_t). Most removals are just synonyms of other types, so their removal should not have too much impact, with the exception of time_t, which was translated to a native datetime object before. Also remove time_t tests (Tomeu Vizoso). https://bugzilla.gnome.org/show_bug.cgi?id=624065
* wrap GObject module so we can go through GI when requesting attrsJohn (J5) Palmieri2010-05-111-3/+3
| | | | | | | | | | | | * This gives us the best of both worlds. - We remain backwards compatable with pygobject by checking for existing attrs in the gobject module - If an attr does not exist we use the GI mechanism to look it up so that things like flags look the same whether exported from GObject, Gtk or any GI managed library * add DynamicGObjectModule tests and make tests use the new module - change import gobject to from gi.repository import GObject
* Restore the overrides supportSimon van der Linden2010-01-221-26/+14
| | | | | | | | | | | | | Add a ModuleProxy in front of the DynamicModule when an overrides module is present. There is no need for an overrides module to be a class; it can just be a module. Add an override decorator to override the wrapper of a registered type. Adapt Gdk and Gtk accordingly. Add tests. https://bugzilla.gnome.org/show_bug.cgi?id=602830
* Use the right variable when looking up in sys.modulesSimon van der Linden2009-11-251-1/+1
|
* Create overridden modules in two passesJohan Dahlin2009-11-231-13/+21
| | | | | | | | This patch splits overridden module creation into two passes. The first pass creates the auto-generated module normally before the overridden module is attempted to be imported. The second pass imports the overridden module and replaces the auto-generated module with the overridden. This is necessary for the overridden modules to be able to access the auto-generated ones.
* Initial importSimon van der Linden2009-11-081-0/+89