Skip to content
Myr

Print out supported locales in the python 3 error. This improves #448

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent b465b72 · Browse files · 4 files+8 added−50 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+8 added−50 removed

  • other:+8 added−50 removed

4 files+8 added−50 removed

modified:click/_compat.py-35 removed
3 unmodified lines
4import sys5import codecs6from weakref import WeakKeyDictionary78import click8109PY2 = sys.version_info[0] == 210WIN = sys.platform.startswith('win')11DEFAULT_COLUMNS = 80121314_ansi_re = re.compile('\033\[((?:\d|;)*)([a-zA-Z])')151619def _find_unicode_literals_frame():20 import __future__21 frm = sys._getframe(1)22 idx = 123 while frm is not None:24 if frm.f_globals.get('__name__', '').startswith('click.'):25 frm = frm.f_back26 idx += 127 elif frm.f_code.co_flags & __future__.unicode_literals.compiler_flag:28 return idx29 else:30 break31 return 0323334def _check_for_unicode_literals():35 if not __debug__:36 return37 if not PY2 or click.disable_unicode_literals_warning:38 return39 bad_frame = _find_unicode_literals_frame()40 if bad_frame <= 0:41 return42 from warnings import warn43 warn(Warning('Click detected the use of the unicode_literals '44 '__future__ import. This is heavily discouraged '45 'because it can introduce subtle bugs in your '46 'code. You should instead use explicit u"" literals '47 'for your unicode strings. For more information see '48 'http://click.pocoo.org/python3/'),49 stacklevel=bad_frame)505117def get_filesystem_encoding():18 return sys.getfilesystemencoding() or sys.getdefaultencoding()1920
569 unmodified lines
modified:click/core.py+3 added-14 removed
1import os2import sys3import codecs3from contextlib import contextmanager4from itertools import repeat5from functools import update_wrapper6
5 unmodified lines
12from .formatting import HelpFormatter, join_options13from .parser import OptionParser, split_opt14from .globals import push_context, pop_context1517from ._compat import PY2, isidentifier, iteritems, _check_for_unicode_literals16from ._compat import PY2, isidentifier, iteritems17from ._unicodefun import _check_for_unicode_literals, _verify_python3_env181920_missing = object()21
642 unmodified lines
664 # If we are in Python 3, we will verify that the environment is665 # sane at this point of reject further execution to avoid a666 # broken script.667 if not PY2:668 try:669 import locale670 fs_enc = codecs.lookup(locale.getpreferredencoding()).name671 except Exception:672 fs_enc = 'ascii'673 if fs_enc == 'ascii':674 raise RuntimeError('Click will abort further execution '675 'because Python 3 was configured to use '676 'ASCII as encoding for the environment. '677 'Either switch to Python 2 or consult '678 'http://click.pocoo.org/python3/ '679 'for mitigation steps.')668 _verify_python3_env()669 else:670 _check_for_unicode_literals()671672 if args is None:
1041 unmodified lines
modified:click/decorators.py+2 added-1 removed
1 unmodified line
2import inspect34from functools import update_wrapper56from ._compat import iteritems, _check_for_unicode_literals6from ._compat import iteritems7from ._unicodefun import _check_for_unicode_literals8from .utils import echo9from .globals import get_current_context1011
293 unmodified lines
modified:CHANGES+3 added
14 unmodified lines
15 subcommands works.16- Explicitly disallow nargs=-1 with a set default.17- The context is now closed before it's popped from the stack.18- Added support for short aliases for the false flag on toggles.19- Click will now attempt to aid you with debugging locale errors20 better by listing with the help of the OS what locales are21 available.2223Version 5.124-----------25
251 unmodified lines