Skip to content

Commit

Permalink
Fix resolution bug in sphinx_literate
Browse files Browse the repository at this point in the history
  • Loading branch information
eliemichel committed Jul 6, 2024
1 parent 7a79883 commit a8ca91f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 28 deletions.
46 changes: 18 additions & 28 deletions _extensions/sphinx_literate/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,31 +417,6 @@ def register_codeblock(self, lit: CodeBlock, options: BlockOptions = set()) -> N
lit.relation_to_prev = 'NEW'
self._add_codeblock(lit)

self._fix_missing_referees(lit)

def _fix_missing_referees(self, lit):
"""
Notify all children tangles that a new block `lit` is defined and thus
may no longer be missing.
Also set child_lit.prev
FIXME: This is inefficient, maybe we should manage missings
differently (e.g., by not storing them and only testing once the full
register is created.)
"""
for child_tangle in self._all_children_tangle_roots(lit.tangle_root):
new_missing_list = []
for missing in self._missing:
if missing.key == CodeBlock.build_key(lit.name, child_tangle):
child_lit = self.get_by_key(missing.key)
if child_lit.prev is not None:
print(f"ERROR {child_lit.format()} has non null prev {child_lit.prev.format()}")
assert(child_lit.prev is None)
assert(child_lit.relation_to_prev not in {'NEW', 'INSERTED'})
child_lit.prev = lit
else:
new_missing_list.append(missing)
self._missing = new_missing_list

def _add_codeblock(self, lit: CodeBlock) -> None:
"""
Add a new code block to the repository. If a block already exists with
Expand Down Expand Up @@ -477,6 +452,14 @@ def _override_codeblock(self, lit: CodeBlock, relation_to_prev: str):

existing = self.get_rec(lit.name, lit.tangle_root)

# DEBUG
if lit.name in { "Application attributes" } and "vanilla" not in lit.tangle_root:
print(f"_override_codeblock({lit.format()}, {relation_to_prev})")
if existing:
print(f" | existing = {existing.format()}")
else:
print(f" | (no prev)")

if existing is None:
self._missing.append(
MissingCodeBlock(lit.key, lit.relation_to_prev)
Expand Down Expand Up @@ -515,23 +498,31 @@ def merge(self, other: CodeBlockRegistry) -> None:
self._add_codeblock(lit)
else:
self._override_codeblock(lit, lit.relation_to_prev)
self._fix_missing_referees(lit)
self.check_integrity(allow_missing=True)

# Merge cross-references
for key, refs in other._references.items():
self._references[key].update(refs)

def try_fixing_all_missing(self):
new_missing_list = []
for missing in self._missing[:]:
missing_tangle_root, missing_name = missing.key.split("##")

# Look for the missing lit name in the parent tangle
entry = self._hierarchy.get(missing_tangle_root)
if entry is None:
continue
parent_tangle_root = entry.parent
existing = self.get_rec(missing_name, parent_tangle_root)

# If found, register it as previous literate block
if existing:
self._fix_missing_referees(existing)
child_lit = self.get_by_key(missing.key)
child_lit.prev = existing
else:
new_missing_list.append(missing)
self._missing = new_missing_list

def remove_codeblocks_by_docname(self, docname: str) -> None:
# TODO: when supporting cross-document REPLACE, be careful here
Expand Down Expand Up @@ -779,7 +770,6 @@ def pretty_dump(self, options: List[str] = set()):
Display debug information about the registry.
Used by {lit-registry} directive.
"""
options = set()
ret = []
ret += ["== Registry dump =="]
ret += ["Blocks:"]
Expand Down
2 changes: 2 additions & 0 deletions basic-3d-rendering/input-geometry/index-buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ Index Buffer
:tangle-root: 034 - Index Buffer - vanilla
:parent: 033 - Multiple Attributes - Option A - vanilla
:alias: Vanilla
:debug:
```

```{lit-setup}
:tangle-root: 034 - Index Buffer
:parent: 033 - Multiple Attributes - Option A
:debug:
```

````{tab} With webgpu.hpp
Expand Down

0 comments on commit a8ca91f

Please sign in to comment.