Skip to content

Commit

Permalink
Fix: Fix detecting poetry mode in existing installations
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bjoernricks committed Nov 8, 2022
1 parent 7f1ec36 commit 4101211
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion autohooks/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4101211

Please sign in to comment.