Skip to content

Commit b756833

Browse files
authored
BUG: Fix full rebuilds (#226)
1 parent c2175bb commit b756833

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

numpydoc/numpydoc.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"""
1919
from __future__ import division, absolute_import, print_function
2020

21+
from copy import deepcopy
2122
import sys
2223
import re
2324
import pydoc
@@ -160,7 +161,7 @@ def mangle_docstrings(app, what, name, obj, options, lines):
160161
'attributes_as_param_list':
161162
app.config.numpydoc_attributes_as_param_list,
162163
'xref_param_type': app.config.numpydoc_xref_param_type,
163-
'xref_aliases': app.config.numpydoc_xref_aliases,
164+
'xref_aliases': app.config.numpydoc_xref_aliases_complete,
164165
'xref_ignore': app.config.numpydoc_xref_ignore,
165166
}
166167

@@ -258,9 +259,15 @@ def setup(app, get_doc_object_=get_doc_object):
258259

259260
def update_config(app):
260261
"""Update the configuration with default values."""
262+
# Do not simply overwrite the `app.config.numpydoc_xref_aliases`
263+
# otherwise the next sphinx-build will compare the incoming values (without
264+
# our additions) to the old values (with our additions) and trigger
265+
# a full rebuild!
266+
numpydoc_xref_aliases_complete = deepcopy(app.config.numpydoc_xref_aliases)
261267
for key, value in DEFAULT_LINKS.items():
262-
if key not in app.config.numpydoc_xref_aliases:
263-
app.config.numpydoc_xref_aliases[key] = value
268+
if key not in numpydoc_xref_aliases_complete:
269+
numpydoc_xref_aliases_complete[key] = value
270+
app.config.numpydoc_xref_aliases_complete = numpydoc_xref_aliases_complete
264271

265272

266273
# ------------------------------------------------------------------------------

numpydoc/tests/test_docscrape.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from __future__ import division, absolute_import, print_function
33

44
from collections import namedtuple
5+
from copy import deepcopy
56
import re
67
import sys
78
import textwrap
@@ -10,6 +11,7 @@
1011
import jinja2
1112

1213
from numpydoc.numpydoc import update_config
14+
from numpydoc.xref import DEFAULT_LINKS
1315
from numpydoc.docscrape import (
1416
NumpyDocString,
1517
FunctionDoc,
@@ -1485,8 +1487,16 @@ def test_xref():
14851487
xref_aliases = {
14861488
'sequence': ':obj:`python:sequence`',
14871489
}
1488-
config = namedtuple('numpydoc_xref_aliases',
1489-
'numpydoc_xref_aliases')(xref_aliases)
1490+
1491+
class Config():
1492+
def __init__(self, a, b):
1493+
self.numpydoc_xref_aliases = a
1494+
self.numpydoc_xref_aliases_complete = b
1495+
1496+
xref_aliases_complete = deepcopy(DEFAULT_LINKS)
1497+
for key in xref_aliases:
1498+
xref_aliases_complete[key] = xref_aliases[key]
1499+
config = Config(xref_aliases, xref_aliases_complete)
14901500
app = namedtuple('config', 'config')(config)
14911501
update_config(app)
14921502

@@ -1496,7 +1506,7 @@ def test_xref():
14961506
xref_doc_txt,
14971507
config=dict(
14981508
xref_param_type=True,
1499-
xref_aliases=xref_aliases,
1509+
xref_aliases=xref_aliases_complete,
15001510
xref_ignore=xref_ignore
15011511
)
15021512
)

numpydoc/tests/test_numpydoc.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# -*- encoding:utf-8 -*-
22
from __future__ import division, absolute_import, print_function
33

4+
from copy import deepcopy
45
from numpydoc.numpydoc import mangle_docstrings
6+
from numpydoc.xref import DEFAULT_LINKS
57
from sphinx.ext.autodoc import ALL
68

9+
710
class MockConfig():
811
numpydoc_use_plots = False
912
numpydoc_use_blockquotes = True
@@ -12,15 +15,18 @@ class MockConfig():
1215
numpydoc_class_members_toctree = True
1316
numpydoc_xref_param_type = False
1417
numpydoc_xref_aliases = {}
18+
numpydoc_xref_aliases_complete = deepcopy(DEFAULT_LINKS)
1519
numpydoc_xref_ignore = set()
1620
templates_path = []
1721
numpydoc_edit_link = False
1822
numpydoc_citation_re = '[a-z0-9_.-]+'
1923
numpydoc_attributes_as_param_list = True
2024

25+
2126
class MockBuilder():
2227
config = MockConfig()
2328

29+
2430
class MockApp():
2531
config = MockConfig()
2632
builder = MockBuilder()
@@ -30,6 +36,7 @@ class MockApp():
3036
app = MockApp()
3137
app.builder.app = app
3238

39+
3340
def test_mangle_docstrings():
3441
s ='''
3542
A top section before
@@ -56,5 +63,6 @@ def test_mangle_docstrings():
5663
assert 'rpartition' in [x.strip() for x in lines]
5764
assert 'upper' not in [x.strip() for x in lines]
5865

66+
5967
if __name__ == "__main__":
6068
import pytest

0 commit comments

Comments
 (0)