From ab1ba8959fb49fe3662c8f45bcf30765ace062e2 Mon Sep 17 00:00:00 2001 From: DongHun Kwak Date: Thu, 14 Jul 2022 11:08:07 +0900 Subject: [PATCH] Imported Upstream version 3.42.1 --- .gitlab-ci/test-msys2.sh | 3 ++ NEWS | 10 +++++++ gi/importer.py | 15 ++++++---- gi/overrides/Gtk.py | 55 +++++++++++++++++++++---------------- gi/pygi-closure.c | 6 ++-- meson.build | 2 +- pyproject.toml | 2 +- setup.py | 2 +- tests/__init__.py | 6 ++-- tests/test_docstring.py | 5 ++-- tests/test_glib.py | 6 ++-- tests/test_overrides_gtk.py | 29 ++++++++++++++++++- 12 files changed, 101 insertions(+), 40 deletions(-) diff --git a/.gitlab-ci/test-msys2.sh b/.gitlab-ci/test-msys2.sh index 8fc4214..8cd39af 100755 --- a/.gitlab-ci/test-msys2.sh +++ b/.gitlab-ci/test-msys2.sh @@ -32,6 +32,9 @@ COV_KEY="${CI_JOB_NAME}" mkdir -p "${COV_DIR}" export COVERAGE_FILE="${COV_DIR}/.coverage.${COV_KEY}" +# FIXME: g_callable_info_free_closure etc +CFLAGS+=" -Wno-error=deprecated-declarations" + # https://docs.python.org/3/using/cmdline.html#envvar-PYTHONDEVMODE export PYTHONDEVMODE=1 diff --git a/NEWS b/NEWS index facff70..3b77c8e 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,13 @@ +3.42.1 - 2022-04-17 +------------------- + +* Do not error out for unknown scopes :mr:`179` +* gtk overrides: restore Gtk.ListStore.insert_with_valuesv with newer gtk4 :issue:`467` +* gtk overrides: Do not override Treeview.enable_model_drag_xx for GTK4 :mr:`175` +* Implement DynamicImporter.find_spec() to silence a deprecation warning with Python 3.10 :issue:`473` +* Some test/CI fixes + + 3.42.0 - 2021-09-19 ------------------- diff --git a/gi/importer.py b/gi/importer.py index 3296797..6378877 100644 --- a/gi/importer.py +++ b/gi/importer.py @@ -107,15 +107,20 @@ class DynamicImporter(object): def __init__(self, path): self.path = path - def find_module(self, fullname, path=None): + def _find_module_check(self, fullname): if not fullname.startswith(self.path): - return + return False path, namespace = fullname.rsplit('.', 1) - if path != self.path: - return + return path == self.path + + def find_spec(self, fullname, path=None, target=None): + if self._find_module_check(fullname): + return importlib.util.spec_from_loader(fullname, self) - return self + def find_module(self, fullname, path=None): + if self._find_module_check(fullname): + return self def load_module(self, fullname): if fullname in sys.modules: diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py index 7739751..6ddc12f 100644 --- a/gi/overrides/Gtk.py +++ b/gi/overrides/Gtk.py @@ -64,21 +64,21 @@ class PyGTKDeprecationWarning(PyGIDeprecationWarning): __all__.append('PyGTKDeprecationWarning') -def _construct_target_list(targets): - """Create a list of TargetEntry items from a list of tuples in the form (target, flags, info) - - The list can also contain existing TargetEntry items in which case the existing entry - is re-used in the return list. - """ - target_entries = [] - for entry in targets: - if not isinstance(entry, Gtk.TargetEntry): - entry = Gtk.TargetEntry.new(*entry) - target_entries.append(entry) - return target_entries +if GTK2 or GTK3: + def _construct_target_list(targets): + """Create a list of TargetEntry items from a list of tuples in the form (target, flags, info) + The list can also contain existing TargetEntry items in which case the existing entry + is re-used in the return list. + """ + target_entries = [] + for entry in targets: + if not isinstance(entry, Gtk.TargetEntry): + entry = Gtk.TargetEntry.new(*entry) + target_entries.append(entry) + return target_entries -__all__.append('_construct_target_list') + __all__.append('_construct_target_list') def _builder_connect_callback(builder, gobj, signal_name, handler_name, connect_obj, flags, obj_or_map): @@ -995,10 +995,17 @@ class ListStore(Gtk.ListStore, TreeModel, TreeSortable): Gtk.ListStore.__init__(self) self.set_column_types(column_types) + # insert_with_valuesv got renamed to insert_with_values with 4.1.0 + # https://gitlab.gnome.org/GNOME/gtk/-/commit/a1216599ff6b39bca3e9 + if not hasattr(Gtk.ListStore, "insert_with_valuesv"): + insert_with_valuesv = Gtk.ListStore.insert_with_values + elif not hasattr(Gtk.ListStore, "insert_with_values"): + insert_with_values = Gtk.ListStore.insert_with_valuesv + def _do_insert(self, position, row): if row is not None: row, columns = self._convert_row(row) - treeiter = self.insert_with_valuesv(position, columns, row) + treeiter = self.insert_with_values(position, columns, row) else: treeiter = Gtk.ListStore.insert(self, position) @@ -1352,16 +1359,18 @@ class TreeView(Gtk.TreeView, Container): get_visible_range = strip_boolean_result(Gtk.TreeView.get_visible_range) get_dest_row_at_pos = strip_boolean_result(Gtk.TreeView.get_dest_row_at_pos) - def enable_model_drag_source(self, start_button_mask, targets, actions): - target_entries = _construct_target_list(targets) - super(TreeView, self).enable_model_drag_source(start_button_mask, - target_entries, - actions) + if GTK2 or GTK3: + def enable_model_drag_source(self, start_button_mask, targets, actions): + target_entries = _construct_target_list(targets) + super(TreeView, self).enable_model_drag_source(start_button_mask, + target_entries, + actions) - def enable_model_drag_dest(self, targets, actions): - target_entries = _construct_target_list(targets) - super(TreeView, self).enable_model_drag_dest(target_entries, - actions) + if GTK2 or GTK3: + def enable_model_drag_dest(self, targets, actions): + target_entries = _construct_target_list(targets) + super(TreeView, self).enable_model_drag_dest(target_entries, + actions) def scroll_to_cell(self, path, column=None, use_align=False, row_align=0.0, col_align=0.0): if not isinstance(path, Gtk.TreePath): diff --git a/gi/pygi-closure.c b/gi/pygi-closure.c index 136eec6..5504f24 100644 --- a/gi/pygi-closure.c +++ b/gi/pygi-closure.c @@ -620,8 +620,10 @@ end: async_free_list = g_slist_prepend (async_free_list, closure); break; default: - g_error ("Invalid scope reached inside %s. Possibly a bad annotation?", - g_base_info_get_name (closure->info)); + /* Handle new scopes added by gobject-introspection */ + g_critical ("Unknown scope reached inside %s. Please file an issue " + "at https://gitlab.gnome.org/GNOME/pygobject/issues/new", + g_base_info_get_name (closure->info)); } _invoke_state_clear (&state); diff --git a/meson.build b/meson.build index 5b53432..9606fdd 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ project('pygobject', 'c', - version : '3.42.0', + version : '3.42.1', meson_version : '>= 0.47.0', default_options : [ 'warning_level=1', 'buildtype=debugoptimized']) diff --git a/pyproject.toml b/pyproject.toml index dd8e7ea..dfe95b8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "PyGObject" -version = "3.42.0" +version = "3.42.1" description = "Python bindings for GObject Introspection" authors = ["Christoph Reiter"] diff --git a/setup.py b/setup.py index 8de6996..cb50ccb 100755 --- a/setup.py +++ b/setup.py @@ -37,7 +37,7 @@ from distutils import dir_util, log from distutils.spawn import find_executable -PYGOBJECT_VERSION = "3.42.0" +PYGOBJECT_VERSION = "3.42.1" GLIB_VERSION_REQUIRED = "2.56.0" GI_VERSION_REQUIRED = "1.56.0" PYCAIRO_VERSION_REQUIRED = "1.16.0" diff --git a/tests/__init__.py b/tests/__init__.py index 125f231..2bcb52e 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -44,8 +44,10 @@ def init_test_environ(): # force untranslated messages, as we check for them in some tests os.environ['LC_MESSAGES'] = 'C' os.environ['G_DEBUG'] = 'fatal-warnings fatal-criticals' - if sys.platform == "darwin": - # gtk 3.22 has warnings and ciriticals on OS X, ignore for now + if sys.platform == "darwin" or os.name == "nt": + # gtk 3.22 has warnings and ciriticals on OS X, ignore for now. + # On Windows glib will create an error dialog which will block tests + # so it's never a good idea there to make things fatal. os.environ['G_DEBUG'] = '' # make Gio able to find our gschemas.compiled in tests/. This needs to be set diff --git a/tests/test_docstring.py b/tests/test_docstring.py index 29b7e5e..49d030f 100644 --- a/tests/test_docstring.py +++ b/tests/test_docstring.py @@ -93,8 +93,9 @@ class Test(unittest.TestCase): @unittest.skipUnless(Gtk, 'no Gtk') def test_shared_array_length_with_prior_out_arg(self): # Test the 'iter' out argument does not effect length argument skipping. - self.assertEqual(Gtk.ListStore.insert_with_valuesv.__doc__, - 'insert_with_valuesv(self, position:int, columns:list, values:list) -> iter:Gtk.TreeIter') + self.assertRegex( + Gtk.ListStore.insert_with_valuesv.__doc__, + 'insert_with_values.*\\(self, position:int, columns:list, values:list\\) -> iter:Gtk.TreeIter') def test_sub_class_doc(self): class A(GObject.Object): diff --git a/tests/test_glib.py b/tests/test_glib.py index 0a5cb3d..19eff7f 100644 --- a/tests/test_glib.py +++ b/tests/test_glib.py @@ -282,8 +282,10 @@ https://my.org/q?x=1&y=2 self.assertGreaterEqual(micro, 0) def test_timezone_constructor(self): - timezone = GLib.TimeZone("+05:21") - self.assertEqual(timezone.get_offset(0), ((5 * 60) + 21) * 60) + with warnings.catch_warnings(): + warnings.simplefilter('ignore', DeprecationWarning) + timezone = GLib.TimeZone("+05:21") + self.assertEqual(timezone.get_offset(0), ((5 * 60) + 21) * 60) def test_source_attach_implicit_context(self): context = GLib.MainContext.default() diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py index 72fd2c8..50c1ad8 100644 --- a/tests/test_overrides_gtk.py +++ b/tests/test_overrides_gtk.py @@ -786,7 +786,7 @@ class TestGtk(unittest.TestCase): @unittest.skipIf(sys.platform == "darwin", "crashes") @unittest.skipIf(GTK4, "uses lots of gtk3 only api") - def test_drag_target_list_gtk3(self): + def test_tree_view_drag_target_list_gtk3(self): mixed_target_list = [Gtk.TargetEntry.new('test0', 0, 0), ('test1', 1, 1), Gtk.TargetEntry.new('test2', 2, 2), @@ -818,6 +818,19 @@ class TestGtk(unittest.TestCase): treeview.enable_model_drag_dest(mixed_target_list, Gdk.DragAction.DEFAULT | Gdk.DragAction.MOVE) + @unittest.skipUnless(GTK4, "gtk4 only") + def test_tree_view_drag_content_formats_gtk4(self): + content_formats = Gdk.ContentFormats.new( + ["application/json", "GTK_TREE_MODEL_ROW"] + ) + treeview = Gtk.TreeView() + treeview.enable_model_drag_source(Gdk.ModifierType.BUTTON1_MASK, + content_formats, + Gdk.DragAction.MOVE) + + treeview.enable_model_drag_dest(content_formats, + Gdk.DragAction.MOVE) + @unittest.skipIf(Gtk_version == "4.0", "not in gtk4") def test_scrollbar(self): adjustment = Gtk.Adjustment() @@ -1377,6 +1390,20 @@ class TestCustomSorter(): assert result.props.name == member +@unittest.skipUnless(Gtk, 'Gtk not available') +class TestListStore(unittest.TestCase): + + def test_insert_with_values(self): + model = Gtk.ListStore(int) + assert hasattr(model, 'insert_with_values') + iter_ = model.insert_with_values(0, (0,), [42]) + assert isinstance(iter_, Gtk.TreeIter) + assert hasattr(model, 'insert_with_valuesv') + iter_ = model.insert_with_valuesv(0, (0,), [43]) + assert isinstance(iter_, Gtk.TreeIter) + assert len(model) == 2 + + @ignore_gi_deprecation_warnings @unittest.skipUnless(Gtk, 'Gtk not available') class TestTreeModel(unittest.TestCase): -- 2.34.1