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
Provenance
- Commit
cf31c15- Tree
19ec128- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
b465b72
4 files changed+8 added−50 removed
modified:click/_compat.py-35 removed
3 unmodified lines4 import sys5 import codecs6 from weakref import WeakKeyDictionary7 8-import click8 10-9 PY2 = sys.version_info[0] == 210 WIN = sys.platform.startswith('win')11 DEFAULT_COLUMNS = 8012 13 14 _ansi_re = re.compile('\033\[((?:\d|;)*)([a-zA-Z])')15 16 19-def _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 032-33-34-def _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)50-51-17 def get_filesystem_encoding():18 return sys.getfilesystemencoding() or sys.getdefaultencoding()19 20 569 unmodified linesmodified:click/core.py+3 added-14 removed
1 import os2 import sys3-import codecs3 from contextlib import contextmanager4 from itertools import repeat5 from functools import update_wrapper6 5 unmodified lines12 from .formatting import HelpFormatter, join_options13 from .parser import OptionParser, split_opt14 from .globals import push_context, pop_context15 17-from ._compat import PY2, isidentifier, iteritems, _check_for_unicode_literals16+from ._compat import PY2, isidentifier, iteritems17+from ._unicodefun import _check_for_unicode_literals, _verify_python3_env18 19 20 _missing = object()21 642 unmodified lines664 # 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()671 672 if args is None:1041 unmodified linesmodified:click/decorators.py+2 added-1 removed
1 unmodified line2 import inspect3 4 from functools import update_wrapper5 6-from ._compat import iteritems, _check_for_unicode_literals6+from ._compat import iteritems7+from ._unicodefun import _check_for_unicode_literals8 from .utils import echo9 from .globals import get_current_context10 11 293 unmodified linesmodified:CHANGES+3 added
14 unmodified lines15 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.22 23 Version 5.124 -----------25 251 unmodified lines