summaryrefslogtreecommitdiff
path: root/sphinx/ext/autodoc.py
diff options
context:
space:
mode:
authorDmitry Shachnev <mitya57@gmail.com>2015-01-28 19:28:53 +0300
committerDmitry Shachnev <mitya57@gmail.com>2015-01-28 21:24:36 +0300
commitd24bd73d0ce8071459a1056691a1934e1ca12194 (patch)
treed587d76fefb266534f2066f6afa9379a4f484d79 /sphinx/ext/autodoc.py
parent81ffb36772820cf2a0123348ce04df01bddd2229 (diff)
downloadsphinx-git-d24bd73d0ce8071459a1056691a1934e1ca12194.tar.gz
Remove non-determinism
To enable packages using Sphinx to build reproducibly, its output needs to be the same from one build to another. Its output now strips memory references such as: <__main__.A at 0x7f68cb685710> In addition, various generated files (objects.inv, searchindex.js, translations) are now written with their keys in a determinstic order. Based on a patch by Chris Lamb <lamby@debian.org>.
Diffstat (limited to 'sphinx/ext/autodoc.py')
-rw-r--r--sphinx/ext/autodoc.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py
index ba4619e7c..27cd54f93 100644
--- a/sphinx/ext/autodoc.py
+++ b/sphinx/ext/autodoc.py
@@ -30,7 +30,7 @@ from sphinx.application import ExtensionError
from sphinx.util.nodes import nested_parse_with_titles
from sphinx.util.compat import Directive
from sphinx.util.inspect import getargspec, isdescriptor, safe_getmembers, \
- safe_getattr, safe_repr, is_builtin_class_method
+ safe_getattr, object_description, is_builtin_class_method
from sphinx.util.docstrings import prepare_docstring
@@ -243,6 +243,11 @@ def between(marker, what=None, keepempty=False, exclude=False):
return process
+def formatargspec(*argspec):
+ return inspect.formatargspec(*argspec,
+ formatvalue=lambda x: '=' + object_description(x))
+
+
class Documenter(object):
"""
A Documenter knows how to autodocument a single object type. When
@@ -1054,7 +1059,7 @@ class FunctionDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter):
argspec = getargspec(self.object.__init__)
if argspec[0]:
del argspec[0][0]
- args = inspect.formatargspec(*argspec)
+ args = formatargspec(*argspec)
# escape backslashes for reST
args = args.replace('\\', '\\\\')
return args
@@ -1109,7 +1114,7 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter):
return None
if argspec[0] and argspec[0][0] in ('cls', 'self'):
del argspec[0][0]
- return inspect.formatargspec(*argspec)
+ return formatargspec(*argspec)
def format_signature(self):
if self.doc_as_attr:
@@ -1220,7 +1225,7 @@ class DataDocumenter(ModuleLevelDocumenter):
sourcename = self.get_sourcename()
if not self.options.annotation:
try:
- objrepr = safe_repr(self.object)
+ objrepr = object_description(self.object)
except ValueError:
pass
else:
@@ -1276,7 +1281,7 @@ class MethodDocumenter(DocstringSignatureMixin, ClassLevelDocumenter):
argspec = getargspec(self.object)
if argspec[0] and argspec[0][0] in ('cls', 'self'):
del argspec[0][0]
- args = inspect.formatargspec(*argspec)
+ args = formatargspec(*argspec)
# escape backslashes for reST
args = args.replace('\\', '\\\\')
return args
@@ -1333,7 +1338,7 @@ class AttributeDocumenter(DocstringStripSignatureMixin, ClassLevelDocumenter):
if not self.options.annotation:
if not self._datadescriptor:
try:
- objrepr = safe_repr(self.object)
+ objrepr = object_description(self.object)
except ValueError:
pass
else: