Revised with mgorny's suggestions.

Index: distutils-r1.eclass
===================================================================
RCS file: /var/cvsroot/gentoo-x86/eclass/distutils-r1.eclass,v
retrieving revision 1.98
diff -u -r1.98 distutils-r1.eclass
--- distutils-r1.eclass 21 Jun 2014 08:14:18 -0000      1.98
+++ distutils-r1.eclass 22 Jun 2014 14:50:08 -0000
@@ -684,6 +684,8 @@
 }
 
 distutils-r1_src_configure() {
+       python_export_utf8_locale
+
        if declare -f python_configure >/dev/null; then
                _distutils-r1_run_foreach_impl python_configure
        fi
Index: python-utils-r1.eclass
===================================================================
RCS file: /var/cvsroot/gentoo-x86/eclass/python-utils-r1.eclass,v
retrieving revision 1.58
diff -u -r1.58 python-utils-r1.eclass
--- python-utils-r1.eclass      19 Jun 2014 15:10:55 -0000      1.58
+++ python-utils-r1.eclass      22 Jun 2014 14:50:08 -0000
@@ -1110,5 +1110,40 @@
        fi
 }
 
+# @FUNCTION: python_export_utf8_locale
+# @RETURN: 0 on success, 1 on failure.
+# @DESCRIPTION:
+# Attempts to export a usable UTF-8 locale in the LC_CTYPE variable. Does
+# nothing if LC_ALL is defined, or if the current locale uses a UTF-8 charmap.
+# This may be used to work around the quirky open() behavior of python3.
+python_export_utf8_locale() {
+       debug-print-function ${FUNCNAME} "${@}"
+
+       if [[ $(locale charmap) != UTF-8 ]]; then
+               if [[ -n ${LC_ALL} ]]; then
+                       ewarn "LC_ALL is set to a locale with a charmap other 
than UTF-8."
+                       ewarn "This may trigger build failures in some python 
packages."
+                       return 1
+               fi
+
+               # Try English first, then everything else.
+               local lang locales="en_US.UTF-8 $(locale -a)"
+
+               for lang in ${locales}; do
+                       if [[ $(LC_CTYPE=${lang} locale charmap 2>/dev/null) == 
UTF-8 ]]; then
+                               export LC_CTYPE=${lang}
+                               return 0
+                       fi  
+               done
+
+               ewarn "Could not find a UTF-8 locale. This may trigger build 
failures in"
+               ewarn "some python packages. Please ensure that a UTF-8 locale 
is listed in"
+               ewarn "/etc/locale.gen and run locale-gen."
+               return 1
+       fi  
+
+       return 0
+}
+
 _PYTHON_UTILS_R1=1
 fi

Reply via email to