Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Read in rb mode then decode #983

Merged
merged 5 commits into from
May 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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