From db7cf972f8e065edf08cdc4f5b848c8a63378f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Fri, 19 Jul 2024 17:09:19 +0200 Subject: [PATCH] BUG: fix an incoming incompatibility with Python 3.15 (locale.getdefaultlocale is deprecated in Python 3.12) --- CHANGES.rst | 3 +++ ah_bootstrap.py | 24 ++++++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 2953d907f5..6b41451d62 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -136,6 +136,9 @@ Infrastructure, Utility and Other Changes and Additions - Versions of PyVO <1.5 are no longer supported. [#3002] +- Fix an incoming incompatibility with Python 3.15 (`locale.getdefaultlocale` + is deprecated in Python 3.12) [#3070] + utils.tap ^^^^^^^^^ diff --git a/ah_bootstrap.py b/ah_bootstrap.py index e42dccc689..41c9e9b723 100644 --- a/ah_bootstrap.py +++ b/ah_bootstrap.py @@ -838,16 +838,20 @@ def run_cmd(cmd): '`{0}` command:\n{1}'.format(' '.join(cmd), str(e))) - # Can fail of the default locale is not configured properly. See - # https://github.com/astropy/astropy/issues/2749. For the purposes under - # consideration 'latin1' is an acceptable fallback. - try: - stdio_encoding = locale.getdefaultlocale()[1] or 'latin1' - except ValueError: - # Due to an OSX oddity locale.getdefaultlocale() can also crash - # depending on the user's locale/language settings. See: - # https://bugs.python.org/issue18378 - stdio_encoding = 'latin1' + if sys.version_info >= (3, 11): + stdio_encoding = locale.getencoding() + else: + # Can fail of the default locale is not configured properly. See + # https://github.com/astropy/astropy/issues/2749. For the purposes under + # consideration 'latin1' is an acceptable fallback. + try: + stdio_encoding = locale.getdefaultlocale()[1] or 'latin1' + except ValueError: + # Due to an OSX oddity locale.getdefaultlocale() can also crash + # depending on the user's locale/language settings. See: + # https://bugs.python.org/issue18378 + stdio_encoding = 'latin1' + # Unlikely to fail at this point but even then let's be flexible if not isinstance(stdout, str):