Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4c8e33c

Browse files
authored
Merge pull request astropy#100 from rocco8773/fix-keyerror-refexplicit
Fix keyerror on refexplicit and refdoc
2 parents 30953a9 + 01add30 commit 4c8e33c

File tree

4 files changed

+47
-15
lines changed

4 files changed

+47
-15
lines changed

azure-template.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ jobs:
22
- job: ${{ format(parameters.name) }}
33
pool:
44
${{ if eq(parameters.os, 'macosx') }}:
5-
vmImage: macOS 10.13
5+
vmImage: 'macOS-latest'
66
${{ if eq(parameters.os, 'linux') }}:
7-
vmImage: Ubuntu 16.04
7+
vmImage: 'ubuntu-latest'
88
${{ if eq(parameters.os, 'windows') }}:
9-
vmImage: vs2017-win2016
9+
vmImage: 'vs2017-win2016'
1010

1111
steps:
1212

@@ -40,7 +40,7 @@ jobs:
4040
versionSpec: '3.7'
4141
architecture: 'x64'
4242

43-
- script: pip install tox coverage
43+
- script: pip install tox "coverage<5.0"
4444
displayName: Installing tox and coverage
4545

4646
- script: tox

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test =
2828
pytest-cov
2929
cython
3030
codecov
31-
coverage
31+
coverage < 5.0
3232

3333
[options.package_data]
3434
sphinx_automodapi = templates/*/*.rst

sphinx_automodapi/automodapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class are included in the generated documentation. Defaults to ``False``.
166166
def automodapi_replace(sourcestr, app, dotoctree=True, docname=None,
167167
warnings=True):
168168
"""
169-
Replaces `sourcestr`'s entries of ".. automdapi::" with the
169+
Replaces `sourcestr`'s entries of ".. automodapi::" with the
170170
automodapi template form based on provided options.
171171
172172
This is used with the sphinx event 'source-read' to replace

sphinx_automodapi/smart_resolver.py

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,53 @@ def merge_mapping(app, env, docnames, env_other):
3434

3535

3636
def missing_reference_handler(app, env, node, contnode):
37+
"""
38+
Handler to be connect to the sphinx 'missing-reference' event. The handler a
39+
resolves reference (node) and returns a new node when sphinx could not
40+
originally resolve the reference.
41+
42+
see `missing-reference in sphinx documentation
43+
<https://www.sphinx-doc.org/en/master/extdev/appapi.html#event-missing-reference>`_
44+
45+
:param app: The Sphinx application object
46+
:param env: The build environment (``app.builder.env`)
47+
:param node: The ``pending_xref`` node to be resolved. Its attributes reftype,
48+
reftarget, modname and classname attributes determine the type and
49+
target of the reference.
50+
:param contnode: The node that carries the text and formatting inside the
51+
future reference and should be a child of the returned
52+
reference node.
53+
"""
54+
# a good example of how a missing reference handle works look to
55+
# https://github.com/sphinx-doc/sphinx/issues/1572#issuecomment-68590981
56+
#
57+
# Important attributes of the "node":
58+
#
59+
# example role: :ref:`title <target>`
60+
#
61+
# 'reftype' - role name (in the example above 'ref' is the reftype)
62+
# 'reftarget' - target of the role, as given in the role content
63+
# (in the example 'target' is the reftarget
64+
# 'refexplicit' - the explicit title of the role
65+
# (in the example 'title' is the refexplicit)
66+
# 'refdoc' - document in which the role appeared
67+
# 'refdomain' - domain of the role, in our case emtpy
3768

3869
if not hasattr(env, 'class_name_mapping'):
3970
env.class_name_mapping = {}
4071
mapping = env.class_name_mapping
4172

4273
reftype = node['reftype']
4374
reftarget = node['reftarget']
75+
refexplicit = node.get('refexplicit') # default: None
76+
refdoc = node.get('refdoc', env.docname)
4477
if reftype in ('obj', 'class', 'exc', 'meth'):
45-
reftarget = node['reftarget']
4678
suffix = ''
4779
if reftarget not in mapping:
4880
if '.' in reftarget:
4981
front, suffix = reftarget.rsplit('.', 1)
5082
else:
83+
front = None
5184
suffix = reftarget
5285

5386
if suffix.startswith('_') and not suffix.startswith('__'):
@@ -56,7 +89,7 @@ def missing_reference_handler(app, env, node, contnode):
5689
# nitpick warning.
5790
return node[0].deepcopy()
5891

59-
if reftype in ('obj', 'meth') and '.' in reftarget:
92+
if reftype in ('obj', 'meth') and front is not None:
6093
if front in mapping:
6194
reftarget = front
6295
suffix = '.' + suffix
@@ -73,10 +106,10 @@ def missing_reference_handler(app, env, node, contnode):
73106
if (reftarget not in mapping and
74107
prefix in inventory):
75108

76-
if 'py:class' in inventory[prefix] and reftarget in inventory[prefix]['py:class']:
109+
if 'py:class' in inventory[prefix] and \
110+
reftarget in inventory[prefix]['py:class']:
77111
newtarget = inventory[prefix]['py:class'][reftarget][2]
78-
if not node['refexplicit'] and \
79-
'~' not in node.rawsource:
112+
if not refexplicit and '~' not in node.rawsource:
80113
contnode = literal(text=reftarget)
81114
newnode = reference('', '', internal=True)
82115
newnode['reftitle'] = reftarget
@@ -87,11 +120,10 @@ def missing_reference_handler(app, env, node, contnode):
87120

88121
if reftarget in mapping:
89122
newtarget = mapping[reftarget] + suffix
90-
if not node['refexplicit'] and '~' not in node.rawsource:
123+
if not refexplicit and '~' not in node.rawsource:
91124
contnode = literal(text=newtarget)
92-
newnode = env.domains['py'].resolve_xref(
93-
env, node['refdoc'], app.builder, 'class', newtarget,
94-
node, contnode)
125+
newnode = env.domains['py'].resolve_xref(env, refdoc, app.builder, 'class',
126+
newtarget, node, contnode)
95127
if newnode is not None:
96128
newnode['reftitle'] = reftarget
97129
return newnode

0 commit comments

Comments
 (0)