Skip to content

Commit

Permalink
Fix links for nested types in generated docs (chapel-lang#24584)
Browse files Browse the repository at this point in the history
This PR pulls in a fix from sphinxcontrib-chapeldomain that fixes how
links for nested types are rendered. This PR also adds a test for
chpldoc to lock in the correct behavior.

See chapel-lang/sphinxcontrib-chapeldomain#90
for details of the fix

[Reviewed by @lydia-duncan]
  • Loading branch information
jabraham17 authored Mar 12, 2024
2 parents c9e1466 + 0efb6ff commit c362c75
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 1 deletion.
25 changes: 25 additions & 0 deletions test/chpldoc/links/nested.doc.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
This test is to make sure that links for nested types are handled correctly. All of these links should resolve correctly
- :type:`nested.A`
- :proc:`nested.A.foo`
- :type:`nested.A.B`
- :proc:`nested.A.B.bar`
- :proc:`nested.A.baz`
- :type:`nested.C`
- :proc:`nested.C.foo`
*/
module nested {
record A {
proc foo() {}
record B {
proc bar() {}
}
proc baz() {}
}
record C {
proc foo() {}
}
}
1 change: 1 addition & 0 deletions test/chpldoc/links/nested.doc.chpldocopts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-o docs
1 change: 1 addition & 0 deletions test/chpldoc/links/nested.doc.cleanfiles
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docs
7 changes: 7 additions & 0 deletions test/chpldoc/links/nested.doc.good
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Found link for reference '#nested.A'
Found link for reference '#nested.A.foo'
Found link for reference '#nested.A.B'
Found link for reference '#nested.A.B.bar'
Found link for reference '#nested.A.baz'
Found link for reference '#nested.C'
Found link for reference '#nested.C.foo'
33 changes: 33 additions & 0 deletions test/chpldoc/links/nested.doc.prediff
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3

import sys
import os
import re

testname = sys.argv[1]
testout = sys.argv[2]

html_file = f"docs/modules/nested.html"
if not os.path.exists(html_file):
with open(testout, "w") as f:
print(f"Could not find '{html_file}'", file=f)
exit()

html_output = ""
with open(html_file, "r") as f:
html_output = f.read()

output = []

# find all the references from the docstring with the following regex
reference_pat = re.compile('<a class="reference internal" href="#(.+?)" title="\\1">')
for m in re.finditer(reference_pat, html_output):
# for each reference, check if the link exists
link = m.group(1)
if not re.search(f'<a class="headerlink" href="#{link}" title="Permalink to this definition">', html_output):
output.append(f"Could not find link for reference '#{link}'")
else:
output.append(f"Found link for reference '#{link}'")

with open(testout, "w") as f:
print("\n".join(output), file=f)
2 changes: 1 addition & 1 deletion third-party/chpl-venv/chpldoc-requirements3.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Split into 3 files to work around problems with CHPL_PIP_FROM_SOURCE
sphinx-rtd-theme==2.0.0
sphinxcontrib-chapeldomain==0.0.30
sphinxcontrib-chapeldomain==0.0.31
breathe==4.35.0

0 comments on commit c362c75

Please sign in to comment.