Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix C coverage support for sphinx.ext.coverage #11591

Merged
merged 4 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,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);