Skip to content

Commit

Permalink
Fix C coverage support in sphinx.ext.coverage (#11591)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenfin committed Aug 15, 2023
1 parent 1e0bc26 commit 53a930f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ Bugs fixed
* #11473: Type annotations containing :py:data:`~typing.Literal` enumeration
values now render correctly.
Patch by Bénédikt Tran.
* #11591: Fix support for C coverage in ``sphinx.ext.coverage`` extension.
Patch by Stephen Finucane.

Testing
-------
Expand Down
2 changes: 1 addition & 1 deletion sphinx/domains/c.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
'thread_local',
]

# these are ordered by preceedence
# these are ordered by precedence
_expression_bin_ops = [
['||', 'or'],
['&&', 'and'],
Expand Down
11 changes: 8 additions & 3 deletions sphinx/ext/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ def write(self, *ignored: Any) -> None:
self.write_c_coverage()

def build_c_coverage(self) -> None:
# Fetch all the info from the header files
c_objects = self.env.domaindata['c']['objects']
c_objects = {}
for obj in self.env.domains['c'].get_objects():
c_objects[obj[2]] = obj[1]
for filename in self.c_sourcefiles:
undoc: set[tuple[str, str]] = set()
with open(filename, encoding="utf-8") as f:
Expand All @@ -124,7 +125,11 @@ def build_c_coverage(self) -> None:
match = regex.match(line)
if match:
name = match.groups()[0]
if name not in c_objects:
if key not in c_objects:
undoc.add((key, name))
continue

if name not in c_objects[key]:
for exp in self.c_ignorexps.get(key, []):
if exp.match(name):
break
Expand Down
2 changes: 2 additions & 0 deletions tests/roots/test-root/objects.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ C items

.. c:var:: int sphinx_global

.. c:function:: PyObject* Py_SphinxFoo(void)


Javascript items
================
Expand Down
3 changes: 2 additions & 1 deletion tests/roots/test-root/special/api.h
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PyAPI_FUNC(PyObject *) Py_SphinxTest();
PyAPI_FUNC(PyObject *) Py_SphinxTest(void);
PyAPI_FUNC(PyObject *) Py_SphinxFoo(void);

0 comments on commit 53a930f

Please sign in to comment.