Skip to content

Commit

Permalink
do not set locale on windows (#441)
Browse files Browse the repository at this point in the history
  • Loading branch information
randy3k committed Oct 18, 2023
1 parent 27885d8 commit 306158f
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion radian/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .app import get_app, main

__version__ = '0.6.7'
__version__ = '0.6.8'

__all__ = ["get_app", "main"]
8 changes: 1 addition & 7 deletions radian/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions radian/rutils.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
],
Expand Down

0 comments on commit 306158f

Please sign in to comment.