How to check for python GObject Introspection modules in Autotools

When we are using compiled languages – we are usually depending on pkg-config files. For example, “PKG_CHECK_MODULES(GLIB, glib2)”, but what if we are using Python?

Autoconf Archive has AX_PYTHON_MODULE macros. We can use it very easy.

How about Python + GObject Introspection? Let’s take GTK+ as an example. I wrote special m4 file (see below), you can place it in “m4” directory. Then you just need add “AX_PYTHON_GI(Gtk, 3.0)” into “configure.ac” and autoconf will check if GI works and Gtk-3.0.typelib is usable.

P.S. note that I’m not m4 expert, but it works for me.

# SYNOPSIS
#
#   AX_PYTHON_GI(gi_module, version[, python])
#
# DESCRIPTION
#
#   Checks for Python GObject Introspection and GI module with the given
#   version.
#
# LICENSE
#
#    Copyright (C) 2015 Igor Gnatenko <ignatenko@src.gnome.org>
#
#    Copying and distribution of this file, with or without modification, are
#    permitted in any medium without royalty provided the copyright notice
#    and this notice are preserved. This file is offered as-is, without any
#    warranty.

AC_DEFUN([AX_PYTHON_GI], [
    AC_MSG_CHECKING([for bindings for GObject Introspection])
    AX_PYTHON_MODULE([gi], [required], [$3])
    AC_MSG_CHECKING([for version $2 of $1 GObject Introspection module])
    $PYTHON -c "import gi; gi.require_version('$1', '$2')" 2> /dev/null
    AS_IF([test $? -eq 0], [], [
        AC_MSG_RESULT([no])
        AC_MSG_ERROR([You need version $2 of the $1 GObject Introspection module.])
    ])
    AC_MSG_RESULT([yes])
])

Python q

q is python module for Quick-and-dirty debugging output for tired programmers. Did you know about it? Toshio Kuratomi said about q yesterday and I use it now everywhere when I’m trying to debug things.

It allow you to easy print variables, function arguments, function returns to temp file when you executing code. Let’s see example:

#!/usr/bin/env python3
import q

@q
def q_test(var1=None, var2=None):
    print(q|var1 + var2)

def main():
    s = {'test': list(range(6))}
    q_test('arg', 'next')
    q.q(s)

if __name__ == '__main__':
    main()

After execution /tmp/q looks like:
Python q output

GNOME Code Assistance supports pylint syntax checker

GNOME Code Assistance (GCA) is a project which aims to provide common code assistance services for code editors (simple editors as well as IDEs). It is an effort to provide a centralized code-assistance as a service for the GNOME platform instead of having every editor implement their own solution.

Yesterday I got some feedback from Vadim Rutkovsky that GNOME Builder or Gedit is unusable for python because missing syntax checker (Coding Standard, Error Detection and etc.). He is using pyflakes, but in DNF project we’re using pylint and I like it more.

I wrote patch which implementing this functionality. Today discussed with Jesse van den Kieboom, fixed some things and patch was merged.

To use pylint with GCA you need to pass {“pylint”: True} as “options” parameter for DBus. You can replace “True” with any string if you want, just don’t use False ;)

Feel free to report bugs and send patches in BGO!

GNOME Builder snippets improvement

Did you know that GNOME Builder support snippets? I didn’t.

I made 4 snippets for RPM Spec files to get spec skeleton: minimal, library, python-arch, python-noarch. You can start typing one of this, press ENTER and see how this magic works. It’s very useful when you packaging something to avoid calling rpmdev-newspec with parameters, opening editor, manual walking by lines and etc.

Also I added some basic snippets for Python files: class/function definition, interpreter line, main function and import. This helps me to more faster write code.

P.S. there some cool C snippets like gobject and main

P.P.S. for switch to next field you want to press Tab

GNOME Builder and python: happy indents

Christian Hergert, author of GNOME Builder, in yesterday morning got some messages from me about auto-indent problems in Python.

According to PEP 8 we can use:

# Aligned with opening delimiter.
foo = long_function_name(var_one, var_two,
                         var_three, var_four)

# More indentation included to distinguish this from the rest.
def long_function_name(
        var_one, var_two, var_three,
        var_four):
    print(var_one)

# Hanging indents should add a level.
foo = long_function_name(
    var_one, var_two,
    var_three, var_four)

Christian added support for auto-indenting for all this cases. I can just write code and don’t care about indentation. You want to try GNOME Builder!

P.S. There are cool Shift-Tab keybinding to remove one tab (4 spaces or whatever)

css.php