Skip to content
Myr

Merge pull request #2199 from pallets/remove-utf8-check

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

remove utf-8 detection

authored by David Lord · committed by GitHub · parents e7cff2a, 0ccada0 · Browse files · 3 files+3 added−105 removed
This commit

State

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

Diff stats

3 files+3 added−105 removed

  • other:+3 added−105 removed

3 files+3 added−105 removed

deleted:src/click/_unicodefun.py-100 removed
1import codecs2import os3from gettext import gettext as _456def _verify_python_env() -> None:7 """Ensures that the environment is good for Unicode."""8 try:9 from locale import getpreferredencoding1011 fs_enc = codecs.lookup(getpreferredencoding()).name12 except Exception:13 fs_enc = "ascii"1415 if fs_enc != "ascii":16 return1718 extra = [19 _(20 "Click will abort further execution because Python was"21 " configured to use ASCII as encoding for the environment."22 " Consult https://click.palletsprojects.com/unicode-support/"23 " for mitigation steps."24 )25 ]2627 if os.name == "posix":28 import subprocess2930 try:31 rv = subprocess.Popen(32 ["locale", "-a"],33 stdout=subprocess.PIPE,34 stderr=subprocess.PIPE,35 encoding="ascii",36 errors="replace",37 ).communicate()[0]38 except OSError:39 rv = ""4041 good_locales = set()42 has_c_utf8 = False4344 for line in rv.splitlines():45 locale = line.strip()4647 if locale.lower().endswith((".utf-8", ".utf8")):48 good_locales.add(locale)4950 if locale.lower() in ("c.utf8", "c.utf-8"):51 has_c_utf8 = True5253 if not good_locales:54 extra.append(55 _(56 "Additional information: on this system no suitable"57 " UTF-8 locales were discovered. This most likely"58 " requires resolving by reconfiguring the locale"59 " system."60 )61 )62 elif has_c_utf8:63 extra.append(64 _(65 "This system supports the C.UTF-8 locale which is"66 " recommended. You might be able to resolve your"67 " issue by exporting the following environment"68 " variables:"69 )70 )71 extra.append(" export LC_ALL=C.UTF-8\n export LANG=C.UTF-8")72 else:73 extra.append(74 _(75 "This system lists some UTF-8 supporting locales"76 " that you can pick from. The following suitable"77 " locales were discovered: {locales}"78 ).format(locales=", ".join(sorted(good_locales)))79 )8081 bad_locale = None8283 for env_locale in os.environ.get("LC_ALL"), os.environ.get("LANG"):84 if env_locale and env_locale.lower().endswith((".utf-8", ".utf8")):85 bad_locale = env_locale8687 if env_locale is not None:88 break8990 if bad_locale is not None:91 extra.append(92 _(93 "Click discovered that you exported a UTF-8 locale"94 " but the locale system could not pick up from it"95 " because it does not exist. The exported locale is"96 " {locale!r} but it is not supported."97 ).format(locale=bad_locale)98 )99100 raise RuntimeError("\n\n".join(extra))
modified:src/click/core.py-5 removed
12 unmodified lines
13from gettext import ngettext14from itertools import repeat1516from . import types17from ._unicodefun import _verify_python_env17from .exceptions import Abort18from .exceptions import BadParameter19from .exceptions import ClickException20from .exceptions import Exit
1006 unmodified lines
10271028 .. versionchanged:: 3.01029 Added the ``standalone_mode`` parameter.1030 """1032 # Verify that the environment is configured correctly, or reject1033 # further execution to avoid a broken script.1034 _verify_python_env()10351031 if args is None:1032 args = sys.argv[1:]10331034 if os.name == "nt" and windows_expand_args:
1875 unmodified lines
modified:CHANGES.rst+3 added
13 unmodified lines
14 - ``get_terminal_size`` is removed, use15 ``shutil.get_terminal_size`` instead.16 - ``get_os_args`` is removed, use ``sys.argv[1:]`` instead.1718- Rely on :pep:`538` and :pep:`540` to handle selecting a UTF-819 encoding instead of ASCII for misconfigured systems. Click's UTF-820 locale detection is removed. :issue:`2198`21- Single options boolean flags with ``show_default=True`` only show22 the default if it is ``True``. :issue:`1971`2324
950 unmodified lines