From 473ae47bd79d4c954e33f460720f0b1532ff8738 Mon Sep 17 00:00:00 2001 From: Xinglin Qiang Date: Mon, 5 May 2025 00:28:43 +0800 Subject: [PATCH 1/2] Fix different behavior for jupyter vs. terminal When run code in non-English system, jupyter would implicitly set encoding to 'utf-8', explicitly set the encoding here would make the behavior consistent. --- cmdstanpy/utils/command.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmdstanpy/utils/command.py b/cmdstanpy/utils/command.py index ca95983e..afc9d841 100644 --- a/cmdstanpy/utils/command.py +++ b/cmdstanpy/utils/command.py @@ -4,6 +4,7 @@ import os import subprocess import sys +import locale from typing import Callable, List, Optional, TextIO from .filesystem import pushd @@ -47,6 +48,7 @@ def do_command( stderr=subprocess.STDOUT, # avoid buffer overflow env=os.environ, universal_newlines=True, + encoding=locale.getencoding(), ) while proc.poll() is None: if proc.stdout is not None: From 6eb8ec5d67bd3eb48c56d019eafa8e2257b25834 Mon Sep 17 00:00:00 2001 From: Xinglin Qiang Date: Mon, 5 May 2025 10:33:11 +0800 Subject: [PATCH 2/2] python 3.8 backward compatible --- cmdstanpy/utils/command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmdstanpy/utils/command.py b/cmdstanpy/utils/command.py index afc9d841..2bb8cfe9 100644 --- a/cmdstanpy/utils/command.py +++ b/cmdstanpy/utils/command.py @@ -48,7 +48,7 @@ def do_command( stderr=subprocess.STDOUT, # avoid buffer overflow env=os.environ, universal_newlines=True, - encoding=locale.getencoding(), + encoding=locale.getdefaultlocale()[1], ) while proc.poll() is None: if proc.stdout is not None: