Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 781875

Summary: sys-apps/portage: improve make.conf parser
Product: Portage Development Reporter: Zac Medico <zmedico>
Component: Core - ConfigurationAssignee: Portage team <dev-portage>
Status: CONFIRMED ---    
Severity: enhancement CC: gentoo, sam
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: All   
See Also: https://bugs.gentoo.org/show_bug.cgi?id=338555
Whiteboard:
Package list:
Runtime testing required: ---

Description Zac Medico gentoo-dev 2021-04-09 21:41:31 UTC
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.
Comment 1 Zac Medico gentoo-dev 2021-04-09 22:05:41 UTC
(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_]+)(:-[^\}:]*)?\}")
Comment 2 Zac Medico gentoo-dev 2021-04-09 22:11:05 UTC
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
Comment 3 Zac Medico gentoo-dev 2021-04-09 22:19:35 UTC
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.