remove utf-8 detection
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent e7cff2a · 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
Provenance
- Commit
0ccada0- Tree
495f98f- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
e7cff2a
3 files changed+3 added−105 removed
deleted:src/click/_unicodefun.py-100 removed
1-import codecs2-import os3-from gettext import gettext as _4-5-6-def _verify_python_env() -> None:7- """Ensures that the environment is good for Unicode."""8- try:9- from locale import getpreferredencoding10-11- fs_enc = codecs.lookup(getpreferredencoding()).name12- except Exception:13- fs_enc = "ascii"14-15- if fs_enc != "ascii":16- return17-18- 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- ]26-27- if os.name == "posix":28- import subprocess29-30- 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 = ""40-41- good_locales = set()42- has_c_utf8 = False43-44- for line in rv.splitlines():45- locale = line.strip()46-47- if locale.lower().endswith((".utf-8", ".utf8")):48- good_locales.add(locale)49-50- if locale.lower() in ("c.utf8", "c.utf-8"):51- has_c_utf8 = True52-53- 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- )80-81- bad_locale = None82-83- 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_locale86-87- if env_locale is not None:88- break89-90- 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- )99-100- raise RuntimeError("\n\n".join(extra))modified:src/click/core.py-5 removed
12 unmodified lines13 from gettext import ngettext14 from itertools import repeat15 16 from . import types17-from ._unicodefun import _verify_python_env17 from .exceptions import Abort18 from .exceptions import BadParameter19 from .exceptions import ClickException20 from .exceptions import Exit1006 unmodified lines1027 1028 .. 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()1035-1031 if args is None:1032 args = sys.argv[1:]1033 1034 if os.name == "nt" and windows_expand_args:1875 unmodified linesmodified:CHANGES.rst+3 added
13 unmodified lines14 - ``get_terminal_size`` is removed, use15 ``shutil.get_terminal_size`` instead.16 - ``get_os_args`` is removed, use ``sys.argv[1:]`` instead.17 18+- 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`23 24 950 unmodified lines