Skip to content

Commit 808a80c

Browse files
authored
Merge pull request #60 from Naveenaidu/add_codecs_locale_hacks
setup.py: Add codecs and locale hacks
2 parents 151ec87 + d0f5717 commit 808a80c

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ First release
99

1010
#. versioning is applied
1111
#. Pipfile included
12+
#. codec and locale hacks added

changelog.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ releases:
66
details:
77
- versioning is applied
88
- Pipfile included
9+
- codec and locale hacks added
910
date: 05.11.2018
1011
version: 0.0.1
1112

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)