From fb026ec795344ebac037674ac251e4fb91635fa0 Mon Sep 17 00:00:00 2001 From: Nils Hjelte Date: Wed, 29 Nov 2023 10:33:04 +0100 Subject: [PATCH 1/6] More robust check of bash version Specifically on windows with git-bash, where python is the normal windows python install Also use `--norc` flag to avoid recursively loading .bashrc (which can happen when the click completion loading does not work properly) --- src/click/shell_completion.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/click/shell_completion.py b/src/click/shell_completion.py index dc9e00b9b0..6127a5f423 100644 --- a/src/click/shell_completion.py +++ b/src/click/shell_completion.py @@ -304,9 +304,12 @@ class BashComplete(ShellComplete): @staticmethod def _check_version() -> None: import subprocess + import shutil + + bash_exe = shutil.which('bash') output = subprocess.run( - ["bash", "-c", 'echo "${BASH_VERSION}"'], stdout=subprocess.PIPE + [bash_exe, "--norc", "-c", 'echo "${BASH_VERSION}"'], stdout=subprocess.PIPE ) match = re.search(r"^(\d+)\.(\d+)\.\d+", output.stdout.decode()) From 71290a6a29af48255779c7b37534594df4ec6cc0 Mon Sep 17 00:00:00 2001 From: Nils Hjelte Date: Wed, 29 Nov 2023 10:43:17 +0100 Subject: [PATCH 2/6] Add changelog entry --- CHANGES.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 8ce12a8cee..df4e5c79a8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -16,7 +16,8 @@ Unreleased :issue:`2632` - Fix ``click.echo(color=...)`` passing ``color`` to coloroma so it can be forced on Windows. :issue:`2606`. - +- More robust bash version check, fixing problem on Windows with git-bash. + :issue:`2638` Version 8.1.7 ------------- From 0813efa2b239af43c13442eb4a5270c8e49bef0f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 29 Nov 2023 09:49:31 +0000 Subject: [PATCH 3/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/click/shell_completion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/click/shell_completion.py b/src/click/shell_completion.py index 6127a5f423..083ead2553 100644 --- a/src/click/shell_completion.py +++ b/src/click/shell_completion.py @@ -306,7 +306,7 @@ def _check_version() -> None: import subprocess import shutil - bash_exe = shutil.which('bash') + bash_exe = shutil.which("bash") output = subprocess.run( [bash_exe, "--norc", "-c", 'echo "${BASH_VERSION}"'], stdout=subprocess.PIPE From f7f159315e28b6ed2f746f3468a7c0539e9cc756 Mon Sep 17 00:00:00 2001 From: Nils Hjelte Date: Wed, 29 Nov 2023 11:06:07 +0100 Subject: [PATCH 4/6] Fix handling of missing bash exectuable --- src/click/shell_completion.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/click/shell_completion.py b/src/click/shell_completion.py index 083ead2553..f0649f5c6f 100644 --- a/src/click/shell_completion.py +++ b/src/click/shell_completion.py @@ -308,10 +308,13 @@ def _check_version() -> None: bash_exe = shutil.which("bash") - output = subprocess.run( - [bash_exe, "--norc", "-c", 'echo "${BASH_VERSION}"'], stdout=subprocess.PIPE - ) - match = re.search(r"^(\d+)\.(\d+)\.\d+", output.stdout.decode()) + if bash_exe is None: + match = None + else: + output = subprocess.run( + [bash_exe, "--norc", "-c", 'echo "${BASH_VERSION}"'], stdout=subprocess.PIPE + ) + match = re.search(r"^(\d+)\.(\d+)\.\d+", output.stdout.decode()) if match is not None: major, minor = match.groups() From c36f7bbd935d6ec88e2a3ff41d3294d5d7da15be Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 29 Nov 2023 10:06:36 +0000 Subject: [PATCH 5/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/click/shell_completion.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/click/shell_completion.py b/src/click/shell_completion.py index f0649f5c6f..c2a2f2e975 100644 --- a/src/click/shell_completion.py +++ b/src/click/shell_completion.py @@ -312,7 +312,8 @@ def _check_version() -> None: match = None else: output = subprocess.run( - [bash_exe, "--norc", "-c", 'echo "${BASH_VERSION}"'], stdout=subprocess.PIPE + [bash_exe, "--norc", "-c", 'echo "${BASH_VERSION}"'], + stdout=subprocess.PIPE, ) match = re.search(r"^(\d+)\.(\d+)\.\d+", output.stdout.decode()) From 6b18fec8fd96fb4e4e8b05c95ad8dcc052f4e885 Mon Sep 17 00:00:00 2001 From: Andreas Backx Date: Sat, 9 Nov 2024 21:55:40 +0000 Subject: [PATCH 6/6] Import sorting. --- src/click/shell_completion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/click/shell_completion.py b/src/click/shell_completion.py index c2a2f2e975..07d0f09bac 100644 --- a/src/click/shell_completion.py +++ b/src/click/shell_completion.py @@ -303,8 +303,8 @@ class BashComplete(ShellComplete): @staticmethod def _check_version() -> None: - import subprocess import shutil + import subprocess bash_exe = shutil.which("bash")