Skip to content

Commit

Permalink
fix: use the uid for toc entries (#104)
Browse files Browse the repository at this point in the history
* fix: use the uid when applicalbe for toc entries

* test: use latest build for Kokoro

* test: revert kokoro setting

* test: update test case

* fix: remove check_name_with_uid function

* chore: lint update
  • Loading branch information
dandhlee authored Aug 24, 2021
1 parent 878f1c3 commit 1364dfc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
33 changes: 10 additions & 23 deletions docfx_yaml/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,52 +1272,39 @@ def convert_module_to_package_if_needed(obj):
del(obj['source'])

yaml_map[uid] = [yaml_data, references]

# Parse the name of the object.
# Some types will need additional parsing to de-duplicate their names and contain
# a portion of their parent name for better disambiguation. This is done in
# a portion of their parent name for better disambiguation. This is done in
# disambiguate_toc_name
node_name = obj.get('class').split(".")[-1] if obj.get('class') else obj['name']

node_name = uid.split(".")[-1]

# Build nested TOC
if uid.count('.') >= 1:
parent_level = '.'.join(uid.split('.')[:-1])
found_node = find_node_in_toc_tree(pkg_toc_yaml, parent_level)

if found_node:
found_node.pop('uid', 'No uid found')
found_node.setdefault(
'items',
'items',
[{'name': 'Overview', 'uidname': parent_level, 'uid': parent_level}]
).append({
'name': node_name,
'uidname': uid,
'uidname': uid,
'uid': uid
})
else:
# Extract the file name to use for new entries into the TOC
# to make TOC entries consistent with filenames.
file_name = obj['source']['path']
# `inspect.getfile() cannot retrieve file path for some
# types. Try to retrieve the file path from its class
# parent, otherwise simply use node_name.
if not file_name:
file_name = app.env.docfx_class_paths.get(obj.get("class"))
try:
file_name = obj['source']['path'].split("/")[-1][:-3]
except AttributeError:
file_name = node_name
pkg_toc_yaml.append({
'name': file_name,
'uidname': uid,
'name': node_name,
'uidname': uid,
'uid': uid
})

else:
pkg_toc_yaml.append({
'name': node_name,
'uidname': uid,
'name': node_name,
'uidname': uid,
'uid': uid
})

Expand Down
2 changes: 1 addition & 1 deletion tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TestGenerate(unittest.TestCase):
def test_find_unique_name(self):

entries = {}

# Disambiguate with unique entries.
entry1 = "google.cloud.aiplatform.v1.schema.predict.instance_v1.types"
entry2 = "google.cloud.aiplatform.v1beta2.schema.predict.instance_v1.types"
Expand Down

0 comments on commit 1364dfc

Please sign in to comment.