Unverified Commit eb08835f authored by fjfzlzj's avatar fjfzlzj Committed by GitHub
Browse files

[Fix] Fix the permission denied error on windows. (#1077)



* Fix the permission denied error on windows.

* Format code.

* Using a cleaner way.

* Update config.py

use os.unlink instead of unlink

* change  unlink to remove

* add notes for new implementation

* Fix typo
Co-authored-by: default avatarWRH <12756472+wangruohui@users.noreply.github.com>
Co-authored-by: default avatarWenwei Zhang <40779233+ZwwWayne@users.noreply.github.com>
parent 560719da
# Copyright (c) Open-MMLab. All rights reserved. # Copyright (c) Open-MMLab. All rights reserved.
import ast import ast
import os
import os.path as osp import os.path as osp
import platform import platform
import shutil import shutil
...@@ -275,11 +276,13 @@ class Config: ...@@ -275,11 +276,13 @@ class Config:
# check if users specify a wrong suffix for python # check if users specify a wrong suffix for python
warnings.warn( warnings.warn(
'Please check "file_format", the file format may be .py') 'Please check "file_format", the file format may be .py')
with tempfile.NamedTemporaryFile(
with tempfile.NamedTemporaryFile('w', suffix=file_format) as temp_file: 'w', suffix=file_format, delete=False) as temp_file:
temp_file.write(cfg_str) temp_file.write(cfg_str)
temp_file.flush() # on windows, previous implementation cause error
cfg = Config.fromfile(temp_file.name) # see PR 1077 for details
cfg = Config.fromfile(temp_file.name)
os.remove(temp_file.name)
return cfg return cfg
@staticmethod @staticmethod
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment