pygobject / pgi

[Unmaintained: Use PyGObject instead] GTK+ / GObject Introspection Bindings for PyPy.
GNU Lesser General Public License v2.1
74 stars 16 forks source link

NotImplementedError: ('type: %r', 'INTERFACE') #13

Open stuaxo opened 9 years ago

stuaxo commented 9 years ago

Looks like there are some differences here:

gi.repository

>>> from gi.repository import Pango
>>> Pango.FontDescription("Helvetica-Bold")

pgi

>>> import pgi
>>> pgi.install_as_gi()
>>> from gi.repository import Pango
>>> Pango.FontDescription("Helvetica-Bold")
>>> ----> 1 Pango.FontDescription("Helvetica-Bold")

TypeError: __init__() takes exactly 1 argument (2 given)
stuaxo commented 9 years ago

I was able to get a bit further by using Pango.FontDescription.from_string(..) instead of the constructor the next unimplemented thing seems to the interface type:

NotImplementedError: ('type: %r', 'INTERFACE')
lazka commented 9 years ago

Thanks.

Pango.FontDescription doesn't take any args. The difference is that gi ignores them while pgi errors out. But pgi should still match it.

lazka commented 9 years ago

Pango.FontDescription.from_string works here. What did you do to get the error?

stuaxo commented 9 years ago

from_string worked fine, I used it instead of passing the font info to the constructor, like in this example: http://zetcode.com/gfx/pycairo/root/

I'll get some minimal code together to reproduce the other error.

stuaxo commented 9 years ago

The INTERFACE bug can be triggered using PangoCairo create_layout

Im not near my computer now, but there is an example here that should trigger it:

https://sites.google.com/site/randomcodecollections/home/python-gtk-3-pango-cairo-example

stuaxo commented 9 years ago

Minimum code to trigger PangoCairo layout caboom:

import cairo
from gi.repository import PangoCairo

surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 100, 100)

cr = cairo.Context(surface)
PangoCairo.create_layout(cr)
NotImplementedError                       Traceback (most recent call last)
<ipython-input-3-f25111c28371> in <module>()
      8 
      9 cr = cairo.Context(surface)
---> 10 PangoCairo.create_layout(cr)

/mnt/data/home/stu/.virtualenvs/shoebot-pgi/lib/python2.7/site-packages/pgi/module.pyc in __getattr__(self, name)
     82         cls = _attr_list[info.type.value]
     83         if cls:
---> 84             attr = cls(info)
     85             setattr(self, name, attr)
     86         else:

/mnt/data/home/stu/.virtualenvs/shoebot-pgi/lib/python2.7/site-packages/pgi/function.pyc in FunctionAttribute(info)
     10 
     11 def FunctionAttribute(info):
---> 12     return generate_function(info)

/mnt/data/home/stu/.virtualenvs/shoebot-pgi/lib/python2.7/site-packages/pgi/codegen/funcgen.pyc in generate_function(info, method)
    332         return func
    333 
--> 334     raise NotImplementedError("\n".join(messages))
    335 
    336 

NotImplementedError: cffi: Traceback (most recent call last):
  File "/mnt/data/home/stu/.virtualenvs/shoebot-pgi/lib/python2.7/site-packages/pgi/codegen/funcgen.py", line 325, in generate_function
    return_type, method)
  File "/mnt/data/home/stu/.virtualenvs/shoebot-pgi/lib/python2.7/site-packages/pgi/codegen/funcgen.py", line 207, in _generate_function
    block = arg.pre_call()
  File "/mnt/data/home/stu/.virtualenvs/shoebot-pgi/lib/python2.7/site-packages/pgi/codegen/arguments.py", line 357, in pre_call
    var = self.get_type()
  File "/mnt/data/home/stu/.virtualenvs/shoebot-pgi/lib/python2.7/site-packages/pgi/codegen/arguments.py", line 109, in get_type
    self.type, desc=self.desc, may_be_null=self.may_be_null)
  File "/mnt/data/home/stu/.virtualenvs/shoebot-pgi/lib/python2.7/site-packages/pgi/codegen/cffi_backend.py", line 404, in get_type
    return get_type(type_, self._gen, desc, may_be_null, may_return_null)
  File "/mnt/data/home/stu/.virtualenvs/shoebot-pgi/lib/python2.7/site-packages/pgi/codegen/cffi_backend.py", line 95, in get_type
    raise NotImplementedError(e)
NotImplementedError: ('type: %r', 'INTERFACE')

ctypes: Traceback (most recent call last):
  File "/mnt/data/home/stu/.virtualenvs/shoebot-pgi/lib/python2.7/site-packages/pgi/codegen/funcgen.py", line 325, in generate_function
    return_type, method)
  File "/mnt/data/home/stu/.virtualenvs/shoebot-pgi/lib/python2.7/site-packages/pgi/codegen/funcgen.py", line 220, in _generate_function
    throws)
  File "/mnt/data/home/stu/.virtualenvs/shoebot-pgi/lib/python2.7/site-packages/pgi/codegen/ctypes_backend/main.py", line 107, in get_function
    "Library doesn't provide symbol: %s" % symbol)
NotImplementedError: Library doesn't provide symbol: pango_cairo_create_layout
stuaxo commented 9 years ago

Here's a little test program to check coverage of gi.* APIs, would it be useful to include something like this into PGI itself ?

I guess I could extend it to check all available gi.repository libraries on the system

# find pgi coverage of a gi.repository module
# you need to have access to both 'gi' and 'pgi' in the current python
# environment.
#
# In a virtualenv this works:

# $ pip install pgi
# $ pip install vext.gi

def test_pgi_coverage(gi_module, pgi_module):
    name_width = len(max(dir(gi_module), key=len))
    print('PGI coverage')
    print('%s %s' % (gi_module.__name__.rjust(name_width), pgi_module.__name__))
    for name in dir(gi_module):
        if name.startswith('_'):
            continue
        status = 'OK'
        try:
            getattr(pgi_module, name)
        except NotImplementedError as e:
            #status = "FAIL: '%s'" % str(e.__class__.__name__)
            status = "FAIL"
            for line in str(e).splitlines():
                if line.startswith('NotImplementedError:'):
                    status =  status + "    " + line
        print("%s\t%s" % (name.rjust(name_width), status))

if __name__=='__main__':
    from pgi.repository import PangoCairo as PGI_PangoCairo
    from gi.repository import PangoCairo as GI_PangoCairo

    test_pgi_coverage(GI_PangoCairo, PGI_PangoCairo)

Output

PGI coverage
  gi.repository.PangoCairo PangoCairo
                 FcFontMap  OK
                      Font  OK
                   FontMap  OK
  context_get_font_options  FAIL    NotImplementedError: ('type: %r', 'INTERFACE')    NotImplementedError: Library doesn't provide symbol: pango_cairo_context_get_font_options
    context_get_resolution  FAIL    NotImplementedError: ('type: %r', 'INTERFACE')    NotImplementedError: Library doesn't provide symbol: pango_cairo_context_get_resolution
  context_set_font_options  FAIL    NotImplementedError: ('type: %r', 'INTERFACE')    NotImplementedError: Library doesn't provide symbol: pango_cairo_context_set_font_options
    context_set_resolution  FAIL    NotImplementedError: ('type: %r', 'INTERFACE')    NotImplementedError: Library doesn't provide symbol: pango_cairo_context_set_resolution
context_set_shape_renderer  FAIL    NotImplementedError: ('type: %r', 'INTERFACE')    NotImplementedError: Library doesn't provide symbol: pango_cairo_context_set_shape_renderer
            create_context  FAIL    NotImplementedError: ('type: %r', 'INTERFACE')    NotImplementedError: Library doesn't provide symbol: pango_cairo_create_context
             create_layout  FAIL    NotImplementedError: ('type: %r', 'INTERFACE')    NotImplementedError: Library doesn't provide symbol: pango_cairo_create_layout
      error_underline_path  FAIL    NotImplementedError: ('type: %r', 'INTERFACE')    NotImplementedError: Library doesn't provide symbol: pango_cairo_error_underline_path
      font_map_get_default  FAIL    NotImplementedError: Library doesn't provide symbol: pango_cairo_font_map_get_default    NotImplementedError: Library doesn't provide symbol: pango_cairo_font_map_get_default
              font_map_new  FAIL    NotImplementedError: Library doesn't provide symbol: pango_cairo_font_map_new    NotImplementedError: Library doesn't provide symbol: pango_cairo_font_map_new
font_map_new_for_font_type  FAIL    NotImplementedError: ('type: %r', 'INTERFACE')    NotImplementedError: Library doesn't provide symbol: pango_cairo_font_map_new_for_font_type
         glyph_string_path  FAIL    NotImplementedError: ('type: %r', 'INTERFACE')    NotImplementedError: Library doesn't provide symbol: pango_cairo_glyph_string_path
          layout_line_path  FAIL    NotImplementedError: ('type: %r', 'INTERFACE')    NotImplementedError: Library doesn't provide symbol: pango_cairo_layout_line_path
               layout_path  FAIL    NotImplementedError: ('type: %r', 'INTERFACE')    NotImplementedError: Library doesn't provide symbol: pango_cairo_layout_path
      show_error_underline  FAIL    NotImplementedError: ('type: %r', 'INTERFACE')    NotImplementedError: Library doesn't provide symbol: pango_cairo_show_error_underline
           show_glyph_item  FAIL    NotImplementedError: ('type: %r', 'INTERFACE')    NotImplementedError: Library doesn't provide symbol: pango_cairo_show_glyph_item
         show_glyph_string  FAIL    NotImplementedError: ('type: %r', 'INTERFACE')    NotImplementedError: Library doesn't provide symbol: pango_cairo_show_glyph_string
               show_layout  FAIL    NotImplementedError: ('type: %r', 'INTERFACE')    NotImplementedError: Library doesn't provide symbol: pango_cairo_show_layout
          show_layout_line  FAIL    NotImplementedError: ('type: %r', 'INTERFACE')    NotImplementedError: Library doesn't provide symbol: pango_cairo_show_layout_line
            update_context  FAIL    NotImplementedError: ('type: %r', 'INTERFACE')    NotImplementedError: Library doesn't provide symbol: pango_cairo_update_context
             update_layout  FAIL    NotImplementedError: ('type: %r', 'INTERFACE')    NotImplementedError: Library doesn't provide symbol: pango_cairo_update_layout
stuaxo commented 8 years ago

I changed the name of the bug, as this seems to be anything that uses INTERFACE.

stuaxo commented 8 years ago

https://github.com/lazka/pgi/pull/25 I've extended the above script to loop through all typelibs it can find.

It has skips at least one module it has trouble importing (ideally I guess it should create a new python instance to try each new import).