Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Commit

Permalink
Fix Bug: fix the bug of lack of ids when docstring contains attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
killa1218 committed Apr 23, 2018
1 parent 864f3d6 commit 57accfa
Showing 1 changed file with 55 additions and 34 deletions.
89 changes: 55 additions & 34 deletions docfx_yaml/monkeypatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,48 +318,69 @@ def transform_all(self, node):
for child in node:
if isinstance(child, addnodes.desc):
if child.get('desctype') == 'attribute':
attribute_map = {} # Used for detecting duplicated attributes in intermediate data and merge them

for item in child:
if isinstance(item, desc_signature) and any(isinstance(n, addnodes.desc_annotation) for n in item):
# capture attributes data and cache it
data.setdefault('added_attribute', [])

item_ids = item.get('ids', [''])
curuid = item_ids[0] if len(item_ids) > 0 else ''
parent = curuid[:curuid.rfind('.')]
name = item.children[0].astext()

if _is_desc_of_enum_class(node):
addedData = {
'uid': curuid,
'id': name,
'parent': parent,
'langs': ['python'],
'name': name,
'fullName': curuid,
'type': item.parent.get('desctype'),
'module': item.get('module'),
'syntax': {
'content': item.astext(),
'return': {
'type': [parent]

if len(item_ids) == 0: # find a node with no 'ids' attribute
curuid = item.get('module', '') + '.' + item.get('fullname', '')
# generate its uid by module and fullname
else:
curuid = item_ids[0]

if len(curuid) > 0:
parent = curuid[:curuid.rfind('.')]
name = item.children[0].astext()

if curuid in attribute_map:
if len(item_ids) == 0: # ensure the order of docstring attributes and real attributes is fixed
attribute_map[curuid]['syntax']['content'] += (' ' + item.astext())
# concat the description of duplicated nodes
else:
attribute_map[curuid]['syntax']['content'] = item.astext() + ' ' + attribute_map[curuid]['syntax']['content']
else:
if _is_desc_of_enum_class(node):
addedData = {
'uid': curuid,
'id': name,
'parent': parent,
'langs': ['python'],
'name': name,
'fullName': curuid,
'type': item.parent.get('desctype'),
'module': item.get('module'),
'syntax': {
'content': item.astext(),
'return': {
'type': [parent]
}
}
}
}
}
else:
addedData = {
'uid': curuid,
'class': parent,
'langs': ['python'],
'name': name,
'fullName': curuid,
'type': 'attribute',
'module': item.get('module'),
'syntax': {
'content': item.astext()
}
}

attribute_map[curuid] = addedData
else:
addedData = {
'uid': curuid,
'class': parent,
'langs': ['python'],
'name': name,
'fullName': curuid,
'type': 'attribute',
'module': item.get('module'),
'syntax': {
'content': item.astext()
}
}

data['added_attribute'].append(addedData) # Add attributes data to a temp list
raise Exception('ids of node: ' + repr(item) + ' is missing.')
# no ids and no duplicate or uid can not be generated.
if 'added_attribute' in data:
data['added_attribute'].extend(attribute_map.values()) # Add attributes data to a temp list

# Don't recurse into child nodes
continue
Expand Down

0 comments on commit 57accfa

Please sign in to comment.