DiffSK / configobj

Python 3+ compatible port of the configobj library
https://configobj.readthedocs.org
Other
322 stars 76 forks source link

Handle pipes via process substitution #206

Open shkm opened 4 years ago

shkm commented 4 years ago

FWIW I'm not a python developer so this code may have repercussions that I'm unable to diagnose.

Background

I'm doing some manual templating on config files for two programs: khal and khard, both of which use configobj. Neither program allows for interpolation in the config files, so I was required to roll my own. Essentially, I run these programs with a wrapper like this:

#!/usr/bin/env bash
source pimenv

/usr/bin/khal -c <(envsubst < "$XDG_CONFIG_HOME/khal/config") "$@"

Sourcing pimenv provides a bunch of environment variables which are interpolated into the config file using envsubst with process substitution, producing a file descriptor (/dev/fd/63).

On Linux, at least, os.path.isfile() returns False for this descriptor, but os.path.islink() returns True. As a result, even though the file is readable, configobj never tries to read it and throws an error.

The Fix

Well, the code is pretty self-explanatory. I've tested this under both khal and khard, and found that everything works as expected now. Interestingly, os.path.isfile() does return True for a symlink, so this is probably quite an edge case.

shkm commented 4 years ago

I now see that this has already been handled by another PR: https://github.com/DiffSK/configobj/pull/187.

I'll leave this open, though; I'm not sure what's the better solution here. Feel free to close if the other is preferred.