summaryrefslogtreecommitdiff
path: root/sphinx/ext/coverage.py
diff options
context:
space:
mode:
authorMartin Brochhaus <mbrochh@gmail.com>2010-09-07 16:06:06 +0200
committerMartin Brochhaus <mbrochh@gmail.com>2010-09-07 16:06:06 +0200
commit8f2f4db5ac87fe66aec481f345120dac9721f4c0 (patch)
treee3d27e33ac647a00a101850262a22bec36e5f6db /sphinx/ext/coverage.py
parentfee6b38142e88dd7caf2074254b6117bf0f4504c (diff)
downloadsphinx-git-8f2f4db5ac87fe66aec481f345120dac9721f4c0.tar.gz
Minor changes to make coverage extension more robust against exceptions and false positives..
Diffstat (limited to 'sphinx/ext/coverage.py')
-rw-r--r--sphinx/ext/coverage.py32
1 files changed, 26 insertions, 6 deletions
diff --git a/sphinx/ext/coverage.py b/sphinx/ext/coverage.py
index f41820e2a..5bcd12b2c 100644
--- a/sphinx/ext/coverage.py
+++ b/sphinx/ext/coverage.py
@@ -166,7 +166,8 @@ class CoverageBuilder(Builder):
if exp.match(name):
break
else:
- if full_name not in objects:
+ if (full_name not in objects
+ and not obj.__doc__):
# not documented at all
classes[name] = []
continue
@@ -174,16 +175,21 @@ class CoverageBuilder(Builder):
attrs = []
for attr_name in dir(obj):
+ if attr_name not in obj.__dict__:
+ continue
attr = getattr(obj, attr_name)
- for attr_name, attr in inspect.getmembers(
- obj, lambda x: inspect.ismethod(x) or \
- inspect.isfunction(x)):
+ if (not inspect.ismethod(attr)
+ and not inspect.isfunction(attr)):
+ continue
if attr_name[0] == '_':
# starts with an underscore, ignore it
continue
full_attr_name = '%s.%s' % (full_name, attr_name)
if full_attr_name not in objects:
+ if not self._is_func_undocumented(
+ obj, attr_name):
+ continue
attrs.append(attr_name)
if attrs:
@@ -192,13 +198,26 @@ class CoverageBuilder(Builder):
self.py_undoc[mod_name] = {'funcs': funcs, 'classes': classes}
+ def _is_func_undocumented(self, obj, attr_name):
+ """Last check looking at the source code. Is function really not documented?"""
+ obj_source = inspect.getsource(obj) or ''
+ obj_source = obj_source.replace(' ', '').replace('\n', '')
+ if not "def%s" % attr_name in obj_source:
+ # Funktion is not defined in this class. No documentation needed.
+ return False
+ m = re.search('def%s\([^\)]*\):"""' %attr_name, obj_source)
+ if not m:
+ return True
+ else:
+ return False
+
def write_py_coverage(self):
output_file = path.join(self.outdir, 'python.txt')
op = open(output_file, 'w')
failed = []
try:
- write_header(op, 'Undocumented Python objects', '=')
-
+ if self.config.coverage_write_headline:
+ write_header(op, 'Undocumented Python objects', '=')
keys = self.py_undoc.keys()
keys.sort()
for name in keys:
@@ -248,3 +267,4 @@ def setup(app):
app.add_config_value('coverage_c_path', [], False)
app.add_config_value('coverage_c_regexes', {}, False)
app.add_config_value('coverage_ignore_c_items', {}, False)
+ app.add_config_value('coverage_write_headline', {}, False) \ No newline at end of file