The variable expansion support in this library could be useful: https://github.com/sloria/environs#variable-expansion We can use it when available, and otherwise fallback to our existing portage.util.getconfig() implementation.
(In reply to Zac Medico from comment #0) > The variable expansion support in this library could be useful: > > https://github.com/sloria/environs#variable-expansion I've checked the code, and it actually uses this regular expression to search for variable references and expand them on-demand (portage can't use it): _EXPANDED_VAR_PATTERN = re.compile(r"(?<!\\)\$\{([A-Za-z0-9_]+)(:-[^\}:]*)?\}")
python-dotenv might be usable, and supports default values with this regex: _posix_variable = re.compile( r""" \$\{ (?P<name>[^\}:]*) (?::- (?P<default>[^\}]*) )? \} """, re.VERBOSE, ) # type: Pattern[Text] https://github.com/theskumar/python-dotenv/blob/master/src/dotenv/variables.py
Since python-dotenv requires { and } to surround variables names, it's only useful in the sense that we can copy and modify its _posix_variable regex.