From 54fae7ae44d06bd920816004a686c1e17751cb54 Mon Sep 17 00:00:00 2001 From: DongHun Kwak Date: Wed, 12 Jul 2017 08:42:56 +0900 Subject: [PATCH] Imported Upstream version 3.15.0 Change-Id: I02b859dff581f456d759a90a2aea3eeec391e2ff Signed-off-by: DongHun Kwak --- ChangeLog | 188 ++++++++++++++++++++ NEWS | 10 ++ PKG-INFO | 4 +- aclocal.m4 | 17 +- config.guess | 313 +++++++++++---------------------- config.sub | 56 +++--- configure | 25 +-- configure.ac | 2 +- gi/gimodule.c | 39 ---- gi/importer.py | 106 ++++++++++- gi/module.py | 68 ------- gi/overrides/GLib.py | 12 +- gi/overrides/Gdk.py | 5 + gi/overrides/__init__.py | 131 ++++++++++---- gi/pygi-array.c | 23 ++- gi/pygi-cache.h | 8 +- gi/pygi-info.c | 7 + gi/pygi-repository.c | 35 ++++ gi/pygobject.h | 2 +- gi/pygoptiongroup.c | 5 +- gi/types.py | 10 +- tests/compat_test_pygtk.py | 16 +- tests/test_atoms.py | 6 +- tests/test_everything.py | 9 + tests/test_gi.py | 17 +- tests/test_glib.py | 6 +- tests/test_import_machinery.py | 56 +++++- tests/test_overrides_gdk.py | 12 ++ tests/test_overrides_gtk.py | 7 +- tests/test_overrides_pango.py | 5 +- tests/test_properties.py | 5 +- tests/test_repository.py | 10 ++ 32 files changed, 769 insertions(+), 446 deletions(-) diff --git a/ChangeLog b/ChangeLog index 926e5ff..970c134 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,191 @@ +commit 5dc113283c0a721c4027026bb8de7243585f1289 +Author: Simon Feltman +Date: Fri Feb 20 21:59:10 2015 -0800 + + Ignore deprecation warning for g_option_group_free() + + gi/pygoptiongroup.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +commit d8961622ea748c42171bdb4703e70022035ec3cc +Author: Simon Feltman +Date: Fri Feb 20 21:52:58 2015 -0800 + + tests: Make get_all_dependendencies() test more robust + + Replace array comparison with checking if individual items are in + the array. + This solves a problem where the returned array might be in a + different order + as well as future proofs the test in case more dependencies are added. + + tests/test_import_machinery.py | 8 +++++--- + 1 file changed, 5 insertions(+), 3 deletions(-) + +commit b10ab49afb97655507e2d3b92f621387287a2928 +Author: Simon Feltman +Date: Fri Feb 20 20:16:35 2015 -0800 + + tests: Fix PEP8 error with commented code in test + + tests/test_gi.py | 1 - + 1 file changed, 1 deletion(-) + +commit 60de632153a693fb2b0f2ce26208c6ff668bdf4d +Author: Garrett Regier +Date: Tue Jan 27 10:39:53 2015 -0800 + + Avoid copying bytearrays from Python to C when transfer nothing + + https://bugzilla.gnome.org/show_bug.cgi?id=743278 + + gi/pygi-array.c | 23 +++++++++++++++++++---- + tests/test_gi.py | 14 +++++++++++++- + 2 files changed, 32 insertions(+), 5 deletions(-) + +commit a4160892dd28ab1d656cef4d4059f3b3f95caf4a +Author: Garrett Regier +Date: Mon Jan 19 14:53:53 2015 -0800 + + Allows passing arguments to opaque Boxed types + + https://bugzilla.gnome.org/show_bug.cgi?id=743214 + + gi/pygi-info.c | 7 +++++++ + gi/types.py | 10 +++++++++- + tests/test_everything.py | 9 +++++++++ + tests/test_glib.py | 6 +++--- + 4 files changed, 28 insertions(+), 4 deletions(-) + +commit ef3bff4e570363e4f383d4cdae9cecd4073b03d8 +Author: Christoph Reiter +Date: Sat Jan 24 20:01:00 2015 +0100 + + Emit ImportWarning when gi.require_version() is not used + + 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 + + gi/importer.py | 99 + +++++++++++++++++++++++++++++++++++++++++- + gi/pygi-repository.c | 35 +++++++++++++++ + tests/compat_test_pygtk.py | 7 ++- + tests/test_atoms.py | 6 ++- + tests/test_import_machinery.py | 22 ++++++++++ + tests/test_overrides_gtk.py | 7 ++- + tests/test_overrides_pango.py | 5 ++- + tests/test_properties.py | 5 ++- + tests/test_repository.py | 10 +++++ + 9 files changed, 187 insertions(+), 9 deletions(-) + +commit 149c31beced944c72fba6ca6e096c81c1100ea2b +Author: Christoph Reiter +Date: Tue Dec 2 15:38:57 2014 +0100 + + Refactor overrides import/modules + + 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 + + gi/importer.py | 11 ++-- + gi/module.py | 68 --------------------- + gi/overrides/__init__.py | 131 + ++++++++++++++++++++++++++++++----------- + tests/test_gi.py | 4 -- + tests/test_import_machinery.py | 32 +++++++--- + 5 files changed, 126 insertions(+), 120 deletions(-) + +commit 4d0ab13a8461f781986accc637fada3909cfb91a +Author: Simon Feltman +Date: Thu Aug 21 15:11:39 2014 -0700 + + Replace statically bound GLib.Variant.new_tuple() with GI + + Remove the static implementation of _wrap_pyg_variant_new_tuple with + usage of the dynamic version coming from GI. Array marshalling has + drastically improved in recent years making the dynamic version usable + with a small compatibility shim for the arguments. + + https://bugzilla.gnome.org/show_bug.cgi?id=735199 + + gi/gimodule.c | 39 --------------------------------------- + gi/overrides/GLib.py | 12 +++++------- + 2 files changed, 5 insertions(+), 46 deletions(-) + +commit 17ec0d39069b7a4cc19691ea1284f821caf84d24 +Author: Simon Feltman +Date: Wed Sep 10 13:30:48 2014 -0700 + + overrides: Add Gdk.EventTouch union discrimination + + Add EventTouch to get/setattr pass-through to support BEGIN, + UPDATE, END, + and CANCEL touch event types. Ensure Gdk.Event methods get_state(), + get_axis(), get_coords(), and get_root_coords() are patched onto + Gdk.EventTouch. + + https://bugzilla.gnome.org/show_bug.cgi?id=736380 + + gi/overrides/Gdk.py | 5 +++++ + tests/test_overrides_gdk.py | 12 ++++++++++++ + 2 files changed, 17 insertions(+) + +commit 16408a81713157cdf1e3b6bd74bd53e816e9dfda +Author: Simon Feltman +Date: Sat Jan 3 17:20:14 2015 -0800 + + tests: Update pixbuf loader test to not raise exception when closing + + GdkPixbuf commit: + https://git.gnome.org/browse/gdk-pixbuf/commit/?id=447bd32650af + changed the close() method to raise if the a loader is prematurely + closed. + Update the test to write a 1x1 PNG stream to ensure close() will + succeed. + + tests/compat_test_pygtk.py | 9 +++++++++ + 1 file changed, 9 insertions(+) + +commit fd3935541ab4baddb504e000ec659b80923afa13 +Author: Murray Cumming +Date: Tue Dec 2 19:55:51 2014 +0100 + + PyGObjectFlags: Remove a trailing comma on the enum. + + Because this produces a g++ pedantic warning. + + gi/pygobject.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +commit 3b70f5bc8e59e49795fcaa7b285aeff0c4565a04 +Author: Simon Feltman +Date: Mon Oct 27 20:19:23 2014 -0700 + + Remove redefinitions of function and vfunc cache typedefs + + https://bugzilla.gnome.org/show_bug.cgi?id=737874 + + gi/pygi-cache.h | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +commit cec9c2b253bdbc1e6493630c533acf6bb4509114 +Author: Simon Feltman +Date: Mon Sep 22 13:26:24 2014 -0700 + + configure.ac: post release version bump to 3.15.0 + + configure.ac | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + commit f20df385f480b65a8128986ce3df4022b324ade0 Author: Simon Feltman Date: Mon Sep 22 12:38:35 2014 -0700 diff --git a/NEWS b/NEWS index 277cc31..48ddaca 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,13 @@ +3.15.0 20-Feb-2015 + - Avoid copying bytearrays from Python to C when transfer nothing (Garrett Regier) (#743278) + - Allows passing arguments to opaque Boxed types (Garrett Regier) (#743214) + - Emit ImportWarning when gi.require_version() is not used (Christoph Reiter) (#727379) + - Refactor overrides import/modules (Christoph Reiter) (#736678) + - Replace statically bound GLib.Variant.new_tuple() with GI (Simon Feltman) (#735199) + - overrides: Add Gdk.EventTouch union discrimination (Simon Feltman) (#736380) + - PyGObjectFlags: Remove a trailing comma on the enum. (Murray Cumming) + - Remove redefinitions of function and vfunc cache typedefs (Simon Feltman) (#737874) + 3.14.0 22-Sep-2014 - configure.ac: pre release version bump to 3.14.0 (Simon Feltman) diff --git a/PKG-INFO b/PKG-INFO index 2c2abd2..86cbefd 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: PyGObject -Version: 3.14.0 +Version: 3.15.0 Summary: Python bindings for GObject Home-page: http://www.pygtk.org/ Author: James Henstridge @@ -8,7 +8,7 @@ Author-email: james@daa.com.au Maintainer: Simon Feltman Maintainer-email: sfeltman@src.gnome.org License: GNU LGPL -Download-url: ftp://ftp.gnome.org/pub/GNOME/sources/pygobject/3.14/pygobject-3.14.0.tar.gz +Download-url: ftp://ftp.gnome.org/pub/GNOME/sources/pygobject/3.15/pygobject-3.15.0.tar.gz Description: Python bindings for GLib and GObject Platform: POSIX, Windows Classifier: Development Status :: 5 - Production/Stable diff --git a/aclocal.m4 b/aclocal.m4 index e3d59c3..f016585 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -672,7 +672,7 @@ See: http://www.gnu.org/software/autoconf-archive/ax_code_coverage.html#ax_code_ # gnome-compiler-flags.m4 # -# serial 2 +# serial 4 # dnl GNOME_COMPILE_WARNINGS @@ -684,7 +684,7 @@ dnl the first argument to the macro, defaulting to 'yes'. dnl Additional warning/error flags can be passed as an optional second argument. dnl dnl For example: GNOME_COMPILE_WARNINGS([maximum],[-Werror=some-flag -Wfoobar]) -AC_DEFUN([GNOME_COMPILE_WARNINGS],[ +AU_DEFUN([GNOME_COMPILE_WARNINGS],[ dnl ****************************** dnl More compiler warnings dnl ****************************** @@ -721,6 +721,7 @@ AC_DEFUN([GNOME_COMPILE_WARNINGS],[ -Werror=format-security \ -Werror=format=2 \ -Werror=missing-include-dirs \ + -Werror=return-type \ " dnl Additional warning or error flags provided by the module author to @@ -791,11 +792,14 @@ AC_DEFUN([GNOME_COMPILE_WARNINGS],[ WARN_CFLAGS="$tested_warning_flags $complCFLAGS" AC_SUBST(WARN_CFLAGS) -]) +], +[[$0: This macro is deprecated. You should use AX_COMPILER_FLAGS instead and +eliminate use of --enable-iso-c. +See: http://www.gnu.org/software/autoconf-archive/ax_compiler_flags.html#ax_compiler_flags]]) dnl For C++, do basically the same thing. -AC_DEFUN([GNOME_CXX_WARNINGS],[ +AU_DEFUN([GNOME_CXX_WARNINGS],[ AC_ARG_ENABLE(cxx-warnings, AS_HELP_STRING([--enable-cxx-warnings=@<:@no/minimum/yes@:>@] [Turn on compiler warnings.]),, @@ -846,7 +850,10 @@ AC_DEFUN([GNOME_CXX_WARNINGS],[ WARN_CXXFLAGS="$CXXFLAGS $warnCXXFLAGS $complCXXFLAGS" AC_SUBST(WARN_CXXFLAGS) -]) +], +[[$0: This macro is deprecated. You should use AX_COMPILER_FLAGS instead and +eliminate use of --enable-iso-cxx. +See: http://www.gnu.org/software/autoconf-archive/ax_compiler_flags.html#ax_compiler_flags]]) # Copyright (C) 2002-2013 Free Software Foundation, Inc. # diff --git a/config.guess b/config.guess index 1804e9f..1f5c50c 100755 --- a/config.guess +++ b/config.guess @@ -1,10 +1,8 @@ #! /bin/sh # Attempt to guess a canonical system name. -# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, -# 2011, 2012, 2013 Free Software Foundation, Inc. +# Copyright 1992-2014 Free Software Foundation, Inc. -timestamp='2012-12-29' +timestamp='2014-03-23' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -26,7 +24,7 @@ timestamp='2012-12-29' # program. This Exception is an additional permission under section 7 # of the GNU General Public License, version 3 ("GPLv3"). # -# Originally written by Per Bothner. +# Originally written by Per Bothner. # # You can get the latest version of this script from: # http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD @@ -52,9 +50,7 @@ version="\ GNU config.guess ($timestamp) Originally written by Per Bothner. -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, -2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, -2012, 2013 Free Software Foundation, Inc. +Copyright 1992-2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." @@ -136,6 +132,27 @@ UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown +case "${UNAME_SYSTEM}" in +Linux|GNU|GNU/*) + # If the system lacks a compiler, then just pick glibc. + # We could probably try harder. + LIBC=gnu + + eval $set_cc_for_build + cat <<-EOF > $dummy.c + #include + #if defined(__UCLIBC__) + LIBC=uclibc + #elif defined(__dietlibc__) + LIBC=dietlibc + #else + LIBC=gnu + #endif + EOF + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC' | sed 's, ,,g'` + ;; +esac + # Note: order is significant - the case branches are not exclusive. case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in @@ -809,7 +826,7 @@ EOF *:MINGW*:*) echo ${UNAME_MACHINE}-pc-mingw32 exit ;; - i*:MSYS*:*) + *:MSYS*:*) echo ${UNAME_MACHINE}-pc-msys exit ;; i*:windows32*:*) @@ -857,21 +874,21 @@ EOF exit ;; *:GNU:*:*) # the GNU system - echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` + echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-${LIBC}`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` exit ;; *:GNU/*:*:*) # other systems with GNU libc and userland - echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu + echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC} exit ;; i*86:Minix:*:*) echo ${UNAME_MACHINE}-pc-minix exit ;; aarch64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; aarch64_be:Linux:*:*) UNAME_MACHINE=aarch64_be - echo ${UNAME_MACHINE}-unknown-linux-gnu + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; alpha:Linux:*:*) case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in @@ -884,59 +901,54 @@ EOF EV68*) UNAME_MACHINE=alphaev68 ;; esac objdump --private-headers /bin/sh | grep -q ld.so.1 - if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi - echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} + if test "$?" = 0 ; then LIBC="gnulibc1" ; fi + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + exit ;; + arc:Linux:*:* | arceb:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; arm*:Linux:*:*) eval $set_cc_for_build if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_EABI__ then - echo ${UNAME_MACHINE}-unknown-linux-gnu + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} else if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_PCS_VFP then - echo ${UNAME_MACHINE}-unknown-linux-gnueabi + echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabi else - echo ${UNAME_MACHINE}-unknown-linux-gnueabihf + echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabihf fi fi exit ;; avr32*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; cris:Linux:*:*) - echo ${UNAME_MACHINE}-axis-linux-gnu + echo ${UNAME_MACHINE}-axis-linux-${LIBC} exit ;; crisv32:Linux:*:*) - echo ${UNAME_MACHINE}-axis-linux-gnu + echo ${UNAME_MACHINE}-axis-linux-${LIBC} exit ;; frv:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; hexagon:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; i*86:Linux:*:*) - LIBC=gnu - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #ifdef __dietlibc__ - LIBC=dietlibc - #endif -EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC'` - echo "${UNAME_MACHINE}-pc-linux-${LIBC}" + echo ${UNAME_MACHINE}-pc-linux-${LIBC} exit ;; ia64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; m32r*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; m68*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; mips:Linux:*:* | mips64:Linux:*:*) eval $set_cc_for_build @@ -955,54 +967,63 @@ EOF #endif EOF eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'` - test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } + test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; } ;; - or32:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu + openrisc*:Linux:*:*) + echo or1k-unknown-linux-${LIBC} + exit ;; + or32:Linux:*:* | or1k*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; padre:Linux:*:*) - echo sparc-unknown-linux-gnu + echo sparc-unknown-linux-${LIBC} exit ;; parisc64:Linux:*:* | hppa64:Linux:*:*) - echo hppa64-unknown-linux-gnu + echo hppa64-unknown-linux-${LIBC} exit ;; parisc:Linux:*:* | hppa:Linux:*:*) # Look for CPU level case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in - PA7*) echo hppa1.1-unknown-linux-gnu ;; - PA8*) echo hppa2.0-unknown-linux-gnu ;; - *) echo hppa-unknown-linux-gnu ;; + PA7*) echo hppa1.1-unknown-linux-${LIBC} ;; + PA8*) echo hppa2.0-unknown-linux-${LIBC} ;; + *) echo hppa-unknown-linux-${LIBC} ;; esac exit ;; ppc64:Linux:*:*) - echo powerpc64-unknown-linux-gnu + echo powerpc64-unknown-linux-${LIBC} exit ;; ppc:Linux:*:*) - echo powerpc-unknown-linux-gnu + echo powerpc-unknown-linux-${LIBC} + exit ;; + ppc64le:Linux:*:*) + echo powerpc64le-unknown-linux-${LIBC} + exit ;; + ppcle:Linux:*:*) + echo powerpcle-unknown-linux-${LIBC} exit ;; s390:Linux:*:* | s390x:Linux:*:*) - echo ${UNAME_MACHINE}-ibm-linux + echo ${UNAME_MACHINE}-ibm-linux-${LIBC} exit ;; sh64*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; sh*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; sparc:Linux:*:* | sparc64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; tile*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; vax:Linux:*:*) - echo ${UNAME_MACHINE}-dec-linux-gnu + echo ${UNAME_MACHINE}-dec-linux-${LIBC} exit ;; x86_64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; xtensa*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; i*86:DYNIX/ptx:4*:*) # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. @@ -1235,19 +1256,31 @@ EOF exit ;; *:Darwin:*:*) UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown - case $UNAME_PROCESSOR in - i386) - eval $set_cc_for_build - if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then - if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ - (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ - grep IS_64BIT_ARCH >/dev/null - then - UNAME_PROCESSOR="x86_64" - fi - fi ;; - unknown) UNAME_PROCESSOR=powerpc ;; - esac + eval $set_cc_for_build + if test "$UNAME_PROCESSOR" = unknown ; then + UNAME_PROCESSOR=powerpc + fi + if test `echo "$UNAME_RELEASE" | sed -e 's/\..*//'` -le 10 ; then + if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then + if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ + (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_64BIT_ARCH >/dev/null + then + case $UNAME_PROCESSOR in + i386) UNAME_PROCESSOR=x86_64 ;; + powerpc) UNAME_PROCESSOR=powerpc64 ;; + esac + fi + fi + elif test "$UNAME_PROCESSOR" = i386 ; then + # Avoid executing cc on OS X 10.9, as it ships with a stub + # that puts up a graphical alert prompting to install + # developer tools. Any system running Mac OS X 10.7 or + # later (Darwin 11 and later) is required to have a 64-bit + # processor. This is not true of the ARM version of Darwin + # that Apple uses in portable devices. + UNAME_PROCESSOR=x86_64 + fi echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} exit ;; *:procnto*:*:* | *:QNX:[0123456789]*:*) @@ -1338,154 +1371,6 @@ EOF exit ;; esac -eval $set_cc_for_build -cat >$dummy.c < -# include -#endif -main () -{ -#if defined (sony) -#if defined (MIPSEB) - /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, - I don't know.... */ - printf ("mips-sony-bsd\n"); exit (0); -#else -#include - printf ("m68k-sony-newsos%s\n", -#ifdef NEWSOS4 - "4" -#else - "" -#endif - ); exit (0); -#endif -#endif - -#if defined (__arm) && defined (__acorn) && defined (__unix) - printf ("arm-acorn-riscix\n"); exit (0); -#endif - -#if defined (hp300) && !defined (hpux) - printf ("m68k-hp-bsd\n"); exit (0); -#endif - -#if defined (NeXT) -#if !defined (__ARCHITECTURE__) -#define __ARCHITECTURE__ "m68k" -#endif - int version; - version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; - if (version < 4) - printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); - else - printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); - exit (0); -#endif - -#if defined (MULTIMAX) || defined (n16) -#if defined (UMAXV) - printf ("ns32k-encore-sysv\n"); exit (0); -#else -#if defined (CMU) - printf ("ns32k-encore-mach\n"); exit (0); -#else - printf ("ns32k-encore-bsd\n"); exit (0); -#endif -#endif -#endif - -#if defined (__386BSD__) - printf ("i386-pc-bsd\n"); exit (0); -#endif - -#if defined (sequent) -#if defined (i386) - printf ("i386-sequent-dynix\n"); exit (0); -#endif -#if defined (ns32000) - printf ("ns32k-sequent-dynix\n"); exit (0); -#endif -#endif - -#if defined (_SEQUENT_) - struct utsname un; - - uname(&un); - - if (strncmp(un.version, "V2", 2) == 0) { - printf ("i386-sequent-ptx2\n"); exit (0); - } - if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ - printf ("i386-sequent-ptx1\n"); exit (0); - } - printf ("i386-sequent-ptx\n"); exit (0); - -#endif - -#if defined (vax) -# if !defined (ultrix) -# include -# if defined (BSD) -# if BSD == 43 - printf ("vax-dec-bsd4.3\n"); exit (0); -# else -# if BSD == 199006 - printf ("vax-dec-bsd4.3reno\n"); exit (0); -# else - printf ("vax-dec-bsd\n"); exit (0); -# endif -# endif -# else - printf ("vax-dec-bsd\n"); exit (0); -# endif -# else - printf ("vax-dec-ultrix\n"); exit (0); -# endif -#endif - -#if defined (alliant) && defined (i860) - printf ("i860-alliant-bsd\n"); exit (0); -#endif - - exit (1); -} -EOF - -$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` && - { echo "$SYSTEM_NAME"; exit; } - -# Apollos put the system type in the environment. - -test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; } - -# Convex versions that predate uname can use getsysinfo(1) - -if [ -x /usr/convex/getsysinfo ] -then - case `getsysinfo -f cpu_type` in - c1*) - echo c1-convex-bsd - exit ;; - c2*) - if getsysinfo -f scalar_acc - then echo c32-convex-bsd - else echo c2-convex-bsd - fi - exit ;; - c34*) - echo c34-convex-bsd - exit ;; - c38*) - echo c38-convex-bsd - exit ;; - c4*) - echo c4-convex-bsd - exit ;; - esac -fi - cat >&2 <." version="\ GNU config.sub ($timestamp) -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, -2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, -2012, 2013 Free Software Foundation, Inc. +Copyright 1992-2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." @@ -256,12 +252,12 @@ case $basic_machine in | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ | am33_2.0 \ - | arc \ + | arc | arceb \ | arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \ | avr | avr32 \ | be32 | be64 \ | bfin \ - | c4x | clipper \ + | c4x | c8051 | clipper \ | d10v | d30v | dlx | dsp16xx \ | epiphany \ | fido | fr30 | frv \ @@ -269,6 +265,7 @@ case $basic_machine in | hexagon \ | i370 | i860 | i960 | ia64 \ | ip2k | iq2000 \ + | k1om \ | le32 | le64 \ | lm32 \ | m32c | m32r | m32rle | m68000 | m68k | m88k \ @@ -286,20 +283,22 @@ case $basic_machine in | mips64vr5900 | mips64vr5900el \ | mipsisa32 | mipsisa32el \ | mipsisa32r2 | mipsisa32r2el \ + | mipsisa32r6 | mipsisa32r6el \ | mipsisa64 | mipsisa64el \ | mipsisa64r2 | mipsisa64r2el \ + | mipsisa64r6 | mipsisa64r6el \ | mipsisa64sb1 | mipsisa64sb1el \ | mipsisa64sr71k | mipsisa64sr71kel \ + | mipsr5900 | mipsr5900el \ | mipstx39 | mipstx39el \ | mn10200 | mn10300 \ | moxie \ | mt \ | msp430 \ | nds32 | nds32le | nds32be \ - | nios | nios2 \ + | nios | nios2 | nios2eb | nios2el \ | ns16k | ns32k \ - | open8 \ - | or32 \ + | open8 | or1k | or1knd | or32 \ | pdp10 | pdp11 | pj | pjl \ | powerpc | powerpc64 | powerpc64le | powerpcle \ | pyramid \ @@ -327,7 +326,7 @@ case $basic_machine in c6x) basic_machine=tic6x-unknown ;; - m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | picochip) + m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | nvptx | picochip) basic_machine=$basic_machine-unknown os=-none ;; @@ -369,13 +368,13 @@ case $basic_machine in | aarch64-* | aarch64_be-* \ | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ - | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ + | alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \ | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ | avr-* | avr32-* \ | be32-* | be64-* \ | bfin-* | bs2000-* \ | c[123]* | c30-* | [cjt]90-* | c4x-* \ - | clipper-* | craynv-* | cydra-* \ + | c8051-* | clipper-* | craynv-* | cydra-* \ | d10v-* | d30v-* | dlx-* \ | elxsi-* \ | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ @@ -384,6 +383,7 @@ case $basic_machine in | hexagon-* \ | i*86-* | i860-* | i960-* | ia64-* \ | ip2k-* | iq2000-* \ + | k1om-* \ | le32-* | le64-* \ | lm32-* \ | m32c-* | m32r-* | m32rle-* \ @@ -403,18 +403,22 @@ case $basic_machine in | mips64vr5900-* | mips64vr5900el-* \ | mipsisa32-* | mipsisa32el-* \ | mipsisa32r2-* | mipsisa32r2el-* \ + | mipsisa32r6-* | mipsisa32r6el-* \ | mipsisa64-* | mipsisa64el-* \ | mipsisa64r2-* | mipsisa64r2el-* \ + | mipsisa64r6-* | mipsisa64r6el-* \ | mipsisa64sb1-* | mipsisa64sb1el-* \ | mipsisa64sr71k-* | mipsisa64sr71kel-* \ + | mipsr5900-* | mipsr5900el-* \ | mipstx39-* | mipstx39el-* \ | mmix-* \ | mt-* \ | msp430-* \ | nds32-* | nds32le-* | nds32be-* \ - | nios-* | nios2-* \ + | nios-* | nios2-* | nios2eb-* | nios2el-* \ | none-* | np1-* | ns16k-* | ns32k-* \ | open8-* \ + | or1k*-* \ | orion-* \ | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \ @@ -796,7 +800,7 @@ case $basic_machine in os=-mingw64 ;; mingw32) - basic_machine=i386-pc + basic_machine=i686-pc os=-mingw32 ;; mingw32ce) @@ -824,6 +828,10 @@ case $basic_machine in basic_machine=powerpc-unknown os=-morphos ;; + moxiebox) + basic_machine=moxie-unknown + os=-moxiebox + ;; msdos) basic_machine=i386-pc os=-msdos @@ -832,7 +840,7 @@ case $basic_machine in basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` ;; msys) - basic_machine=i386-pc + basic_machine=i686-pc os=-msys ;; mvs) @@ -1354,7 +1362,7 @@ case $os in -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\ | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \ - | -sym* | -kopensolaris* \ + | -sym* | -kopensolaris* | -plan9* \ | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ | -aos* | -aros* \ | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ @@ -1369,14 +1377,14 @@ case $os in | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \ | -linux-newlib* | -linux-musl* | -linux-uclibc* \ - | -uxpv* | -beos* | -mpeix* | -udk* \ + | -uxpv* | -beos* | -mpeix* | -udk* | -moxiebox* \ | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ - | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es*) + | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* | -tirtos*) # Remember, each alternative MUST END IN *, to match a version number. ;; -qnx*) @@ -1500,9 +1508,6 @@ case $os in -aros*) os=-aros ;; - -kaos*) - os=-kaos - ;; -zvmoe) os=-zvmoe ;; @@ -1551,6 +1556,9 @@ case $basic_machine in c4x-* | tic4x-*) os=-coff ;; + c8051-*) + os=-elf + ;; hexagon-*) os=-elf ;; diff --git a/configure b/configure index 9bfb4e8..b8a8b80 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for pygobject 3.14.0. +# Generated by GNU Autoconf 2.69 for pygobject 3.15.0. # # Report bugs to . # @@ -591,8 +591,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='pygobject' PACKAGE_TARNAME='pygobject' -PACKAGE_VERSION='3.14.0' -PACKAGE_STRING='pygobject 3.14.0' +PACKAGE_VERSION='3.15.0' +PACKAGE_STRING='pygobject 3.15.0' PACKAGE_BUGREPORT='http://bugzilla.gnome.org/enter_bug.cgi?product=pygobject' PACKAGE_URL='https://wiki.gnome.org/Projects/PyGObject/' @@ -1395,7 +1395,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures pygobject 3.14.0 to adapt to many kinds of systems. +\`configure' configures pygobject 3.15.0 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1465,7 +1465,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of pygobject 3.14.0:";; + short | recursive ) echo "Configuration of pygobject 3.15.0:";; esac cat <<\_ACEOF @@ -1603,7 +1603,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -pygobject configure 3.14.0 +pygobject configure 3.15.0 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -1881,7 +1881,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by pygobject $as_me 3.14.0, which was +It was created by pygobject $as_me 3.15.0, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -2240,9 +2240,9 @@ $as_echo "#define PYGOBJECT_MAJOR_VERSION 3" >>confdefs.h PYGOBJECT_MAJOR_VERSION=3 -$as_echo "#define PYGOBJECT_MINOR_VERSION 14" >>confdefs.h +$as_echo "#define PYGOBJECT_MINOR_VERSION 15" >>confdefs.h -PYGOBJECT_MINOR_VERSION=14 +PYGOBJECT_MINOR_VERSION=15 $as_echo "#define PYGOBJECT_MICRO_VERSION 0" >>confdefs.h @@ -2767,7 +2767,7 @@ fi # Define the identity of the package. PACKAGE='pygobject' - VERSION='3.14.0' + VERSION='3.15.0' cat >>confdefs.h <<_ACEOF @@ -14308,6 +14308,7 @@ fi -Werror=format-security \ -Werror=format=2 \ -Werror=missing-include-dirs \ + -Werror=return-type \ " additional_flags="" @@ -15376,7 +15377,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by pygobject $as_me 3.14.0, which was +This file was extended by pygobject $as_me 3.15.0, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -15443,7 +15444,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -pygobject config.status 3.14.0 +pygobject config.status 3.15.0 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index 6122e8e..97099d5 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ m4_define(python3_min_ver, 3.1) dnl the pygobject version number m4_define(pygobject_major_version, 3) -m4_define(pygobject_minor_version, 14) +m4_define(pygobject_minor_version, 15) m4_define(pygobject_micro_version, 0) m4_define(pygobject_version, pygobject_major_version.pygobject_minor_version.pygobject_micro_version) diff --git a/gi/gimodule.c b/gi/gimodule.c index a18c477..de9b787 100644 --- a/gi/gimodule.c +++ b/gi/gimodule.c @@ -469,44 +469,6 @@ _wrap_pyg_has_vfunc_implementation (PyObject *self, PyObject *args) } #endif -static PyObject * -_wrap_pyg_variant_new_tuple (PyObject *self, PyObject *args) -{ - PyObject *py_values; - GVariant **values = NULL; - GVariant *variant = NULL; - PyObject *py_variant = NULL; - PyObject *py_type; - gssize i; - - if (!PyArg_ParseTuple (args, "O!:variant_new_tuple", - &PyTuple_Type, &py_values)) { - return NULL; - } - - py_type = _pygi_type_import_by_name ("GLib", "Variant"); - - values = g_newa (GVariant*, PyTuple_Size (py_values)); - - for (i = 0; i < PyTuple_Size (py_values); i++) { - PyObject *value = PyTuple_GET_ITEM (py_values, i); - - if (!PyObject_IsInstance (value, py_type)) { - PyErr_Format (PyExc_TypeError, "argument %" G_GSSIZE_FORMAT " is not a GLib.Variant", i); - return NULL; - } - - values[i] = pyg_pointer_get (value, GVariant); - } - - variant = g_variant_new_tuple (values, PyTuple_Size (py_values)); - g_variant_ref_sink (variant); - - py_variant = _pygi_struct_new ( (PyTypeObject *) py_type, variant, FALSE); - - return py_variant; -} - static PyObject * _wrap_pyg_variant_type_from_string (PyObject *self, PyObject *args) { @@ -617,7 +579,6 @@ static PyMethodDef _gi_functions[] = { { "register_interface_info", (PyCFunction) _wrap_pyg_register_interface_info, METH_VARARGS }, { "hook_up_vfunc_implementation", (PyCFunction) _wrap_pyg_hook_up_vfunc_implementation, METH_VARARGS }, - { "variant_new_tuple", (PyCFunction) _wrap_pyg_variant_new_tuple, METH_VARARGS }, { "variant_type_from_string", (PyCFunction) _wrap_pyg_variant_type_from_string, METH_VARARGS }, { "source_new", (PyCFunction) _wrap_pyg_source_new, METH_NOARGS }, { "source_set_callback", (PyCFunction) pyg_source_set_callback, METH_VARARGS }, diff --git a/gi/importer.py b/gi/importer.py index cea0f8b..c097b74 100644 --- a/gi/importer.py +++ b/gi/importer.py @@ -2,6 +2,7 @@ # vim: tabstop=4 shiftwidth=4 expandtab # # Copyright (C) 2005-2009 Johan Dahlin +# 2015 Christoph Reiter # # importer.py: dynamic importer for introspected libraries. # @@ -22,15 +23,105 @@ from __future__ import absolute_import import sys +import warnings +from contextlib import contextmanager +import gi from ._gi import Repository -from .module import DynamicModule +from .module import get_introspection_module +from .overrides import load_overrides repository = Repository.get_default() + +# only for backwards compatibility modules = {} +def _get_all_dependencies(namespace): + """Like get_dependencies() but will recurse and get all dependencies. + The namespace has to be loaded before this can be called. + + :: + + _get_all_dependencies('Gtk') -> ['Atk-1.0', 'GObject-2.0', ...] + """ + + todo = repository.get_dependencies(namespace) + dependencies = [] + + while todo: + current = todo.pop() + if current in dependencies: + continue + ns, version = current.split("-", 1) + todo.extend(repository.get_dependencies(ns)) + dependencies.append(current) + + return dependencies + + +# See _check_require_version() +_active_imports = [] +_implicit_required = {} + + +@contextmanager +def _check_require_version(namespace, stacklevel): + """A context manager which tries to give helpful warnings + about missing gi.require_version() which could potentially + break code if only an older version than expected is installed + or a new version gets introduced. + + :: + + with _check_require_version("Gtk", stacklevel): + load_namespace_and_overrides() + """ + + global _active_imports, _implicit_required + + # This keeps track of the recursion level so we only check for + # explicitly imported namespaces and not the ones imported in overrides + _active_imports.append(namespace) + + try: + yield + except: + raise + else: + # Keep track of all dependency versions forced due to this import, so + # we don't warn for them in the future. This mirrors the import + # behavior where importing will get an older version if a previous + # import depended on it. + for dependency in _get_all_dependencies(namespace): + ns, version = dependency.split("-", 1) + _implicit_required[ns] = version + finally: + _active_imports.remove(namespace) + + # Warn in case: + # * this namespace was explicitly imported + # * the version wasn't forced using require_version() + # * the version wasn't forced implicitly by a previous import + # * this namespace isn't part of glib (we have bigger problems if + # versions change there) + is_explicit_import = not _active_imports + version_required = gi.get_required_version(namespace) is not None + version_implicit = namespace in _implicit_required + is_in_glib = namespace in ("GLib", "GObject", "Gio") + + if is_explicit_import and not version_required and \ + not version_implicit and not is_in_glib: + version = repository.get_version(namespace) + warnings.warn( + "%(namespace)s was imported without specifying a version first. " + "Use gi.require_version('%(namespace)s', '%(version)s') before " + "import to ensure that the right version gets loaded." + % {"namespace": namespace, "version": version}, + ImportWarning, stacklevel=stacklevel) + + class DynamicImporter(object): # Note: see PEP302 for the Importer Protocol implemented below. @@ -57,13 +148,18 @@ class DynamicImporter(object): return sys.modules[fullname] path, namespace = fullname.rsplit('.', 1) - dynamic_module = DynamicModule(namespace) - modules[namespace] = dynamic_module + + # we want the warning to point to the line doing the import + if sys.version_info >= (3, 0): + stacklevel = 10 + else: + stacklevel = 4 + with _check_require_version(namespace, stacklevel=stacklevel): + introspection_module = get_introspection_module(namespace) + dynamic_module = load_overrides(introspection_module) dynamic_module.__file__ = '<%s>' % fullname dynamic_module.__loader__ = self - sys.modules[fullname] = dynamic_module - dynamic_module._load() return dynamic_module diff --git a/gi/module.py b/gi/module.py index 8c25fd7..f27d516 100644 --- a/gi/module.py +++ b/gi/module.py @@ -23,7 +23,6 @@ from __future__ import absolute_import import sys -import types import importlib _have_py3 = (sys.version_info[0] >= 3) @@ -35,7 +34,6 @@ except AttributeError: from string import maketrans import gi -from .overrides import registry from ._gi import \ Repository, \ @@ -273,69 +271,3 @@ def get_introspection_module(namespace): module = IntrospectionModule(namespace, version) _introspection_modules[namespace] = module return module - - -class DynamicModule(types.ModuleType): - """A module composed of an IntrospectionModule and an overrides module. - - DynamicModule wraps up an IntrospectionModule and an overrides module - into a single accessible module. This is what is returned from statements - like "from gi.repository import Foo". Accessing attributes on a DynamicModule - will first look overrides (or the gi.overrides.registry cache) and then - in the introspection module if it was not found as an override. - """ - def __init__(self, namespace): - self._namespace = namespace - self._introspection_module = None - self._overrides_module = None - self.__path__ = None - - def _load(self): - self._introspection_module = get_introspection_module(self._namespace) - try: - self._overrides_module = importlib.import_module('gi.overrides.' + self._namespace) - except ImportError: - self._overrides_module = None - - self.__path__ = repository.get_typelib_path(self._namespace) - if _have_py3: - # get_typelib_path() delivers bytes, not a string - self.__path__ = self.__path__.decode('UTF-8') - - def __getattr__(self, name): - if self._overrides_module is not None: - override_exports = getattr(self._overrides_module, '__all__', ()) - if name in override_exports: - return getattr(self._overrides_module, name, None) - else: - # check the registry just in case the module hasn't loaded yet - # TODO: Only gtypes are registered in the registry right now - # but it would be nice to register all overrides and - # get rid of the module imports. We might actually see a - # speedup. - key = '%s.%s' % (self._namespace, name) - if key in registry: - return registry[key] - - return getattr(self._introspection_module, name) - - def __dir__(self): - # Python's default dir() is just dir(self.__class__) + self.__dict__.keys() - result = set(dir(self.__class__)) - result.update(self.__dict__.keys()) - - result.update(dir(self._introspection_module)) - override_exports = getattr(self._overrides_module, '__all__', ()) - result.update(override_exports) - return list(result) - - def __repr__(self): - path = repository.get_typelib_path(self._namespace) - if _have_py3: - # get_typelib_path() delivers bytes, not a string - path = path.decode('UTF-8') - - return "<%s.%s %r from %r>" % (self.__class__.__module__, - self.__class__.__name__, - self._namespace, - path) diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py index e72ed36..ce15da1 100644 --- a/gi/overrides/GLib.py +++ b/gi/overrides/GLib.py @@ -24,7 +24,7 @@ import warnings import sys from ..module import get_introspection_module -from .._gi import (variant_new_tuple, variant_type_from_string, source_new, +from .._gi import (variant_type_from_string, source_new, source_set_callback, io_channel_read) from ..overrides import override, deprecated from gi import PyGIDeprecationWarning, version_info @@ -243,6 +243,10 @@ class Variant(GLib.Variant): v.format_string = format_string return v + @staticmethod + def new_tuple(*elements): + return GLib.Variant.new_tuple(elements) + def __del__(self): self.unref() @@ -457,16 +461,10 @@ class Variant(GLib.Variant): return res -@classmethod -def new_tuple(cls, *elements): - return variant_new_tuple(elements) - - def get_string(self): value, length = GLib.Variant.get_string(self) return value -setattr(Variant, 'new_tuple', new_tuple) setattr(Variant, 'get_string', get_string) __all__.append('Variant') diff --git a/gi/overrides/Gdk.py b/gi/overrides/Gdk.py index 95030f8..c127550 100644 --- a/gi/overrides/Gdk.py +++ b/gi/overrides/Gdk.py @@ -190,6 +190,10 @@ class Event(Gdk.Event): Gdk.EventType.DROP_FINISHED: 'dnd', Gdk.EventType.CLIENT_EVENT: 'client', Gdk.EventType.VISIBILITY_NOTIFY: 'visibility', + Gdk.EventType.TOUCH_BEGIN: 'touch', + Gdk.EventType.TOUCH_UPDATE: 'touch', + Gdk.EventType.TOUCH_END: 'touch', + Gdk.EventType.TOUCH_CANCEL: 'touch', } if Gdk._version == '2.0': @@ -228,6 +232,7 @@ event_member_classes = ['EventAny', 'EventVisibility', 'EventMotion', 'EventButton', + 'EventTouch', 'EventScroll', 'EventKey', 'EventCrossing', diff --git a/gi/overrides/__init__.py b/gi/overrides/__init__.py index 35e14ea..b337b35 100644 --- a/gi/overrides/__init__.py +++ b/gi/overrides/__init__.py @@ -1,5 +1,7 @@ import types import warnings +import importlib +import sys from gi import PyGIDeprecationWarning from gi._gi import CallableInfo @@ -11,8 +13,6 @@ from gi._constants import \ from pkgutil import extend_path __path__ = extend_path(__path__, __name__) -registry = None - def wraps(wrapped): def assign(wrapper): @@ -22,40 +22,75 @@ def wraps(wrapped): return assign -class _Registry(dict): - def __setitem__(self, key, value): - """We do checks here to make sure only submodules of the override - module are added. Key and value should be the same object and come - from the gi.override module. +class OverridesProxyModule(types.ModuleType): + """Wraps a introspection module and contains all overrides""" - We add the override to the dict as "override_module.name". For instance - if we were overriding Gtk.Button you would retrive it as such: - registry['Gtk.Button'] - """ - if not key == value: - raise KeyError('You have tried to modify the registry. This should only be done by the override decorator') + def __init__(self, introspection_module): + super(OverridesProxyModule, self).__init__( + introspection_module.__name__) + self._introspection_module = introspection_module - try: - info = getattr(value, '__info__') - except AttributeError: - raise TypeError('Can not override a type %s, which is not in a gobject introspection typelib' % value.__name__) + def __getattr__(self, name): + return getattr(self._introspection_module, name) - if not value.__module__.startswith('gi.overrides'): - raise KeyError('You have tried to modify the registry outside of the overrides module. ' - 'This is not allowed (%s, %s)' % (value, value.__module__)) + def __dir__(self): + result = set(dir(self.__class__)) + result.update(self.__dict__.keys()) + result.update(dir(self._introspection_module)) + return sorted(result) + + def __repr__(self): + return "<%s %r>" % (type(self).__name__, self._introspection_module) - g_type = info.get_g_type() - assert g_type != TYPE_NONE - if g_type != TYPE_INVALID: - g_type.pytype = value - # strip gi.overrides from module name - module = value.__module__[13:] - key = "%s.%s" % (module, value.__name__) - super(_Registry, self).__setitem__(key, value) +def load_overrides(introspection_module): + """Loads overrides for an introspection module. - def register(self, override_class): - self[override_class] = override_class + Either returns the same module again in case there are no overrides or a + proxy module including overrides. Doesn't cache the result. + """ + + namespace = introspection_module.__name__.rsplit(".", 1)[-1] + module_key = 'gi.repository.' + namespace + + # We use sys.modules so overrides can import from gi.repository + # but restore everything at the end so this doesn't have any side effects + has_old = module_key in sys.modules + old_module = sys.modules.get(module_key) + + proxy = OverridesProxyModule(introspection_module) + sys.modules[module_key] = proxy + + # backwards compat: + # gedit uses gi.importer.modules['Gedit']._introspection_module + from ..importer import modules + assert hasattr(proxy, "_introspection_module") + modules[namespace] = proxy + + try: + try: + override_mod = importlib.import_module('gi.overrides.' + namespace) + except ImportError: + return introspection_module + finally: + del modules[namespace] + del sys.modules[module_key] + if has_old: + sys.modules[module_key] = old_module + + override_all = [] + if hasattr(override_mod, "__all__"): + override_all = override_mod.__all__ + + for var in override_all: + try: + item = getattr(override_mod, var) + except (AttributeError, TypeError): + # Gedit puts a non-string in __all__, so catch TypeError here + continue + setattr(proxy, var, item) + + return proxy class overridefunc(object): @@ -63,23 +98,47 @@ class overridefunc(object): def __init__(self, func): if not isinstance(func, CallableInfo): raise TypeError("func must be a gi function, got %s" % func) - from ..importer import modules + module_name = func.__module__.rsplit('.', 1)[-1] - self.module = modules[module_name]._introspection_module + self.module = sys.modules["gi.repository." + module_name] def __call__(self, func): setattr(self.module, func.__name__, func) return func -registry = _Registry() - def override(type_): - """Decorator for registering an override""" + """Decorator for registering an override. + + Other than objects added to __all__, these can get referenced in the same + override module via the gi.repository module (get_parent_for_object() does + for example), so they have to be added to the module immediately. + """ + if isinstance(type_, (types.FunctionType, CallableInfo)): return overridefunc(type_) else: - registry.register(type_) + try: + info = getattr(type_, '__info__') + except AttributeError: + raise TypeError( + 'Can not override a type %s, which is not in a gobject ' + 'introspection typelib' % type_.__name__) + + if not type_.__module__.startswith('gi.overrides'): + raise KeyError( + 'You have tried override outside of the overrides module. ' + 'This is not allowed (%s, %s)' % (type_, type_.__module__)) + + g_type = info.get_g_type() + assert g_type != TYPE_NONE + if g_type != TYPE_INVALID: + g_type.pytype = type_ + + namespace = type_.__module__.rsplit(".", 1)[-1] + module = sys.modules["gi.repository." + namespace] + setattr(module, type_.__name__, type_) + return type_ diff --git a/gi/pygi-array.c b/gi/pygi-array.c index e2598cd..121992b 100644 --- a/gi/pygi-array.c +++ b/gi/pygi-array.c @@ -191,6 +191,7 @@ _pygi_marshal_from_py_array (PyGIInvokeState *state, GArray *array_ = NULL; PyGISequenceCache *sequence_cache = (PyGISequenceCache *)arg_cache; PyGIArgGArray *array_cache = (PyGIArgGArray *)arg_cache; + GITransfer cleanup_transfer = arg_cache->transfer; if (py_arg == Py_None) { @@ -234,7 +235,21 @@ _pygi_marshal_from_py_array (PyGIInvokeState *state, if (sequence_cache->item_cache->type_tag == GI_TYPE_TAG_UINT8 && PYGLIB_PyBytes_Check (py_arg)) { - memcpy(array_->data, PYGLIB_PyBytes_AsString (py_arg), length); + gchar *data = PYGLIB_PyBytes_AsString (py_arg); + + /* Avoid making a copy if the data + * is not transferred to the C function + * and cannot not be modified by it. + */ + if (array_cache->array_type == GI_ARRAY_TYPE_C && + arg_cache->transfer == GI_TRANSFER_NOTHING && + !array_cache->is_zero_terminated) { + g_free (array_->data); + array_->data = data; + cleanup_transfer = GI_TRANSFER_EVERYTHING; + } else { + memcpy (array_->data, data, length); + } array_->len = length; if (array_cache->is_zero_terminated) { /* If array_ has been created with zero_termination, space for the @@ -385,7 +400,7 @@ array_success: */ arg->v_pointer = array_->data; - if (arg_cache->transfer == GI_TRANSFER_EVERYTHING) { + if (cleanup_transfer == GI_TRANSFER_EVERYTHING) { g_array_free (array_, FALSE); *cleanup_data = NULL; } else { @@ -394,10 +409,10 @@ array_success: } else { arg->v_pointer = array_; - if (arg_cache->transfer == GI_TRANSFER_NOTHING) { + if (cleanup_transfer == GI_TRANSFER_NOTHING) { /* Free everything in cleanup. */ *cleanup_data = array_; - } else if (arg_cache->transfer == GI_TRANSFER_CONTAINER) { + } else if (cleanup_transfer == GI_TRANSFER_CONTAINER) { /* Make a shallow copy so we can free the elements later in cleanup * because it is possible invoke will free the list before our cleanup. */ *cleanup_data = is_ptr_array ? diff --git a/gi/pygi-cache.h b/gi/pygi-cache.h index 093dde2..0361f00 100644 --- a/gi/pygi-cache.h +++ b/gi/pygi-cache.h @@ -197,7 +197,7 @@ struct _PyGICallableCache GICallableInfo *callable_info); }; -typedef struct _PyGIFunctionCache { +struct _PyGIFunctionCache { PyGICallableCache callable_cache; /* An invoker with ffi_cif already setup */ @@ -207,13 +207,13 @@ typedef struct _PyGIFunctionCache { PyGIInvokeState *state, PyObject *py_args, PyObject *py_kwargs); -} PyGIFunctionCache; +} ; -typedef struct _PyGIVFuncCache { +struct _PyGIVFuncCache { PyGIFunctionWithInstanceCache fwi_cache; GIBaseInfo *info; -} PyGIVFuncCache; +}; gboolean diff --git a/gi/pygi-info.c b/gi/pygi-info.c index 4df3359..8e0892a 100644 --- a/gi/pygi-info.c +++ b/gi/pygi-info.c @@ -2167,9 +2167,16 @@ _wrap_g_union_info_get_methods (PyGIBaseInfo *self) return _make_infos_tuple (self, g_union_info_get_n_methods, g_union_info_get_method); } +static PyObject * +_wrap_g_union_info_get_size (PyGIBaseInfo *self) +{ + return PYGLIB_PyLong_FromSize_t (g_union_info_get_size (self->info)); +} + static PyMethodDef _PyGIUnionInfo_methods[] = { { "get_fields", (PyCFunction) _wrap_g_union_info_get_fields, METH_NOARGS }, { "get_methods", (PyCFunction) _wrap_g_union_info_get_methods, METH_NOARGS }, + { "get_size", (PyCFunction) _wrap_g_union_info_get_size, METH_NOARGS }, { NULL, NULL, 0 } }; diff --git a/gi/pygi-repository.c b/gi/pygi-repository.c index 30890ba..a1f1ca6 100644 --- a/gi/pygi-repository.c +++ b/gi/pygi-repository.c @@ -267,6 +267,40 @@ _wrap_g_irepository_get_loaded_namespaces (PyGIRepository *self) return py_namespaces; } +static PyObject * +_wrap_g_irepository_get_dependencies (PyGIRepository *self, + PyObject *args, + PyObject *kwargs) +{ + static char *kwlist[] = { "namespace", NULL }; + const char *namespace_; + char **namespaces; + PyObject *py_namespaces; + gssize i; + + if (!PyArg_ParseTupleAndKeywords (args, kwargs, + "s:Repository.get_dependencies", kwlist, &namespace_)) { + return NULL; + } + + py_namespaces = PyList_New (0); + /* Returns NULL in case of no dependencies */ + namespaces = g_irepository_get_dependencies (self->repository, namespace_); + if (namespaces == NULL) { + return py_namespaces; + } + + for (i = 0; namespaces[i] != NULL; i++) { + PyObject *py_namespace = PYGLIB_PyUnicode_FromString (namespaces[i]); + PyList_Append (py_namespaces, py_namespace); + Py_DECREF(py_namespace); + } + + g_strfreev (namespaces); + + return py_namespaces; +} + static PyMethodDef _PyGIRepository_methods[] = { { "enumerate_versions", (PyCFunction) _wrap_g_irepository_enumerate_versions, METH_VARARGS | METH_KEYWORDS }, { "get_default", (PyCFunction) _wrap_g_irepository_get_default, METH_STATIC | METH_NOARGS }, @@ -276,6 +310,7 @@ static PyMethodDef _PyGIRepository_methods[] = { { "get_typelib_path", (PyCFunction) _wrap_g_irepository_get_typelib_path, METH_VARARGS | METH_KEYWORDS }, { "get_version", (PyCFunction) _wrap_g_irepository_get_version, METH_VARARGS | METH_KEYWORDS }, { "get_loaded_namespaces", (PyCFunction) _wrap_g_irepository_get_loaded_namespaces, METH_NOARGS }, + { "get_dependencies", (PyCFunction) _wrap_g_irepository_get_dependencies, METH_VARARGS | METH_KEYWORDS }, { NULL, NULL, 0 } }; diff --git a/gi/pygobject.h b/gi/pygobject.h index 85359a5..9e45dde 100644 --- a/gi/pygobject.h +++ b/gi/pygobject.h @@ -25,7 +25,7 @@ struct _PyGClosure { typedef enum { PYGOBJECT_USING_TOGGLE_REF = 1 << 0, PYGOBJECT_IS_FLOATING_REF = 1 << 1, - PYGOBJECT_GOBJECT_WAS_FLOATING = 1 << 2, + PYGOBJECT_GOBJECT_WAS_FLOATING = 1 << 2 } PyGObjectFlags; /* closures is just an alias for what is found in the diff --git a/gi/pygoptiongroup.c b/gi/pygoptiongroup.c index 4c1664d..3248b18 100644 --- a/gi/pygoptiongroup.c +++ b/gi/pygoptiongroup.c @@ -118,8 +118,11 @@ pyg_option_group_dealloc(PyGOptionGroup *self) { GOptionGroup *tmp = self->group; self->group = NULL; - if (tmp) + if (tmp) { + G_GNUC_BEGIN_IGNORE_DEPRECATIONS g_option_group_free(tmp); + G_GNUC_END_IGNORE_DEPRECATIONS + } } PyObject_Del(self); diff --git a/gi/types.py b/gi/types.py index e244f8c..8acbcc2 100644 --- a/gi/types.py +++ b/gi/types.py @@ -313,6 +313,10 @@ def mro(C): return bases +def nothing(*args, **kwargs): + pass + + class StructMeta(type, MetaClassHelper): """Meta class used for GI Struct based types.""" @@ -330,8 +334,12 @@ class StructMeta(type, MetaClassHelper): for method_info in cls.__info__.get_methods(): if method_info.is_constructor() and \ method_info.__name__ == 'new' and \ - not method_info.get_arguments(): + (not method_info.get_arguments() or + cls.__info__.get_size() == 0): cls.__new__ = staticmethod(method_info) + # Boxed will raise an exception + # if arguments are given to __init__ + cls.__init__ = nothing break @property diff --git a/tests/compat_test_pygtk.py b/tests/compat_test_pygtk.py index f0126c3..b2e7a11 100644 --- a/tests/compat_test_pygtk.py +++ b/tests/compat_test_pygtk.py @@ -3,14 +3,20 @@ import unittest import contextlib +import base64 +import gi from gi.repository import GLib try: + try: + gi.require_version("Gtk", "3.0") + except ValueError as e: + raise ImportError(e) + from gi.repository import Gtk from gi.repository import Pango from gi.repository import Atk from gi.repository import Gdk - from gi.repository import Gtk (Atk, Gtk, Pango) # pyflakes import pygtkcompat @@ -143,9 +149,17 @@ class TestGTKCompat(unittest.TestCase): gtk.gdk.Pixbuf() def test_pixbuf_loader(self): + # load a 1x1 pixel PNG from memory + data = base64.b64decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP4n8Dw' + 'HwAGIAJf85Z3XgAAAABJRU5ErkJggg==') loader = gtk.gdk.PixbufLoader('png') + loader.write(data) loader.close() + pixbuf = loader.get_pixbuf() + self.assertEqual(pixbuf.get_width(), 1) + self.assertEqual(pixbuf.get_height(), 1) + def test_pixbuf_formats(self): formats = gtk.gdk.pixbuf_get_formats() self.assertEqual(type(formats[0]), dict) diff --git a/tests/test_atoms.py b/tests/test_atoms.py index 18f8d09..dfd4e36 100644 --- a/tests/test_atoms.py +++ b/tests/test_atoms.py @@ -1,9 +1,11 @@ import unittest try: - from gi.repository import Atk, Gdk, Gtk + import gi + gi.require_version('Gtk', '3.0') + from gi.repository import Gtk, Atk, Gdk (Atk, Gdk) # pyflakes -except: +except (ValueError, ImportError): Gdk = None diff --git a/tests/test_everything.py b/tests/test_everything.py index 741de1a..88b6da1 100644 --- a/tests/test_everything.py +++ b/tests/test_everything.py @@ -1096,6 +1096,15 @@ class TestBoxed(unittest.TestCase): self.assertTrue(boxed42_2.equals(boxed42)) self.assertTrue(boxed42.equals(boxed42)) + def test_boxed_b_constructor(self): + with warnings.catch_warnings(record=True) as warn: + warnings.simplefilter('always') + boxed = Everything.TestBoxedB(42, 47) + self.assertTrue(issubclass(warn[0].category, TypeError)) + + self.assertEqual(boxed.some_int8, 0) + self.assertEqual(boxed.some_long, 0) + def test_boxed_c_equality(self): boxed = Everything.TestBoxedC() # TestBoxedC uses refcounting, so we know that diff --git a/tests/test_gi.py b/tests/test_gi.py index 20c7343..9633f57 100644 --- a/tests/test_gi.py +++ b/tests/test_gi.py @@ -1089,7 +1089,18 @@ class TestGByteArray(unittest.TestCase): self.assertEqual(b'\x001\xFF3', GIMarshallingTests.bytearray_full_return()) def test_bytearray_none_in(self): - GIMarshallingTests.bytearray_none_in(b'\x00\x31\xFF\x33') + b = b'\x00\x31\xFF\x33' + ba = GLib.ByteArray.new_take(b) + + # b should always have the same value even + # though the generated GByteArray is being modified + GIMarshallingTests.bytearray_none_in(b) + GIMarshallingTests.bytearray_none_in(b) + + # The GByteArray is just a bytes + # thus it will not reflect any changes + GIMarshallingTests.bytearray_none_in(ba) + GIMarshallingTests.bytearray_none_in(ba) class TestGList(unittest.TestCase): @@ -2203,10 +2214,6 @@ class TestPythonGObject(unittest.TestCase): object_ = self.SubObject(int=1) self.assertEqual(object_.vfunc_return_value_only(), 2121) - def test_dynamic_module(self): - from gi.module import DynamicModule - self.assertTrue(isinstance(GObject, DynamicModule)) - def test_subobject_non_vfunc_do_method(self): class PythonObjectWithNonVFuncDoMethod(object): def do_not_a_vfunc(self): diff --git a/tests/test_glib.py b/tests/test_glib.py index f9e4853..17ac2de 100644 --- a/tests/test_glib.py +++ b/tests/test_glib.py @@ -226,9 +226,9 @@ https://my.org/q?x=1&y=2 self.assertGreaterEqual(minor, 0) self.assertGreaterEqual(micro, 0) - def test_timezone_constructor_error(self): - self.assertRaisesRegexp(TypeError, '.*constructor.*help\(GLib.TimeZone\).*', - GLib.TimeZone) + def test_timezone_constructor(self): + 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_import_machinery.py b/tests/test_import_machinery.py index f68f522..a1adab1 100644 --- a/tests/test_import_machinery.py +++ b/tests/test_import_machinery.py @@ -6,6 +6,7 @@ import unittest import gi.overrides import gi.module +import gi.importer try: from gi.repository import Regress @@ -14,7 +15,8 @@ except ImportError: Regress = None -class TestRegistry(unittest.TestCase): +class TestOverrides(unittest.TestCase): + def test_non_gi(self): class MyClass: pass @@ -31,6 +33,29 @@ class TestRegistry(unittest.TestCase): # https://bugzilla.gnome.org/show_bug.cgi?id=680913 self.assertEqual(Regress.REGRESS_OVERRIDE, 42) + def test_load_overrides(self): + mod = gi.module.get_introspection_module('GIMarshallingTests') + mod_override = gi.overrides.load_overrides(mod) + self.assertTrue(mod_override is not mod) + self.assertTrue(mod_override._introspection_module is mod) + self.assertEqual(mod_override.OVERRIDES_CONSTANT, 7) + self.assertEqual(mod.OVERRIDES_CONSTANT, 42) + + def test_load_no_overrides(self): + mod_key = "gi.overrides.GIMarshallingTests" + had_mod = mod_key in sys.modules + old_mod = sys.modules.get(mod_key) + try: + # this makes override import fail + sys.modules[mod_key] = None + mod = gi.module.get_introspection_module('GIMarshallingTests') + mod_override = gi.overrides.load_overrides(mod) + self.assertTrue(mod_override is mod) + finally: + del sys.modules[mod_key] + if had_mod: + sys.modules[mod_key] = old_mod + class TestModule(unittest.TestCase): # Tests for gi.module @@ -49,12 +74,6 @@ class TestModule(unittest.TestCase): mod2 = gi.module.get_introspection_module(mod_name) self.assertTrue(mod1 is mod2) - # Using a DynamicModule will use get_introspection_module internally - # in its _load method. - mod_overridden = gi.module.DynamicModule(mod_name) - mod_overridden._load() - self.assertTrue(mod1 is mod_overridden._introspection_module) - # Restore the previous cache gi.module._introspection_modules = old_modules @@ -98,3 +117,26 @@ class TestImporter(unittest.TestCase): self.assertTrue('introspection typelib' not in exception_string) else: self.assertTrue('introspection typelib' in exception_string) + + def test__get_all_dependencies(self): + get_all_dependencies = gi.importer._get_all_dependencies + deps = set(get_all_dependencies("Regress")) + + self.assertTrue('Gio-2.0' in deps) + self.assertTrue('GObject-2.0' in deps) + self.assertTrue('GLib-2.0' in deps) + self.assertTrue('cairo-1.0' in deps) + + def test_require_version_warning(self): + check = gi.importer._check_require_version + + # make sure it doesn't fail at least + with check("GLib", 1): + from gi.repository import GLib + GLib + + # make sure the exception propagates + with self.assertRaises(ImportError): + with check("InvalidGObjectRepositoryModuleName", 1): + from gi.repository import InvalidGObjectRepositoryModuleName + InvalidGObjectRepositoryModuleName diff --git a/tests/test_overrides_gdk.py b/tests/test_overrides_gdk.py index 60d5ae4..da96855 100644 --- a/tests/test_overrides_gdk.py +++ b/tests/test_overrides_gdk.py @@ -70,6 +70,18 @@ class TestGdk(unittest.TestCase): event.type = Gdk.EventType.SCROLL self.assertRaises(AttributeError, lambda: getattr(event, 'foo_bar')) + def test_event_touch(self): + event = Gdk.Event.new(Gdk.EventType.TOUCH_BEGIN) + self.assertEqual(event.type, Gdk.EventType.TOUCH_BEGIN) + + # emulating_pointer is unique to touch events + self.assertFalse(event.emulating_pointer) + self.assertFalse(event.touch.emulating_pointer) + + event.emulating_pointer = True + self.assertTrue(event.emulating_pointer) + self.assertTrue(event.touch.emulating_pointer) + def test_event_setattr(self): event = Gdk.Event.new(Gdk.EventType.DRAG_MOTION) event.x_root, event.y_root = 0, 5 diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py index d3351d4..a57b7da 100644 --- a/tests/test_overrides_gtk.py +++ b/tests/test_overrides_gtk.py @@ -10,15 +10,18 @@ import warnings from compathelper import _unicode, _bytes +import gi import gi.overrides import gi.types from gi.repository import GLib, GObject try: - from gi.repository import GdkPixbuf, Gdk, Gtk + gi.require_version('Gtk', '3.0') + gi.require_version('GdkPixbuf', '2.0') + from gi.repository import Gtk, GdkPixbuf, Gdk Gtk # pyflakes PyGTKDeprecationWarning = Gtk.PyGTKDeprecationWarning -except ImportError: +except (ValueError, ImportError): Gtk = None PyGTKDeprecationWarning = None diff --git a/tests/test_overrides_pango.py b/tests/test_overrides_pango.py index 1e8fe2d..5177213 100644 --- a/tests/test_overrides_pango.py +++ b/tests/test_overrides_pango.py @@ -4,11 +4,14 @@ import unittest try: + import gi + gi.require_version('Pango', '1.0') + gi.require_version('PangoCairo', '1.0') from gi.repository import Pango from gi.repository import PangoCairo Pango PangoCairo -except ImportError: +except (ValueError, ImportError): Pango = None PangoCairo = None diff --git a/tests/test_properties.py b/tests/test_properties.py index 999bff1..a147aae 100644 --- a/tests/test_properties.py +++ b/tests/test_properties.py @@ -6,6 +6,7 @@ import struct import types import unittest +import gi from gi.repository import GObject from gi.repository.GObject import GType, new, PARAM_READWRITE, \ PARAM_CONSTRUCT, PARAM_READABLE, PARAM_WRITABLE, PARAM_CONSTRUCT_ONLY @@ -22,13 +23,15 @@ from gi.repository.GObject import \ from gi.repository import Gio from gi.repository import GLib +gi.require_version('GIMarshallingTests', '1.0') from gi.repository import GIMarshallingTests from gi import _propertyhelper as propertyhelper try: + gi.require_version('Regress', '1.0') from gi.repository import Regress has_regress = True -except ImportError: +except (ValueError, ImportError): has_regress = False if sys.version_info < (3, 0): diff --git a/tests/test_repository.py b/tests/test_repository.py index b73fbf9..43c7d9e 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -23,6 +23,10 @@ import unittest import collections +import gi + +gi.require_version('GIRepository', '2.0') + import gi._gi as GIRepository from gi.module import repository as repo from gi.repository import GObject @@ -49,9 +53,15 @@ def find_child_info(info, getter_name, name): class Test(unittest.TestCase): def setUp(self): + repo.require('GLib') repo.require('GObject') repo.require('GIMarshallingTests') + def test_repo_get_dependencies(self): + self.assertRaises(TypeError, repo.get_dependencies) + self.assertEqual(repo.get_dependencies("GLib"), []) + self.assertEqual(repo.get_dependencies("GObject"), ["GLib-2.0"]) + def test_arg_info(self): func_info = repo.find_by_name('GIMarshallingTests', 'array_fixed_out_struct') args = func_info.get_arguments() -- 2.34.1