7
7
8
8
from contextlib import contextmanager
9
9
import locale
10
+ import platform
10
11
import re
11
12
import subprocess
12
- from typing import (
13
- Callable ,
14
- Generator ,
15
- )
13
+ from typing import Generator
16
14
17
15
from pandas ._config .config import options
18
16
@@ -107,15 +105,10 @@ def _valid_locales(locales: list[str] | str, normalize: bool) -> list[str]:
107
105
]
108
106
109
107
110
- def _default_locale_getter () -> bytes :
111
- return subprocess .check_output (["locale -a" ], shell = True )
112
-
113
-
114
108
def get_locales (
115
109
prefix : str | None = None ,
116
110
normalize : bool = True ,
117
- locale_getter : Callable [[], bytes ] = _default_locale_getter ,
118
- ) -> list [str ] | None :
111
+ ) -> list [str ]:
119
112
"""
120
113
Get all the locales that are available on the system.
121
114
@@ -129,9 +122,6 @@ def get_locales(
129
122
Call ``locale.normalize`` on the resulting list of available locales.
130
123
If ``True``, only locales that can be set without throwing an
131
124
``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.
135
125
136
126
Returns
137
127
-------
@@ -141,15 +131,15 @@ def get_locales(
141
131
142
132
locale.setlocale(locale.LC_ALL, locale_string)
143
133
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)
145
135
146
136
"""
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 []
153
143
154
144
try :
155
145
# raw_locales is "\n" separated list of locales
0 commit comments