77
88from contextlib import contextmanager
99import locale
10+ import platform
1011import re
1112import subprocess
12- from typing import (
13- Callable ,
14- Generator ,
15- )
13+ from typing import Generator
1614
1715from pandas ._config .config import options
1816
@@ -107,15 +105,10 @@ def _valid_locales(locales: list[str] | str, normalize: bool) -> list[str]:
107105 ]
108106
109107
110- def _default_locale_getter () -> bytes :
111- return subprocess .check_output (["locale -a" ], shell = True )
112-
113-
114108def get_locales (
115109 prefix : str | None = None ,
116110 normalize : bool = True ,
117- locale_getter : Callable [[], bytes ] = _default_locale_getter ,
118- ) -> list [str ] | None :
111+ ) -> list [str ]:
119112 """
120113 Get all the locales that are available on the system.
121114
@@ -129,9 +122,6 @@ def get_locales(
129122 Call ``locale.normalize`` on the resulting list of available locales.
130123 If ``True``, only locales that can be set without throwing an
131124 ``Exception`` are returned.
132- locale_getter : callable
133- The function to use to retrieve the current locales. This should return
134- a string with each locale separated by a newline character.
135125
136126 Returns
137127 -------
@@ -141,15 +131,15 @@ def get_locales(
141131
142132 locale.setlocale(locale.LC_ALL, locale_string)
143133
144- On error will return None (no locale available, e.g. Windows)
134+ On error will return an empty list (no locale available, e.g. Windows)
145135
146136 """
147- try :
148- raw_locales = locale_getter ( )
149- except subprocess . CalledProcessError :
150- # Raised on (some? all?) Windows platforms because Note: "locale -a"
151- # is not defined
152- return None
137+ if platform . system () in ( "Linux" , "Darwin" ) :
138+ raw_locales = subprocess . check_output ([ "locale" , "-a" ] )
139+ else :
140+ # Other platforms e.g. windows platforms don't define "locale -a"
141+ # Note: is_platform_windows causes circular import here
142+ return []
153143
154144 try :
155145 # raw_locales is "\n" separated list of locales
0 commit comments