Skip to content

Commit

Permalink
Fix random behavior of update_model_index in pre-commit hook (#784)
Browse files Browse the repository at this point in the history
  • Loading branch information
Junjun2016 authored Aug 15, 2021
1 parent 2acd563 commit 6eff941
Show file tree
Hide file tree
Showing 32 changed files with 2,258 additions and 2,251 deletions.
28 changes: 17 additions & 11 deletions .dev/md2yml.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,23 @@ def dump_yaml_and_check_difference(obj, filename):
Returns:
Bool: If the target YAML file is different from the original.
"""
original = None

str_dump = mmcv.dump(obj, None, file_format='yaml', sort_keys=True)
if osp.isfile(filename):
file_exists = True
with open(filename, 'r', encoding='utf-8') as f:
original = f.read()
with open(filename, 'w', encoding='utf-8') as f:
mmcv.dump(obj, f, file_format='yaml', sort_keys=False)
is_different = True
if original is not None:
with open(filename, 'r') as f:
new = f.read()
is_different = (original != new)
str_orig = f.read()
else:
file_exists = False
str_orig = None

if file_exists and str_orig == str_dump:
is_different = False
else:
is_different = True
with open(filename, 'w', encoding='utf-8') as f:
f.write(str_dump)

return is_different


Expand Down Expand Up @@ -183,11 +189,11 @@ def update_model_index():
if __name__ == '__main__':
file_list = [fn for fn in sys.argv[1:] if osp.basename(fn) == 'README.md']
if not file_list:
exit(0)
sys.exit(0)
file_modified = False
for fn in file_list:
file_modified |= parse_md(fn)

file_modified |= update_model_index()

exit(1 if file_modified else 0)
sys.exit(1 if file_modified else 0)
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ repos:
additional_dependencies: [mmcv]
language: python
files: ^configs/.*\.md$
require_serial: true
Loading

0 comments on commit 6eff941

Please sign in to comment.