From 6a953613a63a6b687e82cb8ad40773c7d23f5dc0 Mon Sep 17 00:00:00 2001 From: Joey Ballentine <34788790+joeyballentine@users.noreply.github.com> Date: Tue, 23 Apr 2024 15:45:01 -0400 Subject: [PATCH] Manually set python encoding env var in subprocesses (to fix language issue) (#2815) Manually set python encoding env var inn subprocesses --- backend/src/dependencies/store.py | 6 ++++++ backend/src/server_process_helper.py | 3 +++ 2 files changed, 9 insertions(+) diff --git a/backend/src/dependencies/store.py b/backend/src/dependencies/store.py index 7f09337ff..fd1638047 100644 --- a/backend/src/dependencies/store.py +++ b/backend/src/dependencies/store.py @@ -21,6 +21,8 @@ DEP_MAX_PROGRESS = 0.8 +ENV = {**os.environ, "PYTHONIOENCODING": "utf-8"} + @dataclass(frozen=True) class DependencyInfo: @@ -101,6 +103,7 @@ def install_dependencies_sync( "--no-warn-script-location", *extra_index_args, ], + env=ENV, ) if exit_code != 0: raise ValueError("An error occurred while installing dependencies.") @@ -167,6 +170,7 @@ def get_progress_amount(): stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="utf-8", + env=ENV, ) installing_name = "Unknown" while True: @@ -252,6 +256,7 @@ def uninstall_dependencies_sync( *[d.package_name for d in dependencies], "-y", ], + env=ENV, ) if exit_code != 0: raise ValueError("An error occurred while uninstalling dependencies.") @@ -301,6 +306,7 @@ def get_progress_amount(): stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="utf-8", + env=ENV, ) uninstalling_name = "Unknown" while True: diff --git a/backend/src/server_process_helper.py b/backend/src/server_process_helper.py index 0a665c02c..564ae7bbb 100644 --- a/backend/src/server_process_helper.py +++ b/backend/src/server_process_helper.py @@ -30,6 +30,8 @@ def _port_in_use(port: int): SANIC_LOG_REGEX = re.compile(r"^\s*\[[^\[\]]*\] \[\d*\] \[(\w*)\] (.*)") +ENV = {**os.environ, "PYTHONIOENCODING": "utf-8"} + class _WorkerProcess: def __init__(self, flags: list[str]): @@ -43,6 +45,7 @@ def __init__(self, flags: list[str]): stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8", + env=ENV, ) self._stop_event = threading.Event()