Skip to content

Commit

Permalink
[Fix] Read in rb mode then decode (#983)
Browse files Browse the repository at this point in the history
* read in rb mode then decode

* Update config.py

* Update .pre-commit-config.yaml

* Update config.py

* Update config.py

Co-authored-by: Wenwei Zhang <[email protected]>
  • Loading branch information
wangruohui and ZwwWayne authored May 13, 2021
1 parent b1df16a commit 8ee8f69
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions mmcv/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class Config:

@staticmethod
def _validate_py_syntax(filename):
with open(filename, 'r') as f:
with open(filename, 'r', encoding='utf-8') as f:
# Setting encoding explicitly to resolve coding issue on windows
content = f.read()
try:
ast.parse(content)
Expand All @@ -109,7 +110,8 @@ def _substitute_predefined_vars(filename, temp_config_name):
fileBasename=file_basename,
fileBasenameNoExtension=file_basename_no_extension,
fileExtname=file_extname)
with open(filename, 'r') as f:
with open(filename, 'r', encoding='utf-8') as f:
# Setting encoding explicitly to resolve coding issue on windows
config_file = f.read()
for key, value in support_templates.items():
regexp = r'\{\{\s*' + str(key) + r'\s*\}\}'
Expand Down Expand Up @@ -159,7 +161,8 @@ def _file2dict(filename, use_predefined_variables=True):
temp_config_file.close()

cfg_text = filename + '\n'
with open(filename, 'r') as f:
with open(filename, 'r', encoding='utf-8') as f:
# Setting encoding explicitly to resolve coding issue on windows
cfg_text += f.read()

if BASE_KEY in cfg_dict:
Expand Down

0 comments on commit 8ee8f69

Please sign in to comment.