update_model_index.py support windows
import glob
import os
-import os.path as osp
+import posixpath as osp # Even on windows, use posixpath
import re
import sys
import warnings
@@ -35,7 +35,9 @@ def dump_yaml_and_check_difference(obj, file):
Bool: If the target YAML file is different from the original.
"""
- str_dump = mmcv.dump(obj, None, file_format='yaml', sort_keys=True)
+ str_dump = mmcv.dump(
+ obj, None, file_format='yaml', sort_keys=True,
+ line_break='\n') # force use LF
if osp.isfile(file):
file_exists = True
@@ -141,7 +143,8 @@ def parse_md(md_file):
README=osp.relpath(md_file, MMEditing_ROOT),
Paper=[])
models = []
- with open(md_file, 'r') as md:
+ # force utf-8 instead of system defined
+ with open(md_file, 'r', encoding='utf-8') as md:
lines = md.readlines()
i = 0
name = lines[0][2:]
@@ -276,8 +279,11 @@ def update_model_index():
yml_files.sort()
model_index = {
- 'Import':
- [osp.relpath(yml_file, MMEditing_ROOT) for yml_file in yml_files]
+ 'Import': [
+ osp.relpath(yml_file, MMEditing_ROOT).replace(
+ '\\', '/') # force using / as path separators
+ for yml_file in yml_files
+ ]
}
model_index_file = osp.join(MMEditing_ROOT, 'model-index.yml')
is_different = dump_yaml_and_check_difference(model_index,
