From 306158fc814194b3fea427fc39d979f8f41d5040 Mon Sep 17 00:00:00 2001 From: Randy Lai Date: Tue, 17 Oct 2023 23:26:00 -0700 Subject: [PATCH] do not set locale on windows (#441) --- README.md | 2 +- radian/__init__.py | 2 +- radian/app.py | 8 +------- radian/rutils.py | 9 ++++----- setup.py | 2 +- 5 files changed, 8 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index e1085bb..cd16d00 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ options( #### Unicode doesn't work in Windows and R 4.2+. -The latest version of R supports Unicode codepage directly. However, radian relies on Python and Python doesn't support Unicode in the way that R supports it. A workaround could be found here: https://github.com/randy3k/radian/issues/269#issuecomment-1169663251 +The latest version of R supports Unicode codepage directly. However, radian relies on Python and Python doesn't support Unicode in the way that R supports it. A workaround could be found here: https://github.com/randy3k/radian/issues/269#issuecomment-1169663251. Though it may break the ploting device (running `plot()` will kill radian). #### I can't specify python runtime in reticulate. diff --git a/radian/__init__.py b/radian/__init__.py index b3354fa..f1f4103 100644 --- a/radian/__init__.py +++ b/radian/__init__.py @@ -1,5 +1,5 @@ from .app import get_app, main -__version__ = '0.6.7' +__version__ = '0.6.8' __all__ = ["get_app", "main"] diff --git a/radian/app.py b/radian/app.py index 1da7937..e33c672 100644 --- a/radian/app.py +++ b/radian/app.py @@ -215,16 +215,10 @@ def run(self, options, cleanup=None): # enable signal handlers os.environ["RCHITECT_REGISTER_SIGNAL_HANDLERS"] = "1" - if sys.platform.startswith("win"): - # avoid "using locale code page other than 1252 may cause problems" warning - lc_ctype = os.environ.pop('LC_CTYPE', "en_US.UTF-8") - else: - lc_ctype = None - rchitect.init(args=args, register_signal_handlers=True) if sys.platform.startswith("win"): - rutils.set_locale(lc_ctype = lc_ctype) + rutils.set_utf8() try: rutils.source_radian_profile(options.profile) diff --git a/radian/rutils.py b/radian/rutils.py index 95b05a0..d1da87b 100644 --- a/radian/rutils.py +++ b/radian/rutils.py @@ -1,7 +1,7 @@ import os import sys from rchitect import rcopy, reval, rcall -from rchitect.interface import roption +from rchitect.interface import roption, setoption from .key_bindings import map_key def is_ascii(str): @@ -96,15 +96,14 @@ def register_cleanup(cleanup): onexit=True) -def set_locale(lc_ctype): +def set_utf8(): if sys.platform.startswith("win"): ucrt = rcopy( reval('compareVersion(paste0(R.version$major, ".", R.version$minor), "4.2.0") >= 0')) if ucrt: if not os.environ.get("LANG", ""): - os.environ["LANG"] = "en_US.UTF-8" - if lc_ctype: - reval("suppressWarnings(Sys.setlocale(locale = '{}'))".format(lc_ctype)) + os.environ["LANG"] = "en_US.UTF-8" + setoption("encoding", "UTF-8") def run_on_load_hooks(): diff --git a/setup.py b/setup.py index c2f52c4..ccab43c 100644 --- a/setup.py +++ b/setup.py @@ -43,7 +43,7 @@ def get_version(package): python_requires='>=3.6', install_requires=[ # 'rchitect@git+https://github.com/randy3k/rchitect', - 'rchitect>=0.4.1,<0.5.0', + 'rchitect>=0.4.3,<0.5.0', 'prompt_toolkit>=3.0.15,<3.1', 'pygments>=2.5.0' ],