From 4101211aaa455bd0e3001768ff396e907b660833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Tue, 8 Nov 2022 14:30:20 +0100 Subject: [PATCH] Fix: Fix detecting poetry mode in existing installations Ensure that old shebang line works with poery mode. With new setups `/usr/bin/env -S poetry run python` is used instead of `/usr/bin/env -S poetry run python3` for the poetry shebang line. The old line must be still detected as poetry mode. --- autohooks/hooks.py | 2 +- tests/test_hooks.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/autohooks/hooks.py b/autohooks/hooks.py index 835e944a..3f4687c2 100644 --- a/autohooks/hooks.py +++ b/autohooks/hooks.py @@ -72,7 +72,7 @@ def read_mode(self) -> Mode: if shebang == PYTHON3_SHEBANG: return Mode.PYTHONPATH - if shebang == POETRY_SHEBANG: + if shebang.startswith(POETRY_SHEBANG): return Mode.POETRY if shebang == PIPENV_SHEBANG: return Mode.PIPENV diff --git a/tests/test_hooks.py b/tests/test_hooks.py index 51a3ce99..127808c6 100644 --- a/tests/test_hooks.py +++ b/tests/test_hooks.py @@ -173,6 +173,12 @@ def test_poetry_mode(self): self.assertEqual(pre_commit_hook.read_mode(), Mode.POETRY) + def test_poetry_mode_with_python3(self): + path = FakeReadPath(f"#!{POETRY_SHEBANG}3") + pre_commit_hook = PreCommitHook(path) + + self.assertEqual(pre_commit_hook.read_mode(), Mode.POETRY) + def test_pipenv_multiline_mode(self): path = FakeReadPath(f"#!{PIPENV_MULTILINE_SHEBANG}") pre_commit_hook = PreCommitHook(path)