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

Commit

Permalink
Merge pull request #79 from docascode/yitian/fix-24421
Browse files Browse the repository at this point in the history
Fix bug of yaml file conflict caused by Windows' case-insensitive file system.
  • Loading branch information
killa1218 committed Aug 27, 2018
2 parents 1f9749c + aa345a5 commit cc864b3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
31 changes: 23 additions & 8 deletions docfx_yaml/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,15 @@ def convert_module_to_package_if_needed(obj):
ensuredir(normalized_outdir)

toc_yaml = []
# Used to record filenames dumped to avoid confliction
# caused by Windows case insenstive file system
file_name_set = set()

# Order matters here, we need modules before lower level classes,
# so that we can make sure to inject the TOC properly
for data_set in (app.env.docfx_yaml_modules, app.env.docfx_yaml_classes): # noqa
for filename, yaml_data in iter(sorted(data_set.items())):
if not filename:
for uid, yaml_data in iter(sorted(data_set.items())):
if not uid:
# Skip objects without a module
continue

Expand All @@ -513,7 +516,10 @@ def convert_module_to_package_if_needed(obj):
# Support having `self` as an arg param, but not documented
arg_params = arg_params[1:]
obj['syntax']['parameters'] = arg_params
if obj['uid'] in app.env.docfx_info_field_data:
if obj['uid'] in app.env.docfx_info_field_data and \
obj['type'] == app.env.docfx_info_field_data[obj['uid']]['type']:
# Avoid entities with same uid and diff type.
del(app.env.docfx_info_field_data[obj['uid']]['type']) # Delete `type` temporarily
if 'syntax' not in obj:
obj['syntax'] = {}
merged_params = []
Expand Down Expand Up @@ -574,6 +580,7 @@ def convert_module_to_package_if_needed(obj):
# Get parent for attrData of enum class
parent = attrData['parent']
obj['references'].append(_create_reference(attrData, parent))
app.env.docfx_info_field_data[obj['uid']]['type'] = obj['type'] # Revert `type` for other objects to use

if 'references' in obj:
# Ensure that references have no duplicate ref
Expand All @@ -599,10 +606,16 @@ def convert_module_to_package_if_needed(obj):
pass

# Output file
if uid.lower() in file_name_set:
filename = uid + "(%s)" % app.env.docfx_info_uid_types[uid]
else:
filename = uid

out_file = os.path.join(normalized_outdir, '%s.yml' % filename)
ensuredir(os.path.dirname(out_file))
if app.verbosity >= 1:
app.info(bold('[docfx_yaml] ') + darkgreen('Outputting %s' % filename))

with open(out_file, 'w') as out_file_obj:
out_file_obj.write('### YamlMime:UniversalReference\n')
dump(
Expand All @@ -615,18 +628,20 @@ def convert_module_to_package_if_needed(obj):
default_flow_style=False
)

file_name_set.add(filename)

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

if found_node:
found_node.setdefault('items', []).append({'name': filename, 'uid': filename})
found_node.setdefault('items', []).append({'name': uid, 'uid': uid})
else:
toc_yaml.append({'name': filename, 'uid': filename})
toc_yaml.append({'name': uid, 'uid': uid})

else:
toc_yaml.append({'name': filename, 'uid': filename})
toc_yaml.append({'name': uid, 'uid': uid})

toc_file = os.path.join(normalized_outdir, 'toc.yml')
with open(toc_file, 'w') as writable:
Expand Down
1 change: 1 addition & 0 deletions docfx_yaml/monkeypatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ def transform_all(self, node):
for key, val in data.copy().items():
if not val:
del data[key]
data['type'] = node.parent["desctype"] if "desctype" in node.parent else 'unknown'
self.directive.env.docfx_info_field_data[uid] = data
super(PatchedDocFieldTransformer, self).transform_all(node)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

setup(
name='sphinx-docfx-yaml',
version='1.2.42',
version='1.2.43',
author='Eric Holscher',
author_email='eric@ericholscher.com',
url='https://github.com/ericholscher/sphinx-docfx-yaml',
Expand Down

0 comments on commit cc864b3

Please sign in to comment.