diff options
author | Dmitry Shachnev <mitya57@gmail.com> | 2015-01-28 19:28:53 +0300 |
---|---|---|
committer | Dmitry Shachnev <mitya57@gmail.com> | 2015-01-28 21:24:36 +0300 |
commit | d24bd73d0ce8071459a1056691a1934e1ca12194 (patch) | |
tree | d587d76fefb266534f2066f6afa9379a4f484d79 /sphinx/util/inspect.py | |
parent | 81ffb36772820cf2a0123348ce04df01bddd2229 (diff) | |
download | sphinx-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/util/inspect.py')
-rw-r--r-- | sphinx/util/inspect.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 8cbf59bde..d2d5dd0a3 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +import re + # this imports the standard library inspect module without resorting to # relatively import this module inspect = __import__('inspect') @@ -18,6 +20,8 @@ from six.moves import builtins from sphinx.util import force_decode +memory_address_re = re.compile(r' at 0x[0-9a-f]{8,16}(?=>$)') + if PY3: from functools import partial @@ -123,14 +127,17 @@ def safe_getmembers(object, predicate=None, attr_getter=safe_getattr): return results -def safe_repr(object): +def object_description(object): """A repr() implementation that returns text safe to use in reST context.""" try: s = repr(object) except Exception: raise ValueError if isinstance(s, binary_type): - return force_decode(s, None).replace('\n', ' ') + s = force_decode(s, None) + # Strip non-deterministic memory addresses such as + # ``<__main__.A at 0x7f68cb685710>`` + s = memory_address_re.sub('', s) return s.replace('\n', ' ') |