Skip to content

Commit

Permalink
Manually set python encoding env var in subprocesses (to fix language…
Browse files Browse the repository at this point in the history
… issue) (#2815)

Manually set python encoding env var inn subprocesses
  • Loading branch information
joeyballentine authored Apr 23, 2024
1 parent 980f4d2 commit 6a95361
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions backend/src/dependencies/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

DEP_MAX_PROGRESS = 0.8

ENV = {**os.environ, "PYTHONIOENCODING": "utf-8"}


@dataclass(frozen=True)
class DependencyInfo:
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -167,6 +170,7 @@ def get_progress_amount():
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
encoding="utf-8",
env=ENV,
)
installing_name = "Unknown"
while True:
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -301,6 +306,7 @@ def get_progress_amount():
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
encoding="utf-8",
env=ENV,
)
uninstalling_name = "Unknown"
while True:
Expand Down
3 changes: 3 additions & 0 deletions backend/src/server_process_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
Expand All @@ -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()

Expand Down

0 comments on commit 6a95361

Please sign in to comment.