fix: encoding

This commit is contained in:
Florian Hönicke
2023-04-22 23:14:28 +02:00
parent 1815bb595e
commit dec8fbdc7a
7 changed files with 14 additions and 13 deletions

View File

@@ -1,4 +1,3 @@
from src import env # noqa: F401 to make sure certain environment variables are set
from src import main from src import main
if __name__ == "__main__": if __name__ == "__main__":

View File

@@ -249,7 +249,7 @@ executors:
''' '''
full_flow_path = os.path.join(dest_folder, full_flow_path = os.path.join(dest_folder,
'flow.yml') 'flow.yml')
with open(full_flow_path, 'w') as f: with open(full_flow_path, 'w', encoding='utf-8') as f:
f.write(flow) f.write(flow)
return full_flow_path return full_flow_path
@@ -264,12 +264,12 @@ def replace_client_line(file_content: str, replacement: str) -> str:
def update_client_line_in_file(file_path, host): def update_client_line_in_file(file_path, host):
with open(file_path, 'r') as file: with open(file_path, 'r', encoding='utf-8') as file:
content = file.read() content = file.read()
replaced_content = replace_client_line(content, f"client = Client(host='{host}')") replaced_content = replace_client_line(content, f"client = Client(host='{host}')")
with open(file_path, 'w') as file: with open(file_path, 'w', encoding='utf-8') as file:
file.write(replaced_content) file.write(replaced_content)

View File

@@ -1,3 +1,4 @@
from src import env # noqa: F401 to make sure certain environment variables are set
import functools import functools
import os import os

View File

@@ -1,3 +1,4 @@
import os import os
os.environ['PYTHONIOENCODING'] = 'utf-8' os.environ['PYTHONIOENCODING'] = 'utf-8'
os.environ['PYTHONLEGACYWINDOWSSTDIO'] = 'utf-8'

View File

@@ -65,7 +65,7 @@ def set_env_variable(shell, key):
config_file = os.path.expanduser(shell_config[shell]["config_file"]) config_file = os.path.expanduser(shell_config[shell]["config_file"])
try: try:
with open(config_file, "r") as file: with open(config_file, "r", encoding='utf-8') as file:
content = file.read() content = file.read()
export_line = shell_config[shell]['export_line'] export_line = shell_config[shell]['export_line']
@@ -74,10 +74,10 @@ def set_env_variable(shell, key):
if f"OPENAI_API_KEY" in content: if f"OPENAI_API_KEY" in content:
content = re.sub(r'OPENAI_API_KEY=.*', f'OPENAI_API_KEY={key}', content, flags=re.MULTILINE) content = re.sub(r'OPENAI_API_KEY=.*', f'OPENAI_API_KEY={key}', content, flags=re.MULTILINE)
with open(config_file, "w") as file: with open(config_file, "w", encoding='utf-8') as file:
file.write(content) file.write(content)
else: else:
with open(config_file, "a") as file: with open(config_file, "a", encoding='utf-8') as file:
file.write(f"\n{export_line}\n") file.write(f"\n{export_line}\n")
click.echo(f''' click.echo(f'''
@@ -130,7 +130,7 @@ def is_key_set_in_config_file(key):
config_file = os.path.expanduser(shell_config[shell]["config_file"]) config_file = os.path.expanduser(shell_config[shell]["config_file"])
try: try:
with open(config_file, "r") as file: with open(config_file, "r", encoding='utf-8') as file:
content = file.read() content = file.read()
if f"OPENAI_API_KEY" in content: if f"OPENAI_API_KEY" in content:
return True return True

View File

@@ -45,7 +45,7 @@ py_modules:
metas: metas:
name: {class_name} name: {class_name}
''' '''
with open(os.path.join(dest_folder, 'config.yml'), 'w') as f: with open(os.path.join(dest_folder, 'config.yml'), 'w', encoding='utf-8') as f:
f.write(config_content) f.write(config_content)
def files_to_string(self, file_name_to_content, restrict_keys=None): def files_to_string(self, file_name_to_content, restrict_keys=None):
@@ -175,13 +175,13 @@ metas:
# fill-in name of microservice # fill-in name of microservice
gateway_name = f'Gateway{microservice_name}' gateway_name = f'Gateway{microservice_name}'
custom_gateway_path = os.path.join(gateway_path, 'custom_gateway.py') custom_gateway_path = os.path.join(gateway_path, 'custom_gateway.py')
with open(custom_gateway_path, 'r') as f: with open(custom_gateway_path, 'r', encoding='utf-8') as f:
custom_gateway_content = f.read() custom_gateway_content = f.read()
custom_gateway_content = custom_gateway_content.replace( custom_gateway_content = custom_gateway_content.replace(
'class CustomGateway(CompositeGateway):', 'class CustomGateway(CompositeGateway):',
f'class {gateway_name}(CompositeGateway):' f'class {gateway_name}(CompositeGateway):'
) )
with open(custom_gateway_path, 'w') as f: with open(custom_gateway_path, 'w', encoding='utf-8') as f:
f.write(custom_gateway_content) f.write(custom_gateway_content)
# write config.yml # write config.yml

View File

@@ -14,7 +14,7 @@ def get_microservice_path(path, microservice_name, packages, num_approach, versi
return os.path.join(path, microservice_name, f'{num_approach}_{package_path}', f'v{version}') return os.path.join(path, microservice_name, f'{num_approach}_{package_path}', f'v{version}')
def persist_file(file_content, file_path): def persist_file(file_content, file_path):
with open(file_path, 'w') as f: with open(file_path, 'w', encoding='utf-8') as f:
f.write(file_content) f.write(file_content)