Skip to content

Commit

Permalink
BUG: Fix full rebuilds (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Jun 21, 2019
1 parent c2175bb commit b756833
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
13 changes: 10 additions & 3 deletions numpydoc/numpydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"""
from __future__ import division, absolute_import, print_function

from copy import deepcopy
import sys
import re
import pydoc
Expand Down Expand Up @@ -160,7 +161,7 @@ def mangle_docstrings(app, what, name, obj, options, lines):
'attributes_as_param_list':
app.config.numpydoc_attributes_as_param_list,
'xref_param_type': app.config.numpydoc_xref_param_type,
'xref_aliases': app.config.numpydoc_xref_aliases,
'xref_aliases': app.config.numpydoc_xref_aliases_complete,
'xref_ignore': app.config.numpydoc_xref_ignore,
}

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

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


# ------------------------------------------------------------------------------
Expand Down
16 changes: 13 additions & 3 deletions numpydoc/tests/test_docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import division, absolute_import, print_function

from collections import namedtuple
from copy import deepcopy
import re
import sys
import textwrap
Expand All @@ -10,6 +11,7 @@
import jinja2

from numpydoc.numpydoc import update_config
from numpydoc.xref import DEFAULT_LINKS
from numpydoc.docscrape import (
NumpyDocString,
FunctionDoc,
Expand Down Expand Up @@ -1485,8 +1487,16 @@ def test_xref():
xref_aliases = {
'sequence': ':obj:`python:sequence`',
}
config = namedtuple('numpydoc_xref_aliases',
'numpydoc_xref_aliases')(xref_aliases)

class Config():
def __init__(self, a, b):
self.numpydoc_xref_aliases = a
self.numpydoc_xref_aliases_complete = b

xref_aliases_complete = deepcopy(DEFAULT_LINKS)
for key in xref_aliases:
xref_aliases_complete[key] = xref_aliases[key]
config = Config(xref_aliases, xref_aliases_complete)
app = namedtuple('config', 'config')(config)
update_config(app)

Expand All @@ -1496,7 +1506,7 @@ def test_xref():
xref_doc_txt,
config=dict(
xref_param_type=True,
xref_aliases=xref_aliases,
xref_aliases=xref_aliases_complete,
xref_ignore=xref_ignore
)
)
Expand Down
8 changes: 8 additions & 0 deletions numpydoc/tests/test_numpydoc.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# -*- encoding:utf-8 -*-
from __future__ import division, absolute_import, print_function

from copy import deepcopy
from numpydoc.numpydoc import mangle_docstrings
from numpydoc.xref import DEFAULT_LINKS
from sphinx.ext.autodoc import ALL


class MockConfig():
numpydoc_use_plots = False
numpydoc_use_blockquotes = True
Expand All @@ -12,15 +15,18 @@ class MockConfig():
numpydoc_class_members_toctree = True
numpydoc_xref_param_type = False
numpydoc_xref_aliases = {}
numpydoc_xref_aliases_complete = deepcopy(DEFAULT_LINKS)
numpydoc_xref_ignore = set()
templates_path = []
numpydoc_edit_link = False
numpydoc_citation_re = '[a-z0-9_.-]+'
numpydoc_attributes_as_param_list = True


class MockBuilder():
config = MockConfig()


class MockApp():
config = MockConfig()
builder = MockBuilder()
Expand All @@ -30,6 +36,7 @@ class MockApp():
app = MockApp()
app.builder.app = app


def test_mangle_docstrings():
s ='''
A top section before
Expand All @@ -56,5 +63,6 @@ def test_mangle_docstrings():
assert 'rpartition' in [x.strip() for x in lines]
assert 'upper' not in [x.strip() for x in lines]


if __name__ == "__main__":
import pytest

0 comments on commit b756833

Please sign in to comment.