Skip to content

Commit 5f35523

Browse files
committed
setup.py: Add codecs and locale hacks
codec and locale hacks have been added to avoid breakages in setup.py Closes #46
1 parent 64e053e commit 5f35523

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

templates/setup.py.jj2

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,30 @@ from platform import python_implementation
2525
{%block compat_block%}
2626
PY2 = sys.version_info[0] == 2
2727
PY26 = PY2 and sys.version_info[1] < 7
28+
PY33 = sys.version_info < (3, 4)
2829
{%endblock%}
2930

31+
# Work around mbcs bug in distutils.
32+
# http://bugs.python.org/issue10945
33+
# This work around is only if a project supports Python < 3.4
34+
{% if PY33 %}
35+
try:
36+
codecs.lookup('mbcs')
37+
except LookupError:
38+
ascii = codecs.lookup('ascii')
39+
func = lambda name, enc=ascii: {True: enc}.get(name=='mbcs')
40+
codecs.register(func)
41+
{% endif %}
42+
43+
# Work around for locale not being set
44+
try:
45+
lc = locale.getlocale()
46+
pf = platform.system()
47+
if pf != 'Windows' and lc == (None, None):
48+
locale.setlocale(locale.LC_ALL, 'C.UTF-8')
49+
except (ValueError, UnicodeError, locale.Error):
50+
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
51+
3052
NAME = '{{name}}'
3153
AUTHOR = '{{author}}'
3254
VERSION = '{{current_version}}'

0 commit comments

Comments
 (0)