From f703415c30dcfb5b10d110de559ac2dfa8c3f411 Mon Sep 17 00:00:00 2001 From: James Meakin <12661555+jmsmkn@users.noreply.github.com> Date: Tue, 29 Mar 2022 10:49:56 +0200 Subject: [PATCH 1/3] Update `patch_click` Borrowed from `patch_click` in `black` 22.3.0 Fixes #132 --- curlylint/cli.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/curlylint/cli.py b/curlylint/cli.py index e627959..fa957e0 100644 --- a/curlylint/cli.py +++ b/curlylint/cli.py @@ -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 @@ -286,15 +286,25 @@ 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 + except ImportError: + pass + else: + modules.append(core) + try: from click import _unicodefun - except ModuleNotFoundError: - return + 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] + if hasattr(module, "_verify_python_env"): + module._verify_python_env = lambda: None # type: ignore [attr-defined] def patched_main() -> None: From db623323f995f2897018c2497204cc439551d647 Mon Sep 17 00:00:00 2001 From: James Meakin <12661555+jmsmkn@users.noreply.github.com> Date: Tue, 29 Mar 2022 16:24:08 +0200 Subject: [PATCH 2/3] Update Black --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 9ac4e94..31dff03 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -black==22.1.0 +black==22.3.0 flake8==4.0.1 mypy==0.812 pytest==7.0.1 From 23c5193aef577ec586453c6efe8f556e0f6c57b0 Mon Sep 17 00:00:00 2001 From: James Meakin <12661555+jmsmkn@users.noreply.github.com> Date: Tue, 29 Mar 2022 16:41:48 +0200 Subject: [PATCH 3/3] Update type annotations type: ignore [misc] added to `main()` call due to changes in click 8.1.0, see https://github.com/pallets/click/issues/2227 --- curlylint/cli.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/curlylint/cli.py b/curlylint/cli.py index fa957e0..14bddaf 100644 --- a/curlylint/cli.py +++ b/curlylint/cli.py @@ -294,7 +294,7 @@ def patch_click() -> None: else: modules.append(core) try: - from click import _unicodefun + from click import _unicodefun # type: ignore [attr-defined] except ImportError: pass else: @@ -302,14 +302,14 @@ def patch_click() -> None: 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 # type: ignore [attr-defined] + module._verify_python_env = lambda: None def patched_main() -> None: patch_click() - main() + main() # type: ignore [misc] if __name__ == "__main__":