From 578b3ba4f4f18ceaa9a23e0cc0eadfb4d99a6a99 Mon Sep 17 00:00:00 2001 From: Marc-Andre Ferland Date: Mon, 17 Oct 2022 23:15:36 -0400 Subject: [PATCH] Force encoding to utf-8 on text file operations Fixes #332 # Conflicts: # ui/server.py --- ui/sd_internal/runtime.py | 2 +- ui/server.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ui/sd_internal/runtime.py b/ui/sd_internal/runtime.py index bb15e588..7b56a3fd 100644 --- a/ui/sd_internal/runtime.py +++ b/ui/sd_internal/runtime.py @@ -616,7 +616,7 @@ Negative Prompt: {req.negative_prompt} Stable Diffusion model: {req.use_stable_diffusion_model + '.ckpt'} ''' try: - with open(meta_out_path, 'w') as f: + with open(meta_out_path, 'w', encoding='utf-8') as f: f.write(metadata) except: print('could not save the file', traceback.format_exc()) diff --git a/ui/server.py b/ui/server.py index 96a49737..42ae3512 100644 --- a/ui/server.py +++ b/ui/server.py @@ -60,7 +60,7 @@ def getConfig(default_val=APP_CONFIG_DEFAULTS): mtime = os.path.getmtime(config_json_path) if mtime <= config_last_mod_time: return config_cached - with open(config_json_path, 'r') as f: + with open(config_json_path, 'r', encoding='utf-8') as f: config_cached = json.load(f) config_last_mod_time = os.path.getmtime(config_json_path) return config_cached @@ -72,7 +72,7 @@ def getConfig(default_val=APP_CONFIG_DEFAULTS): def setConfig(config): try: # config.json config_json_path = os.path.join(CONFIG_DIR, 'config.json') - with open(config_json_path, 'w') as f: + with open(config_json_path, 'w', encoding='utf-8') as f: return json.dump(config, f) except: print(traceback.format_exc()) @@ -100,7 +100,7 @@ def setConfig(config): config_bat.append(f"::@set CUDA_VISIBLE_DEVICES={','.join(gpu_devices)}") # Needs better detection for edge cases, add as a comment for now. print('Add the line "@set CUDA_VISIBLE_DEVICES=N" where N is the GPUs to use to config.bat') config_bat_path = os.path.join(CONFIG_DIR, 'config.bat') - with open(config_bat_path, 'w') as f: + with open(config_bat_path, 'w', encoding='utf-8') as f: f.write(f.write('\r\n'.join(config_bat))) except Exception as e: print(traceback.format_exc()) @@ -115,7 +115,7 @@ def setConfig(config): config_sh.append(f"#CUDA_VISIBLE_DEVICES={','.join(gpu_devices)}") # Needs better detection for edge cases, add as a comment for now. print('Add the line "CUDA_VISIBLE_DEVICES=N" where N is the GPUs to use to config.sh') config_sh_path = os.path.join(CONFIG_DIR, 'config.sh') - with open(config_sh_path, 'w') as f: + with open(config_sh_path, 'w', encoding='utf-8') as f: f.write('\n'.join(config_sh)) except Exception as e: print(traceback.format_exc())