Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update patch_click #133

Merged
merged 3 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions curlylint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def main(

def patch_click() -> None:
"""Borrowed from black.
https://github.com/psf/black/blob/959848c17639bfc646128f6b582c5858164a5001/black.py
https://github.com/psf/black/blob/e9681a40dcb3d38b56b301d811bb1c55201fd97e/src/black/__init__.py#L1419-L1448
Make Click not crash.
On certain misconfigured environments, Python 3 selects the ASCII encoding as the
default which restricts paths that it can access during the lifetime of the
Expand All @@ -286,20 +286,30 @@ def patch_click() -> None:
file paths is minimal since it's Python source code. Moreover, this crash was
spurious on Python 3.7 thanks to PEP 538 and PEP 540.
"""
modules: List[Any] = []
try:
from click import core
from click import _unicodefun
except ModuleNotFoundError:
return
except ImportError:
pass
else:
modules.append(core)
try:
from click import _unicodefun # type: ignore [attr-defined]
except ImportError:
pass
else:
modules.append(_unicodefun)

for module in (core, _unicodefun):
for module in modules:
if hasattr(module, "_verify_python3_env"):
module._verify_python3_env = lambda: None # type: ignore [attr-defined]
module._verify_python3_env = lambda: None
if hasattr(module, "_verify_python_env"):
module._verify_python_env = lambda: None


def patched_main() -> None:
patch_click()
main()
main() # type: ignore [misc]


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
black==22.1.0
black==22.3.0
flake8==4.0.1
mypy==0.812
pytest==7.0.1
Expand Down