diff options
author | Arthur Zamarin <arthurzam@gentoo.org> | 2023-10-23 20:03:29 +0300 |
---|---|---|
committer | Arthur Zamarin <arthurzam@gentoo.org> | 2023-10-23 20:03:29 +0300 |
commit | 6749d045ad29ea56eec1e380335594c37d53efde (patch) | |
tree | ed80427fe0f906a963f064de2ac3eb4c623d15a6 | |
parent | eclassdoc: output exported phases (diff) | |
download | pkgcore-6749d045ad29ea56eec1e380335594c37d53efde.tar.gz pkgcore-6749d045ad29ea56eec1e380335594c37d53efde.tar.bz2 pkgcore-6749d045ad29ea56eec1e380335594c37d53efde.zip |
eclassdoc: parse default and initial values
A little bit ugly, but does the job.
Resolves: https://github.com/pkgcore/pkgcore/issues/297
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
-rw-r--r-- | src/pkgcore/ebuild/eclass.py | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/pkgcore/ebuild/eclass.py b/src/pkgcore/ebuild/eclass.py index 9859f657..f1a0cacd 100644 --- a/src/pkgcore/ebuild/eclass.py +++ b/src/pkgcore/ebuild/eclass.py @@ -173,7 +173,7 @@ class ParseEclassDoc: """Return default field mapping for the block.""" return {name: default for name, _required, _func, default in self.tags.values()} - def parse(self, lines, line_ind): + def parse(self, lines, line_ind, _next_line): """Parse an eclass block.""" blocks = [] data = self.defaults @@ -260,6 +260,15 @@ class EclassVarBlock(ParseEclassDoc): } super().__init__(tags) + def parse(self, lines, line_ind, next_line): + data = dict(super().parse(lines, line_ind, next_line)) + var_name = data["name"] + if mo := re.search(rf"{var_name}=(?P<value>.*)", next_line): + data["initial_value"] = mo.group("value") + if mo := re.search(rf": \${{{var_name}:?=(?P<value>.*)}}", next_line): + data["default_value"] = mo.group("value") + return AttrDict(data) + # For backwards compatibility, can be removed after 2022-12-31 class EclassVarBlockCompat(ParseEclassDoc): @@ -492,13 +501,13 @@ class EclassDoc(AttrDict): block = [] block_start = line_ind + 1 while line_ind < len(lines): - line = lines[line_ind] + next_line = line = lines[line_ind] if not line.startswith(prefix): break line = line[len(prefix) + 1 :] block.append(line) line_ind += 1 - blocks.append((tag, block, block_start)) + blocks.append((tag, block, block_start, next_line)) line_ind += 1 # set default fields @@ -526,9 +535,9 @@ class EclassDoc(AttrDict): duplicates = {k: set() for k in ParseEclassDoc.blocks} # parse identified blocks - for tag, block, block_start in blocks: + for tag, block, block_start, next_line in blocks: block_obj = ParseEclassDoc.blocks[tag] - block_data = block_obj.parse(block, block_start) + block_data = block_obj.parse(block, block_start, next_line) # check if duplicate blocks exist and merge data if block_obj.key is None: # main @ECLASS block @@ -619,6 +628,10 @@ class EclassDoc(AttrDict): rst.extend(_header_only("-", "Variables")) for var in external_vars: vartype = "" + if default_value := getattr(var, "default_value", None): + vartype += f" ?= *{default_value}*" + elif initial_value := getattr(var, "initial_value", None): + vartype += f" = *{initial_value}*" if var.required: vartype += " (REQUIRED)" if var.pre_inherit: |