Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8182689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:56:04+00:00 2026-06-07T00:56:04+00:00

First, some context: I’m a Python developer who has written a medium-sized application using

  • 0

First, some context: I’m a Python developer who has written a medium-sized application using PyGObject, taking advantage of GObject Introspection to access things like GSettings, etc. Some of my Python objects actually subclass GObject.GObject, so I’m using GObject quite extensively.

Recently, a certain library has come to my attention that wraps a C library in GObject (gexiv2, used by Shotwell/Vala), however it doesn’t currently support introspection. I’m interested in adding introspection support to gexiv2 so that I can access it from Python, but I don’t even know where to begin on this topic.

When I research introspection and VAPI, I see lots of documentation referencing the fact that the VAPI can be automatically generated from the introspection annotations… but what about a project that already has a VAPI, but no introspection? Is it possible to automatically generate the introspection annotations given the VAPI?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:56:06+00:00Added an answer on June 7, 2026 at 12:56 am

    Well, after getting sick of the tediousness of hand-copying VAPI definitions into introspection annotations, I wrote this (crude) script to do it for me:

    #!/bin/env python
    
    import sys
    
    from collections import defaultdict
    
    ANNOTATION = """/**
     * %s:
    %s *
     * Returns:%s
     */
    """
    
    PARAMETER = """ * @%s:%s
    """
    
    methods = defaultdict(set)
    
    attrs = defaultdict(dict)
    
    with open(sys.argv[1]) as vapi:
        for line in vapi:
            tokens = line.split()
            try:
                names = tuple(tokens[0].split('.'))
            except IndexError:
                continue
    
            attrs[names] = {}
            for attribute in tokens[1:]:
                key, val = attribute.split('=')
                if val == '"1"': val = True
                if val == '"0"': val = False
                attrs[names][key] = val
    
            methods[names[0]]
            if len(names) > 1:
                methods[names[0]].add(names[-1])
    
    for method in methods:
        params = ''
        for param in methods[method]:
            param_attributes = ''
            param_attrs = attrs[(method, param)]
            if param_attrs.get('hidden'):
                param_attributes += ' (skip)'
            if param_attrs.get('is_out'):
                param_attributes += ' (out)'
            if param_attrs.get('transfer_ownership'):
                param_attributes += ' (transfer full)'
            elif 'transfer_ownership' in param_attrs:
                param_attributes += ' (transfer none)'
            if param_attrs.get('array_null_terminated'):
                param_attributes += ' (array zero-terminated=1)'
            if param_attrs.get('array_length_pos'):
                param_attributes += ' (array length=FIXME)'
            if param_attributes:
                param_attributes += ':'
            params += PARAMETER % (param, param_attributes)
    
        attributes = ''
        method_attrs = attrs[(method,)]
        if method_attrs.get('transfer_ownership'):
            attributes += ' (transfer full)'
        elif 'transfer_ownership' in method_attrs:
            attributes += ' (transfer none)'
        if method_attrs.get('nullable'):
            attributes += ' (allow-none)'
        if method_attrs.get('array_null_terminated'):
            attributes += ' (array zero-terminated=1)'
        if attributes:
            attributes += ':'
    
        print ANNOTATION % (method, params, attributes)
    

    This obviously has some disadvantages: It doesn’t insert the annotations into the code, it simply prints them, so you have to do quite a bit of copy & pasting to get everything into the right place. It also doesn’t handle arrays very well, but it at least lets you know when there’s an array you need to fix manually. All in all, it was significantly less work to run this script and then massage the results than it was to parse by hand. I’m posting it here in the hopes that it gets picked up by google and somebody else may benefit one day (although I dearly hope that all GObject-based projects from here on out simply start with annotations and then use vapigen).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First, some background: I'm developing a web application using Python. All of my (text)
First some brief background: I have an existing ASP.NET MVC 1 application using Entity
First some background: I'm working on an application and I'm trying to follow MVVM
First some background, I am currently working on a relatively large Asp.Net MVC application
First, some context: I'm currently working on a project in which I use the
First some context: I have an MVC3 .net project which, for the sake of
First some background..I am using the Telerik MVC Grid to display data. The grid
First here's some context on what I want to achieve. I'm writing a small
First of all some context : I have a form, where I post back
I have a TextBox which has some default context menu and it works fine.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.