Having fun with exporting automake variables - or how it was obviously a pyflakes bug (no, it wasn't) ...

Each line of a Makefile target is executed in a sub-shell, this has pros and cons, but at least the following side-effect can be observed:

fun:
    export FOO="wunder bar"
    echo $$FOO

This doesn’t echo “wunder bar” to the cmdline when you run make because the export happens in a different shell then the echo.

You can anyhow set environment variables using the export keyword:

export FOO="wunder bar"
fun:
    echo $FOO

This now echos “wunder bar” to the cmdline when you run make.

So what is problematic with this? The quotes. The environment variable FOO will contain the string “wunder bar” - including the quotes! This happens because export is now theautomake keyword, and that means the whole part on the right of the equals sign (=) is the value of the variable named on the left hand side (FOO). And in the example above this includes the quotes.

What happened to me earlier on was that I tried to set an environment variable (PYFLAKES_BUILTINS) which got picked up by pyflakes. I used:

export PYFLAKES_BUILTINS="_"
fun:
    pyflakes file.py

Now, spot the problem.

Solution: pyflakes (correctly) didn’t behave as expected (handle _ as a built-in), because the value of the variable was “_”, instead of _.

$ export PYFLAKES_BUILTINS="_"
$ pyflakes file.py

The above snippet on the other hand works oin the shell, because the quotes (in the export line) are interpreted by the shell, and are nto part of the PYFLAKES_BUILTIN variable.

::: {#footer} [ September 16th, 2013 10:45am ]{#timestamp} [automake]{.tag} [fedora]{.tag} [pyflakes]{.tag} [python]{.tag} [node]{.tag} :::